- Docs
- API Reference
- Socket SDK
- Socket SDK Channels
Socket SDK Channels
Channel handles are how Socket clients subscribe and publish.
Manager (socket.channels)
| Method | Description |
|---|---|
get(name) | Channel handle for name |
has(name) | Whether a handle exists |
release(name) | Drop local handle (ref-count) |
remove(name) | Remove handle |
Channel methods
const channel = socket.channels.get("demo");
await channel.subscribe((message) => {
console.log(message.data, message.event);
}, { event: "optional-filter", timeout: 10000 });
await channel.publish({ hello: true }, { event: "ping", alias: "bot" });
await channel.unsubscribe(); // whole channel
await channel.unsubscribe(handler, { event: "optional-filter" });
channel.pause({ bufferMessages: true });
channel.resume();
| Method | Description |
|---|---|
subscribe(handler, options?) | Subscribe; resolves on ack. Options: event, timeout (default 10s) |
unsubscribe(handler?, options?) | Unsubscribe all or one event handler |
publish(data, options?) | Publish over WebSocket |
pause(options?) | Pause delivery locally |
resume() | Resume |
on(event, handler) | Channel lifecycle events |
Event filters are applied in the SDK after a full-channel subscription.
Message callback
Fields commonly used by apps: channel, event, data, alias, id, timestamp.
Channel events
initialized, subscribing, subscribed, unsubscribing, unsubscribed, paused, resumed, failed.
Previous
Connection
Next
REST SDK