首页 > 解决方案 > 获取 Pubnub 中某个频道的订阅者数量

问题描述

有没有办法在 Pubnub 中获取订阅特定频道的订阅者数量?

如果是这样,请告诉我。谢谢。

标签: pubnub

解决方案


存在 - 现在在这里

阅读有关 Presence 的所有文档,以基本了解它提供的功能。

hereNowAPI是所寻求的。如果您需要其他语言的代码示例,您可以导航到文档站点上的其他 SDK(语言)。

老派的callback方式:

pubnub.hereNow(
  {
    channels: ["chats.room1", "chats.room2"],
    includeState: true
  },
  function (status, response) {
    console.log(status, response);
  }
);

async/await方式:

async function getChannelOccupants {
    try {
        const result = await pubnub.hereNow({
            channels: ["chats.room1", "chats.room2"],
        });
    } 
    catch (status) {
        console.log(status);
    }
}

推荐阅读