update
This commit is contained in:
@@ -428,7 +428,11 @@ export const initializeWebSocket = async (server: http.Server, sessionParser: Re
|
|||||||
// 传递必要信息给 connection 事件
|
// 传递必要信息给 connection 事件
|
||||||
(request as any).clientIpAddress = ipAddress;
|
(request as any).clientIpAddress = ipAddress;
|
||||||
(request as any).isRdpProxy = true; // 标记为 RDP 代理连接
|
(request as any).isRdpProxy = true; // 标记为 RDP 代理连接
|
||||||
(request as any).rdpToken = parsedUrl.query.token; // 传递 RDP token
|
// 传递 RDP token 和其他参数
|
||||||
|
(request as any).rdpToken = parsedUrl.query.token;
|
||||||
|
(request as any).rdpWidth = parsedUrl.query.width;
|
||||||
|
(request as any).rdpHeight = parsedUrl.query.height;
|
||||||
|
(request as any).rdpDpi = parsedUrl.query.dpi;
|
||||||
wss.emit('connection', extWs, request);
|
wss.emit('connection', extWs, request);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -458,11 +462,16 @@ export const initializeWebSocket = async (server: http.Server, sessionParser: Re
|
|||||||
|
|
||||||
// --- RDP 代理连接处理 ---
|
// --- RDP 代理连接处理 ---
|
||||||
if (isRdpProxy) {
|
if (isRdpProxy) {
|
||||||
|
// Retrieve all necessary parameters passed from the upgrade handler
|
||||||
const rdpToken = (request as any).rdpToken;
|
const rdpToken = (request as any).rdpToken;
|
||||||
if (!rdpToken) {
|
const rdpWidth = (request as any).rdpWidth;
|
||||||
console.error(`WebSocket: RDP Proxy connection for ${ws.username} missing token.`);
|
const rdpHeight = (request as any).rdpHeight;
|
||||||
ws.send(JSON.stringify({ type: 'rdp:error', payload: 'Missing RDP connection token.' }));
|
const rdpDpi = (request as any).rdpDpi;
|
||||||
ws.close(1008, 'Missing RDP token');
|
|
||||||
|
if (!rdpToken || !rdpWidth || !rdpHeight || !rdpDpi) {
|
||||||
|
console.error(`WebSocket: RDP Proxy connection for ${ws.username} missing required parameters (token, width, height, dpi).`);
|
||||||
|
ws.send(JSON.stringify({ type: 'rdp:error', payload: 'Missing RDP connection parameters.' }));
|
||||||
|
ws.close(1008, 'Missing RDP parameters');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +488,8 @@ export const initializeWebSocket = async (server: http.Server, sessionParser: Re
|
|||||||
|
|
||||||
// Ensure base URL doesn't end with a slash before appending query params
|
// Ensure base URL doesn't end with a slash before appending query params
|
||||||
const cleanRdpBaseUrl = rdpBaseUrl.endsWith('/') ? rdpBaseUrl.slice(0, -1) : rdpBaseUrl;
|
const cleanRdpBaseUrl = rdpBaseUrl.endsWith('/') ? rdpBaseUrl.slice(0, -1) : rdpBaseUrl;
|
||||||
const rdpTargetUrl = `${cleanRdpBaseUrl}/?token=${rdpToken}`; // Append token query param
|
// Append ALL parameters to the target URL
|
||||||
|
const rdpTargetUrl = `${cleanRdpBaseUrl}/?token=${encodeURIComponent(rdpToken)}&width=${encodeURIComponent(rdpWidth)}&height=${encodeURIComponent(rdpHeight)}&dpi=${encodeURIComponent(rdpDpi)}`;
|
||||||
|
|
||||||
console.log(`WebSocket: RDP Proxy for ${ws.username} attempting to connect to ${rdpTargetUrl}`);
|
console.log(`WebSocket: RDP Proxy for ${ws.username} attempting to connect to ${rdpTargetUrl}`);
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,20 @@ const desiredModalHeight = ref(858); // User sets the desired TOTAL modal height
|
|||||||
const MIN_MODAL_WIDTH = 1024;
|
const MIN_MODAL_WIDTH = 1024;
|
||||||
const MIN_MODAL_HEIGHT = 768;
|
const MIN_MODAL_HEIGHT = 768;
|
||||||
|
|
||||||
// Dynamically construct WebSocket URL
|
// Dynamically construct WebSocket URL based on environment
|
||||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
let backendBaseUrl: string;
|
||||||
const wsHost = window.location.hostname;
|
|
||||||
const backendPort = '3001'; // Backend WebSocket port
|
if (import.meta.env.DEV && import.meta.env.VITE_BACKEND_WS_URL) {
|
||||||
const BACKEND_WEBSOCKET_URL = `${wsProtocol}//${wsHost}:${backendPort}`; // URL for backend proxy
|
// Development mode: Use the URL specified in .env
|
||||||
|
backendBaseUrl = import.meta.env.VITE_BACKEND_WS_URL;
|
||||||
|
console.log(`[RDP Modal] Using development WebSocket Base URL from env: ${backendBaseUrl}`);
|
||||||
|
} else {
|
||||||
|
// Production mode: Construct URL based on current window location
|
||||||
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
const wsHostAndPort = window.location.host;
|
||||||
|
backendBaseUrl = `${wsProtocol}//${wsHostAndPort}`;
|
||||||
|
console.log(`[RDP Modal] Using production WebSocket Base URL from window.location: ${backendBaseUrl}`);
|
||||||
|
}
|
||||||
// Removed localStorage keys
|
// Removed localStorage keys
|
||||||
|
|
||||||
const connectRdp = async () => { // Removed useInputValues parameter
|
const connectRdp = async () => { // Removed useInputValues parameter
|
||||||
@@ -91,8 +100,8 @@ const connectRdp = async () => { // Removed useInputValues parameter
|
|||||||
// Consider setting an error state or notifying the user
|
// Consider setting an error state or notifying the user
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct URL for the backend proxy endpoint
|
// Construct URL for the backend proxy endpoint using the determined base URL
|
||||||
const tunnelUrl = `${BACKEND_WEBSOCKET_URL}/rdp-proxy?token=${encodeURIComponent(token)}&width=${widthToSend}&height=${heightToSend}&dpi=${dpiToSend}`;
|
const tunnelUrl = `${backendBaseUrl}/rdp-proxy?token=${encodeURIComponent(token)}&width=${widthToSend}&height=${heightToSend}&dpi=${dpiToSend}`;
|
||||||
console.log(`[RDP Modal] Connecting to tunnel: ${tunnelUrl}`); // Log the final URL
|
console.log(`[RDP Modal] Connecting to tunnel: ${tunnelUrl}`); // Log the final URL
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const tunnel = new Guacamole.WebSocketTunnel(tunnelUrl);
|
const tunnel = new Guacamole.WebSocketTunnel(tunnelUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user