You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
function liveplayer (elt) {
|
|
var last_timestamp,
|
|
DELAY_TIME_SECS = 5;
|
|
|
|
async function poll () {
|
|
var rows = await (await fetch("/cgi-bin/radioimplicancies.cgi")).json();
|
|
// console.log("rows", rows);
|
|
if (rows) {
|
|
// get the last (most recent) item
|
|
var d = rows[rows.length-1];
|
|
if (d.time && d.time != last_timestamp) {
|
|
last_timestamp = d.time;
|
|
console.log("liveplayer: current metadata", d);
|
|
window.setTimeout(function () {
|
|
var old_nowplaying = elt.querySelector(".now_playing");
|
|
if (old_nowplaying) {
|
|
old_nowplaying.classList.remove("now_playing");
|
|
}
|
|
var nowplaying = elt.querySelector("#"+d.title);
|
|
if (nowplaying) {
|
|
console.log("liveplayer: nowplaying", nowplaying);
|
|
nowplaying.classList.add("now_playing");
|
|
} else {
|
|
console.log("liveplayer: warning no div matching title " + d.title);
|
|
}
|
|
}, DELAY_TIME_SECS*1000);
|
|
}
|
|
}
|
|
}
|
|
|
|
window.setInterval(poll, 1000);
|
|
} |