# Homedroid Desktop protocol (v1) Homedroid Desktop is a small companion program for Windows, Linux and macOS. It turns the phone's camera into a webcam on the computer and carries out MacroPads buttons (hotkeys, media keys, typing, launching apps) on the computer. **The computer always connects to the phone**, never the other way round: no firewall prompts on the computer, and it works anywhere the computer can reach the dashboard (LAN, Tailscale, another cluster phone's address). Everything below is on the dashboard port (8800, plain HTTP like the dashboard; use Tailscale for remote use). ## Pairing 1. The user opens **Desktop** in the phone app or dashboard and taps **Pair a computer**. The phone shows a 6-digit code, valid for 5 minutes, single use. 2. The desktop app asks for the phone's address and the code and calls: ``` POST /desktop/v1/pair {"code": "123456", "name": "Sudipta's laptop", "os": "windows|linux|macos", "version": "0.9.5"} → 200 {"token": "<64 hex chars>", "computerId": "c-3f2a9b", "phone": "Pixel 6", "phoneId": ""} → 403 {"error": "That code is wrong or expired"} ``` Wrong codes are rate limited (5 per minute per address). The token is stored by the desktop app in its config file (`~/.config/homedroid-desktop/config.json`, or `%APPDATA%\Homedroid\ desktop.json`), and on the phone only as a SHA-256 hash. Paired computers are listed and can be removed on the phone; a removed computer's requests get 401 and it shows "Pair again". Every other request carries `Authorization: Bearer `. ``` GET /desktop/v1/hello → {"phone": "Pixel 6", "computerId": "c-3f2a9b", "cameras": [{"id": "0", "facing": "back", "sizes": [[1920,1080],[1280,720],[640,480]], "fps": [15,30], "capabilities": {"torch": true, "zoom": [1.0, 8.0]}}], "features": ["webcam", "macros"]} ``` ## Webcam ``` GET /desktop/v1/webcam?camera=0&width=1280&height=720&fps=30&quality=80 ``` Response: `200`, `Content-Type: multipart/x-mixed-replace; boundary=hdframe`, then for every frame, as soon as it is encoded: ``` --hdframe\r\n Content-Type: image/jpeg\r\n Content-Length: \r\n X-Frame: \r\n X-Time: \r\n \r\n \r\n ``` - The phone picks the nearest supported size and frame rate; the first frame's JPEG tells the real size. `camera` may also be `front` or `back`. - Low latency over completeness: when the connection can't keep up, the phone drops frames rather than queueing them (it always sends the newest one). - One webcam stream at a time per phone; a second one gets `409` while the first is open. - Closing the connection stops the camera (unless the phone's IPCam is using it). - `POST /desktop/v1/webcam/control {...}` adjusts the running stream. The body is a patch of the fields below; it is validated atomically against the active camera's capabilities (an unknown field, a bad type or value, or an unsupported control returns `400` and changes nothing). The reply is `{"ok": true, "settings": {...}}` with the full effective settings. Changing `camera`, `width`, `height` or `fps` restarts the capture pipeline on the phone (the desktop connection stays open; frames pause briefly). `409` if no stream is active. | Field | Type / range | Notes | |---|---|---| | `camera` | camera id, `front`, `back` | switches source; resets controls to that camera's defaults | | `width`, `height`, `fps` | from the camera's `sizes` / `fps` | restart | | `quality` | 1-100 | JPEG quality | | `zoom` | within `capabilities.zoom` | zoom ratio (crop region fallback before Android 11) | | `torch` | bool | needs `capabilities.torch` | | `focus` | `continuous`, `auto`, `manual` | only values listed in `capabilities.focus` | | `focusDistance` | 0..`capabilities.focusDistance` (diopters) | required with `focus: "manual"` | | `x`, `y` | 0..1, both required | tap to focus on the (output-space) point; implies `focus: "auto"` | | `ev` | within `capabilities.ev`, multiple of `evStep` | exposure compensation in EV | | `aeLock`, `awbLock` | bool | needs the matching capability | | `wb` | `auto`, `incandescent`, `fluorescent`, `daylight`, `cloudy` | those in `capabilities.wb` | | `manualSensor`, `iso`, `shutterNs` | bool, int, int | manual exposure; `iso` and `shutterNs` required together and only with `manualSensor: true` | | `stabilization` | bool | video stabilization | | `antiBanding` | `auto`, `50hz`, `60hz` | those in `capabilities.antiBanding` | | `mirror`, `flip` | bool | applied on the phone before JPEG encoding | | `rotate` | 0, 90, 180, 270 | clockwise, applied on the phone | | `reset` | bool | restore the camera's defaults, then apply the rest of the patch | ### Camera capabilities Each entry of `cameras` in `hello` carries what that camera supports, so the desktop only offers usable controls (read from `CameraCharacteristics`, never guessed from the lens facing): ``` {"id": "0", "facing": "back", "sensorOrientation": 90, "sizes": [[1920,1080]], "fps": [15,30], "capabilities": { "torch": true, "focus": ["continuous","auto","manual"], "focusDistance": 10.0, "tapFocus": true, "zoom": [1.0, 8.0], "ev": [-4.0, 4.0], "evStep": 0.5, "aeLock": true, "awbLock": true, "wb": ["auto","daylight"], "antiBanding": ["auto","50hz","60hz"], "stabilization": true, "manualSensor": true, "iso": [50, 3200], "shutterNs": [100000, 500000000], "quality": [1, 100], "mirror": true, "flip": true, "rotate": [0,90,180,270]}} ``` Keys that are absent or `false`/empty are unsupported. `sizes` lists only even sizes up to 4096x2160 pixels. ## MacroPads events The desktop app keeps one long-lived request open: ``` GET /desktop/v1/events → 200, Content-Type: application/x-ndjson, chunked; one JSON object per line: {"type": "hello", "computerId": "c-3f2a9b"} {"type": "ping"} (every 15 s; reconnect if nothing for 45 s) {"type": "action", "id": "a-17", "action": {...}} (see below) ``` and acknowledges each action: ``` POST /desktop/v1/ack {"id": "a-17", "ok": true} or {"id": "a-17", "ok": false, "error": "No such app"} ``` Actions not acknowledged within 10 s show as failed on the deck. When the events request drops, the desktop app reconnects with backoff (1 s, 2 s, 5 s, then every 10 s). ### Action objects | `kind` | fields | effect on the computer | |---|---|---| | `hotkey` | `keys`: e.g. `["ctrl","shift","m"]` | press all, release in reverse | | `key` | `key`: one key name, `repeat` (default 1) | tap a key | | `text` | `text` | types the text (Unicode) | | `media` | `key`: `play_pause`, `next`, `previous`, `stop`, `volume_up`, `volume_down`, `mute` | media key | | `open` | `target`: URL, file or folder | opens with the default app | | `launch` | `path`, `args` (array) | starts a program | | `command` | `command`, `shell` (bool) | runs a command; **refused unless the user turned on "Allow commands" in the desktop app** | | `mouse` | `action`: `click`/`right_click`/`move`/`scroll`, `x`,`y` (move), `dy` (scroll) | mouse input; `move` is absolute pixels, except relative on Wayland (uinput) | | `sequence` | `steps`: array of actions, each may have `delayMs` before it | runs steps in order | Key names: `ctrl`, `shift`, `alt`, `meta` (Windows/Command key), `enter`, `tab`, `escape`, `space`, `backspace`, `delete`, `up`, `down`, `left`, `right`, `home`, `end`, `pageup`, `pagedown`, `f1`–`f24`, `a`–`z`, `0`–`9`, `printscreen`, and single printable characters. Every action object may have `"computer": ""` on the phone side; the phone only sends it to that computer (or to all connected ones when absent). ## MacroPads on the phone (for reference) Stored in `files/macropads.json`: ```json { "version": 1, "profiles": [{ "id": "p-default", "name": "Default", "rows": 3, "cols": 5, "pages": [{ "id": "pg-1", "name": "Main", "buttons": [{ "id": "b-1", "row": 0, "col": 0, "label": "Mute mic", "icon": "mic-off", "emoji": null, "color": "#1F6FEB", "textColor": "#FFFFFF", "action": {"kind": "hotkey", "keys": ["ctrl", "shift", "m"]}, "computer": null, "toggle": {"label": "Unmute", "icon": "mic", "color": "#DA3633"} }] }] }] } ``` Phone-local button kinds (handled on the phone, not sent): `{"kind": "page", "page": "pg-2"}`, `{"kind": "profile", "profile": "p-x"}`, `{"kind": "back"}`, and `{"kind": "http", "method", "url", "body"}` (calls a URL from the phone, e.g. Home Assistant webhooks). Dashboard API (session-authenticated, like the rest of `/api`): - `GET /api/macropads` → the JSON above plus `"computers": [{"id","name","os","online","lastSeen"}]` - `PUT /api/macropads` (whole document, validated) - `POST /api/macropads/press {"profile","page","button"}` → `{"ok": true}` or error (test a button from the dashboard) - `POST /api/desktop/pair` → `{"code": "123456", "expires": }`; `GET /api/desktop/computers`; `DELETE /api/desktop/computers/`