1
0

Updated main.js. Added a new update() function that does everything. Not completed yet.

This commit is contained in:
Alexander Andreev 2023-10-02 03:56:57 +04:00
parent 35429e57d2
commit c2c8c82212
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -1,5 +1,19 @@
const $ = id => document.getElementById(id); const $ = id => document.getElementById(id);
function update() {
fetch("/api/status")
.then(r => r.json())
.then(r => {
$("radio-song").textContent = `${r.current_song.artist} - ${r.current_song.title}`;
$("radio-duration").textContent = r.current_song.duration;
$("radio-listeners").textContent = r.listeners.current;
$("radio-listener-peak").textContent = r.listeners.peak;
}).catch(() => {
$("radio-song").textContent = "";
$("radio-listeners").textContent =
$("radio-listener-peak").textContent = "0"; });
}
function updateRadioStatus() { function updateRadioStatus() {
fetch("/status") fetch("/status")
.then(r => r.json()) .then(r => r.json())
@ -29,12 +43,9 @@ function updateLastPlayedSong() {
row.insertCell().appendChild(document.createTextNode(last_played.listeners == 0 ? "" : last_played.listeners)); row.insertCell().appendChild(document.createTextNode(last_played.listeners == 0 ? "" : last_played.listeners));
row.insertCell().appendChild(document.createTextNode(last_played.song)); }); } row.insertCell().appendChild(document.createTextNode(last_played.song)); }); }
$("radio-update").addEventListener("click", () => { $("radio-update").addEventListener("click", () => update());
updateLastPlayedSong();
updateRadioStatus(); });
setInterval(updateRadioStatus, 45000); setInterval(update, 45000);
setInterval(updateLastPlayedSong, 45000);
const audio = document.getElementsByTagName("audio")[0]; const audio = document.getElementsByTagName("audio")[0];
audio.hidden = true; audio.hidden = true;