diff --git a/bower.json b/bower.json index 19b2e8ca0..56205905c 100644 --- a/bower.json +++ b/bower.json @@ -32,6 +32,7 @@ "hyperjson": "~1.2.2", "textpatcher": "^1.2.0", "proxy-polyfill": "^0.1.5", - "chainpad": "^0.2.2" + "chainpad": "^0.2.2", + "chainpad-json-validator": "^0.1.1" } } diff --git a/www/canvas/main.js b/www/canvas/main.js index 5564d95f1..64a782120 100644 --- a/www/canvas/main.js +++ b/www/canvas/main.js @@ -9,7 +9,7 @@ define([ '/common/crypto.js', '/bower_components/textpatcher/TextPatcher.amd.js', 'json.sortify', - '/common/json-ot.js', + '/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/fabric.js/dist/fabric.min.js', '/bower_components/jquery/dist/jquery.min.js', '/customize/pad.js' diff --git a/www/common/chainpad-listmap.js b/www/common/chainpad-listmap.js index b1c502207..fe0c1b1ec 100644 --- a/www/common/chainpad-listmap.js +++ b/www/common/chainpad-listmap.js @@ -3,7 +3,7 @@ define([ '/api/config?cb=' + Math.random().toString(16).substring(2), '/common/crypto.js', '/common/realtime-input.js', - '/common/json-ot.js', + '/bower_components/chainpad-json-validator/json-ot.js', 'json.sortify', '/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/jquery/dist/jquery.min.js', diff --git a/www/common/json-ot.js b/www/common/json-ot.js deleted file mode 100644 index f04cf3b75..000000000 --- a/www/common/json-ot.js +++ /dev/null @@ -1,68 +0,0 @@ -define([ - '/common/realtime-input.js' -], function () { - var ChainPad = window.ChainPad; - var JsonOT = {}; - - var validate = JsonOT.validate = function (text, toTransform, transformBy) { - var DEBUG = window.REALTIME_DEBUG = window.REALTIME_DEBUG || {}; - - var resultOp, text2, text3; - try { - // text = O (mutual common ancestor) - // toTransform = A (the first incoming operation) - // transformBy = B (the second incoming operation) - // threeway merge (0, A, B) - - resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy); - - /* if after operational transform we find that no op is necessary - return null to ignore this patch */ - if (!resultOp) { return null; } - - text2 = ChainPad.Operation.apply(transformBy, text); - text3 = ChainPad.Operation.apply(resultOp, text2); - try { - JSON.parse(text3); - return resultOp; - } catch (e) { - console.error(e); - var info = DEBUG.ot_parseError = { - type: 'resultParseError', - resultOp: resultOp, - - toTransform: toTransform, - transformBy: transformBy, - - text1: text, - text2: text2, - text3: text3, - error: e - }; - console.log('Debugging info available at `window.REALTIME_DEBUG.ot_parseError`'); - } - } catch (x) { - console.error(x); - window.DEBUG.ot_applyError = { - type: 'resultParseError', - resultOp: resultOp, - - toTransform: toTransform, - transformBy: transformBy, - - text1: text, - text2: text2, - text3: text3, - error: x - }; - console.log('Debugging info available at `window.REALTIME_DEBUG.ot_applyError`'); - } - - // returning **null** breaks out of the loop - // which transforms conflicting operations - // in theory this should prevent us from producing bad JSON - return null; - }; - - return JsonOT; -}); diff --git a/www/pad/main.js b/www/pad/main.js index 5f6cfa0c8..e22d439a4 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -8,7 +8,7 @@ define([ '/common/hyperscript.js', '/common/toolbar.js', '/common/cursor.js', - '/common/json-ot.js', + '/bower_components/chainpad-json-validator/json-ot.js', '/common/TypingTests.js', 'json.sortify', '/bower_components/textpatcher/TextPatcher.amd.js',