ChannelDetails

Channel metadata describes the current state of a channel, including whether it is active and its occupancy metrics. It is represented by the ChannelDetails type.

A realtime client receives ChannelDetails payloads in two ways:

  • By subscribing to a metachannel such as [meta]channel.lifecycle, where each message's data is a ChannelDetails object describing a channel lifecycle event.
  • By subscribing to a channel with the occupancy channel option enabled, which delivers [meta]occupancy events whose data contains the channel's occupancy metrics.

The canonical, typed way to fetch a channel's current ChannelDetails on demand is the REST SDK's channel.status() method; over a realtime connection the same information arrives asynchronously as the events described above.

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

// Receive channel lifecycle events, each carrying a ChannelDetails payload
const metaChannel = realtime.channels.get('[meta]channel.lifecycle');
await metaChannel.subscribe((message) => {
  const details = message.data;
  console.log(details.channelId, details.status.occupancy.metrics.connections);
});

// Receive occupancy events by enabling the occupancy channel option
const channel = realtime.channels.get('all-gas-ion', {
  params: { occupancy: 'metrics' },
});
await channel.subscribe('[meta]occupancy', (message) => {
  console.log(message.data.metrics);
});

ChannelDetails

A ChannelDetails object contains information about a channel, along with its current state in a ChannelStatus object.

channelIdString
The name of the channel, including any qualifier.
statusChannelStatus
The current state of the channel.

Example

The following is an example of a ChannelDetails payload:

JSON

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

{
  "channelId": "foo",
  "status": {
    "isActive": true,
    "occupancy": {
      "metrics": {
        "connections": 1,
        "publishers": 1,
        "subscribers": 1,
        "presenceConnections": 1,
        "presenceMembers": 0,
        "presenceSubscribers": 1
      }
    }
  }
}