Handle infinite-spinner errors and properly inform the user
This commit is contained in:
@@ -9,23 +9,33 @@ define([
|
|||||||
AppConfig.badStateTimeout: 30000;
|
AppConfig.badStateTimeout: 30000;
|
||||||
|
|
||||||
var connected = false;
|
var connected = false;
|
||||||
|
var intr;
|
||||||
|
var infiniteSpinnerHandlers = [];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO make this not blow up when disconnected or lagging...
|
TODO make this not blow up when disconnected or lagging...
|
||||||
*/
|
*/
|
||||||
common.whenRealtimeSyncs = function (Cryptpad, realtime, cb) {
|
common.whenRealtimeSyncs = function (Cryptpad, realtime, cb) {
|
||||||
realtime.sync();
|
|
||||||
|
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
if (realtime.getAuthDoc() === realtime.getUserDoc()) {
|
if (realtime.getAuthDoc() === realtime.getUserDoc()) {
|
||||||
return void cb();
|
return void cb();
|
||||||
|
} else {
|
||||||
|
realtime.onSettle(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
var to = setTimeout(function () {
|
if (intr) { return; }
|
||||||
if (!connected) { 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();
|
realtime.abort();
|
||||||
// don't launch more than one popup
|
// don't launch more than one popup
|
||||||
if (common.infiniteSpinnerDetected) { return; }
|
if (common.infiniteSpinnerDetected) { return; }
|
||||||
|
infiniteSpinnerHandlers.forEach(function (ish) { ish(); });
|
||||||
|
|
||||||
// inform the user their session is in a bad state
|
// inform the user their session is in a bad state
|
||||||
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
||||||
@@ -33,14 +43,12 @@ define([
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
common.infiniteSpinnerDetected = true;
|
common.infiniteSpinnerDetected = true;
|
||||||
}, BAD_STATE_TIMEOUT);
|
}, 2000);
|
||||||
realtime.onSettle(function () {
|
|
||||||
clearTimeout(to);
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
common.onInfiniteSpinner = function (f) { infiniteSpinnerHandlers.push(f); };
|
||||||
|
|
||||||
common.setConnectionState = function (bool) {
|
common.setConnectionState = function (bool) {
|
||||||
if (typeof(bool) !== 'boolean') { return; }
|
if (typeof(bool) !== 'boolean') { return; }
|
||||||
connected = bool;
|
connected = bool;
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ define([
|
|||||||
logLevel: logLevel
|
logLevel: logLevel
|
||||||
});
|
});
|
||||||
chainpad.onMessage(function(message, cb) {
|
chainpad.onMessage(function(message, cb) {
|
||||||
sframeChan.query('Q_RT_MESSAGE', message, function (ret) {
|
sframeChan.query('Q_RT_MESSAGE', message, cb);
|
||||||
if (ret === 'OK') { cb(); }
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
chainpad.onPatch(function () {
|
chainpad.onPatch(function () {
|
||||||
onRemote({ realtime: chainpad });
|
onRemote({ realtime: chainpad });
|
||||||
|
|||||||
@@ -155,13 +155,14 @@ define([], function () {
|
|||||||
// want to keep the same chainpad (realtime) object
|
// want to keep the same chainpad (realtime) object
|
||||||
try {
|
try {
|
||||||
wcObject.wc.bcast(message).then(function() {
|
wcObject.wc.bcast(message).then(function() {
|
||||||
cb('OK');
|
cb();
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
// The message has not been sent, display the error.
|
// The message has not been sent, display the error.
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} 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) {
|
network.on('disconnect', function (reason) {
|
||||||
|
console.log('disconnect');
|
||||||
if (isIntentionallyLeaving) { return; }
|
if (isIntentionallyLeaving) { return; }
|
||||||
if (reason === "network.disconnect() called") { return; }
|
if (reason === "network.disconnect() called") { return; }
|
||||||
sframeChan.event('EV_RT_DISCONNECT');
|
sframeChan.event('EV_RT_DISCONNECT');
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ define([
|
|||||||
'/common/metadata-manager.js',
|
'/common/metadata-manager.js',
|
||||||
|
|
||||||
'/customize/application_config.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,
|
], function ($, nThen, Messages, CpNfInner, SFrameChannel, Title, UI, History, MetadataMgr,
|
||||||
AppConfig, Cryptpad) {
|
AppConfig, Cryptpad, CommonRealtime) {
|
||||||
|
|
||||||
// Chainpad Netflux Inner
|
// Chainpad Netflux Inner
|
||||||
var funcs = {};
|
var funcs = {};
|
||||||
@@ -292,6 +293,10 @@ define([
|
|||||||
if (titleUpdated) { titleUpdated(undefined, title); }
|
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);
|
cb(funcs);
|
||||||
});
|
});
|
||||||
} };
|
} };
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ define([
|
|||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
'/common/sframe-common.js',
|
'/common/sframe-common.js',
|
||||||
'/api/config',
|
'/api/config',
|
||||||
|
'/common/common-realtime.js',
|
||||||
|
|
||||||
'/bower_components/file-saver/FileSaver.min.js',
|
'/bower_components/file-saver/FileSaver.min.js',
|
||||||
'/bower_components/diff-dom/diffDOM.js',
|
'/bower_components/diff-dom/diffDOM.js',
|
||||||
@@ -41,8 +42,24 @@ define([
|
|||||||
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||||
'less!/customize/src/less/cryptpad.less',
|
'less!/customize/src/less/cryptpad.less',
|
||||||
'less!/customize/src/less/toolbar.less'
|
'less!/customize/src/less/toolbar.less'
|
||||||
], function ($, Crypto, Hyperjson,
|
], function (
|
||||||
Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher, Cryptpad, Cryptget, Links, nThen, SFCommon, ApiConfig) {
|
$,
|
||||||
|
Crypto,
|
||||||
|
Hyperjson,
|
||||||
|
Toolbar,
|
||||||
|
Cursor,
|
||||||
|
JsonOT,
|
||||||
|
TypingTest,
|
||||||
|
JSONSortify,
|
||||||
|
TextPatcher,
|
||||||
|
Cryptpad,
|
||||||
|
Cryptget,
|
||||||
|
Links,
|
||||||
|
nThen,
|
||||||
|
SFCommon,
|
||||||
|
ApiConfig,
|
||||||
|
CommonRealtime)
|
||||||
|
{
|
||||||
var saveAs = window.saveAs;
|
var saveAs = window.saveAs;
|
||||||
var Messages = Cryptpad.Messages;
|
var Messages = Cryptpad.Messages;
|
||||||
var DiffDom = window.diffDOM;
|
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
|
// don't let the user edit until the pad is ready
|
||||||
setEditable(false);
|
setEditable(false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user