From a51d37c011922425057f71317f9ea2a5e1caf079 Mon Sep 17 00:00:00 2001 From: Waldek Date: Wed, 6 Jan 2021 13:03:07 +0100 Subject: [PATCH] Add files via upload --- scripts/hbmon.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 scripts/hbmon.js diff --git a/scripts/hbmon.js b/scripts/hbmon.js new file mode 100644 index 0000000..c305f8c --- /dev/null +++ b/scripts/hbmon.js @@ -0,0 +1,94 @@ + var sock = null; + var ellog = null; + + window.onload = function() { + var wsuri; + + ellog = document.getElementById('log'); + + bridge_table = document.getElementById('bridge'); + info_table = document.getElementById('info'); + main_table = document.getElementById('main'); + masters_table = document.getElementById('masters'); + moni_table = document.getElementById('moni'); + opb_table = document.getElementById('opb'); + peers_table = document.getElementById('peers'); + sysinfo_table = document.getElementById('sinfo'); + + wsuri = "ws://" + window.location.hostname + ":9000"; + + + if ("WebSocket" in window) { + sock = new WebSocket(wsuri); + } else if ("MozWebSocket" in window) { + sock = new MozWebSocket(wsuri); + } else { + log("Browser does not support WebSocket!"); + } + + if (sock) { + sock.onopen = function() { + log("Connected to " + wsuri); + } + sock.onclose = function(e) { + log("Connection closed (wasClean = " + e.wasClean + ", code = " + e.code + ", reason = '" + e.reason + "')"); + bridge_table.innerHTML = ""; + info_table.innerHTML = ""; + main_table.innerHTML = ""; + masters_table.innerHTML = ""; + moni_table.innerHTML = ""; + opb_table.innerHTML = ""; + peers_table.innerHTML = ""; + sysinfo_table.innerHTML = ""; + sock = null; + } + sock.onmessage = function(e) { + var opcode = e.data.slice(0,1); + var message = e.data.slice(1); + if (opcode == "b") { + Bmsg(message); + } else if (opcode == "c") { + Cmsg(message); + } else if (opcode == "i") { + Imsg(message); + } else if (opcode == "m") { + Mmsg(message); + } else if (opcode == "o") { + Omsg(message); + } else if (opcode == "p") { + Pmsg(message); + } else if (opcode == "t") { + Tmsg(message); + } else if (opcode == "s") { + Smsg(message); + } else if (opcode == "l") { + log(message); + } else if (opcode == "q") { + log(message); + bridge_table.innerHTML = ""; + info_table.innerHTML = ""; + main_table.innerHTML = ""; + masters_table.innerHTML = ""; + moni_table.innerHTML = ""; + opb_table.innerHTML = ""; + peers_table.innerHTML = ""; + sysinfo_table.innerHTML = ""; + } else { + log("Unknown Message Received: " + message); + } + } + } + }; + + function Bmsg(_msg) {bridge_table.innerHTML = _msg;}; + function Cmsg(_msg) {masters_table.innerHTML = _msg;}; + function Imsg(_msg) {main_table.innerHTML = _msg;}; + function Mmsg(_msg) {moni_table.innerHTML = _msg;}; + function Omsg(_msg) {opb_table.innerHTML = _msg;}; + function Pmsg(_msg) {peers_table.innerHTML = _msg;}; + function Tmsg(_msg) {info_table.innerHTML = _msg;}; + function Smsg(_msg) {sysinfo_table.innerHTML = _msg;}; + + function log(_msg) { + ellog.innerHTML += _msg + '\n'; + ellog.scrollTop = ellog.scrollHeight;};