From 4a37bc4a1c15431cd92e3187decfa34541ccd912 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 10 Jul 2017 10:34:25 +0200 Subject: [PATCH] abort the realtime session if it does not synchronize for 30 seconds --- customize.dist/translations/messages.js | 2 ++ www/common/cryptpad-common.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 02f682d4d..6fc608855 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -36,6 +36,8 @@ define(function () { out.synced = "Everything is saved"; out.deleted = "Pad deleted from your CryptDrive"; + out.realtime_unrecoverableError = "The realtime engine has encountered an unrecoverable error. Click OK to reload."; + out.disconnected = 'Disconnected'; out.synchronizing = 'Synchronizing'; out.reconnecting = 'Reconnecting...'; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 8af4c045a..d8547d4a4 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -202,13 +202,29 @@ define([ return; }; + common.infiniteSpinnerDetected = false; var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) { realtime.sync(); + window.setTimeout(function () { if (realtime.getAuthDoc() === realtime.getUserDoc()) { return void cb(); } + + var to = setTimeout(function () { + realtime.abort(); + // don't launch more than one popup + if (common.infiniteSpinnerDetected) { return; } + + // inform the user their session is in a bad state + common.confirm(Messages.realtime_unrecoverableError, function (yes) { + if (!yes) { return; } + window.location.reload(); + }); + common.infiniteSpinnerDetected = true; + }, 30000); realtime.onSettle(function () { + clearTimeout(to); cb(); }); }, 0);