more testing and crap
This commit is contained in:
parent
4b35a145e3
commit
420a7098a6
@ -37,6 +37,25 @@ define([
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var setRandomizedInterval = function (func, target, range) {
|
||||||
|
var timeout;
|
||||||
|
var again = function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
again();
|
||||||
|
func();
|
||||||
|
}, target - (range / 2) + Math.random() * range);
|
||||||
|
};
|
||||||
|
again();
|
||||||
|
return {
|
||||||
|
cancel: function () {
|
||||||
|
if (timeout) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var andThen = function (Ckeditor) {
|
var andThen = function (Ckeditor) {
|
||||||
$(window).on('hashchange', function() {
|
$(window).on('hashchange', function() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@ -149,20 +168,22 @@ define([
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var now = function () { return new Date().getTime() };
|
||||||
|
|
||||||
|
var DD = new DiffDom(diffOptions);
|
||||||
// apply patches, and try not to lose the cursor in the process!
|
// apply patches, and try not to lose the cursor in the process!
|
||||||
var applyHjson = function (shjson) {
|
var applyHjson = function (shjson) {
|
||||||
setEditable(false);
|
//setEditable(false);
|
||||||
|
console.log(now());
|
||||||
var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
|
var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
|
||||||
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
|
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
|
||||||
var DD = new DiffDom(diffOptions);
|
console.log(now());
|
||||||
|
|
||||||
//assertStateMatches();
|
//assertStateMatches();
|
||||||
|
|
||||||
var patch = (DD).diff(inner, userDocStateDom);
|
var patch = (DD).diff(inner, userDocStateDom);
|
||||||
(DD).apply(inner, patch);
|
(DD).apply(inner, patch);
|
||||||
|
console.log(now());
|
||||||
// push back to the textarea so we get a userDocState
|
// push back to the textarea so we get a userDocState
|
||||||
setEditable(true);
|
//setEditable(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onRemote = function (info) {
|
var onRemote = function (info) {
|
||||||
@ -238,11 +259,11 @@ define([
|
|||||||
|
|
||||||
var rti = module.realtimeInput = window.rti = realtimeInput.start(realtimeOptions);
|
var rti = module.realtimeInput = window.rti = realtimeInput.start(realtimeOptions);
|
||||||
|
|
||||||
var propogate = function () {
|
var propogate = window.cryptpad_propogate = function () {
|
||||||
var hjson = Convert.core.hyperjson.fromDOM(inner, isNotMagicLine);
|
var hjson = Convert.core.hyperjson.fromDOM(inner, isNotMagicLine);
|
||||||
var shjson = JSON.stringify(hjson);
|
var shjson = JSON.stringify(hjson);
|
||||||
|
|
||||||
rti.propogate(shjson);
|
if (!rti.propogate(shjson)) { return; }
|
||||||
rti.onEvent(shjson);
|
rti.onEvent(shjson);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -255,10 +276,10 @@ define([
|
|||||||
max_errors = 15,
|
max_errors = 15,
|
||||||
interval;
|
interval;
|
||||||
var cancel = function () {
|
var cancel = function () {
|
||||||
if (interval) { window.clearInterval(interval); }
|
//if (interval) { interval.cancel(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
interval = window.setInterval(function () {
|
interval = setRandomizedInterval(function () {
|
||||||
propogate();
|
propogate();
|
||||||
try {
|
try {
|
||||||
el.replaceData(j, 0, input.charAt(i));
|
el.replaceData(j, 0, input.charAt(i));
|
||||||
@ -270,14 +291,14 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.error(err);
|
console.error(err);
|
||||||
var next = document.createTextNode("");
|
var next = document.createTextNode("-");
|
||||||
el.parentNode.appendChild(next);
|
window.inner.appendChild(next);
|
||||||
el = next;
|
el = next;
|
||||||
j = 0;
|
j = -1;
|
||||||
}
|
}
|
||||||
i = (i + 1) % l;
|
i = (i + 1) % l;
|
||||||
j++;
|
j++;
|
||||||
}, 200);
|
}, 200, 50);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cancel: cancel
|
cancel: cancel
|
||||||
|
|||||||
@ -52,7 +52,7 @@ define([
|
|||||||
|
|
||||||
// ------------------ Trapping Keyboard Events ---------------------- //
|
// ------------------ Trapping Keyboard Events ---------------------- //
|
||||||
|
|
||||||
var bindEvents = function (element, events, callback, unbind) {
|
var _unused_bindEvents = function (element, events, callback, unbind) {
|
||||||
for (var i = 0; i < events.length; i++) {
|
for (var i = 0; i < events.length; i++) {
|
||||||
var e = events[i];
|
var e = events[i];
|
||||||
if (element.addEventListener) {
|
if (element.addEventListener) {
|
||||||
@ -71,7 +71,7 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var bindAllEvents = function (textarea, docBody, onEvent, unbind)
|
var _unused_bindAllEvents = function (textarea, docBody, onEvent, unbind)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
we use docBody for the purposes of CKEditor.
|
we use docBody for the purposes of CKEditor.
|
||||||
@ -208,8 +208,10 @@ define([
|
|||||||
// assert things here...
|
// assert things here...
|
||||||
if (realtime.getUserDoc() !== newText) {
|
if (realtime.getUserDoc() !== newText) {
|
||||||
// this is a problem
|
// this is a problem
|
||||||
// warn("realtime.getUserDoc() !== newText");
|
warn("realtime.getUserDoc() !== newText");
|
||||||
}
|
}
|
||||||
|
//try{throw new Error();}catch(e){console.log(e.stack);}
|
||||||
|
console.log("2: " + realtime.Sha.hex_sha256(realtime.getUserDoc()));
|
||||||
};
|
};
|
||||||
|
|
||||||
// pass your shiny new realtime into initialization functions
|
// pass your shiny new realtime into initialization functions
|
||||||
@ -255,11 +257,14 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO improve this RegExp such that it allows for more names
|
realtime.onPatch(function () {
|
||||||
// right now it only handles names generated by rand64()
|
if (config.onRemote) {
|
||||||
var whoami = new RegExp(userName.replace(/[\/\+]/g, function (c) {
|
config.onRemote({
|
||||||
return '\\' +c;
|
realtime: realtime
|
||||||
}));
|
//realtime.getUserDoc()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// when you receive a message...
|
// when you receive a message...
|
||||||
socket.onMessage.push(function (evt) {
|
socket.onMessage.push(function (evt) {
|
||||||
@ -270,10 +275,11 @@ define([
|
|||||||
verbose(message);
|
verbose(message);
|
||||||
allMessages.push(message);
|
allMessages.push(message);
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
if (PARANOIA) {
|
|
||||||
// FIXME this is out of sync with the application logic
|
// FIXME this is out of sync with the application logic
|
||||||
onEvent();
|
console.log("xxx");
|
||||||
}
|
window.cryptpad_propogate();
|
||||||
|
} else {
|
||||||
|
console.log("init");
|
||||||
}
|
}
|
||||||
realtime.message(message);
|
realtime.message(message);
|
||||||
if (/\[5,/.test(message)) { verbose("pong"); }
|
if (/\[5,/.test(message)) { verbose("pong"); }
|
||||||
@ -281,16 +287,9 @@ define([
|
|||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
if (/\[2,/.test(message)) {
|
if (/\[2,/.test(message)) {
|
||||||
//verbose("Got a patch");
|
//verbose("Got a patch");
|
||||||
if (whoami.test(message)) {
|
|
||||||
//verbose("Received own message");
|
//TODO clean this all up
|
||||||
} else {
|
|
||||||
//verbose("Received remote message");
|
|
||||||
// obviously this is only going to get called if... XXX wat
|
|
||||||
if (config.onRemote) { config.onRemote({
|
|
||||||
realtime: realtime
|
|
||||||
//realtime.getUserDoc()
|
|
||||||
}); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -329,7 +328,7 @@ define([
|
|||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
// TODO maybe push this out to the application layer.
|
// TODO maybe push this out to the application layer.
|
||||||
bindAllEvents(null, doc, onEvent, false);
|
//bindAllEvents(null, doc, onEvent, false);
|
||||||
|
|
||||||
// TODO rename 'sharejs.attach' to imply what we want to do
|
// TODO rename 'sharejs.attach' to imply what we want to do
|
||||||
var genOp = toReturn.propogate = sharejs.attach({
|
var genOp = toReturn.propogate = sharejs.attach({
|
||||||
|
|||||||
@ -52,21 +52,22 @@ var attachTextarea = function(config) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// *** remote -> local changes
|
// *** remote -> local changes
|
||||||
ctx.onRemove(function(pos, length) {
|
ctx.onPatch(function(pos, length) {
|
||||||
replaceText(ctx.getUserDoc());
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.onInsert(function(pos, text) {
|
|
||||||
replaceText(ctx.getUserDoc());
|
replaceText(ctx.getUserDoc());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// propogate()
|
||||||
return function (newContent) {
|
return function (newContent) {
|
||||||
if (newContent !== content) {
|
if (newContent !== content) {
|
||||||
applyChange(ctx, ctx.getUserDoc(), newContent);
|
applyChange(ctx, ctx.getUserDoc(), newContent);
|
||||||
if (ctx.getUserDoc() !== newContent) {
|
if (ctx.getUserDoc() !== newContent) {
|
||||||
console.log("Expected that: `ctx.getUserDoc() === newContent`!");
|
console.log("Expected that: `ctx.getUserDoc() === newContent`!");
|
||||||
}
|
}
|
||||||
|
console.log("1: " + ctx.Sha.hex_sha256(ctx.getUserDoc()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
console.log("no change");
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1163,6 +1163,7 @@ module.exports.create = function (userName, authToken, channelId, initialState,
|
|||||||
Common.assert(typeof(initialState) === 'string');
|
Common.assert(typeof(initialState) === 'string');
|
||||||
var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf);
|
var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf);
|
||||||
return {
|
return {
|
||||||
|
Sha: Sha,
|
||||||
onPatch: enterChainPad(realtime, function (handler) {
|
onPatch: enterChainPad(realtime, function (handler) {
|
||||||
Common.assert(typeof(handler) === 'function');
|
Common.assert(typeof(handler) === 'function');
|
||||||
realtime.patchHandlers.push(handler);
|
realtime.patchHandlers.push(handler);
|
||||||
|
|||||||
@ -327,10 +327,11 @@ console.log(new Error().stack);
|
|||||||
error(false, 'realtime.getUserDoc() !== docText');
|
error(false, 'realtime.getUserDoc() !== docText');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var now = function () { return new Date().getTime(); };
|
||||||
var userDocBeforePatch;
|
var userDocBeforePatch;
|
||||||
var incomingPatch = function () {
|
var incomingPatch = function () {
|
||||||
if (isErrorState || initializing) { return; }
|
if (isErrorState || initializing) { return; }
|
||||||
|
console.log("before patch " + now());
|
||||||
userDocBeforePatch = userDocBeforePatch || getFixedDocText(doc, ifr.contentWindow);
|
userDocBeforePatch = userDocBeforePatch || getFixedDocText(doc, ifr.contentWindow);
|
||||||
if (PARANOIA && userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)) {
|
if (PARANOIA && userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)) {
|
||||||
error(false, "userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)");
|
error(false, "userDocBeforePatch !== getFixedDocText(doc, ifr.contentWindow)");
|
||||||
@ -339,6 +340,7 @@ console.log(new Error().stack);
|
|||||||
if (!op) { return; }
|
if (!op) { return; }
|
||||||
attempt(HTMLPatcher.applyOp)(
|
attempt(HTMLPatcher.applyOp)(
|
||||||
userDocBeforePatch, op, doc.body, Rangy, ifr.contentWindow);
|
userDocBeforePatch, op, doc.body, Rangy, ifr.contentWindow);
|
||||||
|
console.log("after patch " + now());
|
||||||
};
|
};
|
||||||
|
|
||||||
realtime.onUserListChange(function (userList) {
|
realtime.onUserListChange(function (userList) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user