# RustDesk Integration — Build Instructions

## Architecture

```
Shelled OS (Tauri)
├── Main Window: OS desktop UI (taskbar, popups)
├── RustDesk Server: Native binary (--server mode, ports 21115-21119)
└── RustDesk Web Client: Flutter web build loaded in a Tauri webview
    └── Connects to server via WebSocket (ws://localhost:21118, ws://localhost:21119)
```

## Step 1: Build RustDesk Native Binary

The RustDesk binary is built from `shelled/rustdesk-as-ref/`.

### Prerequisites (Windows)
- Rust toolchain (`rustup`)
- vcpkg with: `libvpx`, `libyuv`, `opus`, `aom`
- Visual Studio Build Tools (C++ workload)

```powershell
set VCPKG_ROOT=C:\path\to\vcpkg
cd shelled\rustdesk-as-ref
cargo build --release
```

### Copy binary
```powershell
mkdir shelled\shelled-os-ui\src-tauri\binaries
copy target\release\rustdesk.exe shelled\shelled-os-ui\src-tauri\binaries\rustdesk.exe
```

## Step 2: Build RustDesk Web Client

The web client is a Flutter web build that communicates with the server via WebSocket.

### Prerequisites
- Flutter SDK 3.24+
- The `flutter/web/js/` WASM bridge (from `rustdesk-web-client` project)

### Build
```powershell
cd shelled\rustdesk-as-ref\flutter

# Install web dependencies
flutter pub get
flutter create --platforms web .   # Generate web/ directory if missing

# Build Flutter web
flutter build web --release
```

### Copy to Shelled OS
```powershell
mkdir shelled\shelled-os-ui\rustdesk-web
xcopy build\web\* shelled\shelled-os-ui\rustdesk-web\ /E
```

### Note on the WASM Bridge
The RustDesk web client requires a JS/WASM bridge layer that provides:
- `setByName(name, value)` — Flutter → Rust/WASM commands
- `getByName(name, value)` — Rust/WASM → Flutter data
- `init()` — Initialize the connection

This bridge was removed from the main RustDesk repo. You'll need to get it from:
- GitHub Releases: `web_deps.tar.gz` from `rustdesk/doc.rustdesk.com`
- Or the `MonsieurBiche/rustdesk-web-client` fork's `fix-build` branch

## Step 3: Run Shelled OS

```powershell
cd shelled\shelled-os-ui
npm run dev
```

### Using the Remote Desktop
1. Click the Remote Desktop icon in the taskbar
2. Click "Start Server" to launch the RustDesk server
3. Click "Launch" to open the web client in a new window
4. Connect to remote machines through the web client

## Server Ports

| Port | Protocol | Purpose |
|------|----------|---------|
| 21115 | TCP | NAT type test |
| 21116 | TCP+UDP | ID registration & signaling |
| 21117 | TCP | Relay server |
| 21118 | TCP/WS | WebSocket signaling (web client) |
| 21119 | TCP/WS | WebSocket relay (web client) |

## WebSocket URLs (for web client)
- Signal: `ws://localhost:21118` (or `wss://` behind reverse proxy)
- Relay: `ws://localhost:21119` (or `wss://` behind reverse proxy)
