diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-29 17:54:14 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-29 17:54:14 +0100 |
commit | b2f3b566c0c0edd41b0314fcbf516a3d7876e14b (patch) | |
tree | 1cebf349b746ae606354733e9464581d530fb5e7 /html | |
parent | 32b5b50dacb1bfc02a0baef0eda47df8d5f2be37 (diff) |
Fix concurrent edit, tests
Diffstat (limited to 'html')
-rw-r--r-- | html/whiteboard.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/html/whiteboard.js b/html/whiteboard.js index a6dc089..b11dc96 100644 --- a/html/whiteboard.js +++ b/html/whiteboard.js @@ -4,6 +4,7 @@ function init() { } var revision; +var modify_in_progress = 0; var baseline = ""; // data contents relating to revision, acknowledged by server var baseline_candidate = ""; // will become baseline, after ack by server @@ -51,7 +52,7 @@ function on_getfile(data, rev, pos) function on_getdiff(diff, rev, pos) { if (rev != revision + 1) - alert("Revision skipped: " + rev + " after " + revision); + console.log("Revision skipped on diff receive: " + rev + " after " + revision); var board = document.getElementById("board"); @@ -95,8 +96,12 @@ function on_version(version) function on_modify_ack(rev) { + if (rev != revision + 1) + console.log("Revision skipped on published local change: " + rev + " after " + revision); + revision = rev; baseline = baseline_candidate; + modify_in_progress = 0; } function on_message(e) { @@ -228,6 +233,13 @@ function redirect_to_new_page() // local change done function on_input() { + if (modify_in_progress == 1) { + console.log("Deferring on_input handler by 100ms"); + setTimeout(function(){on_input();}, 100); // re-try after 100ms + return; + } + modify_in_progress = 1; + var parser = new DOMParser(); var xmlDocument = parser.parseFromString("<request></request>", "text/xml"); @@ -243,6 +255,11 @@ function on_input() baseline_candidate = document.getElementById("board").value; + if (baseline == baseline_candidate) { + modify_in_progress = 0; + return; + } + var revisionElement = xmlDocument.createElement("baserev"); revisionElement.appendChild(document.createTextNode(revision)); requestElement.appendChild(revisionElement); |