Metrics

Metrics provide a point-in-time snapshot detailing connections currently active in a room. Each time a connection joins or leaves a room, or joins or leaves a room's presence set, a metrics event is broadcast to all subscribers.

Subscribing to Metrics Events

By default, metrics are not broadcast to all connections. To receive metrics updates, you need to explicitly subscribe an event handler.

const myRoom = relayBox.join('myRoom');

await myRoom.metrics.subscribe((data) => {
  console.log(data);

  /*
    {
      connection: 100,
      subscriber: 100,
      publisher: 50,
      presenceSubscriber: 20,
      presenceMember: 50
   }
  */
});

Metrics data contains more information about the connections in a room, including how many connections are active and the permissions attached.

Unsubscribing from Metrics Events

To unsubscribe from metrics events, simply call the unsubscribe() method.

const myRoom = relayBox.join('myRoom');

await myRoom.metrics.unsubscribe((data) => {
  console.log(data);
});

    On this page