summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-12-10 05:53:29 +0300
committerDevaev Maxim <[email protected]>2019-12-10 05:53:29 +0300
commitf5a6fe35a99735c11eaad5d194061223bf9a0820 (patch)
tree5459afdd2856a4f9917d5f6c4aa95eb95300513c /web
parent3048fc79233f1ece909dee0f100e72a2f3f5a639 (diff)
ws api refactoring
Diffstat (limited to 'web')
-rw-r--r--web/share/js/kvm/keyboard.js5
-rw-r--r--web/share/js/kvm/mouse.js13
-rw-r--r--web/share/js/kvm/session.js28
3 files changed, 18 insertions, 28 deletions
diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js
index d573d924..a443b2c9 100644
--- a/web/share/js/kvm/keyboard.js
+++ b/web/share/js/kvm/keyboard.js
@@ -126,9 +126,8 @@ export function Keyboard() {
tools.debug("Keyboard: key", (state ? "pressed:" : "released:"), code);
if (__ws) {
__ws.send(JSON.stringify({
- event_type: "key",
- key: code,
- state: state,
+ "event_type": "key",
+ "event": {"key": code, "state": state},
}));
}
};
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index 3b5da1de..1b8aa716 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -147,9 +147,8 @@ export function Mouse() {
__sendMove();
if (__ws) {
__ws.send(JSON.stringify({
- event_type: "mouse_button",
- button: button,
- state: state,
+ "event_type": "mouse_button",
+ "event": {"button": button, "state": state},
}));
}
};
@@ -166,8 +165,8 @@ export function Mouse() {
tools.debug("Mouse: moved:", to);
if (__ws) {
__ws.send(JSON.stringify({
- event_type: "mouse_move",
- to: to,
+ "event_type": "mouse_move",
+ "event": {"to": to},
}));
}
__sent_pos = pos;
@@ -202,8 +201,8 @@ export function Mouse() {
tools.debug("Mouse: scrolled:", delta);
if (__ws) {
__ws.send(JSON.stringify({
- event_type: "mouse_wheel",
- delta: delta,
+ "event_type": "mouse_wheel",
+ "event": {"delta": delta},
}));
}
}
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) {