// 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;
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 ) {
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.
////////////////////////////////////////////////////////////////