summaryrefslogtreecommitdiff
path: root/bairadio.js
diff options
context:
space:
mode:
authorLibravatar jay 2020-03-09 17:55:03 -0300
committerLibravatar jay 2020-03-09 17:55:03 -0300
commit718a975322891fa028e60f91d8b9ee23aa4f559c (patch)
tree892d147429e88d8684b6e751ff3a197fbb048c38 /bairadio.js
parentafe1df2632fa82d9c0f1189f0719db3fe5ce85e7 (diff)
downloadbairadio-frontend-718a975322891fa028e60f91d8b9ee23aa4f559c.tar.gz
bairadio-frontend-718a975322891fa028e60f91d8b9ee23aa4f559c.tar.xz
bairadio-frontend-718a975322891fa028e60f91d8b9ee23aa4f559c.zip
Arreglando otros bugs menores
Diffstat (limited to 'bairadio.js')
-rw-r--r--bairadio.js90
1 files changed, 51 insertions, 39 deletions
diff --git a/bairadio.js b/bairadio.js
index 4ee1541..b318c1f 100644
--- a/bairadio.js
+++ b/bairadio.js
@@ -1,4 +1,5 @@
-var radionum = 0;
+var selected = "";
+var renderType = 0;
function update(first) {
var first = first || false;
@@ -9,41 +10,47 @@ function update(first) {
req.send();
req.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
- if (first) { document.getElementById("status").textContent = ""; }
-
var resp = JSON.parse(req.response);
- resp = resp.icestats.source;
+ if (resp.icestats.source) {
+ resp = resp.icestats.source;
+ } else {
+ document.getElementById("status").textContent = "*** La radio está OFFLINE ***";
+ var o = document.createElement("option");
+ o.textContent = "Nadie está transmitiendo...";
+ sel.appendChild(o);
+ selected = "";
+ return;
+ }
- if (radionum > resp.length) { radionum = 0; }
+ if (!resp.length) { resp = [resp]; }
+
+ if (first || !selected) {
+ document.getElementById("status").textContent = "";
+ selected = resp[0].listenurl.replace("http://bienvenidoainternet.org:8000", "");
+ }
var sel = document.getElementById("server_name");
sel.textContent = "";
- if (resp.length > 1) {
- for (var i = -1; ++i < resp.length;) {
- var o = document.createElement("option");
- o.value = i;
- o.textContent = resp[i].server_name;
- if (resp[i].server_description) {
- o.textContent += ": " + resp[i].server_description;
- }
- if (i == radionum) { o.defaultSelected = true; }
- sel.appendChild(o);
- }
- resp = resp[radionum];
- } else {
+ var selectedPos = 0;
+ for (var i = -1; ++i < resp.length;) {
var o = document.createElement("option");
- o.value = 0;
- o.textContent = resp.server_name;
- if (resp.server_description) {
- o.textContent += ": " + resp.server_description;
+ resp[i].listenurl = resp[i].listenurl.replace("http://bienvenidoainternet.org:8000", "");
+ o.value = resp[i].listenurl;
+ o.textContent = resp[i].server_name;
+ if (resp[i].server_description) {
+ o.textContent += ": " + resp[i].server_description;
+ }
+ if (resp[i].listenurl == selected) {
+ o.defaultSelected = true;
+ selectedPos = i;
}
- o.defaultSelected = true;
sel.appendChild(o);
}
+ resp = resp[selectedPos];
var audio = document.getElementById("stream");
- resp.listenurl = resp.listenurl.replace("http://bienvenidoainternet.org:8000", "https://bienvenidoainternet.org:8443");
+ resp.listenurl = "https://bienvenidoainternet.org:8443" + resp.listenurl;
if (audio.src != resp.listenurl) {
audio.src = resp.listenurl;
if (!first) { playPause(); }
@@ -146,7 +153,7 @@ function checkLong() {
var ws = strip.clientWidth;
var wc = cont.clientWidth
if (ws > wc) {
- var travel = ws - (wc-5);
+ var travel = ws - (wc-10);
var style = document.createElement("style");
style.id = "marqueeStyle";
var dur = Math.round(travel/10);
@@ -165,8 +172,8 @@ function playPause() {
radio.play();
stat.setAttribute("class", "playing");
} else {
- stat.setAttribute("class", "paused");
radio.pause();
+ stat.setAttribute("class", "paused");
}
}
@@ -194,15 +201,15 @@ function changeVolume(e) {
}
}
-function collapseHistory() {
- var box = document.getElementById("box-history");
- var cont = document.getElementById("history").parentElement;
- if (box.className == "outer") {
- box.classList.add("collapse");
- cont.style.width = (box.clientWidth - document.getElementById("box-history-title").clientWidth - 14) + "px";
- } else {
+function collapseWindow(e) {
+ var box = this.parentElement.parentElement;
+ var cont = box.getElementsByClassName("content")[0];
+ if (box.classList.contains("collapse")) {
cont.removeAttribute("style");
box.classList.remove("collapse");
+ } else {
+ box.classList.add("collapse");
+ cont.style.width = (box.clientWidth - this.clientWidth - 14) + "px";
}
box.scrollTop = box.scrollHeight;
removeSel();
@@ -266,7 +273,7 @@ function interpretNewMsg(info) {
var msg = unescapeColon(arg[2]);
addMsg(msg);
} else if (arg[0] == "COUNT") {
- document.getElementById("chat-count").textContent = " (Usuarios: " + arg[1] + ")";
+ document.getElementById("chat-count").textContent = arg[1];
}
}
@@ -277,12 +284,12 @@ function checkSend(e) {
var msgField = document.getElementById("msg_type");
var msg = msgField.value.trim();
- if (!msg) return;
+ if (!msg) { return; }
if (chatConnected) {
sendMsg("MSG:0:" + escapeColon(msg));
addMsg(msg);
- } else return;
+ } else { return; }
msgField.value = "";
antiFlood = true;
@@ -322,12 +329,17 @@ function addMsg(msg) {
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("control").addEventListener("click", playPause);
document.getElementById("volume").addEventListener("mousedown", changeVolume);
- document.getElementById("server_name").addEventListener("change", function(e) { radionum = this.value; });
- document.getElementById("box-history-title").addEventListener("dblclick", collapseHistory);
+ document.getElementById("server_name").addEventListener("change", function(e) { selected = this.value; });
+ var boxt = document.getElementsByClassName("boxtitle");
+ for (var i = -1; ++i < boxt.length;) {
+ boxt[i].addEventListener("click", collapseWindow);
+ }
+ document.getElementById("resize").addEventListener("mousedown", resizeChat);
document.getElementById("resize").addEventListener("mousedown", resizeChat);
+ //return;
update(true);
startVisualization();
- setInterval(update, 1500);
+ setInterval(update, 2000);
connect();
});