简体   繁体   English

取消订阅PubNub不会触发在线状态事件

[英]PubNub unsubscribe isn't firing presence event

I'm using the latest JavaScript API for PubNub, with presence switched on in the admin interface. 我正在使用适用于PubNub的最新JavaScript API,并且在管理界面中已打开状态。 I'm running two clients on a channel, initialized and subscribed like this: 我在一个通道上运行两个客户端,如下所示进行初始化和订阅:

pubnub = PUBNUB.init({
                publish_key   : 'xxx',
                subscribe_key : 'xxx',
                origin        : 'pubsub.pubnub.com',
                cipher_key    : 'xxx',
                ssl           : 'true',
                uuid          : uuid
            });

pubnub.subscribe({
                channel : CHANNEL,
                callback : function (message) {
                    $("#box").val($("#box").val() + message + "\r\n");
                },
                connect:    function () { console.log("Connected"); users(); },
                disconnect: function () { console.log("Disconnected"); },
                reconnect:  function () { console.log("Reconnected"); },
                error:      function () { console.log("Network Error"); },
                presence:   function (m) { console.log("Presence: " + m); }
            });

I unsubscribe from the channel like this: 我这样退订频道:

function unsubscribe() {
    pubnub.unsubscribe({
        channel:    CHANNEL
    });
    console.log("Unsubscribed");
};

When clients join the channel, I see join presence actions in all clients that are subscribed. 当客户端加入频道时,我会在所有订阅的客户端中看到join状态操作。 When clients timeout, I see those actions too. 当客户端超时时,我也看到了这些动作。

When I call unsubscribe() the log line prints, and that client does not receive any more messages published on the channel, but there is no leave presence action received by other clients who are still subscribed. 当我调用unsubscribe()将打印日志行,并且该客户端不再收到该通道上发布的任何消息,但是仍在订阅的其他客户端没有收到leave状态操作 What am I doing wrong? 我究竟做错了什么?

Strangely enough, when I tried to subscribe this morning I got a 400 Invalid error. 奇怪的是,当我今天早上尝试订阅时,出现了400个无效错误。 When I investigated, the PubNub admin screen told me that there were no keys associated with my project. 当我调查时,PubNub管理员屏幕告诉我没有与我的项目关联的密钥。

When I had regenerated the keys I could subscribe - and the join and leave events worked as expected too. 重新生成密钥后,我可以预订-联接和离开事件也按预期工作。 I now get the response I expect from here-now as well. 现在,我现在也能收到我期望的答复。

Odd, but fixed! 奇怪,但固定!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM