summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-06-07 05:12:22 +0300
committerMaxim Devaev <[email protected]>2023-06-07 05:12:22 +0300
commit9f98a2f701703a3f9f591868547c834463d3d6b1 (patch)
treef2fe4f4541c78edaa6ec791a304d73f0595d4751 /web
parent9c694da00c7d93cbff3aa910ffdeeb8dded691c0 (diff)
binary keyboard protocol
Diffstat (limited to 'web')
-rw-r--r--web/share/js/kvm/keyboard.js2
-rw-r--r--web/share/js/kvm/mouse.js33
-rw-r--r--web/share/js/kvm/recorder.js2
-rw-r--r--web/share/js/kvm/session.js43
4 files changed, 47 insertions, 33 deletions
diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js
index 7cbdc1e8..b398e769 100644
--- a/web/share/js/kvm/keyboard.js
+++ b/web/share/js/kvm/keyboard.js
@@ -134,7 +134,7 @@ export function Keyboard(__recordWsEvent) {
"event": {"key": code, "state": state},
};
if (__ws && !$("hid-mute-switch").checked) {
- __ws.send(JSON.stringify(event));
+ __ws.sendHidEvent(event);
}
__recordWsEvent(event);
};
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index fb510d27..f2d6afde 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -345,38 +345,11 @@ export function Mouse(__getGeometry, __recordWsEvent) {
};
var __sendEvent = function(event_type, event) {
- let wrapped_event = {"event_type": event_type, "event": event};
+ event = {"event_type": event_type, "event": event};
if (__ws && !$("hid-mute-switch").checked) {
- if (event_type == "mouse_move") {
- let data = new Uint8Array([
- 3,
- (event.to.x >> 8) & 0xFF, event.to.x & 0xFF,
- (event.to.y >> 8) & 0xFF, event.to.y & 0xFF,
- ]);
- __ws.send(data);
-
- } else if (event_type == "mouse_relative" || event_type == "mouse_wheel") {
- let data;
- if (Array.isArray(event.delta)) {
- data = new Int8Array(2 + event.delta.length * 2);
- let index = 0;
- for (let delta of event.delta) {
- data[index + 2] = delta["x"];
- data[index + 3] = delta["y"];
- index += 2;
- }
- } else {
- data = new Int8Array([0, 0, event.delta.x, event.delta.y]);
- }
- data[0] = (event_type == "mouse_relative" ? 4 : 5);
- data[1] = (event.squash ? 1 : 0);
- __ws.send(data);
-
- } else {
- __ws.send(JSON.stringify(wrapped_event));
- }
+ __ws.sendHidEvent(event);
}
- __recordWsEvent(wrapped_event);
+ __recordWsEvent(event);
};
__init__();
diff --git a/web/share/js/kvm/recorder.js b/web/share/js/kvm/recorder.js
index 8f6683f7..88e5bbe5 100644
--- a/web/share/js/kvm/recorder.js
+++ b/web/share/js/kvm/recorder.js
@@ -290,7 +290,7 @@ export function Recorder() {
return;
} else if (["key", "mouse_button", "mouse_move", "mouse_wheel", "mouse_relative"].includes(event.event_type)) {
- __ws.send(JSON.stringify(event));
+ __ws.sendHidEvent(event);
}
index += 1;
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index 25159a4f..277e786d 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -278,6 +278,7 @@ export function Session() {
if (http.readyState === 4) {
if (http.status === 200) {
__ws = new WebSocket(`${tools.is_https ? "wss" : "ws"}://${location.host}/api/ws`);
+ __ws.sendHidEvent = (event) => __sendHidEvent(__ws, event.event_type, event.event);
__ws.onopen = __wsOpenHandler;
__ws.onmessage = __wsMessageHandler;
__ws.onerror = __wsErrorHandler;
@@ -294,6 +295,46 @@ export function Session() {
});
};
+ var __ascii_encoder = new TextEncoder("ascii");
+
+ var __sendHidEvent = function(ws, event_type, event) {
+ if (event_type == "key") {
+ let data = __ascii_encoder.encode("\x01\x00" + event.key);
+ data[1] = (event.state ? 1 : 0);
+ ws.send(data);
+
+ } else if (event_type == "mouse_button") {
+ let data = __ascii_encoder.encode("\x02\x00" + event.button);
+ data[1] = (event.state ? 1 : 0);
+ ws.send(data);
+
+ } else if (event_type == "mouse_move") {
+ let data = new Uint8Array([
+ 3,
+ (event.to.x >> 8) & 0xFF, event.to.x & 0xFF,
+ (event.to.y >> 8) & 0xFF, event.to.y & 0xFF,
+ ]);
+ ws.send(data);
+
+ } else if (event_type == "mouse_relative" || event_type == "mouse_wheel") {
+ let data;
+ if (Array.isArray(event.delta)) {
+ data = new Int8Array(2 + event.delta.length * 2);
+ let index = 0;
+ for (let delta of event.delta) {
+ data[index + 2] = delta["x"];
+ data[index + 3] = delta["y"];
+ index += 2;
+ }
+ } else {
+ data = new Int8Array([0, 0, event.delta.x, event.delta.y]);
+ }
+ data[0] = (event_type == "mouse_relative" ? 4 : 5);
+ data[1] = (event.squash ? 1 : 0);
+ ws.send(data);
+ }
+ };
+
var __wsOpenHandler = function(event) {
tools.debug("Session: socket opened:", event);
$("link-led").className = "led-green";
@@ -365,7 +406,7 @@ export function Session() {
if (__missed_heartbeats >= 15) {
throw new Error("Too many missed heartbeats");
}
- __ws.send(JSON.stringify({"event_type": "ping", "event": {}}));
+ __ws.send("{\"event_type\": \"ping\", \"event\": {}}");
} catch (err) {
tools.error("Session: ping error:", err.message);
if (__ws) {