mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-24 08:58:06 +01:00
Disable web when losing connection
This commit is contained in:
parent
b640bce997
commit
5d95838769
1 changed files with 15 additions and 5 deletions
|
@ -2,7 +2,8 @@ const GLOBAL_TIMEOUT = 7000;
|
||||||
|
|
||||||
function play() {
|
function play() {
|
||||||
console.log("Play...");
|
console.log("Play...");
|
||||||
fetch("/play", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) });
|
fetch("/play", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function volume(modifier) {
|
function volume(modifier) {
|
||||||
|
@ -10,14 +11,16 @@ function volume(modifier) {
|
||||||
body.set("modifier", modifier);
|
body.set("modifier", modifier);
|
||||||
fetch(`/change-volume`, { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
fetch(`/change-volume`, { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(handleStatus);
|
.then(handleStatus)
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadStatus() {
|
function loadStatus() {
|
||||||
console.log("Status...");
|
console.log("Status...");
|
||||||
fetch("/status", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
fetch("/status", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(handleStatus);
|
.then(handleStatus)
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectFile(name) {
|
function selectFile(name) {
|
||||||
|
@ -26,10 +29,12 @@ function selectFile(name) {
|
||||||
body.set("fileName", name);
|
body.set("fileName", name);
|
||||||
fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(handleStatus);
|
.then(handleStatus)
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleStatus(data) {
|
function handleStatus(data) {
|
||||||
|
document.body.classList.remove("w3-disabled");
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
let dom = "";
|
let dom = "";
|
||||||
data.files.forEach(element => {
|
data.files.forEach(element => {
|
||||||
|
@ -46,7 +51,12 @@ function handleStatus(data) {
|
||||||
document.getElementById("volume-decrease").disabled = !data.volume.canDecrease;
|
document.getElementById("volume-decrease").disabled = !data.volume.canDecrease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleError() {
|
||||||
|
console.log("Lost connection :'(");
|
||||||
|
document.body.classList.add("w3-disabled");
|
||||||
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
loadStatus();
|
loadStatus();
|
||||||
setInterval(loadStatus, 10000);
|
setInterval(loadStatus, GLOBAL_TIMEOUT);
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue