1

This may be working as intended and I am just not fully understanding how disconnects work, but I have a chat client that I set the heartbeat to 30seconds (i know that's low).

Using chrome's debugger throttling I would set throttling profile to offline then immediately watch the time.

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

The javascript client is firing the event at pretty much the same time as the "timeout" presence is sent out. However, I cannot figure out the rhyme or reason why the time it takes them to fire vary so much.

Is it possible to have the system ALWAYS fire the disconnect callback and "timeout" presence after 30sec of connectivity loss?

EDIT: Using the latest SDK 3.14.4

Client 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));
        }
    });

Client 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));
        }
    });      
Josh Danko
  • 73
  • 1
  • 6
  • Can you provide your full code? – Craig Conover Mar 25 '16 at 22:14
  • I updated with 2 test clients I made to more closely resemble what our app is doing (client1: channel and client2: channel_group with client1's channel added to it). "Client2" always seems to get the timeout around 20sec. client1 doesn't seem to fire "disconnected" hardly ever really. When it does it is usually 60sec+. I am sure I probably am doing something wrong, but I cannot see what. I followed this: https://www.pubnub.com/docs/web-javascript/presence#optimizing_timeout_events – Josh Danko Mar 28 '16 at 15:36
  • Just an FYI. All I did was add a presence callback on client1 and now it fires after 30sec every time. In my test app and in our main app. I removed the handler and it goes back to being inconsistent. I looked at the source of the JS SDK and the only thing I see it does is subscribe to the presence channel and call here_now. – Josh Danko Mar 29 '16 at 18:03

0 Answers0