Null-DRM-Official/apps/agent/README.md
404errordeveloper a091922efa
All checks were successful
release / build-and-upload (push) Successful in 7m2s
streamd v0.2.2: session uptimes, egress DNS, Support, agent/Widevine
Dashboard Live uptimes + Recent runs from stream_sessions; overview.recent_sessions.
WireGuard netns resolv.conf + missing-deps WARN. Support donations card.
Agent start/stop/update, job_backoff default off, wvkey ensure/venv, phonecap retries,
modhost YAML enrich, DRM SetCredentials requires keys.
2026-10-10 19:26:39 +02:00

79 lines
3 KiB
Markdown

# agent
Always-on credentials refresher, hosted by the single binary as `streamd agent`.
```text
apps/agent/
agentcmd/ the command body, imported by apps/cli
internal/ poller, durable queue, device pool, worker, ws client
agent.yaml config
```
## What it does
1. Polls streamd (`GET /api/streams`)
2. When an **enabled** stream is down/errored or missing `mpd`/`key`, enqueues a job
in a durable SQLite queue under `data_dir`
3. Claims a free ADB device that **already has** the app installed — it never installs
4. Runs a phone capture through the stream's app module
5. `POST /api/streams/:id/credentials`
6. Force-stops the app and clears the device proxy so the phone is free
It never runs a downloader. Claims are kept alive by a websocket heartbeat, so they
expire by themselves if the agent dies.
## Run
```bash
# terminal 1 — control plane
./bin/streamd serve --bind 127.0.0.1:8083 --data .cache/streamd
# terminal 2 — agent in the background (Linux / macOS / Windows)
export STREAMD_API_KEY=ndk_…
./bin/streamd agent start --config apps/agent/agent.yaml
./bin/streamd agent status --config apps/agent/agent.yaml
# foreground debug: ./bin/streamd agent run --config apps/agent/agent.yaml
# stop / restart: ./bin/streamd agent stop|restart --config …
# self-update: ./bin/streamd agent update [--beta] [--tag vX.Y.Z]
```
```bash
./bin/streamd agent devices
./bin/streamd agent enqueue --stream tg4-ioi --reason manual
./bin/streamd agent cancel --job 3
```
With `sync_modules: true` (default in the sample config), the agent **pulls**
provider modules from the streamd Modules page into `<data_dir>/modules/`. You do
not need a hand-maintained `modules/` tree on each agent host. The agent drives
whichever module a stream names and contains no provider logic.
## Config
`agent.yaml` — `streamd_url`, **`api_key`** (preferred) or `token` (alias), or
env `STREAMD_API_KEY` / `STREAMD_TOKEN`. Also: `poll_interval_sec`, `workers`,
`max_attempts`, `capture_wait_sec`, `devices` (empty = any authorised device),
`wvd`, `user_agent`, `agent_id`, `data_dir`, `sync_modules`, `modules_dir`
(default `<data_dir>/modules`), `modules_sync_interval_sec`, `modules_prune`,
`job_backoff` (default false — exponential delays only when several agents
share work), plus daemon fields `log_file`, `pid_file`, `channel`, `asset`,
`keep_old` for `agent start|stop|update`.
Create the key in the streamd dashboard (role **operator**). The legacy shared
`--token` / `STREAMD_TOKEN` still works but is meant for migration only.
`wvd` must be set or key fetches fail. On first `agent start`/`run`, streamd
bootstraps `apps/wvkey/` and creates `<install>/.venv` with `pywidevine` using
the system Python (Windows, Linux, or macOS) so Widevine key fetch works without
a hand-made venv.
## Build
```bash
go -C apps/cli build -o ../../bin/streamd .
# cross-compile
GOOS=darwin GOARCH=arm64 go -C apps/cli build -o ../../bin/streamd .
```
**Full guide: [docs/streamd.md](../../docs/streamd.md)**