1import React from 'react';
2import { apiFetch } from '../../lib/api';
3import MeshDesktopViewer from '../../components/RemoteDesktop/MeshDesktopViewer';
5function TabRds({ agentId, agentUuid }) {
7 const [meshInfo, setMeshInfo] = React.useState(null);
8 const [meshLoading, setMeshLoading] = React.useState(false);
9 const [meshError, setMeshError] = React.useState(null);
11 // Load MeshCentral URL function (accessible for retry button)
12 const loadMeshCentralUrl = React.useCallback(async () => {
17 const response = await apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`);
20 const errorData = await response.json();
21 throw new Error(errorData.error || 'Failed to get MeshCentral URL');
24 const data = await response.json();
28 console.error('[RDS] Failed to load MeshCentral URL:', err);
29 setMeshError(err.message);
31 setMeshLoading(false);
33 }, [agentUuid, agentId]);
35 // Load MeshCentral URL when component mounts or agentUuid/agentId changes
36 React.useEffect(() => {
37 if (agentUuid || agentId) {
40 }, [agentUuid, agentId, loadMeshCentralUrl]);
43 <div className="tab-container" style={{ height: 'calc(100vh - 200px)', display: 'flex', flexDirection: 'column' }}>
44 <h2 style={{ marginBottom: '1rem' }}>Remote Desktop</h2>
47 <div className="card" style={{ textAlign: 'center', padding: '3rem' }}>
48 <div className="spinner" style={{ margin: '0 auto 1rem' }}></div>
49 <p>Loading MeshCentral connection...</p>
52 <div className="card" style={{ textAlign: 'center', padding: '2rem' }}>
53 <div style={{ fontSize: '3rem', marginBottom: '1rem' }}>⚠️</div>
54 <h3>Connection Error</h3>
55 <p style={{ color: '#d32f2f', marginBottom: '1rem' }}>{meshError}</p>
56 <p style={{ fontSize: '0.9em', color: '#666', marginBottom: '1.5rem' }}>
57 Make sure the MeshAgent is installed and connected to this device.
59 <button className="btn" onClick={loadMeshCentralUrl}>
63 ) : meshInfo?.meshcentralNodeId ? (
64 <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
66 meshcentralNodeId={meshInfo.meshcentralNodeId}
67 meshcentralUrl={meshInfo.remoteDesktopUrl?.split('/login')[0] || process.env.REACT_APP_MESHCENTRAL_URL}
74 <div className="card">