查询Websocket在线用户列表 - GoEasy PubSub

启用和关闭

所有应用(包括免费应用)均可在我的应用 -> 查看详情 -> 高级功能 -> 在线用户查询和上下线提醒 自助启用和关闭。

资费

1.每调用一次扣减消息量1条

前置条件

只有初始化了客户端ID客户端才能被查询。

客户端Javascript查询

根据channel获取当前在线客户端列表

    goeasy.pubsub.hereNow({
        channels: ["my_channel", "my_channel2"],
        includeUsers: true, //可选项,是否返回用户列表,默认false
        distinct: true, //可选项,相同userId的客户端,列表中只保留一个,默认false,
        onSuccess: function (response) {  //获取成功
            alert("hereNow response: " + JSON.stringify(response));//json格式的response           
            /**
            response示例:
            {
               "code": 200,
               "content": {
                  "channels": {
                     "channel_A": {      //channel
                        "channel": "channel_A",
                        "clientAmount": 2,    //在线客户端数量
                        "userAmount": 2,      //在线用户数量
                        "users": [    //在线用户id列表
                           {"id":"Jack","data":{"avatar":"/www/xxx.png","nickname":"Jack"}}, //在线用户
                           {"id":"Ted","data":{"avatar":"/www/xxx.png","nickname":"Ted"}}                                    
                        ]
                     },
                     "channel_B": {       //channel
                        "channel": "channel_B",
                        "clientAmount": 1,     
                        "userAmount": 1,       
                        "users": [     
                           {"id":"Tom","data":{"avatar":"/www/xxx.png","nickname":"Tom"}}
                        ]
                     }
                  }
               }
            }
            **/
        },
        onFailed: function (error) { //获取失败
            console.log("Failed to obtain online clients, code:"+error.code+ ",error:"+error.content);
        }
    });

根据userId获取当前在线客户端列表

    goeasy.pubsub.hereNowByUserIds({
        userIds: ["Jack", "Ted", "Tom"],
        distinct: true, //可选项,相同userId的客户端,列表中只保留一个,默认false
        onSuccess: function (response) {
            alert("hereNowByUserIds response: "  + JSON.stringify(response));//json格式的response           
            /**
            response示例:
            {
                "code":200,
                "content":[
                    {"id":"Ted","data":{"avatar":"/www/xxx.png","nickname":"Ted"}},
                    {"id":"Jack","data":{"avatar":"/www/xxx.png","nickname":"Jack"}}
                ]
            }
            **/
        },
        onFailed: function (error) { //获取失败
            console.log("Failed to obtain online clients, code:"+error.code+ ",error:"+error.content);
        }
    });

results matching ""

    No results matching ""