EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabRds_NEW.jsx
Go to the documentation of this file.
1import React from 'react';
2import MeshCentralEmbed, { VIEWMODE } from '../../components/MeshCentralEmbed';
3import { apiFetch } from '../../lib/api';
4
5/**
6 * Remote Desktop Tab
7 * Embeds MeshCentral's remote desktop interface
8 */
9export default function TabRds({ agentId, agentUuid }) {
10 const [nodeId, setNodeId] = React.useState(null);
11 const [loading, setLoading] = React.useState(true);
12 const [error, setError] = React.useState(null);
13
14 // Load MeshCentral node ID for this agent
15 React.useEffect(() => {
16 async function loadNodeId() {
17 setLoading(true);
18 setError(null);
19
20 try {
21 const response = await apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`);
22
23 if (!response.ok) {
24 const errorData = await response.json();
25 throw new Error(errorData.error || 'Failed to get MeshCentral connection');
26 }
27
28 const data = await response.json();
29 setNodeId(data.meshcentralNodeId);
30
31 } catch (err) {
32 console.error('[TabRds] Failed to load MeshCentral node ID:', err);
33 setError(err.message);
34 } finally {
35 setLoading(false);
36 }
37 }
38
39 if (agentUuid || agentId) {
40 loadNodeId();
41 }
42 }, [agentUuid, agentId]);
43
44 if (loading) {
45 return (
46 <div className="tab-container">
47 <div style={{ textAlign: 'center', padding: '3rem' }}>
48 <div className="spinner" style={{ margin: '0 auto 1rem' }}></div>
49 <p>Loading remote desktop...</p>
50 </div>
51 </div>
52 );
53 }
54
55 if (error) {
56 return (
57 <div className="tab-container">
58 <div className="card" style={{ textAlign: 'center', padding: '2rem' }}>
59 <div style={{ fontSize: '3rem', marginBottom: '1rem' }}>⚠️</div>
60 <h3>Connection Error</h3>
61 <p style={{ color: '#d32f2f', marginBottom: '1rem' }}>{error}</p>
62 <button className="btn" onClick={() => window.location.reload()}>
63 Retry
64 </button>
65 </div>
66 </div>
67 );
68 }
69
70 return (
71 <div className="tab-container" style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
72 <MeshCentralEmbed
73 nodeId={nodeId}
74 viewMode={VIEWMODE.DESKTOP}
75 title="Remote Desktop"
76 />
77 </div>
78 );
79}