From 7758725ac61905da205012783b45d1f44fcd2183 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 2 Jan 2023 23:16:07 +0100 Subject: [PATCH] Reduce polling rate --- data/www/script.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/www/script.js b/data/www/script.js index 4341b07..383275b 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -1,5 +1,6 @@ const GLOBAL_TIMEOUT = 10000; let connectionOk = true; +let statusTimeout = null; function play() { console.log("Play..."); @@ -41,6 +42,7 @@ function selectFile(name) { } function handleStatus(data) { + clearTimeout(statusTimeout); document.body.classList.remove("w3-disabled"); if (!connectionOk) { connectionOk = true; @@ -60,6 +62,7 @@ function handleStatus(data) { document.getElementById("volume-current").innerText = data.volume.current; document.getElementById("volume-increase").disabled = !data.volume.canIncrease; document.getElementById("volume-decrease").disabled = !data.volume.canDecrease; + statusTimeout = setTimeout(loadStatus, GLOBAL_TIMEOUT); } function handleError() { @@ -70,5 +73,5 @@ function handleError() { (() => { loadStatus(); - setInterval(loadStatus, GLOBAL_TIMEOUT); + statusTimeout = setTimeout(loadStatus, GLOBAL_TIMEOUT); })();