Handle infinite-spinner errors and properly inform the user
This commit is contained in:
@@ -9,23 +9,33 @@ define([
|
||||
AppConfig.badStateTimeout: 30000;
|
||||
|
||||
var connected = false;
|
||||
var intr;
|
||||
var infiniteSpinnerHandlers = [];
|
||||
|
||||
/*
|
||||
TODO make this not blow up when disconnected or lagging...
|
||||
*/
|
||||
common.whenRealtimeSyncs = function (Cryptpad, realtime, cb) {
|
||||
realtime.sync();
|
||||
|
||||
window.setTimeout(function () {
|
||||
if (realtime.getAuthDoc() === realtime.getUserDoc()) {
|
||||
return void cb();
|
||||
} else {
|
||||
realtime.onSettle(cb);
|
||||
}
|
||||
|
||||
var to = setTimeout(function () {
|
||||
if (!connected) { return; }
|
||||
if (intr) { return; }
|
||||
intr = window.setInterval(function () {
|
||||
var l;
|
||||
try {
|
||||
l = realtime.getLag();
|
||||
} catch (e) {
|
||||
throw new Error("ChainPad.getLag() does not exist, please `bower update`");
|
||||
}
|
||||
if (l.lag < BAD_STATE_TIMEOUT || !connected) { return; }
|
||||
realtime.abort();
|
||||
// don't launch more than one popup
|
||||
if (common.infiniteSpinnerDetected) { return; }
|
||||
infiniteSpinnerHandlers.forEach(function (ish) { ish(); });
|
||||
|
||||
// inform the user their session is in a bad state
|
||||
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
||||
@@ -33,14 +43,12 @@ define([
|
||||
window.location.reload();
|
||||
});
|
||||
common.infiniteSpinnerDetected = true;
|
||||
}, BAD_STATE_TIMEOUT);
|
||||
realtime.onSettle(function () {
|
||||
clearTimeout(to);
|
||||
cb();
|
||||
});
|
||||
}, 2000);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
common.onInfiniteSpinner = function (f) { infiniteSpinnerHandlers.push(f); };
|
||||
|
||||
common.setConnectionState = function (bool) {
|
||||
if (typeof(bool) !== 'boolean') { return; }
|
||||
connected = bool;
|
||||
|
||||
Reference in New Issue
Block a user