summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bairadio.js45
1 files changed, 24 insertions, 21 deletions
diff --git a/bairadio.js b/bairadio.js
index b318c1f..74b9b4e 100644
--- a/bairadio.js
+++ b/bairadio.js
@@ -1,5 +1,4 @@
var selected = "";
-var renderType = 0;
function update(first) {
var first = first || false;
@@ -11,10 +10,23 @@ function update(first) {
req.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
var resp = JSON.parse(req.response);
+
+ var status = document.getElementById("status");
+ var artist = document.getElementById("artist");
+ var title = document.getElementById("title");
+ var bitrate = document.getElementById("bitrate");
+ var audio_samplerate = document.getElementById("audio_samplerate");
+ var listeners = document.getElementById("listeners");
+
if (resp.icestats.source) {
resp = resp.icestats.source;
} else {
- document.getElementById("status").textContent = "*** La radio está OFFLINE ***";
+ artist.textContent = "";
+ title.textContent = "";
+ bitrate.textContent = "--";
+ audio_samplerate.textContent = "--";
+ listeners.textContent = "0";
+ status.textContent = "*** La radio está OFFLINE ***";
var o = document.createElement("option");
o.textContent = "Nadie está transmitiendo...";
sel.appendChild(o);
@@ -25,7 +37,7 @@ function update(first) {
if (!resp.length) { resp = [resp]; }
if (first || !selected) {
- document.getElementById("status").textContent = "";
+ status.textContent = "";
selected = resp[0].listenurl.replace("http://bienvenidoainternet.org:8000", "");
}
@@ -55,10 +67,9 @@ function update(first) {
audio.src = resp.listenurl;
if (!first) { playPause(); }
}
-
- var current = document.getElementById("artist").textContent + document.getElementById("title").textContent;
-
- var artist = document.getElementById("artist");
+
+ var current = artist.textContent + title.textContent;
+
if (resp.artist) {
resp.artist = resp.artist.trim();
if (artist.textContent.slice(0,-3) != resp.artist) {
@@ -68,7 +79,6 @@ function update(first) {
artist.textContent = "";
}
- var title = document.getElementById("title");
if (resp.title) {
resp.title = String(resp.title).trim();
} else {
@@ -85,27 +95,20 @@ function update(first) {
checkLong();
}
- if (resp.listeners) {
- var listeners = document.getElementById("listeners");
- if (listeners.textContent != resp.listeners) {
- listeners.textContent = resp.listeners;
- }
- }
-
- if (resp["ice-bitrate"]) {
- var bitrate = document.getElementById("bitrate");
- if (bitrate.textContent != resp["ice-bitrate"]) {
- bitrate.textContent = resp["ice-bitrate"];
- }
+ if (resp["ice-bitrate"] && bitrate.textContent != resp["ice-bitrate"]) {
+ bitrate.textContent = resp["ice-bitrate"];
}
if (resp.audio_samplerate) {
- var audio_samplerate = document.getElementById("audio_samplerate");
var khz = Math.round(resp.audio_samplerate / 1000);
if (audio_samplerate.textContent != khz) {
audio_samplerate.textContent = khz;
}
}
+
+ if (resp.listeners && listeners.textContent != resp.listeners) {
+ listeners.textContent = resp.listeners;
+ }
}
}
}