Channels Collection
Access channels through thechannels property:
get
channels.get(name, options?): Channel
Get or create a channel instance.
Channel name. Use
: to separate namespaces (for example, chat:room1).Channel options:
params(object): Channel parameters for filteringmodes(array): Channel modes (for example,['PUBLISH', 'SUBSCRIBE'])cipher(object): Encryption configuration
release
channels.release(name): void
Release a channel and remove all listeners.
Channel Object
A channel instance provides methods for publishing, subscribing, and managing channel state.Properties
The channel name.
Current channel state:
initialized, attaching, attached, detaching, detached, or failed.Error information if channel is in failed state.
Presence object for this channel. See Presence API.
publish
publish(name?, data?, callback?): Promise<void>
Publish a message to the channel.
Optional event name for the message.
Message payload. Supported types: string, JSON object, binary data.
Optional callback function called on completion.
subscribe
subscribe(eventName?, listener): Promise<void>
Subscribe to messages on the channel.
Optional event name to filter messages.
Callback function called for each message.
unsubscribe
unsubscribe(eventName?, listener?): void
Unsubscribe from messages.
attach
attach(callback?): Promise<void>
Explicitly attach to the channel.
detach
detach(callback?): Promise<void>
Detach from the channel.
history
history(options?): Promise<PaginatedResult<Message>>
Retrieve message history for the channel.
Start time in milliseconds since epoch.
End time in milliseconds since epoch.
Maximum number of messages to return (max 1000).
Query direction:
forwards or backwards.Channel Events
Subscribe to channel state changes: Channel states:initialized- Channel created but not attachedattaching- Attachment in progressattached- Successfully attacheddetaching- Detachment in progressdetached- Detached from channelfailed- Attachment failed
