Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Error handler
guac.onerror = (error) => console.log(error.message);
window.onunload = () => guac.disconnect();
// Mouse
const mouse = new Guacamole.Mouse(guac.getDisplay().getElement());
mouse.onmousemove = (mouseState) => {
if (navigator.userAgent.indexOf('Firefox') === -1) {
mouseState.x = mouseState.x + 125;
mouseState.y = mouseState.y + 65;
}
guac.sendMouseState(mouseState);
}
const keyboard = new Guacamole.Keyboard(document);
keyboard.onkeydown = (keysym) => guac.sendKeyEvent(1, keysym);
keyboard.onkeyup = (keysym) => guac.sendKeyEvent(0, keysym);
}
}
useEffect(() => {
// don't bind to events if we know this input will not be accepted at server side
if (!controlInput) {
return;
}
// Keyboard
let keyboard = new Guacamole.Keyboard(displayRef.current);
const fixKeys = (keysym) => {
// 65508 - Right Ctrl
// 65507 - Left Ctrl
// somehow Right Ctrl is not sent, so send Left Ctrl instead
if (keysym === 65508) return 65507;
return keysym
};
keyboard.onkeydown = function (keysym) {
guacRef.current.sendKeyEvent(1, fixKeys(keysym));
};
keyboard.onkeyup = function (keysym) {
guacRef.current.sendKeyEvent(0, fixKeys(keysym));