mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-24 00:48:03 +01:00
Reduce polling rate
This commit is contained in:
parent
13c58ea1b6
commit
7758725ac6
1 changed files with 4 additions and 1 deletions
|
@ -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);
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue