|
|
@ -15,11 +15,16 @@
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
|
|
|
|
'/common/common-util.js',
|
|
|
|
|
|
|
|
'/customize/application_config.js',
|
|
|
|
'/bower_components/chainpad/chainpad.dist.js'
|
|
|
|
'/bower_components/chainpad/chainpad.dist.js'
|
|
|
|
], function () {
|
|
|
|
], function (Util, AppConfig) {
|
|
|
|
var ChainPad = window.ChainPad;
|
|
|
|
var ChainPad = window.ChainPad;
|
|
|
|
var module = { exports: {} };
|
|
|
|
var module = { exports: {} };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var badStateTimeout = typeof(AppConfig.badStateTimeout) === 'number' ?
|
|
|
|
|
|
|
|
AppConfig.badStateTimeout : 30000;
|
|
|
|
|
|
|
|
|
|
|
|
var verbose = function (x) { console.log(x); };
|
|
|
|
var verbose = function (x) { console.log(x); };
|
|
|
|
verbose = function () {}; // comment out to enable verbose logging
|
|
|
|
verbose = function () {}; // comment out to enable verbose logging
|
|
|
|
|
|
|
|
|
|
|
@ -44,9 +49,25 @@ define([
|
|
|
|
var chainpad;
|
|
|
|
var chainpad;
|
|
|
|
var myID;
|
|
|
|
var myID;
|
|
|
|
var isReady = false;
|
|
|
|
var isReady = false;
|
|
|
|
|
|
|
|
var evConnected = Util.mkEvent(true);
|
|
|
|
|
|
|
|
var evInfiniteSpinner = Util.mkEvent(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.setInterval(function () {
|
|
|
|
|
|
|
|
if (!chainpad || !myID) { return; }
|
|
|
|
|
|
|
|
var l;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
l = chainpad.getLag();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
throw new Error("ChainPad.getLag() does not exist, please `bower update`");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l.lag < badStateTimeout) { return; }
|
|
|
|
|
|
|
|
chainpad.abort();
|
|
|
|
|
|
|
|
evInfiniteSpinner.fire();
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('EV_RT_DISCONNECT', function () {
|
|
|
|
sframeChan.on('EV_RT_DISCONNECT', function () {
|
|
|
|
isReady = false;
|
|
|
|
isReady = false;
|
|
|
|
|
|
|
|
if (chainpad) { chainpad.abort(); }
|
|
|
|
onConnectionChange({ state: false });
|
|
|
|
onConnectionChange({ state: false });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
sframeChan.on('EV_RT_CONNECT', function (content) {
|
|
|
|
sframeChan.on('EV_RT_CONNECT', function (content) {
|
|
|
@ -55,6 +76,7 @@ define([
|
|
|
|
isReady = false;
|
|
|
|
isReady = false;
|
|
|
|
if (chainpad) {
|
|
|
|
if (chainpad) {
|
|
|
|
// it's a reconnect
|
|
|
|
// it's a reconnect
|
|
|
|
|
|
|
|
if (chainpad) { chainpad.start(); }
|
|
|
|
onConnectionChange({ state: true, myId: myID });
|
|
|
|
onConnectionChange({ state: true, myId: myID });
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,6 +99,7 @@ define([
|
|
|
|
realtime: chainpad,
|
|
|
|
realtime: chainpad,
|
|
|
|
readOnly: readOnly
|
|
|
|
readOnly: readOnly
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
evConnected.fire();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
sframeChan.on('Q_RT_MESSAGE', function (content, cb) {
|
|
|
|
sframeChan.on('Q_RT_MESSAGE', function (content, cb) {
|
|
|
|
if (isReady) {
|
|
|
|
if (isReady) {
|
|
|
@ -92,9 +115,22 @@ define([
|
|
|
|
setMyID({ myID: myID });
|
|
|
|
setMyID({ myID: myID });
|
|
|
|
onReady({ realtime: chainpad });
|
|
|
|
onReady({ realtime: chainpad });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var whenRealtimeSyncs = function (cb) {
|
|
|
|
|
|
|
|
evConnected.reg(function () {
|
|
|
|
|
|
|
|
if (chainpad.getAuthDoc() === chainpad.getUserDoc()) {
|
|
|
|
|
|
|
|
return void cb();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
chainpad.onSettle(cb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Object.freeze({
|
|
|
|
return Object.freeze({
|
|
|
|
getMyID: function () { return myID; },
|
|
|
|
getMyID: function () { return myID; },
|
|
|
|
metadataMgr: metadataMgr
|
|
|
|
metadataMgr: metadataMgr,
|
|
|
|
|
|
|
|
whenRealtimeSyncs: whenRealtimeSyncs,
|
|
|
|
|
|
|
|
onInfiniteSpinner: evInfiniteSpinner.reg
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return Object.freeze(module.exports);
|
|
|
|
return Object.freeze(module.exports);
|
|
|
|