这可能按预期工作,我只是不完全理解断开连接的工作原理,但我有一个聊天客户端,我将心跳设置为 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 客户端几乎在发送“超时”存在的同时触发事件。但是,我无法弄清楚为什么它们开火所需的时间变化如此之大的押韵或原因。
是否有可能让系统在连接丢失 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));
}
});