|
@@ -3,377 +3,21 @@
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
- <meta name="description" content="RemdesKVM Management Interface">
|
|
|
+ <meta name="description" content="dezuKVM Management Interface">
|
|
|
<meta name="author" content="imuslab">
|
|
|
- <title>Connected | RemdesKVM</title>
|
|
|
+ <title>Connected | dezuKVM</title>
|
|
|
|
|
|
<!-- OpenGraph Metadata -->
|
|
|
- <meta property="og:title" content="RemdesKVM Management Interface">
|
|
|
- <meta property="og:description" content="A web-based management interface for RemdesKVM">
|
|
|
+ <meta property="og:title" content="dezuKVM Management Interface">
|
|
|
+ <meta property="og:description" content="A web-based management interface for dezuKVM">
|
|
|
<meta property="og:type" content="website">
|
|
|
<meta property="og:url" content="https://kvm.aroz.org">
|
|
|
<meta property="og:image" content="https://kvm.aroz.org/og.jpg">
|
|
|
- <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
|
|
- <link rel="stylesheet" href="/main.css">
|
|
|
+ <script src="js/jquery-3.7.1.min.js"></script>
|
|
|
+ <link rel="stylesheet" href="main.css">
|
|
|
</head>
|
|
|
<body>
|
|
|
<img id="remoteCapture" src="/stream" oncontextmenu="return false;"></img>
|
|
|
- <script>
|
|
|
- let socket;
|
|
|
- let protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
|
|
- let port = window.location.port ? window.location.port : (protocol === 'wss' ? 443 : 80);
|
|
|
- let socketURL = `${protocol}://${window.location.hostname}:${port}/hid`;
|
|
|
- let mouseMoveAbsolte = true; // Set to true for absolute mouse coordinates, false for relativeZ
|
|
|
- let mouseIsOutside = false;
|
|
|
- let audioFrontendStarted = false;
|
|
|
-
|
|
|
- /* Mouse events */
|
|
|
- function handleMouseMove(event) {
|
|
|
- const hidCommand = {
|
|
|
- event: 2,
|
|
|
- mouse_x: event.clientX,
|
|
|
- mouse_y: event.clientY,
|
|
|
- };
|
|
|
-
|
|
|
- const rect = event.target.getBoundingClientRect();
|
|
|
- const relativeX = event.clientX - rect.left;
|
|
|
- const relativeY = event.clientY - rect.top;
|
|
|
-
|
|
|
- if (relativeX < 0 || relativeY < 0 || relativeX > rect.width || relativeY > rect.height) {
|
|
|
- mouseIsOutside = true;
|
|
|
- return; // Mouse is outside the client rect
|
|
|
- }
|
|
|
- mouseIsOutside = false;
|
|
|
- const percentageX = (relativeX / rect.width) * 4096;
|
|
|
- const percentageY = (relativeY / rect.height) * 4096;
|
|
|
-
|
|
|
- hidCommand.mouse_x = Math.round(percentageX);
|
|
|
- hidCommand.mouse_y = Math.round(percentageY);
|
|
|
-
|
|
|
- //console.log(`Mouse move: (${event.clientX}, ${event.clientY})`);
|
|
|
- //console.log(`Mouse move relative: (${relativeX}, ${relativeY})`);
|
|
|
- //console.log(`Mouse move percentage: (${hidCommand.mouse_x}, ${hidCommand.mouse_y})`);
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- function handleMousePress(event) {
|
|
|
- event.preventDefault();
|
|
|
- event.stopImmediatePropagation();
|
|
|
- if (mouseIsOutside) {
|
|
|
- console.warn("Mouse is outside the capture area, ignoring mouse press.");
|
|
|
- return;
|
|
|
- }
|
|
|
- const buttonMap = {
|
|
|
- 0: 1,
|
|
|
- 1: 3,
|
|
|
- 2: 2
|
|
|
- }; //Map javascript mouse buttons to HID buttons
|
|
|
-
|
|
|
- const hidCommand = {
|
|
|
- event: 3,
|
|
|
- mouse_button: buttonMap[event.button] || 0
|
|
|
- };
|
|
|
-
|
|
|
- // Log the mouse button state
|
|
|
- console.log(`Mouse down: ${hidCommand.mouse_button}`);
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
-
|
|
|
- if (!audioFrontendStarted){
|
|
|
- startAudioWebSocket();
|
|
|
- audioFrontendStarted = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function handleMouseRelease(event) {
|
|
|
- event.preventDefault();
|
|
|
- event.stopImmediatePropagation();
|
|
|
- if (mouseIsOutside) {
|
|
|
- console.warn("Mouse is outside the capture area, ignoring mouse press.");
|
|
|
- return;
|
|
|
- }
|
|
|
- const buttonMap = {
|
|
|
- 0: 1,
|
|
|
- 1: 3,
|
|
|
- 2: 2
|
|
|
- }; //Map javascript mouse buttons to HID buttons
|
|
|
-
|
|
|
- const hidCommand = {
|
|
|
- event: 4,
|
|
|
- mouse_button: buttonMap[event.button] || 0
|
|
|
- };
|
|
|
-
|
|
|
- console.log(`Mouse release: ${hidCommand.mouse_button}`);
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function handleMouseScroll(event) {
|
|
|
- const hidCommand = {
|
|
|
- event: 5,
|
|
|
- mouse_scroll: event.deltaY
|
|
|
- };
|
|
|
- if (mouseIsOutside) {
|
|
|
- console.warn("Mouse is outside the capture area, ignoring mouse press.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- console.log(`Mouse scroll: mouse_scroll=${event.deltaY}`);
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Attach mouse event listeners
|
|
|
- let remoteCaptureEle = document.getElementById('remoteCapture');
|
|
|
- remoteCaptureEle.addEventListener('mousemove', handleMouseMove);
|
|
|
- remoteCaptureEle.addEventListener('mousedown', handleMousePress);
|
|
|
- remoteCaptureEle.addEventListener('mouseup', handleMouseRelease);
|
|
|
- remoteCaptureEle.addEventListener('wheel', handleMouseScroll);
|
|
|
-
|
|
|
- /* Keyboard */
|
|
|
- function isNumpadEvent(event) {
|
|
|
- return event.location === 3;
|
|
|
- }
|
|
|
-
|
|
|
- function handleKeyDown(event) {
|
|
|
- event.preventDefault();
|
|
|
- event.stopImmediatePropagation();
|
|
|
- const key = event.key;
|
|
|
- let hidCommand = {
|
|
|
- event: 0,
|
|
|
- keycode: event.keyCode
|
|
|
- };
|
|
|
-
|
|
|
- console.log(`Key down: ${key} (code: ${event.keyCode})`);
|
|
|
-
|
|
|
- // Check if the key is a modkey on the right side of the keyboard
|
|
|
- const rightModKeys = ['Control', 'Alt', 'Shift', 'Meta'];
|
|
|
- if (rightModKeys.includes(key) && event.location === 2) {
|
|
|
- hidCommand.is_right_modifier_key = true;
|
|
|
- }else if (key === 'Enter' && isNumpadEvent(event)) {
|
|
|
- //Special case for Numpad Enter
|
|
|
- hidCommand.is_right_modifier_key = true;
|
|
|
- }else{
|
|
|
- hidCommand.is_right_modifier_key = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function handleKeyUp(event) {
|
|
|
- event.preventDefault();
|
|
|
- event.stopImmediatePropagation();
|
|
|
- const key = event.key;
|
|
|
-
|
|
|
- let hidCommand = {
|
|
|
- event: 1,
|
|
|
- keycode: event.keyCode
|
|
|
- };
|
|
|
-
|
|
|
- console.log(`Key up: ${key} (code: ${event.keyCode})`);
|
|
|
-
|
|
|
- // Check if the key is a modkey on the right side of the keyboard
|
|
|
- const rightModKeys = ['Control', 'Alt', 'Shift', 'Meta'];
|
|
|
- if (rightModKeys.includes(key) && event.location === 2) {
|
|
|
- hidCommand.is_right_modifier_key = true;
|
|
|
- } else if (key === 'Enter' && isNumpadEvent(event)) {
|
|
|
- //Special case for Numpad Enter
|
|
|
- hidCommand.is_right_modifier_key = true;
|
|
|
- }else{
|
|
|
- hidCommand.is_right_modifier_key = false;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (socket && socket.readyState === WebSocket.OPEN) {
|
|
|
- socket.send(JSON.stringify(hidCommand));
|
|
|
- } else {
|
|
|
- console.error("WebSocket is not open.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* Start and Stop events */
|
|
|
- function startWebSocket(){
|
|
|
- if (socket){
|
|
|
- //Already started
|
|
|
- alert("Websocket already started");
|
|
|
- return;
|
|
|
- }
|
|
|
- const socketUrl = socketURL;
|
|
|
- socket = new WebSocket(socketUrl);
|
|
|
-
|
|
|
- socket.addEventListener('open', function(event) {
|
|
|
- console.log('WebSocket is connected.');
|
|
|
- });
|
|
|
-
|
|
|
- socket.addEventListener('message', function(event) {
|
|
|
- //console.log('Message from server ', event.data);
|
|
|
- });
|
|
|
-
|
|
|
- document.addEventListener('keydown', handleKeyDown);
|
|
|
- document.addEventListener('keyup', handleKeyUp);
|
|
|
- }
|
|
|
-
|
|
|
- function stopWebSocket(){
|
|
|
- if (!socket){
|
|
|
- alert("No ws connection to stop");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- socket.close();
|
|
|
- console.log('WebSocket is disconnected.');
|
|
|
- document.removeEventListener('keydown', handleKeyDown);
|
|
|
- document.removeEventListener('keyup', handleKeyUp);
|
|
|
- }
|
|
|
-
|
|
|
- /* Audio Streaming Frontend */
|
|
|
- let audioSocket;
|
|
|
- let audioContext;
|
|
|
- let audioQueue = [];
|
|
|
- let audioPlaying = false;
|
|
|
-
|
|
|
- //accept low, standard, high quality audio mode
|
|
|
- function startAudioWebSocket(quality="standard") {
|
|
|
- if (audioSocket) {
|
|
|
- console.warn("Audio WebSocket already started");
|
|
|
- return;
|
|
|
- }
|
|
|
- let protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
|
|
- let port = window.location.port ? window.location.port : (protocol === 'wss' ? 443 : 80);
|
|
|
- let audioSocketURL = `${protocol}://${window.location.hostname}:${port}/audio?quality=${quality}`;
|
|
|
-
|
|
|
- audioSocket = new WebSocket(audioSocketURL);
|
|
|
- audioSocket.binaryType = 'arraybuffer';
|
|
|
-
|
|
|
- audioSocket.onopen = function() {
|
|
|
- console.log("Audio WebSocket connected");
|
|
|
- if (!audioContext) {
|
|
|
- audioContext = new (window.AudioContext || window.webkitAudioContext)({sampleRate: 24000});
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- const MAX_AUDIO_QUEUE = 8;
|
|
|
- let PCM_SAMPLE_RATE;
|
|
|
- if (quality == "high"){
|
|
|
- PCM_SAMPLE_RATE = 48000; // Use 48kHz for high quality
|
|
|
- } else if (quality == "low") {
|
|
|
- PCM_SAMPLE_RATE = 16000; // Use 24kHz for low quality
|
|
|
- } else {
|
|
|
- PCM_SAMPLE_RATE = 24000; // Default to 24kHz for standard quality
|
|
|
- }
|
|
|
- let scheduledTime = 0;
|
|
|
- audioSocket.onmessage = function(event) {
|
|
|
- if (!audioContext) return;
|
|
|
- let pcm = new Int16Array(event.data);
|
|
|
- if (pcm.length === 0) {
|
|
|
- console.warn("Received empty PCM data");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (pcm.length % 2 !== 0) {
|
|
|
- console.warn("Received PCM data with odd length, dropping last sample");
|
|
|
- pcm = pcm.slice(0, -1);
|
|
|
- }
|
|
|
- // Convert Int16 PCM to Float32 [-1, 1]
|
|
|
- let floatBuf = new Float32Array(pcm.length);
|
|
|
- for (let i = 0; i < pcm.length; i++) {
|
|
|
- floatBuf[i] = pcm[i] / 32768;
|
|
|
- }
|
|
|
- // Limit queue size to prevent memory overflow
|
|
|
- if (audioQueue.length >= MAX_AUDIO_QUEUE) {
|
|
|
- audioQueue.shift();
|
|
|
- }
|
|
|
- audioQueue.push(floatBuf);
|
|
|
- scheduleAudioPlayback();
|
|
|
- };
|
|
|
-
|
|
|
- audioSocket.onclose = function() {
|
|
|
- console.log("Audio WebSocket closed");
|
|
|
- audioSocket = null;
|
|
|
- audioPlaying = false;
|
|
|
- audioQueue = [];
|
|
|
- scheduledTime = 0;
|
|
|
- };
|
|
|
-
|
|
|
- audioSocket.onerror = function(e) {
|
|
|
- console.error("Audio WebSocket error", e);
|
|
|
- };
|
|
|
-
|
|
|
- function scheduleAudioPlayback() {
|
|
|
- if (!audioContext || audioQueue.length === 0) return;
|
|
|
-
|
|
|
- // Use audioContext.currentTime to schedule buffers back-to-back
|
|
|
- if (scheduledTime < audioContext.currentTime) {
|
|
|
- scheduledTime = audioContext.currentTime;
|
|
|
- }
|
|
|
-
|
|
|
- while (audioQueue.length > 0) {
|
|
|
- let floatBuf = audioQueue.shift();
|
|
|
- let frameCount = floatBuf.length / 2;
|
|
|
- let buffer = audioContext.createBuffer(2, frameCount, PCM_SAMPLE_RATE);
|
|
|
- for (let ch = 0; ch < 2; ch++) {
|
|
|
- let channelData = buffer.getChannelData(ch);
|
|
|
- for (let i = 0; i < frameCount; i++) {
|
|
|
- channelData[i] = floatBuf[i * 2 + ch];
|
|
|
- }
|
|
|
- }
|
|
|
- let source = audioContext.createBufferSource();
|
|
|
- source.buffer = buffer;
|
|
|
- source.connect(audioContext.destination);
|
|
|
- source.start(scheduledTime);
|
|
|
- scheduledTime += buffer.duration;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function stopAudioWebSocket() {
|
|
|
- if (!audioSocket) {
|
|
|
- console.warn("No audio WebSocket to stop");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (audioSocket.readyState === WebSocket.OPEN) {
|
|
|
- audioSocket.send("exit");
|
|
|
- }
|
|
|
- audioSocket.onclose = null; // Prevent onclose from being called again
|
|
|
- audioSocket.onerror = null; // Prevent onerror from being called again
|
|
|
- audioSocket.close();
|
|
|
- audioSocket = null;
|
|
|
- audioPlaying = false;
|
|
|
- audioQueue = [];
|
|
|
- if (audioContext) {
|
|
|
- audioContext.close();
|
|
|
- audioContext = null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- startWebSocket();
|
|
|
-
|
|
|
- window.addEventListener('beforeunload', function() {
|
|
|
- stopAudioWebSocket();
|
|
|
- });
|
|
|
- </script>
|
|
|
+ <script src="kvmevt.js"></script>
|
|
|
</body>
|
|
|
</html>
|