|
|
@ -64,8 +64,11 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var bindAllEvents = function (textarea, docBody, onEvent, unbind)
|
|
|
|
var bindAllEvents = function (textarea, docBody, onEvent, unbind)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// FIXME why docBody?
|
|
|
|
/*
|
|
|
|
|
|
|
|
we use docBody for the purposes of CKEditor.
|
|
|
|
|
|
|
|
because otherwise special keybindings like ctrl-b and ctrl-i
|
|
|
|
|
|
|
|
would open bookmarks and info instead of applying bold/italic styles
|
|
|
|
|
|
|
|
*/
|
|
|
|
docBody && bindEvents(docBody,
|
|
|
|
docBody && bindEvents(docBody,
|
|
|
|
['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste'],
|
|
|
|
['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste'],
|
|
|
|
onEvent,
|
|
|
|
onEvent,
|
|
|
@ -133,17 +136,20 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var start = module.exports.start =
|
|
|
|
var start = module.exports.start =
|
|
|
|
function (textarea, websocketUrl, userName, channel, cryptKey, doc, onRemote)
|
|
|
|
function (textarea, websocketUrl, userName, channel, cryptKey, config)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var passwd = 'y';
|
|
|
|
var passwd = 'y';
|
|
|
|
|
|
|
|
|
|
|
|
console.log({
|
|
|
|
// make sure configuration is defined
|
|
|
|
textarea: textarea,
|
|
|
|
config = config || {};
|
|
|
|
websocketUrl: websocketUrl,
|
|
|
|
|
|
|
|
userName: userName,
|
|
|
|
var doc = config.doc || null;
|
|
|
|
channel: channel,
|
|
|
|
|
|
|
|
cryptKey: cryptKey
|
|
|
|
// trying to deprecate onRemote, prefer loading it via the conf
|
|
|
|
});
|
|
|
|
onRemote = config.onRemote || onRemote;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transformFunction = config.transformFunction || null;
|
|
|
|
|
|
|
|
|
|
|
|
var socket = makeWebsocket(websocketUrl);
|
|
|
|
var socket = makeWebsocket(websocketUrl);
|
|
|
|
// define this in case it gets called before the rest of our stuff is ready.
|
|
|
|
// define this in case it gets called before the rest of our stuff is ready.
|
|
|
@ -156,12 +162,6 @@ 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) {
|
|
|
@ -176,24 +176,11 @@ define([
|
|
|
|
channel,
|
|
|
|
channel,
|
|
|
|
$(textarea).val(),
|
|
|
|
$(textarea).val(),
|
|
|
|
{
|
|
|
|
{
|
|
|
|
transformFunction: function (text, toTransform, transformBy) {
|
|
|
|
transformFunction: config.transformFunction
|
|
|
|
console.log({
|
|
|
|
|
|
|
|
text: text,
|
|
|
|
|
|
|
|
toTransform: toTransform,
|
|
|
|
|
|
|
|
transformBy: transformBy
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returning **null** breaks out of the loop
|
|
|
|
|
|
|
|
// which transforms conflicting operations
|
|
|
|
|
|
|
|
// in theory this should prevent us from producing bad JSON
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onEvent = function () {
|
|
|
|
onEvent = function () {
|
|
|
|
if (isErrorState || initializing) { return; }
|
|
|
|
if (isErrorState || initializing) { return; }
|
|
|
|
/* var currentDoc = $textarea.val();
|
|
|
|
|
|
|
|
if (currentDoc !== realtime.getUserDoc()) { warn("currentDoc !== realtime.getUserDoc()"); } */
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
realtime.onUserListChange(function (userList) {
|
|
|
|
realtime.onUserListChange(function (userList) {
|
|
|
@ -202,14 +189,13 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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
|
|
|
|
|
|
|
|
initializing = false;
|
|
|
|
initializing = false;
|
|
|
|
debug("Done initializing:");
|
|
|
|
|
|
|
|
debug("Userlist: ["+userList.join(",")+"]");
|
|
|
|
|
|
|
|
/* TODO execute a callback here */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputDisabled(true);
|
|
|
|
// execute an onReady callback if one was supplied
|
|
|
|
|
|
|
|
// pass an object so we can extend this later
|
|
|
|
|
|
|
|
config.onReady && config.onReady({
|
|
|
|
|
|
|
|
userList: userList
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var whoami = new RegExp(userName.replace(/\/\+/g, function (c) {
|
|
|
|
var whoami = new RegExp(userName.replace(/\/\+/g, function (c) {
|
|
|
@ -274,7 +260,6 @@ define([
|
|
|
|
var socketChecker = setInterval(function () {
|
|
|
|
var socketChecker = setInterval(function () {
|
|
|
|
if (checkSocket(socket)) {
|
|
|
|
if (checkSocket(socket)) {
|
|
|
|
warn("Socket disconnected!");
|
|
|
|
warn("Socket disconnected!");
|
|
|
|
inputDisabled(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recoverableErrorCount += 1;
|
|
|
|
recoverableErrorCount += 1;
|
|
|
|
|
|
|
|
|
|
|
@ -284,7 +269,7 @@ define([
|
|
|
|
socketChecker && clearInterval(socketChecker);
|
|
|
|
socketChecker && clearInterval(socketChecker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
inputDisabled(false);
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},200);
|
|
|
|
},200);
|
|
|
|
|
|
|
|
|
|
|
@ -296,7 +281,6 @@ define([
|
|
|
|
realtime.start();
|
|
|
|
realtime.start();
|
|
|
|
debug('started');
|
|
|
|
debug('started');
|
|
|
|
|
|
|
|
|
|
|
|
// this has three names :|
|
|
|
|
|
|
|
|
bump = realtime.bumpSharejs;
|
|
|
|
bump = realtime.bumpSharejs;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|