diff options
author | Devaev Maxim <[email protected]> | 2019-12-10 05:53:29 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-12-10 05:53:29 +0300 |
commit | f5a6fe35a99735c11eaad5d194061223bf9a0820 (patch) | |
tree | 5459afdd2856a4f9917d5f6c4aa95eb95300513c /web/share/js/kvm/session.js | |
parent | 3048fc79233f1ece909dee0f100e72a2f3f5a639 (diff) |
ws api refactoring
Diffstat (limited to 'web/share/js/kvm/session.js')
-rw-r--r-- | web/share/js/kvm/session.js | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js index cc9af52d..5df1481c 100644 --- a/web/share/js/kvm/session.js +++ b/web/share/js/kvm/session.js @@ -114,23 +114,15 @@ export function Session() { var __wsMessageHandler = function(event) { // tools.debug("Session: received socket data:", event.data); - event = JSON.parse(event.data); - if (event.msg_type === "pong") { - __missed_heartbeats = 0; - } else if (event.msg_type === "event") { - if (event.msg.event === "info_state") { - __setKvmdInfo(event.msg.event_attrs); - } else if (event.msg.event === "hid_state") { - __hid.setState(event.msg.event_attrs); - } else if (event.msg.event === "atx_state") { - __atx.setState(event.msg.event_attrs); - } else if (event.msg.event === "msd_state") { - __msd.setState(event.msg.event_attrs); - } else if (event.msg.event === "streamer_state") { - __streamer.setState(event.msg.event_attrs); - } else if (event.msg.event === "wol_state") { - __wol.setState(event.msg.event_attrs); - } + let data = JSON.parse(event.data); + switch (data.event_type) { + case "pong": __missed_heartbeats = 0; break; + case "info_state": __setKvmdInfo(data.event); break; + case "wol_state": __wol.setState(data.event); break; + case "hid_state": __hid.setState(data.event); break; + case "atx_state": __atx.setState(data.event); break; + case "msd_state": __msd.setState(data.event); break; + case "streamer_state": __streamer.setState(data.event); break; } }; @@ -171,7 +163,7 @@ export function Session() { if (__missed_heartbeats >= 5) { throw new Error("Too many missed heartbeats"); } - __ws.send(JSON.stringify({"event_type": "ping"})); + __ws.send(JSON.stringify({"event_type": "ping", "event": {}})); } catch (err) { tools.error("Session: ping error:", err.message); if (__ws) { |