From b2f3b566c0c0edd41b0314fcbf516a3d7876e14b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 29 Jan 2023 17:54:14 +0100 Subject: Fix concurrent edit, tests --- html/whiteboard.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'html/whiteboard.js') 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("", "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); -- cgit v1.2.3