Using Channels

Channels are named topics. You do not create them ahead of time — publish or subscribe with a string name.

Get a channel handle

const channel = socket.channels.get("chat.lobby");

get returns a local handle. It does not call the network by itself.

Subscribe (Socket only)

await channel.subscribe((message) => {
  console.log(message.channel, message.event, message.data);
});

// Optional SDK event filter
await channel.subscribe(handler, { event: "message.created" });

Publish

Socket

await channel.publish({ text: "hi" }, { event: "chat", alias: "Alice" });

WebSocket publish is fire-and-forget from the client’s perspective.

REST

const result = await rest.channels.get("chat.lobby").publish(
  { text: "hi" },
  { event: "chat" }
);

Unsubscribe / release

await channel.unsubscribe();
socket.channels.release("chat.lobby"); // drop local handle (used by React hooks)

Pause / resume (Socket)

channel.pause({ bufferMessages: true });
channel.resume();

Naming tips

  • Prefer domain.entity.action style: orders.42.updates
  • Avoid spaces and ambiguous short names
  • Coordinate names across publishers and subscribers in your app

Access control

Who can publish or subscribe is controlled by permissions on the API key or JWT — not by channel “types”.