Merge branch 'reconnect' into staging

This commit is contained in:
yflory
2020-03-26 15:24:38 +01:00
6 changed files with 64 additions and 28 deletions

View File

@@ -1499,6 +1499,13 @@ define([
return;
}
var onError = function (err) {
channel.bcast("PAD_ERROR", err);
// If this is a DELETED, EXPIRED or RESTRICTED pad, leave the channel
if (["EDELETED", "EEXPIRED", "ERESTRICTED"].indexOf(err.type) === -1) { return; }
Store.leavePad(null, data, function () {});
};
var conf = {
onReady: function (pad) {
var padData = pad.metadata || {};
@@ -1522,14 +1529,8 @@ define([
onLeave: function (m) {
channel.bcast("PAD_LEAVE", m);
},
onError: function (err) {
channel.bcast("PAD_ERROR", err);
Store.leavePad(null, data, function () {});
},
onChannelError: function (err) {
channel.bcast("PAD_ERROR", err);
Store.leavePad(null, data, function () {});
},
onError: onError,
onChannelError: onError,
onRejected: function (allowed, _cb) {
var cb = Util.once(Util.mkAsync(_cb));

View File

@@ -325,6 +325,11 @@ define([
UI.updateLoadingProgress({ state: -1 }, false);
if (toolbar) {
// Check if we have a new chainpad instance
toolbar.resetChainpad(cpNfInner.chainpad);
}
var newPad = false;
if (newContentStr === '') { newPad = true; }
@@ -364,6 +369,9 @@ define([
}).nThen(function () {
stateChange(STATE.READY);
firstConnection = false;
oldContent = undefined;
if (!readOnly) { onLocal(); }
evOnReady.fire(newPad);

View File

@@ -49,24 +49,29 @@ define([
config = undefined;
var evPatchSent = Util.mkEvent();
var chainpad;
var chainpad = ChainPad.create({
userName: userName,
initialState: initialState,
patchTransformer: patchTransformer,
validateContent: validateContent,
avgSyncMilliseconds: avgSyncMilliseconds,
logLevel: logLevel
});
chainpad.onMessage(function(message, cb) {
sframeChan.query('Q_RT_MESSAGE', message, function (err) {
if (!err) { evPatchSent.fire(); }
cb(err);
var makeChainPad = function () {
var _chainpad = ChainPad.create({
userName: userName,
initialState: initialState,
patchTransformer: patchTransformer,
validateContent: validateContent,
avgSyncMilliseconds: avgSyncMilliseconds,
logLevel: logLevel
});
});
chainpad.onPatch(function () {
onRemote({ realtime: chainpad });
});
_chainpad.onMessage(function(message, cb) {
sframeChan.query('Q_RT_MESSAGE', message, function (err) {
if (!err) { evPatchSent.fire(); }
cb(err);
});
});
_chainpad.onPatch(function () {
onRemote({ realtime: chainpad });
});
return _chainpad;
};
chainpad = makeChainPad();
var myID;
var isReady = false;
@@ -96,6 +101,11 @@ define([
sframeChan.on('EV_RT_ERROR', function (err) {
isReady = false;
chainpad.abort();
if (err.type === 'EUNKNOWN') { // XXX
// Recoverable error: make a new chainpad
chainpad = makeChainPad();
return;
}
onError(err);
});
sframeChan.on('EV_RT_CONNECT', function (content) {
@@ -149,15 +159,18 @@ define([
});
};
return Object.freeze({
var cpNfInner = {
getMyID: function () { return myID; },
metadataMgr: metadataMgr,
whenRealtimeSyncs: whenRealtimeSyncs,
onInfiniteSpinner: evInfiniteSpinner.reg,
onPatchSent: evPatchSent.reg,
offPatchSent: evPatchSent.unreg,
chainpad: chainpad,
};
cpNfInner.__defineGetter__("chainpad", function () {
return chainpad;
});
return Object.freeze(cpNfInner);
};
return Object.freeze(module.exports);
});

View File

@@ -1331,6 +1331,15 @@ MessengerUI, Messages) {
showColors = true;
};
// If we had to create a new chainpad instance, reset the one used in the toolbar
toolbar.resetChainpad = function (chainpad) {
if (config.realtime !== chainpad) {
config.realtime = chainpad;
config.realtime.onPatch(ks(toolbar, config));
config.realtime.onMessage(ks(toolbar, config, true));
}
};
// On log out, remove permanently the realtime elements of the toolbar
Common.onLogout(function () {
failed();