From: Urban Wallasch Date: Tue, 13 Aug 2019 20:35:23 +0000 (+0200) Subject: * Use different update intervals depending on live / paused / error status. X-Git-Tag: v0.1.0~22 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=0c090b2dccc6d621cd3a17c2b563159280aba185;p=ets2_tele.git * Use different update intervals depending on live / paused / error status. --- diff --git a/dash.html b/dash.html index 1d6e928..dd758f3 100644 --- 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 + '
' + 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. ////////////////////////////////////////////////////////////////