* Use different update intervals depending on live / paused / error status.
authorUrban Wallasch <urban.wallasch@freenet.de>
Tue, 13 Aug 2019 20:35:23 +0000 (22:35 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Tue, 13 Aug 2019 20:35:23 +0000 (22:35 +0200)
dash.html

index 1d6e928b841a754f8792ca7f730de0e56041cf46..dd758f362066713f07bc52846e1433b72d3720c0 100644 (file)
--- a/dash.html
+++ b/dash.html
@@ -304,6 +304,20 @@ function tnow() {
 // Begin display update code.
 ////////////////////////////////////////////////////////////////
 
+// Update interval:
+const FAST_TICK =  333  // 1/3 second ticks in active or paused state
+const SLOW_TICK = 2000  // 2 second ticks in error or offline state
+
+// XHRequest:
+var xhttp = new XMLHttpRequest();
+xhttp.onreadystatechange = update_cb;
+setTimeout( loadDoc, FAST_TICK );
+
+function loadDoc() {
+  xhttp.open( 'GET', '/json', true );
+  xhttp.send();
+}
+
 // Version and flag constants:
 const TELE_VERSION = 1;
 const TELE_FLAG_ALIVE = 1;
@@ -337,8 +351,10 @@ function update_cb() {
         errbar.innerHTML = 'Game offline';
       }
       last_tele = tele;
+      setTimeout( loadDoc, SLOW_TICK );
       return;
     }
+    setTimeout( loadDoc, FAST_TICK );
 
     // Check telemetry version:
     if ( !last_tele || last_tele.version != tele.tele_version ) {
@@ -503,19 +519,10 @@ function update_cb() {
       errbar.innerHTML = 'Status: ' + this.status + '<br>' + this.responseText;
     else
       errbar.innerHTML = 'Connection error';
+    setTimeout( loadDoc, SLOW_TICK );
   }
 };
 
-function loadDoc() {
-  xhttp.open( 'GET', '/json', true );
-  xhttp.send();
-}
-
-// XHRequest:
-var xhttp = new XMLHttpRequest();
-xhttp.onreadystatechange = update_cb;
-window.setInterval(loadDoc, 333);
-
 ////////////////////////////////////////////////////////////////
 // End display update code.
 ////////////////////////////////////////////////////////////////