Documentation / zerotal / client / Socket
Class: Socket
Defined in: packages/client/src/Socket.ts:224
Realtime client for Zerotal broadcasting (native ws / redis drivers). Exposes a
familiar realtime-client API over the native protocol — see the module header for usage.
Constructors
Constructor
new Socket(
options?):Socket
Defined in: packages/client/src/Socket.ts:248
Parameters
options?
SocketOptions = {}
Returns
Socket
Accessors
state
Get Signature
get state():
SocketState
Defined in: packages/client/src/Socket.ts:281
Current connection state.
Returns
Methods
socketId()
socketId():
string|null
Defined in: packages/client/src/Socket.ts:276
The socket id assigned by the server — pass it as the X-Socket-ID header so server
toOthers() broadcasts skip this client. null until connected.
Returns
string | null
connect()
connect():
void
Defined in: packages/client/src/Socket.ts:286
Open the connection (no-op if already open/connecting).
Returns
void
disconnect()
disconnect():
void
Defined in: packages/client/src/Socket.ts:303
Close the connection and stop reconnecting.
Returns
void
on()
on(
state,cb): () =>void
Defined in: packages/client/src/Socket.ts:312
Register a connection-state callback. Returns an unsubscribe function.
Parameters
state
cb
(detail?) => void
Returns
() => void
channel()
channel(
name):Channel
Defined in: packages/client/src/Socket.ts:322
Subscribe to a public channel.
Parameters
name
string
Returns
private()
private(
name):Channel
Defined in: packages/client/src/Socket.ts:327
Subscribe to a private channel (the private- prefix is added for you).
Parameters
name
string
Returns
presence()
presence(
name):PresenceChannel
Defined in: packages/client/src/Socket.ts:333
Subscribe to a presence channel (the presence- prefix is added for you).
Parameters
name
string
Returns
join()
join(
name):PresenceChannel
Defined in: packages/client/src/Socket.ts:339
Echo alias for presence (window.Echo.join(...)).
Parameters
name
string
Returns
leave()
leave(
name):void
Defined in: packages/client/src/Socket.ts:347
Leave a channel by its base name — unsubscribes the public, private-, and presence-
variants (Echo's leave() semantics).
Parameters
name
string
Returns
void
leaveChannel()
leaveChannel(
wireName):void
Defined in: packages/client/src/Socket.ts:354
Leave one exact (already-prefixed) channel.
Parameters
wireName
string
Returns
void
channels()
channels():
Channel[]
Defined in: packages/client/src/Socket.ts:360
All currently-subscribed channels (by wire name).
Returns
Channel[]