Nurama Developers
Namespaces

socket

Methods and types of the `socket` namespace (`client.socket` / `bot.socket`).

Interfaces

BaseNotificationEvent

Properties

PropertyType
changes?{ create?: { resource: any; resourceId: string; resourceType: string; }[]; delete?: { resourceId: string; resourceType: string; }[]; update?: { newResource?: any; oldResource?: any; resource: any; resourceId: string; resourceType: string; }[]; }
changes.create?{ resource: any; resourceId: string; resourceType: string; }[]
changes.delete?{ resourceId: string; resourceType: string; }[]
changes.update?{ newResource?: any; oldResource?: any; resource: any; resourceId: string; resourceType: string; }[]
channelsstring[]
createdAtstring
initiatorany
initiatorIdstring | null
initiatorType"user" | "system"
resourceIdstring
resourceTypestring
tokens?Record<string, any>
typestring

PublicSocketOptions

Properties

PropertyTypeDescription
autoReconnect?booleanAutomatically reconnect if connection is lost Default true
debug?booleanDebug logging Default false
websocketURL?stringOverride the WebSocket URL for this specific connection Takes precedence over the client's websocketURL option

SocketChannel

Properties

PropertyTypeDescription
channelstringChannel path
listenersRecord<string, Set<(event) => void>>Event listeners
socketSocketInterfaceSocket.IO instance

SocketInterface

Properties

PropertyType
connectedboolean
disconnect() => void
emit(event, ...args) => void
off(event) => void
on(event, listener) => void
timeout(ms) => { emit: (event, ...args) => void; }

SocketOptions

Properties

PropertyTypeDescription
autoReconnect?booleanAutomatically reconnect if connection is lost Default true
autoReconnectOnTokenExpiry?booleanAutomatically attempt to reconnect if token expires Default true
autoRefresh?booleanAutomatically handle token refresh Default true
debug?booleanDebug logging Default false
websocketURL?stringOverride the WebSocket URL for this specific connection Takes precedence over the client's websocketURL option

Type Aliases

SocketMethods

type SocketMethods = ReturnType<typeof default>;

Functions

default()

function default(client): {
  connect: (channel, options) => Promise<SocketChannel>;
  connectPublic: (publicToken, options) => Promise<SocketChannel>;
  disconnect: (channel) => Promise<void>;
  disconnectAll: () => Promise<void>;
  emit: (channel, event, data?) => void;
  emitWithAck: (channel, event, data, timeoutMs) => Promise<boolean>;
  isConnected: (channel) => boolean;
  onReconnect: (channel, callback) => void;
  onReconnectFailed: (channel, callback) => void;
  subscribe: <T>(channel, event, callback) => Promise<void>;
  subscribePublic: <T>(publicToken, event, callback) => Promise<void>;
  unsubscribe: (channel, event, callback?) => void;
};

Parameters

ParameterType
clientdefault

Returns

NameTypeDescription
connect()(channel, options) => Promise<SocketChannel>Connect to a socket channel
connectPublic()(publicToken, options) => Promise<SocketChannel>Connect to a public socket channel without authentication
disconnect()(channel) => Promise<void>Disconnect from a socket channel
disconnectAll()() => Promise<void>Disconnect from all channels
emit()(channel, event, data?) => voidEmit an event to a connected channel
emitWithAck()(channel, event, data, timeoutMs) => Promise<boolean>Emit an event with a timeout-bounded server acknowledgement. Resolves true if the server acks within timeoutMs, false on timeout or transport error. Use it to actively verify a channel's liveness when socket.connected may be stale — most notably after a backgrounded tab returns to focus, where the flag can remain true for up to socket.io's own heartbeat window (~25–45s) even after the underlying TCP transport has died. Relies on socket.io v4's socket.timeout(ms).emit(ev, data, cb) pattern: the server acknowledges the event via its trailing callback; if no ack arrives within timeoutMs the callback receives an Error.
isConnected()(channel) => booleanCheck if connected to a channel
onReconnect()(channel, callback) => voidRegister a callback for when the channel reconnects — a socket.io transport-level reconnect, or the token-refresh reconnect. Use it to recover any gap of server->client messages missed while the connection was down; socket.io does not replay those. Dispatched from the 'reconnect' handler in connect() and from the token-refresh path.
onReconnectFailed()(channel, callback) => voidRegister a callback for when Socket.IO exhausts all reconnection attempts
subscribe()<T>(channel, event, callback) => Promise<void>Subscribe to an event on a channel
subscribePublic()<T>(publicToken, event, callback) => Promise<void>Subscribe to an event on a public channel Automatically connects to the public channel if not already connected
unsubscribe()(channel, event, callback?) => voidStop listening for an event on a channel. If callback is provided, only that specific listener is removed; otherwise every listener for that event is cleared.

On this page