Files
vantage/web/lib/guacConsole.ts
T
mrhid6 a02747d02e
Server Deploy / deploy (push) Successful in 44s
fix: Fixed console resolution
2026-07-20 09:30:44 +01:00

37 lines
1.2 KiB
TypeScript

// 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,
connectData = ""
): { disconnect: () => void; setScale: (scale: number) => void } {
// Guacamole's WebSocketTunnel builds the socket URL as `wsUrl + "?" + data`,
// so wsUrl must NOT already contain a query string — pass params via connectData.
const tunnel = new Guacamole.WebSocketTunnel(wsUrl);
const client = new Guacamole.Client(tunnel);
container.innerHTML = "";
container.appendChild(client.getDisplay().getElement());
client.connect(connectData);
// 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();
},
setScale(scale: number) {
client.getDisplay().scale(scale);
},
};
}