()
| 9 | let statsHeight = 0; |
| 10 | |
| 11 | function connect() { |
| 12 | let socket = new WebSocket(location.protocol.replace("http", "ws") + "//" + host + (location.port ? ':' + location.port : '') + pathname + "logs") |
| 13 | socket.onopen = () => { |
| 14 | console.log("ws open") |
| 15 | } |
| 16 | |
| 17 | socket.onclose = event => { |
| 18 | console.log("ws close", event) |
| 19 | |
| 20 | setTimeout(() => { |
| 21 | connect() |
| 22 | }, 1000) |
| 23 | } |
| 24 | |
| 25 | socket.onerror = err => { |
| 26 | console.error('ws error: ', err.message, 'Closing socket'); |
| 27 | socket.close(); |
| 28 | } |
| 29 | |
| 30 | socket.onmessage = message => { |
| 31 | let data = JSON.parse(message.data); |
| 32 | if (data.Type == "log") { |
| 33 | let log = data.Data; |
| 34 | if (log.type !== "out" && log.type !== "error") return; |
| 35 | let div = document.getElementById("logs"); |
| 36 | let lines = div.getElementsByClassName('log') |
| 37 | while (lines.length > 999) lines[0].remove(); |
| 38 | let p = document.createElement("p"); |
| 39 | p.setAttribute("class", "log"); |
| 40 | let span = document.createElement("span"); |
| 41 | span.setAttribute("style", "color: " + (log.type == "out" ? "#00bb00" : "#d00000" + ";")); |
| 42 | if (SHOW_TIME) span.appendChild(document.createTextNode("[" + new Date(log.time).toLocaleString() + "] ")); |
| 43 | if (SHOW_ID) span.appendChild(document.createTextNode(log.id + " ")); |
| 44 | if (SHOW_APP_NAME) span.appendChild(document.createTextNode(log.app + " ")); |
| 45 | p.appendChild(span); |
| 46 | p.appendChild(document.createTextNode("> " + log.message)); |
| 47 | let isScrolledToBottom = div.scrollHeight - div.clientHeight <= div.scrollTop + div.offsetHeight * 0.25 |
| 48 | div.appendChild(p); |
| 49 | if (isScrolledToBottom && !getSelectedText()) { |
| 50 | div.scrollTop = div.scrollHeight - div.clientHeight |
| 51 | } |
| 52 | } else if (data.Type == "stats") { |
| 53 | let stats = data.Data; |
| 54 | let txt = "<table>" |
| 55 | txt += "<tr class=\"table_title\">"; |
| 56 | txt += "<td>App name</td>" |
| 57 | txt += "<td>id</td>" |
| 58 | txt += "<td>pid</td>" |
| 59 | txt += "<td>status</td>" |
| 60 | txt += "<td>restart</td>" |
| 61 | txt += "<td>uptime</td>" |
| 62 | txt += "<td>cpu</td>" |
| 63 | txt += "<td>mem</td>" |
| 64 | txt += "<td>user</td>" |
| 65 | if (SHOW_ACTIONS) txt += "<td>actions</td>" |
| 66 | txt += "</tr>" |
| 67 | for (var i in stats) { |
| 68 | let uptime = Math.floor((data.Time - stats[i].uptime) / 1000); |
no test coverage detected