Fix layout bug, tabs height, and RDP tunnel UUID handshake
- MainLayout: replace inner <Layout> with row-flex div so sidebar and session tabs appear side-by-side instead of stacked vertically - global.css: add Ant Design Tabs CSS overrides so tab pane content fills available height (SSH terminal and RDP canvas sized correctly) - rdp.ts: send guacd's ready-UUID as first WebSocket message so Guacamole.WebSocketTunnel completes its tunnel handshake correctly - RdpTab: add connecting/error/disconnected status overlays for visibility when RDP fails Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { createConnection, Socket } from 'net';
|
import { createConnection, Socket } from 'net';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
import { FastifyInstance, FastifyRequest } from 'fastify';
|
import { FastifyInstance, FastifyRequest } from 'fastify';
|
||||||
import { SocketStream } from '@fastify/websocket';
|
import { SocketStream } from '@fastify/websocket';
|
||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
@@ -165,7 +166,12 @@ export async function rdpWebsocket(fastify: FastifyInstance) {
|
|||||||
throw new Error(`guacd handshake failed: expected 'ready', got '${readyInstruction[0]}'`);
|
throw new Error(`guacd handshake failed: expected 'ready', got '${readyInstruction[0]}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Flush any buffered bytes that arrived after 'ready'
|
// 5. Send the guacd connection UUID as the first WebSocket message.
|
||||||
|
// Guacamole.WebSocketTunnel expects this as its tunnel-UUID handshake.
|
||||||
|
const guacdUUID = readyInstruction[1] ?? randomUUID();
|
||||||
|
socket.send(guacdUUID);
|
||||||
|
|
||||||
|
// 6. Flush any buffered bytes that arrived after 'ready'
|
||||||
if (tcpBuf.value.length > 0 && socket.readyState === WebSocket.OPEN) {
|
if (tcpBuf.value.length > 0 && socket.readyState === WebSocket.OPEN) {
|
||||||
socket.send(tcpBuf.value);
|
socket.send(tcpBuf.value);
|
||||||
tcpBuf.value = '';
|
tcpBuf.value = '';
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export const MainLayout: React.FC = () => {
|
|||||||
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
||||||
<TopNav />
|
<TopNav />
|
||||||
|
|
||||||
<Layout style={{ flex: 1, overflow: 'hidden' }}>
|
<div style={{ display: 'flex', flexDirection: 'row', flex: 1, overflow: 'hidden' }}>
|
||||||
{/* Resizable sidebar */}
|
{/* Resizable sidebar */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -89,7 +89,7 @@ export const MainLayout: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<SessionTabs />
|
<SessionTabs />
|
||||||
</Content>
|
</Content>
|
||||||
</Layout>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
|
import { Alert, Spin } from 'antd';
|
||||||
import Guacamole from 'guacamole-common-js';
|
import Guacamole from 'guacamole-common-js';
|
||||||
import { useStore } from '../../store';
|
import { useStore } from '../../store';
|
||||||
import { Session } from '../../types';
|
import { Session } from '../../types';
|
||||||
@@ -7,6 +8,8 @@ interface Props {
|
|||||||
session: Session;
|
session: Session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Status = 'connecting' | 'connected' | 'disconnected' | 'error';
|
||||||
|
|
||||||
function getWsUrl(connectionId: string, token: string): string {
|
function getWsUrl(connectionId: string, token: string): string {
|
||||||
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const host = window.location.host;
|
const host = window.location.host;
|
||||||
@@ -16,11 +19,16 @@ function getWsUrl(connectionId: string, token: string): string {
|
|||||||
export const RdpTab: React.FC<Props> = ({ session }) => {
|
export const RdpTab: React.FC<Props> = ({ session }) => {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const token = useStore((s) => s.token) ?? '';
|
const token = useStore((s) => s.token) ?? '';
|
||||||
|
const [status, setStatus] = useState<Status>('connecting');
|
||||||
|
const [errorMsg, setErrorMsg] = useState<string>('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const container = containerRef.current;
|
const container = containerRef.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
|
setStatus('connecting');
|
||||||
|
setErrorMsg('');
|
||||||
|
|
||||||
const url = getWsUrl(session.connection.id, token);
|
const url = getWsUrl(session.connection.id, token);
|
||||||
const tunnel = new Guacamole.WebSocketTunnel(url);
|
const tunnel = new Guacamole.WebSocketTunnel(url);
|
||||||
const client = new Guacamole.Client(tunnel);
|
const client = new Guacamole.Client(tunnel);
|
||||||
@@ -30,7 +38,7 @@ export const RdpTab: React.FC<Props> = ({ session }) => {
|
|||||||
displayEl.style.cursor = 'default';
|
displayEl.style.cursor = 'default';
|
||||||
container.appendChild(displayEl);
|
container.appendChild(displayEl);
|
||||||
|
|
||||||
// Mouse input — forward all mouse events to guacd
|
// Mouse input
|
||||||
const mouse = new Guacamole.Mouse(displayEl);
|
const mouse = new Guacamole.Mouse(displayEl);
|
||||||
const sendMouse = (mouseState: Guacamole.Mouse.State) =>
|
const sendMouse = (mouseState: Guacamole.Mouse.State) =>
|
||||||
client.sendMouseState(mouseState, true);
|
client.sendMouseState(mouseState, true);
|
||||||
@@ -52,21 +60,29 @@ export const RdpTab: React.FC<Props> = ({ session }) => {
|
|||||||
display.scale(Math.min(scaleX, scaleY));
|
display.scale(Math.min(scaleX, scaleY));
|
||||||
};
|
};
|
||||||
|
|
||||||
client.getDisplay().onresize = fitDisplay;
|
client.getDisplay().onresize = () => {
|
||||||
|
setStatus('connected');
|
||||||
|
fitDisplay();
|
||||||
|
};
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(fitDisplay);
|
const resizeObserver = new ResizeObserver(fitDisplay);
|
||||||
resizeObserver.observe(container);
|
resizeObserver.observe(container);
|
||||||
|
|
||||||
// Connect
|
|
||||||
client.connect();
|
|
||||||
|
|
||||||
tunnel.onerror = (status: Guacamole.Status) => {
|
tunnel.onerror = (status: Guacamole.Status) => {
|
||||||
console.error('Guacamole tunnel error:', status.message);
|
console.error('Guacamole tunnel error:', status.message);
|
||||||
|
setStatus('error');
|
||||||
|
setErrorMsg(`Tunnel error: ${status.message ?? 'unknown'}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
client.onerror = (error: Guacamole.Status) => {
|
client.onerror = (error: Guacamole.Status) => {
|
||||||
console.error('Guacamole client error:', error.message);
|
console.error('Guacamole client error:', error.message);
|
||||||
|
setStatus('error');
|
||||||
|
setErrorMsg(`Client error: ${error.message ?? 'unknown'}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
client.connect();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
keyboard.onkeydown = null;
|
keyboard.onkeydown = null;
|
||||||
keyboard.onkeyup = null;
|
keyboard.onkeyup = null;
|
||||||
@@ -80,16 +96,66 @@ export const RdpTab: React.FC<Props> = ({ session }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
background: '#000',
|
background: '#000',
|
||||||
|
position: 'relative',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
}}
|
}}
|
||||||
|
>
|
||||||
|
{/* Guacamole canvas is appended here by the effect */}
|
||||||
|
<div ref={containerRef} style={{ width: '100%', height: '100%' }} />
|
||||||
|
|
||||||
|
{/* Status overlays */}
|
||||||
|
{status === 'connecting' && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
inset: 0,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
background: '#000a',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Spin size="large" tip="Connecting to RDP…" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status === 'error' && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 16,
|
||||||
|
left: 16,
|
||||||
|
right: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Alert
|
||||||
|
type="error"
|
||||||
|
showIcon
|
||||||
|
message="RDP Connection Failed"
|
||||||
|
description={errorMsg || 'See browser console for details.'}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status === 'disconnected' && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 16,
|
||||||
|
left: 16,
|
||||||
|
right: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Alert type="warning" showIcon message="RDP session disconnected." />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
19
frontend/src/global.css
Normal file
19
frontend/src/global.css
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* Reset */
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body { margin: 0; padding: 0; }
|
||||||
|
|
||||||
|
/* Ant Design Tabs: ensure tab content fills available height */
|
||||||
|
.ant-tabs.ant-tabs-top {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.ant-tabs-content-holder {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.ant-tabs-content {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.ant-tabs-tabpane {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
|
import './global.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
|
|||||||
Reference in New Issue
Block a user