diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index b81b152f2..5600af0c8 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1048,17 +1048,22 @@ define([ cb(); }; - /*var onPing = function (data, cb) { + var onPing = function (data, cb) { cb(); }; + var timeout = false; var onTimeout = function () { - //alert("Timeout"); - };*/ + // XXX + timeout = true; + common.onNetworkDisconnect.fire(); + // FIXME: no UI in outer... + alert("Timeout error, please reload this tab"); + }; var queries = { - /*PING: onPing, - TIMEOUT: onTimeout,*/ + PING: onPing, + TIMEOUT: onTimeout, REQUEST_LOGIN: requestLogin, UPDATE_METADATA: common.changeMetadata, UPDATE_TOKEN: function (data) { @@ -1375,6 +1380,7 @@ define([ console.log('Outer ready'); Object.keys(queries).forEach(function (q) { chan.on(q, function (data, cb) { + if (timeout) { return; } try { queries[q](data, cb); } catch (e) { @@ -1387,6 +1393,7 @@ define([ postMessage = function (cmd, data, cb, opts) { cb = cb || function () {}; + if (timeout) { return void cb ({error: 'TIMEOUT'}); } chan.query(cmd, data, function (err, data) { if (err) { return void cb ({error: err}); } cb(data); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 6a3d64f06..0ff44e651 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1277,6 +1277,7 @@ define([ } store.cursor.removeClient(clientId); store.onlyoffice.removeClient(clientId); + Object.keys(Store.channels).forEach(function (chanId) { var chanIdx = Store.channels[chanId].clients.indexOf(clientId); if (chanIdx !== -1) { @@ -1592,7 +1593,6 @@ define([ broadcast([], 'NETWORK_RECONNECT', {myId: info.myId}); }); - /* // Ping clients regularly to make sure one tab was not closed without sending a removeClient() // command. This allow us to avoid phantom viewers in pads. var PING_INTERVAL = 30000; @@ -1609,24 +1609,22 @@ define([ clients.forEach(function (cId) { var nb = 0; var ping = function () { - nb++; if (nb >= MAX_FAILED_PING) { Store._removeClient(cId); postMessage(cId, 'TIMEOUT'); - console.error('TIMEOUT 5 errors'); + console.error('TIMEOUT', cId); return; } + nb++; var to = setTimeout(ping, MAX_PING); - console.log('ping'); - postMessage(cId, 'PING', null, function () { - console.log('pong'); + postMessage(cId, 'PING', null, function (err) { + if (err) { console.error(err); } clearTimeout(to); }); }; ping(); }); }, PING_INTERVAL); - */ };