From 10f0f6e995d5081332f3976ca7091c9c92752113 Mon Sep 17 00:00:00 2001 From: jay Date: Fri, 13 Mar 2020 01:46:03 -0300 Subject: Nuevas emisiones son informadas en chat --- bairadio.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'bairadio.js') diff --git a/bairadio.js b/bairadio.js index 104e2f3..df63006 100644 --- a/bairadio.js +++ b/bairadio.js @@ -1,4 +1,5 @@ var selected = ""; +var shows = []; function update(first) { var first = first || false; @@ -43,12 +44,16 @@ function update(first) { var sel = document.getElementById("server_name"); sel.textContent = ""; - var selectedPos = 0; + var currentShows = []; for (var i = -1; ++i < resp.length;) { var o = document.createElement("option"); resp[i].listenurl = resp[i].listenurl.replace("http://bienvenidoainternet.org:8000", ""); o.value = resp[i].listenurl; + if (checkNew(resp[i].listenurl) && !first) { + addMsg("Ha comenzado una nueva transmisiĆ³n: " + resp[i].server_name); + } + currentShows.push(resp[i].listenurl); o.textContent = resp[i].server_name; if (resp[i].server_description) { o.textContent += ": " + resp[i].server_description; @@ -60,6 +65,7 @@ function update(first) { sel.appendChild(o); } resp = resp[selectedPos]; + shows = currentShows; var currentListen = document.getElementById("current_server"); currentListen.value = resp.server_name; @@ -72,7 +78,7 @@ function update(first) { if (document.getElementById("chat-filter")) { filterChat(true); } } - var current = artist.textContent + title.textContent; + var currentSong = artist.textContent + title.textContent; if (resp.artist) { resp.artist = resp.artist.trim(); @@ -90,7 +96,7 @@ function update(first) { } if (title.textContent != resp.title) { var history = document.getElementById("history"); - history.innerHTML += '
' + current + '
'; + history.innerHTML += '
' + currentSong + '
'; history.scrollTop = history.scrollHeight; title.textContent = resp.title; @@ -117,6 +123,19 @@ function update(first) { } } +function checkNew(mount) { + var isNew = true; + for (var i = -1; ++i < shows.length;) { + if (mount == shows[i]) { + isNew = false; + break; + } + } + if (isNew) { shows.push(mount); } + + return isNew; +} + function startVisualization() { var ctx = new AudioContext(); var audio = document.getElementById("stream"); @@ -295,12 +314,12 @@ function checkSend(e) { var msgField = document.getElementById("msg_type"); var msg = msgField.value.trim(); - var stream = document.getElementById("current_server").value; + var show = document.getElementById("current_server").value; if (!msg) { return; } if (chatConnected) { sendMsg("MSG:" + escapeColon(stream) + ":" + escapeColon(msg)); - addMsg(msg, stream, false, true); + addMsg(msg, show, false, true); } else { return; } msgField.value = ""; @@ -350,11 +369,11 @@ function filterChat(enable) { if (filter) { filter.parentElement.removeChild(filter); } if (enable) { - var current = document.getElementById("current_server").value; + var currentShow = document.getElementById("current_server").value; var style = document.createElement("style"); style.id = "chat-filter"; style.textContent = '[data-stream] { display: none; }'; - style.textContent += '[data-stream^="' + current + '"] { display: block; }'; + style.textContent += '[data-stream^="' + currentShow + '"] { display: block; }'; document.getElementsByTagName("head")[0].appendChild(style); } -- cgit v1.2.1-18-gbd029