Subscriptions

Manage what data the server pushes to your connection. Subscribe to multiple channels per connection; the server multiplexes them on the same socket.

Subscribe

{ "type": "subscribe", "channel": "nba.scores.live" }

You can subscribe to multiple channels in parallel:

ws.send(JSON.stringify({ type: 'subscribe', channel: 'nba.scores.live' }));
ws.send(JSON.stringify({ type: 'subscribe', channel: 'news.injuries' }));

Unsubscribe

{ "type": "unsubscribe", "channel": "nba.scores.live" }

Filters

Most channels accept a filter object to narrow what you receive. Cuts down on bandwidth and your own filtering logic.

{
  "type": "subscribe",
  "channel": "news",
  "filter": { "league": "nba", "team": "LAL" }
}

Wildcards

Channel names support a single trailing wildcard (*) for catch-alls. The server flattens these to individual subscriptions on its side.

{ "type": "subscribe", "channel": "news.*" }
{ "type": "subscribe", "channel": "nba.games.*" }