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