From 38c51e5a3e13417a1e60a50116dea884ea42beaf Mon Sep 17 00:00:00 2001 From: mrhid6 Date: Fri, 17 Jul 2026 11:42:44 +0100 Subject: [PATCH] feat: vendor guacamole-common-js and console wrapper --- web/lib/guacConsole.ts | 27 +++++++++++++++++++++++++++ web/lib/guacamole-common.js | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 web/lib/guacConsole.ts create mode 100644 web/lib/guacamole-common.js diff --git a/web/lib/guacConsole.ts b/web/lib/guacConsole.ts new file mode 100644 index 0000000..fee85fa --- /dev/null +++ b/web/lib/guacConsole.ts @@ -0,0 +1,27 @@ +// Thin wrapper over the vendored guacamole-common-js client. +// The library attaches a global `Guacamole` object when loaded. +declare const Guacamole: any; + +export function openConsole(container: HTMLElement, wsUrl: string): { disconnect: () => void } { + const tunnel = new Guacamole.WebSocketTunnel(wsUrl); + const client = new Guacamole.Client(tunnel); + + container.innerHTML = ""; + container.appendChild(client.getDisplay().getElement()); + + client.connect(""); + + // Wire keyboard + mouse. + const mouse = new Guacamole.Mouse(client.getDisplay().getElement()); + mouse.onmousedown = mouse.onmouseup = mouse.onmousemove = (state: any) => + client.sendMouseState(state); + const keyboard = new Guacamole.Keyboard(document); + keyboard.onkeydown = (k: number) => client.sendKeyEvent(1, k); + keyboard.onkeyup = (k: number) => client.sendKeyEvent(0, k); + + return { + disconnect() { + client.disconnect(); + }, + }; +} diff --git a/web/lib/guacamole-common.js b/web/lib/guacamole-common.js new file mode 100644 index 0000000..1b7007f --- /dev/null +++ b/web/lib/guacamole-common.js @@ -0,0 +1,7 @@ +/* + * guacamole-common-js v1.5.0 (Apache License 2.0) + * Vendored from npm package guacamole-common-js@1.5.0 (dist/cjs/guacamole-common.min.js). + * Trailing CommonJS "module.exports=Guacamole" replaced with "window.Guacamole=Guacamole" + * so it works as a plain browser