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.

55 lines
1.9 KiB
JavaScript

function liveplayer (elt, iframe) {
var last_timestamp,
DELAY_TIME_SECS = 5,
originalsrc= iframe ? iframe.src : '';
async function poll () {
console.log("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);
}
console.log("****", iframe, d.artist);
if (iframe&&d.artist){
if (d.artist.endsWith(".jpg") || d.artist.endsWith(".png")) {
console.log("IMAGE", d.artist);
// iframe.style.backgroundImage = "url("+d.artist+")";
// iframe.src = "blank.html";
iframe.src = d.artist;
} else {
console.log("OTHER URL");
iframe.src = d.artist;
}
} else if (iframe) {
iframe.src = originalsrc;
}
}, DELAY_TIME_SECS*1000);
}
window.setTimeout(poll, 10000);
} else {
window.setTimeout(poll, 20000);
}
}
window.setTimeout(poll, 0);
}