From 0c090b2dccc6d621cd3a17c2b563159280aba185 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Tue, 13 Aug 2019 22:35:23 +0200 Subject: [PATCH] * Use different update intervals depending on live / paused / error status. --- dash.html | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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. //////////////////////////////////////////////////////////////// -- 2.30.2