]> git.sesse.net Git - remoteglot/commitdiff
Add a primitive user-selectable delay, for matching up with TV. Requested by Sigurd...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Oct 2022 15:26:06 +0000 (17:26 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Oct 2022 15:26:06 +0000 (17:26 +0200)
www/js/remoteglot.js

index a03bad6a8d76e48a33bd9a3620c2950d4b798bc3..d98c90210d7c3e216a0f4d7dad813bc45f96ffb7 100644 (file)
@@ -127,6 +127,9 @@ var unique = null;
 /** @type {boolean} @private */
 var enable_sound = false;
 
+/** @type {!number} @private */
+var delay_ms = 0;
+
 /**
  * Our best estimate of how many milliseconds we need to add to 
  * new Date() to get the true UTC time. Calibrated against the
@@ -257,7 +260,11 @@ var request_update = function() {
        current_analysis_xhr = $.ajax({
                url: backend_url + "?ims=" + ims + "&unique=" + unique
        }).done(function(data, textstatus, xhr) {
-               process_update_response(data, textstatus, xhr);
+               if (delay_ms === 0) {
+                       process_update_response(data, textstatus, xhr);
+               } else {
+                       setTimeout(function() { process_update_response(data, textstatus, xhr); }, delay_ms);
+               }
 
                // Next update.
                if (!backend_url.match(/history/)) {
@@ -2298,6 +2305,7 @@ var switch_backend = function(game) {
 window['switch_backend'] = switch_backend;
 
 window['flip'] = function() { board.flip(); redraw_arrows(); };
+window['set_delay_ms'] = function(ms) { delay_ms = ms; console.log('Delay is now ' + ms + ' ms.'); };
 
 // Mostly from Wikipedia's chess set as of October 2022, but some pieces are from
 // the 2013 version, as I like those better (and it matches the 2014 PNGs; nobody