Namespaces
socket
Methods and types of the `socket` namespace (`client.socket` / `bot.socket`).
Interfaces
BaseNotificationEvent
Properties
PublicSocketOptions
Properties
SocketChannel
Properties
| Property | Type | Description |
|---|---|---|
channel | string | Channel path |
listeners | Record<string, Set<(event) => void>> | Event listeners |
socket | SocketInterface | Socket.IO instance |
SocketInterface
Properties
| Property | Type |
|---|---|
connected | boolean |
disconnect | () => void |
emit | (event, ...args) => void |
off | (event) => void |
on | (event, listener) => void |
timeout | (ms) => { emit: (event, ...args) => void; } |
SocketOptions
Properties
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
| Parameter | Type |
|---|---|
client | default |
Returns
| Name | Type | Description |
|---|---|---|
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?) => void | Emit 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) => boolean | Check if connected to a channel |
onReconnect() | (channel, callback) => void | Register 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) => void | Register 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?) => void | Stop 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. |