Learn · Publish and subscribe

Multiplexing

Share one WebSocket while each view keeps independent selection, processing, and progress.

Multiplexing carries several independent subscriptions over one WebSocket. Share a RoomClient across your application, then let each view choose its own selection, handlers, and lifetime.

One room journal feeds authorized, selected subscription frames over a shared WebSocket. Frames route to a transcript consumer and a work consumer. Each has its own selector, ordered callback queue, and processed cursor. The shared network and bounded queues still limit capacity.
Share transport and identity; keep consumer selection, callback order, and processed progress independent.Open SVG ↗Excalidraw source ↓

Share the room handle

TypeScript
// client is an RmcClient; credentials came from your authenticated backend.
const room = client.room(roomId, participantToken);

// Pass this same instance to both views.
const chat = room.channel("chat").subscribe({onEvent: renderChat});
const work = room.subscribe({
  selector: {eventTypes: ["delegation.*"]},
  onEvent: renderWork,
});

renderChat and renderWork are application callbacks. The first subscription lazily opens the socket; the second joins that connection. Each additional call to client.room(...) creates another handle with its own stream, even for identical room credentials. The React guide shows where to keep the shared instance.

Separate transport from progress

Shared by the room handle Owned by each subscription
Participant identity and WebSocket Selector and local handle ID
Connection authentication and reconnect Ordered callback queue
Network capacity and connection failures Last successfully processed cursor
Transport shutdown when the last consumer closes Handler failure and explicit consumer recovery

One handler can await application work while another subscription progresses. A slow consumer can fill its bounded queue and close; the delivery guide covers limits and recovery. A slow network connection can still affect all consumers sharing the socket.

Reconnect without merging cursors

After a transient disconnect, the SDK reopens the transport and resubscribes each active consumer from its own processed cursor. It does not use whichever consumer happened to be furthest ahead. A page restart loses these in-memory positions unless your application saved them.

Cursors and checkpoints describe how each view records progress through filtered history.

Close at the owning scope

Close chat when the chat view unmounts. Close work when its panel ends. The final subscription's closure releases the socket. The room owner can call room.dispose() to release all stream consumers together; native media has a separate lifetime.

Read SDK stream.ts, the multiplexed server, and multiplex tests. This is fan-out pub/sub: two eligible consumers can both receive an event. It does not assign work to exactly one consumer in a worker group.

Search the documentation

Type to search all guides.

Diagram

100%Open original ↗