PubNub - 不稳定的断开行为

时间:2016-03-25 14:44:57

标签: callback timeout pubnub disconnect user-presence

这可能是按预期工作的,我只是没有完全理解断开连接是如何工作的,但我有一个聊天客户端,我将心跳设置为30秒(我知道它很低)。

使用chrome的调试器限制我会将限制配置文件设置为离线然后立即观看时间。

1st pass 
- Javascript Client disconnect callback fired after ~300s (the default) 
- Server side presence "timeout" received ~300s later

2nd pass
- Client disconnect callback fired after exactly 30s (the heartbeat i set)
- Server side presence "timeout" received ~31s

3rd pass
- Client disconnect callback fired after ~270 seconds (30seconds less than     the default)
- Server side presence "timeout" received ~272 seconds

4th pass
- Client disconnect callback fired after ~249 seconds
- Server side presence "timeout" received ~248 seconds

javascript客户端几乎与" timeout"同时触发事件。存在被发送出去。但是,我无法弄清楚为什么他们开火的时间变化如此之多的押韵或原因。

是否可以让系统始终触发断开连接回调和"超时"在30秒的连接丢失后存在?

编辑:使用最新的SDK 3.14.4

客户1:

var client = PUBNUB.init({
        subscribe_key: 'sub-key',
        restore: false,
        ssl: true,
        uuid: 'client1',
        heartbeat: 30
    });

    client.subscribe({
        channel: 'mychannel2',
        connect: function () {
            console.log('Connected');
        },
        disconnect: function () {
            console.log('Disconnected');
        },
        reconnect: function () {
            console.log('Reconnected');
        },
        error: function () {
            console.log('Error');
        },
        message: function (message) {
            console.log('Message: ' + JSON.stringify(message));
        }
    });

客户2:

    var client = PUBNUB.init({
        subscribe_key: 'sub-key',
        restore: true,
        ssl: true,
        uuid: 'client2'
    });

    client.channel_group_add_channel({
        channel: 'mychannel2', 
        channel_group: 'mygroup'});

    client.subscribe({
        channel_group: 'mygroup',
        connect: function () {
            console.log('Connected');
        },
        disconnect: function () {
            console.log('Disconnected');
        },
        reconnect: function () {
            console.log('Reconnected');
        },
        error: function () {
            console.log('Error');
        },
        message: function (message) {
            console.log('Message: ' + JSON.stringify(message));
        },
        presence: function (message) {
            console.log('Presence: ' + JSON.stringify(message));
        }
    });      

0 个答案:

没有答案