diff options
author | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-10-21 17:46:59 +0300 |
commit | cda32a083faf3e7326cfe317336e473c905c6dfd (patch) | |
tree | 19445e4098d4603f3b2cd296504a648110712af1 /web | |
parent | b67a2325842a6f407d3935f8445d50cb8bf307f2 (diff) |
new events model
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/kvm/session.js | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js index 353815da..22cefe89 100644 --- a/web/share/js/kvm/session.js +++ b/web/share/js/kvm/session.js @@ -62,9 +62,21 @@ export function Session() { /************************************************************************/ - var __setAboutInfoMeta = function(state) { + var __setInfoState = function(state) { + for (let key of Object.keys(state)) { + switch (key) { + case "meta": __setInfoStateMeta(state.meta); break; + case "hw": __setInfoStateHw(state.hw); break; + case "fan": __setInfoStateFan(state.fan); break; + case "system": __setInfoStateSystem(state.system); break; + case "extras": __setInfoStateExtras(state.extras); break; + } + } + }; + + var __setInfoStateMeta = function(state) { if (state !== null) { - let text = JSON.stringify(state, undefined, 4).replace(/ /g, " ").replace(/\n/g, "<br>"); + let text = tools.escape(JSON.stringify(state, undefined, 4)).replace(/ /g, " ").replace(/\n/g, "<br>"); $("about-meta").innerHTML = ` <span class="code-comment">// The PiKVM metadata.<br> // You can get this JSON using handle <a target="_blank" href="/api/info?fields=meta">/api/info?fields=meta</a>.<br> @@ -74,10 +86,10 @@ export function Session() { ${text} `; if (state.server && state.server.host) { - $("kvmd-meta-server-host").innerHTML = `Server: ${state.server.host}`; + $("kvmd-meta-server-host").innerText = `Server: ${state.server.host}`; document.title = `PiKVM Session: ${state.server.host}`; } else { - $("kvmd-meta-server-host").innerHTML = ""; + $("kvmd-meta-server-host").innerText = ""; document.title = "PiKVM Session"; } @@ -88,7 +100,7 @@ export function Session() { } }; - var __setAboutInfoHw = function(state) { + var __setInfoStateHw = function(state) { if (state.health.throttling !== null) { let flags = state.health.throttling.parsed_flags; let ignore_past = state.health.throttling.ignore_past; @@ -105,7 +117,7 @@ export function Session() { __renderAboutInfoHardware(); }; - var __setAboutInfoFan = function(state) { + var __setInfoStateFan = function(state) { let failed = false; let failed_past = false; if (state.monitored) { @@ -207,11 +219,11 @@ export function Session() { } }; - var __colored = function(color, text) { - return `<font color="${color}">${text}</font>`; + var __colored = function(color, html) { + return `<font color="${color}">${html}</font>`; }; - var __setAboutInfoSystem = function(state) { + var __setInfoStateSystem = function(state) { $("about-version").innerHTML = ` KVMD: <span class="code-comment">${state.kvmd.version}</span><br> <hr> @@ -221,8 +233,8 @@ export function Session() { ${state.kernel.system} kernel: ${__formatUname(state.kernel)} `; - $("kvmd-version-kvmd").innerHTML = state.kvmd.version; - $("kvmd-version-streamer").innerHTML = state.streamer.version; + $("kvmd-version-kvmd").innerText = state.kvmd.version; + $("kvmd-version-streamer").innerText = state.streamer.version; }; var __formatStreamerFeatures = function(features) { @@ -244,14 +256,14 @@ export function Session() { }; var __formatUl = function(pairs) { - let text = "<ul>"; + let html = ""; for (let pair of pairs) { - text += `<li>${pair[0]}: <span class="code-comment">${pair[1]}</span></li>`; + html += `<li>${pair[0]}: <span class="code-comment">${pair[1]}</span></li>`; } - return text + "</ul>"; + return `<ul>${html}</ul>`; }; - var __setExtras = function(state) { + var __setInfoStateExtras = function(state) { let show_hook = null; let close_hook = null; let has_webterm = (state.webterm && (state.webterm.enabled || state.webterm.started)); @@ -354,11 +366,7 @@ export function Session() { let data = JSON.parse(event.data); switch (data.event_type) { case "pong": __missed_heartbeats = 0; break; - case "info_meta_state": __setAboutInfoMeta(data.event); break; - case "info_hw_state": __setAboutInfoHw(data.event); break; - case "info_fan_state": __setAboutInfoFan(data.event); break; - case "info_system_state": __setAboutInfoSystem(data.event); break; - case "info_extras_state": __setExtras(data.event); break; + case "info_state": __setInfoState(data.event); break; case "gpio_state": __gpio.setState(data.event); break; case "hid_keymaps_state": __hid.setKeymaps(data.event); break; case "hid_state": __hid.setState(data.event); break; |