summaryrefslogtreecommitdiff
path: root/bairadio.js
diff options
context:
space:
mode:
authorLibravatar jay 2020-03-11 22:56:41 -0300
committerLibravatar jay 2020-03-11 22:56:41 -0300
commit5aa59bf662561980755acf131897379092eeeba3 (patch)
tree7384cffcdc1ba7827d60089a02449ec91f21d26f /bairadio.js
parent4114ad51d9d30f60855b32b185a62dd40dc960c3 (diff)
downloadbairadio-frontend-5aa59bf662561980755acf131897379092eeeba3.tar.gz
bairadio-frontend-5aa59bf662561980755acf131897379092eeeba3.tar.xz
bairadio-frontend-5aa59bf662561980755acf131897379092eeeba3.zip
Agregando historial de mensajes
Diffstat (limited to 'bairadio.js')
-rw-r--r--bairadio.js42
1 files changed, 26 insertions, 16 deletions
diff --git a/bairadio.js b/bairadio.js
index 74b9b4e..685eaff 100644
--- a/bairadio.js
+++ b/bairadio.js
@@ -61,6 +61,9 @@ function update(first) {
}
resp = resp[selectedPos];
+ var currentListen = document.getElementById("current_server");
+ currentListen.value = resp.server_name;
+
var audio = document.getElementById("stream");
resp.listenurl = "https://bienvenidoainternet.org:8443" + resp.listenurl;
if (audio.src != resp.listenurl) {
@@ -204,7 +207,7 @@ function changeVolume(e) {
}
}
-function collapseWindow(e) {
+function collapsePanel(e) {
var box = this.parentElement.parentElement;
var cont = box.getElementsByClassName("content")[0];
if (box.classList.contains("collapse")) {
@@ -218,15 +221,16 @@ function collapseWindow(e) {
removeSel();
}
-function resizeChat(e) {
+function resizePanel(e) {
var mousepos = e.y;
+ var id = this.dataset.id;
document.addEventListener("mousemove", calcResize);
document.addEventListener("mouseup", function() {
document.removeEventListener("mousemove", calcResize);
});
function calcResize(e) {
- var chat = document.getElementById("chat-all");
+ var chat = document.getElementById(id);
var dx = mousepos - e.y;
mousepos = e.y;
chat.style.height = (parseInt(getComputedStyle(chat, "").height) - dx) + "px";
@@ -247,8 +251,8 @@ const chatFloodTime = 1100;
function connect() {
sock = new WebSocket("wss://radio.bienvenidoainternet.org/daemon/");
sock.addEventListener("open", function(e) {
- addMsg("Conectado al chat.");
chatConnected = true;
+ sock.send("HISTORY:10");
enableChat();
});
sock.addEventListener("message", function(e) {
@@ -273,10 +277,13 @@ function interpretNewMsg(info) {
var arg = info.split(":");
if (arg[0] == "MSG") {
- var msg = unescapeColon(arg[2]);
- addMsg(msg);
+ addMsg(unescapeColon(arg[2]), arg[1]);
} else if (arg[0] == "COUNT") {
document.getElementById("chat-count").textContent = arg[1];
+ } else if (arg[0] == "HMSG") {
+ addMsg(unescapeColon(arg[3]), unescapeColon(arg[2]), arg[1]);
+ } else if (arg[0] == "HISTORY_OK") {
+ addMsg("Conectado al chat.");
}
}
@@ -290,7 +297,7 @@ function checkSend(e) {
if (!msg) { return; }
if (chatConnected) {
- sendMsg("MSG:0:" + escapeColon(msg));
+ sendMsg("MSG:" + escapeColon(document.getElementById("current_server").value) + ":" + escapeColon(msg));
addMsg(msg);
} else { return; }
@@ -312,35 +319,38 @@ function sendMsg(msg) {
sock.send(msg);
}
-function addMsg(msg) {
+function addMsg(msg, stream, time) {
+ var time = time || false;
+ var stream = stream || false;
var chat = document.getElementById("chat-all");
-
+
var line = document.createElement("div");
- line.className = "msg";
- var presentTime = new Date();
+ line.className = (time ? "msg history" : "msg");
+ var presentTime = (time ? new Date(Number(time)) : new Date());
var hh = presentTime.getHours();
hh = (hh < 10) ? ("0" + hh) : hh;
var mm = presentTime.getMinutes();
mm = (mm < 10) ? ("0" + mm) : mm;
line.textContent = "[" + hh + ":" + mm + "] ";
+ if (stream) { line.textContent += "(" + stream + ") "; }
line.textContent += msg;
chat.appendChild(line);
chat.scrollTop = chat.scrollHeight;
}
-
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("control").addEventListener("click", playPause);
document.getElementById("volume").addEventListener("mousedown", changeVolume);
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);
+ boxt[i].addEventListener("click", collapsePanel);
+ }
+ var resize = document.getElementsByClassName("resize");
+ for (var i = -1; ++i < resize.length;) {
+ resize[i].addEventListener("mousedown", resizePanel);
}
- document.getElementById("resize").addEventListener("mousedown", resizeChat);
- document.getElementById("resize").addEventListener("mousedown", resizeChat);
- //return;
update(true);
startVisualization();
setInterval(update, 2000);