Skip to content

subscribe

const subscribe: any = addon.subscribe

Defined in: index.cts:493

Subscribes one or more WebSocket connections to a channel, or copies subscriptions from one channel to another. Multiple subscriptions to the same channel by the same connection are reference-counted.

socketIdOrChannelName

Can be:

  • A single socket ID (number): applies delta to that socket’s subscription
  • An array of socket IDs (number[]): applies delta to all sockets’ subscriptions
  • A channel name (Buffer/ArrayBuffer/string): applies delta to all subscribers of this source channel
  • An array mixing socket IDs and channel names: applies delta to sockets and source channel subscribers

channelName

The target channel name (Buffer, ArrayBuffer, or string).

delta

Optional. The amount to change the subscription count by (default: 1). Positive values add subscriptions, negative values remove them. When the count reaches zero, the subscription is removed.

An array of socket IDs that were affected by the operation:

  • For positive delta: socket IDs that became newly subscribed (reference count went from 0 to positive)
  • For negative delta: socket IDs that became completely unsubscribed (reference count reached 0)