【问题标题】:Get the number of subscribers to a channel in Pubnub获取 Pubnub 中某个频道的订阅者数量
【发布时间】:2021-12-24 12:56:55
【问题描述】:

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

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

【问题讨论】:

    标签: pubnub


    【解决方案1】:

    存在 - 现在在这里

    阅读所有docs about Presence 以基本了解它所提供的功能。

    hereNow API 是所寻求的。如果您需要其他语言的代码示例,您可以导航到文档站点上的其他 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 2015-09-27
      相关资源
      最近更新 更多