1import React from 'react';
2import { apiFetch } from '../../lib/api';
4function TabRds({ agentId, agentUuid }) {
5 const [rustdeskInfo, setRustdeskInfo] = React.useState(null);
6 const [loading, setLoading] = React.useState(false);
7 const [error, setError] = React.useState(null);
9 React.useEffect(() => {
15 async function loadRustdeskInfo() {
20 const response = await apiFetch(`/rustdesk/connect/${agentUuid}`);
23 throw new Error(`HTTP ${response.status}: ${response.statusText}`);
26 const data = await response.json();
27 console.log('[RDS] Received data:', data);
30 setRustdeskInfo(data);
31 } else if (data.install_required) {
32 setRustdeskInfo({ install_required: true });
34 setError(data.error || 'Failed to load Rustdesk info');
37 console.error('[RDS] Failed to load info:', err);
38 setError(err.message);
44 function openRustdesk() {
45 if (!rustdeskInfo || !rustdeskInfo.rustdesk_id) return;
47 const { rustdesk_id, server, public_key } = rustdeskInfo;
49 // Build complete connection URL with all parameters
50 // Format: rustdesk://<ID>?relay-server=<server>:21117&rendezvous-server=<server>:21116&key=<key>
51 const rustdeskUrl = `rustdesk://${rustdesk_id}?relay-server=${server}:21117&rendezvous-server=${server}:21116&key=${encodeURIComponent(public_key)}`;
53 console.log('[RDS] Opening RustDesk with URL:', rustdeskUrl);
55 // Attempt to open (may not work on all platforms)
56 const iframe = document.createElement('iframe');
57 iframe.style.display = 'none';
58 iframe.src = rustdeskUrl;
59 document.body.appendChild(iframe);
62 document.body.removeChild(iframe);
65 // Show manual instructions
66 alert(`RustDesk Connection Info:
70Public Key: ${public_key}
72⚠️ IMPORTANT - ONE-TIME SETUP REQUIRED:
73Your RustDesk client must be configured to use YOUR custom server.
74Otherwise you'll get "Failed to connect" or wrong server errors.
78OPTION 1 - Automatic Setup (Windows):
79 Download and run: https://everydaytech.au/agent/rustdesk-admin-setup.bat
80 This will configure RustDesk automatically.
82OPTION 2 - Manual Setup:
83 1. Open RustDesk application
84 2. Click the menu icon (☰) or go to Settings
85 3. Click "Network" tab
86 4. Click "Unlock Network Settings"
87 5. Set ID Server: ${server}
88 6. Set Relay Server: ${server}
89 7. Set Key: ${public_key}
90 8. Click "Apply" and restart RustDesk
92After setup, you can connect by just entering the ID: ${rustdesk_id}
93No password needed for unattended access.`);
98 <div className="tab-container">
99 <h2>Remote Desktop (Rustdesk)</h2>
100 <div className="card">Loading...</div>
107 <div className="tab-container">
108 <h2>Remote Desktop (Rustdesk)</h2>
109 <div className="card" style={{ color: 'red' }}>
110 Error: {error}<br /><br />
111 <button className="btn" onClick={loadRustdeskInfo}>Retry</button>
119 <div className="tab-container">
120 <h2>Remote Desktop (Rustdesk)</h2>
121 <div className="card">No connection info available</div>
126 if (rustdeskInfo.install_required) {
128 <div className="tab-container">
129 <h2>Remote Desktop (Rustdesk)</h2>
130 <div className="card">
131 <p><strong>Rustdesk is installing...</strong></p>
132 <p>Rustdesk will automatically install when the agent starts. This may take a few minutes.</p>
133 <p>Please refresh this page in 2-3 minutes.</p>
135 <button className="btn" onClick={loadRustdeskInfo}>Refresh Status</button>
142 <div className="tab-container">
143 <h2>Remote Desktop (Rustdesk)</h2>
144 <div className="card">
145 <h3>Connection Information</h3>
146 <div style={{ marginBottom: '15px' }}>
147 <div style={{ marginBottom: '10px' }}>
148 <strong>Rustdesk ID:</strong>
152 background: '#f5f5f5',
157 {rustdeskInfo.rustdesk_id}
160 <div style={{ marginBottom: '10px' }}>
161 <strong>Server:</strong>
165 background: '#f5f5f5',
170 {rustdeskInfo.server}
173 <div style={{ marginBottom: '10px' }}>
174 <strong>Public Key:</strong>
178 background: '#f5f5f5',
182 wordBreak: 'break-all'
184 {rustdeskInfo.public_key}
187 <div style={{ marginBottom: '10px' }}>
188 <strong>Hostname:</strong> {rustdeskInfo.hostname}
193 marginBottom: '20px',
195 background: '#fff3cd',
196 border: '1px solid #ffc107',
199 <strong>⚠️ ONE-TIME SETUP REQUIRED</strong><br />
200 Your computer must be configured to use YOUR custom RustDesk server.<br />
201 <strong>Download and run:</strong> <a href="/agent/rustdesk-admin-setup.bat" download style={{fontWeight: 'bold'}}>rustdesk-admin-setup.bat</a><br />
202 <em style={{fontSize: '0.9em', color: '#856404'}}>This only needs to be done once per support computer.</em>
205 <button className="btn" onClick={openRustdesk} style={{ marginBottom: '20px' }}>
206 🖥️ Connect via Rustdesk
212 background: '#f9f9f9',
216 <p style={{ marginTop: 0 }}><strong>⚠️ First Time Setup (Required):</strong></p>
217 <ol style={{ marginBottom: 0, paddingLeft: '20px' }}>
218 <li>Open RustDesk application on your computer</li>
219 <li>Click the <strong>menu icon (☰)</strong> at the top</li>
220 <li>Select <strong>"Settings"</strong></li>
221 <li>Click <strong>"Network"</strong> tab</li>
222 <li>Click <strong>"Unlock Network Settings"</strong> button</li>
223 <li>In <strong>ID Server</strong> field, enter: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.server}</code></li>
224 <li>In <strong>Relay Server</strong> field, enter: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.server}</code></li>
225 <li>In <strong>Key</strong> field, paste: <code style={{background: '#fff', padding: '2px 6px', fontSize: '11px'}}>{rustdeskInfo.public_key}</code></li>
226 <li>Click <strong>"Apply"</strong> or <strong>"OK"</strong></li>
227 <li>Close and restart RustDesk</li>
228 <li>After restart, enter this ID: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.rustdesk_id}</code></li>
229 <li>Click <strong>"Connect"</strong></li>
231 <p style={{ marginTop: '15px', marginBottom: 0, color: '#d9534f' }}>
232 <strong>⚠️ On Linux:</strong> You may need to reboot your computer after installing RustDesk for the protocol handler to work.
234 <p style={{ marginTop: '10px', marginBottom: 0 }}>
235 <strong>Don't have RustDesk?</strong>
236 <a href="https://rustdesk.com/download" target="_blank" rel="noopener" style={{ marginLeft: '5px' }}>
246export default TabRds;