minor patches that make things a bit more reliable, still some bugs
This commit is contained in:
parent
ac0f7852fc
commit
ed03a48092
@ -156,6 +156,12 @@ define([
|
|||||||
|
|
||||||
var $textarea = $(textarea);
|
var $textarea = $(textarea);
|
||||||
|
|
||||||
|
var inputDisabled = function (cond) {
|
||||||
|
$textarea.attr("disabled", cond||false);
|
||||||
|
};
|
||||||
|
|
||||||
|
inputDisabled(false);
|
||||||
|
|
||||||
var bump = function () {};
|
var bump = function () {};
|
||||||
|
|
||||||
socket.onOpen.push(function (evt) {
|
socket.onOpen.push(function (evt) {
|
||||||
@ -177,7 +183,7 @@ define([
|
|||||||
transformBy: transformBy
|
transformBy: transformBy
|
||||||
});
|
});
|
||||||
|
|
||||||
// returning false breaks out of the loop
|
// returning **null** breaks out of the loop
|
||||||
// which transforms conflicting operations
|
// which transforms conflicting operations
|
||||||
// in theory this should prevent us from producing bad JSON
|
// in theory this should prevent us from producing bad JSON
|
||||||
return null;
|
return null;
|
||||||
@ -191,16 +197,22 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
realtime.onUserListChange(function (userList) {
|
realtime.onUserListChange(function (userList) {
|
||||||
if (!initializing || userList.indexOf(userName) === -1) { return; }
|
if (!initializing || userList.indexOf(userName) === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// if we spot ourselves being added to the document, we'll switch
|
// if we spot ourselves being added to the document, we'll switch
|
||||||
// 'initializing' off because it means we're fully synced.
|
// 'initializing' off because it means we're fully synced.
|
||||||
|
|
||||||
// we should only see this happen once
|
// we should only see this happen once
|
||||||
initializing = false;
|
initializing = false;
|
||||||
|
debug("Done initializing:");
|
||||||
debug("Userlist: ["+userList.join(",")+"]");
|
debug("Userlist: ["+userList.join(",")+"]");
|
||||||
|
/* TODO execute a callback here */
|
||||||
|
|
||||||
|
inputDisabled(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
var whoami = new RegExp(userName.replace(/./, function (c) {
|
var whoami = new RegExp(userName.replace(/\/\+/g, function (c) {
|
||||||
return '\\' +c;
|
return '\\' +c;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -209,7 +221,6 @@ define([
|
|||||||
verbose(evt.data);
|
verbose(evt.data);
|
||||||
if (isErrorState) { return; }
|
if (isErrorState) { return; }
|
||||||
|
|
||||||
//console.log(evt);
|
|
||||||
var message = Crypto.decrypt(evt.data, cryptKey);
|
var message = Crypto.decrypt(evt.data, cryptKey);
|
||||||
verbose(message);
|
verbose(message);
|
||||||
allMessages.push(message);
|
allMessages.push(message);
|
||||||
@ -220,14 +231,19 @@ define([
|
|||||||
}
|
}
|
||||||
realtime.message(message);
|
realtime.message(message);
|
||||||
if (/\[5,/.test(message)) { verbose("pong"); }
|
if (/\[5,/.test(message)) { verbose("pong"); }
|
||||||
|
|
||||||
|
if (!initializing) {
|
||||||
if (/\[2,/.test(message)) {
|
if (/\[2,/.test(message)) {
|
||||||
verbose("Got a patch");
|
//verbose("Got a patch");
|
||||||
if (whoami.test(message)) {
|
if (whoami.test(message)) {
|
||||||
verbose("Received own message");
|
//verbose("Received own message");
|
||||||
} else {
|
} else {
|
||||||
|
//verbose("Received remote message");
|
||||||
|
// obviously this is only going to get called if
|
||||||
onRemote && onRemote(realtime.getAuthDoc());
|
onRemote && onRemote(realtime.getAuthDoc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// when a message is ready to send
|
// when a message is ready to send
|
||||||
@ -255,12 +271,10 @@ define([
|
|||||||
|
|
||||||
socket.onerror = warn;
|
socket.onerror = warn;
|
||||||
|
|
||||||
debug('started');
|
|
||||||
|
|
||||||
var socketChecker = setInterval(function () {
|
var socketChecker = setInterval(function () {
|
||||||
if (checkSocket(socket)) {
|
if (checkSocket(socket)) {
|
||||||
warn("Socket disconnected!");
|
warn("Socket disconnected!");
|
||||||
$textarea.attr('disabled', true);
|
inputDisabled(true);
|
||||||
|
|
||||||
recoverableErrorCount += 1;
|
recoverableErrorCount += 1;
|
||||||
|
|
||||||
@ -270,7 +284,7 @@ define([
|
|||||||
socketChecker && clearInterval(socketChecker);
|
socketChecker && clearInterval(socketChecker);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$textarea.attr('disabled', false);
|
inputDisabled(false);
|
||||||
}
|
}
|
||||||
},200);
|
},200);
|
||||||
|
|
||||||
@ -280,6 +294,7 @@ define([
|
|||||||
sharejs.attach(textarea, realtime);
|
sharejs.attach(textarea, realtime);
|
||||||
|
|
||||||
realtime.start();
|
realtime.start();
|
||||||
|
debug('started');
|
||||||
|
|
||||||
// this has three names :|
|
// this has three names :|
|
||||||
bump = realtime.bumpSharejs;
|
bump = realtime.bumpSharejs;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user