diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 3f362a146..bdcea756b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -6,6 +6,7 @@ define([ '/common/common-messaging.js', '/common/common-constants.js', '/common/common-feedback.js', + '/common/visible.js', '/common/userObject.js', '/common/outer/local-store.js', '/common/outer/worker-channel.js', @@ -14,7 +15,7 @@ define([ '/customize/application_config.js', '/bower_components/nthen/index.js', ], function (Config, Messages, Util, Hash, - Messaging, Constants, Feedback, UserObject, LocalStore, Channel, Block, + Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block, AppConfig, Nthen) { /* This file exposes functionality which is specific to Cryptpad, but not to @@ -1749,19 +1750,37 @@ define([ cb(); }; + var lastPing = +new Date(); var onPing = function (data, cb) { + lastPing = +new Date(); cb(); }; var timeout = false; common.onTimeoutEvent = Util.mkEvent(); - var onTimeout = function () { + var onTimeout = function (fromOuter) { + var key = fromOuter ? "TIMEOUT_OUTER" : "TIMEOUT_KICK"; + Feedback.send(key, true); timeout = true; common.onNetworkDisconnect.fire(); common.padRpc.onDisconnectEvent.fire(); common.onTimeoutEvent.fire(); }; + Visible.onChange(function (visible) { + if (!visible) { return; } + var now = +new Date(); + // If last ping is bigger than 2min, ping the worker + if (now - lastPing > (2 * 60 * 1000)) { + var to = setTimeout(function () { + onTimeout(true); + }); + postMessage('PING', null, function () { + clearTimeout(to); + }); + } + }); + var queries = { PING: onPing, TIMEOUT: onTimeout, diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index 41a3f7a0e..82f7e1452 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -13,6 +13,7 @@ define([ DISCONNECT: Store.disconnect, CREATE_README: Store.createReadme, MIGRATE_ANON_DRIVE: Store.migrateAnonDrive, + PING: function (cId, data, cb) { cb(); }, // RPC UPDATE_PIN_LIMIT: Store.updatePinLimit, GET_PIN_LIMIT: Store.getPinLimit, diff --git a/www/share/main.js b/www/share/main.js index adbd69e05..f1f9a3a3a 100644 --- a/www/share/main.js +++ b/www/share/main.js @@ -79,7 +79,10 @@ define([ var metaObj; nThen(function (waitFor) { Cryptpad.getMetadata(waitFor(function (err, n) { - if (err) { console.log(err); } + if (err) { + waitFor.abort(); + return void console.log(err); + } metaObj = n; })); }).nThen(function (/*waitFor*/) {