Handle infinite-spinner errors and properly inform the user

pull/1/head
Caleb James DeLisle 7 years ago
parent cbf63b4c52
commit 0a6f81850f

@ -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;

@ -67,9 +67,7 @@ define([
logLevel: logLevel
});
chainpad.onMessage(function(message, cb) {
sframeChan.query('Q_RT_MESSAGE', message, function (ret) {
if (ret === 'OK') { cb(); }
});
sframeChan.query('Q_RT_MESSAGE', message, cb);
});
chainpad.onPatch(function () {
onRemote({ realtime: chainpad });

@ -155,13 +155,14 @@ define([], function () {
// want to keep the same chainpad (realtime) object
try {
wcObject.wc.bcast(message).then(function() {
cb('OK');
cb();
}, function(err) {
// The message has not been sent, display the error.
console.error(err);
});
} catch (e) {
cb('ERROR');
console.log(e);
// Just skip calling back and it will fail on the inside.
}
}
};
@ -214,6 +215,7 @@ define([], function () {
};
network.on('disconnect', function (reason) {
console.log('disconnect');
if (isIntentionallyLeaving) { return; }
if (reason === "network.disconnect() called") { return; }
sframeChan.event('EV_RT_DISCONNECT');

@ -10,9 +10,10 @@ define([
'/common/metadata-manager.js',
'/customize/application_config.js',
'/common/cryptpad-common.js'
'/common/cryptpad-common.js',
'/common/common-realtime.js'
], function ($, nThen, Messages, CpNfInner, SFrameChannel, Title, UI, History, MetadataMgr,
AppConfig, Cryptpad) {
AppConfig, Cryptpad, CommonRealtime) {
// Chainpad Netflux Inner
var funcs = {};
@ -292,6 +293,10 @@ define([
if (titleUpdated) { titleUpdated(undefined, title); }
});
});
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); });
cb(funcs);
});
} };

@ -33,6 +33,7 @@ define([
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
'/api/config',
'/common/common-realtime.js',
'/bower_components/file-saver/FileSaver.min.js',
'/bower_components/diff-dom/diffDOM.js',
@ -41,8 +42,24 @@ define([
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/customize/src/less/cryptpad.less',
'less!/customize/src/less/toolbar.less'
], function ($, Crypto, Hyperjson,
Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher, Cryptpad, Cryptget, Links, nThen, SFCommon, ApiConfig) {
], function (
$,
Crypto,
Hyperjson,
Toolbar,
Cursor,
JsonOT,
TypingTest,
JSONSortify,
TextPatcher,
Cryptpad,
Cryptget,
Links,
nThen,
SFCommon,
ApiConfig,
CommonRealtime)
{
var saveAs = window.saveAs;
var Messages = Cryptpad.Messages;
var DiffDom = window.diffDOM;
@ -322,6 +339,8 @@ define([
}
};
CommonRealtime.onInfiniteSpinner(function () { setEditable(false); });
// don't let the user edit until the pad is ready
setEditable(false);

Loading…
Cancel
Save