Check if the worker is available when focusing a tab again
This commit is contained in:
@@ -6,6 +6,7 @@ define([
|
|||||||
'/common/common-messaging.js',
|
'/common/common-messaging.js',
|
||||||
'/common/common-constants.js',
|
'/common/common-constants.js',
|
||||||
'/common/common-feedback.js',
|
'/common/common-feedback.js',
|
||||||
|
'/common/visible.js',
|
||||||
'/common/userObject.js',
|
'/common/userObject.js',
|
||||||
'/common/outer/local-store.js',
|
'/common/outer/local-store.js',
|
||||||
'/common/outer/worker-channel.js',
|
'/common/outer/worker-channel.js',
|
||||||
@@ -14,7 +15,7 @@ define([
|
|||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
], function (Config, Messages, Util, Hash,
|
], function (Config, Messages, Util, Hash,
|
||||||
Messaging, Constants, Feedback, UserObject, LocalStore, Channel, Block,
|
Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block,
|
||||||
AppConfig, Nthen) {
|
AppConfig, Nthen) {
|
||||||
|
|
||||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||||
@@ -1749,19 +1750,37 @@ define([
|
|||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var lastPing = +new Date();
|
||||||
var onPing = function (data, cb) {
|
var onPing = function (data, cb) {
|
||||||
|
lastPing = +new Date();
|
||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
var timeout = false;
|
var timeout = false;
|
||||||
common.onTimeoutEvent = Util.mkEvent();
|
common.onTimeoutEvent = Util.mkEvent();
|
||||||
var onTimeout = function () {
|
var onTimeout = function (fromOuter) {
|
||||||
|
var key = fromOuter ? "TIMEOUT_OUTER" : "TIMEOUT_KICK";
|
||||||
|
Feedback.send(key, true);
|
||||||
timeout = true;
|
timeout = true;
|
||||||
common.onNetworkDisconnect.fire();
|
common.onNetworkDisconnect.fire();
|
||||||
common.padRpc.onDisconnectEvent.fire();
|
common.padRpc.onDisconnectEvent.fire();
|
||||||
common.onTimeoutEvent.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 = {
|
var queries = {
|
||||||
PING: onPing,
|
PING: onPing,
|
||||||
TIMEOUT: onTimeout,
|
TIMEOUT: onTimeout,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ define([
|
|||||||
DISCONNECT: Store.disconnect,
|
DISCONNECT: Store.disconnect,
|
||||||
CREATE_README: Store.createReadme,
|
CREATE_README: Store.createReadme,
|
||||||
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
||||||
|
PING: function (cId, data, cb) { cb(); },
|
||||||
// RPC
|
// RPC
|
||||||
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
||||||
GET_PIN_LIMIT: Store.getPinLimit,
|
GET_PIN_LIMIT: Store.getPinLimit,
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ define([
|
|||||||
var metaObj;
|
var metaObj;
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
Cryptpad.getMetadata(waitFor(function (err, n) {
|
Cryptpad.getMetadata(waitFor(function (err, n) {
|
||||||
if (err) { console.log(err); }
|
if (err) {
|
||||||
|
waitFor.abort();
|
||||||
|
return void console.log(err);
|
||||||
|
}
|
||||||
metaObj = n;
|
metaObj = n;
|
||||||
}));
|
}));
|
||||||
}).nThen(function (/*waitFor*/) {
|
}).nThen(function (/*waitFor*/) {
|
||||||
|
|||||||
Reference in New Issue
Block a user