MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / RdpViewer

Function RdpViewer

frontend/src/components/RdpViewer.jsx:354–858  ·  view source on GitHub ↗
({ host, isOpen })

Source from the content-addressed store, hash-verified

352);
353
354const RdpViewer = ({ host, isOpen }) => {
355 const displayRef = useRef(null);
356 const clientRef = useRef(null);
357 const tunnelRef = useRef(null);
358 const mouseRef = useRef(null);
359 const keyboardRef = useRef(null);
360 const resizeObserverRef = useRef(null);
361 const pasteHandlerRef = useRef(null);
362
363 const [isConnecting, setIsConnecting] = useState(false);
364 const [isConnected, setIsConnected] = useState(false);
365 const [error, setError] = useState(null); // { code, message } | null
366 const [isFullscreen, setIsFullscreen] = useState(false);
367 const [requirementsOpen, setRequirementsOpen] = useState(false);
368 const [credentials, setCredentials] = useState({
369 username: "",
370 password: "",
371 });
372
373 const clearCredentials = useCallback(() => {
374 setCredentials({
375 username: "",
376 password: "",
377 });
378 }, []);
379
380 /** Scale the Guacamole display to fit the container */
381 const scaleDisplay = useCallback(() => {
382 const client = clientRef.current;
383 const container = displayRef.current;
384 if (!client || !container) return;
385
386 const display = client.getDisplay();
387 const displayWidth = display.getWidth();
388 const displayHeight = display.getHeight();
389 if (!displayWidth || !displayHeight) return;
390
391 const containerWidth = container.offsetWidth;
392 const containerHeight = container.offsetHeight;
393 const scale = Math.min(
394 containerWidth / displayWidth,
395 containerHeight / displayHeight,
396 );
397
398 display.scale(scale);
399 }, []);
400
401 const disconnect = useCallback(
402 (options = {}) => {
403 if (pasteHandlerRef.current && displayRef.current) {
404 displayRef.current.removeEventListener(
405 "paste",
406 pasteHandlerRef.current,
407 );
408 pasteHandlerRef.current = null;
409 }
410 if (resizeObserverRef.current) {
411 resizeObserverRef.current.disconnect();

Callers

nothing calls this directly

Calls 3

connectMethod · 0.95
deriveCodeFromHttpErrorFunction · 0.85
deriveCodeFromGuacStatusFunction · 0.85

Tested by

no test coverage detected