EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabRds.jsx
Go to the documentation of this file.
1import React from 'react';
2import { apiFetch } from '../../lib/api';
3import MeshDesktopViewer from '../../components/RemoteDesktop/MeshDesktopViewer';
4
5function TabRds({ agentId, agentUuid }) {
6 // MeshCentral state
7 const [meshInfo, setMeshInfo] = React.useState(null);
8 const [meshLoading, setMeshLoading] = React.useState(false);
9 const [meshError, setMeshError] = React.useState(null);
10
11 // Load MeshCentral URL function (accessible for retry button)
12 const loadMeshCentralUrl = React.useCallback(async () => {
13 setMeshLoading(true);
14 setMeshError(null);
15
16 try {
17 const response = await apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`);
18
19 if (!response.ok) {
20 const errorData = await response.json();
21 throw new Error(errorData.error || 'Failed to get MeshCentral URL');
22 }
23
24 const data = await response.json();
25 setMeshInfo(data);
26
27 } catch (err) {
28 console.error('[RDS] Failed to load MeshCentral URL:', err);
29 setMeshError(err.message);
30 } finally {
31 setMeshLoading(false);
32 }
33 }, [agentUuid, agentId]);
34
35 // Load MeshCentral URL when component mounts or agentUuid/agentId changes
36 React.useEffect(() => {
37 if (agentUuid || agentId) {
38 loadMeshCentralUrl();
39 }
40 }, [agentUuid, agentId, loadMeshCentralUrl]);
41
42 return (
43 <div className="tab-container" style={{ height: 'calc(100vh - 200px)', display: 'flex', flexDirection: 'column' }}>
44 <h2 style={{ marginBottom: '1rem' }}>Remote Desktop</h2>
45
46 {meshLoading ? (
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>
50 </div>
51 ) : meshError ? (
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.
58 </p>
59 <button className="btn" onClick={loadMeshCentralUrl}>
60 Retry
61 </button>
62 </div>
63 ) : meshInfo?.meshcentralNodeId ? (
64 <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
65 <MeshDesktopViewer
66 meshcentralNodeId={meshInfo.meshcentralNodeId}
67 meshcentralUrl={meshInfo.remoteDesktopUrl?.split('/login')[0] || process.env.REACT_APP_MESHCENTRAL_URL}
68 onError={(error) => {
69 setMeshError(error);
70 }}
71 />
72 </div>
73 ) : (
74 <div className="card">
75 <p>Loading...</p>
76 </div>
77 )}
78 </div>
79 );
80}
81
82export default TabRds;