InvergeDocs
JavaScriptAPI reference

Realtime

Realtime in the JavaScript SDK.

// access
nexus.realtime
SymbolKindSummary
EventHandlertype
NexusRealtimeclassRealtime messaging over Socket.IO.

EventHandler

type
export type EventHandler = (data: unknown) => void;

NexusRealtime

class

Realtime messaging over Socket.IO. Authenticated with the API key + journey identity. socket.io-client is an optional peer dependency (loaded on demand).

NexusRealtime

constructor
new NexusRealtime(cfg: ResolvedConfig, id: NexusIdentity)

Parameters

Prop

Type

Returns NexusRealtime

View source

isConnected

property
readonly isConnected: boolean

connect()

method
async connect(): Promise<void>

Open the connection. Idempotent, and safe under concurrent callers — a connection already open (or being opened) is reused, never duplicated. Rooms are re-joined after every reconnect.

View source

join()

method
async join(room: string): Promise<unknown>

Join a room. Idempotent — a room already joined this session is not re-emitted (the reconnect handler re-joins it automatically). Returns the server ack ({ ok, room, related }), or a synthetic ack when already joined.

Parameters

Prop

Type

Returns Promise<unknown>

View source

leave()

method
async leave(room: string): Promise<unknown>

Leave a room.

Parameters

Prop

Type

Returns Promise<unknown>

View source

emit()

method
async emit(room: string, event: string | string[], payload?: unknown): Promise<unknown>

Emit one or more named events to a room with a payload.

Parameters

Prop

Type

Returns Promise<unknown>

View source

on()

method
on(event: string, handler: EventHandler): () => void

Listen for a server event. Multiple handlers per event are supported. Registering the SAME handler twice is a no-op (never stacks a duplicate socket listener). Returns an unsubscribe function — call it (e.g. from a component's teardown) instead of leaking a listener on every remount.

Parameters

Prop

Type

Returns () => void

View source

off()

method
off(event: string, handler?: EventHandler): void

Stop listening. With a handler, removes just that one; without, removes every handler for the event.

Parameters

Prop

Type

View source

disconnect()

method
disconnect(): void
View source

On this page