2023-01-02 22:10:01 +01:00
|
|
|
const GLOBAL_TIMEOUT = 7000;
|
|
|
|
|
2022-12-30 20:14:35 +01:00
|
|
|
function play() {
|
|
|
|
console.log("Play...");
|
2023-01-02 22:10:01 +01:00
|
|
|
fetch("/play", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) });
|
|
|
|
}
|
|
|
|
|
|
|
|
function volume(modifier) {
|
|
|
|
const body = new FormData();
|
|
|
|
body.set("modifier", modifier);
|
|
|
|
fetch(`/change-volume`, { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(handleStatus);
|
2022-12-30 20:14:35 +01:00
|
|
|
}
|
2023-01-01 02:43:54 +01:00
|
|
|
|
2023-01-02 22:10:01 +01:00
|
|
|
function loadStatus() {
|
|
|
|
console.log("Status...");
|
|
|
|
fetch("/status", { signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
2023-01-01 02:43:54 +01:00
|
|
|
.then(response => response.json())
|
2023-01-02 22:10:01 +01:00
|
|
|
.then(handleStatus);
|
2023-01-01 02:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectFile(name) {
|
|
|
|
console.log("Select file");
|
|
|
|
const body = new FormData();
|
|
|
|
body.set("fileName", name);
|
2023-01-02 22:10:01 +01:00
|
|
|
fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(GLOBAL_TIMEOUT) })
|
2023-01-01 02:55:32 +01:00
|
|
|
.then(response => response.json())
|
2023-01-02 22:10:01 +01:00
|
|
|
.then(handleStatus);
|
2023-01-01 02:55:32 +01:00
|
|
|
}
|
|
|
|
|
2023-01-02 22:10:01 +01:00
|
|
|
function handleStatus(data) {
|
2023-01-01 02:55:32 +01:00
|
|
|
console.log("data", data);
|
|
|
|
let dom = "";
|
|
|
|
data.files.forEach(element => {
|
|
|
|
if (element === data.selectedFile) {
|
|
|
|
dom += `<button class="w3-button w3-green" onclick="selectFile('${element}')">${element}</button>`;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dom += `<button class="w3-button w3-blue" onclick="selectFile('${element}')">${element}</button>`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
document.getElementById("available-files").innerHTML = dom;
|
2023-01-02 22:10:01 +01:00
|
|
|
document.getElementById("volume-current").innerText = data.volume.current;
|
|
|
|
document.getElementById("volume-increase").disabled = !data.volume.canIncrease;
|
|
|
|
document.getElementById("volume-decrease").disabled = !data.volume.canDecrease;
|
2023-01-01 02:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
(() => {
|
2023-01-02 22:10:01 +01:00
|
|
|
loadStatus();
|
|
|
|
setInterval(loadStatus, 10000);
|
2023-01-01 02:43:54 +01:00
|
|
|
})();
|