Merge branch 'netflux' of github.com:xwiki-labs/cryptpad into integrate
This commit is contained in:
commit
822b2bd2b9
@ -33,7 +33,7 @@ define(function () {
|
|||||||
interval = setRandomizedInterval(function () {
|
interval = setRandomizedInterval(function () {
|
||||||
cb();
|
cb();
|
||||||
try {
|
try {
|
||||||
el.replaceData(j, 0, input.charAt(i));
|
el.replaceData(Math.min(j, el.length), 0, input.charAt(i));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors++;
|
errors++;
|
||||||
if (errors >= max_errors) {
|
if (errors >= max_errors) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ define(() => {
|
|||||||
const MAX_LAG_BEFORE_PING = 15000;
|
const MAX_LAG_BEFORE_PING = 15000;
|
||||||
const MAX_LAG_BEFORE_DISCONNECT = 30000;
|
const MAX_LAG_BEFORE_DISCONNECT = 30000;
|
||||||
const PING_CYCLE = 5000;
|
const PING_CYCLE = 5000;
|
||||||
const REQUEST_TIMEOUT = 5000;
|
const REQUEST_TIMEOUT = 30000;
|
||||||
|
|
||||||
const now = () => new Date().getTime();
|
const now = () => new Date().getTime();
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ const onMessage = (ctx, evt) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg[2] === 'PING') {
|
if (msg[2] === 'PING') {
|
||||||
msg[1] = 'PONG';
|
msg[2] = 'PONG';
|
||||||
ctx.ws.send(JSON.stringify(msg));
|
ctx.ws.send(JSON.stringify(msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ const connect = (websocketURL) => {
|
|||||||
const req = ctx.requests[id];
|
const req = ctx.requests[id];
|
||||||
if (now() - req.time > REQUEST_TIMEOUT) {
|
if (now() - req.time > REQUEST_TIMEOUT) {
|
||||||
delete ctx.requests[id];
|
delete ctx.requests[id];
|
||||||
req.reject({ type: 'TIMEOUT', message: 'waited ' + now() - req.time + 'ms' });
|
if(typeof req.reject === "function") { req.reject({ type: 'TIMEOUT', message: 'waited ' + now() - req.time + 'ms' }); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|||||||
@ -14,17 +14,15 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
window.Reflect = { has: function (x,y) { return (y in x); } };
|
|
||||||
define([
|
define([
|
||||||
'/common/messages.js',
|
'/common/messages.js',
|
||||||
'/common/netflux-client.js',
|
'/common/netflux-client.js',
|
||||||
'/common/crypto.js',
|
'/common/crypto.js',
|
||||||
'/common/toolbar.js',
|
|
||||||
'/common/TextPatcher.js',
|
'/common/TextPatcher.js',
|
||||||
'/common/es6-promise.min.js',
|
'/common/es6-promise.min.js',
|
||||||
'/common/chainpad.js',
|
'/common/chainpad.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
], function (Messages, Netflux, Crypto, Toolbar, TextPatcher) {
|
], function (Messages, Netflux, Crypto, TextPatcher) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
var ChainPad = window.ChainPad;
|
var ChainPad = window.ChainPad;
|
||||||
var PARANOIA = true;
|
var PARANOIA = true;
|
||||||
@ -41,37 +39,6 @@ define([
|
|||||||
verbose = function (x) { console.log(x); };
|
verbose = function (x) { console.log(x); };
|
||||||
verbose = function () {}; // comment out to enable verbose logging
|
verbose = function () {}; // comment out to enable verbose logging
|
||||||
|
|
||||||
// ------------------ Trapping Keyboard Events ---------------------- //
|
|
||||||
|
|
||||||
var bindEvents = function (element, events, callback, unbind) {
|
|
||||||
for (var i = 0; i < events.length; i++) {
|
|
||||||
var e = events[i];
|
|
||||||
if (element.addEventListener) {
|
|
||||||
if (unbind) {
|
|
||||||
element.removeEventListener(e, callback, false);
|
|
||||||
} else {
|
|
||||||
element.addEventListener(e, callback, false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (unbind) {
|
|
||||||
element.detachEvent('on' + e, callback);
|
|
||||||
} else {
|
|
||||||
element.attachEvent('on' + e, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var getParameterByName = function (name, url) {
|
|
||||||
if (!url) { url = window.location.href; }
|
|
||||||
name = name.replace(/[\[\]]/g, "\\$&");
|
|
||||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
|
||||||
results = regex.exec(url);
|
|
||||||
if (!results) { return null; }
|
|
||||||
if (!results[2]) { return ''; }
|
|
||||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
|
||||||
};
|
|
||||||
|
|
||||||
var start = module.exports.start =
|
var start = module.exports.start =
|
||||||
function (config)
|
function (config)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -32,7 +32,8 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var module = window.REALTIME_MODULE = {
|
var module = window.REALTIME_MODULE = {
|
||||||
localChangeInProgress: 0
|
Hyperjson: Hyperjson,
|
||||||
|
Hyperscript: Hyperscript
|
||||||
};
|
};
|
||||||
|
|
||||||
var userName = Crypto.rand64(8),
|
var userName = Crypto.rand64(8),
|
||||||
@ -104,8 +105,7 @@ define([
|
|||||||
var cursor = window.cursor = Cursor(inner);
|
var cursor = window.cursor = Cursor(inner);
|
||||||
|
|
||||||
var setEditable = function (bool) {
|
var setEditable = function (bool) {
|
||||||
inner.setAttribute('contenteditable',
|
inner.setAttribute('contenteditable', bool);
|
||||||
(typeof (bool) !== 'undefined'? bool : true));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't let the user edit until the pad is ready
|
// don't let the user edit until the pad is ready
|
||||||
@ -113,25 +113,53 @@ define([
|
|||||||
|
|
||||||
var diffOptions = {
|
var diffOptions = {
|
||||||
preDiffApply: function (info) {
|
preDiffApply: function (info) {
|
||||||
/* Don't remove local instances of the magicline plugin */
|
/* DiffDOM will filter out magicline plugin elements
|
||||||
|
in practice this will make it impossible to use it
|
||||||
|
while someone else is typing, which could be annoying.
|
||||||
|
|
||||||
|
we should check when such an element is going to be
|
||||||
|
removed, and prevent that from happening. */
|
||||||
if (info.node && info.node.tagName === 'SPAN' &&
|
if (info.node && info.node.tagName === 'SPAN' &&
|
||||||
info.node.getAttribute('contentEditable') === 'false') {
|
info.node.getAttribute('contentEditable') === "false") {
|
||||||
return true;
|
// it seems to be a magicline plugin element...
|
||||||
|
if (info.diff.action === 'removeElement') {
|
||||||
|
// and you're about to remove it...
|
||||||
|
// this probably isn't what you want
|
||||||
|
|
||||||
|
/*
|
||||||
|
I have never seen this in the console, but the
|
||||||
|
magic line is still getting removed on remote
|
||||||
|
edits. This suggests that it's getting removed
|
||||||
|
by something other than diffDom.
|
||||||
|
*/
|
||||||
|
console.log("preventing removal of the magic line!");
|
||||||
|
|
||||||
|
// return true to prevent diff application
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// no use trying to recover the cursor if it doesn't exist
|
||||||
if (!cursor.exists()) { return; }
|
if (!cursor.exists()) { return; }
|
||||||
|
|
||||||
|
/* frame is either 0, 1, 2, or 3, depending on which
|
||||||
|
cursor frames were affected: none, first, last, or both
|
||||||
|
*/
|
||||||
var frame = info.frame = cursor.inNode(info.node);
|
var frame = info.frame = cursor.inNode(info.node);
|
||||||
|
|
||||||
if (!frame) { return; }
|
if (!frame) { return; }
|
||||||
if (typeof info.diff.oldValue === 'string' &&
|
|
||||||
typeof info.diff.newValue === 'string') {
|
if (typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
||||||
var pushes = cursor.pushDelta(info.diff.oldValue,
|
var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
|
||||||
info.diff.newValue);
|
|
||||||
if (frame & 1) {
|
if (frame & 1) {
|
||||||
|
// push cursor start if necessary
|
||||||
if (pushes.commonStart < cursor.Range.start.offset) {
|
if (pushes.commonStart < cursor.Range.start.offset) {
|
||||||
cursor.Range.start.offset += pushes.delta;
|
cursor.Range.start.offset += pushes.delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (frame & 2) {
|
if (frame & 2) {
|
||||||
|
// push cursor end if necessary
|
||||||
if (pushes.commonStart < cursor.Range.end.offset) {
|
if (pushes.commonStart < cursor.Range.end.offset) {
|
||||||
cursor.Range.end.offset += pushes.delta;
|
cursor.Range.end.offset += pushes.delta;
|
||||||
}
|
}
|
||||||
@ -143,7 +171,7 @@ define([
|
|||||||
if (info.node) {
|
if (info.node) {
|
||||||
if (info.frame & 1) { cursor.fixStart(info.node); }
|
if (info.frame & 1) { cursor.fixStart(info.node); }
|
||||||
if (info.frame & 2) { cursor.fixEnd(info.node); }
|
if (info.frame & 2) { cursor.fixEnd(info.node); }
|
||||||
} else { console.log("info.node did not exist"); }
|
} else { console.error("info.node did not exist"); }
|
||||||
|
|
||||||
var sel = cursor.makeSelection();
|
var sel = cursor.makeSelection();
|
||||||
var range = cursor.makeRange();
|
var range = cursor.makeRange();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user