Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。
feat(voice): add room voice and secure local invitations
AAAda7218bf446e
diff --git a/.env.example b/.env.exampleindex cb1ad8ea..b6997ab1 100644--- a/.env.example+++ b/.env.example@@ -7,6 +7,13 @@ PUBLIC_BASE_URL=http://localhost:8787# Leave empty to follow PUBLIC_BASE_URL. For multiple trusted browser addresses,# list all exact origins (scheme, host and port), including PUBLIC_BASE_URL.ALLOWED_ORIGINS=+# Optional direct HTTPS; leave these unset behind a reverse proxy.+# Set PUBLIC_BASE_URL=https://<LAN-IP>:8787 and TLS_SELF_SIGNED=true for+# private LAN use. The temporary certificate changes on each process restart.+# Or supply both PEM files; Piik loads them at startup, without managing renewal.+TLS_SELF_SIGNED=false+TLS_CERT_FILE=+TLS_KEY_FILE=# Optional site access password in every environment. Unset or empty allows# entry without a site password; room ownership and invitations still apply.# Non-empty values are matched exactly; spaces and Unicode are supported.diff --git a/.github/pull_request_template.md b/.github/pull_request_template.mdindex 9b54d3c8..d9483b83 100644--- a/.github/pull_request_template.md+++ b/.github/pull_request_template.md@@ -9,14 +9,16 @@<!-- Required for product-changing PRs; omit this section for standalone website/docs/maintenance work. Public copy, automatically published in GitHub Releases. Keep this exact heading; use ### for subsections. Describe user benefits, fixes and required upgrade actions in concise Chinese and English. Omit internal logs, audit prompts and unverified claims. 产品改动需填写公开的中英文更新说明;仅官网、文档或外围维护可删去此节。 --><!-- Follow docs/standards/versioning.md#release-notes. Keep the public Release title Piik vX.Y.Z.-An optional editorial headline opens the body as two bold plain-text paragraphs: English, then Chinese.+An optional editorial opening uses a short **bold title** and one plain paragraph explaining its concrete+feature/fact, first the English pair, then the Chinese pair. The explanation is not a second slogan.Keep/change/omit it by editorial relevance, independently of semver. A released feature, verified communitymilestone, thanks or light aside is fine; do not present an old feature as new or promise a prototype.Then use ### English followed by ### 中文 to explain THIS update: actual benefits, fixes and required actions.Group details only when useful. Serious upgrade instructions take precedence over playful copy.Preview the complete generated release, including earlier unpublished changes: one bilingual headline at most.The last product PR supplies that headline (or omits it); earlier PRs retain their actual changes.-正文可先写一组双语主题:先英文、后中文,各一个 **纯文本粗体段落**。按内容决定沿用、换掉或省略,与版本位无关。+正文可先写一组双语主题:每种语言用一个 **纯文本粗体短标题**,接一个普通段落解释具体功能或事实;先完整英文、后完整中文。+例如“远程同乐,轮到你啦!”下一段写“Piik 现已支持远程控制与远程同乐。”,不要再写一句口号。按内容决定沿用、换掉或省略,与版本位无关。主题可以讲已上线功能、真实社区里程碑或轻松小事;随后必须明确“本次更新”改了什么,不用俏皮话代替事实。合并前检查整份生成文案和官网摘句,勿重复主题、误报新功能或手工复制另一份文案。-->diff --git a/.github/workflows/repository-hygiene.yml b/.github/workflows/repository-hygiene.ymlindex 345a0275..334d673a 100644--- a/.github/workflows/repository-hygiene.yml+++ b/.github/workflows/repository-hygiene.yml@@ -186,12 +186,20 @@ jobs:fail-fast: falsematrix:include:- - arch: amd64+ - os: linux+ arch: amd64runner: ubuntu-latestartifact: piik-server- - arch: arm64+ - os: linux+ arch: arm64runner: ubuntu-24.04-armartifact: piik-server-linux-arm64+ # Cross-compiled on the same Linux runner; no container recipe and a+ # ZIP archive instead of the Linux tar.gz.+ - os: windows+ arch: amd64+ runner: ubuntu-latest+ artifact: piik-server-windows-amd64runs-on: ${{ matrix.runner }}timeout-minutes: 15env:@@ -211,16 +219,30 @@ jobs:cache-dependency-path: go.sum- name: Install dependenciesrun: npm ci+ # Only the Windows target writes a ZIP, and the Linux ZIP writer shells+ # out to the `zip` CLI.+ - name: Ensure zip is available+ if: matrix.os == 'windows'+ run: command -v zip >/dev/null || (sudo apt-get update && sudo apt-get install -y zip)- name: Package Server release+ if: matrix.os == 'linux'run: >-node scripts/package-server-release.mjs "$RUNNER_TEMP/server-release"- --arch "${{ matrix.arch }}"+ --os "${{ matrix.os }}" --arch "${{ matrix.arch }}"--container-image "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}"+ - name: Package Windows Server release+ if: matrix.os == 'windows'+ run: >-+ node scripts/package-server-release.mjs "$RUNNER_TEMP/server-release"+ --os "${{ matrix.os }}" --arch "${{ matrix.arch }}"- name: Check the container and deployment recipe+ if: matrix.os == 'linux'run: npm run check:container -- "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}" "$GITHUB_SHA"- name: Save the verified container+ if: matrix.os == 'linux'run: docker save "piik-candidate:$GITHUB_SHA-${{ matrix.arch }}" --output "$RUNNER_TEMP/piik-container-${{ matrix.arch }}.tar"- name: Upload the verified container+ if: matrix.os == 'linux'uses: actions/upload-artifact@v7with:name: piik-container-${{ matrix.arch }}-${{ github.sha }}diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 2de43482..b125cc08 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -27,6 +27,10 @@ valuable. Duplicate work already independently resolved, personal preferences orlow-value changes may be declined; merging is not an attribution mechanism.Retain authorship for accepted contributions and credit substantive discoveriesaccurately, without attributing independently written code to a PR author.+Keep contributor patch commits limited to their necessary changes; put maintainer+adaptations and unrelated work in separate commits. Preserve a useful original+patch commit at integration instead of adding its author as co-author of an+entire phase's squash commit.评审看实际价值、证据和产品定位,不看代码行数。发现并解决真实问题的小修复同样值得接纳;已经独立解决的重复工作、个人偏好或收益很低的改动可以不合并,不为增加贡献者名单而合并。保留已接纳贡献的作者信息,如实说明有价值的问题发现;独立编写的代码不应冒记为他人共同编写。@@ -134,6 +138,11 @@ does not establish coverage.result. A manual diagnostic may locate a failure, but is not retained as passevidence. Existing `PIIK_CLIENT_*` gate environment names retain their currentcontract; renaming the tools does not change those overrides.+- `gate:room-voice` exercises normal Host/Viewer pages against a local production+ server with real fake-device capture. Set `PIIK_ROOM_VOICE_GATE=true`,+ `CHROME_PATH` and `PIIK_SERVER_EXE`; repeat with `PIIK_ROOM_VOICE_SFU=true`+ for embedded SFU. Requires `agent-browser` (or `AGENT_BROWSER_PATH`). Reports+ and screenshots stay under ignored `build/voice-integration`.- `gate:network-lab` runs the opt-in [controlled network laboratory](./docs/research/network-lab.md).It requires a disposable Linux runner with namespace administration. Its ownrouters contain all firewall and traffic-shaping changes; do not run it on adiff --git a/README.md b/README.mdindex 0c200409..a850815c 100644--- a/README.md+++ b/README.md@@ -66,8 +66,8 @@ you can also create a room in the online version.1. Select **Start sharing**, then choose the picture and audio to share.2. Select **Copy invite link** and send it to your friends. Keep the sharing tab open.-Turn on the **Microphone** for commentary; its settings let you choose the input-device and adjust your voice volume.+Open **Interact → Voice** to talk together, with or without picture sharing.+The Host opens voice; everyone joins to listen and chooses when to turn on their microphone.Piik follows your system language: Chinese or English, with English as the fallback.Use **中 / EN / ✦** in the header to switch language or try the visual mode.@@ -84,7 +84,7 @@ Download a ZIP beginning with **`piik-app`**. The filename also identifies the p| `linux-amd64` | Linux x64 || `linux-arm64` | Linux ARM64 |-[**Full setup guide →**](./docs/guide/getting-started.md) · [**Open online →**](https://demo.piik.tv)+[**Getting started →**](./docs/guide/getting-started.md) · [**Troubleshooting →**](./docs/guide/troubleshooting.md)Browser capture requires HTTPS or `localhost`. Windows App and desktop browsersharing are the primary tested paths. Physical-device coverage for the macOS and@@ -108,6 +108,9 @@ extract it, and run:./piik-server```+Windows x64 uses `piik-<revision>-windows-amd64-runtime.zip`; extract it and run+`./piik-server.exe` in PowerShell. The same configuration applies.+Open `http://localhost:8787` to try it locally. For a public site, configure yourdomain, HTTPS reverse proxy and STUN address. Room data is stored in SQLite.For containers, use the [Docker Compose setup](./docs/operations/self-hosting.md#docker-compose).diff --git a/README.zh-CN.md b/README.zh-CN.mdindex a80c5de4..a7a9e55a 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -62,7 +62,8 @@ Piik 是一个免费开源的私密屏幕共享工具,适合游戏直播、一1. 点击**开始分享**,选择要分享的画面和声音。2. 点击**复制邀请链接**,发给朋友。分享期间保持标签页打开。-分享时还可以开启**麦克风**解说,在旁边的设置中选择设备、调整人声音量。+打开 **互动 → 语音** 即可一起聊天,开播前后都能使用。+房主开启语音后,大家自行加入收听,想说话时再打开自己的麦克风。Piik 默认跟随系统语言,中文系统显示简体中文,其他语言显示英文。顶部的 **中 / EN / ✦** 可切换中英文或体验纯视觉模式。@@ -78,7 +79,7 @@ Piik App 可创建本地房间或临时公网邀请,也能在后台为已授| `linux-amd64` | Linux x64 || `linux-arm64` | Linux ARM64 |-[**完整使用教程 →**](./docs/guide/getting-started.zh-CN.md) · [**打开在线版 →**](https://demo.piik.tv)+[**快速上手 →**](./docs/guide/getting-started.zh-CN.md) · [**问题排查 →**](./docs/guide/troubleshooting.zh-CN.md)浏览器采集需要 HTTPS 或 `localhost`。目前主要测试 Windows 版 Piik App 和桌面浏览器分享。macOS 和 Linux 版 Piik App 仍需更多实机测试,欢迎有设备的朋友试用并[反馈问题](https://github.com/TNTcraftHIM/Piik/issues)。@@ -99,6 +100,9 @@ Piik Server 是一个内置网页界面的独立程序。./piik-server```+Windows x64 可下载 `piik-<revision>-windows-amd64-runtime.zip`,解压后在 PowerShell+运行 `./piik-server.exe`;配置方式相同。+打开 `http://localhost:8787` 即可在本机试用。对外提供服务时,再配置域名、HTTPS 反向代理和 STUN 地址。房间数据保存在 SQLite 中。也可以使用 [Docker Compose 部署](./docs/operations/self-hosting.zh-CN.md#使用-docker-compose)。diff --git a/cmd/piik-app/DEVELOPMENT.md b/cmd/piik-app/DEVELOPMENT.mdnew file mode 100644index 00000000..b20bba5a--- /dev/null+++ b/cmd/piik-app/DEVELOPMENT.md@@ -0,0 +1,194 @@+# Piik App Development++Build, package and verify Piik App from the repository root. For installation,+mode selection and diagnostics, use the [App guide](./README.md).++## Run From Source++Use the Node/npm/Go versions in [Run from source](../../docs/README.md#run-from-source).+The binary embeds the Browser assets, so build them from the repository root first:++```sh+npm ci+npm run build:web+```++On Linux or macOS:++```sh+go run ./cmd/piik-app+```++On Windows, build and run from a stable executable path for the system firewall:++```powershell+go build -o build/dev/piik-app.exe ./cmd/piik-app+./build/dev/piik-app.exe+```++These commands build the App only. Choose **Local room** or open a Piik Site+for Browser capture. Native capture and **Public invite** need their helpers;+use `--capture-process` / `--tunnel-process` to select built helpers, or follow+[packaging](#packaging) for a complete bundle.++The repository-level entry used locally and by CI is:++```sh+npm run check:go+```++On Windows, its generated App, capture, and media-test executables are+written to the ignored repository `build/go-check` directory and reused on+the next run. This keeps the executable identity stable for the system firewall;+the files are local build output and are never packaged or committed.++It runs Go formatting, unit tests, vet, and Windows/Linux cgo-free cross-builds.+The Darwin App and peer gate build only on macOS with cgo enabled and an+installed SDK; other hosts report that skipped platform explicitly. The pinned+media dependency's Darwin CPU statistics use Mach APIs through cgo, so a Windows+or Linux core check does not establish Darwin build acceptance.+The check compiles the current platform's isolated capture process and validates+its bounded capability response. macOS additionally encodes one in-memory hardware H.264+IDR; Linux probes the Portal/PipeWire/GStreamer adapter. Real capture, GPU+attribution, Browser decode, and public-network paths remain explicit physical+gates rather than environment-dependent unit tests.++App and Hosted share the Go room service. The Browser UI coordinates native+capture and Viewer receive/relay through the App's local control service;+Viewer receive/relay remains available without a supported native capture encoder.+Use the [module map](../../docs/standards/engineering.md#module-map) and+[contract map](../../docs/standards/engineering.md#contract-map) to find the source owners.+The candidate packager checks that capture helpers match the App's contract.++Packaged builds report the product version and source SHA in the terminal and+diagnostics. [Versioning](../../docs/standards/versioning.md) explains build identity+and update notices; [GitHub operations](../../docs/operations/github.md)+describes automatic publication.++## Packaging++From a clean revision, build the application release and run the platform's+candidate wrapper on its native operating system. The wrapper builds capture,+verifies the pinned public-link helper, and assembles and checks the App:++```sh+node scripts/package-server-release.mjs /outside/repository/app-release+node scripts/package-app-candidate.mjs /outside/repository/app-release windows-amd64 /outside/repository/app-candidate+```++Supported targets are `windows-amd64`, `linux-amd64`, `linux-arm64`, `darwin-arm64` and `darwin-amd64`.+Use the matching target name in the command above. Darwin assembly requires a+native macOS runner with its SDK and enables cgo; Windows and Linux assembly keep+cgo disabled.+The result is a ZIP bundle and SHA-256 file. Manual sidecar assembly,+explicit CI packaging, Release publication and updates are documented in+[deployment](../../docs/deployment.md); creating a candidate does not publish it.++The App runtime contains the following files. On macOS they live inside+`Piik App.app/Contents/MacOS`; move the whole `.app` when installing it.++```text+piik-app[.exe]+REVISION+LICENSE+THIRD-PARTY-NOTICES.txt+runtime/native/piik-capture[.exe] # supported native-media packages+runtime/tunnel/cloudflared[.exe] # packages that support --link+```++The executable embeds the Browser assets of the consumed application release and+carries that same full Git revision as the package `REVISION`. App/Site+interoperability follows the+[public compatibility contract](../../docs/standards/versioning.md#public-compatibility-promise).++For a native Host smoke run, launch the App and select a window in the Host+page, then open its invitation on another device. Choose the mode for that+network as described in the [App guide](./README.md#modes).++### Desktop Icons++The Windows App embeds the shared Piik mark through the+`cmd/piik-app/piik_windows_amd64.syso` resource; the platform+suffix keeps that Windows resource out of Linux and macOS builds.+Linux packages include the standard `share/applications` desktop entry and+hicolor icon. macOS packages include `Piik App.app` with an ICNS resource,+the App executable and its helpers. For terminal use, the executable is+`"Piik App.app/Contents/MacOS/piik-app"`.++The editable badge is [public/favicon.svg](../../public/favicon.svg).+Export it at 16/24/32/48/64/128/256 px as PNG entries in `cmd/piik-app/piik.ico`;+the package builder derives Linux and macOS icons from those entries. Keep the+website exports in sync: `public/favicon.png` at 96 px, and `public/favicon.ico`+with 16/32/48 px entries. Check actual small sizes on light and dark backgrounds.+Render the SVG at each target size so its small-icon styling applies.+Then regenerate the Windows resource from the repository root:++```sh+go run github.com/akavel/[email protected] -ico cmd/piik-app/piik.ico -arch amd64 -o cmd/piik-app/piik_windows_amd64.syso+```++## Gates++The Local gate starts the packaged process, loads a real built page in Chromium,+proves bootstrap access and LAN invitation construction, and verifies complete+process/profile cleanup. The loopback gate separately proves Site access with+and without Chromium Local Network Access permission. Environment syntax below+is POSIX; use equivalent variables on Windows. For the loopback gate, provide a+reachable Piik Site and run once without `PIIK_CLIENT_GATE_GRANT_LOOPBACK`, then+again with `PIIK_CLIENT_GATE_GRANT_LOOPBACK=true` to cover both permission states.++```sh+PIIK_CLIENT_LOCAL_GATE=true \+CHROME_PATH=/path/to/chrome \+PIIK_CLIENT_EXE=/path/to/piik-app \+PIIK_CLIENT_GATE_LAN_ADDRESS=192.168.1.10 \+npm run gate:app-local++PIIK_CLIENT_LOOPBACK_GATE=true \+CHROME_PATH=/path/to/chrome \+PIIK_CLIENT_EXE=/path/to/piik-app \+PIIK_CLIENT_GATE_SITE_URL=https://<test-site> \+npm run probe:app-loopback++PIIK_CLIENT_MEDIA_GATE=true \+CHROME_PATH=/path/to/chrome \+PIIK_CLIENT_GATE_STUN_URLS=stun:<stun-host>:3478 \+npm run gate:app-media++PIIK_CLIENT_NATIVE_HOST_GATE=true \+CHROME_PATH=/path/to/chrome \+PIIK_GO=/path/to/go \+npm run gate:app-native-host++PIIK_CLIENT_NATIVE_HOST_GATE=true \+PIIK_CLIENT_LINK_MEDIA_GATE=true \+CHROME_PATH=/path/to/chrome \+PIIK_GO=/path/to/go \+PIIK_CLOUDFLARED=/path/to/cloudflared \+PIIK_REMOTE_HOST=<public-test-host> \+PIIK_REMOTE_USER=<ssh-user> \+PIIK_REMOTE_SSH_KEY=/path/to/key \+npm run gate:app-native-host++PIIK_CLIENT_LINK_GATE=true \+PIIK_GO=/path/to/go \+PIIK_CLOUDFLARED=/path/to/cloudflared \+PIIK_REMOTE_HOST=<public-test-host> \+PIIK_REMOTE_USER=<ssh-user> \+PIIK_REMOTE_SSH_KEY=/path/to/key \+npm run gate:app-link+```++The Windows media gate proves one hardware-H.264+capture generation, shared Pion source, Browser decode, PLI recovery, and STUN+candidate gathering. The native Host gate proves room creation and native video+delivery through the current route; native audio is included when the capability+probe and target OS support it. The one-link media variant carries signaling+through the App's temporary public origin and requires direct video RTP delivery+to an independent Linux peer, with a selected `srflx` or `prflx` candidate.+SSH only runs the remote probe; media never travels through it. Without a remote+host, this variant checks decoded media in a local Browser through the public+invitation; that does not establish cross-network connectivity. Native P2P+quality evidence and embedded SFU delivery have explicit gates. macOS and Linux capture still+require physical desktop/media gates; CI compilation and package smoke do not+substitute for them.diff --git a/cmd/piik-app/README.md b/cmd/piik-app/README.mdindex 30f1f08b..3187911d 100644--- a/cmd/piik-app/README.md+++ b/cmd/piik-app/README.md@@ -11,6 +11,7 @@ Extract the matching platform bundle in full. On Windows and Linux, keep`runtime` beside the App executable and run `piik-app.exe` or `./piik-app`.On macOS, open `Piik App.app`; you can move the whole `.app` to Applications.The launcher opens in the system Browser.+If macOS blocks the first launch, follow the [Mac opening steps](../../docs/guide/troubleshooting.md#macos-blocks-first-launch).Linux native capture uses the system dependencies describedin the [Linux capture guide](../../native/capture/linux/README.md).@@ -20,8 +21,7 @@ or press **O** there to retry. Keep the App running while using that page.Windows App and browser sharing are the primary tested paths. Physical-devicecoverage for the macOS and Linux apps is still limited; test results and[feedback](https://github.com/TNTcraftHIM/Piik/issues) are welcome. macOS native-capture requires macOS 13 or newer on Apple silicon or Intel. Package construction and public Release-publication are separate steps in [deployment](../../docs/deployment.md).+capture requires macOS 13 or newer on Apple silicon or Intel.## Modes@@ -32,22 +32,38 @@ publication are separate steps in [deployment](../../docs/deployment.md).turn the star off to restore the launcher. Replacing or revoking the Site clears this choice.- The launcher remembers the last mode confirmed with **Open Piik**. Without asaved Local/Public choice, it selects Public invite and waits for confirmation.- The mode preference is stored beside the settings in `client.json.mode`;- [App configuration](../../docs/standards/configuration.md#piik-app-configuration)- covers saved preferences and custom paths.-- The `--site`, `--local`, and `--link` flags select a mode for CI and development.- The default launcher checks official releases after it opens, using GitHubfirst and Gitee if GitHub is unavailable. Click the update button to downloadthe matching platform ZIP, or open the release page when no package matches.**Release notes** opens separately; a new major version includes an upgradewarning. The App does not install or replace itself.-Local rooms last for this App run and work on a reachable LAN. **Public invite**-uses the packaged Cloudflare Tunnel helper to expose that same room service at a-temporary HTTPS address. Picture and sound travel between participants (P2P),-outside the tunnel. Both modes need a usable UDP media path and provide no-media-server forwarding (SFU) or TURN relay fallback. The-[routing reference](../../docs/standards/routing-transport.md) explains connection setup.+### Local Room++Choose **Local room** for a reachable LAN. Rooms last for this App run.++For Local invitations, the App automatically selects a sole active address or+sole private IPv4. If several addresses remain possible, choose an interface+and IP in the launcher. Public invite and use through a Site need no LAN selection.+The selected address is checked again at startup;+it selects the Local HTTPS entry and invitation address, while ICE selects media paths independently.+Local invitations use HTTPS on that address; the Host keeps its HTTP loopback+page. First access requires [confirming the local certificate](../../docs/guide/troubleshooting.md#local-https-certificate-warning)+against the App terminal. The certificate stays in memory and changes on restart.++### Public Invite++For one-link Internet sharing, open the App launcher, choose **Public invite**,+create a room in the opened Browser, and send its normal invitation link. The+random `trycloudflare.com` origin lasts only for that App run; a later launch+creates a new temporary link. Cloudflare Quick Tunnels provide no uptime guarantee;+use a configured Site when persistent control availability or SFU fallback matters.++Public invite uses the packaged Cloudflare Tunnel helper to expose the same+room service at a temporary HTTPS address. Picture and sound travel between+participants (P2P), outside the tunnel. Local and Public invite both need a usable+UDP media path and provide no media-server forwarding (SFU) or TURN relay fallback.+The [routing reference](../../docs/standards/routing-transport.md) explains connection setup.Public invite uses Cloudflare, MiWiFi (Xiaomi) and Bilibili STUN services todiscover reachable addresses. Each contacted operator can see your public IP,@@ -57,21 +73,20 @@ To choose your own STUN services for public invitations, set `PIIK_STUN_URLS`before starting App; see [App configuration](../../docs/standards/configuration.md#piik-app-configuration).An approved Site supplies its own `STUN_URLS`; App Local rooms configure no public STUN.-For Local invitations, the App automatically selects a sole active address or-sole private IPv4. If several addresses remain possible, choose an interface-and IP in the launcher. Public invite and use through a Site need no LAN selection.-When bypassing the launcher with `--local`, use `--lan-address <address>` to-resolve an ambiguous choice. The selected address is checked again at startup;-it affects Local invitation links, while ICE selects media paths independently.+### Approved SiteTo use a Piik Site, keep the App running and click **App** at the top of the Site.Confirm its address on the local approval page. The App remembers one approvedSite, which the launcher can open or revoke. Approving another replaces it andends the previous Site's App connections; Local rooms remain independent.+Click the connected **App** button on a Site to reopen the launcher. If the Site+will not open, use the **App launcher** address in the App terminal instead.The browser remembers activation, so later visits reuse the running App withthat Site's rooms and any enabled SFU fallback. Browser capture remains availablewithout the App; see the-[entry workflow](../../docs/standards/presentation-lifecycle.md#product-surface).+[connection steps](../../docs/guide/getting-started.md#use-app-with-an-existing-site).++## CaptureThe Host page offers Browser and Camera capture alongside available nativewindows or screens; select the source explicitly. Windows native capture offers VP8/Auto/H264;@@ -85,18 +100,32 @@ Native capture uses the Host's current quality settings. Thelive changes and encoding reuse; [verification status](../../docs/verification-status.md)keeps the measured limits.-On supported Windows versions, the **Apps / Windows** and **Screens** tabs offer-**Show capture border**, off by default. Change it when selecting or switching a+When the Windows App's capture runtime supports it, the **Apps / Windows** and+**Screens** tabs offer **Show capture border**, off by default. Change it when selecting or switching asource; the Host page remembers your choice. Windows 10, system policy or anotheractive capture can keep the yellow border visible; sharing remains available.See [capture-border troubleshooting](../../docs/guide/troubleshooting.md#yellow-capture-border-on-windows)for an optional Windows 10 workaround.+## Configuration And Command Line+The App configuration keeps an optional Local site passphrase. Leave itblank for an open Local site, or enter a password in the launcher beforestarting. Viewer invitations grant access to their room independently; see[rooms and access](../../docs/standards/rooms-access.md).+For saved preferences, configuration paths and environment variables, see+[App configuration](../../docs/standards/configuration.md#piik-app-configuration).+To bypass the launcher in development or automation, select a mode explicitly:++| Flag | Mode |+| --- | --- |+| `--local` | Local room; add `--lan-address <address>` when several LAN addresses are possible |+| `--link` | Temporary Public invite |+| `--site <origin>` | Save and open a Piik Site |++## Terminal And Shutdown+The terminal shows the current mode, entry links and startup state; its languagefollows the launcher and App-enabled pages.Press `o` to reopen the Browser, or `q` / Ctrl+C to end Local@@ -107,12 +136,6 @@ When launched in its own Windows console, a startup or runtime error leaves theerror visible until Enter is pressed. Normal shutdown, existing terminals andredirected or automated runs exit directly.-For one-link Internet sharing, open the App launcher, choose **Public invite**,-create a room in the opened Browser, and send its normal invitation link. The-random `trycloudflare.com` origin lasts only for that App run; a later launch-creates a new temporary link. Cloudflare Quick Tunnels provide no uptime guarantee;-use a configured Site when persistent control availability or SFU fallback matters.-## Troubleshooting### Chromium WebRTC Connections@@ -135,189 +158,8 @@ For cooperation failures, include both reports from the same reproduction. The[diagnostic reference](../../docs/standards/configuration.md#diagnostics) ownslog locations, export commands, retention and privacy boundaries.-## Development--Use the Node/npm/Go versions in [Run from source](../../docs/README.md#run-from-source).-The binary embeds the Browser assets, so build them from the repository root first:--```sh-npm ci-npm run build:web-```--On Linux or macOS:--```sh-go run ./cmd/piik-app-```--On Windows, build and run from a stable executable path for the system firewall:--```powershell-go build -o build/dev/piik-app.exe ./cmd/piik-app-./build/dev/piik-app.exe-```--These commands build the App only. Choose **Local room** or open a Piik Site-for Browser capture. Native capture and **Public invite** need their helpers;-use `--capture-process` / `--tunnel-process` to select built helpers, or follow-[packaging](#packaging) for a complete bundle.--The repository-level entry used locally and by CI is:--```sh-npm run check:go-```--On Windows, its generated App, capture, and media-test executables are-written to the ignored repository `build/go-check` directory and reused on-the next run. This keeps the executable identity stable for the system firewall;-the files are local build output and are never packaged or committed.--It runs Go formatting, unit tests, vet, and Windows/Linux cgo-free cross-builds.-The Darwin App and peer gate build only on macOS with cgo enabled and an-installed SDK; other hosts report that skipped platform explicitly. The pinned-media dependency's Darwin CPU statistics use Mach APIs through cgo, so a Windows-or Linux core check does not establish Darwin build acceptance.-The check compiles the current platform's isolated capture process and validates-its bounded capability response. macOS additionally encodes one in-memory hardware H.264-IDR; Linux probes the Portal/PipeWire/GStreamer adapter. Real capture, GPU-attribution, Browser decode, and public-network paths remain explicit physical-gates rather than environment-dependent unit tests.--App and Hosted share the Go room service. The Browser UI coordinates native-capture and Viewer receive/relay through the App's local control service;-Viewer receive/relay remains available without a supported native capture encoder.-Use the [module map](../../docs/standards/engineering.md#module-map) and-[contract map](../../docs/standards/engineering.md#contract-map) to find the source owners.-The candidate packager checks that capture helpers match the App's contract.--Packaged builds report the product version and source SHA in the terminal and-diagnostics. [Versioning](../../docs/standards/versioning.md) explains build identity-and update notices; [GitHub operations](../../docs/operations/github.md)-describes automatic publication.--## Packaging--From a clean revision, build the application release and run the platform's-candidate wrapper on its native operating system. The wrapper builds capture,-verifies the pinned public-link helper, and assembles and checks the App:--```sh-node scripts/package-server-release.mjs /outside/repository/app-release-node scripts/package-app-candidate.mjs /outside/repository/app-release windows-amd64 /outside/repository/app-candidate-```--Supported targets are `windows-amd64`, `linux-amd64`, `linux-arm64`, `darwin-arm64` and `darwin-amd64`.-Use the matching target name in the command above. Darwin assembly requires a-native macOS runner with its SDK and enables cgo; Windows and Linux assembly keep-cgo disabled.-The result is a ZIP bundle and SHA-256 file. Manual sidecar assembly,-explicit CI packaging, Release publication and updates are documented in-[deployment](../../docs/deployment.md); creating a candidate does not publish it.--The App runtime contains the following files. On macOS they live inside-`Piik App.app/Contents/MacOS`; move the whole `.app` when installing it.--```text-piik-app[.exe]-REVISION-LICENSE-THIRD-PARTY-NOTICES.txt-runtime/native/piik-capture[.exe] # supported native-media packages-runtime/tunnel/cloudflared[.exe] # packages that support --link-```--The executable embeds the Browser assets of the consumed application release and-carries that same full Git revision as the package `REVISION`. App/Site-interoperability follows the-[public compatibility contract](../../docs/standards/versioning.md#public-compatibility-promise).--For a native Host smoke run, launch the App and select a window in the Host-page, then open its invitation on another device. Choose the mode for that-network as described [above](#modes).--### Desktop Icons--The Windows App embeds the shared Piik mark through the-`cmd/piik-app/piik_windows_amd64.syso` resource; the platform-suffix keeps that Windows resource out of Linux and macOS builds.-Linux packages include the standard `share/applications` desktop entry and-hicolor icon. macOS packages include `Piik App.app` with an ICNS resource,-the App executable and its helpers. For terminal use, the executable is-`"Piik App.app/Contents/MacOS/piik-app"`.--The editable badge is [public/favicon.svg](../../public/favicon.svg).-Export it at 16/24/32/48/64/128/256 px as PNG entries in `cmd/piik-app/piik.ico`;-the package builder derives Linux and macOS icons from those entries. Keep the-website exports in sync: `public/favicon.png` at 96 px, and `public/favicon.ico`-with 16/32/48 px entries. Check actual small sizes on light and dark backgrounds.-Render the SVG at each target size so its small-icon styling applies.-Then regenerate the Windows resource from the repository root:--```sh-go run github.com/akavel/[email protected] -ico cmd/piik-app/piik.ico -arch amd64 -o cmd/piik-app/piik_windows_amd64.syso-```--## Gates--The Local gate starts the packaged process, loads a real built page in Chromium,-proves bootstrap access and LAN invitation construction, and verifies complete-process/profile cleanup. The loopback gate separately proves Site access with-and without Chromium Local Network Access permission. Environment syntax below-is POSIX; use equivalent variables on Windows.--```sh-PIIK_CLIENT_LOCAL_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_EXE=/path/to/piik-app \-PIIK_CLIENT_GATE_LAN_ADDRESS=192.168.1.10 \-npm run gate:app-local--PIIK_CLIENT_LOOPBACK_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_EXE=/path/to/piik-app \-npm run probe:app-loopback--PIIK_CLIENT_MEDIA_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_GATE_STUN_URLS=stun:<stun-host>:3478 \-npm run gate:app-media--PIIK_CLIENT_NATIVE_HOST_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_GO=/path/to/go \-npm run gate:app-native-host--PIIK_CLIENT_NATIVE_HOST_GATE=true \-PIIK_CLIENT_LINK_MEDIA_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_GO=/path/to/go \-PIIK_CLOUDFLARED=/path/to/cloudflared \-PIIK_REMOTE_HOST=<public-test-host> \-PIIK_REMOTE_USER=<ssh-user> \-PIIK_REMOTE_SSH_KEY=/path/to/key \-npm run gate:app-native-host--PIIK_CLIENT_LINK_GATE=true \-PIIK_GO=/path/to/go \-PIIK_CLOUDFLARED=/path/to/cloudflared \-PIIK_REMOTE_HOST=<public-test-host> \-PIIK_REMOTE_USER=<ssh-user> \-PIIK_REMOTE_SSH_KEY=/path/to/key \-npm run gate:app-link-```--The Windows media gate proves one hardware-H.264-capture generation, shared Pion source, Browser decode, PLI recovery, and STUN-candidate gathering. The native Host gate proves room creation and native video-delivery through the current route; native audio is included when the capability-probe and target OS support it. The one-link media variant carries signaling-through the App's temporary public origin and requires direct video RTP delivery-to an independent Linux peer, with a selected `srflx` or `prflx` candidate.-SSH only runs the remote probe; media never travels through it. Without a remote-host, this variant checks decoded media in a local Browser through the public-invitation; that does not establish cross-network connectivity. Native P2P-quality evidence and embedded SFU delivery have explicit gates. macOS and Linux capture still-require physical desktop/media gates; CI compilation and package smoke do not-substitute for them.+## For Developers++[App development](./DEVELOPMENT.md) covers source builds, packaging, desktop icons+and validation gates. [Deployment](../../docs/deployment.md) covers maintained+release publication.diff --git a/cmd/piik-app/README.zh-CN.md b/cmd/piik-app/README.zh-CN.mdindex ceb75924..444e980e 100644--- a/cmd/piik-app/README.zh-CN.md+++ b/cmd/piik-app/README.zh-CN.md@@ -9,6 +9,7 @@ Piik App 通过系统浏览器中的 Piik 网页界面,提供本地房间与完整解压对应平台的程序包。Windows 和 Linux 保留 App 程序旁的 `runtime` 目录,分别运行 `piik-app.exe` 或 `./piik-app`。macOS 打开 `Piik App.app`,也可以将整个 `.app` 移到「应用程序」。+首次打开被拦截时,按 [Mac 打开说明](../../docs/guide/troubleshooting.zh-CN.md#macos-提示已损坏或无法验证开发者)处理。启动页会在系统浏览器中打开。Linux 原生采集所需的系统依赖见[Linux 采集指南](../../native/capture/linux/README.md)。@@ -17,8 +18,7 @@ macOS 打开 `Piik App.app`,也可以将整个 `.app` 移到「应用程序」目前主要测试 Windows 版 Piik App 和浏览器分享。macOS 与 Linux 版 Piik App 仍需更多实机测试,欢迎试用并[反馈结果](https://github.com/TNTcraftHIM/Piik/issues)。macOS 原生采集需要-Apple 芯片或 Intel Mac,以及 macOS 13 或更新版本。构建程序包与公开发布 Release 是两个独立步骤,-详见[部署与发布](../../docs/deployment.md)。+Apple 芯片或 Intel Mac,以及 macOS 13 或更新版本。## 运行模式@@ -28,16 +28,29 @@ Apple 芯片或 Intel Mac,以及 macOS 13 或更新版本。构建程序包与替换站点或取消授权也会清除星标。- 启动页会记住上次点击 **进入 Piik** 确认的模式。没有已保存的本地/公网选择时,默认选中公网邀请;确认后才启动。- 模式偏好保存在配置旁的 `client.json.mode` 中;保存项与自定义路径见- [App 配置](../../docs/standards/configuration.md#piik-app-configuration)。-- `--site`、`--local` 和 `--link` 用于在 CI 或开发时直接选择模式。- 默认启动页打开后会检查官方发布,优先使用 GitHub,GitHub 不可用时使用 Gitee。点击更新按钮下载对应平台的 ZIP,没有匹配包时打开发布页。**版本说明** 可单独查看;发现新的大版本时会显示升级提示。App 不会自行安装或替换程序。-本地房间仅在本次 App 运行期间有效,适用于设备间可互相访问的局域网。-**公网邀请** 通过程序包中的 Cloudflare Tunnel 辅助程序,为同一个房间服务提供临时 HTTPS 地址。-画面和声音在参与者之间传输(P2P),不经过隧道。这两种模式都需要可用的 UDP 媒体路径,+### 本地房间++选择 **本地房间**,在设备间可互相访问的局域网中使用。房间仅在本次 App 运行期间有效。++本地邀请会自动选择唯一的活动地址或唯一的私有 IPv4 地址。仍有多个可能地址时,+请在启动页选择网卡和 IP。公网邀请和搭配站点使用时无需选择局域网地址。+App 会在启动时再次检查所选地址;它用于本地 HTTPS 入口和邀请链接,媒体路径仍由 ICE 独立选择。+房主继续使用 HTTP 本机页面;朋友首次打开 HTTPS 邀请时,需与 App 终端核对+[本地证书](../../docs/guide/troubleshooting.zh-CN.md#本地-https-证书提示)。证书只保存在内存中,重启后更换。++### 公网邀请++临时公网分享时,打开 App 启动页,选择 **公网邀请**,在随后打开的浏览器中创建房间,+发送通常的邀请链接即可。随机的 `trycloudflare.com` 来源仅在本次 App 运行期间有效,+下次启动会创建新链接。Cloudflare Quick Tunnels 不保证持续可用;+需要持久的控制服务或 SFU 兜底时,请使用配置好的站点。++公网邀请通过程序包中的 Cloudflare Tunnel 辅助程序,为同一个房间服务提供临时 HTTPS 地址。+画面和声音在参与者之间传输(P2P),不经过隧道。本地房间和公网邀请都需要可用的 UDP 媒体路径,没有媒体服务器转发(SFU)或 TURN 中继兜底。连接机制见[路由参考](../../docs/standards/routing-transport.md)。@@ -47,16 +60,16 @@ Apple 芯片或 Intel Mac,以及 macOS 13 或更新版本。构建程序包与`PIIK_STUN_URLS` 替换 STUN 服务,示例见 [App 配置](../../docs/standards/configuration.md#piik-app-configuration)。搭配已授权站点时使用站点的 `STUN_URLS`;App 本地房间不配置公共 STUN。-本地邀请会自动选择唯一的活动地址或唯一的私有 IPv4 地址。仍有多个可能地址时,-请在启动页选择网卡和 IP。公网邀请和搭配站点使用时无需选择局域网地址。-通过 `--local` 跳过启动页时,可用 `--lan-address <address>` 指定地址来解决多地址歧义。-App 会在启动时再次检查所选地址;它只影响本地邀请链接,媒体路径仍由 ICE 独立选择。+### 已授权站点使用 Piik 站点时,保持 App 运行,点击站点顶部的 **App**,在本机确认页核对网址并允许使用。App 记住一个已授权站点,可在启动页打开或取消授权。允许另一个站点会替换旧站点,-结束旧站点的 App 连接;本地房间不受影响。同一浏览器记住启用选择,+结束旧站点的 App 连接;本地房间不受影响。点击站点上已连接的 **App** 按钮可重开启动页;+站点打不开时,可使用 App 终端中的 **App 启动页** 地址。同一浏览器记住启用选择,之后访问站点即可继续使用 App,同时使用该站点的房间和已启用的 SFU 兜底。-没有 App 时仍可使用浏览器采集,详见[进入流程](../../docs/standards/presentation-lifecycle.md#product-surface)。+没有 App 时仍可使用浏览器采集,详见[连接步骤](../../docs/guide/getting-started.zh-CN.md#通过已有站点使用-app)。++## 采集房主页面提供浏览器、摄像头采集,以及可用的原生窗口或屏幕,请明确选择来源。Windows 原生采集提供 VP8/Auto/H264,Auto 会为本次分享选定一种编码。@@ -67,25 +80,35 @@ macOS 和 Linux 原生采集需要硬件 H264。可选来源与音频支持取[媒体质量参考](../../docs/standards/media-quality.md)说明,实测边界见[验证状态](../../docs/verification-status.md)。-在支持的 Windows 版本上,选源器的 **程序 / 窗口** 和 **屏幕** 页提供 **显示采集边框** 开关,默认关闭。+Windows App 检测到采集能力支持时,选源器的 **程序 / 窗口** 和 **屏幕** 页会出现+**显示采集边框** 开关,默认关闭。选取或切换来源时可以修改,本次房主页面会记住选择。Windows 10、系统策略或其他正在进行的采集可能让黄框保持可见,分享仍可正常进行。Windows 10 的可选处理方法见[采集边框问题排查](../../docs/guide/troubleshooting.zh-CN.md#windows-分享时出现黄框)。+## 配置与命令行+App 配置保存可选的本地站点口令。留空表示本地站点开放进入;需要口令时,在启动页填写后再启动。观众邀请独立授予对应房间的访问权,详见[房间与访问](../../docs/standards/rooms-access.md)。+保存的偏好、配置路径与环境变量见+[App 配置](../../docs/standards/configuration.md#piik-app-configuration)。+开发或自动化运行时,可直接指定模式,跳过启动页:++| 参数 | 模式 |+| --- | --- |+| `--local` | 本地房间;有多个可能的局域网地址时,添加 `--lan-address <address>` |+| `--link` | 临时公网邀请 |+| `--site <origin>` | 保存并打开 Piik 站点 |++## 终端与关闭+终端显示当前模式、入口链接与启动状态,语言跟随启动页和已启用 App 的页面。按 `o` 重新打开浏览器,按 `q` 或 Ctrl+C 结束本地房间,停止本地服务与临时公网链接。纯文本输出时使用 Ctrl+C。Linux 桌面入口也会打开此终端。关闭站点标签页后,App 仍会继续运行。App 在独立 Windows 控制台中启动时,启动或运行错误会保留在窗口中,按 Enter 后退出。正常关闭、在已有终端中运行、重定向输出或自动化运行时,会直接退出。-临时公网分享时,打开 App 启动页,选择 **公网邀请**,在随后打开的浏览器中创建房间,-发送通常的邀请链接即可。随机的 `trycloudflare.com` 来源仅在本次 App 运行期间有效,-下次启动会创建新链接。Cloudflare Quick Tunnels 不保证持续可用;-需要持久的控制服务或 SFU 兜底时,请使用配置好的站点。-## 问题排查### Chromium WebRTC 连接@@ -104,166 +127,7 @@ App 在独立 Windows 控制台中启动时,启动或运行错误会保留在调查浏览器与 App 配合的问题时,请提供同一次复现的两份报告。[诊断参考](../../docs/standards/configuration.md#diagnostics)说明日志位置、导出命令、保留规则与隐私边界。-## 开发--Node/npm/Go 版本见[从源码运行](../../docs/README.md#run-from-source)。-程序会内嵌浏览器资源,请先在仓库根目录构建:--```sh-npm ci-npm run build:web-```--Linux 或 macOS:--```sh-go run ./cmd/piik-app-```--Windows 使用固定的可执行文件路径,便于系统防火墙识别:+## 开发者参考-```powershell-go build -o build/dev/piik-app.exe ./cmd/piik-app-./build/dev/piik-app.exe-```--这些命令只构建 App。体验浏览器采集时,选择 **本地房间**,或直接打开 Piik 站点。-原生采集和 **公网邀请** 需要各自的辅助程序,可用 `--capture-process` / `--tunnel-process`-指定已构建的程序,或按[打包](#打包)步骤生成完整程序包。--本地与 CI 共用的仓库级检查入口是:--```sh-npm run check:go-```--在 Windows 上,该入口将 App、采集及媒体测试程序写入已忽略的仓库 `build/go-check`-目录,并在下次运行时复用路径,保持系统防火墙识别的可执行文件身份稳定。-这些文件是本地构建输出,不会打包或提交。--检查包括 Go 格式、单元测试、vet,以及禁用 cgo 的 Windows/Linux 交叉构建。-Darwin App 和 peer gate 仅在安装 SDK 的 macOS 上启用 cgo 构建;其他系统会明确报告跳过该平台。-固定版本的媒体依赖在 Darwin 上通过 cgo 调用 Mach API 获取 CPU 统计,-因此 Windows 或 Linux 上的核心检查不能证明 Darwin 构建通过。-检查会编译当前平台的独立采集程序,并验证有界的能力响应。macOS 还会在内存中编码一个硬件 H.264-IDR;Linux 会探测 Portal/PipeWire/GStreamer 适配层。真实采集、GPU 归因、浏览器解码-和公网路径由明确的实机验证负责,不作为依赖环境的单元测试。--App 与托管站点共用 Go 房间服务。浏览器界面通过 App 的本地控制服务协调原生采集,-以及观众接收与中继;即使本机没有可用的原生采集编码器,观众接收与中继仍可使用。-源码职责见[模块地图](../../docs/standards/engineering.md#module-map)和-[接口地图](../../docs/standards/engineering.md#contract-map)。候选打包脚本会检查采集辅助程序-是否匹配 App 的协议。--打包版本会在终端和诊断中报告产品版本与源码 SHA。[版本规则](../../docs/standards/versioning.md)-说明构建身份与更新提示,[GitHub 运维](../../docs/operations/github.md)说明自动发布。--## 打包--从干净的源码版本开始,构建应用发布产物,再在目标平台的操作系统上运行候选打包脚本。-脚本会构建采集程序、验证固定版本的公网链接辅助程序,并组装和检查 App:--```sh-node scripts/package-server-release.mjs /outside/repository/app-release-node scripts/package-app-candidate.mjs /outside/repository/app-release windows-amd64 /outside/repository/app-candidate-```--支持的目标为 `windows-amd64`、`linux-amd64`、`linux-arm64`、`darwin-arm64` 和 `darwin-amd64`,请替换命令中的目标名称。-Darwin 组装需要原生 macOS runner 与 SDK,并启用 cgo;Windows 与 Linux 组装禁用 cgo。-结果是 ZIP 程序包和 SHA-256 文件。手动组装辅助程序、显式 CI 打包、Release 发布与更新,-见[部署与发布](../../docs/deployment.md);创建候选包不会将它发布。--App 运行目录包含以下文件。macOS 下它们位于-`Piik App.app/Contents/MacOS`,安装时移动整个 `.app` 即可。--```text-piik-app[.exe]-REVISION-LICENSE-THIRD-PARTY-NOTICES.txt-runtime/native/piik-capture[.exe] # 支持原生媒体的程序包-runtime/tunnel/cloudflared[.exe] # 支持 --link 的程序包-```--App 内嵌所用应用发布产物的浏览器资源,程序内的完整 Git 版本与包内 `REVISION` 一致。-App 与站点之间的互操作遵循[公开兼容规则](../../docs/standards/versioning.md#public-compatibility-promise)。--执行原生房主冒烟检查时,启动 App,在房主页面选择一个窗口,再用另一台设备打开邀请。-按[运行模式](#运行模式)说明选择适合该网络的模式。--### 桌面图标--Windows App 通过 `cmd/piik-app/piik_windows_amd64.syso` 资源内嵌共享的 Piik 标识;-平台后缀使该 Windows 资源不参与 Linux 和 macOS 构建。-Linux 程序包包含标准的 `share/applications` 桌面入口与 hicolor 图标。-macOS 的 `Piik App.app` 包含 ICNS 图标、App 程序及其辅助程序。-需要从终端运行时,入口为 `"Piik App.app/Contents/MacOS/piik-app"`。--图标源文件为 [public/favicon.svg](../../public/favicon.svg)。-将它按 16/24/32/48/64/128/256 px 导出为 PNG 图层,写入 `cmd/piik-app/piik.ico`;-打包脚本从这些图层生成 Linux 和 macOS 图标。同时更新网站导出:96 px 的-`public/favicon.png`,以及包含 16/32/48 px 图层的 `public/favicon.ico`。-按每个目标尺寸渲染 SVG,让小图标样式生效。检查深浅背景下的实际小尺寸效果,-然后在仓库根目录重新生成 Windows 资源:--```sh-go run github.com/akavel/[email protected] -ico cmd/piik-app/piik.ico -arch amd64 -o cmd/piik-app/piik_windows_amd64.syso-```--## 验证入口--Local gate 会启动已打包进程,在 Chromium 中加载真实构建的页面,验证启动访问与局域网-邀请构造,并检查进程和浏览器配置的完整清理。loopback gate 分别验证授予和未授予-Chromium Local Network Access 权限时的站点访问。以下环境变量语法用于 POSIX shell;-Windows 请使用等效的环境变量设置方式。--```sh-PIIK_CLIENT_LOCAL_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_EXE=/path/to/piik-app \-PIIK_CLIENT_GATE_LAN_ADDRESS=192.168.1.10 \-npm run gate:app-local--PIIK_CLIENT_LOOPBACK_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_EXE=/path/to/piik-app \-npm run probe:app-loopback--PIIK_CLIENT_MEDIA_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_CLIENT_GATE_STUN_URLS=stun:<stun-host>:3478 \-npm run gate:app-media--PIIK_CLIENT_NATIVE_HOST_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_GO=/path/to/go \-npm run gate:app-native-host--PIIK_CLIENT_NATIVE_HOST_GATE=true \-PIIK_CLIENT_LINK_MEDIA_GATE=true \-CHROME_PATH=/path/to/chrome \-PIIK_GO=/path/to/go \-PIIK_CLOUDFLARED=/path/to/cloudflared \-PIIK_REMOTE_HOST=<public-test-host> \-PIIK_REMOTE_USER=<ssh-user> \-PIIK_REMOTE_SSH_KEY=/path/to/key \-npm run gate:app-native-host--PIIK_CLIENT_LINK_GATE=true \-PIIK_GO=/path/to/go \-PIIK_CLOUDFLARED=/path/to/cloudflared \-PIIK_REMOTE_HOST=<public-test-host> \-PIIK_REMOTE_USER=<ssh-user> \-PIIK_REMOTE_SSH_KEY=/path/to/key \-npm run gate:app-link-```--Windows media gate 验证一个硬件 H.264 采集代次、共享 Pion 来源、浏览器解码、PLI 恢复和-STUN 候选收集。native Host gate 验证房间创建及当前路由上的原生视频传输;-能力探测与目标系统支持时,也包含原生音频。--公网邀请媒体变体通过 App 临时公网地址传送信令,要求将视频 RTP 直接传给独立的 Linux 对端,-且选中的候选对包含 `srflx` 或 `prflx`。SSH 仅运行远端探针,媒体不会经过 SSH。-不配置远端主机时,该变体在本机浏览器中通过公网邀请检查解码画面,不能据此认定跨网络连通。-原生 P2P 质量证据与内嵌 SFU 传输有各自的验证入口。-macOS 和 Linux 采集仍需实机桌面与媒体验证,CI 编译及程序包冒烟检查不能替代这些验证。+[App 开发指南(英文)](./DEVELOPMENT.md)集中说明源码构建、打包、桌面图标与验证入口。+维护者的 Release 发布流程见[部署与发布(英文)](../../docs/deployment.md)。diff --git a/cmd/piik-server/main.go b/cmd/piik-server/main.goindex 43cfe90e..0ec44e0e 100644--- a/cmd/piik-server/main.go+++ b/cmd/piik-server/main.go@@ -27,6 +27,7 @@ import ("github.com/TNTcraftHIM/Piik/internal/server/app""github.com/TNTcraftHIM/Piik/internal/server/config""github.com/TNTcraftHIM/Piik/internal/server/webassets"+ "github.com/TNTcraftHIM/Piik/internal/tlsconfig")// shutdownTimeout bounds the ordered stop (signaling, listener, room store).@@ -138,6 +139,9 @@ func serve(debug bool) (returnedErr error) {"host", configuration.ListenHost, "port", port, "publicUrl", config.Origin(configuration.PublicBaseURL),"sqlite", configuration.RoomDatabasePath != "", "siteAccessProtected", configuration.SiteAccessPassword != "","sfu", configuration.SFU != nil, "natPrediction", configuration.NATPredictionEnabled)+ if configuration.TLS != nil {+ logger.Info("HTTPS certificate", "sha256", tlsconfig.Fingerprint(configuration.TLS))+ }ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)// One bounded background lookup never delays serving. Join it before closingdiff --git a/deploy/frp/frpc.toml.example b/deploy/frp/frpc.toml.examplenew file mode 100644index 00000000..89f5fbb5--- /dev/null+++ b/deploy/frp/frpc.toml.example@@ -0,0 +1,21 @@+# Run beside Piik; inject the same nonempty FRP_TOKEN into frpc and frps.+# See docs/operations/self-hosting.md for the public HTTPS proxy and frps setup.+serverAddr = "relay.example.com"+serverPort = 7000+auth.token = "{{ .Envs.FRP_TOKEN }}"+transport.tls.enable = true++[[proxies]]+name = "piik-web"+type = "tcp"+localIP = "127.0.0.1"+localPort = 8787+remotePort = 8787++[[proxies]]+name = "piik-sfu"+type = "udp"+localIP = "127.0.0.1"+# All three ports must match: localPort, remotePort, Piik's SFU_UDP_PORT.+localPort = 7882+remotePort = 7882diff --git a/docs/README.md b/docs/README.mdindex 2fcd189f..a34ac1fb 100644--- a/docs/README.md+++ b/docs/README.md@@ -4,24 +4,17 @@For using Piik, troubleshooting or self-hosting, start with the[reader documentation](./guide/README.md) · [中文文档中心](./guide/README.zh-CN.md).-This page also indexes developer and maintainer references.+This page indexes developer and maintainer references.-## Guides And References+## Developer And Maintainer Entry Points| Task | Guide || --- | --- |-| Use Piik online | [Open the online site](https://demo.piik.tv) · [Online sharing guide](./guide/getting-started.md#use-piik-online) |-| Watch a friend or share my first screen | [Getting started](./guide/getting-started.md) |-| Choose an App mode or fix sound and connection trouble | [First-use help](./guide/getting-started.md#choose-an-app-mode) |-| Page opens but video will not connect / 网页能打开,画面连不上 | [Connection troubleshooting](./guide/getting-started.md#when-video-will-not-connect) · [中文排查](./guide/getting-started.zh-CN.md#画面连接不上) |-| Run Piik App, check platform requirements, or build a package | [App guide](../cmd/piik-app/README.md) · [中文 App 指南](../cmd/piik-app/README.zh-CN.md) || Try or change the source code | [Run from source](#run-from-source) || Find a directory or the module responsible for a behavior | [Repository layout and module map](./standards/engineering.md#repository-layout) || Find the shared product, design and lifecycle rules | [Standards index](./standards/README.md) |-| Host a site for my group | [Self-hosting](./operations/self-hosting.md) · [中文部署](./operations/self-hosting.zh-CN.md) |-| Keep a server running with systemd or Docker | [Service management](./operations/service-management.md) · [中文服务管理](./operations/service-management.zh-CN.md) |-| Set passwords, ports, or room storage | [Configuration](./standards/configuration.md) |-| Update my server | [Server updates](./operations/self-hosting.md#keep-it-running-and-update) |+| Deploy or configure a service | [Self-hosting](./operations/self-hosting.md) · [Configuration](./standards/configuration.md) · [Service management](./operations/service-management.md) |+| Build App packages and native capture | [App development](../cmd/piik-app/DEVELOPMENT.md) || Build, publish or recover a maintained release | [Maintainer release tooling](./deployment.md) || Send a useful bug report | [Diagnostics and export](./standards/configuration.md#diagnostics) || Translate Piik or improve wording | [Translation guide](./guide/translating.md) · [中文翻译教程](./guide/translating.zh-CN.md) |@@ -66,8 +59,8 @@ computer; remote invitations need a reachable origin as described in[configuration](./standards/configuration.md).Browser capture requires `localhost` or HTTPS.-For the self-contained App, follow [App development](../cmd/piik-app/README.md#development)-and [packaging](../cmd/piik-app/README.md#packaging), including the platform's+For the self-contained App, follow [App development](../cmd/piik-app/DEVELOPMENT.md#run-from-source)+and [packaging](../cmd/piik-app/DEVELOPMENT.md#packaging), including the platform'snative capture requirements.## Work on Piikdiff --git a/docs/adr/0005-automatic-hybrid-media-routing.md b/docs/adr/0005-automatic-hybrid-media-routing.mdindex dbebe504..eb13f9f9 100644--- a/docs/adr/0005-automatic-hybrid-media-routing.md+++ b/docs/adr/0005-automatic-hybrid-media-routing.md@@ -58,6 +58,12 @@ One transition-overlap reservation may temporarily raise a producer toauthorized. SFU ingress and subscription egress are independent server resourcesand are not inferred from endpoint child counts.+The room-voice candidate adds an explicit, session-scoped relay volunteer+override under the [endpoint capacity contract](../standards/routing-transport.md#endpoint-and-server-capacity).+It retains ordinary caps and one serial overlap reservation, but a capable+volunteer's admitted fanout may reach 20, with one extra transition slot.+This exception does not turn an ordinary Viewer into a separate SFU worker.+### One Graph And Reconcile LoopOne room controller owns:@@ -78,6 +84,15 @@ relay or a relay with reduced capacity accepts no new children; only itsdeterministic overflow children are reassigned. A relay whose ingress fails isitself reparented while its descendants remain attached.+### Room Media Lifetime (Candidate)++The room-voice candidate keeps this graph at room lifetime, with independent+picture generations and voice publications. Its existing serial operation also+owns video attachment and composite picture/voice readiness; physical facets+have distinct identities so retiring one cannot remove the others. The+[room-media contract](../standards/routing-transport.md#room-media) owns that+extension. No second graph, all-pairs mesh or generic transport framework is added.+### Deterministic CandidatesEach child operation owns one immutable purpose, one candidate list and cursor,diff --git a/docs/adr/0010-cross-platform-client-runtime.md b/docs/adr/0010-cross-platform-client-runtime.mdindex 9a36940f..3e5d2873 100644--- a/docs/adr/0010-cross-platform-client-runtime.md+++ b/docs/adr/0010-cross-platform-client-runtime.md@@ -79,7 +79,11 @@ topologies and makes a saved Site unavailable while another room source runs.the Site cannot approve itself. A popup message requests an authorized healthrecheck, not authorization. Clearing Site data requires connecting again.7. A self-contained Local deployment serves reachable LAN peers without a- central Piik service. Its explicit `--link` mode starts one accountless+ central Piik service. Local serves an in-memory self-signed HTTPS entry on+ the selected LAN IP and retains the Host's HTTP loopback entry at the same+ port. Both belong to the shared service lifecycle; certificate confirmation+ and optional Hosted TLS follow the [configuration owner](../standards/configuration.md).+ Its explicit `--link` mode starts one accountlessCloudflare Quick Tunnel for the same HTTP/WebSocket surface. The Appreserves the exact IPv4 listener before creating that tunnel, then appliesits HTTPS origin before the server starts serving that listener. It retains the samediff --git a/docs/assets/room-en-dark.png b/docs/assets/room-en-dark.pngindex c9d40c7a..778e2078 100644Binary files a/docs/assets/room-en-dark.png and b/docs/assets/room-en-dark.png differdiff --git a/docs/assets/room-en-light.png b/docs/assets/room-en-light.pngindex de2858c7..8e3fabbb 100644Binary files a/docs/assets/room-en-light.png and b/docs/assets/room-en-light.png differdiff --git a/docs/assets/room-zh-dark.png b/docs/assets/room-zh-dark.pngindex cc095021..39514608 100644Binary files a/docs/assets/room-zh-dark.png and b/docs/assets/room-zh-dark.png differdiff --git a/docs/assets/room-zh-light.png b/docs/assets/room-zh-light.pngindex 80f3abc8..94619abb 100644Binary files a/docs/assets/room-zh-light.png and b/docs/assets/room-zh-light.png differdiff --git a/docs/deployment.md b/docs/deployment.mdindex 4e45ff1e..8e1cc45d 100644--- a/docs/deployment.md+++ b/docs/deployment.md@@ -51,6 +51,12 @@ the archive, manifest, and descriptor together to `/opt/piik/uploads`.ARM64 file names include `-linux-arm64` after the revision; x64 names stayunchanged. The deployment wrapper rejects a package for another host architecture.+`--os windows --arch amd64` packages the same Server core as+`piik-<revision>-windows-amd64-runtime.zip`, with `piik-server.exe` in place of the+Linux executable. It uses the same descriptor and checksum inventory; containers+and `release-server.sh` remain Linux-only. Windows operation follows the+[self-hosting guide](./operations/self-hosting.md).+Public Release pages expose the runnable packages and put package checksums inthe release body. Retain the original complete build output outside the checkoutfor later managed deployment or mirror retries: descriptors and manifests arediff --git a/docs/guide/README.md b/docs/guide/README.mdindex 2ac042ab..4d27690e 100644--- a/docs/guide/README.md+++ b/docs/guide/README.md@@ -7,22 +7,22 @@ Choose a guide for what you want to do.## Start using Piik-| I want to… | Start here |-| --- | --- |-| Watch a friend | [Open an invitation](./getting-started.md#join-a-friends-room); no installation needed. |-| Share my screen | [Download Piik App](https://piik.tv/?lang=en#download), then follow [the App steps](./getting-started.md#share-with-piik-app). |-| Use Piik without installing | [Open the online site](https://demo.piik.tv) and follow [the online guide](./getting-started.md#use-piik-online). |-| Use my group's Piik site | [Connect the App or share in a browser](./getting-started.md#share-from-an-existing-site). |-| Understand App options | [Modes, platform requirements and diagnostics](../../cmd/piik-app/README.md). |+- **Watch a friend:** [open an invitation](./getting-started.md#join-a-friends-room); no installation needed.+- **Share my screen:** [download Piik App](https://piik.tv/?lang=en#download), then follow [the App steps](./getting-started.md#share-with-piik-app).+- **Use Piik without installing:** [open the online site](https://demo.piik.tv) and follow [the online guide](./getting-started.md#use-piik-online).+- **Use my group's Piik site:** [connect the App or share in a browser](./getting-started.md#share-from-an-existing-site).-## Get help+## Use the room tools++- [Sharing and playback](./sharing.md): picture quality, cameras, source sound and viewing controls.+- [Chat, voice and remote control](./room-tools.md): reactions, conversations and letting a friend take control.+- [App reference](../../cmd/piik-app/README.md): saved modes, site access, command-line options and diagnostics.-[Troubleshooting](./troubleshooting.md) starts from the symptom you see. Common checks:+## Get help-- [Public invitation failure or 1033](./troubleshooting.md#public-invitation-fails-or-shows-1033), or [room creation returns 403](./troubleshooting.md#room-creation-returns-403).-- [Sharing will not start](./troubleshooting.md#sharing-does-not-start-after-source-selection), [missing App sources](./troubleshooting.md#app-windows-or-screens-are-missing), or [H264 and graphics checks](./troubleshooting.md#h264-sharing-fails-on-windows).-- [Video will not connect](./troubleshooting.md#when-video-will-not-connect), including WebRTC settings and campus networks.-- [Blur or stuttering](./troubleshooting.md#picture-blurs-stutters-or-stops), or [HDR overexposure](./troubleshooting.md#hdr-picture-looks-too-bright-or-washed-out).+[Troubleshooting](./troubleshooting.md) groups checks by what is failing:+opening Piik or an invitation, starting a share, picture and sound, or the media connection.+Start with that symptom; advanced network checks come after the basic steps.Still stuck? [Report a problem](https://github.com/TNTcraftHIM/Piik/issues/new/choose)with your version, system, browser and reproduction steps. The@@ -32,7 +32,8 @@ with your version, system, browser and reproduction steps. The<p><a href="../operations/self-hosting.md#docker-compose"><img src="https://img.shields.io/badge/Deploy_with-Docker_Compose-2764c4?style=for-the-badge&logo=docker&logoColor=white" alt="Deploy Piik Server with Docker Compose"></a></p>-Self-hosting is an advanced option requiring a server, domain and network configuration.+Self-hosting is an advanced option. Public sites need a reachable address, HTTPS+and network configuration; App users do not need to deploy a server.- [Deploy Piik Server](../operations/self-hosting.md) with Docker Compose or the server package.- [Keep it running and update](../operations/service-management.md).diff --git a/docs/guide/README.zh-CN.md b/docs/guide/README.zh-CN.mdindex 14221972..b12f1387 100644--- a/docs/guide/README.zh-CN.md+++ b/docs/guide/README.zh-CN.md@@ -7,22 +7,21 @@## 开始使用-| 我想…… | 从这里开始 |-| --- | --- |-| 看朋友的分享 | [打开邀请链接](./getting-started.zh-CN.md#加入朋友的房间),无须安装。 |-| 分享自己的屏幕 | [下载 Piik App](https://piik.tv/?lang=zh-CN#download),再按 [App 使用步骤](./getting-started.zh-CN.md#用-piik-app-分享)操作。 |-| 免安装使用 | 打开[在线版](https://demo.piik.tv),参阅[在线版教程](./getting-started.zh-CN.md#使用在线版)。 |-| 使用已有的 Piik 站点 | [配合 App 使用,或直接在浏览器中分享](./getting-started.zh-CN.md#使用已有站点分享)。 |-| 了解 App 的选项 | [运行模式、平台要求与诊断](../../cmd/piik-app/README.zh-CN.md)。 |+- **看朋友的分享:** [打开邀请链接](./getting-started.zh-CN.md#加入朋友的房间),无须安装。+- **分享自己的屏幕:** [下载 Piik App](https://piik.tv/?lang=zh-CN#download),再按 [App 使用步骤](./getting-started.zh-CN.md#用-piik-app-分享)操作。+- **免安装使用:** 打开[在线版](https://demo.piik.tv),参阅[在线版教程](./getting-started.zh-CN.md#使用在线版)。+- **使用已有的 Piik 站点:** [配合 App 使用,或直接在浏览器中分享](./getting-started.zh-CN.md#使用已有站点分享)。-## 遇到问题+## 使用房间工具++- [分享与播放](./sharing.zh-CN.md):画质、摄像头、来源声音与观看控制。+- [聊天、语音与远程控制](./room-tools.zh-CN.md):表情互动、聊天,或让朋友接手操作。+- [App 使用参考](../../cmd/piik-app/README.zh-CN.md):模式记忆、站点授权、命令行参数与诊断。-[问题排查](./troubleshooting.zh-CN.md)按遇到的现象提供处理步骤,常用入口:+## 遇到问题-- [公网邀请失败或 1033](./troubleshooting.zh-CN.md#公网邀请创建失败或出现-1033)、[创建房间返回 403](./troubleshooting.zh-CN.md#创建房间返回-403)。-- [无法开始分享](./troubleshooting.zh-CN.md#选源后无法开始分享)、[App 找不到来源](./troubleshooting.zh-CN.md#app-找不到窗口或屏幕)、[H264 与显卡排查](./troubleshooting.zh-CN.md#windows-上-h264-分享失败)。-- [画面连接不上](./troubleshooting.zh-CN.md#画面连接不上),包括 WebRTC 设置与校园网问题。-- [模糊或卡顿](./troubleshooting.zh-CN.md#画面模糊卡顿或中断)、[HDR 过曝](./troubleshooting.zh-CN.md#hdr-画面过亮或颜色发白)。+[问题排查](./troubleshooting.zh-CN.md)按打不开 App 或邀请、无法开始分享、画面与声音、+媒体连接等现象分类。先看对应的常规步骤,需要时再进入进阶网络排查。仍然没解决?可以[反馈问题](https://github.com/TNTcraftHIM/Piik/issues/new/choose),附上版本、系统、浏览器和复现步骤。需要收集报告时,参阅@@ -32,7 +31,7 @@<p><a href="../operations/self-hosting.zh-CN.md#使用-docker-compose"><img src="https://img.shields.io/badge/Deploy_with-Docker_Compose-2764c4?style=for-the-badge&logo=docker&logoColor=white" alt="使用 Docker Compose 部署 Piik Server"></a></p>-自部署属于进阶操作,需要服务器、域名和网络配置。+自部署属于进阶操作;公网服务需要可访问的地址、HTTPS 与网络配置,普通 App 用户无须部署。- [部署 Piik Server](../operations/self-hosting.zh-CN.md):使用 Docker Compose 或服务端程序包。- [长期运行与更新](../operations/service-management.zh-CN.md)。diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.mdindex a976d643..f0017143 100644--- a/docs/guide/getting-started.md+++ b/docs/guide/getting-started.md@@ -7,8 +7,7 @@ watching, using Piik online, using Piik App and sharing through an existing site[Join a room](#join-a-friends-room) · [Use online](#use-piik-online) ·[Piik App](#share-with-piik-app) · [Existing site](#share-from-an-existing-site) ·-[Remote control](#let-a-friend-control-your-shared-screen) · [Chat and reactions](#chat-and-reactions) ·-[Troubleshooting](#when-something-gets-in-the-way)+[Room tools](./room-tools.md) · [Troubleshooting](./troubleshooting.md)Viewers need a browser and an invitation. To start sharing, download Piik Appand choose **Public invite**. To share without installing, open@@ -25,18 +24,7 @@ Use the playback button to pause or resume; on a computer, double-click the pictleave fullscreen where supported. On a phone, tap the picture to show the barand use its buttons. Safari may show system controls in video fullscreen.-<details>-<summary>Playback controls, at a glance</summary>--| Control | What it does |-| --- | --- |-| **Theater mode** | Expands the picture inside the browser tab. |-| **Fullscreen** | Expands the picture to the full screen. |-| **Picture in picture** | Opens a floating video where supported. |-| **Volume** | Goes up to 200% with audio boost, or 100% otherwise. Lower it if the sound distorts. |-| **Playback settings** | **Fit** keeps the whole picture visible; **Fill** crops its edges; **Stretch** fills the area by changing its proportions. Connection settings default to **Auto**; available alternatives depend on the host and site. |--</details>+See [playback controls](./sharing.md#playback-controls) for display and sound options.With just a four-digit room code, open the same Piik site and choose**Join a room**. You may need the site's passphrase and the room's password.@@ -77,6 +65,8 @@ restrictive networks may load the page but block video.**Screens** as available. Pick the actual source and sound option.5. Copy and send the room invitation. Keep both the App and sharing tab open.+If macOS blocks the first launch, follow the [Mac opening steps](./troubleshooting.md#macos-blocks-first-launch).+Click the launcher's update button to download the new App. **Gitee mirror**provides an alternative if the download is slow or unavailable. A new majorversion includes a compatibility warning that links to the upgrade instructions;@@ -105,6 +95,9 @@ See the [App guide](../../cmd/piik-app/README.md) for package and runtime detailFor Local room and Public invite, expand **Site passphrase** to set an optionalaccess passphrase.+Local invitations use HTTPS. On first access, confirm the local certificate+against the Host's App terminal before continuing; see the+[certificate guide](./troubleshooting.md#local-https-certificate-warning).Once the room service starts, click the connected **App** button at the top rightto return to the launcher, manage site access or reopen the room. The App terminalalso keeps an **App launcher** address. To change between Local room and Public@@ -126,18 +119,12 @@ selector; its list updates as soon as the connection completes.If connection fails, the App button offers **Retry** and **Download App**.You can still share and watch in your browser.-The same browser remembers this connection. On later visits, **Start sharing**-offers **Apps / Windows** and **Screens** from the running App. In another browser,-in a private window or after clearing site data, connect again. The same exact-site already approved by App needs no repeat confirmation. The launcher-shows the approved site; **×** beside its address revokes access. Approving a different site-replaces the previous one and ends that site's App connections.-Select **☆** beside the address to open that site automatically next time you-start the App. Turn it off to return to the launcher on startup. The connected-**App** button on the site opens the launcher for these settings.-If the site is unavailable, use the **App launcher** address in the App terminal.-To use your App with a friend's new public-invitation address, connect and approve-that address again. Sharing-quality settings saved in App survive the address change.+The browser remembers the connection to an approved site. Reconnect after+changing browsers, using a private window or clearing site data. In the App+launcher, **×** revokes a site and **☆** makes it open next time; approving a+different site replaces the previous one. See the [App reference](../../cmd/piik-app/README.md#modes)+for these options and returning to the launcher. A new public-invite address needs+its own approval.**A page that opens does not guarantee a video connection.** Public invite givesyour room a temporary web address; picture and sound still travel between@@ -160,8 +147,7 @@ Read the release notes onthe [update guide](../operations/service-management.md). Then update the Appsconnecting to that site and refresh all sharing and viewing pages.-Restarting an App or Server interrupts active shares. This upgrade does not-change the room database schema.+Restarting an App or Server interrupts active shares.## Share from an existing site@@ -188,159 +174,8 @@ The site manages rooms and invitations; the App supplies native capture.If its operator has enabled SFU forwarding, turn off **Privacy mode** beforesharing to allow that fallback. The project's online site uses P2P only.-## Picture and sound settings--Open **Sharing settings** below the picture. Picture presets are directly available;-expand **Fine-tune picture** for resolution, frame-rate, bitrate, picture preference and video codec.--- In **Fine-tune picture**, enter width and height under **Resolution limit**.- Piik preserves the source's proportions within that ceiling, including portrait- and ultrawide pictures.-- Sliders cover 15–60 fps in steps of 5 and 2–12 Mbps in steps of 0.5. You can also enter an- **FPS limit** from 1 to 240 fps and a **Bitrate limit** from 0.1 to 240 Mbps.- Values outside those slider steps show **Custom**; **Use common range**- selects the nearest available slider value.- The frame-rate limit depends- on picture size: for example, 1080p240, 1440p144 and 4K60 are accepted requests.-- Under **Sound**, adjust source audio and microphone input. **Audio quality**- controls the shared audio output: choose a preset or enter an **Audio bitrate limit**- from 6 to 320 kbps.--The selectable range depends on picture size and the connected App. Picture and sound-still adapt to the source, device and available bandwidth.--Piik remembers your applied settings for the next visit. Browser-only use remembers-them for the current site; opening Piik through an updated App also keeps them-when your public-invite address changes.--## Add your voice--While sharing, select **Microphone** below the picture and-allow microphone access. Select it again to mute. Open **Sharing settings → Sound** below the picture-to choose a microphone and adjust its input volume.-The default volume is 100%, with up to 200% available.-Source audio and your voice reach viewers together. The Host preview stays muted.--Camera sharing does not enable the microphone automatically. App **Apps / Windows**-and **Screens** capture use the same controls. Leave the device on **Default device**-or choose a specific microphone. In the **Camera** tab, allow access if asked,-then select a picture card to start sharing. Device names and previews depend on-browser permissions; while a camera is shared, other cameras are listed by name.-Use headphones to keep speaker sound from feeding back into the microphone.--With **Browser** or **Camera** capture, **Noise & echo reduction** in sound-settings is on by default, asking the browser to handle echo, noise and volume.-Turn it off for music or a virtual audio input. Device and system effects remain-controlled by their own settings. App native capture uses device/system audio settings.--A camera with a built-in microphone still needs separate video and audio input-selection. OBS Virtual Camera supplies video only. To include OBS audio, follow-the [OBS audio-routing guide](https://obsproject.com/kb/video-call-streaming-tutorial/),-then select the virtual audio input in Piik's microphone list and turn on the microphone.--### Exclude a voice app from screen audio--On Windows, this control applies to system sound from **Screens**. **Apps / Windows**-captures only the selected application's process tree; **Camera** uses the separately-selected microphone or audio input.--On supported Windows Apps, open the **Screens** tab and enable **System sound**.-Under **Exclude application audio**, select a window belonging to the voice app,-then choose the screen to share. Open the app's window and refresh if it is absent.-This excludes one process and its children. Other apps remain audible, including-those playing through other output devices.-It does not mute your Piik microphone or prevent speaker sound reaching a microphone.--If a virtual microphone remains audible with Piik's microphone off, temporarily-turn off **System sound** to compare. If the voice disappears, check the mixer's-playback output and monitoring, or capture only the desired application's window-audio. Excluding a voice app does not also exclude a separate mixer that plays-your processed voice, even through a virtual output device.--While sharing, use **Sharing settings → Sound** to change system sound or the-excluded app without stopping the share. If the app closes or restarts, source-audio stops; refresh the application list and select it again.-Turning source audio off retains the exclusion choice;-select **None** to restore unfiltered system audio. This control requires an updated page and a Windows App-whose capability probe supports process exclusion; it is not a Browser-capture filter.-Windows 10 support depends on system updates and the actual capability check.-If the option is absent, share a single application window or route the voice-app to a different playback device.--## Let a friend control your shared screen--1. Share through Piik App using **Apps / Windows** or **Screens**.-2. Open **Remote control** below the picture and turn it on. It starts with- **Ask each time**.-3. Your friend selects **Request control** in their playback bar. Choose- **Allow control** on your sharing page when their request arrives.--When sharing a window, switch back to that window after allowing control. Input-pauses while another window is active and resumes when you return.--One viewer can control at a time, using a desktop or mobile browser. Update the-host's App and the room's site, then refresh the viewing page. The control button-appears when the host enables control and the connection supports it. Browser-and camera capture cannot receive remote input.--Either person can choose **End control**. On the host's computer, **Ctrl+Alt+F10**-on Windows or **Control+Option+F10** on macOS also stops control. Changing the-shared source or stopping sharing turns remote control off. After a connection-interruption, the viewer requests control again.--On a phone, swipe to move the pointer, tap to click and hold to drag. Two-finger-tap is right-click; two-finger swipe scrolls. Pinch to zoom, then use two fingers-to move around the enlarged picture. **Remote keyboard** provides keys,-shortcuts and text input. On a computer, **Game mouse** captures continuous-mouse movement; press **Esc** to release it.--<details>-<summary>Permissions and platform support</summary>--**Room Viewers** allows a room member to take idle control without asking each-time; **Password** requires a separate control password. These choices apply-only to the current shared source. Control gives access to the computer's mouse-and keyboard, so allow people you trust. It is not limited to what is visible-inside the video.--macOS asks for Accessibility permission. Linux needs a supported desktop Portal-and currently controls a selected screen, not an application window. Windows-is the primary physically tested host; macOS/Linux device acceptance is still-limited. System-protected shortcuts and some games may not accept remote input.--</details>--## Chat and reactions--Once the host starts the first share, participants can select **Interact** below the-sofa to send messages. Select a person on the sofa to open their reaction menu:-your own reactions appear above you; reactions sent to a friend fly towards them.-The interaction window can be moved and resized without rearranging the page.--Supported desktop browsers show **Open in always-on-top window** in its top-right-corner. You can read messages, see reactions and select someone to interact with-while playing. Keep the Piik page open; closing the small window returns it to the page.-Use a windowed or borderless game; exclusive fullscreen may cover the window.-The window cannot show the game through its background or let mouse clicks pass through.--**On screen**, beside the message box or in the viewer's playback bar, shows new-messages over the picture. It is off by default and only changes your own view.-Adjust text size and opacity in **Playback settings → On-screen chat**, or in-the chat window's **Chat settings**. Both use the same local preferences.-System video fullscreen and picture in picture cannot show these overlays.--Stopping a share keeps the room's chat available. App Local and Public invite-rooms require the App to stay open. Each page retains only its latest received-messages: refreshing clears them, and late joiners receive no earlier history.-To keep a copy, use **Chat settings → Export chat** to save the latest messages-retained on this page (up to 1,000) as a text file.-Chat travels through the room's server and is **not end-to-end encrypted**.--## When something gets in the way--For sound, capture, startup or playback issues, see [Troubleshooting](./troubleshooting.md).--### When video will not connect--See [connection troubleshooting](./troubleshooting.md#when-video-will-not-connect)-for “No media route available” and similar connection failures.+## Next steps++- [Sharing and playback](./sharing.md): picture settings, camera inputs and source sound.+- [Chat, voice and remote control](./room-tools.md): talk, react or let a friend take control.+- [Troubleshooting](./troubleshooting.md): start from the symptom you see.diff --git a/docs/guide/getting-started.zh-CN.md b/docs/guide/getting-started.zh-CN.mdindex fa289aa8..1755ec20 100644--- a/docs/guide/getting-started.zh-CN.md+++ b/docs/guide/getting-started.zh-CN.md@@ -7,7 +7,7 @@ Piik 支持一位房主分享屏幕,最多 20 位受邀观众通过浏览器[加入房间](#加入朋友的房间) · [在线版](#使用在线版) ·[Piik App](#用-piik-app-分享) · [已有站点](#使用已有站点分享) ·-[远程控制](#让朋友操作共享的电脑) · [聊天与表情](#聊天与表情) · [问题排查](#遇到问题了)+[房间工具](./room-tools.zh-CN.md) · [问题排查](./troubleshooting.zh-CN.md)观众只需要浏览器和邀请链接。分享画面推荐下载 Piik App,选择 **公网邀请**。@@ -23,18 +23,7 @@ Piik 支持一位房主分享屏幕,最多 20 位受邀观众通过浏览器点击播控栏的按钮可暂停或继续;电脑上双击画面可进入或退出全屏(浏览器支持时)。手机上轻点画面唤出控制栏,再使用其中的按钮。Safari 的视频全屏可能使用系统播控。-<details>-<summary>播放按钮分别做什么?</summary>--| 按钮 | 作用 |-| --- | --- |-| **剧场模式** | 在浏览器标签页内展开画面。 |-| **全屏观看** | 将画面展开至全屏。 |-| **悬浮小窗** | 浏览器支持时,把视频放进独立小窗。 |-| **音量** | 支持增强时最高 200%,否则最高 100%;声音失真时调低一些。 |-| **播放设置** | **完整显示** 保留全部画面;**等比铺满** 会裁掉边缘;**拉伸铺满** 会改变比例。连接设置默认为 **自动**,可选线路取决于房主和站点。 |--</details>+画面显示与音量选项见[播放控制](./sharing.zh-CN.md#播放控制)。只有四位房间号时,打开同一个 Piik 站点,选择 **加入房间**。你可能需要站点口令和房间密码。能否通过房间号加入由房主决定;@@ -70,6 +59,8 @@ App 的本地房间和临时公网邀请会随本次 App 退出而结束。然后选定要分享的画面与声音。5. 复制房间邀请发给朋友。分享期间保持 App 和分享标签页打开。+macOS 首次打开被拦截时,按 [Mac 打开说明](./troubleshooting.zh-CN.md#macos-提示已损坏或无法验证开发者)处理。+点击启动页的更新按钮即可下载新版 App;下载慢或无法下载时,可使用下方的 **Gitee 备用下载**。跨大版本更新会显示兼容性提醒,点击提醒可查看升级说明;替换 App 前,请先阅读。@@ -94,6 +85,8 @@ Linux 原生采集还需要[系统组件](../../native/capture/linux/README.md)| **公网邀请** | 朋友在别处,想临时发个邀请。 | 需要互联网连接;公网地址只在本次 App 运行期间有效。 |本地房间和公网邀请可展开 **站点口令** 设置可选的访问口令。+本地邀请使用 HTTPS;首次访问时,先与房主的 App 终端核对本地证书,再继续进入,+操作见[证书确认说明](./troubleshooting.zh-CN.md#本地-https-证书提示)。房间服务启动后,点击网页右上角已就绪的 **App**,可回到启动页管理授权或重新进入房间;App 终端也保留 **App 启动页** 地址。更换本地房间/公网邀请模式时,关闭并重新打开 App 后选择。这会结束原有房间,公网邀请地址也会重新生成。@@ -110,14 +103,10 @@ App 终端也保留 **App 启动页** 地址。更换本地房间/公网邀请也可以在 **开始分享** 的选源窗口里点击 **连接 Piik App**,连接后列表会直接显示 App 来源。连接失败时,App 按钮旁会提供 **重试** 和 **下载 App**;仍可继续使用浏览器分享和观看。-同一浏览器会记住这次连接。之后直接访问站点,点击 **开始分享**,-选择 **程序 / 窗口** 或 **屏幕**,即可使用正在运行的 App。-换浏览器、使用无痕窗口或清除站点数据后,重新连接即可;App 已允许的同一站点无需再次确认。-启动页显示已授权的站点,网址右侧的 **×** 可取消授权;允许新站点会替换旧站点,并结束旧站点的 App 连接。-点亮网址旁的 **☆**,下次启动 App 时就会直接打开该站点;取消星标后恢复打开启动页。-连接后,点击站点顶部的 **App** 可再次打开启动页,管理这些设置。-站点打不开时,可使用 App 终端中的 **App 启动页** 地址。-如要通过自己的 App 使用朋友的新公网邀请地址,需要重新连接并确认;App 保存的分享画质不受地址变化影响。+浏览器会记住已授权站点的连接;换浏览器、使用无痕窗口或清除站点数据后,重新连接即可。+App 启动页的 **×** 可取消站点授权,**☆** 可设为下次启动时打开的站点;允许新站点会替换旧站点。+这些选项与返回启动页的方法见 [App 使用参考](../../cmd/piik-app/README.zh-CN.md#运行模式)。+朋友的新公网邀请地址需要单独授权。**网页能打开,不代表视频一定能连通。** 公网邀请为房间提供临时网页地址,画面和声音仍靠参与者之间的连接传输。此模式没有媒体服务器兜底,@@ -136,7 +125,7 @@ App 终端也保留 **App 启动页** 地址。更换本地房间/公网邀请- **已有站点:** 管理员先按[更新指南](../operations/service-management.zh-CN.md)升级 Server,然后更新连接该站点的 App,并刷新所有分享与观看页面。-重启 App 或 Server 会中断正在进行的分享。本次升级不变更房间数据库结构。+重启 App 或 Server 会中断正在进行的分享。## 使用已有站点分享@@ -159,121 +148,8 @@ App 终端也保留 **App 启动页** 地址。更换本地房间/公网邀请如果管理员已启用 SFU 转发,房主可在开始分享前关闭 **隐私模式**,允许使用这条兜底线路。项目提供的在线版仅使用 P2P。-## 画面与声音设置--在画面下方打开 **分享设置**,可直接选择画质预设;-展开 **画面细调**,再调整分辨率、帧率、码率、画面偏好和视频编码。--- 在 **画面细调** 的 **分辨率上限** 中填写宽和高。画面在上限内保留来源比例,- 包括竖屏和超宽屏。-- 滑块覆盖 15–60 帧(每步 5 帧)、2–12 Mbps(每步 0.5 Mbps)的常用范围;也可直接填写 1–240 帧的 **帧率上限**- 和 0.1–240 Mbps 的 **视频码率上限**。- 不在滑块档位上的数值显示为 **自定义**;点击 **返回常用范围**,使用最近的可用档位。- 帧率范围随画幅变化,例如可以请求 1080p240、1440p144 或 4K60。-- **声音** 下可调整来源声音和麦克风输入;**音频质量** 调整分享输出,- 可选择预设,也可填写 6–320 kbps 的 **音频码率上限**。--可选范围会随画幅和连接的 App 变化。实际画质和声音仍会根据来源、设备与可用带宽调整。--Piik 会记住已应用的设置,供下次使用。仅用浏览器时,设置保存在当前站点;-通过新版 App 打开时,更换公网邀请网址也能保留设置。--## 加上自己的声音--分享时,点击画面下方的 **麦克风**,并允许访问。-再次点击即可静音。在画面下方的 **分享设置 → 声音** 中可以选择麦克风和调节输入音量,默认 100%,最高可调至 200%。-观众会同时听到来源声音和你的解说;房主本机预览保持静音。--摄像头分享不会自动开启麦克风。App 的 **程序 / 窗口** 和 **屏幕** 采集也使用同一组控件,-可以保留「默认设备」,也可以指定麦克风。在 **摄像头** 页签中允许访问后,点击对应的画面卡片开始分享。-设备名称和可用预览取决于浏览器权限;正在分享摄像头时,其他摄像头只显示名称。-建议佩戴耳机,避免扬声器声音被麦克风再次收进去。--通过 **浏览器** 或 **摄像头** 分享时,声音设置中的 **降噪与回声消除** 默认开启,-由浏览器处理回声、杂音和音量。输入音乐或虚拟音频设备的声音时,可关闭它;-设备及系统自身的音效仍由各自设置控制。App 原生采集使用设备及系统的音频设置。--带麦克风的摄像头仍需分别选择画面和音频输入。OBS 虚拟摄像头只提供画面;-如需带上 OBS 的声音,可按 [OBS 音频转接教程](https://obsproject.com/kb/video-call-streaming-tutorial/)-设置虚拟音频设备,再在 Piik 的麦克风列表中选择对应输入并开启麦克风。--### 分享屏幕时排除语音软件的声音--在 Windows 上,此控件用于 **屏幕** 分享的系统声音。**程序 / 窗口** 只采集所选应用及其子进程的声音;-**摄像头** 的声音来自单独选择的麦克风或音频输入。--在支持此功能的 Windows App 中,打开 **屏幕** 页签并开启 **系统声音**,-在 **排除应用声音** 中选择语音软件的窗口,再选择要分享的屏幕。-未列出的应用请先打开窗口,再刷新。此功能排除所选进程及其子进程,-其他应用的声音仍会被分享,包括输出到其他播放设备的声音。-它不影响 Piik 麦克风,也不能消除扬声器被麦克风收音产生的回声。--使用虚拟麦克风时,如果关闭 Piik 麦克风后仍能听到你的声音,可暂时关闭 **系统声音** 对照。-若声音随之消失,请检查混音软件的播放输出与监听,或改为只分享目标应用的窗口音频。-排除语音软件不会同时排除另一个混音软件;后者输出到虚拟播放设备的声音也可能被采集。--开播后,可在 **分享设置 → 声音** 中调整系统声音和排除的应用,无需停止分享。-所选应用关闭或重启后,来源声音会停止;请刷新应用列表并重新选择。-暂时关闭来源声音会保留排除选择;需要恢复完整的系统声音时,选择 **不排除**。-此控件需要新版页面和通过进程排除能力检测的 Windows App,不适用于浏览器自带的分享选择器。-Windows 10 是否支持取决于系统更新与实际检测;未显示此选项时,可改为分享单个应用窗口,或将语音软件输出到另一播放设备。--## 让朋友操作共享的电脑--1. 通过 Piik App 的 **程序 / 窗口** 或 **屏幕** 开始分享。-2. 打开画面下方的 **远程控制** 并开启开关,默认使用 **每次询问**。-3. 朋友在播放控制栏中点击 **请求控制**。收到请求后,在自己的分享页面选择 **允许控制**。--分享窗口时,允许控制后请切回该窗口。其他窗口处于前台时,远程输入会暂停;切回即可继续。--同一时间只能有一位观众控制,可使用电脑或手机浏览器。更新房主的 App 和房间所在站点后,-观众刷新页面即可。房主开启远控、连接支持后,观众才会看到控制按钮。-浏览器和摄像头采集不支持接收远程操作。--双方都可以点击 **结束控制**。房主还可以在本机按 **Ctrl+Alt+F10**(Windows)-或 **Control+Option+F10**(macOS)立即结束。切换来源或停止分享会关闭远控;-连接中断后,观众需要重新请求。--手机上滑动可移动鼠标,轻点点击、长按拖动;双指轻点右击、滑动滚动。-捏合可以放大画面,放大后用双指移动查看位置。**远程键盘** 提供按键、组合键和文字输入。-电脑上可开启 **游戏鼠标** 连续转动视角,按 **Esc** 释放鼠标。--<details>-<summary>授权与平台支持</summary>--**房间观众** 允许房间内的观众直接取得空闲控制权;**控制密码** 要求输入单独设置的控制密码。-这些设置只对当前分享来源有效。允许控制后,对方可以操作这台电脑的鼠标和键盘,-请只授权给信任的人;操作范围不受视频画面边界限制。--macOS 需要允许「辅助功能」权限。Linux 需要桌面环境支持 Portal,目前只支持控制所选屏幕,-不支持单个应用窗口。Windows 是主要经过实机验证的房主平台,macOS/Linux 的设备验收仍有限。-受系统保护的快捷键和部分游戏可能无法接收远程输入。--</details>--## 聊天与表情--房主首次开始分享、创建房间后,参与者可以点击沙发下方的 **互动** 发送消息。-点击沙发上的人物可打开表情菜单:给自己发的表情出现在头顶,送给朋友的表情会飞向对方。-互动窗口可以移动和缩放,不会挤动页面。--支持的桌面浏览器会在窗口右上角显示 **在置顶窗口中打开**,方便玩游戏时看消息、接收表情,-也可以在小窗中选人互动。保持 Piik 页面打开;关闭小窗会将它收回页面。建议游戏使用窗口或无边框模式,-独占全屏不保证显示置顶窗。小窗目前不支持透出游戏画面或鼠标穿透。--输入框旁和观众播放控制栏中的 **弹幕** 可以把新消息显示在画面上,默认关闭,只影响自己的观看。-通过 **播放设置 → 弹幕** 或聊天窗口中的 **聊天设置** 调整字号和不透明度,两处共用本机设置。-系统视频全屏和画中画无法显示弹幕。--停止分享后仍可继续聊天;App 的本地房间和公网邀请需要保持 App 运行。-每个页面只保留本页最近收到的消息,刷新后清空,后来加入的人看不到此前的记录。-需要留存时,可通过 **聊天设置 → 导出聊天记录** 将本页保留的最近消息(最多 1,000 条)保存为文本文件。-聊天消息经过房间所在的服务器,**不提供端到端加密**。--## 遇到问题了--声音、采集、启动或播放遇到问题时,先看[问题排查](./troubleshooting.zh-CN.md)。--### 画面连接不上+## 接下来可以做什么-出现「没有可用的媒体线路」等提示时,参阅[画面连接排查](./troubleshooting.zh-CN.md#画面连接不上)。+- [分享与播放](./sharing.zh-CN.md):画面设置、摄像头与来源声音。+- [聊天、语音与远程控制](./room-tools.zh-CN.md):聊天互动,或让朋友接手操作。+- [问题排查](./troubleshooting.zh-CN.md):按遇到的现象寻找处理步骤。diff --git a/docs/guide/room-tools.md b/docs/guide/room-tools.mdnew file mode 100644index 00000000..29c07b05--- /dev/null+++ b/docs/guide/room-tools.md@@ -0,0 +1,127 @@+# Chat, voice and remote control++English · [简体中文](./room-tools.zh-CN.md) · [Documentation](./README.md)++These tools belong to the room. You can chat before or after a picture share;+remote control requires an active App window or screen share.++## Chat and reactions++Once the host creates a room, participants can select **Interact** below the+sofa to send messages. Select a person on the sofa to open their reaction menu:+your own reactions appear above you; reactions sent to a friend fly towards them.+Chat and voice avatars also open a quick reaction menu; **More reactions**+shows the full palette while the conversation stays available.+The interaction window can be moved and resized without rearranging the page.++Supported desktop browsers show **Open in always-on-top window** in its top-right+corner. You can read messages, see reactions and select someone to interact with+while playing. Keep the Piik page open; closing the small window returns it to the page.+Use a windowed or borderless game; exclusive fullscreen may cover the window.+The window cannot show the game through its background or let mouse clicks pass through.++**On screen**, beside the message box or in the viewer's playback bar, shows new+messages over the picture. It is off by default and only changes your own view.+The settings button beside the Chat/Voice tabs opens the current page's settings;+**Back** returns to that page. **Chat settings** contains text size and opacity.+Playback settings remain dedicated to picture display and connection preferences.+System video fullscreen and picture in picture cannot show these overlays.++Stopping a share keeps the room's chat available. App Local and Public invite+rooms require the App to stay open. Each page retains only its latest received+messages: refreshing clears them, and late joiners receive no earlier history.+To keep a copy, use **Chat settings → Export chat** to save the latest messages+retained on this page (up to 1,000) as a text file.+Chat travels through the room's server and is **not end-to-end encrypted**.++## Room voice++The Host may choose **Create room** before sharing, then copy its invitation.+Open **Interact → Voice** and select **Open room voice**. Room members can then+select **Join voice**, without another approval.+Joining never opens a microphone: each speaker selects the **Microphone** button+and grants browser access. A person's speaker button mutes them only for you.+Microphone capture needs a browser-accepted HTTPS or localhost page; ordinary+LAN HTTP pages can still join and listen. For voice input or remote control over+a LAN or virtual LAN, see the [virtual-LAN options](./troubleshooting.md#optional-a-virtual-lan).+After joining, the bottom toolbar provides microphone, listening and leave+controls. The headphone button pauses room voice locally; your microphone, video+sound and voice forwarding remain unaffected. **Voice settings**+offers input device, microphone and listening volumes (both 0%–200%, default+100%), and noise/echo reduction. Listening volume only changes room voice for+you. The microphone icon's green fill rises with your actual input level;+a slashed icon means the microphone is off. Browser and App-backed sharing use+these same controls. Hover over a microphone, headphone or person's speaker+button to adjust its volume directly; on touchscreens, press and hold it.+A person's local 0%–200% level combines with the master listening level and+does not change what anyone else hears. Participant microphone status stays+visible while the green dot indicates speech.++Voice stays connected when picture sharing stops. It also stays active when you+close or detach the interaction window. Viewers choose **Leave voice** to leave;+the Host's **Close room voice** ends voice for everyone. Reopening does not+rejoin Viewers or turn on their microphones.+Host speech uses this same room microphone; viewers join voice to hear it.+Source sound stays with the picture. Room voice favors timely conversation and+can arrive ahead of a delayed picture. Use headphones; whole-system sound sharing can include+received voices, so [audio exclusion](./sharing.md#exclude-a-voice-app-from-screen-audio)+may help on supported App capture paths.++Microphone and master listening settings stay in this browser on the current+site; person volumes apply to current room participants. Settings never reopen+your microphone automatically. Keep noise and echo reduction on for ordinary+speech, or turn it off when the selected input already processes your voice.++## Let a friend control your shared screen++1. Share through Piik App using **Apps / Windows** or **Screens**.+2. Open **Remote control** below the picture and turn it on. It starts with+ **Ask each time**.+3. Your friend selects **Request control** in their playback bar. Choose+ **Allow control** on your sharing page when their request arrives.++When sharing a window, switch back to that window after allowing control. Input+pauses while another window is active and resumes when you return.++One viewer can control at a time, using a desktop or mobile browser. Update the+host's App and the room's site, then refresh the viewing page. The control button+appears when the host enables control and the connection supports it. Browser+and camera capture cannot receive remote input.+Viewers need HTTPS or a localhost page for remote control. A LAN or virtual-IP+HTTP page can play video but lacks the browser cryptography interface required+for remote control, so no control button appears.++Either person can choose **End control**. On the host's computer, **Ctrl+Alt+F10**+on Windows or **Control+Option+F10** on macOS also stops control by default.+Change the function key in the host's **Remote control** panel if it conflicts+with another app. Shortcut choices are saved in this site's browser storage;+each site is configured independently. The viewer can separately change **Exit control shortcut**+in **Remote keyboard**, including its detached window. Changing the+shared source or stopping sharing turns remote control off. After a connection+interruption, the viewer requests control again.+The authorization choice is remembered, but remote control does not turn on+automatically. If the previous choice was **Room Viewers**, enabling it shows+the permission explanation first; select **Allow Viewers** to+apply it. Control passwords are not saved.++On a phone, swipe to move the pointer, tap to click and hold to drag. Two-finger+tap is right-click; two-finger swipe scrolls. Pinch to zoom, then use two fingers+to move around the enlarged picture. **Remote keyboard** provides keys,+shortcuts and text input. On a computer, **Game mouse** captures continuous+mouse movement; press **Esc** to release it.++<details>+<summary>Permissions and platform support</summary>++**Room Viewers** allows a room member to take idle control without asking each+time; **Password** requires a separate control password. These choices apply+only to the current shared source. Control gives access to the computer's mouse+and keyboard, so allow people you trust. It is not limited to what is visible+inside the video.++macOS asks for Accessibility permission. Linux needs a supported desktop Portal+and currently controls a selected screen, not an application window. Windows+is the primary physically tested host; macOS/Linux device acceptance is still+limited. System-protected shortcuts and some games may not accept remote input.++</details>diff --git a/docs/guide/room-tools.zh-CN.md b/docs/guide/room-tools.zh-CN.mdnew file mode 100644index 00000000..5a86390d--- /dev/null+++ b/docs/guide/room-tools.zh-CN.md@@ -0,0 +1,96 @@+# 聊天、语音与远程控制++[English](./room-tools.md) · 简体中文 · [文档中心](./README.zh-CN.md)++这些工具以房间为单位。开播前、停播后都可以聊天;远程控制需要房主正在通过 App 分享窗口或屏幕。++## 聊天与表情++房主创建房间后,参与者可以点击沙发下方的 **互动** 发送消息。+点击沙发上的人物可打开表情菜单:给自己发的表情出现在头顶,送给朋友的表情会飞向对方。+聊天或语音列表中的头像也能打开快捷表情菜单;点击 **更多表情** 可展开完整选择,同时继续看消息和聊天。+互动窗口可以移动和缩放,不会挤动页面。++支持的桌面浏览器会在窗口右上角显示 **在置顶窗口中打开**,方便玩游戏时看消息、接收表情,+也可以在小窗中选人互动。保持 Piik 页面打开;关闭小窗会将它收回页面。建议游戏使用窗口或无边框模式,+独占全屏不保证显示置顶窗。小窗目前不支持透出游戏画面或鼠标穿透。++输入框旁和观众播放控制栏中的 **弹幕** 可以把新消息显示在画面上,默认关闭,只影响自己的观看。+聊天与语音共用标签页旁的设置按钮,点击 **返回** 可回到原页面。+**聊天设置** 可调整字号和不透明度;播放设置负责画面显示和连接偏好。+系统视频全屏和画中画无法显示弹幕。++停止分享后仍可继续聊天;App 的本地房间和公网邀请需要保持 App 运行。+每个页面只保留本页最近收到的消息,刷新后清空,后来加入的人看不到此前的记录。+需要留存时,可通过 **聊天设置 → 导出聊天记录** 将本页保留的最近消息(最多 1,000 条)保存为文本文件。+聊天消息经过房间所在的服务器,**不提供端到端加密**。++## 房间语音++房主可先点击 **创建房间**、复制邀请,不必立即开播。+打开 **互动 → 语音**,点击 **开启房间语音**,房间成员即可自行 **加入语音**,不需要再次审批。+加入不会打开麦克风;发言者仍需自己点击 **麦克风** 按钮,并允许浏览器访问。+开麦需要浏览器接受的 HTTPS 页面或本机地址;普通内网 HTTP 页面仍可加入收听。+局域网或虚拟局域网下需要开麦、远控时,参阅[虚拟局域网说明](./troubleshooting.zh-CN.md#可选虚拟局域网)。+点击某个人的扬声器按钮,只在你这里静音此人。+加入后,底部工具栏提供麦克风、收听和退出按钮。+耳机按钮只暂停你这里的房间语音播放,麦克风、视频声音和语音转发不受影响。+语音页的 **语音设置** 可选择输入设备、调整麦克风和收听音量(均为 0%–200%,默认 100%),+以及开关降噪与回声消除。收听音量只改变你听到的房间语音。+麦克风图标里的绿色填充随实际输入音量升降,斜线则表示麦克风已关闭。+浏览器与 App 分享都使用这组控件。+悬停在麦克风、耳机或某个人的扬声器按钮上,可直接调节对应音量;触屏上可长按。+每个人都有独立的 0%–200% 音量,与总收听音量叠加,只改变你自己听到的声音。+参与者的麦克风开关状态固定显示,绿点亮起才表示正在说话。++停止画面分享后仍可继续语音;关闭或弹出互动窗口也不会退出。+观众可点击 **退出语音**;房主点击 **关闭房间语音** 会结束所有人的语音。+重新开启后,观众仍需自行加入、开麦。+房主说话也使用这个房间麦克风,观众需加入语音才能收听。+来源声音继续跟随画面;房间语音优先保证实时交流,画面延迟时可能先听到说话声。+建议佩戴耳机;分享整个系统声音可能把收到的语音再次传出,支持的 App 采集路径可尝试+[排除应用声音](./sharing.zh-CN.md#分享屏幕时排除语音软件的声音)。++麦克风和总收听设置保存在当前站点的浏览器中,个人音量只用于当前房间的参与者;不会自动重新开麦。+普通说话通常保持降噪与回声消除开启;+如果输入设备已经处理了声音,可关闭它。++## 让朋友操作共享的电脑++1. 通过 Piik App 的 **程序 / 窗口** 或 **屏幕** 开始分享。+2. 打开画面下方的 **远程控制** 并开启开关,默认使用 **每次询问**。+3. 朋友在播放控制栏中点击 **请求控制**。收到请求后,在自己的分享页面选择 **允许控制**。++分享窗口时,允许控制后请切回该窗口。其他窗口处于前台时,远程输入会暂停;切回即可继续。++同一时间只能有一位观众控制,可使用电脑或手机浏览器。更新房主的 App 和房间所在站点后,+观众刷新页面即可。房主开启远控、连接支持后,观众才会看到控制按钮。+浏览器和摄像头采集不支持接收远程操作。+观众需通过 HTTPS 或本机页面使用远控;普通局域网或虚拟 IP 的 HTTP 页面可以观看,+但没有远控所需的浏览器加密接口,因此不会出现控制按钮。++双方都可以点击 **结束控制**。房主还可以在本机按 **Ctrl+Alt+F10**(Windows)+或 **Control+Option+F10**(macOS)立即结束;如与其他应用冲突,可在房主的+**远程控制** 面板中更换功能键。快捷键保存在当前站点的浏览器存储中,各站点独立设置。+观众可以在 **远程键盘** 中单独调整+**退出控制快捷键**,独立键盘窗口也可使用。切换来源或停止分享会关闭远控;+连接中断后,观众需要重新请求。+授权方式会记住,但不会自动开启远控。上次选择 **房间观众** 时,再次开启会先展示+授权说明;点击 **允许观众控制** 后才生效。控制密码不会保存。++手机上滑动可移动鼠标,轻点点击、长按拖动;双指轻点右击、滑动滚动。+捏合可以放大画面,放大后用双指移动查看位置。**远程键盘** 提供按键、组合键和文字输入。+电脑上可开启 **游戏鼠标** 连续转动视角,按 **Esc** 释放鼠标。++<details>+<summary>授权与平台支持</summary>++**房间观众** 允许房间内的观众直接取得空闲控制权;**控制密码** 要求输入单独设置的控制密码。+这些设置只对当前分享来源有效。允许控制后,对方可以操作这台电脑的鼠标和键盘,+请只授权给信任的人;操作范围不受视频画面边界限制。++macOS 需要允许「辅助功能」权限。Linux 需要桌面环境支持 Portal,目前只支持控制所选屏幕,+不支持单个应用窗口。Windows 是主要经过实机验证的房主平台,macOS/Linux 的设备验收仍有限。+受系统保护的快捷键和部分游戏可能无法接收远程输入。++</details>diff --git a/docs/guide/sharing.md b/docs/guide/sharing.mdnew file mode 100644index 00000000..e5b52db6--- /dev/null+++ b/docs/guide/sharing.md@@ -0,0 +1,86 @@+# Sharing and playback++English · [简体中文](./sharing.zh-CN.md) · [Documentation](./README.md)++Start with [your first room](./getting-started.md). This guide covers the picture+and source sound you share, plus controls that affect only your own viewing.++## Picture and sound settings++Open **Sharing settings** below the picture. Choose a picture preset first;+expand **Fine-tune picture** to adjust resolution, frame rate, bitrate, picture+preference or video codec. Resolution is a ceiling: the source keeps its proportions,+including portrait and ultrawide pictures.++Sliders cover common values. To go beyond them, enter a custom value within the+range shown by the field; **Use common range** returns to a nearby slider value.+Under **Sound**, choose the source audio and its output quality. Actual picture+and sound still adapt to the source, device and available bandwidth.++Applied settings are remembered for the current site. Opening Piik through an+updated App also keeps sharing-quality settings when a public-invite address changes.++## Cameras and virtual audio inputs++Camera sharing requests only video permission. In the **Camera** tab, allow+access if asked, then select a picture card. Device names and previews depend+on browser permissions; while a camera is shared, other cameras are listed by name.+A camera with a built-in microphone still needs separate video and audio input+selection. OBS Virtual Camera supplies video only. To include OBS audio, follow+the [OBS audio-routing guide](https://obsproject.com/kb/video-call-streaming-tutorial/),+then choose that input in [room voice’s microphone settings](./room-tools.md#room-voice) and turn it on.+This is the conversation channel, separate from the camera picture and source sound.++## Exclude a voice app from screen audio++On Windows, this control applies to system sound from **Screens**. **Apps / Windows**+captures only the selected application's process tree. **Camera** shares video;+its microphone or virtual audio input uses room voice separately.++On supported Windows Apps, open the **Screens** tab and enable **System sound**.+Under **Exclude application audio**, select a window belonging to the voice app,+then choose the screen to share. Open the app's window and refresh if it is absent.+This excludes one process and its children. Other apps remain audible, including+those playing through other output devices.+It does not mute your Piik microphone or prevent speaker sound reaching a microphone.++If a virtual microphone remains audible with Piik's microphone off, temporarily+turn off **System sound** to compare. If the voice disappears, check the mixer's+playback output and monitoring, or capture only the desired application's window+audio. Excluding a voice app does not also exclude a separate mixer that plays+your processed voice, even through a virtual output device.++While sharing, use **Sharing settings → Sound** to change system sound or the+excluded app without stopping the share. If the app closes or restarts, source+audio stops; refresh the application list and select it again.+Turning source audio off retains the exclusion choice;+select **None** to restore unfiltered system audio. This control requires an updated page and a Windows App+whose capability probe supports process exclusion; it is not a Browser-capture filter.+Windows 10 support depends on system updates and the actual capability check.+If the option is absent, share a single application window or route the voice+app to a different playback device.++## Playback controls++The playback bar changes only your own viewing and listening. Move the pointer+over the picture or tap it to show the bar.++| Control | What it does |+| --- | --- |+| **Theater mode** | Expands the picture inside the browser tab. |+| **Fullscreen** | Expands the picture to the full screen. |+| **Picture in picture** | Opens a floating video where supported. |+| **Volume** | Goes up to 200% with audio boost, or 100% otherwise. Lower it if the sound distorts. |+| **Playback settings** | **Fit** keeps the whole picture visible; **Fill** crops its edges; **Stretch** fills the area by changing its proportions. Connection settings default to **Auto**; available alternatives depend on the host and site. |+| **Rotate picture** | Switches between portrait and landscape locally, without rotating the device or changing the shared source. |++### Connection preferences++Leave the connection setting on **Auto** unless comparing a specific route.+The choices depend on the Host and site; selecting a route does not make an+unavailable server or blocked network reachable.++On supporting sites, **Playback settings → Connection → Help relay to more+viewers** lets a Viewer volunteer more upload for the current visit. It remains+an ordinary P2P relay; enable it on a stable connection with upload to spare.+This option requires updated Server/Web pages; older sites do not offer it.diff --git a/docs/guide/sharing.zh-CN.md b/docs/guide/sharing.zh-CN.mdnew file mode 100644index 00000000..09fb22af--- /dev/null+++ b/docs/guide/sharing.zh-CN.md@@ -0,0 +1,70 @@+# 分享与播放++[English](./sharing.md) · 简体中文 · [文档中心](./README.zh-CN.md)++第一次使用请先看[快速上手](./getting-started.zh-CN.md)。本页介绍分享的画面、来源声音,+以及只影响自己观看的播放控制。++## 画面与声音设置++在画面下方打开 **分享设置**,先选择画质预设;需要进一步调整时,展开 **画面细调**,+修改分辨率、帧率、码率、画面偏好或视频编码。分辨率表示上限,画面仍保留来源比例,+包括竖屏和超宽屏。++滑块提供常用范围;需要更高或更低的数值时,可在输入框显示的范围内自定义。+点击 **返回常用范围** 可回到附近的滑块档位。在 **声音** 中选择来源声音和输出质量。+实际画质与声音仍会根据来源、设备和可用带宽调整。++已应用的设置会保存在当前站点;通过新版 App 打开时,更换公网邀请网址也能保留分享画质设置。++## 摄像头与虚拟音频输入++摄像头分享只请求画面权限。在 **摄像头** 页签中允许访问后,点击对应的画面卡片开始分享。+设备名称和可用预览取决于浏览器权限;正在分享摄像头时,其他摄像头只显示名称。+带麦克风的摄像头仍需分别选择画面和音频输入。OBS 虚拟摄像头只提供画面;+如需带上 OBS 的声音,可按 [OBS 音频转接教程](https://obsproject.com/kb/video-call-streaming-tutorial/)+设置虚拟音频设备,再在[房间语音的麦克风设置](./room-tools.zh-CN.md#房间语音) 中选择对应输入并开启麦克风。+它使用实时语音频道,与摄像头画面、来源声音分开传输。++## 分享屏幕时排除语音软件的声音++在 Windows 上,此控件用于 **屏幕** 分享的系统声音。**程序 / 窗口** 只采集所选应用及其子进程的声音;+**摄像头** 分享画面,麦克风或虚拟音频输入通过房间语音单独传输。++在支持此功能的 Windows App 中,打开 **屏幕** 页签并开启 **系统声音**,+在 **排除应用声音** 中选择语音软件的窗口,再选择要分享的屏幕。+未列出的应用请先打开窗口,再刷新。此功能排除所选进程及其子进程,+其他应用的声音仍会被分享,包括输出到其他播放设备的声音。+它不影响 Piik 麦克风,也不能消除扬声器被麦克风收音产生的回声。++使用虚拟麦克风时,如果关闭 Piik 麦克风后仍能听到你的声音,可暂时关闭 **系统声音** 对照。+若声音随之消失,请检查混音软件的播放输出与监听,或改为只分享目标应用的窗口音频。+排除语音软件不会同时排除另一个混音软件;后者输出到虚拟播放设备的声音也可能被采集。++开播后,可在 **分享设置 → 声音** 中调整系统声音和排除的应用,无需停止分享。+所选应用关闭或重启后,来源声音会停止;请刷新应用列表并重新选择。+暂时关闭来源声音会保留排除选择;需要恢复完整的系统声音时,选择 **不排除**。+此控件需要新版页面和通过进程排除能力检测的 Windows App,不适用于浏览器自带的分享选择器。+Windows 10 是否支持取决于系统更新与实际检测;未显示此选项时,可改为分享单个应用窗口,或将语音软件输出到另一播放设备。++## 播放控制++播放控制栏只影响你自己看到的画面和听到的声音。将鼠标移到画面上,或轻点画面,即可显示。++| 按钮 | 作用 |+| --- | --- |+| **剧场模式** | 在浏览器标签页内展开画面。 |+| **全屏观看** | 将画面展开至全屏。 |+| **悬浮小窗** | 浏览器支持时,把视频放进独立小窗。 |+| **音量** | 支持增强时最高 200%,否则最高 100%;声音失真时调低一些。 |+| **播放设置** | **完整显示** 保留全部画面;**等比铺满** 会裁掉边缘;**拉伸铺满** 会改变比例。连接设置默认为 **自动**,可选线路取决于房主和站点。 |+| **横竖切换** | 只在本机切换画面方向,无需打开设备自动旋转,也不改变分享源。 |++### 连接偏好++通常保持 **自动**,需要对照某条线路时再选择其他选项。可选线路取决于房主和站点;+选择某条线路,并不会让未开启的服务器或被网络阻断的连接变得可用。++支持的站点还提供 **播放设置 → 连接 → 帮助更多观众转发**,+允许观众为本次访问提供更多上行带宽。它仍是普通 P2P 转发;请在连接稳定、上行有余量时开启。+这个选项需要更新 Server/网页,旧版站点不会出现。diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.mdindex 020e04f3..50e78e90 100644--- a/docs/guide/troubleshooting.md+++ b/docs/guide/troubleshooting.md@@ -1,70 +1,168 @@+---+outline: 2+---+# TroubleshootingEnglish · [简体中文](./troubleshooting.zh-CN.md) · [Documentation](./README.md)-Find the symptom below and try the suggested checks. Stop when it works;-collect a diagnostic report if the problem persists.+Find your symptom below. Try its checks in order and stop when it works.+If it persists, [save a diagnostic report](#reporting-a-problem) before refreshing.## Common problems-| What you see | Try this |+- [Opening App and joining a room](#opening-app-and-joining-a-room): startup, invitation links, certificates and room access.+- [Starting a share](#starting-a-share): source lists, capture permissions and encoders.+- [Picture and playback](#picture-and-playback): connection, quality, games and fullscreen.+- [Sound and browser permissions](#sound-and-browser-permissions): source sound, voice, echo and remote control.+- [Advanced network checks](#advanced-network-checks): WebRTC, STUN, campus networks and virtual LANs.++## Opening App and joining a room++### App startup fails, or no page opens++1. Read the reason on the launch page and in the terminal. If the App is still+ running, copy its displayed address into your browser.+2. If Local mode lists several addresses, choose the adapter and IP that friends+ can reach. See [Local invitation checks](#local-invitation-will-not-open).+3. If startup still fails, retry with **Debug launch** enabled and save the complete+ error and an [App report](#reporting-a-problem).++### macOS blocks first launch++Current Mac builds are not Developer ID-signed or notarized. macOS can block+their first launch; the wording alone does not identify a damaged download.++1. Download the matching Mac ZIP from the project's Releases and compare its+ SHA-256 with the checksum published for that release. In Terminal, run+ `shasum -a256 ~/Downloads/piik-app-darwin-arm64.zip` (use `darwin-amd64` on Intel).+ If it differs, download again rather than bypassing the warning.+2. Move the complete `Piik App.app` to Applications. Try opening it, then check+ **System Settings → Privacy & Security → Open Anyway**, as described in+ [Apple's first-launch guidance](https://support.apple.com/102445).+3. If **Open Anyway** is unavailable and the official ZIP's checksum matches,+ you can remove the download quarantine from this App only, then reopen it:++ ```sh+ xattr -dr com.apple.quarantine "/Applications/Piik App.app"+ ```++Use the App's actual path if you kept it elsewhere. Keep system-wide security+checks enabled.++### Public invitation fails or shows 1033++App **Public invite** uses Cloudflare Tunnel to provide a temporary web address.+Reachability varies by network, and [Quick Tunnels have no uptime guarantee](https://developers.cloudflare.com/tunnel/get-started/quick-tunnels/#limitations).+`public invitation service exited before connecting` means the helper exited+before connecting; `exit status 1` alone does not identify the cause.+[Cloudflare error 1033](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1033/)+means that the address currently has no available tunnel connection. This differs+from a page that opens but reports **No media route available**.++1. **Viewers: confirm the link.** Ask the host to check that the App is running+ and the computer is awake, then send the current invitation. Use a new link+ after the App restarts; the old address may no longer work.+2. **Hosts: read the failure details.** Check that the complete App package was+ extracted. Save the full error from the launch page or terminal, including+ any detail after the exit code, and try again with **Debug launch**+ enabled.+3. **Compare networks.** Try a phone hotspot. Check whether DNS, a proxy or a+ firewall blocks Cloudflare Tunnel; adjust only relevant rules. Ask the+ administrator about a school or workplace network.++<details>+<summary>Advanced: tunnel errors, proxy routing and port 7844</summary>++If you use a proxy, confirm that it actually routes the `cloudflared` process.+Browser proxy settings or `HTTP_PROXY`/`HTTPS_PROXY` alone do not route the+currently bundled tunnel helper through a proxy.++The error details help identify which stage failed:++| Error contains | What to check || --- | --- |-| App startup fails, or no page opens automatically | Read the reason on the page and in the terminal. If the App is still running, copy its address into your browser. See [App diagnostics](../../cmd/piik-app/README.md#diagnostics) to collect a report; if Local mode lists several addresses, choose an adapter and IP on the launch page. |-| Public invitation fails to start, or a link shows 1033 | Check the host's App and current link using [public invitation troubleshooting](#public-invitation-fails-or-shows-1033). |-| Local invitation will not open | Check that both devices are on the same network and can reach each other. Guest Wi-Fi or firewall rules can block local access. |-| Room code says the room does not exist | Open the host's current full invitation link. Codes work only on their original site; a site with empty-room recycling may also have reclaimed it. The host can create a new room; see [joining a room](./getting-started.md#join-a-friends-room). |-| Cannot create a room (403) | On a self-hosted site, ask the administrator to check the [allowed site address](#room-creation-returns-403). |-| All room codes are in use | Retry later or use another Piik site. Administrators can enable [empty-room retention](../operations/self-hosting.md#1-configure-and-start-piik) to reclaim unused codes. This is separate from the per-room Viewer limit. |-| No screen picker | Allow the browser or App to record the screen when the OS asks. Browser capture needs HTTPS or `localhost`; try sharing from a desktop computer. |-| No App windows or screens listed | Check the message in the source picker, then follow [App source troubleshooting](#app-windows-or-screens-are-missing). **Browser** → **Choose what to share** opens the browser's screen, window or tab chooser. |-| Sharing fails after selecting a source | Click the error icon below the TV for details and guidance, then follow [sharing startup checks](#sharing-does-not-start-after-source-selection). |-| H264 fails to start, or sharing stops just after source selection | Try **Auto** or **VP8**, then follow [Windows H264 and graphics checks](#h264-sharing-fails-on-windows). |-| Game capture is black, shows only the desktop, or stops when entering the game | Compare sources and window modes using [game capture checks](#game-capture-is-black-or-sharing-stops). |-| HDR picture looks too bright or washed out | On Windows, try App capture or temporarily turn off HDR; see [HDR capture](#hdr-picture-looks-too-bright-or-washed-out). |-| Yellow outline around the shared window or screen | This is Windows' capture indicator. See [capture borders](#yellow-capture-border-on-windows) for Windows 11 controls and an optional Windows 10 workaround. |-| Picture but no source sound | Unmute the video. The host should choose a source with shareable audio and enable sound in the source picker. Camera video and audio inputs are selected separately; see [audio settings](./getting-started.md#add-your-voice). |-| Cannot hear the host's voice | The host can enable **Microphone** below the picture, then check the selected input and its volume in **Sharing settings → Sound**. Check the device connection and microphone permission. If the control is unavailable, update the App and refresh the page. |-| Screen sharing includes a voice app's audio | Windows App screen capture can [exclude application audio](./getting-started.md#exclude-a-voice-app-from-screen-audio). This does not remove echo from speakers picked up by a microphone. |-| Virtual microphone has echo, or remains audible when muted in Piik | Temporarily turn off **System sound** to compare. A mixer's playback can enter source audio separately from Piik's microphone; check its [audio routing](./getting-started.md#exclude-a-voice-app-from-screen-audio). |-| Page opens but video will not connect | Use **Reconnect** if available, or refresh the viewing page. See [connection troubleshooting](#when-video-will-not-connect) if it still fails. |-| WebRTC or IP-leak protection is enabled | Check whether it blocks media connections using [browser WebRTC settings](#browser-webrtc-restrictions). |-| Connection fails on a campus or restricted network | Compare with a phone hotspot, then consider a [site with SFU forwarding](#campus-networks-and-strict-nat). |-| Picture repeatedly blurs, stutters or stops | Identify who is affected, then follow [picture quality and interruption checks](#picture-blurs-stutters-or-stops). |-| Phone fullscreen has black bars, or the button does not work | Video keeps its proportions by default. Try landscape orientation, or choose **Fill** or **Stretch** in the page's **Playback settings**. Use the playback bar's **Fullscreen** button; system video fullscreen depends on the browser. See [viewing controls](./getting-started.md#join-a-friends-room). |-| Sharing stops after sleep or suspension | Wake the device and return to the sharing tab; start sharing again if needed. Browser and OS suspension can interrupt capture or playback. |--For a bug report, include the version, OS/browser, what you expected, and how-to reproduce it. [Diagnostics and export](../../cmd/piik-app/README.md#diagnostics)-explains how to collect a local report and what to review before sharing it.--## Sharing does not start after source selection--The error icon below the TV explains the current failure. Click it for suggested-checks, a copyable failure summary and browser diagnostics. The summary contains-the Web version, message and error code, without invitation links or source names.+| `failed to request quick Tunnel` or `api.trycloudflare.com` | The temporary address could not be allocated. Read the cause that follows: check DNS for lookup errors, or outbound HTTPS, proxy rules and service status for connection timeouts. |+| QUIC timeout, `dial tcp ...:7844` or `TLS handshake with edge` | The connection to a Cloudflare tunnel endpoint failed. Check outbound rules for `cloudflared`, including whether a proxy or game accelerator affects the connection. |-- **App disconnected or request timed out:** check that the App is running and- responding, then click **App** at the top of the site to connect. Allow local network- access if the browser asks. A timeout alone does not establish a graphics fault.-- **App could not start the selected source:** try an ordinary window or screen,- then compare with the **Browser** source picker. On Windows, try **Auto** or- **VP8** and follow [graphics checks](#h264-sharing-fails-on-windows).-- **Browser cannot read the source or permission is missing:** keep the source- open, allow screen recording and select the source again from the sharing page.- For a camera, also check whether another application has exclusive use of it.-- **Media connection failed:** check [browser WebRTC settings](#browser-webrtc-restrictions)- and local network permission. For **room creation HTTP 403**, use the next section.+Piik already enables HTTP/2 (TCP) fallback when QUIC (UDP) fails. Both use outbound+port `7844`. If neither path is reachable, repeated attempts cannot fix it;+loading ordinary websites does not establish that this port is accessible.+See [Cloudflare's connection troubleshooting](https://developers.cloudflare.com/tunnel/troubleshooting/)+for the requirements. You do not need to open an inbound port on your router.++</details>++**To continue without a public invite:** keep App running, open+[Piik online](https://demo.piik.tv) or another reachable site, and+[authorize App capture](./getting-started.md#use-app-with-an-existing-site).+Send the new site's room invitation; the old link does not lead to this room.+Piik online needs no site passphrase and remains P2P-only, without SFU fallback.+If the page opens but video does not connect, follow+[media connection troubleshooting](#when-video-will-not-connect).+If the unavailable address is a self-hosted site rather than the App's+temporary address, ask that site's administrator to check its service.++### Local invitation will not open++If the browser times out before showing Piik, check web access first. P2P+connection has not started at this point.++1. Keep the host's App running. In **Local room**, select an adapter address+ friends can reach and send the full invitation link. Both devices need a+ reachable LAN or the same virtual LAN; guest Wi-Fi may isolate them.+2. On the Windows host, open **Windows Security → Firewall & network protection →+ Allow an app through firewall**. Check the currently running `piik-app.exe`+ and allow the network type in use. A virtual adapter may be classified as+ **Public**; advanced rules can restrict access to that adapter and subnet.+3. After extracting an update to another folder, check whether the rule still+ points to the old file. No prompt does not mean access is allowed: add the+ current App manually if needed. Keep the firewall on and allow the needed app.++If App reports **the local port is unavailable**, close an older Piik instance+using it. If another application needs that port, start Piik with `--port 9876`+and send the newly generated invitation. Both the web and local STUN ports must+be available; changing only the URL will not move the service.++Changing permissions may require an administrator; see+[Microsoft's instructions](https://support.microsoft.com/en-us/windows/security/firewall/risks-of-allowing-apps-through-windows-firewall).+If the page opens but video does not connect, continue with+[media connection checks](#when-video-will-not-connect).++### Local HTTPS certificate warning++Piik App's **Local room**, and servers using `TLS_SELF_SIGNED=true`, generate a+local certificate without asking a public certificate authority. The browser+therefore shows a certificate warning before opening the invitation.-Stop when sharing works. Otherwise, enable diagnostics before reproducing it once:-the Web button collects browser reports only. For App capture, also enable-**Debug launch** on its mode selection page, then press `D` in the terminal to export.-Send the reports from that attempt with the copied failure summary and the source-type you selected. You can still report without logs; a generic failure screenshot-alone usually cannot distinguish capture, encoding and connection causes.-Logs stay on your device; review private information before sharing them.-See [diagnostics and export](../../cmd/piik-app/README.md#diagnostics) for details.+1. Check that the address is the one the Host intended to share.+2. Open the warning's certificate details and compare its **SHA-256 fingerprint**+ with **Local certificate · SHA-256** in the Host's App terminal, or the+ Server's **HTTPS certificate** startup message. Ask the Host over your usual+ trusted chat if you are on another device.+3. If it matches, use the browser's **Advanced → Continue** option where available.+ Then allow microphone access or request remote control normally.-## Room creation returns 403+The temporary certificate changes after an App/Server restart. A different+fingerprint needs confirmation again; the App saves no certificate files and+does not install a trusted CA. Do not disable browser security checks globally.+If the browser cannot accept an exception, use a site with a certificate that+device already trusts; administrators can follow the [HTTPS deployment guide](../operations/self-hosting.md#2-enable-https).++These instructions apply to an expected local self-signed certificate. An+unexpected warning on a public HTTPS site needs investigation by its operator.++### Room code does not work++Open the Host's current full invitation link first. A room code works only on+its original Piik site. A site with empty-room recycling may have reclaimed the+room; the Host can create a new one. See [joining a room](./getting-started.md#join-a-friends-room).++If all room codes on the site are in use, retry later or use another Piik site.+Administrators can configure [empty-room retention](../operations/self-hosting.md#1-configure-and-start-piik)+to reclaim unused codes. This is separate from the per-room Viewer limit.++### Room creation returns 403Piik rejects room creation from a browser address that the server has not allowed,even when the page opens normally. The site administrator should:@@ -82,13 +180,20 @@ reverse proxy preserves the browser's `Origin` header. A 403 from the proxy orWAF itself needs its own logs; do not disable origin validation to bypass it.See [Server deployment](../operations/self-hosting.md) for the configuration.-## App windows or screens are missing+## Starting a share++### No screen picker-Keep Piik App running on the computer where you are sharing. Click **App** at-the top of the site, then confirm its address on the local approval page.-If the browser asks for local-network access, allow it, then-refresh the source list. If access was previously blocked, review this site's-browser permissions first.+Allow screen recording when your OS asks. Browser screen capture needs HTTPS or+`localhost`; try sharing from a desktop computer. In the source picker, choose+**Browser → Choose what to share** to open the browser's screen, window or tab+chooser. Missing App sources are covered below.++### App windows or screens are missing++Keep App running on the sharing computer. Select **App** at the top of the site,+confirm the site on the local approval page, and allow browser local-network+access if asked. Refresh the list; review this site's permissions if previously blocked.The source picker distinguishes these outcomes:@@ -104,11 +209,28 @@ Local-network permission lets the page contact the App. It is separate fromthe WebRTC media settings described below. An unreachable App alone does notprove that permission was denied.-## H264 sharing fails on Windows+### Sharing does not start after source selection++Click the error icon below the TV for suggested checks, a copyable failure+summary and browser diagnostics.++- **App disconnected or request timed out:** check that the App is running and+ responding, then click **App** at the top of the site to connect. Allow local network+ access if the browser asks. A timeout alone does not establish a graphics fault.+- **App could not start the selected source:** try an ordinary window or screen,+ then compare with the **Browser** source picker. On Windows, try **Auto** or+ **VP8** and follow [graphics checks](#h264-sharing-fails-on-windows).+- **Browser cannot read the source or permission is missing:** keep the source+ open, allow screen recording and select the source again from the sharing page.+ For a camera, also check whether another application has exclusive use of it.+- **Media connection failed:** check [browser WebRTC settings](#browser-webrtc-restrictions)+ and local network permission. For **room creation HTTP 403**, check [site configuration](#room-creation-returns-403).+++If it still fails, [collect matching Web and App reports](#reporting-a-problem)+with the copied failure summary and selected source type.-If selecting a window or screen returns you to the start screen, or reports a-sharing failure, it may involve capture, encoding or the Browser-to-App media-connection. The message alone does not identify a graphics-driver problem.+### H264 sharing fails on Windows1. **Compare codecs on the same source.** In **Sharing settings → Picture → Fine-tune picture**, change thevideo codec from **H264** to **Auto** or **VP8**, then start sharing again.@@ -125,13 +247,62 @@ connection. The message alone does not identify a graphics-driver problem.**Let Windows decide** ([Microsoft's graphics settings](https://support.microsoft.com/en-us/windows/hardware/display-graphics/optimizations-for-windowed-games-in-windows-11)).The Windows preference is a browser-side check, not a guarantee of H264 support.-Piik App selects its native encoder separately; changing Chrome's GPU preference-does not select the App's capture GPU. If App capture still fails, keep the codec-comparison and export the App and browser reports for the same attempt. Include-your GPU model, driver version, source type and whether VP8 works. If both codecs-fail, also check [WebRTC restrictions](#browser-webrtc-restrictions).+Piik App selects its native encoder separately; Chrome's preference does not+select App's capture GPU. If it still fails, [save reports](#reporting-a-problem)+with the codec comparison. If both codecs fail, also check+[WebRTC restrictions](#browser-webrtc-restrictions).-## Game capture is black or sharing stops+## Picture and playback++### When video will not connect++**No media route available** means Piik has not found a working path to deliver+the picture to your device. Web pages and media use different connections;+the message alone does not identify the cause.++1. **Retry the viewing page.** Use **Reconnect** if available; otherwise refresh+ or reopen the invitation. Let each attempt finish. One or two fresh attempts+ are enough to compare; repeated refreshes cannot remove a network restriction.+2. **Check browser WebRTC settings.** Browser settings, VPNs and privacy extensions+ can block media for both Host and Viewer. Follow the [WebRTC checks](#browser-webrtc-restrictions).+3. **Try another network**, such as a phone hotspot. Check your VPN/proxy's UDP+ policy; ask the administrator on a managed network.+4. **Invite a friend on another network.** A Viewer who receives the picture and+ has spare forwarding capacity may give Piik another path to you. Piik chooses+ it automatically; extra people help only when those connections work.++Still failing? Continue with [advanced network checks](#advanced-network-checks)+and collect reports from the Host and affected Viewer for the same attempt.++### Picture blurs, stutters or stops++Brief blur can result from automatic adjustments to network or encoding load.+If it recurs or never recovers, compare the following:++1. **Identify who is affected.** Is it the host's preview, every viewer or just+ one viewer? Note the time and whether it recovers on its own. A clear host+ preview does not establish that viewers' connections are healthy.+2. **Change one thing at a time.** The host can try a lower resolution or frame+ rate under **Sharing settings → Picture**, and check CPU/GPU load while the game runs.+ An affected viewer can compare another browser or a phone hotspot. Increasing+ bitrate does not necessarily help.+3. **Check the actual codec.** Open the host's **Connection details** and+ read **Video codec**. On Windows, Auto may select VP8 when H264 is unavailable,+ its check cannot finish, or it cannot sustain the selected frame rate.+ Software encoding competes with the game for CPU time. For **Browser** capture,+ follow the [graphics checks](#h264-sharing-fails-on-windows), or compare the App's+ window/screen capture. The App tries available hardware encoders independently.+ VP8 alone does not establish a GPU fault; forcing H264 after a failed check may+ make performance worse.+4. **Save reports from the affected period.** Follow [report collection](#reporting-a-problem) for the Host and affected Viewer;+ App capture also needs an App report. Try **Reconnect** if the picture does+ not recover. Export before refreshing.++If sharing stopped altogether, read the reason below the TV and follow+[sharing startup checks](#sharing-does-not-start-after-source-selection). If the+host is still sharing but viewers cannot receive video, follow [connection checks](#when-video-will-not-connect).++### Game capture is black or sharing stopsCheck that you selected the game's window or the screen displaying it, then trythe game's borderless window mode. Compare an ordinary window, and try both App@@ -140,10 +311,9 @@ for capture; one game failing does not establish that every source is affected.If Piik returns to the start screen after you enter a game, read the reason belowthe TV and follow [sharing startup checks](#sharing-does-not-start-after-source-selection).-Include the game, window mode, source type, codec and matching App/browser reports-in your feedback. A missing picture alone does not identify an encoder fault.+Include the game and window mode in your [report](#reporting-a-problem).-## HDR picture looks too bright or washed out+### HDR picture looks too bright or washed outWindows App capture through **Apps / Windows** or **Screens** converts HDR to SDRfor viewers. The **Browser** picker uses browser capture instead; some HDR sources@@ -151,18 +321,17 @@ can look overexposed. This is a known limitation. Try the App categories above,or temporarily turn off HDR in Windows display settings and select the source again.Higher resolution or bitrate cannot restore clipped highlights.-If the picture still looks wrong, report the source type, HDR setting, GPU and-display model, with a comparison of the source and viewer pictures. Technical-background is in [HDR capture notes](../research/media-fidelity.md#hdr-to-sdr).+If it persists, report the HDR setting and GPU/display model with source/viewer+comparison pictures. See [HDR capture notes](../research/media-fidelity.md#hdr-to-sdr) for background.-## Yellow capture border on Windows+### Yellow capture border on WindowsWindows draws this outline to identify the window or display being captured.-On supported Windows versions, the App source picker offers **Show capture border**,+When the App's capture runtime supports it, the source picker offers **Show capture border**,off by default. Windows permissions or another active capture can still requirethe border. Windows 10 does not provide this control for its capture API.-### Windows 11: the border is still visible+#### Windows 11: the border is still visible1. Select **Apps / Windows** or **Screens** in Piik and leave **Show capture border**off. A Browser-selected source uses the browser's own capture indicator.@@ -173,10 +342,12 @@ the border. Windows 10 does not provide this control for its capture API.Windows requires consent and can retain the border when another capture requestsit ([Microsoft's API documentation](https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscapturesession.isborderrequired)).-If it persists, include the Windows version, selected source type and an-[App diagnostic report](../../cmd/piik-app/README.md#diagnostics) with your feedback.+If it persists, include the Windows version and an [App report](#reporting-a-problem).-### Optional Windows 10 workaround+<details>+<summary>Advanced: optional Windows 10 workaround</summary>++#### Optional Windows 10 workaround[DWM Custom Projection Border](https://windhawk.net/mods/dwm-custom-projection-border)is a third-party Windhawk mod for x64 Windows that can hide the border while keeping the same@@ -199,153 +370,71 @@ See the [mod author's instructions](https://github.com/ramensoftware/windhawk-moand [Windhawk's process settings](https://github.com/ramensoftware/windhawk/wiki/Injection-targets-and-critical-system-processes)for current setup details.-## Public invitation fails or shows 1033+</details>-App **Public invite** uses Cloudflare Tunnel to provide a temporary web address.-Reachability varies by network, and [Quick Tunnels have no uptime guarantee](https://developers.cloudflare.com/tunnel/get-started/quick-tunnels/#limitations).-`public invitation service exited before connecting` means the helper exited-before connecting; `exit status 1` alone does not identify the cause.-[Cloudflare error 1033](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1033/)-means that the address currently has no available tunnel connection. This differs-from a page that opens but reports **No media route available**.+### Fullscreen or playback after sleep-1. **Viewers: confirm the link.** Ask the host to check that the App is running- and the computer is awake, then send the current invitation. Use a new link- after the App restarts; the old address may no longer work.-2. **Hosts: read the failure details.** Check that the complete App package was- extracted. Save the full error from the launch page or terminal, including- any detail after the exit code, and try again with **Debug launch**- enabled. The App retries early tunnel-process exits within its startup deadline.-3. **Compare networks.** Try a phone hotspot. Check whether DNS, a proxy or a- firewall blocks Cloudflare Tunnel; adjust only relevant rules. Ask the- administrator about a school or workplace network.+- **Phone fullscreen has black bars:** video preserves its proportions. Try+ landscape orientation, or select **Fill** or **Stretch** under **Playback settings**.+- **Fullscreen button does not work:** use the playback bar's **Fullscreen** button.+ System video fullscreen depends on the browser; see [viewing controls](./getting-started.md#join-a-friends-room).+- **Sharing stops after sleep or suspension:** wake the device and return to the+ sharing tab. Start sharing again if needed; browser and OS suspension can+ interrupt capture or playback.-If you use a proxy, confirm that it actually routes the `cloudflared` process.-Browser proxy settings or `HTTP_PROXY`/`HTTPS_PROXY` alone do not route the-currently bundled tunnel helper through a proxy.+## Sound and browser permissions-The error details help identify which stage failed:+### Picture but no source sound-| Error contains | What to check |-| --- | --- |-| `failed to request quick Tunnel` or `api.trycloudflare.com` | The temporary address could not be allocated. Read the cause that follows: check DNS for lookup errors, or outbound HTTPS, proxy rules and service status for connection timeouts. |-| QUIC timeout, `dial tcp ...:7844` or `TLS handshake with edge` | The connection to a Cloudflare tunnel endpoint failed. Check outbound rules for `cloudflared`, including whether a proxy or game accelerator affects the connection. |+1. Unmute the video and check your playback volume.+2. The Host should select a source with shareable audio and enable its sound in+ the source picker. Available sound depends on the source and platform.+3. Camera video and microphone inputs are selected separately. For a built-in+ camera microphone or OBS audio, see [camera and audio inputs](./sharing.md#cameras-and-virtual-audio-inputs).-Piik already enables HTTP/2 (TCP) fallback when QUIC (UDP) fails. Both use outbound-port `7844`. If neither path is reachable, repeated attempts cannot fix it;-loading ordinary websites does not establish that this port is accessible.-See [Cloudflare's connection troubleshooting](https://developers.cloudflare.com/tunnel/troubleshooting/)-for the requirements. You do not need to open an inbound port on your router.+### Cannot hear someone speaking-**To continue without a public invite:** keep the App running and open-[Piik online](https://demo.piik.tv) or another reachable Piik site. Follow-[Use App with an existing site](./getting-started.md#use-app-with-an-existing-site)-to authorize App window/screen capture, then send your friends the new site's-room invitation. The old public-invitation link does not lead to this new room.-Piik online needs no site passphrase. This bypasses the temporary Cloudflare web-address; the online site remains P2P-only, with no SFU fallback.-If the page opens but video does not connect, follow-[media connection troubleshooting](#when-video-will-not-connect).-Include the App version, failure time and [App diagnostic report](../../cmd/piik-app/README.md#diagnostics)-in feedback. If the unavailable address is a self-hosted site rather than the App's-temporary address, ask that site's administrator to check its service.+In voice-capable builds:-## Picture blurs, stutters or stops+1. Both people join **Interact → Voice**; the Host selects **Open room voice** first.+ Joining only starts listening. Each speaker must turn on their own microphone.+2. The speaker checks browser microphone permission, input device and input volume+ in **Microphone settings**. Microphone access needs HTTPS or `localhost`.+3. Check whether you paused listening or muted that person locally. These controls+ are separate from video mute; **Pause listening** leaves your microphone on.-Brief blur can result from automatic adjustments to network or encoding load.-If it recurs or never recovers, compare the following:+If voice reports a connection failure, compare [WebRTC settings](#browser-webrtc-restrictions)+and another network. Picture playback alone does not establish that voice works.+For feature availability, see [room voice](./room-tools.md#room-voice).-1. **Identify who is affected.** Is it the host's preview, every viewer or just- one viewer? Note the time and whether it recovers on its own. A clear host- preview does not establish that viewers' connections are healthy.-2. **Change one thing at a time.** The host can try a lower resolution or frame- rate under **Sharing settings → Picture**, and check CPU/GPU load while the game runs.- An affected viewer can compare another browser or a phone hotspot. Increasing- bitrate does not necessarily help.-3. **Check the actual codec.** Open the host's **Show connection details** and- read **Video codec**. On Windows, Auto may select VP8 when H264 is unavailable,- its check cannot finish, or it cannot sustain the selected frame rate.- Software encoding competes with the game for CPU time. For **Browser** capture,- follow the [graphics checks](#h264-sharing-fails-on-windows), or compare the App's- window/screen capture. The App tries available hardware encoders independently.- VP8 alone does not establish a GPU fault; forcing H264 after a failed check may- make performance worse.-4. **Save reports from the affected period.** Enable diagnostics on the host and- affected viewer pages before reproducing; App capture also needs an App report.- Try **Reconnect** if the picture does not recover. Export before refreshing.+### Echo or unwanted application audio-If sharing stopped altogether, read the reason below the TV and follow-[sharing startup checks](#sharing-does-not-start-after-source-selection). If the-host is still sharing but viewers cannot receive video, continue with the checks below.+Use headphones if speakers are feeding sound back into a microphone. Windows+App screen capture can [exclude a voice app from source audio](./sharing.md#exclude-a-voice-app-from-screen-audio);+this does not remove acoustic echo.-## When video will not connect+If a virtual microphone remains audible when muted in Piik, temporarily turn off+**System sound**. If that removes it, the mixer's playback output is also entering+source audio. Check its playback/monitoring route or share only the desired app's+window audio. Piik's microphone mute does not mute that separate source.-**No media route available** means Piik has not found a working path to deliver-the picture to your device. Loading the page and receiving media use different-connections, so one can work while the other fails.--NAT (Network Address Translation) lets several devices share an Internet address.-Routers and providers differ in how they map addresses and admit incoming traffic;-some combinations make direct connections difficult. Firewalls and browser-policies can also block media. The message alone does not identify the cause.--STUN helps discover an address for direct connections; it does not relay the-picture. An unreachable STUN service can therefore leave chat working while-media fails. App Public invite already uses multiple discovery services; one-STUN error alone does not mean every path failed. On self-hosted sites,-administrators should check that `STUN_URLS`-points to reachable UDP services; an HTTP reverse proxy does not forward STUN.-App users who need different providers can set-[`PIIK_STUN_URLS`](../standards/configuration.md#piik-app-configuration)-before starting Public invite. This replaces every built-in discovery address;-choose trusted services, since they see the participants' public IP addresses.-Compare the diagnostic reports from both peers before assigning the cause.--Try these in order, stopping when the picture arrives:--1. **Retry the viewing page.** Choose **Reconnect** if it is available. If it is- disabled or does not help, refresh the viewing page or reopen the invitation.- Let each connection attempt finish. One or two fresh attempts can be worth- trying; repeated refreshes cannot remove a network restriction.-2. **Check browser WebRTC settings.** Browser settings or VPN/privacy extensions- can block media even while the page loads. This affects both sharing and viewing;- follow [browser WebRTC checks](#browser-webrtc-restrictions) below.-3. **Try another network.** For example, test a phone hotspot. If you use a VPN- or proxy, check its UDP policy; ask the administrator on a managed network.-4. **Enable usable IPv6.** Check that your provider, router and device support it.- When both peers have working IPv6, Piik can try that direct path alongside- IPv4. It does not bypass firewall rules; keep IPv4 enabled too.-5. **Check your own router, if you manage it.** On a trusted home network,- supported UPnP, PCP or NAT-PMP settings can let the App's native media path- request a port mapping. Browser-only capture does not request these mappings.- If a modem and router both perform NAT, follow your model's bridge/AP-mode- instructions to remove the extra layer. Carrier-grade NAT is upstream of your- router; ask your provider about available public IPv4 or IPv6 service.- Back up settings before changing the router's operating mode.-6. **Invite a friend on another network.** A Viewer who can receive the picture- and has spare forwarding capacity may give Piik another path to you. Piik- chooses this automatically; extra people help only when those connections work.-7. **Use a site with media fallback.** Its operator must enable SFU forwarding.- If the site offers **Privacy mode**, the Host must turn it off before sharing.- Sites configured for **Server media** already require SFU. The public- `demo.piik.tv` site and the App's **Public invite** mode do not provide SFU.- [Self-hosting](../operations/self-hosting.md#optional-media-fallback) is an- advanced option. Both P2P and SFU media currently use UDP; a network that blocks- UDP entirely still needs a different network or an administrator's help.--Router menus vary by model. These manufacturer guides explain-[IPv6 prerequisites](https://support.google.com/googlehome/answer/6361450),-[UPnP](https://support.google.com/googlehome/answer/6274337), and-[double NAT with a modem and router](https://www.tp-link.com/us/support/faq/3113/).-The [WebRTC connection guide](https://webrtc.org/getting-started/peer-connections)-explains discovery and connection checks in more technical detail.+### Microphone or remote controls are unavailable++1. Open the complete HTTPS invitation generated by the current App. For a local+ invitation, [confirm its certificate](#local-https-certificate-warning) first.+ A plain HTTP LAN page can play video, chat and listen to voice, but cannot use+ the secure microphone/camera capture or remote-control APIs. Changing only the+ URL scheme does not enable HTTPS; `localhost` means the current device.+2. For a microphone, review this site's browser permission and selected input.+3. For remote control, update the Host's App and the site, then refresh the Viewer+ page. The Host must use App window/screen capture and enable control; Browser+ and camera capture cannot receive remote input. Follow the+ [authorization steps](./room-tools.md#let-a-friend-control-your-shared-screen).-If these steps do not help, collect a [Debug report](../../cmd/piik-app/README.md#diagnostics)-from the affected Viewer and, if possible, the Host for the same attempt. Include-the time, Piik version and network type when reporting the problem.-For a self-hosted site using SFU, also include the Server report. Successful Host-upload or subscription setup alone does not establish that the Viewer received-and decoded the picture; the reports from both sides help locate the failing step.+If your browser cannot accept the local certificate, use a reachable **Public+invite** or an HTTPS site with a trusted certificate.++## Advanced network checks### Browser WebRTC restrictions@@ -368,22 +457,111 @@ Allowing these connections can expose network addresses to WebRTC peers; changeonly the relevant setting. See [Chrome's policy reference](https://developer.chrome.com/docs/extensions/reference/api/privacy#property-network)and [Vivaldi's privacy settings](https://help.vivaldi.com/desktop/privacy/privacy-settings/).-### Campus networks and strict NAT--A campus network can work with Piik, but a shared Internet gateway or restrictive-firewall may make direct connections harder. Try a phone hotspot first: if the-same invitation works there, focus on the original network's restrictions.+### STUN, IPv6 and router checks++NAT lets several devices share an Internet address. Some routers or provider+networks make direct connections harder; firewalls and browser policies can+also block media. Check the parts you manage:++1. **STUN discovery:** STUN finds addresses for direct connections; it does not+ relay the picture. An unreachable service can leave chat working while media+ fails. App Public invite already uses several discovery services; one STUN+ error does not mean every path failed. Self-hosted administrators should check+ that `STUN_URLS` points to reachable UDP services. HTTP reverse proxies do not+ forward STUN. App users can set [`PIIK_STUN_URLS`](../standards/configuration.md#piik-app-configuration)+ before starting Public invite to replace all built-in discovery addresses.+ Choose trusted providers, since they see participants' public IP addresses.+2. **IPv6:** when the provider, router and both devices have usable IPv6, Piik can+ try that direct path alongside IPv4. Keep IPv4 enabled too; IPv6 still obeys+ firewall rules.+3. **Home router:** supported UPnP, PCP or NAT-PMP can let App's native media path+ request port mappings. Browser-only capture does not request them. If both a+ modem and router perform NAT, your model's bridge/AP-mode instructions may+ remove a layer. Back up settings before changing its operating mode.+ Carrier-grade NAT is upstream; ask your provider about public IPv4 or IPv6.++Router menus vary. See manufacturer guidance on+[IPv6](https://support.google.com/googlehome/answer/6361450),+[UPnP](https://support.google.com/googlehome/answer/6274337), and+[double NAT](https://www.tp-link.com/us/support/faq/3113/), or the+[WebRTC connection guide](https://webrtc.org/getting-started/peer-connections)+for discovery details. Compare both peers' reports before assigning a cause.-For regular use, consider **self-hosting a Piik site with SFU media forwarding**.-This gives viewers a server path when direct connections fail. Follow the-[deployment guide](../operations/self-hosting.md#optional-media-fallback), including-its public-address and UDP-port requirements. Keep Piik App running, open the new-site in your browser and select **App** at the top to approve its local access.-Send invitations generated by that site.+### Campus networks and strict NAT-The public demo and App Public invite mode remain P2P-only. SFU also requires-usable UDP: when the network blocks UDP entirely, use another network or ask the-administrator for access. Deploying a server alone does not remove that restriction.+Compare the same invitation on a phone hotspot first. If it works there, focus+on the original network's shared gateway or firewall restrictions.++For regular use, an operator can [enable SFU media fallback](../operations/self-hosting.md#optional-media-fallback)+on a self-hosted Piik site. If it offers **Privacy mode**, the Host must turn it+off before sharing; a site configured for **Server media** already requires SFU.+Keep App running, open the new site and select **App** to approve local access,+then send that site's invitation.++The public `demo.piik.tv` site and App **Public invite** provide P2P only. Both P2P+and SFU media currently need UDP. Deploying a server does not bypass a network+that blocks media UDP entirely; use another network or ask its administrator.++### Optional: a virtual LAN++If hosting a server is inconvenient, you can also try a third-party virtual LAN+to put your friends on the same virtual network. For example,+[UU's official guide (Chinese)](https://uu.163.com/blog/lan-multiplayer-guide-net.html)+offers LAN and general-purpose multiplayer rooms. Choose general-purpose LAN+networking, rather than acceleration limited to one game. The tool must provide+reachable virtual IPv4 addresses and carry both Piik's web traffic and WebRTC UDP.++1. Everyone runs the networking tool and joins the same virtual LAN.+2. If its virtual adapter and IP appear in Piik App's **Local room** address list,+ the host selects that address and starts sharing. If the page will not open,+ use [Local invitation checks](#local-invitation-will-not-open) to review+ Windows firewall permissions for that virtual network.+3. Send friends the full Piik invitation using that address, not a `localhost`+ address or just a room code. Check picture and sound after the page opens;+ a reachable web page does not establish that media UDP works too.+4. Keep the networking tool running on every device. If its virtual IP changes,+ select the new address in the App and send a new invitation.++**Local room** sends an HTTPS invitation on the selected virtual IP. Confirm its+[local certificate](#local-https-certificate-warning) on first access. Microphone,+camera and remote control can then work without a public tunnel, just as on an+ordinary LAN. If unavailable, check [browser permissions](#microphone-or-remote-controls-are-unavailable).+Connection details show the selected media addresses.++Use an updated App for address discovery on routed virtual LANs. This method+needs a usable virtual address and media UDP; it cannot work with tools that+forward only game traffic. Firewalls, browser discovery and the third-party+service still affect availability. Join only with trusted friends.++[ZeroTier](https://docs.zerotier.com/start/) and+[Tailscale](https://tailscale.com/docs/how-to/quickstart) also create private+networks. Check device support and the requirements above; these alternatives+have not been tested with Piik.++For administrators with a public server, the [frp recipe](../operations/self-hosting.md#optional-forward-an-existing-server-with-frp)+forwards an existing site's web and SFU endpoints through frps. Forwarding the+web page alone does not forward WebRTC media.++## Reporting a problem++Include the Piik version, OS/browser, time, expected result and reproduction steps.+For capture problems, add the source type, codec, GPU/driver and whether another+source or VP8 works. For network problems, add the network type.++Enable diagnostics before reproducing once, then export before refreshing:++- **Web:** use the page's diagnostics button. A sharing failure's error icon below+ the TV also provides a copyable summary; it contains the Web version, message+ and code, without invitation links or source names.+- **App capture:** also enable **Debug launch** on the App's mode selection page,+ then press `D` in the terminal to export its report.+- **Connection failure:** collect the affected Viewer and Host reports for the+ same attempt. For self-hosted SFU, include the Server report too. Host upload or+ subscription setup alone does not prove that the Viewer received the picture.++Reports stay on your device. Review private information before sharing them;+[diagnostics and export](../../cmd/piik-app/README.md#diagnostics) explains their contents.+You can still report without logs; a generic failure screenshot alone may not+identify the failing stage.-Ready to host a site for your group? Follow [self-hosting](../operations/self-hosting.md).For other guides, return to [the documentation home](./README.md).diff --git a/docs/guide/troubleshooting.zh-CN.md b/docs/guide/troubleshooting.zh-CN.mdindex 04c8f6c5..1865f7ac 100644--- a/docs/guide/troubleshooting.zh-CN.md+++ b/docs/guide/troubleshooting.zh-CN.md@@ -1,63 +1,137 @@+---+outline: 2+---+# 问题排查[English](./troubleshooting.md) · 简体中文 · [文档中心](./README.zh-CN.md)-按遇到的现象查找下方说明,恢复正常后就不必继续。-如果问题仍然存在,可以收集诊断报告反馈。+按症状查找下方说明,依次尝试,恢复正常后就不必继续。+仍有问题时,请在刷新前[收集诊断报告](#反馈问题)。## 常见问题-| 你遇到的情况 | 可以先试什么 |+- [打开 App 与加入房间](#打开-app-与加入房间):启动、邀请链接、证书与房间准入。+- [开始分享](#开始分享):来源列表、采集权限与编码器。+- [画面与播放](#画面与播放):连接、画质、游戏采集与全屏。+- [声音与浏览器权限](#声音与浏览器权限):来源声音、语音、回声与远程控制。+- [进阶网络排查](#进阶网络排查):WebRTC、STUN、校园网与虚拟局域网。++## 打开 App 与加入房间++### App 启动失败或没有打开网页++1. 查看启动页面和终端中的原因。App 仍在运行时,可复制显示的地址,在浏览器中打开。+2. 本地模式列出多个地址时,选择朋友能访问的网卡和 IP,见[本地邀请排查](#本地邀请打不开)。+3. 仍然失败时,开启 **诊断启动** 后重试,保留完整错误和 [App 报告](#反馈问题)。++### macOS 提示已损坏或无法验证开发者++当前 Mac 版本尚未进行 Developer ID 签名和 Apple 公证,首次打开可能被系统拦截;+仅凭弹窗措辞,不能断定下载文件真的损坏。++1. 从项目 Releases 下载对应的 Mac ZIP,核对同一版本公布的 SHA-256。+ 在终端运行 `shasum -a256 ~/Downloads/piik-app-darwin-arm64.zip`;+ Intel Mac 将文件名中的 `arm64` 换为 `amd64`。校验不一致时应重新下载,不要绕过警告。+2. 把完整的 `Piik App.app` 移到「应用程序」,尝试打开后,在+ **系统设置 → 隐私与安全性 → 仍要打开** 中确认。+ 具体步骤见 [Apple 首次打开说明](https://support.apple.com/zh-cn/102445)。+3. 如果没有「仍要打开」,且已确认官方 ZIP 的校验值一致,可在终端仅移除这个 App+ 的下载隔离标记,再重新打开:++ ```sh+ xattr -dr com.apple.quarantine "/Applications/Piik App.app"+ ```++保留在其他位置时,换成 App 的实际路径。保持系统整体安全检查开启。++### 公网邀请创建失败或出现 1033++App 的 **公网邀请** 通过 Cloudflare Tunnel 提供临时网页地址。+该服务的可达性会随网络而变化,[Quick Tunnels 不保证持续可用](https://developers.cloudflare.com/tunnel/get-started/quick-tunnels/#limitations)。+`public invitation service exited before connecting` 表示辅助程序在连接完成前退出;+`exit status 1` 本身不能说明具体原因。+[Cloudflare 的 1033 说明](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1033/)(英文)+表示该地址当前没有可用的隧道连接。这与网页能打开、但显示「没有可用的媒体线路」是不同的问题。++1. **观众先确认链接。** 请房主确认 App 仍在运行、电脑未休眠,并发送当前邀请。+ App 重新启动后应使用新链接,旧地址可能失效。+2. **房主查看错误详情。** 确认已完整解压 App 程序包;保留启动页面或终端的完整错误,+ 包括退出码后的详细信息。开启 **诊断启动** 后再试。+3. **对照网络。** 可用手机热点重试,检查 DNS、代理或防火墙是否阻止 Cloudflare Tunnel。+ 只调整相关规则;学校或公司的网络应联系管理员。++<details>+<summary>进阶:隧道错误、代理与 7844 端口</summary>++使用代理时,请确认它实际覆盖 `cloudflared` 进程。仅开启浏览器代理或设置+`HTTP_PROXY`/`HTTPS_PROXY`,不会让当前随包的隧道程序自动走代理。++错误详情可以帮助区分失败的环节:++| 错误中出现 | 检查什么 || --- | --- |-| App 启动失败,或没有自动打开网页 | 查看页面和终端中的原因;App 仍在运行时可复制终端中的地址打开。按 [App 运行与诊断说明](../../cmd/piik-app/README.zh-CN.md#诊断)收集报告;本地模式提示多个地址时,在启动页选择网卡和 IP。 |-| 公网邀请创建失败,或打开链接出现 1033 | 按[公网邀请排查](#公网邀请创建失败或出现-1033)检查房主 App 和当前链接。 |-| 本地邀请打不开 | 确认两台设备在同一网络且可以互相访问。访客 Wi-Fi 或防火墙规则可能阻止本地连接。 |-| 输入房间号后提示房间不存在 | 先打开房主最新的完整邀请链接。房间号只在原站点有效;站点开启空房间回收时,旧房间也可能已被回收,由房主重新创建即可。参阅[加入房间](./getting-started.zh-CN.md#加入朋友的房间)。 |-| 无法创建房间 (403) | 自建站点请联系管理员检查[允许访问的站点地址](#创建房间返回-403)。 |-| 站点房间号已用满 | 稍后重试或使用其他 Piik 站点;管理员可配置[空房间回收](../operations/self-hosting.zh-CN.md#1-配置并启动-piik)。这与单个房间的观众人数上限不同。 |-| 没有屏幕选择弹窗 | 按系统提示允许浏览器或 App 录制屏幕。浏览器采集需要 HTTPS 或 `localhost`,请在电脑上尝试分享。 |-| App 的窗口或屏幕列表为空 | 先查看选源器中的提示,再按 [App 来源排查](#app-找不到窗口或屏幕) 操作;也可以选 **浏览器** → **选择画面**,在浏览器弹窗中选择屏幕、窗口或标签页。 |-| 选源后提示分享失败 | 点击电视下方的错误图标查看原因和排查入口,按[分享启动排查](#选源后无法开始分享)逐步对照。 |-| H264 无法开播,或选源后立即退回未分享状态 | 先试 **自动** 或 **VP8**,再按 [Windows H264 与显卡排查](#windows-上-h264-分享失败)操作。 |-| 游戏黑屏、只显示桌面,或进入游戏后停止分享 | 对照其他来源和窗口模式,按[游戏采集排查](#游戏黑屏或进入游戏后停止分享)操作。 |-| HDR 画面过亮或颜色发白 | Windows 上可改用 App 选源,或暂时关闭 HDR;查看 [HDR 说明](#hdr-画面过亮或颜色发白)。 |-| 分享的窗口或屏幕周围出现黄框 | 这是 Windows 的采集提示。查看[采集边框说明](#windows-分享时出现黄框),了解 Windows 11 的开关和 Windows 10 的可选处理方法。 |-| 有画面,没来源声音 | 先取消视频静音。房主应选择支持分享声音的来源,并在选源器中打开声音。摄像头画面与音频输入分别选择,见[声音设置](./getting-started.zh-CN.md#加上自己的声音)。 |-| 听不到房主说话 | 房主可在画面下方开启 **麦克风**,在 **分享设置 → 声音** 中检查输入设备和音量,并确认设备连接与麦克风权限。如控件不可用,请更新 App 并刷新页面。 |-| 分享时把语音软件的声音也传出去了 | Windows App 屏幕采集可选择[排除应用声音](./getting-started.zh-CN.md#分享屏幕时排除语音软件的声音);该功能不消除扬声器被麦克风收音产生的回声。 |-| 虚拟麦克风有回声,或在 Piik 闭麦后仍能听到 | 暂时关闭 **系统声音** 对照。混音软件的播放输出可能通过来源音频进入分享,请检查[音频路由](./getting-started.zh-CN.md#分享屏幕时排除语音软件的声音)。 |-| 网页能打开,画面连不上 | **重新连接** 按钮可用时先点击,否则刷新观看页。仍然失败时,查看 [画面连接排查](#画面连接不上)。 |-| 开启了 WebRTC 或 IP 泄露保护 | 按[浏览器 WebRTC 设置](#浏览器限制了-webrtc)检查是否阻止了媒体连接。 |-| 校园网或受限网络连不上 | 先用手机热点对照,再考虑[启用 SFU 的自建站点](#校园网或严格-nat)。 |-| 画面反复模糊、卡顿或中断 | 先分清哪些观众受影响,再按[画质与中断排查](#画面模糊卡顿或中断)操作。 |-| 手机全屏仍有黑边,或全屏按钮无效 | 画面默认保持原始比例,可尝试横屏,或在页面内的 **播放设置** 中选择 **等比铺满** 或 **拉伸铺满**。使用播放栏的 **全屏观看** 按钮;系统视频全屏由浏览器提供。详见[观看操作](./getting-started.zh-CN.md#加入朋友的房间)。 |-| 休眠或挂起后分享中断 | 唤醒设备,回到分享标签页,必要时重新开始分享。浏览器或系统挂起可能中断采集和播放。 |--反馈问题时,请附上版本、系统与浏览器、预期结果和复现步骤。-[诊断与导出](../../cmd/piik-app/README.zh-CN.md#诊断)-说明如何收集本地报告,以及分享前需要检查哪些内容。--## 选源后无法开始分享--电视下方的错误图标说明当前失败;点击可打开排查面板,查看建议、复制失败信息,-或开启网页诊断。复制内容包含网页版本、提示和错误编号,不包含邀请链接或来源名称。+| `failed to request quick Tunnel`、`api.trycloudflare.com` | 临时地址申请失败。查看后面的具体原因:域名解析错误检查 DNS;连接超时检查 HTTPS 出站连接、代理或服务状态。 |+| QUIC 超时、`dial tcp ...:7844` 或 `TLS handshake with edge` | 到 Cloudflare 隧道节点的连接失败。检查 `cloudflared` 的出站规则,包括代理或游戏加速器是否影响该连接。 |-- **App 连接断开或请求超时**:确认 App 仍在运行且可以响应,点击站点顶部的 **App** 完成连接。- 浏览器询问本地网络权限时允许访问。超时只说明请求未及时完成,不能据此认定显卡故障。-- **App 未能启动所选来源**:先换一个普通窗口或屏幕;再对照「浏览器」选源。- Windows 上可试「自动」或 VP8,后续按[显卡排查](#windows-上-h264-分享失败)操作。-- **浏览器无法读取来源或缺少权限**:保持来源打开,允许系统录屏权限,回到分享页重新选源。- 摄像头还需检查设备是否正被其他程序独占。-- **媒体连接失败**:检查[浏览器 WebRTC 设置](#浏览器限制了-webrtc)和本地网络权限。- **创建房间返回 403** 则按下节检查站点配置。+Piik 已启用 QUIC(UDP)失败后尝试 HTTP/2(TCP),两者都使用出站端口 `7844`。+如果两条线路都不可达,反复重试也无法解决;浏览器能访问普通网页不代表该端口可用。+具体要求见 [Cloudflare 连接排查](https://developers.cloudflare.com/tunnel/troubleshooting/)(英文),+无需在路由器上开放入站端口。++</details>++**暂时绕过公网邀请:** 保持 App 运行,打开[在线版](https://demo.piik.tv)或其他可访问站点,+[授权 App 采集](./getting-started.zh-CN.md#通过已有站点使用-app),再发送新站点的房间邀请;原链接不会转到这个房间。+在线版无需站点口令,仍仅使用 P2P,不提供 SFU 兜底。+网页能打开但画面连不上时,转到[画面连接排查](#画面连接不上)。+如果打不开的是自建站点而非 App 的临时地址,请联系该站点管理员检查服务。++### 本地邀请打不开++浏览器提示连接超时、Piik 页面都打不开时,先检查网页访问;这时还没有进入 P2P 连接。++1. 保持房主 App 运行,在 **本地房间** 选择朋友能访问的网卡地址,发送完整邀请链接。+ 两台设备需处于可互访的局域网或同一个虚拟局域网;访客 Wi-Fi 可能隔离设备。+2. Windows 房主打开 **Windows 安全中心 → 防火墙和网络保护 → 允许应用通过防火墙**,+ 检查当前运行的 `piik-app.exe`,允许所用的网络类型。虚拟网卡可能被识别为 **公用网络**;+ 需要更小范围时,可在高级规则中限定该虚拟网卡和网段。+3. 更新后换了解压目录,也要检查规则是否仍指向旧文件。系统未弹出询问不代表已经放行,+ 可在上述页面手动添加当前 App。保持防火墙开启,只放行需要的应用。++App 提示 **本地端口不可用** 时,先关闭占用它的旧 Piik 实例。如果其他程序需要这个端口,+可用 `--port 9876` 启动 Piik,再发送新生成的邀请。网页和本地 STUN 端口都需要可用;+只修改链接里的端口不会改变服务的实际位置。++放行操作可能需要管理员权限,参阅 [Microsoft 说明](https://support.microsoft.com/zh-cn/windows/security/firewall/risks-of-allowing-apps-through-windows-firewall)。+网页能打开但画面连不上时,再按[画面连接排查](#画面连接不上)检查媒体线路。++### 本地 HTTPS 证书提示++Piik App 的 **本地房间**,以及启用 `TLS_SELF_SIGNED=true` 的服务端,会自行生成本地证书。+它没有经过公共证书机构签发,因此浏览器会先显示证书警告。++1. 确认网址与房主准备分享的地址一致。+2. 打开警告页的证书详情,将 **SHA-256 指纹** 与房主 App 终端中的 **本地证书 · SHA-256**,+ 或服务端启动时的 **HTTPS certificate** 信息对照。异地使用时,可通过平时信任的聊天渠道向房主核对。+3. 指纹一致后,使用浏览器提供的 **高级 → 继续访问**;进入页面后,再正常允许麦克风或申请远控。-恢复后不必继续排查。仍然失败时,先开启诊断,再重现一次:网页按钮只收集浏览器报告;-使用 App 时也请在模式选择页开启「诊断启动」,随后在终端按 `D` 导出 App 报告。-将同一次尝试的报告与复制的失败信息一起反馈,并说明所选来源类型。-没有报告时仍可反馈;单独一张「分享失败」截图通常无法确定采集、编码或连接中的具体原因。-日志保存在本机,分享前请检查其中的私人信息。操作细节见[诊断与导出](../../cmd/piik-app/README.zh-CN.md#诊断)。+重启 App/服务端会更换临时证书,新指纹需要重新确认。App 不保存证书文件,也不安装系统受信任证书。+不要全局关闭浏览器的安全检查。如果浏览器不允许接受例外,请改用该设备已信任证书的 HTTPS 站点;+管理员可参阅 [HTTPS 部署说明](../operations/self-hosting.zh-CN.md#2-配置-https)。-## 创建房间返回 403+以上只适用于预期中的本地自签名证书;普通公网 HTTPS 站点突然出现证书警告时,应让管理员排查原因。++### 房间号无法使用++先打开房主最新的完整邀请链接。房间号只在原 Piik 站点有效;站点开启空房间回收时,+旧房间也可能已被回收,由房主重新创建即可。参阅[加入房间](./getting-started.zh-CN.md#加入朋友的房间)。++站点房间号已用满时,稍后重试或使用其他 Piik 站点。管理员可配置+[空房间回收](../operations/self-hosting.zh-CN.md#1-配置并启动-piik)以收回闲置号码。+这与单个房间的观众人数上限不同。++### 创建房间返回 403浏览器访问的网址不在服务端允许的范围内时,页面可能正常打开,但创建房间会被拒绝。站点管理员可以按以下步骤检查:@@ -71,11 +145,18 @@请求头。如果 403 来自代理或 WAF 本身,则应查看对应日志,不要通过关闭来源校验来绕过。配置方法见 [Server 部署指南](../operations/self-hosting.zh-CN.md)。-## App 找不到窗口或屏幕+## 开始分享++### 没有屏幕选择弹窗-在分享画面的这台电脑上保持 Piik App 运行,点击站点顶部的 **App**,-在本机确认页核对网址并允许使用。-浏览器询问本地网络权限时允许访问,再刷新来源列表;如果之前拒绝过,先检查当前站点的浏览器权限。+按系统提示允许录制屏幕。浏览器屏幕采集需要 HTTPS 或 `localhost`,请在电脑上尝试分享。+在选源器中选择 **浏览器 → 选择画面**,打开浏览器的屏幕、窗口或标签页选择弹窗。+App 来源缺失则按下节操作。++### App 找不到窗口或屏幕++在分享电脑上保持 App 运行,点击站点顶部的 **App**,在本机确认页核对站点并授权。+浏览器询问本地网络权限时允许访问,再刷新来源列表;之前拒绝过则先检查当前站点的权限。选源器会区分以下情况:@@ -90,10 +171,23 @@本地网络权限用于让网页连接 App,与下文的 WebRTC 媒体设置不同。仅凭 App 未连接,不能确定是权限被拒绝。-## Windows 上 H264 分享失败+### 选源后无法开始分享-选中窗口或屏幕后回到未分享状态,或出现「启动分享失败」,可能涉及采集、编码或网页与 App-之间的媒体连接,不能仅凭提示确定是显卡驱动问题。+点击电视下方的错误图标,可查看排查建议、复制失败信息,或开启网页诊断。++- **App 连接断开或请求超时**:确认 App 仍在运行且可以响应,点击站点顶部的 **App** 完成连接。+ 浏览器询问本地网络权限时允许访问。超时只说明请求未及时完成,不能据此认定显卡故障。+- **App 未能启动所选来源**:先换一个普通窗口或屏幕;再对照「浏览器」选源。+ Windows 上可试「自动」或 VP8,后续按[显卡排查](#windows-上-h264-分享失败)操作。+- **浏览器无法读取来源或缺少权限**:保持来源打开,允许系统录屏权限,回到分享页重新选源。+ 摄像头还需检查设备是否正被其他程序独占。+- **媒体连接失败**:检查[浏览器 WebRTC 设置](#浏览器限制了-webrtc)和本地网络权限。+ **创建房间返回 403** 则检查[站点配置](#创建房间返回-403)。+++仍然失败时,[收集同一次尝试的网页与 App 报告](#反馈问题),附上复制的失败信息和所选来源类型。++### Windows 上 H264 分享失败1. **用同一来源对比编码。** 在 **分享设置 → 画面 → 画面细调** 中,将视频编码从 **H264** 改为 **自动** 或**VP8**,重新开始分享。如果 VP8 正常,可以先用它,再排查 H264 路径。@@ -106,38 +200,72 @@完全退出 Chrome 后重新打开再试;没有改善就恢复 **让 Windows 决定**([微软显卡设置说明](https://support.microsoft.com/en-us/windows/hardware/display-graphics/optimizations-for-windowed-games-in-windows-11),英文)。-首选显卡是浏览器侧的排查项,不保证 H264 一定可用。Piik App 会单独选择原生编码器,-修改 Chrome 的首选显卡不会指定 App 的采集显卡。App 采集仍失败时,保留上述编码对照结果,-导出同一次尝试的 App 与网页诊断报告,并附上显卡型号、驱动版本、选源方式和 VP8 是否正常。-两种编码都失败时,也检查下方的 [WebRTC 限制](#浏览器限制了-webrtc)。+首选显卡是浏览器侧的排查项,不保证 H264 可用。Piik App 单独选择原生编码器;Chrome 的首选显卡不会指定 App 的采集显卡。+仍然失败时,[收集报告](#反馈问题)并保留编码对照结果;两种编码都失败时,也检查 [WebRTC 限制](#浏览器限制了-webrtc)。++## 画面与播放-## 游戏黑屏或进入游戏后停止分享+### 画面连接不上++**没有可用的媒体线路** 表示 Piik 还没有找到能把画面送到你设备上的连接。+网页和媒体使用不同的连接;仅凭这条提示还不能确定具体原因。++1. **重新尝试观看连接。** **重新连接** 可用时先点击,否则刷新观看页或重新打开邀请。+ 每次等连接尝试结束,重试一两次即可;反复刷新无法解除网络限制。+2. **检查浏览器 WebRTC 设置。** 浏览器设置、VPN 或隐私扩展可能阻止房主或观众的媒体连接,+ 具体操作见 [WebRTC 排查](#浏览器限制了-webrtc)。+3. **换个网络测试。** 例如试用手机热点。使用 VPN 或代理时,检查其 UDP 策略;受管理的网络请联系管理员。+4. **请另一网络的朋友加入。** 对方能正常看画面且有余力转发时,Piik 可能经由这位观众送到你这里。+ 线路由 Piik 自动选择,能否帮上忙取决于这些连接是否可用。++仍然失败时,继续[进阶网络排查](#进阶网络排查),并收集房主与受影响观众同一次尝试的报告。++### 画面模糊、卡顿或中断++短时变糊可能来自网络或编码负载的自动调整;反复出现或长期不恢复时,按下面的步骤对照:++1. **确认影响范围。** 是房主预览、所有观众,还是只有某位观众?记录大致时间,+ 以及能否自行恢复。房主预览清楚并不保证观众的连接也正常。+2. **一次调整一项。** 房主可在 **分享设置 → 画面** 中先试较低的分辨率或帧率,+ 检查游戏运行时 CPU/GPU 是否接近满载;受影响的观众可用另一浏览器或手机热点对照。+ 将码率调高不一定有帮助。+3. **查看实际编码。** 展开房主的 **连接详情**,查看 **视频编码**。Windows 上,+ 「自动」选择 VP8 可能是 H264 不可用、未能完成检测,或检测未达到所选帧率;+ 软件编码会与游戏争用 CPU。使用「浏览器」选源时,可按[显卡排查](#windows-上-h264-分享失败)+ 检查图形设置,或对照 App 的窗口/屏幕采集。App 会独立尝试可用的硬件编码器。+ 不要仅凭 VP8 判断显卡故障,也不必强制使用检测未通过的 H264。+4. **保留问题发生时的报告。** 按[反馈说明](#反馈问题)收集房主和受影响观众的报告,+ App 采集还需 App 报告。画面持续不恢复时可尝试 **重新连接**;请先导出报告再刷新页面。++如果分享已自动停止,查看电视下方的具体原因,并按[分享启动排查](#选源后无法开始分享)操作;+如果仍在分享但观众看不到画面,按[连接排查](#画面连接不上)操作。++### 游戏黑屏或进入游戏后停止分享先确认当前分享的是游戏窗口或游戏所在的屏幕,再尝试游戏的无边框窗口模式。对照分享一个普通窗口,并在 App 选源与 **浏览器** 选源之间比较。受保护的内容可能无法采集;某个游戏失败不代表所有来源都不可用。如果进入游戏后 Piik 退回未分享状态,查看电视下方的失败原因,按[分享启动排查](#选源后无法开始分享)操作。-反馈时附上游戏名称、窗口模式、选源方式、编码器和同一次尝试的 App/网页报告。-不要仅凭「没有画面」确定为编码故障。+[反馈报告](#反馈问题)中请附上游戏名称和窗口模式。-## HDR 画面过亮或颜色发白+### HDR 画面过亮或颜色发白Windows App 的 **程序 / 窗口** 和 **屏幕** 采集会将 HDR 转成 SDR,再分享给观众。**浏览器** 选源由浏览器负责采集,部分 HDR 来源可能过曝;这是当前的已知限制。可改用 App 的上述分类,或在 Windows 显示设置中暂时关闭 HDR 后重新选源。提高分辨率或码率无法恢复已经丢失的亮部细节。-仍然异常时,请说明使用的是哪种选源方式、是否开启 HDR、显卡和显示器型号,-并附上源画面与观众画面的对照。技术背景见 [HDR 采集说明(英文)](../research/media-fidelity.md#hdr-to-sdr)。+仍然异常时,请附上 HDR 设置、显卡/显示器型号及源画面与观众画面的对照。+技术背景见 [HDR 采集说明(英文)](../research/media-fidelity.md#hdr-to-sdr)。-## Windows 分享时出现黄框+### Windows 分享时出现黄框-Windows 用黄色边框标出正在采集的窗口或屏幕。在支持的 Windows 版本上,-App 选源器提供 **显示采集边框** 开关,默认关闭;系统权限或其他正在进行的采集+Windows 用黄色边框标出正在采集的窗口或屏幕。App 检测到采集能力支持时,+选源器会提供 **显示采集边框** 开关,默认关闭;系统权限或其他正在进行的采集仍可能要求显示边框。Windows 10 的采集接口没有这个开关。-### Windows 11 关闭开关后仍有黄框+#### Windows 11 关闭开关后仍有黄框1. 从 Piik 的 **程序 / 窗口** 或 **屏幕** 列表选源,保持 **显示采集边框** 关闭。通过浏览器选源时,采集标识由浏览器管理。@@ -147,10 +275,12 @@ App 选源器提供 **显示采集边框** 开关,默认关闭;系统权限Windows 需要用户授权;其他采集要求显示边框时,边框仍会保留([微软接口说明](https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscapturesession.isborderrequired),英文)。-仍未解决时,反馈中请附上 Windows 版本、选源方式和-[App 诊断报告](../../cmd/piik-app/README.zh-CN.md#诊断)。+仍未解决时,请附上 Windows 版本和 [App 报告](#反馈问题)。++<details>+<summary>进阶:Windows 10 可选处理方法</summary>-### Windows 10 可选处理方法+#### Windows 10 可选处理方法[DWM Custom Projection Border](https://windhawk.net/mods/dwm-custom-projection-border)是适用于 x64(64 位)Windows 的 Windhawk 第三方模组,可以在保持原有采集方式的情况下隐藏黄框。@@ -170,116 +300,59 @@ Windows 需要用户授权;其他采集要求显示边框时,边框仍会保最新操作说明见[模组作者说明](https://github.com/ramensoftware/windhawk-mods/blob/main/mods/dwm-custom-projection-border.wh.cpp)和 [Windhawk 进程设置文档](https://github.com/ramensoftware/windhawk/wiki/Injection-targets-and-critical-system-processes)(英文)。-## 公网邀请创建失败或出现 1033+</details>-App 的 **公网邀请** 通过 Cloudflare Tunnel 提供临时网页地址。-该服务的可达性会随网络而变化,[Quick Tunnels 不保证持续可用](https://developers.cloudflare.com/tunnel/get-started/quick-tunnels/#limitations)。-`public invitation service exited before connecting` 表示辅助程序在连接完成前退出;-`exit status 1` 本身不能说明具体原因。-[Cloudflare 的 1033 说明](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1033/)(英文)-表示该地址当前没有可用的隧道连接。这与网页能打开、但显示「没有可用的媒体线路」是不同的问题。+### 全屏或休眠后播放异常-1. **观众先确认链接。** 请房主确认 App 仍在运行、电脑未休眠,并发送当前邀请。- App 重新启动后应使用新链接,旧地址可能失效。-2. **房主查看错误详情。** 确认已完整解压 App 程序包;保留启动页面或终端的完整错误,- 包括退出码后的详细信息。开启 **诊断启动** 后再试。- App 会在启动时限内重试提前退出的隧道进程。-3. **对照网络。** 可用手机热点重试,检查 DNS、代理或防火墙是否阻止 Cloudflare Tunnel。- 只调整相关规则;学校或公司的网络应联系管理员。+- **手机全屏仍有黑边:** 画面默认保持原始比例,可尝试横屏,或在 **播放设置** 中选择+ **等比铺满** 或 **拉伸铺满**。+- **全屏按钮无效:** 使用播放栏的 **全屏观看** 按钮。系统视频全屏由浏览器提供,+ 见[观看操作](./getting-started.zh-CN.md#加入朋友的房间)。+- **休眠或挂起后分享中断:** 唤醒设备,回到分享标签页,必要时重新开始分享。+ 浏览器或系统挂起可能中断采集和播放。-使用代理时,请确认它实际覆盖 `cloudflared` 进程。仅开启浏览器代理或设置-`HTTP_PROXY`/`HTTPS_PROXY`,不会让当前随包的隧道程序自动走代理。+## 声音与浏览器权限-错误详情可以帮助区分失败的环节:+### 有画面但没有来源声音-| 错误中出现 | 检查什么 |-| --- | --- |-| `failed to request quick Tunnel`、`api.trycloudflare.com` | 临时地址申请失败。查看后面的具体原因:域名解析错误检查 DNS;连接超时检查 HTTPS 出站连接、代理或服务状态。 |-| QUIC 超时、`dial tcp ...:7844` 或 `TLS handshake with edge` | 到 Cloudflare 隧道节点的连接失败。检查 `cloudflared` 的出站规则,包括代理或游戏加速器是否影响该连接。 |+1. 取消视频静音,并检查播放音量。+2. 房主应选择支持分享声音的来源,并在选源器中打开声音;可用声音取决于来源和平台。+3. 摄像头画面与麦克风输入分别选择。内置麦克风或 OBS 音频的用法,见[摄像头与音频输入](./sharing.zh-CN.md#摄像头与虚拟音频输入)。-Piik 已启用 QUIC(UDP)失败后尝试 HTTP/2(TCP),两者都使用出站端口 `7844`。-如果两条线路都不可达,反复重试也无法解决;浏览器能访问普通网页不代表该端口可用。-具体要求见 [Cloudflare 连接排查](https://developers.cloudflare.com/tunnel/troubleshooting/)(英文),-无需在路由器上开放入站端口。+### 听不到说话声-**暂时绕过公网邀请:** 保持 App 运行,打开[在线版](https://demo.piik.tv)或其他可访问的 Piik 站点,-按[通过已有站点使用 App](./getting-started.zh-CN.md#通过已有站点使用-app)完成授权并使用窗口/屏幕采集,-再将新站点的房间邀请发给朋友。原公网邀请链接不会转到这个新房间。-在线版无需站点口令。这绕过的是 Cloudflare 临时网页入口;在线版仍仅使用 P2P,不提供 SFU 兜底。-网页能打开但画面连不上时,转到[画面连接排查](#画面连接不上)。-反馈中请附上 App 版本、失败时间和 [App 诊断报告](../../cmd/piik-app/README.zh-CN.md#诊断)。-如果打不开的是自建站点而非 App 的临时地址,请联系该站点管理员检查服务。+支持房间语音的版本中:-## 画面模糊、卡顿或中断+1. 双方都加入 **互动 → 语音**,由房主先选择 **开启房间语音**。+ 加入只开始收听,每位发言者还需主动打开自己的麦克风。+2. 发言者检查浏览器的麦克风权限,以及 **麦克风设置** 中的输入设备和音量。+ 使用麦克风需要 HTTPS 或 `localhost`。+3. 检查自己是否暂停收听或将对方本地静音。这些控制与视频静音分开;**暂停收听** 不会关闭自己的麦克风。-短时变糊可能来自网络或编码负载的自动调整;反复出现或长期不恢复时,按下面的步骤对照:+语音提示连接失败时,对照 [WebRTC 设置](#浏览器限制了-webrtc)及另一网络。+能看画面不代表语音连接正常。功能可用范围见[房间语音](./room-tools.zh-CN.md#房间语音)。-1. **确认影响范围。** 是房主预览、所有观众,还是只有某位观众?记录大致时间,- 以及能否自行恢复。房主预览清楚并不保证观众的连接也正常。-2. **一次调整一项。** 房主可在 **分享设置 → 画面** 中先试较低的分辨率或帧率,- 检查游戏运行时 CPU/GPU 是否接近满载;受影响的观众可用另一浏览器或手机热点对照。- 将码率调高不一定有帮助。-3. **查看实际编码。** 展开房主的 **显示连接详情**,查看 **视频编码**。Windows 上,- 「自动」选择 VP8 可能是 H264 不可用、未能完成检测,或检测未达到所选帧率;- 软件编码会与游戏争用 CPU。使用「浏览器」选源时,可按[显卡排查](#windows-上-h264-分享失败)- 检查图形设置,或对照 App 的窗口/屏幕采集。App 会独立尝试可用的硬件编码器。- 不要仅凭 VP8 判断显卡故障,也不必强制使用检测未通过的 H264。-4. **保留问题发生时的报告。** 在房主和受影响的观众页面开启诊断后重现,- App 采集还需 App 报告。画面持续不恢复时可尝试 **重新连接**;请先导出报告再刷新页面。+### 回声或传出了多余的应用声音-如果分享已自动停止,查看电视下方的具体原因,并按[分享启动排查](#选源后无法开始分享)操作;-如果仍在分享但观众看不到画面,继续查看下方的连接排查。+扬声器被麦克风再次收音时,可使用耳机。Windows App 屏幕采集支持+[排除语音软件的来源音频](./sharing.zh-CN.md#分享屏幕时排除语音软件的声音),但不会消除声学回声。-## 画面连接不上+虚拟麦克风在 Piik 闭麦后仍可听见时,暂时关闭 **系统声音** 对照。如果声音消失,+说明混音软件的播放输出也进入了来源音频。检查其播放/监听路由,或只分享需要的应用窗口音频。+Piik 的麦克风静音不会关闭这条独立来源。-**没有可用的媒体线路** 表示 Piik 还没有找到能把画面送到你设备上的连接。-网页和媒体使用不同的连接,所以可能出现网页能打开、画面却连不上的情况。--NAT(网络地址转换)让多台设备共用一个上网地址。不同路由器和运营商对地址转换、-外部数据进入的规则不同,有些组合会让设备难以直连。防火墙和浏览器策略也可能阻止媒体连接,-仅凭这条提示还不能确定具体原因。--STUN 帮助设备发现用于直连的地址,不负责转发画面。STUN 服务不可达时,-也可能出现聊天正常、媒体连不上的情况。App 公网邀请已使用多个发现服务,-单个 STUN 报错不代表全部线路失败。自部署管理员应检查 `STUN_URLS`-是否指向可达的 UDP 服务;HTTP 反向代理不能转发 STUN。-App 用户需要更换服务商时,可在启动公网邀请前设置-[`PIIK_STUN_URLS`](../standards/configuration.md#piik-app-configuration),-替换所有内置发现地址。请选择信任的服务,因为 STUN 会接收到参与者的公网 IP。-请结合双方同一次尝试的诊断报告判断原因。--可以依次尝试,画面恢复后就不必继续:--1. **重新尝试观看连接。** 如果 **重新连接** 可用,先点击;按钮不可用或没有效果时,- 刷新观看页或重新打开邀请链接。每次等连接尝试结束,重试一两次即可;反复刷新无法解除网络限制。-2. **检查浏览器的 WebRTC 设置。** 浏览器设置、VPN 或隐私扩展可能阻止媒体连接,- 即使网页本身能打开;房主和观众都会受影响,具体操作见下方的 [WebRTC 排查](#浏览器限制了-webrtc)。-3. **换个网络测试。** 例如试用手机热点。如果使用了 VPN 或代理,检查其 UDP 策略;受管理的网络请联系管理员。-4. **开启可用的 IPv6。** 先确认宽带、路由器和设备都支持。连接双方都有可用 IPv6 时,- Piik 可以多尝试一条直连路径;它仍受防火墙规则约束,同时保留 IPv4 即可。-5. **检查自己管理的路由器。** 在可信家庭网络中,路由器支持的 UPnP、PCP 或 NAT-PMP- 可以让 App 的原生媒体连接申请端口映射;纯浏览器采集不会申请这些映射。- 如果光猫和路由器都在做 NAT,可按对应型号的桥接或 AP 模式说明减少一层。- 运营商共享公网地址(CGNAT)位于路由器上游,需要向运营商咨询公网 IPv4 或 IPv6 服务。- 修改路由器工作模式前,先备份配置。-6. **请另一网络的朋友加入。** 如果对方能正常看到画面,且有余力转发,Piik 可能经由这位观众- 把画面送到你这里。线路由 Piik 自动选择,能否帮上忙取决于这些连接是否可用。-7. **使用有媒体兜底的站点。** 管理员需要先启用 SFU 转发。如果页面提供 **隐私模式**,- 房主应在分享前关闭;配置为 **服务器转发** 的站点已经强制使用 SFU。- 公开站点 `demo.piik.tv` 和 App 的 **公网邀请** 模式均没有 SFU 兜底。- 有服务器的用户也可以按 [部署指南](../operations/self-hosting.zh-CN.md#可选启用媒体兜底) 配置,属于进阶操作。- 目前 P2P 和 SFU 媒体都使用 UDP;网络完全禁止 UDP 时,仍需换网络或由管理员放行。--不同型号的路由器菜单会有差异,可参考厂商的-[IPv6 条件说明](https://support.google.com/googlehome/answer/6361450?hl=zh-Hans)、-[UPnP 说明](https://support.google.com/googlehome/answer/6274337?hl=zh-Hans) 和-[双重 NAT 调整示例](https://www.tp-link.com/us/support/faq/3113/)(英文)。-想了解连接机制,可以阅读 [WebRTC 官方说明](https://webrtc.org/getting-started/peer-connections)(英文)。--仍然失败时,收集出现问题的观众端与房主端同一次尝试的-[诊断报告](../../cmd/piik-app/README.zh-CN.md#诊断),反馈时附上发生时间、Piik 版本和所用网络类型。-自部署站点使用 SFU 时,也请附上服务端报告。房主上传成功或订阅建立,并不代表观众已经收到并解码画面;-两端报告能帮助判断具体卡在哪一步。+### 无法使用麦克风或远程控制++1. 打开当前 App 生成的完整 HTTPS 邀请。本地邀请应先[确认证书](#本地-https-证书提示)。+ 普通 HTTP 内网页面可以观看、聊天和加入语音收听,但不能使用需要安全上下文的麦克风、摄像头采集和远控接口。+ 仅修改链接里的协议名不会开启 HTTPS;`localhost` 只代表当前设备。+2. 麦克风不可用时,检查当前站点的浏览器权限和所选输入设备。+3. 远控需更新房主 App 和站点,再刷新观众页面。房主必须使用 App 窗口/屏幕采集并开启远控;+ 浏览器与摄像头采集不能接收远程输入。随后按[授权步骤](./room-tools.zh-CN.md#让朋友操作共享的电脑)操作。++浏览器不接受本地证书例外时,改用可访问的 **公网邀请** 或具有可信证书的 HTTPS 站点。++## 进阶网络排查### 浏览器限制了 WebRTC@@ -298,18 +371,82 @@ Piik 通过 WebRTC 传输画面和声音。禁用 WebRTC 或禁止未经代理参考 [Chrome 策略说明](https://developer.chrome.com/docs/extensions/reference/api/privacy#property-network)和 [Vivaldi 隐私设置](https://help.vivaldi.com/desktop/privacy/privacy-settings/)(英文)。+### STUN、IPv6 与路由器检查++NAT 让多台设备共用一个上网地址。有些路由器或运营商网络会使直连更困难;+防火墙和浏览器策略也可能阻止媒体。检查自己能够管理的部分:++1. **STUN 地址发现:** STUN 帮助发现直连地址,不负责转发画面。服务不可达时,可能聊天正常而媒体连不上。+ App 公网邀请已使用多个发现服务,单个 STUN 报错不代表全部线路失败。+ 自部署管理员应检查 `STUN_URLS` 是否指向可达的 UDP 服务;HTTP 反向代理不能转发 STUN。+ App 用户可在启动公网邀请前设置 [`PIIK_STUN_URLS`](../standards/configuration.md#piik-app-configuration),+ 替换所有内置发现地址。请选择信任的服务,因为它会接收到参与者的公网 IP。+2. **IPv6:** 宽带、路由器和双方设备都有可用 IPv6 时,Piik 可以在 IPv4 之外尝试这条直连路径。+ 同时保留 IPv4;IPv6 仍受防火墙约束。+3. **家庭路由器:** 支持的 UPnP、PCP 或 NAT-PMP 可以让 App 原生媒体连接申请端口映射;+ 纯浏览器采集不会申请。光猫和路由器都做 NAT 时,可按对应型号的桥接或 AP 模式说明减少一层,+ 修改工作模式前先备份配置。运营商共享公网地址(CGNAT)位于上游,需向运营商咨询公网 IPv4 或 IPv6 服务。++路由器菜单随型号而异,可参考厂商的+[IPv6 条件](https://support.google.com/googlehome/answer/6361450?hl=zh-Hans)、+[UPnP 说明](https://support.google.com/googlehome/answer/6274337?hl=zh-Hans)、+[双重 NAT 示例](https://www.tp-link.com/us/support/faq/3113/)及+[WebRTC 连接说明](https://webrtc.org/getting-started/peer-connections)(后两篇为英文)。+结合双方报告判断原因。+### 校园网或严格 NAT-校园网并不一定无法使用 Piik,但多人共用出口、严格的防火墙策略可能让直连更困难。-先用手机热点打开同一邀请对照;热点可用时,优先排查原网络的限制。+先用手机热点打开同一邀请对照。热点可用时,优先排查原网络的共享出口或防火墙限制。++经常使用时,管理员可在自建 Piik 站点[启用 SFU 媒体兜底](../operations/self-hosting.zh-CN.md#可选启用媒体兜底)。+页面提供 **隐私模式** 时,房主应在分享前关闭;配置为 **服务器转发** 的站点已经强制使用 SFU。+保持 App 运行,打开新站点,点击 **App** 完成本机授权,再发送该站点的邀请。++公开站点 `demo.piik.tv` 和 App 的 **公网邀请** 仅提供 P2P。目前 P2P 和 SFU 媒体均需要 UDP。+单独搭建服务器不能绕过完全禁止媒体 UDP 的网络;需换网络或由管理员放行。++### 可选:虚拟局域网++不便部署服务器时,也可以尝试第三方虚拟局域网,让朋友先加入同一虚拟网络。+例如 [UU 官方教程](https://uu.163.com/blog/lan-multiplayer-guide-net.html)提供了「局域网联机」和「通用联机」入口。+选择通用局域网组网功能,而不是仅限某个游戏的加速;工具需提供可互访的虚拟 IPv4 地址,+并同时支持 Piik 的网页访问和 WebRTC UDP。++1. 所有参与者先运行组网工具,加入同一个虚拟局域网。+2. 如果工具提供的虚拟网卡和 IP 出现在 Piik App 的 **本地房间** 地址列表中,+ 房主选择该地址进入并开始分享。打不开网页时,先按[本地邀请排查](#本地邀请打不开)+ 检查 Windows 防火墙是否允许 Piik 通过该虚拟网络。+3. 将该地址下的完整 Piik 邀请链接发给朋友,不要发送 `localhost` 地址或只发房间号。+ 网页能打开后,还需确认画面和声音正常;网页连通不代表媒体 UDP 一定可用。+4. 所有设备保持组网工具运行。工具的虚拟 IP 变化后,在 App 中重新选择地址并发送新邀请。++**本地房间** 会为所选虚拟 IP 生成 HTTPS 邀请,首次访问应先[确认证书](#本地-https-证书提示)。+随后支持的浏览器即可开麦、使用摄像头或远控,无需公网隧道;普通局域网的用法相同。+不可用时,检查[浏览器权限](#无法使用麦克风或远程控制)。连接详情中可查看所选媒体地址。++请使用已更新的 App,以发现经过路由的虚拟局域网地址。本方法需要可用的虚拟地址和媒体 UDP,+不适用于仅转发游戏流量的工具。防火墙、浏览器地址发现和第三方服务仍会影响可用性;仅与信任的朋友组网。++[ZeroTier](https://docs.zerotier.com/start/) 和 [Tailscale](https://tailscale.com/docs/how-to/quickstart) 也提供私有组网能力。+使用前需确认设备支持和上述条件;这些替代工具尚未与 Piik 实测。++有公网服务器的管理员可按 [frp 教程](../operations/self-hosting.zh-CN.md#可选通过-frp-转发已有服务),+通过 frps 转发已有站点的网页和 SFU 端点;只转发网页不能同时转发 WebRTC 媒体。++## 反馈问题++请附上 Piik 版本、系统与浏览器、发生时间、预期结果和复现步骤。+采集问题还需说明来源类型、编码、显卡/驱动,以及其他来源或 VP8 是否正常;网络问题说明所用网络类型。++先开启诊断,重现一次,再在刷新前导出:-经常需要使用的话,建议考虑 **自建 Piik 站点并启用 SFU 媒体转发**,让直连失败时有服务器路线。-按[部署指南](../operations/self-hosting.zh-CN.md#可选启用媒体兜底)配置公网地址并放行所需 UDP 端口。-保持 Piik App 运行,用浏览器打开新站点,点击顶部的 **App** 完成本机授权,-再发送该站点生成的邀请链接。+- **网页:** 使用页面的诊断按钮。分享失败时,电视下方的错误图标还可复制失败信息,+ 包含网页版本、提示和错误编号,不包含邀请链接或来源名称。+- **App 采集:** 还需在 App 模式选择页开启 **诊断启动**,随后在终端按 `D` 导出 App 报告。+- **连接失败:** 收集受影响观众和房主同一次尝试的报告;自部署 SFU 还需服务端报告。+ 房主上传成功或订阅建立,并不代表观众已经收到画面。-公开 Demo 和 App 的公网邀请模式只有 P2P。SFU 同样需要 UDP 可用;如果网络完全禁止 UDP,-仍需换网络或联系管理员放行,单独搭建服务器不能解除这类限制。+报告保存在本机,分享前请检查私人信息;[诊断与导出](../../cmd/piik-app/README.zh-CN.md#诊断)说明报告内容。+没有日志也可以反馈,但一张通用失败截图可能无法确定具体环节。-想为朋友搭一个站点?从 [部署指南](../operations/self-hosting.zh-CN.md) 开始。-其他指南可在 [文档中心](./README.zh-CN.md) 找到。+其他指南可在[文档中心](./README.zh-CN.md)找到。diff --git a/docs/operations/self-hosting.md b/docs/operations/self-hosting.mdindex 5078b43c..7306fb4f 100644--- a/docs/operations/self-hosting.md+++ b/docs/operations/self-hosting.md@@ -14,24 +14,27 @@ participants' capture and encoding work.## Try it locally-These instructions support Linux x64 and ARM64.+Server packages are available for Linux x64/ARM64 and Windows x64.Download the Server archive matching your machinefrom [GitHub Releases](https://github.com/TNTcraftHIM/Piik/releases)or the [Gitee mirror](https://gitee.com/TNTcraftHIM/Piik/releases).-Use `uname -m` to check the architecture:+On Linux, use `uname -m` to check the architecture:-| Architecture | Archive |+| Platform | Archive || --- | --- |-| `x86_64` (x64) | `piik-<revision>-runtime.tar.gz` |-| `aarch64` (ARM64) | `piik-<revision>-linux-arm64-runtime.tar.gz` |+| Linux `x86_64` (x64) | `piik-<revision>-runtime.tar.gz` |+| Linux `aarch64` (ARM64) | `piik-<revision>-linux-arm64-runtime.tar.gz` |+| Windows x64 | `piik-<revision>-windows-amd64-runtime.zip` |-Extract it and run the following in its directory:+Extract it and run the following in its directory on Linux:```sh./piik-server```+On Windows, open PowerShell in the extracted directory and run `./piik-server.exe`.+Open `http://localhost:8787`. This is a local trial; use the configuration belowto let friends connect over the internet. To start a temporary room on your computer,use the [Piik App guide](../guide/getting-started.md).@@ -60,9 +63,47 @@ the sample `.env` also shows how to enable SFU fallback. Keep the `piik-data`volume, which stores room data and optional diagnostics. See[container maintenance](./service-management.md#container) for updates and backups.+## Private LAN without a domain++For a NAS, home server or virtual LAN, Piik can serve HTTPS directly. Save the+following as `.env` beside the server binary, replacing every `192.168.1.10`+with the server's address on that network:++```dotenv+PIIK_ENV=production+LISTEN_HOST=0.0.0.0+PORT=8787+PUBLIC_BASE_URL=https://192.168.1.10:8787+TLS_SELF_SIGNED=true+STUN_URLS=stun:192.168.1.10:3478+```++From that directory, run `./piik-server --check-config`, then `./piik-server`+(use `.exe` on Windows).+Allow TCP 8787 and UDP 3478 on that network. Open the **HTTPS** address on each+device; no public IP, domain or reverse proxy is needed. With Docker Compose,+also change the web port mapping from `127.0.0.1:8787:8787/tcp` to+`8787:8787/tcp` so LAN devices can reach it.++The browser will warn about the self-signed certificate. Compare its SHA-256+fingerprint with the server's **HTTPS certificate** startup message before+continuing; see [local certificate confirmation](../guide/troubleshooting.md#local-https-certificate-warning).+The certificate stays in memory and changes when Piik restarts, so confirm the+new one after a restart. Browser microphone, camera and remote control still+require their ordinary permissions and supported APIs.++To keep your own certificate, turn off `TLS_SELF_SIGNED` and set both+`TLS_CERT_FILE` and `TLS_KEY_FILE` to its PEM files. With Docker, mount those+files read-only and use their paths inside the container. The certificate must cover+the host in `PUBLIC_BASE_URL`. `--check-config` checks the pair and validity;+restart Piik after replacing the files. Piik does not obtain or renew these+certificates. For a long-running public site, use the automatic HTTPS proxy below.+If the web port is occupied, stop the conflicting service or change both `PORT`+and the port in `PUBLIC_BASE_URL`, then send new invitations.+## Put it online-You need a Linux x64 or ARM64 server and a domain pointing to its public IP.+You need a supported server and a domain pointing to its public IP.The example uses `share.example.com`; replace it with your domain.### 1. Configure and start Piik@@ -85,6 +126,9 @@ Run these commands from that directory as a regular user:./piik-server```+On Windows, use `./piik-server.exe --check-config` and `./piik-server.exe` in+PowerShell. The same `.env` file and ports apply.+The server reads `.env` automatically and stores rooms in `rooms.sqlite` in theworking directory. A blank `SITE_ACCESS_PASSWORD` allowsentry without a site passphrase; enter a passphrase to require one.@@ -155,9 +199,75 @@ To send every room through your server, also set `SFU_ONLY=true` and restart.The sharing settings will show **Server media**. Plan server bandwidth for everyViewer; this mode does not fall back to P2P if the server route fails.+## Optional: forward an existing server with frp++If Piik runs behind NAT and you control a public frps host, frp can forward its+existing web and SFU endpoints. P2P ICE discovery remains unchanged.++Run the [HTTPS proxy above](#2-enable-https) on the public host, keeping its+WebSocket-capable upstream at `127.0.0.1:8787`. Point `share.example.com` and+`relay.example.com` to that host. Open TCP 7000 for frpc and UDP 7882 for media,+alongside TCP 80/443; keep the forwarded TCP 8787 private to the HTTPS proxy.++On the public host, configure `frps.toml`:++```toml+bindPort = 7000+auth.token = "{{ .Envs.FRP_TOKEN }}"+transport.tls.force = true+allowPorts = [{ single = 8787 }, { single = 7882 }]+```++On the Piik machine, copy [frpc.toml.example](../../deploy/frp/frpc.toml.example)+to `frpc.toml` and replace `relay.example.com`. Inject the same private, nonempty+`FRP_TOKEN` into both frp process environments. Validate each file with+`frps verify -c frps.toml` / `frpc verify -c frpc.toml`, then start each process+with `-c` and its file. See [frp configuration](https://gofrp.org/en/docs/features/common/configure/)+and [TCP/UDP forwarding](https://gofrp.org/en/docs/features/tcp-udp/).++Keep Piik's `LISTEN_HOST=127.0.0.1` and update its `.env`:++```dotenv+PUBLIC_BASE_URL=https://share.example.com+STUN_URLS=stun:stun.direct.example.com:3478+SFU_UDP_PORT=7882+SFU_PUBLIC_IP=203.0.113.10+```++Replace the example IPv4 with the public frps address and the STUN hostname with+a directly reachable STUN service. The frpc local and remote UDP ports must both+equal `SFU_UDP_PORT`. Do not forward Piik's STUN ports through frp: its UDP proxy+[changes the source mapping](../research/nat-traversal.md#external-forwarding-and-participant-relays)+STUN would report. Restart Piik and check HTTPS health, room access and+**Server media** from another network.++### Using a managed frp provider++Services such as SakuraFrp supply the public server and their own client or+launcher. Follow the provider's setup instead of copying the private frps token+configuration above. Check that the chosen node supports both HTTPS web access+with WebSockets and an ordinary UDP tunnel.++| Endpoint | Local target | Piik setting |+| --- | --- | --- |+| Web | `127.0.0.1:8787`, with HTTPS supplied by your proxy or provider | Set `PUBLIC_BASE_URL` to the actual public HTTPS address, including any port. |+| Media | `127.0.0.1:<assigned UDP port>` | Set `SFU_UDP_PORT` to that same local/public port and `SFU_PUBLIC_IP` to the UDP node's public IPv4. |++For example, if the provider assigns UDP port `30000`, use `30000` for both+tunnel ports and Piik's `SFU_UDP_PORT`; the web port can remain `8787` locally.+Keep STUN directly reachable as above. A web-only tunnel carries signaling but+does not add an SFU media route for strict NAT.++See SakuraFrp's [web setup](https://doc.natfrp.com/app/http.html) and+[UDP connectivity notes](https://doc.natfrp.com/faq/network.html). Node features,+access requirements and bandwidth depend on the provider; Piik has not yet+field-tested this managed service.+## Keep it running and update-For automatic startup, use the [systemd or container guide](./service-management.md).+On Linux, use the [systemd or container guide](./service-management.md) for automatic+startup. On Windows, run the executable under your existing service manager or+Task Scheduler; Piik does not install a Windows service.Keep `.env` and `rooms.sqlite` across updates. Back up room data while the server isstopped, replace the executable with the new release, then restart and checkhealth and room access. Read release notes before an upgrade that changes data formats.diff --git a/docs/operations/self-hosting.zh-CN.md b/docs/operations/self-hosting.zh-CN.mdindex ef311694..29f83b3b 100644--- a/docs/operations/self-hosting.zh-CN.md+++ b/docs/operations/self-hosting.zh-CN.md@@ -12,23 +12,26 @@ Piik Server 将网页、房间管理和可选的媒体转发打包在**一个服## 先在本机试用-以下操作适用于 Linux x64 和 ARM64 服务器。+服务端提供 Linux x64/ARM64 和 Windows x64 程序包。从 [GitHub Releases](https://github.com/TNTcraftHIM/Piik/releases) 或[Gitee 镜像](https://gitee.com/TNTcraftHIM/Piik/releases)下载对应架构的服务端程序包。-可运行 `uname -m` 查看架构:+Linux 可运行 `uname -m` 查看架构:-| 架构 | 程序包 |+| 平台 | 程序包 || --- | --- |-| `x86_64`(x64) | `piik-<revision>-runtime.tar.gz` |-| `aarch64`(ARM64) | `piik-<revision>-linux-arm64-runtime.tar.gz` |+| Linux `x86_64`(x64) | `piik-<revision>-runtime.tar.gz` |+| Linux `aarch64`(ARM64) | `piik-<revision>-linux-arm64-runtime.tar.gz` |+| Windows x64 | `piik-<revision>-windows-amd64-runtime.zip` |-解压后,在该目录运行:+Linux 解压后,在该目录运行:```sh./piik-server```+Windows 解压后,在该目录打开 PowerShell,运行 `./piik-server.exe`。+打开 `http://localhost:8787` 即可试用。需要让朋友通过互联网访问时,继续完成下方配置。如果只想在自己的电脑上临时开房间,可直接使用 [Piik App](../guide/getting-started.zh-CN.md#用-piik-app-分享)。@@ -55,9 +58,41 @@ Docker 会自动选择对应架构的镜像。请保留 `piik-data` 数据卷,房间数据和可选诊断文件都保存在其中。更新与备份见[容器维护说明](./service-management.zh-CN.md#容器)。+## 无域名的内网部署++NAS、家用服务器或虚拟局域网可以直接使用 Piik 提供的 HTTPS,无需另装反向代理。+在服务端程序旁创建 `.env`,填写以下配置,将所有 `192.168.1.10` 换成服务器在该网络中的 IP:++```dotenv+PIIK_ENV=production+LISTEN_HOST=0.0.0.0+PORT=8787+PUBLIC_BASE_URL=https://192.168.1.10:8787+TLS_SELF_SIGNED=true+STUN_URLS=stun:192.168.1.10:3478+```++在该目录先运行 `./piik-server --check-config`,检查通过后运行 `./piik-server`;Windows 加上 `.exe`。+在该网络放行 TCP 8787 和 UDP 3478,然后用各台设备打开上述 **HTTPS** 地址。+不需要公网 IP 或域名。如果使用 Docker Compose,还需把网页端口映射+`127.0.0.1:8787:8787/tcp` 改为 `8787:8787/tcp`,让内网设备可以访问。++浏览器会提示证书不受信任。请先核对证书的 SHA-256 指纹,与服务端启动时的+**HTTPS certificate** 信息一致后再继续,见[本地证书确认说明](../guide/troubleshooting.zh-CN.md#本地-https-证书提示)。+临时证书只保存在内存中,重启 Piik 后会更换,需要重新确认。+开麦、摄像头和远控仍需浏览器支持相关接口,并完成各自的正常授权。++如果已有自己的证书,关闭 `TLS_SELF_SIGNED`,同时设置 `TLS_CERT_FILE` 和 `TLS_KEY_FILE`,+指向 PEM 格式的证书和私钥文件。Docker 中需将文件只读挂载,并使用容器内的路径。+证书需覆盖 `PUBLIC_BASE_URL` 中的域名或 IP;+`--check-config` 会检查文件配对、地址与有效期,替换文件后需重启 Piik。+Piik 不负责申请或续期证书。长期对外服务的站点建议使用下方自动管理证书的 HTTPS 代理。+网页端口被占用时,先停止占用服务,或同时修改 `PORT` 与 `PUBLIC_BASE_URL` 中的端口,+再重新发送邀请。+## 对外提供服务-准备一台 Linux x64 或 ARM64 服务器,以及一个指向服务器公网 IP 的域名。+准备一台受支持的服务器,以及一个指向服务器公网 IP 的域名。下文以 `share.example.com` 为例,请替换成自己的域名。### 1. 配置并启动 Piik@@ -80,6 +115,9 @@ SITE_ACCESS_PASSWORD=./piik-server```+Windows 请在 PowerShell 中改用 `./piik-server.exe --check-config` 和+`./piik-server.exe`;`.env` 文件和端口配置相同。+程序会自动读取 `.env`,并将房间数据保存在工作目录的 `rooms.sqlite` 中。`SITE_ACCESS_PASSWORD` 留空时,进入站点无须口令;如需设置口令,填写你想使用的口令即可。房间邀请与加入权限仍由房主管理。@@ -140,9 +178,69 @@ TCP 8787 仅供本机反向代理访问。STUN 域名需要直接解析到服务分享设置中会显示 **服务器转发**。请为每位观众预留服务器带宽;服务器线路失败时,此模式不会改走 P2P。+## 可选:通过 frp 转发已有服务++如果 Piik 位于 NAT 后方,且你有一台公网 frps 主机,可用 frp 转发已有的网页和 SFU 端口。+P2P 的 ICE 探测方式保持不变。++将[上方的 HTTPS 代理](#2-配置-https)部署在公网主机,仍转发到 `127.0.0.1:8787`,+并保留 WebSocket 支持。将 `share.example.com` 和 `relay.example.com` 解析到该主机。+除 TCP 80/443 外,放行供 frpc 连接的 TCP 7000 和媒体使用的 UDP 7882;+转发后的 TCP 8787 仅供 HTTPS 代理访问,不对公网开放。++在公网主机配置 `frps.toml`:++```toml+bindPort = 7000+auth.token = "{{ .Envs.FRP_TOKEN }}"+transport.tls.force = true+allowPorts = [{ single = 8787 }, { single = 7882 }]+```++在 Piik 所在机器,将 [frpc.toml.example](../../deploy/frp/frpc.toml.example)+复制为 `frpc.toml`,替换其中的 `relay.example.com`。+为两端的 frp 进程注入相同、非空的私密环境变量 `FRP_TOKEN`。+分别运行 `frps verify -c frps.toml` / `frpc verify -c frpc.toml` 检查配置,+再用 `-c` 指定各自的文件启动。具体用法见 [frp 配置说明](https://gofrp.org/zh-cn/docs/features/common/configure/)+和 [TCP/UDP 转发](https://gofrp.org/zh-cn/docs/features/tcp-udp/)。++Piik 保持 `LISTEN_HOST=127.0.0.1`,并修改 `.env`:++```dotenv+PUBLIC_BASE_URL=https://share.example.com+STUN_URLS=stun:stun.direct.example.com:3478+SFU_UDP_PORT=7882+SFU_PUBLIC_IP=203.0.113.10+```++将示例 IPv4 换成 frps 的公网地址,将 STUN 域名换成直接可达的 STUN 服务。+frpc 的本地与公网 UDP 端口必须都等于 `SFU_UDP_PORT`。+不要通过 frp 转发 Piik 的 STUN 端口:UDP 代理会+[改变 STUN 所观察到的源地址映射](../research/nat-traversal.md#external-forwarding-and-participant-relays)。+重启 Piik,从另一网络验证 HTTPS 健康检查、房间访问及**服务器转发**。++### 使用托管 frp 服务++SakuraFrp 等服务会提供公网服务器和自己的客户端或启动器;按服务商教程配置,+不必套用上面的自建 frps 令牌配置。先确认所选节点同时支持带 WebSocket 的 HTTPS 网页访问和普通 UDP 隧道。++| 端点 | 本地目标 | Piik 设置 |+| --- | --- | --- |+| 网页 | `127.0.0.1:8787`,由自己的代理或服务商提供 HTTPS | 将 `PUBLIC_BASE_URL` 设为实际公网 HTTPS 地址,包含所需端口。 |+| 媒体 | `127.0.0.1:<分配的 UDP 端口>` | 将 `SFU_UDP_PORT` 设为相同的本地/公网端口,`SFU_PUBLIC_IP` 设为 UDP 节点的公网 IPv4。 |++例如,服务商分配 UDP `30000` 时,将隧道的本地、公网端口和 Piik 的 `SFU_UDP_PORT` 都设为 `30000`;+网页本地端口仍可使用 `8787`。STUN 仍按上文保持直接可达。+只穿透网页可以承载信令,但不会为严格 NAT 增加 SFU 媒体路线。++可参考 SakuraFrp 的[网页配置](https://doc.natfrp.com/app/http.html)和+[UDP 连通说明](https://doc.natfrp.com/faq/network.html)。节点功能、访问要求与带宽以服务商为准;+Piik 尚未完成该托管服务的实际连通与性能验收。+## 长期运行与更新-需要开机启动时,参阅 [systemd 与容器配置](./service-management.zh-CN.md)。+Linux 开机启动可参考 [systemd 与容器配置](./service-management.zh-CN.md)。+Windows 可使用已有的服务管理工具或任务计划程序;Piik 不会安装 Windows 服务。更新时保留 `.env` 和 `rooms.sqlite`:停止服务、备份房间数据、替换新版程序,再启动并检查健康状态和房间访问。涉及数据格式变化的版本,请先阅读发布说明。diff --git a/docs/operations/website.md b/docs/operations/website.mdindex 5f196e1e..f6027d44 100644--- a/docs/operations/website.md+++ b/docs/operations/website.md@@ -108,7 +108,7 @@ bundles. Their HTML references come from the same build, including importeddependencies; fixed filenames must not mix a new page with cached old controlsor styles. Publish the complete output together.-Favicons share the [App artwork and exports](../../cmd/piik-app/README.md#desktop-icons).+Favicons share the [App artwork and exports](../../cmd/piik-app/DEVELOPMENT.md#desktop-icons).The website build copies the public SVG/PNG/ICO assets for the homepage, filmand documentation, keeping their URLs stable.@@ -161,7 +161,7 @@ native latest-attachment route:Both links follow provider publication without a website rebuild. Supported Apparchitecture choices stay visible; one selection updates both providers' links.An optional GitHub metadata request supplies the latest version/date and its-authored editorial headline;+authored editorial title and one-line explanation;failure does not disable architecture selection. Without JavaScript, the defaultlinks remain Windows x64, Apple silicon and Linux x64. Publish a newly listed Apppackage before deploying its website option. ARM64 Server packages alone do notdiff --git a/docs/project-memory.md b/docs/project-memory.mdindex 4d8656f9..c1d58c79 100644--- a/docs/project-memory.md+++ b/docs/project-memory.md@@ -1,6 +1,6 @@# Project Memory-Last updated: 2026-10-19+Last updated: 2026-10-21Piik is private, low-latency screen sharing for one Host and up to 20authenticated friends. The current product surface is Web Host, Web Viewer, and@@ -36,8 +36,8 @@ unsupported APIs and failed pooling retain ordinary senders. Windows, macOS andLinux producers share one encoded-frameboundary and Host quality controls. Source replacement retains route andconnection identity; lower-output adaptation preserves the original and higher-sibling outputs. [Status](./status.md) owns the remaining physical and release-acceptance boundary; runtime release descriptors own deployed identity.+sibling outputs. [Status](./status.md) owns candidate and release readiness;+runtime release descriptors own deployed identity.The Local launcher keeps an optional user-chosen site-access password; leaving itblank keeps the self-contained site open.@@ -76,9 +76,11 @@ implementation and routine UI detail.publication; Piik configures no TURN or TCP media route. Hosted operators mayrequire SFU-only media through the same controller. On P2P-first sites, apre-share peer-only policy can exclude that SFU suffix for one share generation.-- Every endpoint shares one steady outbound-copy cap, default `2` and limited to- `1..3`. One room controller owns one committed graph, one reconcile loop, and- one serial child operation. First decoded frame commits availability work;+- Ordinary endpoints share one steady outbound-copy cap, default `2` and limited to+ `1..3`; the candidate's explicit relay volunteer uses the+ [capacity owner](./standards/routing-transport.md#endpoint-and-server-capacity).+ One room controller owns one committed graph, one reconcile loop, and+ one serial child operation. First decoded frame commits picture availability work;accepted quality work adds native edge proof before commit in that operation.- Browser WebRTC and the shared Pion/LiveKit media adapter own congestion control,media adaptation, pacing and layer selection. Parent demand is local to direct@@ -102,6 +104,13 @@ implementation and routine UI detail.## Current Snapshot+Room voice integrates normal App/Server/Web rather than a+standalone demo. It keeps room authority and one route controller while picture+generations and explicitly joined voice publications have separate+lifetimes. [Status](./status.md#current-work)+indexes delivery and [room media](./standards/routing-transport.md#room-media)+owns the new behavior.+Optional attended keyboard/mouse control follows the committed media route backto the native Host. One source-scoped grant admits one controller; source change,stop and revocation retire it. It adds no separate connection planner or listener.@@ -116,8 +125,9 @@ room authority and the H.264/VP8 sender gate remain. [Status](./status.md)indexes source and deployment evidence; protocol rollback requiresmatching Browser and App artifacts, not only an application symlink.-Current work is owned by the [TODO ledger](./todo.md). Open physical evidence is-owned by [verification status](./verification-status.md). Environment and initial+Unfinished work is owned by the [TODO ledger](./todo.md).+[Verification status](./verification-status.md) summarizes material evidence+boundaries. Environment and initialservices are owned by [configuration](./standards/configuration.md) and[self-hosting](./operations/self-hosting.md); application release is owned by[deployment](./deployment.md), with exact deployed identity retained in thediff --git a/docs/research/camera-and-microphone.md b/docs/research/camera-and-microphone.mdindex b6d6eca6..0bd8c5b2 100644--- a/docs/research/camera-and-microphone.md+++ b/docs/research/camera-and-microphone.md@@ -1,7 +1,7 @@# Camera And Host MicrophoneStatus: integrated into the ordinary Host UI and accepted for release.-Remaining device coverage belongs to [TODO](../todo.md#awaiting-device-or-reporter-evidence).+Platform evidence is summarized in [verification status](../verification-status.md#device-evidence-boundary).## Scope And Ownershipdiff --git a/docs/research/nat-traversal.md b/docs/research/nat-traversal.mdindex cae6f120..9ca97f84 100644--- a/docs/research/nat-traversal.md+++ b/docs/research/nat-traversal.md@@ -456,7 +456,19 @@ directly and frpc's backend socket through frp, confirming the STUN limitationabove. These loopback controls do not establish Browser decoding, audible audio,public-network performance, loss recovery or QUIC behavior.+The October 20 review also checked frp's [VirtualNet example](https://gofrp.org/en/docs/examples/virtualnet/).+It describes a TUN-based private network between clients and visitors, which is+closer to the virtual-LAN approach than fixed-port forwarding. The official guide+still marks it Alpha and unsuitable for production. It requires frp setup on+participating endpoints as well as a reachable frps service; it is not part of+Piik's tested forwarding recipe or a default campus-network recommendation.+A well-connected participant already can help through the existing Viewer relay.+The normal integration candidate now exposes an explicit voluntary fanout+override through that controller, bounded by actual endpoint capability and+the room's 20-Viewer limit. This is not a new SFU worker or a guarantee that the+participant is reachable. Browser room-voice checks cover a real three-person+relay and local-mute isolation; external networks remain the next evidence step.Browser relays reuse WebRTC senders; Native relays can forward suitable encodedmedia. Any voluntary capacity control should feed the existing room controller,with its endpoint cap and current-edge retirement. Bandwidth alone does not prove@@ -687,8 +699,8 @@ control. No new automatic renomination, probing loop or retry budget is enabled.Keep Piik's fresh-interface mux and connection-owned STUN/mapping repairs: thenewer framework still snapshots its default interface view and caches successfuluniversal-mux observations. An upstream release-note match is not sufficient to-remove these protections. Physical network/device coverage remains in-[verification status](../verification-status.md#remaining-device-and-network-acceptance).+remove these protections. [Verification status](../verification-status.md#interpretation)+summarizes how local evidence applies to device and network claims.#### Pion Renomination Preflight@@ -1041,6 +1053,41 @@ physical connection instead of per Engine. Existing connection/copy limits boundtheir number. This changes no public wire format, fixed service port or routepolicy, and is not evidence that any unmatched field report has been resolved.+## Routed Virtual LAN Discovery++A two-Windows-device UU virtual-LAN trial on 2026-10-20 established HTTP,+WebSocket and decoded video transport. Ordinary LAN ICE stalled with the remote+Browser's `.local` candidates. A test-only substitution with that verified+peer's virtual IP restored picture; removing it and restarting the share+reproduced the stall. This isolates address discovery rather than proving that+the virtual LAN blocks media UDP.++The subsequent control removed candidate substitution and supplied a local+STUN endpoint through the temporary signaling fixture. The Browser then+advertised a server-reflexive candidate on the virtual address; the Native+sender selected it and the remote Viewer decoded 1920×1080 at about 20 fps,+with roughly 32 ms RTT and no loss in the sampled windows. This follows the+[mDNS candidate guidance](https://rtcweb-wg.github.io/mdns-ice-candidates/draft-ietf-mmusic-mdns-ice-candidates.html),+which retains numeric reflexive candidates even when host candidates are hidden.+[mDNS itself is local-link discovery](https://www.rfc-editor.org/rfc/rfc6762).++Pure LAN configuration therefore reuses the existing Binding-only STUN service+on its selected address and App UDP port. Public-link discovery, NAT prediction,+media routing and authorization retain their owners. The test's temporary HTTP+proxy used an already firewall-permitted executable; that initial control alone+did not establish direct packaged-App reachability.++A same-day follow-up used the packaged App's ordinary Local invitation directly.+The remote Browser initially timed out before reaching Piik. The host listened+on the selected virtual address, but Windows classified the adapter as Public,+blocked inbound traffic by default and had no rule for the new executable path;+new-app notifications were disabled. With the owner's approval, inbound rules+were limited to that App, virtual adapter and subnet: TCP on the web port and+UDP for discovery/media. The remote TCP connection then reached the App process,+and the owner confirmed both page and picture worked. No proxy, candidate+substitution or Browser privacy change was used. This closes the direct+App-to-Browser trial without claiming universal campus-network compatibility.+## Primary Sources- [RFC 8445: Interactive Connectivity Establishment](https://datatracker.ietf.org/doc/html/rfc8445)diff --git a/docs/research/native-client-media.md b/docs/research/native-client-media.mdindex 1421077b..1223b93e 100644--- a/docs/research/native-client-media.md+++ b/docs/research/native-client-media.md@@ -135,32 +135,37 @@ and the [upstream audio-capture lifecycle](https://github.com/obsproject/obs-stuExisting Go pipe fixtures now cover ready-but-silent audio, audio that neverbecomes ready, video startup in both cases and cancellation of blocked readers.Both controls pass without changing Go startup deadlines or adding retries.-They do not reproduce the report's additional video timeout. Its display-audio-attempt and window-filter crash refer to different processes; they do not-establish one failure or an App bundle-identity collision. The native audio-self-test is part of the Mac capture check. Both Darwin architectures compiled-and passed that self-test in candidate CI on 2026-10-19; actual source/microphone-capture and permissions remain unverified on this Windows workstation.--The remaining video timeout needs a separate Mac reproduction. Darwin emits-`StartingStatus` after `SCShareableContent` enumeration and filter construction,-before creating or starting its video stream. Native Host currently starts both-helpers before reading video status, so their initial enumerations can overlap.-An [Apple Developer Forums report](https://developer.apple.com/forums/thread/772365)-reproduces an unresponsive `replayd` and similar 4097 errors using repeated-concurrent enumeration from multiple processes, without capturing media-(FB16310901). This is a candidate mechanism, not an established cause of #486;-Apple has not confirmed its cause or a fix.--The smallest Mac comparison uses the existing `piik-capture --list`: run one-helper, then two concurrently, under the same parent with bounded attempts.-Discard source metadata and retain only timing and errors. Separately compare-current startup with waiting for the video's existing `StartingStatus` before-starting audio. Keep deadlines, bundle identity and permissions unchanged in-these comparisons. Terminal versus App launch is a separate variable:-[Apple DTS describes TCC's responsible-process attribution](https://developer.apple.com/forums/thread/125438),-so a successful manual helper does not establish identical permission context.-No same-parent comparison or startup-order fix has yet been verified on a Mac.+The native audio self-test is part of the Mac capture check; both Darwin+architectures compiled and passed it in candidate CI on 2026-10-19.++The 2026-10-20 pipe reproduction establishes a second startup defect: waiting+for audio readiness before reading video can fill the video pipe and block a+capture service that audio initialization also needs. The session now waits for+video readiness while draining video, then initializes optional source audio.+The full-pipe/silent/no-ready controls and native Host lifecycle tests pass+without longer deadlines. This also removes the overlapping initial source+enumeration described in an [Apple Developer Forums report](https://developer.apple.com/forums/thread/772365)+(FB16310901); that report does not establish the cause of every #486 timeout.++The window-audio filter now selects the owning application on a display, matching+its process-audio responsibility, rather than constructing a video-window filter.+The helper initializes CoreGraphics through its public display API before asking+ScreenCaptureKit for content. This addresses the initialization dependency shown+by the reported SkyLight filter crash and the [primary implementation](https://github.com/indutny/mac-screen-share/blob/main/addon.mm).+These Darwin changes passed Mac SDK compilation and packaged startup on both+architectures in candidate CI on 2026-10-20. Physical source/audio capture remains+unverified here.+Terminal launch and App launch remain distinct permission contexts under+[Apple's TCC attribution](https://developer.apple.com/forums/thread/125438).++The subsequent Mac report also identified an App-side geometry mismatch:+ScreenCaptureKit correctly reports the source's fitted size, but startup required+exact equality with the selected ceiling. The shared status decoder now admits+legal even dimensions within the original output ceiling, while retaining the+codec, frame-rate and output-plan checks. Preparation uses that same validation.+The process fixture reproduces the previous rejection of a 640x480 source under+a 1280x720 ceiling and passes with the correction; this does not substitute for+physical Mac capture.## Current Boundary@@ -202,7 +207,7 @@ less initialization and a valid handoff, not a material speedup or a repair foran uninterruptible driver call. Concurrent cadence benchmarks are not adopted:shared-device contention would change the capability being measured.-The current v2.2.1 report in [#437](https://github.com/TNTcraftHIM/Piik/issues/437)+The earlier v2.2.1 report in [#437](https://github.com/TNTcraftHIM/Piik/issues/437)records device loss after about 3.25 seconds, before the Auto selection finishes.The selector could then enter another candidate despite lacking time for itsrequired cadence measurement. Admission now uses that same measurement schedule@@ -211,6 +216,26 @@ remaining-budget control rejects Auto at 30 fps but retains manual H264 and theimmediate 1 fps probe. This fixes budget admission, not the physical`DEVICE_HUNG`; the later blocked API and reporter-device outcome remain unknown.+The [October 20 follow-up](https://github.com/TNTcraftHIM/Piik/issues/437#issuecomment-6284470067)+contains v2.2.2 App evidence: all six Auto attempts report device loss during+probe texture creation, with removal reason `DEVICE_HUNG`, then select VP8.+Four reach active capture; two later hit local-edge preparation deadlines.+The reporter's separate manual-H264 success is not in this trace. The failing+API locates detection, not necessarily the GPU operation that caused the hang.++The local candidate now prepares synthetic BGRA through the existing capture+converter, supplying the same GPU-produced NV12 surface contract as live capture.+It retains eight distinct frames outside the cadence measurement, and keeps+deadlines, genuine failures, fallback and the proven encoder instance unchanged.+[Microsoft permits initialized textures](https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11device-createtexture2d);+this is not a claim that every direct NV12 allocation is invalid.+[Chromium's MF input handling](https://chromium.googlesource.com/chromium/src/+/main/media/gpu/windows/media_foundation_video_encode_accelerator_win.cc)+also distinguishes initialized CPU uploads from video-processor output and+preserves consistent encoder inputs. Local NVIDIA/AMD conversion checks and+retained-frame checks pass. Single Auto controls selected H264 in 1.7–1.8 seconds,+with explicit H264 around 0.2 seconds; these are neither a benchmark nor a+reproduction of the reporter's driver hang. The affected-device retest remains open.+The `input-texture-create / 0x887a0005` report identifies a lost D3D device duringcandidate preparation, not a failed room route or proof that every candidatefailed. Following Microsoft's [device-loss guidance](https://learn.microsoft.com/en-us/windows/uwp/gaming/handling-device-lost-scenarios),@@ -872,6 +897,16 @@ This uses GStreamer 1.28.3 and libportal 0.9.1 on an isolated Alpine runner;its probe correctly reports no capture without a desktop session. ActualPortal capture and platform packaging remain separate checks.+The square-pixel correction from [#488](https://github.com/TNTcraftHIM/Piik/pull/488)+constrains the raw desktop source before downstream scaling. This follows+[GStreamer negotiation](https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/negotiation.html):+the source selects from downstream caps, so an output-only constraint can leave+PipeWire choosing an extreme pixel aspect ratio. The headless regression checks+source fixation and real 3840x2160 to 1920x1080 conversion. The contributor reports+restored KDE Wayland capture on AMD hardware; that is separate from our build+checks and does not establish all desktop/driver combinations. Encoded-input+transcoding keeps its existing path and source-aspect handling.+A uniform-noise 4K1/50 Mbps stress input reached the retained 4 MiB access-unitguard in both Native codecs; VP8 produced a 6,199,837-byte frame. The output wasrejected rather than expanding allocation limits. Large bitrate/low-cadencediff --git a/docs/research/network-lab.md b/docs/research/network-lab.mdindex 8fdeb7ff..dc98852e 100644--- a/docs/research/network-lab.md+++ b/docs/research/network-lab.md@@ -75,6 +75,14 @@ Chrome and a Linux App with Browser-generated H264 ingress; it does not exercisephysical capture, other Browser engines, real gateway mapping or the publicinvitation provider.+The `voice-browser-browser`, `voice-browser-app`, `voice-app-browser` and+`voice-app-app` cases additionally open room voice through the normal UI and+require progressing received audio in both directions. `voice-sfu-fallback`+blocks direct media, and `voice-media-outage` interrupts then restores UDP while+picture and voice are active. These cases use Browser microphone capture even+when picture media uses the App. They reuse the existing routers and cleanup;+their execution evidence is separate from the previously completed picture matrix.+Actual packets/counters must corroborate each impairment. DevTools accepting anetwork-emulation request is insufficient: an earlier Piik check observed RTPoutside the requested limits. Keep negative controls, finite deadlines anddiff --git a/docs/research/node-local-media-design.md b/docs/research/node-local-media-design.mdindex c5684875..3133ef9b 100644--- a/docs/research/node-local-media-design.md+++ b/docs/research/node-local-media-design.md@@ -589,6 +589,21 @@ Desired maximum, available layers and current forwarding target remain distinct;Dynacast is not proof that stopping every currently unselected high layer aloneprovides recovery.+On 2026-10-20, a matched v2.2.2 report supplied a separate reproducible failure:+receive-clock rate skew accumulates through inherited queue delay, even though+packet history is bounded. An independent Pion TWCC replay with no loss or real+queue growth entered congestion after about 752 seconds at +67 ppm and still+blocked probing after 30 minutes. The field trace's roughly 67 ppm slope is+consistent with this mechanism, but the archive does not directly measure the+devices' clock rates or contain full packet feedback for replay.+The candidate applies [RFC 6817 A.2's virtual faster sender clock](https://www.rfc-editor.org/rfc/rfc6817.html#appendix-A.2)+only to queue-delay inference, with its documented 500 ppm allowance. Raw rates,+timestamps, loss, allocator policy and probe ownership are unchanged. Thirty-minute+controls at 0, +67/-67, +200/-200 and +400 ppm no longer enter false congestion;+actual growing queues and loss still lower capacity and release probing after+they clear. This repairs the shared Native/SFU estimator, not Browser-owned GCC,+and does not assign every historical low-quality report the same cause.+For dormant output admission, the parent can prepare a layer when a child'sfresh framework video budget covers that layer's existing configured ceiling.The active prefix includes this preparation demand, the library target and thediff --git a/docs/research/room-interactions.md b/docs/research/room-interactions.mdindex 16c99280..aa5a426b 100644--- a/docs/research/room-interactions.md+++ b/docs/research/room-interactions.md@@ -13,7 +13,8 @@ owns room/publication lifetime.| Concern | Owner | Lifetime || --- | --- | --- || Identity, room membership and access | Existing room store and authenticated signaling session | Current admitted participant |-| Screen/camera plus Host commentary | Existing capture and media owners | Current share and source |+| Screen/camera and source sound | Existing capture and media owners | Current share and source |+| Room microphone and listening | `RoomVoiceSession`, Browser input and room-route adapters | Explicit voice membership, independent of picture sharing || Text and reactions | `signal/interactions.go`, shared protocol and `RoomInteractionSession` | Current authenticated room session; bounded page-local presentation || Chat panel, optional chat overlay and reaction placement | Shared `RoomInteractions` and `RoomChatOverlay`; `RoomInteractionSession` owns bounded events | Current room UI |@@ -119,7 +120,7 @@ confirmation without locking draft editing or introducing a message queue.The conversation entry shares the couch footer with its participant count,separate from the Host's sharing controls. Theater hides the seating and count,retaining the same compact conversation entry and focus target.-Selecting a person opens the compact reaction palette in the shared floating+Selecting a person on the couch opens the reaction palette in the shared floatingshell, initially beside the selected person (below when space permits). Eachopening anchors there before allowing free movement. Its portrait and name identify thetarget even after moving the window. Selecting a different participant keeps its@@ -128,20 +129,24 @@ The default palette height follows its content, bounded by the visible viewport.One's own palette expresses a reaction above oneself and holds the local effects switch; otherpeople's palettes offer targeted expressions and two throwing props. The props forma compact pair of named action buttons beneath the expression grid, using the-shared button motion. The same palette serves both the couch and conversation.+shared button motion.Connection details remain secondary when that participant has inspectable data.Close or Escape dismisses the palette; it also closes if its participant leaves.Sending keeps it open for repeated interaction, with the existing short cooldown.Confirmation never changes menu visibility; failure stays visible in the card.Opening or closing a reaction card preserves the chat draft and unread state.-The interaction window keeps one composer with an on-demand reaction tray.-Its recipient strip uses the same room identities and the couch's shared palette.-The tray shortens the scrollable message list rather than covering messages;-the input and reading position stay in place. Its composer button or a current-participant's message avatar opens it and focuses the selected person; Escape-returns to that opener. Avatars of departed participants remain non-interactive.-Typing or pressing Escape dismisses the tray; sending a reaction keeps it open.-While it is closed, the newest live reaction briefly shows its sender and recipient+The interaction window uses a compact attached palette beside the chosen chat+or voice avatar, without replacing or compressing the list and composer. Its+quick actions are thumbs up/down and the two throwing props; one's own entry+substitutes laugh and heart. More reactions exposes the full curated palette,+with a labelled back arrow in its heading. The native+popover and shared anchored placement own dismissal, focus and viewport fit.+Clicking the input dismisses it and continues typing; sending keeps it open.+Changing pages or moving the tool between documents dismisses this brief menu+without changing the session, draft or reading position. Avatars of departed+participants remain non-interactive. Both menus use the same target heading,+reaction buttons and send owner.+The newest live reaction briefly shows its sender and recipientwith the same animation renderer.It adds neither a message history entry nor an independent expiry timer. Membercontrols and reactions open on demand within the small companion window. Only@@ -253,6 +258,32 @@ peers. Room voice is an isolated prototype, not a published capability.### Room Voice Transport Assessment+Integration update, 2026-10-20: the normal App/Server/Web candidate now uses one+room controller for voice and picture, with companion Browser audio connections+on its selected edges and an embedded Opus SFU adapter on the existing UDP mux.+The earlier experiments below remain design evidence, not the distributable+implementation. Room voice now opens when the Host joins and closes when the+Host leaves. Room admission replaces per-person voice permissions. All current+microphone controls use room voice; pausing local listening leaves the microphone+on. Source sound stays with the picture. This follows the independent media+source model in [LiveKit](https://docs.livekit.io/intro/basics/rooms-participants-tracks/)+and the [RTP synchronization boundary](https://www.rfc-editor.org/rfc/rfc8834.html#section-12.2.3):+sharing a route does not guarantee synchronized playback across independent+voice and picture connections. Conversation prioritizes timely delivery.+Normal UI checks exercise pre-share room creation, channel activation,+duplex capture, a three-participant Peer relay, local mute without interrupting+forwarding, picture start/stop/restart, detach and authority retirement on P2P+and forced-SFU arms. The existing network laboratory also exercises voice across+Browser/App endpoint combinations, blocked direct paths and UDP interruption.+These synthetic-device checks do not establish microphone echo behavior, public+NAT success rates or 21-person all-speaking audio capacity.+`PIIK_ROOM_VOICE_LEGACY_WEB` optionally points the same normal-page gate at an+older checkout and records its revision, checking that an older Viewer retains+picture playback without subscribing to voice events.+Product owners are [room voice](../standards/rooms-access.md#room-voice) and+[room media](../standards/routing-transport.md#room-media); the public release+does not yet include this candidate.+Reviewed 2026-10-19. The owner requested optional self-hosted voice and assessmentof App-hosted voice. The local prototype forwards independent Opus publications,uses existing room identities, and enforces Host admission and speaking grants.@@ -485,8 +516,10 @@ and the platform [AES-GCM API](https://developer.mozilla.org/en-US/docs/Web/API/sessions share the same physical keyboard and pointer. Remote control startsoff. The Browser remembers the last successfully applied authorization mode;the Host must still enable it manually for each new shared source. Ask each time-is the default. A remembered password mode asks for a new password before-applying; the password itself is never remembered. Automatic modes accept only+is the default. Remembered Room Viewers mode opens the existing permission form+and needs an explicit allow action before becoming active for the new audience.+A remembered password mode asks for a new password before applying; the password+itself is never remembered. Automatic modes accept onlyauthenticated room Viewers and never displace an active controller. Permissionbelongs to the current shared source; changing sources or stopping turns it off.Turning it off also clears pending requests and releases held input, including@@ -518,8 +551,22 @@ the recovered path carries a fresh request. App playback and relay descendantsfollow the same rule; interruption releases the upstream grant.A closed control channel needs a new mediaconnection; neither path silently restores a grant. Either side can end control-from its page. Windows also supplies a local Ctrl+Alt+F10 stop shortcut; macOS-uses Control+Option+F10. Linux retains the desktop's sharing controls instead+from its page. Windows also supplies a local Ctrl+Alt+F10 stop shortcut by default;+macOS uses Control+Option+F10. The Host can change the function key in the control+panel; the current Site's Browser storage owns this preference and reapplies it+before enabling control. App keeps only the running binding, with no shortcut+configuration file. Configuration probes availability;+registration lasts only while at least one native session enables control,+never merely because App is running. An occupied key fails that operation+without disabling capture or the input backend. Replacing+the shortcut retains the old binding until registration succeeds; only a+successful change is saved in the Browser. Each Site has its own preference.+Viewers independently choose their page-local exit shortcut in the remote+keyboard; it also works in a detached keyboard window and saves in that Browser.+Both selectors offer F1–F11 with fixed Ctrl+Alt/Option modifiers;+[Windows reserves F12](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey#remarks).+The optional App discovery capability gates the new commands, preserving the+published permission and input-state messages. Linux retains the desktop's sharing controls insteadof registering a second global key grab. A Host stop (including that local shortcut) also resets automaticpermission to Ask each time. A Viewer ending their own control leaves the Host'spolicy in place. This adds no service, automatic sharing or control across Appdiff --git a/docs/standards/configuration.md b/docs/standards/configuration.mdindex 753af3fd..3f78aed4 100644--- a/docs/standards/configuration.md+++ b/docs/standards/configuration.md@@ -25,13 +25,15 @@ service secret store or an untracked access-restricted environment file.| `PORT` | Positive TCP port, default `8787`; the tracked release wrapper supports only that default. || `PUBLIC_BASE_URL` | Exact public HTTP(S) origin; production requires HTTPS. || `ALLOWED_ORIGINS` | Unset or empty follows `PUBLIC_BASE_URL`. A non-empty comma-separated list replaces that default; include every trusted browser origin (scheme, host and port). Wildcard is invalid. |+| `TLS_SELF_SIGNED` | Optional direct HTTPS, default `false`. `true` generates an in-memory certificate for the exact `PUBLIC_BASE_URL` host; it changes on restart and requires browser confirmation. Requires an HTTPS public origin; cannot combine with certificate files. |+| `TLS_CERT_FILE` / `TLS_KEY_FILE` | Optional PEM certificate chain and private key, configured together. Direct HTTPS uses the existing `LISTEN_HOST`/`PORT`. Startup and `--check-config` validate the pair, host and validity dates. Files are read at startup; renewal and restart remain the operator's responsibility. || `SITE_ACCESS_PASSWORD` | Optional in every environment. Unset or empty allows entry without a site password. A configured value is matched exactly, including spaces and Unicode; there are no password length or character rules. General HTTP request limits still apply. Room ownership and Viewer admission remain independent. || `ROOM_DATABASE_PATH` | Hosted defaults to `rooms.sqlite` in its working directory when unset or blank. An explicit absolute file path selects another SQLite file; `:memory:` opts into process-memory room authority. App Local remains in memory. || `ROOM_EMPTY_TIMEOUT_SECONDS` | Integer `0..31536000`, default `0` (disabled). Positive values enable empty-room expiry and oldest-empty reclamation under allocation pressure. Apply at Server startup; App Local retains its process-only lifecycle. || `MAX_VIEWERS_PER_ROOM` | `1..20`, default `20`; excludes the Host. || `ENDPOINT_MEDIA_COPY_CAPACITY` | Shared endpoint steady-copy cap `1..3`, default `2`. || `STUN_URLS` | Comma-separated advertised `stun:` discovery URLs; at least one is required in production. These are not local bind addresses and may use an unproxied DNS name separate from the Web origin. |-| `STUN_LISTEN_HOST` | Hosted IPv4 STUN bind address, default `0.0.0.0` when `STUN_URLS` is configured; independent of HTTP `LISTEN_HOST`. Local App construction creates no STUN listeners. |+| `STUN_LISTEN_HOST` | Hosted IPv4 STUN bind address, default `0.0.0.0` when `STUN_URLS` is configured; independent of HTTP `LISTEN_HOST`. App Local configuration owns its separate LAN endpoint below. || `NAT_PREDICTION_ENABLED` | Optional bounded NAT prediction capability, default `false`; requires an ordinary `STUN_URLS` endpoint on UDP 3478. Hosted startup binds UDP 3479/3480 before advertising the capability. Current pages use it automatically on P2P-first sites; ordinary ICE remains available without it. Firewall reachability remains an operator requirement. |### Room capacity@@ -119,6 +121,19 @@ one or two use ordinary ICE only. Empty or unset retains the defaults. LocalLAN mode ignores this setting, and an approved Site supplies its own ICEconfiguration. No settings panel or additional media transport is involved.+LAN mode retains the Host's HTTP loopback entry and serves HTTPS on the selected+LAN IPv4 address at the same TCP port. Both listeners share one HTTP server,+room authority and shutdown owner. Its self-signed certificate and private key+live only in memory for that run; the App terminal displays the SHA-256+fingerprint for manual confirmation. No CA is installed and no TLS files are saved.+The selected LAN address also runs the existing Binding-only STUN service on+the App's numeric UDP port (default `8787`). This lets Browsers+discover usable addresses on routed virtual LANs without relying on multicast+name discovery or contacting a public STUN service. HTTP and STUN have one+application startup/shutdown owner; public-link mode does not bind this LAN+endpoint. Allow Piik through the firewall on the selected network for both TCP+and UDP; STUN carries address discovery, not shared media.+For example, in PowerShell, set `$env:PIIK_STUN_URLS = 'stun:your-stun.example:3478'`before running `./piik-app.exe`. Use a service you trust: STUN sees participants'public network addresses, but does not receive shared media.@@ -148,8 +163,8 @@ For Local mode, the launcher selects a sole active address or sole private IPv4address automatically. With several choices it shows interface names and IPs;an ambiguous choice must be selected before launch. `--lan-address` preselectsan active address. Selection applies to this launch and is revalidated at startup.-It sets the local invitation origin; HTTP still listens on the existing wildcard-listener and ICE remains free to use available media interfaces. Public Link+It sets the local HTTPS listener and invitation origin; the Host keeps its+HTTP loopback entry and ICE remains free to use available media interfaces. Public Linkand use through an approved Site require no local address selection.Command-line options select entry and local runtime behavior:@@ -159,7 +174,7 @@ Command-line options select entry and local runtime behavior:| `--site <origin>` / `--local` | Save and use a Site, or select the self-contained Local mode. Mutually exclusive. || `--link` | Create a public Viewer invitation for Local mode. || `--config <path>` | Select another App configuration file. |-| `--lan-address <IPv4>` / `--port <port>` | Override the Local invitation address or HTTP port (default `8787`). |+| `--lan-address <IPv4>` / `--port <port>` | Override the Local invitation address or web port (default `8787`). || `--capture-process <path>` / `--tunnel-process <path>` | Override packaged native capture or public tunnel helpers. Ordinary installations use the packaged paths. || `--debug` / `--log-dir <path>` | Enable diagnostics or choose their destination as described below. |@@ -286,7 +301,7 @@ project references and the reasons for this collection boundary.| UDP 3478 | public | in-process STUN-only Piik listener || UDP 3479/3480 | public when NAT prediction is enabled | in-process auxiliary STUN-only Piik listeners || UDP 7882 (or `SFU_UDP_PORT`) | public when SFU enabled | in-process Piik WebRTC media |-| TCP 8787 | private | Piik application |+| TCP 8787 | private behind a proxy, or reachable within the chosen LAN for direct HTTPS | Piik application |TCP 3478, TCP/TLS 5349, TURN relay ranges, media TCP, and other mediaports remain closed. HTTPS/WSS transport is independent of the UDP-only media@@ -308,8 +323,9 @@ test requires a second public IPv4.## Bounds-- Site-access requests are rate-limited at the reverse proxy and use constant-- time secret comparison in the application.+- Site access uses constant-time secret comparison in the application. Reverse-+ proxy deployments also configure request rate limits there; direct HTTPS does+ not add a proxy rate limiter.- HTTP body, WebSocket payload, total/unauthed connections, room count, Viewercount, output buffers, endpoint copies, and SFU resources are bounded.- The four-digit code space fixes the maximum managed Host publications atdiff --git a/docs/standards/documentation.md b/docs/standards/documentation.mdindex a0672814..b1ce7b80 100644--- a/docs/standards/documentation.md+++ b/docs/standards/documentation.md@@ -26,7 +26,7 @@ verification procedures stay in [CONTRIBUTING.md](../../CONTRIBUTING.md).| Compact product map | `docs/project-memory.md` | Stable summaries and domain navigation, not implementation inventories || Current execution/deployment index | `docs/status.md` | Current boundaries and pointers; exact artifact identity stays in release metadata || Remaining work and decisions | `docs/todo.md` | One task ledger, with executable work separated from parked ideas |-| Unresolved physical acceptance | `docs/verification-status.md` | Still-relevant evidence gaps across modules |+| Evidence boundaries | `docs/verification-status.md` | Compact limits that affect product claims; no duplicate retest ledger || Completed history | Git commits and PRs | Changes and outcomes; do not reproduce them in memory or TODO |Source schemas and existing conformance fixtures own exact interface fields;@@ -36,6 +36,11 @@ use the product; technical details link to the relevant owner. English/Chineseentry guides are intentional translations and must change together; technicalreferences keep one version.+First-use guides stop at a working room. Detailed controls belong to task guides,+symptom-based checks to troubleshooting, and build/release procedures to maintainer+references. Remove repaired incident narratives instead of appending them to the+reader's path; retain checks for current platform and network limitations.+The public documentation website renders selected repository Markdown withoutowning another copy. Its [reader index](../guide/README.md) serves usage and support;the repository map remains the developer/maintainer entry. The@@ -64,6 +69,9 @@ checklists as product truth.After an audit, put accepted constraints in their existing owners and unresolvedwork in TODO, then remove the report and handoff bundle. Do not create datedaudit-summary directories or replacement archives of completed work.+Remove repaired, sufficiently verified work from TODO and compact snapshots.+An unmatched historical report alone does not create a permanent retest task;+keep its discussion in the issue and reopen work when new evidence warrants it.Published copy describes Piik's behavior and design directly. Remove discardeddesign labels, private operational details and conversational comparisons todiff --git a/docs/standards/media-quality.md b/docs/standards/media-quality.mdindex 03de67b7..01ae1a98 100644--- a/docs/standards/media-quality.md+++ b/docs/standards/media-quality.md@@ -11,6 +11,19 @@ contract. [Status](../status.md) indexes delivery and remaining acceptance.## Capture And Controls+Room voice handles both Host and Viewer microphones, separate+from source sound. One Browser capture owner supplies device selection, input+gain and optional speech processing, including on App-backed pages. Settings+remain local to the Browser origin; joining and microphone activation are never+remembered. Stopping picture capture does not stop room voice. Source audio stays+with the picture; room voice prioritizes interactive latency and is not promised+to remain synchronized with a delayed picture.+Microphone gain, master voice listening volume and each person's local volume+range from 0% to 200%, defaulting to 100%. Master and per-person listening gains+multiply. Per-person levels belong to the current participant identity and retire+with it. Listening gain, deafen and per-person mute affect only local playback,+never forwarding or the picture's source audio.+- The Web Host may share a display, application window, Browser tab or camera and maystop, synchronously pause/resume audio and video, or switch source.- An App-launched Host explicitly chooses either that Browser capture path or@@ -20,24 +33,16 @@ contract. [Status](../status.md) indexes delivery and remaining acceptance.- Camera is a peer source choice in the same picker, including on phones. Onlythe chosen source requests permission. Camera input and thumbnails requestan uncropped device format; sender constraints own later scaling.- Browser/camera Host microphone capture- is explicit and defaults to Browser voice processing, separately from screen audio.- The Host may turn that processing off for music or virtual audio inputs;- the input change preserves the existing mixed output and leaves the previous- input usable on failure. This requests Browser processing settings, not a- bypass of device/system effects. Native PCM capture uses device/system settings.- The mixer produces one audio output for the existing media routes. Muting or losing the- microphone must not stop healthy video. Share retirement releases its devices- and rejects late permission results. Native App capture mixes source and- microphone PCM before its existing Opus encoder, preserving one output track- through mute, pause and source replacement. A capable App/page pair opts into- this output at startup; source sound and microphone state remain independent- facts. Browser preview audio never becomes the native mixing source.-- Audio input availability belongs to the Host capture/mixer owner: a live source- audio input or an enabled, live Host microphone makes audio available. A retained- mixed output track alone does not. This describes input presence, not measured+ Camera capture does not implicitly open a microphone. Room voice owns speech+ independently. A microphone device/processing change keeps the previous input+ on failure and does not replace picture media. Browser processing preferences+ do not bypass device/system effects. Published Native control commands retain+ mixed source/commentary support for older Sites; the current UI uses room voice.+- Source-audio availability belongs to the Host capture owner. A live source+ input makes source audio available; a retained Native output track alone does+ not. This describes input presence, not measuredloudness; quiet content, share pause and Viewer-local mute remain separate facts.- Source replacement and microphone changes update this fact without rebuilding+ Source replacement and source-audio changes update this fact without rebuildingthe output or media route. An opted-in room session carries it for the currentpublication, including late joins and signaling reconnects.- An audio-only update with the same capture video preserves the Browser videodiff --git a/docs/standards/presentation-lifecycle.md b/docs/standards/presentation-lifecycle.mdindex e1aca925..a13c2d51 100644--- a/docs/standards/presentation-lifecycle.md+++ b/docs/standards/presentation-lifecycle.md@@ -26,8 +26,9 @@ desktop and mobile viewports.Personal room-tool presentation and incoming-route preferences are rememberedwithin the same Browser origin across rooms and reloads. Their existing domain-owners still apply capability and room-policy constraints. Restoring preferences-never restores room admission, control grants, actual held input, passwords or+owners still apply capability and room-policy constraints. Remote-control+shortcut choices follow this same boundary; App applies them only in memory.+Restoring preferences never restores room admission, control grants, actual held input, passwords ormessage drafts, and never starts capture or remote control.A capable, opted-in authenticated room session@@ -40,6 +41,14 @@ is absent, provided the room service and their admitted sessions remain availabl[Rooms and access](./rooms-access.md#room-interactions) owns interaction authorityand retention; [status](../status.md#accepted-interaction-phase) owns release readiness.+The Host can explicitly **Create room** before sharing.+Chat and voice use tabs in the existing interaction window, including its+detached presentation. Closing or changing that window does not leave voice or+stop capture. Microphone, admission and connection states stay literal; an+enabled microphone is not proof that someone is speaking. The+[room voice contract](./rooms-access.md#room-voice) owns channel activation and+membership, independently of the window and picture publication.+On capable desktop browsers, the interaction window can move to a DocumentPicture-in-Picture window. It retains the admitted room session's messages,reactions and draft. Read visibility and guidance follow its current document.@@ -166,7 +175,10 @@ Viewer playback settings reuse shared controls in an anchored popover;placement follows the [visual language](./visual-language.md) without resizing video. Local picturefit defaults to contain; cover preserves proportions and may crop edges, whilestretch fills the player by changing proportions. These choices do not change-capture or encoding. Remote input and magnification use the same rendered+capture or encoding. Manual quarter-turn rotation is another local picture+preference; it does not depend on device auto-rotation and applies to page+playback, including theater and DOM fullscreen. System video presentations+retain their browser-owned behavior. Remote input and magnification use the same renderedpicture geometry. Incoming-route choice follows the[routing contract](./routing-transport.md#viewer-route-choice); its selected valueis server-acknowledged intent, not evidence of the currently playing route.@@ -200,10 +212,10 @@ keyboard shortcut own that action. Desktop double-click toggles the availablefullscreen action. Remote-control input consumes its own clicks and key presses;controls and overlays keep their own immediate behavior.-Host source-audio feedback describes the selected source independently of Host-microphone commentary. Viewer sound controls require a received audio track and,+Host source-audio feedback describes the selected source independently of room+voice. Viewer picture-sound controls require a received audio track and,when the Host supplies input availability, an available source or microphone-input. With no input, sound controls are disabled with the no-audio explanation;+input (including published commentary from older Hosts). With no input, sound controls are disabled with the no-audio explanation;the Viewer's volume and mute preferences remain intact for audio returning.Older Hosts without this fact retain received-track feedback. These controls donot infer input presence from silence or change capture, transport or relay audio.@@ -324,6 +336,8 @@ at most 24 Unicode code points, and rejects unsafe control or bidirectionalcharacters. It is a label, not an account, authorization identity, or routinginput. Duplicate names are allowed and receive a room-scoped peer suffix onlywhen disambiguation is needed.+Chat applies the same labeling rule to recorded sender names; repeated messages+from one peer do not create another identity. Media readiness never owns identity.Connection details are progressive and use one card shape for P2P, peer relay,and SFU Viewers. Summary fields prioritize actual resolution, FPS, bitrate, anddiff --git a/docs/standards/public-introduction.md b/docs/standards/public-introduction.mdindex 40fbdd76..f356b9c3 100644--- a/docs/standards/public-introduction.md+++ b/docs/standards/public-introduction.md@@ -169,7 +169,7 @@ The [website operations guide](../operations/website.md) owns Pages publication,public destinations and the separate P2P-only demo. The primary action leadsto the platform download section. The website operations guide owns eachplatform's latest download routes and provider labels. The download entry may-show the current Release's [editorial headline](./versioning.md#release-notes),+show the current Release's [editorial title and factual explanation](./versioning.md#release-notes),read from the same metadata request as its version and date. Keep the fullrelease-note link and verify destinations as part of publication. Without thatmetadata, the ordinary download links remain usable.diff --git a/docs/standards/rooms-access.md b/docs/standards/rooms-access.mdindex 42500c5c..f4f4330a 100644--- a/docs/standards/rooms-access.md+++ b/docs/standards/rooms-access.md@@ -73,8 +73,8 @@ Three independent authorities exist:active. It authorizes room creation, Host role, and code-only Viewerattempts; it is not a room credential, and Viewer-grant admission cannotcreate or renew it. Cookie transport attributes follow the configured- destination: public HTTPS retains the Secure host-prefixed cookie, while a- separately configured HTTP LAN origin can use its HTTP cookie. Login,+ destination: HTTPS retains the Secure host-prefixed cookie, while a+ separately configured HTTP origin, such as App loopback, uses its HTTP cookie. Login,renewal, room creation and WebSocket admission use that same selection.Cookie signatures use a random process key independent of the password;restarting the Server/App requires site-password entry again. This does not@@ -159,6 +159,33 @@ the distinction between a room session and its current media publication.[Interaction research](../research/room-interactions.md) records delivery bounds,compatibility and design rationale.+## Room Voice++Optional room voice uses the same authenticated room.+The Host joining opens room voice; leaving closes it for everyone. Channel+availability is derived from that membership, not a separate switch. Authenticated+room members can join an open channel without another approval. Joining never+opens a microphone. Closing clears everyone's voice membership and publications;+reopening does not rejoin Viewers or restart microphones. Each speaker explicitly+starts capture and owns one server-assigned publication; mute, leaving and+session replacement retire that publication. Local mute changes+only the listener's playback, including when that listener relays for others.+Pausing listening mutes all local room-voice playback without changing the+microphone, membership or forwarding. Microphone and listening are independent.++Joining also authorizes a participant to forward decodable voice. A video relay+outside voice cannot carry it; the existing route controller selects a joined+path or reports that voice is unavailable. Local deafening never removes that+forwarding responsibility.+This is transport encryption between neighbors, not end-to-end encryption+against an admitted relay or the SFU operator.++Voice membership and routes outlive picture pause, stop and source replacement.+Leaving voice releases its microphone and forwarding demand; room retirement or+authorization loss ends the corresponding voice authority. Runtime voice state+is not persisted. The [routing contract](./routing-transport.md#room-media)+owns placement and recovery; [status](../status.md#current-work) indexes delivery.+## Persistence Modes- **Stable mode (Hosted default):** one exact-schema SQLite owner persists roomdiff --git a/docs/standards/routing-transport.md b/docs/standards/routing-transport.mdindex 0c81fb5f..c28b8298 100644--- a/docs/standards/routing-transport.md+++ b/docs/standards/routing-transport.md@@ -9,7 +9,7 @@ owns ports and [self-hosting](../operations/self-hosting.md) owns service setup.- Media defaults to automatic P2P-first routing. Viewers may constrain their ownincoming hop; parent selection, transport and adaptation remain automatic.-- The Host is the only source. Every Viewer has at most one active upstream, and+- The Host is the only shared-picture source. Every Viewer has at most one active upstream, andthe committed media graph is acyclic and source-reachable.- A Viewer may relay its received Browser track to bounded peer children. Thisis standard WebRTC receive, decode, and per-child re-encode, not shared encode.@@ -95,6 +95,13 @@ participants retain their established protocol and automatic behavior.Every non-server endpoint has one server-authoritative steady outbound media-copy cap `C`, default `2` and configurable only as `1`, `2`, or `3`.+A Viewer can also volunteer to relay to more participants+for the current visit. That explicit intent raises its permitted fanout only to+the endpoint's reported capability, at most the room's 20-Viewer limit. Ordinary+participants keep the configured cap. Withdrawing consent schedules affected+children through the same operation; it does not abruptly drop the subtree.+This remains an ordinary Peer relay, with no separate SFU service or authority.+- one peer child consumes one copy;- the Host's single SFU publication consumes one copy;- upstream receive is free;@@ -105,6 +112,35 @@ return to steady capacity at commit or abort. SFU publication ingress andper-Viewer subscription egress use an independent server admission ledger;ordinary endpoint child counts are not server capacity.+## Room Media++One room controller and its existing serial+operation serve both picture and voice. Opening and joining room voice can acquire+the graph before sharing; picture start attaches a new video generation and+picture stop removes that generation while voice remains. Empty rooms allocate+no media connections, and page entry alone creates no room.++The directed tree still places each Viewer under one parent. Independent Opus+publications travel both ways along its permitted edges, excluding the ingress+branch. Voice uses a companion WebRTC audio connection on each selected edge;+picture retains its existing Browser/Native sender and adaptation owners.+There is no all-pairs mesh or second route planner. SFU voice reuses its existing+UDP listener and admission, including on SFU-only sites.++A candidate carrying picture and voice commits only after both decoded-picture+proof and the required voice transports connect. A silent voice-only candidate+uses actual transport connection, without requiring samples or a video frame.+Video-only attachment to an already committed room edge uses its own fresh+physical identity and decoded-frame proof. Retired facet callbacks cannot+invalidate a replacement. Stop, pause and failure statuses describe the affected+consumer; a voice failure does not become a video error.+When current decoded-picture proof still establishes a healthy committed path,+a failed companion voice transport is recreated on that same path without+invalidating picture readiness or consuming a topology candidate. Without that+proof, the existing route operation owns repair and alternative selection.+The topology diagram projects connected room edges for voice as well as picture;+voice readiness never becomes evidence that a video frame has arrived.+## ReconciliationOne room controller owns the committed graph and one bounded child transition.@@ -306,7 +342,9 @@ encrypted hop-by-hop with DTLS-SRTP but terminates at the SFU; the product doesnot claim operator-blind media without a separately accepted application E2EEdesign. All-UDP-blocked networks currently end in bounded failure.-App Local mode runs this graph without SFU, NAT prediction, or default STUN.+App Local mode runs this graph without SFU or NAT prediction. Its selected LAN+address supplies Binding-only STUN on the App's UDP port, so routed virtual+LANs need not carry Browser mDNS; it uses no public discovery destination.One-link mode tunnels only HTTP/WebSocket control and adds public STUN to thesame Browser/Native P2P edges. Reachable peers form one mixed relay tree; anunreachable path adds no route type or score. App-enabled Site pages use thatdiff --git a/docs/standards/versioning.md b/docs/standards/versioning.mdindex b8c85826..10ef369f 100644--- a/docs/standards/versioning.md+++ b/docs/standards/versioning.md@@ -278,8 +278,14 @@ thanks or an occasional light aside can lead. Keep Piik's friendly tone withoutforced jokes; never turn an old feature into a claim that it is new in thisupdate, advertise an unfinished prototype or trivialize a serious failure.-When used, write the headline as the first two bold paragraphs, English then-Chinese, with plain text inside `**...**`. The website reads this same pair from+When used, open with a short bold title followed by one plain paragraph explaining+that headline's concrete meaning. Write the complete English pair first, then the+Chinese pair. For example: **Play together. Your turn!** / Piik now supports+remote control and remote co-play; **远程同乐,轮到你啦!** / Piik 现已支持远程控制与远程同乐。+The explanation states the feature or fact, rather than adding another slogan;+it does not replace the description of this update below. Keep each title and+explanation to one authored line, using plain text inside `**...**` and the+description. The website reads these same pairs fromthe published Release body and displays the current language; it does not keepanother copy, interpret arbitrary Markdown or guess a headline from olderreleases. Gitee retains the same body. Do not add a campaign registry or automaticdiff --git a/docs/standards/visual-language.md b/docs/standards/visual-language.mdindex ea52befc..28929e8a 100644--- a/docs/standards/visual-language.md+++ b/docs/standards/visual-language.md@@ -79,6 +79,7 @@ permissions and window chrome are verified in the actual platform, not imitated.| Switch related content pages | A named tablist with one selected tab and its associated panel; use the shared sliding treatment for short labels, including capture categories, and `navigateTabs` for Arrow/Home/End navigation || Pick a device or an item from a variable list | Existing named selector/menu; use source thumbnails when appearance helps identify the item || Adjust a numeric value | Range slider for quick adjustment, with a visible value; reuse `QualityNumberControl` when exact entry or a wider accepted range is useful |+| Return within a room tool | Shared `BackButton`: left arrow and **Back**, with the same quiet dense treatment in settings and expanded reactions || Apply several settings together | A named preset tile/chip; allow no preset to be selected when the current values are custom |Selection, expansion and pending operations describe different facts. Use the@@ -128,11 +129,19 @@ that every popup should acquire.| Keep a room tool available while watching or working | `FloatingPanel`, as used for interactions and Host remote permissions; retain its position without reflowing the room || Use a tool outside the page | Optional `usePanelWindow` on capable browsers; reuse the same content/session, as with interactions, remote permissions and the docked remote keyboard |+Chat and voice share one settings entry beside their tabs. Returning from either+settings page or an expanded reaction palette uses `BackButton`, not a destination+name or content icon. Audio icons keep their direct microphone/listening toggle;+`AudioVolumeMenu` exposes the shared volume slider on mouse hover, keyboard focus+or touch hold. It uses the guidance timing constants and anchored popover owner,+replaces a hint with an actual control, and never widens the participant row.+Settings remain an explicit touch entry for microphone and master volume.+Persistent room utilities use the shared floating panel without reflowing theliving room. The shell owns visibility, focus return, movement, resizing andviewport/keyboard bounds; contents retain their domain state. Support title-bardragging, corner resizing and equivalent keyboard controls without a second-placement menu. An interaction palette starts beside its chosen+placement menu. The couch's full interaction palette starts beside its chosenparticipant, stays open after sending and keeps its position when retargeted.One-shot settings and guidance retain their existing disclosures. Anchoredmenus use native popovers and shared viewport placement; a small parent panel@@ -141,13 +150,16 @@ platform polyfill installed before UI mounting; controls retain the samevisibility, focus and dismissal contract. Escape closesinner guidance first, then the most recently opened floating panel, then theatermode; an IME composition must not dismiss these surfaces.-The interaction window gives conversation the main space and keeps one stable-composer. Its reaction entry or a current participant's message avatar reveals-the same compact recipient strip and shared palette above the input. The tray-takes space from the scrollable message list without covering it; neither a-permanent roster nor a second target heading competes with messages. More-recipients scroll within that strip. Keep the composer in place while picking,-and preserve the draft and reading position.+The interaction window keeps its conversation and composer available while+reacting. A current participant's message avatar or voice avatar opens a small+attached palette with thumbs up/down and the two throwing props; one's own+entry uses laugh and heart in place of throws. Throwing props keep the full+palette's distinct card styling; compact buttons omit captions. More reactions expands+the same curated choices on demand, with a labelled back arrow in the heading.+Do not add a second roster or reflow the list. The native+popover owns outside-click and Escape dismissal; sending keeps it open for+repeated interaction. The couch retains its movable full palette. Both surfaces+reuse target identity, reaction buttons and the existing send owner.Live reactions can appear briefly in the conversation surface without moving itslayout. Retention and export details belong in settings, not beside every entry.Detachable tools reuse the same content in the browser's own always-on-top frame.@@ -244,7 +256,9 @@ the colour, outline and selected position without decorative displacement.The shared button uses the same pressed value for `aria-pressed` and its selectedtreatment; active state remains distinct from hover in both themes.Disclosure buttons keep a stable visible caption, while their expanded state and-accessible action describe opening or closing. Neutral panel borders stay quieter+accessible action describe opening or closing. Related tool captions use the same+grammatical form: name the feature rather than mixing feature names with instructions+to show them. Neutral panel borders stay quieterthan the controls inside them; nested diagnostic panels retain their softer fill.Keep room identity, invitation and admission controls ahead of expanded topologyand connection details, so inspecting a route does not displace room actions.@@ -267,7 +281,8 @@ One inline settings panel uses picture and sound tabs with the shared slidingtwo-option control. Picture presets lead; a fine-tuning disclosure containspicture limits, preference and video encoding, keeping configured limits visiblewhen closed. In sound,-source and microphone inputs precede the mixed output's audio quality. Presets+source-audio inputs precede source-audio quality; room microphone settings stay+in the voice panel. Presetsremain available before sharing starts. Switching tabs does not reset valuesor restart media. Keep the less frequent connection options in a shareddisclosure below the tabs. Expand in page flow, pushing later content down@@ -281,8 +296,13 @@ common step is an explicit action; rendering, focus or reopening never changesthe value. Derive this presentation from the current value, without a secondsetting mode. Shared presentation stays separatefrom the existing setting/resource owners.-The microphone comic depicts Host commentary gain;+The microphone comic depicts microphone input gain;the Viewer's listening-volume comic remains a different action.+Room voice retains one bottom toolbar: open/join and close/leave share its right+action position; microphone and listening controls appear to the left after+joining. Use the shared media-control styling for both states. Missing browser+microphone capability disables capture with a contextual explanation, without+disabling listening.The Viewer bar groups local play/volume/overlay, remote mouse/keyboard, thensettings/display modes, with fullscreen at the outer edge. Quiet dividers mark@@ -294,8 +314,10 @@ Remote input keeps its own clicks. When controls hide during remote input,retain a local pull on the TV bezel, away from the status lamp. Theater andfullscreen place it at the screen edge. Ordinary viewing reveals controls onmouse movement or a touch tap on the picture, without another button or setting.-Keep the chat-overlay toggle in the bar; its appearance settings also belong in-playback settings and reuse the interaction window's controls and local owner.+Keep the chat-overlay toggle in the bar. Its text size and opacity have one+entry in interaction settings for both Host and Viewers; playback settings own+local picture display and connection preferences. Microphone settings belong+to the voice page. All entries retain their existing local setting owner.Shorten the volume slider before moving display modes into settings; keep thebar on one line at supported mobile widths.Viewer settings use a brief anchored popover, preferring space below the picture@@ -350,8 +372,9 @@ changing the badge does not restyle the UI, wordmark or illustrations.| Shared or watched media | Small television, including antenna, body and feet || Browser application | Browser chrome around content; not a second design of television || A captured window or display | Window title bar or display stand, with the shared media metaphor kept distinct |-| A camera source or Host commentary | `camera` identifies the alternative picture source; `microphone` identifies the enabled Host voice input and `microphoneOff` its muted state. Neither replaces the speaker metaphor for source/playback sound. |+| A camera source | `camera` identifies the alternative picture source. Source/playback sound retains the speaker metaphor. || Room text and reactions | `chat` opens the conversation, `danmaku` controls its optional picture overlay, `smile` identifies reactions and `send` submits the chosen content. These do not represent media transport or voice. |+| Room voice | `microphone` / `microphoneOff` identify input state; `headphones` / `headphonesOff` pause or resume room-voice listening, while `speaker` / `speakerOff` mute one person locally. Input, playback and forwarding remain independent. Toggle names stay fixed. The microphone's green fill shows measured input after gain, not the configured gain percentage. Participant microphone state stays visible; measured speech changes only the green dot and accessible speaking description, without replacing the visible status text. An enabled input alone is not speaking evidence. Opening the channel and opening a microphone stay separate actions. The Host has labelled open/close-room actions, with `stop` and danger styling for closing everyone's voice; a Viewer's `door` leaves only their own voice participation. Joined membership does not use a network-strength symbol. || Experimental attended desktop control | `mouse` identifies keyboard/mouse control, distinct from sharing or playback. Permission copy stays literal; an active control marker describes the grant, not media connectivity. || Floating utility placement | `grip` marks a draggable title bar; corner handles resize the window. Closing a panel hides its presentation, not its room session. || Server forwarding media | A server on the media path; opening a Site alone does not imply SFU |@@ -421,6 +444,7 @@ type checking rather than silently render a warning triangle.| Meaning / 含义 | Symbols | Use and boundary || --- | --- | --- || Participants and room / 人与房间 | `users`, `couch`, `door` | People, shared room, room entry. Use the shared pawn for a person and `HostMark` for Host authority. |+| Create / 创建 | `plus` | Create the named object. An empty room-code frame uses this action before the room exists; the resulting code replaces it in place. || Shared screen / 共享画面 | `tv`, `MiniTv`, 📺 | Media or its sharing source. The TV beside the Host name identifies the source; the crown on a person identifies the role. || Start and choose a source / 分享与选源 | `cast`, `share`, `switchSource` | Start sharing, capture a screen, replace the current capture source respectively. A captured window keeps window chrome or a display stand. || Capture source / 采集来源 | `window`, `display` | An application window or a whole display; these nouns remain distinct from the source-switch action. |@@ -429,13 +453,13 @@ type checking rather than silently render a warning triangle.| Restriction / 受限 | `lock` | Restricted entry, concealed password or a setting fixed by availability; show the affected object. A lock never promises anonymity or secure media. || Site and public entry / 站点与公开入口 | `globe` | Browser/Site entry or code-based public entry. It does not claim internet reachability. || Preferred destination / 默认去处 | `star` | A user-selected default, such as the App's startup Site. It is a preference, not authorization or connection health. |-| Connections / 连接 | `network`, `branch`, `signal`, `wifiOff`, `server` | Topology, branching, signaling, disconnected signaling and the named server. A server on a media path means forwarding; a Site backend or control-link server alone does not imply SFU. An invitation chain does not represent signaling. |+| Connections / 连接 | `network`, `branch`, `signal`, `wifiOff`, `server` | Topology, branching, signaling, disconnected signaling and the named server. The header's rising bars show only signaling state: three steady green for connected, two animated yellow for connecting/recovering, all grey for offline. Active bars have equal brightness; this is neither a signal-strength measurement nor a media-quality claim. The television lamp owns sharing/viewing state. A server on a media path means forwarding; a Site backend or control-link server alone does not imply SFU. An invitation chain does not represent signaling. || Playback / 播放 | `play`, `pause`, `stop` | Play/resume, pause, end. The control label states whether it affects local viewing or the Host's share. Stop is distinct from a paused or idle room. || Audio / 声音 | `speaker`, `speakerOff` | Audio and mute/no audio, qualified by the source or local playback label. A source track's presence does not establish delivered sound. |-| Size and viewing mode / 尺寸与观看模式 | `expand`, `contract`, `pip`, `pipExit`, `theater`, `theaterExit`, `fitContain`, `fitCover`, `fitStretch` | Expand/restore, enter/leave picture in picture or theatre mode; contain, proportional crop and stretch change only local picture fit. The same size symbol can accompany a resolution measurement. |+| Size and viewing mode / 尺寸与观看模式 | `expand`, `contract`, `pip`, `pipExit`, `theater`, `theaterExit`, `fitContain`, `fitCover`, `fitStretch`, `rotatePicture` | Expand/restore, enter/leave picture in picture or theatre mode; contain, proportional crop and stretch change only local picture fit. Picture rotation switches the local landscape/portrait view. The same size symbol can accompany a resolution measurement. || Local actions / 本地操作 | `copy`, `save`, `pencil`, `eye`, `eyeOff` | Copy, save, edit, reveal and conceal the named object. An action icon does not prove completion. || Text appearance / 文字外观 | `textSize`, `opacity` | Relative text size and opacity. These are local display preferences, not message delivery states. |-| Repeat and disclosure / 重试与展开 | `refresh`, `chevron`, `arrowRight` | Repeat/refresh, expand/collapse, proceed/enter. Direction follows the control's action; no arrow alone establishes delivery. |+| Repeat and disclosure / 重试与展开 | `refresh`, `chevron`, `arrowRight`, `arrowLeft` | Repeat/refresh, expand/collapse, proceed/enter and return. Direction follows the control's action; no arrow alone establishes delivery. || Transfer and upgrade / 传输与更新 | `arrowUp`, `arrowDown` | Outbound/inbound or upload/download, qualified by the adjacent label. An explicit update label may use the upward arrow for upgrade; neither arrow is a connection-quality rating. || Diagnostics / 诊断 | `cpu` | Technical diagnostics in the labelled diagnostic control; in metrics the same processor identifies encoding work. The surrounding control or measured field states the scope. || Help / 帮助 | `help`, `book` | Open product help or read a guide, respectively; current build identity belongs with this low-frequency information, separate from media settings and App connection state. |diff --git a/docs/status.md b/docs/status.mdindex 9ce3ff1d..6fdf9716 100644--- a/docs/status.md+++ b/docs/status.md@@ -1,9 +1,9 @@# Current Status-Last updated: 2026-10-20+Last updated: 2026-10-21This is the compact execution/deployment index. Product modules own behavior,-[verification status](./verification-status.md) owns unresolved physical limits,+[verification status](./verification-status.md) summarizes material evidence limits,and Git/PRs own completed history.## Accepted Release Contract@@ -27,11 +27,11 @@ and Git/PRs own completed history.mascot, concrete media waits use their owning comic, and waiting captions aresecondary to literal status. Website reduced-motion preference and playertooltip placement follow the same presentation owners.-- Camera sharing and Host microphone commentary are accepted product features.- Both Browser and native App audio use the existing media routes; device- selection and sharing settings keep their current resource owners. The+- Camera sharing and room voice are accepted product features. Source audio+ follows the picture; room voice owns Host and Viewer microphones under the+ same route controller. Device selection and sharing settings keep their owners. The[capture assessment](./research/camera-and-microphone.md) owns platform behavior- and the remaining physical evidence limits.+ and platform limits.Website delivery includes a bilingual reader documentation center generatedfrom the repository's guides alongside the homepage, with search and detailed@@ -46,11 +46,10 @@ panel. Its opted-in room session can outlive a publication; capture, quality androute owners remain unchanged. Optional Windows screen-audio exclusion uses theexisting source/mixer boundary. Hosted Serveralso accepts an optional SFU-only policy through the same route controller.-Windows native capture and thumbnails now share automatic HDR-to-SDR conversion;-synthetic GPU and Browser reception checks pass, with physical HDR display-acceptance still pending in [verification status](./verification-status.md).-Room voice is outside this published phase; Host microphone commentary remains.-These features are published; physical device limits remain open.+Windows native capture and thumbnails share automatic HDR-to-SDR conversion.+The [fidelity assessment](./research/media-fidelity.md#hdr-to-sdr) owns its evidence+and the distinction from Browser capture and end-to-end HDR.+Room voice supplies Host and Viewer speech separately from source audio.Release artifacts and operator deployment records own delivery completion;[TODO](./todo.md#now) owns remaining work.@@ -60,16 +59,26 @@ The current 2.x release line retains attended keyboard/mouse control, Viewerplayback settings and the interaction window, with the maintenance media and lifecyclerepairs. The accepted maintenance phase preserves the published protocols androute owners; release artifacts and operator records establish publication and-postflight completion. Current implementation work turns to room-owned routing-and voice in the isolated prototype, while device/reporter follow-up remains in-the TODO ledger. The promotional film remains an online-review draft; export-follows owner acceptance.-Separate local prototypes assess room voice and shared-keyboard/virtual-gamepad-co-play. A room-owned tree experiment now reuses the existing route controller-for bidirectional voice and video on shared Pion connections. Local media-owner-experiments do not establish public App-hosted voice;-neither prototype changes the published feature or protocol boundary.-[TODO](./todo.md) owns upstream follow-up, device acceptance and deferred work;+postflight completion. Room voice integrates normal App/Server/Web, with the same+room graph and serial route operation, separate picture and voice lifetimes, explicit pre-share room creation+and Host-owned room voice activation. Normal Browser checks cover a three-participant Peer+relay and embedded SFU, duplex audio, local-mute isolation, picture replacement,+detached UI and capture retirement. Optional voluntary Peer fanout and local+picture rotation are included; frp uses the documented existing UDP configuration.+Windows x64 Server packaging uses the existing+release inventory; Docker images remain Linux-only.+App Local invitations now use HTTPS on the selected LAN address; the Host keeps+its loopback entry. Hosted Server also supports optional direct HTTPS with a+temporary local certificate or supplied certificate files. Both use the same+room authority and require the browser to accept the certificate.+Channel availability derives from Host membership and uses one+room microphone for Host and Viewers. Local normal-page acceptance covers both+P2P and SFU, independent listening, picture continuity and voice-facet recovery.+Controlled-network voice cases and platform package checks have passed; the+release artifacts and operator records establish publication and deployment.+Separate shared-keyboard/virtual-gamepad experiments remain prototypes.+The promotional film stays an online-review draft; export follows owner acceptance.+[TODO](./todo.md) owns unfinished work and explicit deferrals;release artifacts and operator records own exact delivery results.2.0 separates numeric media requests from presets and bounded runtime admission,@@ -87,10 +96,8 @@ Magicsock remains excluded: its [controlled comparison](./research/nat-traversalestablished no additional reachability worth its integration costs.The [media assessment](./research/native-client-media.md#media-capability-extension-assessment)-owns bounded output and live-control evidence. Physical macOS/Linux capture,-limited decoders and sustained game/4K use retain the limits in-[verification status](./verification-status.md). Additional codecs, room voice,-surround delivery and end-to-end HDR remain outside this phase.+owns bounded output and live-control evidence. Additional codecs, surround+delivery and end-to-end HDR remain outside the published phase.2.0 was published after final acceptance without a separate field beta.Immutable release artifacts and operator records own exact delivery@@ -119,7 +126,7 @@ HTTPS, runtime assets, all three STUN listeners and a bounded browser P2Psharing/stop check passed; the browser check used synthetic video on one network.The operator record owns exact identity and postflight evidence.-[TODO](./todo.md) owns remaining verification and follow-up work. The owner declared the first+[TODO](./todo.md) owns unfinished work. The owner declared the firstpublic release on 2026-09-12. Source is public, main protection is active, and`piik.tv` runs on GitHub Pages behind Cloudflare with HTTPS. The private serviceremains a separate deployment. Release descriptors and GitHub deployment records@@ -135,7 +142,7 @@ product changes publish automatically; standalone website and documentationchanges validate and deploy the website without creating App/Server versions.GitHub/Gitee release comparison, mirror publishing and PR-sourced notes follow[versioning](./standards/versioning.md). [Verification status](./verification-status.md#device-evidence-boundary)-owns the remaining physical limits; shared lessons live in+summarizes material evidence limits; shared lessons live in[engineering](./standards/engineering.md).## Media Evidence And Limits@@ -167,8 +174,6 @@ owns the remaining physical limits; shared lessons live inowns these measurements and failed controls. The owner accepted this scopedBrowser composition for release; actual deployment identity stays in theruntime descriptor.-- Slow adaptation recovery, the extreme CPU-overload sampling limit and missing- broad device/network/endurance results remain explicit in- [encoder research](./research/webrtc-encoder-pool.md) and verification status.- macOS/Linux physical capture is deferred by the owner; Windows App and- Browser are this phase's primary targets.+- Browser-controlled recovery and extreme CPU-overload limits remain in+ [encoder research](./research/webrtc-encoder-pool.md). Windows App and Browser+ are this phase's primary targets; macOS/Linux physical capture remains deferred.diff --git a/docs/todo.md b/docs/todo.mdindex c3829455..38459dae 100644--- a/docs/todo.md+++ b/docs/todo.md@@ -1,325 +1,89 @@# Current TODO Ledger-Last reviewed: 2026-10-20+Last reviewed: 2026-10-21-Explicit owner holds remain in force; an investigation does not itself-accept a new feature or architecture. A missing device or reporter trace blocks-only that evidence claim, not unrelated work. Product modules own behavior;-Git/PRs own completed history.+This ledger contains unfinished work and explicit owner holds. Product modules+own behavior; research and Git/PRs own evidence and completed history.## Now-The 2.x maintenance line retains the published protocol and route owners.-Release artifacts and operator records own exact delivery; remaining product-work is listed below. Broader device coverage does not override the owner's-platform deferrals or establish a diagnosis for unmatched reports.--- [ ] **Return LiveKit to an upstream pin.** Native publication now supplies- unmet encoder demand to the existing allocator through the scoped dependency- revision submitted in [upstream #5016](https://github.com/livekit/livekit/pull/5016).- When maintained upstream provides this input, pass the same recovery gate and- remove the temporary replacement. [Provenance and removal](../internal/thirdparty/README.md#local-encoder-probe-demand)- own that boundary; this local repair does not diagnose the unmatched field- reports below.--- [ ] **New promotional film.** Refine the accepted short proof's art direction- into a standalone Chinese/English introduction that assumes no earlier film.- Functional and mechanism work takes priority. Keep the draft in the online- review player; export video only after the owner accepts that preview.- Keep sharing, invitation, Host consent- and playing together causally connected, using product components with staged- content for actual operations. The local 36-second cut now carries this story,- including a real reaction picker and a friend's tomato throw;- refine the two-player party-game vignette, motion, reading time and soundtrack- before replacing the online film. Depict the published local-Host plus one- remote-friend keyboard flow; experimental multi-controller features are not claims.+- [ ] **Return LiveKit to an upstream pin.** Follow+ [upstream #5016](https://github.com/livekit/livekit/pull/5016). Once upstream+ supplies the allocator input Piik needs, verify recovery and remove the+ temporary replacement. [Dependency provenance](../internal/thirdparty/README.md#local-encoder-probe-demand)+ owns the patch and removal boundary.+- [ ] **New promotional film.** Refine the online Chinese/English draft as a+ standalone introduction: sharing, invitations, Host consent and playing together.+ Improve the party-game example, motion, reading time and soundtrack. Functional+ work takes priority; export only after the owner accepts the online preview.+ Depict published functionality rather than multi-controller prototypes.## Held By Owner-- [ ] **Remote-control latency and responsiveness.** Scheduled after this release.- Compare input-to-visible-response timing on the same endpoints, source and- network against a mature remote-control implementation. Separate input- delivery, Host execution, capture/encode and receive/playout; retain the- existing route and authorization owners. Identify the dominant delay before- changing budgets or buffering, and compare loss/recovery as well as steady latency.--- [ ] **Persistent-loss estimator replacement.** Deferred by the owner on- 2026-10-18. Retain mature congestion control and accept quality reduction under- sustained high loss; no custom loss model or release prerequisite is added.- [Evidence and limits](./research/node-local-media-design.md#persistent-loss-with-low-source-utilization)- retain the low-utilization collapse and distinguish it from concrete feedback- accounting or recovery defects, which remain in scope for ordinary fixes.-- [ ] **Multiple remote-control screens.** Deferred by the owner on 2026-10-17.- Keep one shared source and the existing Host source picker; Viewer-initiated- screen switching and simultaneous multi-screen streams are later work.-- [ ] **32-bit Windows/Linux Apps.** Deferred by the owner on 2026-10-02;- no package or website option is planned. Browser use remains available where- the OS/browser supports the required media APIs. Retain the isolated- Git evidence for the Windows x86 capture experiment; revisit its native dependencies,- atomic alignment and real 32-bit device coverage only if this work is reopened.-- [ ] **Windows ARM64 App.** Deferred by the owner on 2026-10-03. Keep Windows- App packages and website downloads x64-only until this work is reopened.-- [ ] **Alternative public-invitation providers.** Deferred by the owner on- 2026-10-16. Retain Cloudflare Quick Tunnel; do not integrate localhost.run or- another provider in this phase. The [provider assessment](./research/cross-platform-client-runtime.md#alternative-invitation-providers)- retains the probe results and tradeoffs for a later decision.--## Awaiting Device Or Reporter Evidence--These physical checks or reporter diagnoses remain unverified. A local repair or-successful test is not proof of a reporter's cause; research owns the completed-experiments and their limits.--- [ ] **macOS bundle startup acceptance (#479).** Verify Finder launch,- quarantine and capture permissions on a physical Mac. The Mach-O entry and- helpers are inside `.app`; moved-bundle assembly and both architecture builds- pass. The corrected packaging has not yet been matched to the reporter's Mac.--- [ ] **macOS sharing with source audio (#486).** Verify actual screen/window- audio plus microphone startup. Both Darwin architectures compile and pass the- audio self-test in candidate CI.- The local repair confirms audio readiness when platform startup succeeds,- rather than waiting for samples. Go pipe controls preserve video with silent- or unavailable audio. The reporter's full start-share timeout and separate- window-filter crash remain unconfirmed; do not close the report on this partial- correction. [Evidence](./research/native-client-media.md#macos-audio-startup)- separates the confirmed readiness defect from the unresolved system failures.--- [ ] **Remote-control device acceptance.** Verify physical Android/iOS- controllers, mixed-DPI displays, commercial games and an actual remote-device- session. macOS needs Finder/Accessibility, focus, Retina and input checks;- Linux needs desktop Portal permissions and capture/input checks. Existing- [evidence and limits](./verification-status.md#device-evidence-boundary) remain- distinct from build and emulated-controller acceptance.--- [ ] **Sustained quality loss.** Retest the affected Native Host and the- v1.9.2 self-hosted Browser setup with matched Host/Viewer/Server diagnostics,- route and codec. [Native controls](./research/node-local-media-design.md#send-queue-recovery)- and [P2P/Browser trials](./research/network-lab.md#sustained-quality-recovery)- do not establish these reports' causes. Windows native QP tuning improves the- [controlled recovery cases](./research/webrtc-encoder-pool.md#budget-restoration).- Browser recovery can still take tens of seconds or remain downscaled after- allocation recovers; its internal QP settings are not exposed to page scripts.- Controlled repetition no longer depends on reporter availability; matched- reports are needed to attribute their cases.- Do not infer server CPU requirements from an unmatched report.--- [ ] **Linux Portal target identity acceptance (#470).** The- [contributor fix](https://github.com/TNTcraftHIM/Piik/pull/470) is integrated- with authorship retained. Compilation and headless serial/node-ID targeting- checks pass. Verify an actual Portal that omits `pipewire-serial` when physical- Linux capture acceptance resumes; headless checks do not exercise desktop capture.-- [ ] **Windows 11 capture border remains visible.** The new report does not- identify the affected version, capture path or Windows build. The reviewed- picker/start/source-change paths preserve the border preference; no additional- confirmed defect was found. [Capture evidence](./research/native-client-lifecycle.md#windows-capture-borders)- owns the permission correction, retirement checks and preview-cancellation- boundary. Visible permission changes, display-mode changes and the reporter's- setup still need matched physical evidence; API success does not prove that- Windows hid the border.-- [ ] **Physical device and network acceptance.** Complete the- [device checks](./verification-status.md#device-evidence-boundary) and- [network/endurance matrix](./verification-status.md#remaining-device-and-network-acceptance),- preserving platform deferrals and serial capture checks. Include limited- decoders, macOS geometry, sustained game/4K use, live changes through relay/SFU,- audio levels/fidelity/exclusion, mobile keyboard/fullscreen and camera behavior,- plus passive App approval/revocation and Local coexistence. The linked- verification owner retains the detailed evidence boundaries; this does not- reopen additional codecs, surround or end-to-end HDR.-- [ ] **Native H.264 motion quality (#432).** Obtain matched source/decoded- pictures and bitstream for the original 720p30 game comparison. Retain current- codec parameters. The [evidence review](./research/native-client-media.md#native-h264-motion-quality)- owns the withdrawn CBR claim, Baseline admission repair and Main/High comparison;- none establishes this report's cause.-- [ ] **Self-hosted room creation HTTP 403.** Retest affected deployments using- the [address checks](./guide/troubleshooting.md#room-creation-returns-403).- Obtain the configured public address/origin and response details; distinguish- Piik's rejection from a proxy/WAF 403 before assigning their cause.-- [ ] **No available media route.** Obtain paired reports and compare the same- endpoints before assigning a regression. Separate allocation, ICE, first-frame- admission and rejection; similar messages do not establish one cause.- [#443](https://github.com/TNTcraftHIM/Piik/issues/443),- [#448](https://github.com/TNTcraftHIM/Piik/issues/448) and- [#453](https://github.com/TNTcraftHIM/Piik/issues/453) need paired transport traces;- the v1.6.3 timeout also needs share-start/SDP evidence.- [#471](https://github.com/TNTcraftHIM/Piik/issues/471) reports working STUN and- a router mapping on v2.1.0, but no ICE check responses. Its single STUN URL- enables ordinary discovery, not the three-destination prediction survey.- Obtain the retained paired reports; that summary alone does not distinguish NAT filtering,- upstream mapping or a blocked path.- [#468](https://github.com/TNTcraftHIM/Piik/issues/468) needs the complete join/- reauthentication trace on repaired connection-opportunity accounting.- [#464](https://github.com/TNTcraftHIM/Piik/issues/464) needs matched SFU reports- after updating; the Viewer-side publication diagnostic was not Host evidence.- [#467](https://github.com/TNTcraftHIM/Piik/issues/467) needs the Host/App rejection- preceding its 170 ms exhaustion; extending ICE timeouts is not justified.- For [#465](https://github.com/TNTcraftHIM/Piik/issues/465), isolate local-network- permission from IP masking using the [local controls](./research/browser-local-encoding-pool.md#local-connection-failure-control).- [#463](https://github.com/TNTcraftHIM/Piik/issues/463) needs the Mac/phone attempt- details to distinguish capture, entry and media failure.-- [ ] **Public-invitation startup and HTTP 1033.** Obtain version and matched- diagnostics; distinguish connector exit/recovery, DNS/provider failure and- obsolete links from media routing. Compare [#396](https://github.com/TNTcraftHIM/Piik/issues/396#issuecomment-5691465700)- with [runtime evidence](./research/cross-platform-client-runtime.md#public-invitation-startup).- [#434](https://github.com/TNTcraftHIM/Piik/issues/434) establishes DNS refusal;- [#452](https://github.com/TNTcraftHIM/Piik/issues/452) needs a same-endpoint- accelerator comparison for QUIC/TCP timeouts, separately from its H.264 report;- [#466](https://github.com/TNTcraftHIM/Piik/issues/466) needs the original exit log.-- [ ] **Viewer interruptions.** Obtain paired endpoint/upstream-relay diagnostics- for established viewing returning to P2P connecting.- Separately retest the v1.5.0 App public-link report where one Viewer drops- immediately after connection details appear while others work. Distinguish- first-frame admission, signaling grace and current-edge recovery.-- [ ] **App discovery and share-start failures.** Retest authorization, Browser- permissions, control capacity, enumeration and startup. The v1.6.5 Auto-to-VP8- report needs the Browser exception/assets and actual output; its early- `stop-share` is not proof of a no-frame timeout. [#419](https://github.com/TNTcraftHIM/Piik/issues/419)- still needs a matched App report. The v2.2.1 log in- [#437](https://github.com/TNTcraftHIM/Piik/issues/437) exposed Auto admitting a- hardware probe with insufficient measurement time. Its local correction- preserves the existing VP8 fallback; retest on the affected device. The- underlying `DEVICE_HUNG` and subsequent blocked API remain unconfirmed.- For `input-texture-create / 0x887a0005`, obtain subsequent candidates and the- final result; [native media research](./research/native-client-media.md#current-boundary)- owns hardware evidence and limits.-- [ ] **Native sharing ends unexpectedly.** The v2.0.0 `app/capture/failed` and- game-entry reports need capture path, codec and matched App diagnostics.- Locate the first capture/output, preview-bridge, control or authority failure;- distinguish quiet sources, target/display changes and device loss using- [capture evidence](./research/native-client-lifecycle.md#quiet-sources-and-viewer-recovery).- The error key alone identifies neither a driver nor a timeout.-- [ ] **System becomes very laggy after starting a share.** Obtain mode, actual- codec, profile, display refresh rate and CPU/GPU use, distinguishing startup- from sustained lag. Compare saturated GPU/game-FPS impact and multi-output- recovery with the [helper-cost checks](./research/native-client-media.md#windows-helper-cost-2026-09-29)- before changing allocation or cadence. For Native/SFU stalls, correlate the- relevant Go runtime using the [GC attribution boundary](./research/realtime-quality-adaptation.md#go-gc-attribution);- no field report currently establishes GC as its cause.+- [ ] **Separate accompaniment sharing.** Deferred on 2026-10-20 and excluded+ from this candidate. Preserve the unfinished prototype on+ `spike/audio-accompaniment` (`5e385add`); it is not a working feature.+ Sharing a music application with source audio remains available.+- [ ] **Remote-control latency and responsiveness.** Scheduled after release.+ Compare input delivery, Host execution, capture/encoding and playback on the+ same endpoints and network before changing budgets or buffering.+- [ ] **Persistent-loss estimator replacement.** Deferred on 2026-10-18.+ Keep mature congestion control and accept quality reduction under sustained+ high loss; concrete accounting/recovery defects remain ordinary bug fixes.+ [Evidence](./research/node-local-media-design.md#persistent-loss-with-low-source-utilization).+- [ ] **Multiple remote-control screens.** Deferred on 2026-10-17. Keep one+ shared source; Viewer screen switching and simultaneous screens are later work.+- [ ] **32-bit Windows/Linux Apps.** Deferred on 2026-10-02. No package or+ website option is planned; preserve the isolated Windows x86 experiment in Git.+- [ ] **Windows ARM64 App.** Deferred on 2026-10-03. Keep Windows downloads x64-only.+- [ ] **Alternative public-invitation providers.** Deferred on 2026-10-16.+ Keep Cloudflare Quick Tunnel. The [provider assessment](./research/cross-platform-client-runtime.md#alternative-invitation-providers)+ owns alternatives and tradeoffs.## Local Interaction Prototypes-- [ ] **Optional room voice (#484).** Continue the isolated self-hosted voice- and room-owned tree experiments. Keep production,- public invitations and the public Demo unchanged; do not recreate the previous- P2P voice mesh. The Host approves voice admission- and speaking, and can mute or revoke participants; each listener can also mute- another participant locally. Voice remains separate from shared-source audio.- The isolated prototype carries actual multi-publisher audio with server-enforced- consent and retirement. Synthetic voice/sharing coexistence and a separate local- media process are exercised; review the experience before product integration.- Physical microphones and external networks remain unverified.- Reuse the existing room authority and mature media transport; keep voice- publications outside the screen-capture lifetime.- Assess an App-hosted instance of the same voice forwarder separately, including- Viewers reachable only through a video relay and voice without an active share.- The room-tree experiment reuses the unmodified controller for Browser/Pion- voice, video and separate source audio, including decoded playback, relay- departure and independent publication retirement. Its authenticated Browser- control now handles negotiation and first-frame commit without a test runner- routing SDP or declaring media ready. Unauthorized voice relays- make that path unavailable without disturbing video; approval restores it on- the same connections. Before integration, complete production App authorization- and control, multi-track upload budgeting, physical audio and external-network- acceptance under those owners.- The [transport assessment](./research/room-interactions.md#room-voice-transport-assessment)- separates this local evidence from a production P2P voice path.- [Issue #484](https://github.com/TNTcraftHIM/Piik/issues/484)- describes the use case; the published product contract is unchanged.--- [ ] **Shared-keyboard remote co-play.** Prototype several consented Viewers- using the existing input channel and media route. Keep one Host source and- one grant/retirement owner, track held keys per participant, and release a key- only after its last holder lets go. Give the shared pointer one explicit owner.- The local Host-plus-two-Viewer trial covers actual decoded video and encrypted- input, individual revoke/disconnect, source replacement and stop/rejoin. Review- the prototype before product integration; its recording sink does not establish- desktop injection, physical Host key overlap or game compatibility.- Multiple screens remain deferred. This experiment- does not accept a new published grant model or claim universal game support.--- [ ] **Optional virtual gamepads for remote co-play.** The owner authorized an- isolated input-backend experiment on 2026-10-19. Let the Host supply the- optional dependency; do not install or bundle a kernel driver. Reuse the- encrypted input route and grant owner, with Host-assigned independent devices- and neutralization/removal on retirement. Evaluate maintained backends,- licensing, privileges and real-game recognition before product integration.- The [input assessment](./research/room-interactions.md#remote-co-play) owns- platform dependencies and the distinction from shared keyboard/mouse control.--## Next: P2P Connection And Feedback Evidence--- [ ] **External forwarding and participant relays.** Complete Browser and- external-network acceptance for existing friend relays. Before adopting frp- for a deployment, compare loss/recovery and performance on that network; the- local SFU media/feedback and STUN controls establish feasibility and the address- limitation, not public-network performance. Keep the [forwarding assessment](./research/nat-traversal.md#external-forwarding-and-participant-relays)- as the evidence owner; no second graph or App-hosted SFU is integrated.--- [ ] **Coordinated Native retry acceptance.**- Compare the same difficult-network peers with enhancement enabled/disabled,- including mixed stable/sequential observations in both directions and decoded- continuity. Preserve the first ordinary attempt, immediate Browser decline- and fixed deadlines. The [process lab](./research/network-lab.md) and- [assessment](./research/nat-traversal.md#coordinated-native-punching-assessment)- own existing controls; random-port overlap and field benefit remain unproven.--Prioritize App-to-Browser and Browser-to-Browser comparisons across interface-changes, lost mappings and asymmetric restrictions, then Native/SFU handoffs-and background P2P recovery. Measure connection success, first-picture time and-failure stage with existing Debug provenance under the [NAT evidence boundaries](./research/nat-traversal.md#gateway-and-survey-limits).-The [Browser-compatible assessment](./research/nat-traversal.md#browser-compatible-follow-up)-owns upgrade and literature evidence; local success is not a field percentage.-Keep Magicsock excluded unless a matched comparison establishes additional-reachability within the [integration boundary](./research/nat-traversal.md#iroh-and-tailscale-comparison).-Keep standard ICE recovery while [renomination's reverse-feedback failure](./research/nat-traversal.md#pion-renomination-preflight)-remains; do not add another retry/transport owner to bypass these limits.+- [ ] **Shared-keyboard remote co-play.** Review the isolated Host-plus-two-Viewer+ prototype before product integration. Reuse the encrypted input route and+ consent owner, with per-participant held keys and one explicit pointer owner.+ The recording-sink trial does not implement desktop injection or game support.+- [ ] **Optional virtual gamepads.** Continue the isolated input-backend+ experiment authorized on 2026-10-19. The Host supplies any optional dependency;+ do not install or bundle a kernel driver. Review maintained backends, licensing,+ privileges and device retirement before integration. The+ [input assessment](./research/room-interactions.md#remote-co-play) owns the design.## Parked Product Work-1. **Broader quality work.** Reopen from measured interruptions, failed recovery- or healthy-sibling degradation at acceptable complexity. The- [Browser pool comparison](./research/browser-local-encoding-pool.md#balanced-startup-and-recovery)- owns cold-encoder tradeoffs; low resolution alone is not a defect. Check- whether a proposed move merely shifts pressure to another parent's siblings.-2. **Platform output.** Reopen for a registered receiver acting as an ordinary- Viewer only after the [platform-output gate](./research/platform-output.md)- passes.-3. **Additional languages.** Review community catalogs and their rendered UI- following the [translation guide](./guide/translating.md), including names,- menu navigation, text direction and layout.-4. **Windows code signing.** Revisit after enrollment in a trusted signing- service. Sign executables before archive checksums; publisher identity does- not guarantee that antivirus cloud scanning stops.-5. **Gitee download-source warning.** Paused by the owner. Keep GitHub primary- and retain Gitee; do not add a self-hosted mirror. Chrome still blocks the- Gitee attachment when Referer is removed. Reopen for new evidence or a- provider review; the warning remains unresolved.-6. **Release-operation policy.** Protected release environments and immutable- draft assets remain unaccepted proposals; evaluate their benefit before- adding release machinery.-7. **Automatic local chat history.** Explicit TXT export covers manual retention.- Reconsider automatic storage only with a stable room-incarnation identity,- bounded retention and a clear delete control; reusable room codes must not- combine conversations. No new history service or wire field is authorized.-8. **Managed Demo hosting.** The [provider assessment](./operations/website.md#managed-hosting-assessment)- identifies UDP/storage requirements but establishes no cost saving. Keep the- existing P2P-only Demo; reopen for an accepted provider and operating boundary.-9. **Phone as a Host microphone.** The [input assessment](./research/camera-and-microphone.md#phone-microphone-assessment)- identifies pairing/revocation and native decoded-input ownership beyond the- device selector. Reopen for a concrete use case that justifies this boundary- and physical latency/echo/background checks. This does not reopen room voice.-10. **Remote co-play and mobile controlled platforms.** The [co-play assessment](./research/room-interactions.md#remote-co-play)- separates virtual gamepad slots from attended keyboard/mouse assistance.- Desktop input acceptance remains above; independent gamepads and mobile- controlled endpoints need a separate scope decision.-11. **Multiple simultaneous sharers.** The [party-mode assessment](./research/room-interactions.md#multiple-sharers-assessment-not-implemented)- separates room administration from publication ownership, with one selected- picture per Viewer and shared endpoint upload limits. Define publication and- subscription lifecycles before a prototype. The current one-Host contract- remains; names and UI follow the model decision.-12. **Windows x64 Server packaging (#485).** Review the contributor's package- extension separately from the maintenance release, including descriptors,- container filtering, mirror inventory and Windows runtime acceptance.- Remove the unrelated history-check fallback before integration; an absent- push base is not a Windows packaging requirement. Existing Linux Server- packages and Windows App support are unchanged.+- **Platform output.** A registered receiver may act as an ordinary Viewer after+ the [platform-output gate](./research/platform-output.md) passes.+- **Additional languages.** Review community catalogs and rendered UI through+ the [translation guide](./guide/translating.md).+- **Windows code signing.** Revisit when a trusted signing service is available;+ sign executables before archive checksums. Signing does not guarantee the end+ of antivirus cloud scanning.+- **macOS distribution signing.** Developer ID signing and Apple notarization+ need an Apple Developer identity. [#489](https://github.com/TNTcraftHIM/Piik/issues/489)+ reports first-launch blocking; the troubleshooting guide provides a scoped+ opening procedure, not a signing fix. Verify downloaded bundles on a Mac when+ signing becomes available.+- **Gitee download-source warning.** Paused by the owner. Keep GitHub primary+ and retain Gitee; do not add a self-hosted mirror. Reopen for new provider evidence.+- **Automatic local chat history.** Manual TXT export already exists. Automatic+ storage needs a stable room-incarnation identity, bounded retention and deletion;+ reusable room codes must not combine conversations.+- **Managed Demo hosting.** The [provider assessment](./operations/website.md#managed-hosting-assessment)+ establishes no cost saving; keep the existing P2P-only Demo pending a concrete option.+- **Phone as a Host microphone.** Revisit only for a concrete use case that+ justifies the [pairing and input boundary](./research/camera-and-microphone.md#phone-microphone-assessment).+- **Mobile controlled endpoints.** Separate scope from desktop keyboard/mouse+ control and the co-play prototypes above.+- **Android App assessment.** Evaluate native phone screen sharing and source+ audio beyond the existing mobile Browser features. Start with Android's+ [MediaProjection](https://developer.android.com/media/grow/media-projection)+ permission/foreground-service lifecycle and+ [playback-capture limits](https://developer.android.com/media/platform/av-capture),+ then assess reuse of the Go room/transport core. This is separate from the+ current voice candidate; a website wrapper alone does not add screen capture.+- **Multiple simultaneous sharers.** Define publication/subscription ownership+ before prototyping. The [party-mode assessment](./research/room-interactions.md#multiple-sharers-assessment-not-implemented)+ owns the proposal; the current one-Host contract remains.diff --git a/docs/verification-status.md b/docs/verification-status.mdindex 4f408dab..34500e7c 100644--- a/docs/verification-status.md+++ b/docs/verification-status.md@@ -1,183 +1,55 @@# Verification Status-Last updated: 2026-10-19+Last updated: 2026-10-21-This file owns physical evidence limits that change how the product may be-described. [Status](./status.md) owns the execution/deployment index.-Product modules own behavior; research owns measurements; Git owns completed-implementation and obsolete package history.+This file summarizes evidence boundaries that materially affect product claims.+[Status](./status.md) owns candidate and deployment readiness; research owns+measurements and platform details.## Current Evidence-Windows App and Browser are the owner's primary acceptance targets. Current-Go packages embed their Web assets and do not run a Node backend.-[Status](./status.md#accepted-release-contract) owns the accepted contract tuple-and current release boundary; artifacts own the exact published build.+Windows App and Browser are the primary acceptance targets. Room voice+passed the normal Host/Viewer flows on P2P and embedded SFU, including+channel activation, forwarding, source replacement and recovery. Controlled voice+checks cover Browser/App endpoint combinations, SFU fallback and UDP interruption;+they do not establish a population connection rate. Native H264/VP8,+constrained-network recovery, the media lifecycle, responsive UI and packaging+checks also passed. Exact results stay with their measured artifacts and revision.-Bounded current checks cover:--- Native H264/VP8 output, compatible encoding reuse, different weak-budget- grouping, keyframe-safe retarget and independent retirement;-- Windows live/paused/quiet-source settings, source replacement and subsequent- sharing, including media-object continuity where required;-- Native H264 SFU video and decoded Opus through a profile change and closure;-- Browser-to-App fanout and App-exit fallback;-- concurrent Native sessions with independent media and retirement;-- complete large encoded access-unit transport and bounded queue/cache behavior;-- Linux container startup as non-root with a read-only filesystem, memory/SQLite- restart semantics, diagnostics export, STUN and listener lifecycle; and-- public embedded-SFU H264/VP8, audio, live profile changes and closure after the- coordinated production cutover.--The owner confirmed Windows 10 whole-display capture resolved. Chromium-WebRTC/IP-handling policy explains the verified local-media failure; it is a-Browser policy limitation, not a Vivaldi-specific transport workaround.--The Windows capture-border control and borderless previews have physical-Windows 11 evidence. Unsupported Windows and actual border-permission denial-remain device checks. The optional Windows 10 Windhawk procedure is documented-from its author and has not been tested with Piik on Windows 10.--NAT traversal and Auto codec selection are implemented features, not unfinished-functionality. On 2026-09-09 the owner confirmed that the new NAT traversal is-useful in actual use. That field confirmation is accepted; it does not claim a-population success percentage or identify which candidate won without a trace.-Neither a statistical NAT campaign nor exhaustive Auto hardware benchmarking-is required to close this phase. Investigate further only from a new failure-or a measured improvement worth its implementation and maintenance cost.+The owner accepted the earlier scoped interaction, Native and Browser media+phases, including NAT and Auto codec behavior.## Device Evidence Boundary-Attended keyboard/mouse control has Windows physical input and local routed-acceptance for consent, revocation, held-key release and source geometry.-Browser checks cover mobile touch/zoom/keyboard emulation, detached tools and-Viewer playback preferences. Physical Android/iOS controllers, mixed-DPI displays,-commercial games and an actual remote-device session remain unverified.-macOS builds and packaging pass; Finder/Accessibility, focus, Retina and input-still need a Mac. Linux compilation and synthetic input/release pass, while-desktop Portal permissions and capture/input need physical acceptance. The-[remote-control assessment](./research/room-interactions.md#attended-remote-control-prototype)-owns the mechanism and game-input limits. These limits do not claim parity with-dedicated remote-control products.--Windows HDR-to-SDR has synthetic FP16 conversion and decoded-H.264/VP8 Browser reception evidence. Local displays were in SDR mode; real HDR-content, SDR white on HDR displays, mixed-display movement, display-mode changes-and sustained GPU contention still require physical acceptance. The-[fidelity assessment](./research/media-fidelity.md#hdr-to-sdr) owns measurements.-These checks do not establish Browser-capture HDR behavior or end-to-end HDR.--Windows source-audio exclusion has bounded parent/child tone-isolation and-target-exit evidence. It does not establish coverage of arbitrary process trees-or real voice applications across playback devices. Windows 10 exclusion-activation and tone isolation still need a physical device check. The-[audio assessment](./research/native-client-media.md#windows-audio-exclusion)-owns that distinction.--Room interactions have multi-page Browser evidence for stop/resume, idle-room-join, Host departure/return, reconnect, invitation revocation and event timing.-Responsive Browser checks cover narrow portrait and landscape layouts, but not-real phone keyboards, Safari behavior or every touch/device combination. The-owner accepted this bounded UI/model walkthrough for phase closure; these-physical limits remain open and are not release authorization.--The [numeric media controls](./research/native-client-media.md#media-capability-extension-assessment)-still need physical limited-decoder, camera-orientation, macOS geometry and-sustained game/4K acceptance. Check live changes and source replacement through-relay/SFU, and listen across the [audio control range](./research/browser-screen-audio-quality.md#numeric-bitrate-assessment).-Existing mono/stereo and Windows HDR-to-SDR retain the [fidelity boundary](./research/media-fidelity.md);-additional codecs, surround delivery and end-to-end HDR are not implemented promises.-The [camera and microphone assessment](./research/camera-and-microphone.md)-owns levels, echo, device replacement/native mixing, OBS input synchronization-and phone permission/orientation/background limits.--Passive App attachment needs cross-device Browser-permission checks for first-and saved approval, Site replacement/revocation and Local coexistence. Local-acceptance does not establish every Browser's permission behavior.--The 2026-09-11 functional test acceptance used two genuine Windows App packages-and matching Server source/Web builds under the same private contract. Both App/Site version-directions delivered decoded 1080p H264 from an isolated native test window.-Replacing the Server process preserved SQLite Host authority, private code-entry-policy, Viewer grant/password authorization and App configuration. Already-open-Host/Viewer pages reauthenticated without reloading and completed subsequent-sharing. Exact measured identity belongs to the package descriptors and local-structured acceptance result; Git retains the preparation history.--This is bounded single-machine Windows evidence. The local Server executables-were built for Windows from the matching source; this run did not execute the-Linux release archives. Process replacement used a forced stop on Windows and-does not promise uninterrupted media. It does not cover game/audio endurance,-storage faults or the wider device/network matrix.--The first public release passed real Server/three-platform App packaging and-GitHub/Gitee publication, including anonymous mirror checksum verification.-These packaging checks do not establish physical macOS/Linux capture or expand the device/network evidence-below. [Status](./status.md) owns current publication and activation state.-Intel macOS runners can lack a usable hardware H.264 encoder. In that case,-the VideoToolbox frame self-test is explicitly skipped; compilation and package-startup do not establish Intel hardware capture. Verify it on a physical Intel-Mac with macOS 13 or newer before claiming that device coverage.-Linux x64 and ARM64 use the same Portal/PipeWire/GStreamer capture path.-Package startup and headless native regressions do not establish physical-screen/audio capture or a working hardware H.264 encoder on an ARM64 desktop.-Verify those capabilities on the target device before claiming device coverage.--## Remaining Device And Network Acceptance--The following are broader coverage and endurance tasks, not automatically new-implementation mechanisms:--- heterogeneous public-network P2P and multi-hop Browser/Native/SFU-fed relays;-- Native IPv6 direct connections across separate networks with usable IPv6;- local dual-stack checks establish socket and candidate behavior only;-- Host/Viewer TUN/VPN combinations, migration and all-UDP-blocked bounded failure;-- two-room public SFU load, real-game audio/video synchronization and sustained- packet loss/recovery;-- weaker Hosts at 720p30, 1080p30 and 1080p60, CPU/GPU contention, thermals,- long-running resources and the 20-Viewer bound; and-- physical mobile autoplay, background/lock, page reclamation, rotation,- Wi-Fi/cellular migration and relay survival.--A short 20-Viewer topology run from an earlier revision proves only its tested-invariants; it is not current-contract endurance or a public-network quality-guarantee. A direct postflight with both endpoints on one machine proves public-signaling and local media, not restricted-NAT traversal.--macOS/Linux physical capture/audio/recovery remains explicitly deferred by the-owner. Linux producer compilation and older Mac SDK/package evidence do not-prove the current Windows multi-output adaptation contract on those platforms.+- macOS/Linux builds and bounded native checks are distinct from physical+ capture and input. Physical platform coverage remains limited.+- Windows HDR-to-SDR has synthetic GPU and decoded-video evidence; it does not+ establish Browser-capture HDR conversion or end-to-end HDR. The+ [fidelity assessment](./research/media-fidelity.md#hdr-to-sdr) owns that boundary.+- Audio-exclusion availability follows actual platform capability. The+ [audio assessment](./research/native-client-media.md#windows-audio-exclusion)+ owns supported interfaces and isolation evidence.+- Room-voice acceptance uses synthetic microphones. It establishes the route and+ membership lifecycle, not acoustic echo performance on every physical device.+- Remote-control UI and routed input have local evidence. OS permissions,+ protected/admin applications and game compatibility retain the limits in the+ [input assessment](./research/room-interactions.md#attended-remote-control-prototype).+- A two-device Windows virtual-LAN trial established direct packaged-App web+ access and remote video after scoped firewall permission. Other networks must+ likewise carry HTTP/WebSocket and media UDP. [Virtual LAN research](./research/nat-traversal.md#routed-virtual-lan-discovery)+ owns the measured setup.## Adaptation Boundaries-The [encoder-pool research](./research/webrtc-encoder-pool.md) retains both-successful and unsuccessful observations:--- A prolonged shaped-network run recovered original output about 1.5 seconds- after release and stayed near 30 fps; an earlier twelve-second observation- missed recovery. The cause of that difference is not established.-- H264's stock QP adaptation can take tens of seconds to restore full size.-- Extreme single-core VP8 overload produced multi-second encode gaps that reset- the stock CPU detector's samples. That result does not establish normal-device- or Browser parity and does not authorize custom CPU thresholds.-- Equal effective demands can share; incompatible demands may need more encoders.- Extra fallback outputs, buffers and recovery keyframes have real costs.-- The 360-to-187 encode-call result compares a bounded prototype with independent- encoders. It is not an old-versus-new Native product CPU benchmark.--The earlier borrowed-child Browser experiment failed independent quality and-accounting. The independent producer in ADR-0014 now has bounded H264/VP8-direct/relay, weak-path, lifecycle and A/V evidence on the acceptance candidate;-[its research](./research/browser-local-encoding-pool.md) owns results and limits.-The owner authorized its release on 2026-09-09. Browser relay shares local outputs-among its direct children; it still re-encodes received media. Native/SFU healthy-forwarding remains encoded.+WebRTC and LiveKit own adaptation. The+[encoder-pool research](./research/webrtc-encoder-pool.md) and+[network controls](./research/network-lab.md#sustained-quality-recovery) distinguish+Native recovery fixes from Browser-controlled recovery and sustained-loss limits.+Browser scripts cannot tune the encoder's internal QP thresholds.## Interpretation-Configuration/unit/loopback checks prove their named invariants. Physical results-belong to the tested revision, device and workload. Missing counters remain-unknown. A new diagnostic collector must be checked in a real exported report,-including retention and failed-collector information; logging a method call alone-does not establish useful evidence. Browser/OS suspension remains a physical-limit rather than a keepalive guarantee.+Evidence applies to its tested revision, device and workload. Builds and local+controls establish their named behavior; they do not promise every remote network+or device or a population NAT success rate. Browser/OS suspension is not a+keepalive guarantee.diff --git a/go.mod b/go.modindex ad6e2ed3..62459a5a 100644--- a/go.mod+++ b/go.mod@@ -1,6 +1,6 @@module github.com/TNTcraftHIM/Piik-go 1.27.2+go 1.27.3// Scoped NAT-PMP fixes; provenance and removal criteria: internal/thirdparty/README.md.replace github.com/netbirdio/go-nat => ./internal/thirdparty/go-natdiff --git a/internal/app/app.go b/internal/app/app.goindex 7396f6c1..347f8fec 100644--- a/internal/app/app.go+++ b/internal/app/app.go@@ -2,6 +2,7 @@ package appimport ("context"+ "crypto/tls""encoding/json""errors""fmt"@@ -22,6 +23,7 @@ import ("github.com/TNTcraftHIM/Piik/internal/app/lan""github.com/TNTcraftHIM/Piik/internal/app/launcher""github.com/TNTcraftHIM/Piik/internal/app/loopback"+ "github.com/TNTcraftHIM/Piik/internal/app/mediaedge""github.com/TNTcraftHIM/Piik/internal/app/nativeaudio""github.com/TNTcraftHIM/Piik/internal/app/nativecapture""github.com/TNTcraftHIM/Piik/internal/app/nativecontrol"@@ -32,6 +34,7 @@ import (serverconfig "github.com/TNTcraftHIM/Piik/internal/server/config""github.com/TNTcraftHIM/Piik/internal/server/protocol""github.com/TNTcraftHIM/Piik/internal/server/webassets"+ "github.com/TNTcraftHIM/Piik/internal/tlsconfig""golang.org/x/mod/semver")@@ -153,10 +156,11 @@ func Run(ctx context.Context, options Options) (returnedErr error) {nativeMedia := discoverNativeMedia(ctx, options.CaptureProcess)input, inputErr := remoteinput.New(ctx, nativeMedia.capture.RemoteInput)if inputErr != nil {- slog.Warn("Remote-control prototype unavailable", "reason", inputErr)+ slog.Warn("Remote control is unavailable", "reason", inputErr)}defer input.Close()nativeMedia.capabilities.RemoteInput = input != nil+ nativeMedia.capabilities.RemoteStopShortcut = input.SupportsStopShortcut()recordContext := func(selected Options, config appconfig.Config) {if recorder == nil {return@@ -507,13 +511,18 @@ func runLocal(ctx context.Context, options Options, config appconfig.Config,}slog.Debug("piik-client", "event", "mode", "mode", view.mode)options.console.show(view)- listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4zero, Port: options.Port})+ bindAddress := net.IPv4zero+ if !options.Link {+ bindAddress = net.IPv4(127, 0, 0, 1)+ }+ listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: bindAddress, Port: options.Port})if err != nil {return errors.Join(failure.LocalPort, fmt.Errorf("local server port is unavailable: %w", err))}+ listeners := []net.Listener{listener}defer func() {- if listener != nil {- _ = listener.Close()+ for _, owned := range listeners {+ _ = owned.Close()}}()addresses, lanErr := lan.Addresses()@@ -527,6 +536,18 @@ func runLocal(ctx context.Context, options Options, config appconfig.Config,if lanErr != nil && !options.Link {return errors.Join(failure.LocalNetwork, lanErr)}+ if !options.Link {+ configuration, err := tlsconfig.SelfSigned(selectedAddress)+ if err != nil {+ return errors.Join(failure.LocalServer, fmt.Errorf("local HTTPS certificate could not be created: %w", err))+ }+ secureListener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.ParseIP(selectedAddress), Port: options.Port})+ if err != nil {+ return errors.Join(failure.LocalPort, fmt.Errorf("local HTTPS port is unavailable: %w", err))+ }+ listeners = append(listeners, tls.NewListener(secureListener, configuration))+ view.certificate = tlsconfig.Fingerprint(configuration)+ }var tunnel *publictunnel.ProcesspublicOrigin := ""if options.Link {@@ -565,17 +586,21 @@ func runLocal(ctx context.Context, options Options, config appconfig.Config,logger = slog.New(slog.NewTextHandler(options.console.logWriter(), nil))}localServer, err := serverapp.New(serverapp.Options{- Config: localConfig,- Listener: listener,- Assets: webassets.FS(),- Logger: logger,+ Config: localConfig,+ Listeners: listeners,+ Assets: webassets.FS(),+ Logger: logger,})if err != nil {return errors.Join(failure.LocalServer, err)}- listener = nil // Ownership is now in the application's startup/shutdown path.+ listeners = nil // Ownership is now in the application's startup/shutdown path.defer func() { returnedErr = errors.Join(returnedErr, endLocalServer(localServer)) }()if _, err = localServer.Listen(ctx); err != nil {+ var socketError *net.OpError+ if errors.As(err, &socketError) && socketError.Op == "listen" {+ return errors.Join(failure.LocalPort, err)+ }return errors.Join(failure.LocalServer, err)}slog.Debug("piik-client", "event", "local-server-ready", "port", options.Port, "publicLink", publicOrigin != "")@@ -591,7 +616,8 @@ func runLocal(ctx context.Context, options Options, config appconfig.Config,if publicOrigin != "" {fmt.Printf("Public invitation origin: %s\n", publicOrigin)} else {- fmt.Printf("LAN invitation origin: http://%s:%d\n", selectedAddress, options.Port)+ fmt.Printf("LAN invitation origin: %s\n", serverconfig.Origin(localConfig.PublicBaseURL))+ fmt.Printf("LAN certificate SHA-256: %s\n", view.certificate)}}launchURL := launchURLWithLocalAccess(@@ -600,7 +626,7 @@ func runLocal(ctx context.Context, options Options, config appconfig.Config,)view.state, view.entry, view.invite = "ready", launchURL, publicOriginif view.invite == "" {- view.invite = fmt.Sprintf("http://%s:%d", selectedAddress, options.Port)+ view.invite = serverconfig.Origin(localConfig.PublicBaseURL)}options.console.show(view)if !options.DisableBrowser {@@ -694,7 +720,7 @@ func discoverNativeMedia(ctx context.Context, configuredPath string) nativeRunticapabilities, err := nativecapture.Discover(ctx, path)if err != nil {return nativeRuntime{captureProcess: path, discoveryErr: err,- capabilities: loopback.NativeMediaCapabilities{ReceiverReuse: true}}+ capabilities: loopback.NativeMediaCapabilities{ReceiverReuse: true, MaxRelayChildren: mediaedge.MaxRelayChildren}}}summary := capabilities.Summary()return nativeRuntime{@@ -710,6 +736,7 @@ func discoverNativeMedia(ctx context.Context, configuredPath string) nativeRuntiMaxVideoBitrate: nativecapture.MaxVideoBitrate,MaxAudioBitrate: nativeaudio.MaxSendBitrate,ReceiverReuse: true,+ MaxRelayChildren: mediaedge.MaxRelayChildren,Video: summary.Video,CaptureBorderControl: summary.CaptureBorderControl,Microphone: summary.Microphone,@@ -722,9 +749,9 @@ func discoverNativeMedia(ctx context.Context, configuredPath string) nativeRunti}}-// localSTUNURLs is the Local room authority's ICE configuration. Only --link-// has a public path, so only --link configures public STUN and the bounded NAT-// prediction survey. Native edges receive ICE configuration from that authority;+// localSTUNURLs supplies public-link discovery. Pure LAN discovery is composed+// by serverconfig.Local on the selected interface. Only --link configures public+// STUN and the bounded NAT prediction survey. Native edges use that authority;// serverconfig.Local deliberately does not inherit Hosted environment settings.// An explicit App override replaces every public destination, including the// survey pair. With fewer than three servers only ordinary ICE is available.diff --git a/internal/app/app_test.go b/internal/app/app_test.goindex 63dcbdae..ebdb71ed 100644--- a/internal/app/app_test.go+++ b/internal/app/app_test.go@@ -672,6 +672,9 @@ func TestMissingCaptureKeepsViewerControlAvailable(t *testing.T) {if native.capabilities.Video || native.capabilities.HardwareH264 {t.Fatalf("missing native capture = %+v", native)}+ if !native.capabilities.ReceiverReuse || native.capabilities.MaxRelayChildren != 20 {+ t.Fatalf("missing capture lost native receiver capability: %+v", native.capabilities)+ }control := native.controlFactory(nil)()if control == nil {t.Fatal("missing capture disabled the native Viewer control")@@ -797,9 +800,16 @@ func TestLocalServerOwnsItsSTUNConfiguration(t *testing.T) {!slices.Equal(natPredictionSTUNURLs, testCase.natPredictionSTUNURLs) {t.Fatalf("Local STUN selection = %v, %v", stunURLs, natPredictionSTUNURLs)}+ publicOrigin := ""+ wantSTUNURLs := []string{"stun:192.168.1.2:8787"}+ if testCase.link {+ publicOrigin = "https://public.example.test"+ wantSTUNURLs = testCase.stunURLs+ }config, err := serverconfig.Local(serverconfig.LocalOptions{Port: 8787,PublicAddress: "192.168.1.2",+ PublicOrigin: publicOrigin,AllowedAddresses: []string{"192.168.1.2"},SiteAccessPassword: "abcdefghijklmnopqrstuvwxyzABCDEF",STUNURLs: stunURLs,@@ -808,7 +818,7 @@ func TestLocalServerOwnsItsSTUNConfiguration(t *testing.T) {if err != nil {t.Fatal(err)}- if !slices.Equal(config.STUNURLs, testCase.stunURLs) ||+ if !slices.Equal(config.STUNURLs, wantSTUNURLs) ||config.NATPredictionEnabled != (len(testCase.natPredictionSTUNURLs) != 0) {t.Fatalf("Local server config = %v, NAT prediction %t",config.STUNURLs, config.NATPredictionEnabled)diff --git a/internal/app/console.go b/internal/app/console.goindex 2eab8642..424dcb12 100644--- a/internal/app/console.go+++ b/internal/app/console.go@@ -25,6 +25,7 @@ import (type consoleView struct {mode, state, entry, invite string+ certificate stringprotected boolproblem errorbrowserError error@@ -113,6 +114,7 @@ var consoleCopy = map[string][3]string{"entry": {"Open in browser", "打开网页", "□"},"launcher": {"App launcher", "App 启动页", "☆"},"invite": {"Site address", "站点地址", "↗"},+ "certificate": {"Local certificate · SHA-256", "本地证书 · SHA-256", "TLS SHA-256"},"access": {"Site access", "站点准入", ""},"open": {"Open", "开放", "○"},"password": {"Password protected", "已设置密码", "*"},@@ -427,6 +429,9 @@ func (model consoleModel) content(styled bool) string {}}accessPicture := ""+ if !compact && model.view.certificate != "" {+ fmt.Fprintf(&out, "\n%s\n%s\n", muted.Render(model.text("certificate")), model.view.certificate)+ }if !compact && model.view.entry != "" && (model.view.mode == "local" || model.view.mode == "link") {access := "open"if model.view.protected {diff --git a/internal/app/local_https_test.go b/internal/app/local_https_test.gonew file mode 100644index 00000000..240505ec--- /dev/null+++ b/internal/app/local_https_test.go@@ -0,0 +1,191 @@+package app++import (+ "context"+ "crypto/sha256"+ "crypto/tls"+ "crypto/x509"+ "encoding/json"+ "errors"+ "fmt"+ "io"+ "net"+ "net/http"+ "net/http/cookiejar"+ "strings"+ "testing"+ "time"++ appconfig "github.com/TNTcraftHIM/Piik/internal/app/config"+ "github.com/TNTcraftHIM/Piik/internal/app/failure"+ "github.com/TNTcraftHIM/Piik/internal/app/lan"+ "github.com/TNTcraftHIM/Piik/internal/app/loopback"+ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+)++func TestLocalHTTPSAndLoopbackShareRoomAuthority(t *testing.T) {+ addresses, err := lan.Addresses()+ if err != nil || len(addresses) == 0 {+ t.Skip("Local App integration needs an active IPv4 interface")+ }+ reservation, err := net.Listen("tcp4", "127.0.0.1:0")+ if err != nil {+ t.Fatal(err)+ }+ port := reservation.Addr().(*net.TCPAddr).Port+ _ = reservation.Close()+ ctx, cancel := context.WithCancel(t.Context())+ control, err := loopback.Start(ctx, loopback.Options{})+ if err != nil {+ cancel()+ t.Fatal(err)+ }+ ready, done := make(chan string, 1), make(chan error, 1)+ go func() {+ done <- runLocal(ctx, Options{Local: true, Port: port, LANAddress: addresses[0],+ DisableBrowser: true, console: newConsole(cancel, true),+ Ready: func(target string) { ready <- target },+ }, appconfig.Config{LocalAccessPassword: "test local passphrase"}, control)+ }()+ t.Cleanup(func() {+ cancel()+ select {+ case err := <-done:+ if err != nil {+ t.Error(err)+ }+ case <-time.After(8 * time.Second):+ t.Error("Local HTTP/TLS service did not retire")+ }+ _ = control.Close()+ for _, address := range []string{"127.0.0.1", addresses[0]} {+ listener, err := net.Listen("tcp4", net.JoinHostPort(address, fmt.Sprint(port)))+ if err != nil {+ t.Errorf("Local listener survived shutdown: %v", err)+ } else {+ _ = listener.Close()+ }+ }+ })+ select {+ case target := <-ready:+ if !strings.HasPrefix(target, fmt.Sprintf("http://127.0.0.1:%d/", port)) {+ t.Fatal("Host lost its stable loopback entry")+ }+ case <-time.After(5 * time.Second):+ t.Fatal("Local App did not become ready")+ }+ lanOrigin := fmt.Sprintf("https://%s:%d", addresses[0], port)+ // Only this isolated fixture accepts its unknown certificate to inspect it.+ // All subsequent requests verify that certificate and the selected LAN IP.+ connection, err := tls.DialWithDialer(&net.Dialer{Timeout: time.Second}, "tcp4",+ net.JoinHostPort(addresses[0], fmt.Sprint(port)), &tls.Config{InsecureSkipVerify: true})+ if err != nil {+ t.Fatal(err)+ }+ certificate := connection.ConnectionState().PeerCertificates[0]+ _ = connection.Close()+ if certificate.IsCA || certificate.VerifyHostname(addresses[0]) != nil ||+ certificate.CheckSignature(certificate.SignatureAlgorithm, certificate.RawTBSCertificate, certificate.Signature) != nil {+ t.Fatal("Local certificate must be self-signed, scoped to the LAN IP and not a CA")+ }+ t.Logf("Local certificate SHA-256: %X", sha256.Sum256(certificate.Raw))+ pool := x509.NewCertPool()+ pool.AddCert(certificate)+ transport := &http.Transport{TLSClientConfig: &tls.Config{RootCAs: pool}}+ t.Cleanup(transport.CloseIdleConnections)+ jar, _ := cookiejar.New(nil)+ client := &http.Client{Transport: transport, Jar: jar, Timeout: 2 * time.Second}+ request := func(origin, path, body string) *http.Response {+ t.Helper()+ req, err := http.NewRequest(http.MethodPost, origin+path, strings.NewReader(body))+ if err != nil {+ t.Fatal(err)+ }+ req.Header.Set("Content-Type", "application/json")+ req.Header.Set("Origin", origin)+ response, err := client.Do(req)+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = response.Body.Close() })+ return response+ }+ for _, origin := range []string{fmt.Sprintf("http://127.0.0.1:%d", port), lanOrigin} {+ login := request(origin, "/api/site-access", `{"password":"test local passphrase"}`)+ cookies := login.Cookies()+ if login.StatusCode != http.StatusOK || len(cookies) != 1 || cookies[0].Secure != strings.HasPrefix(origin, "https:") {+ t.Fatalf("wrong Local admission cookie at %s: status=%d cookies=%v", origin, login.StatusCode, cookies)+ }+ }+ created := request(fmt.Sprintf("http://127.0.0.1:%d", port), "/api/rooms", `{"codeEntryPolicy":"open"}`)+ var room protocol.CreateRoomResponse+ if err := json.NewDecoder(created.Body).Decode(&room); err != nil || created.StatusCode != http.StatusCreated ||+ !strings.HasPrefix(room.InviteURL, lanOrigin+"/r/") {+ t.Fatalf("Local room did not produce its HTTPS invitation: status=%d err=%v", created.StatusCode, err)+ }+ req, _ := http.NewRequest(http.MethodPost, lanOrigin+"/api/rooms/"+room.RoomID+"/access",+ strings.NewReader(`{"action":"set-code-entry-policy","policy":"private"}`))+ req.Header.Set("Origin", lanOrigin)+ req.Header.Set("Content-Type", "application/json")+ req.Header.Set("Authorization", "Bearer "+room.HostToken)+ response, err := client.Do(req)+ if err != nil {+ t.Fatal(err)+ }+ defer response.Body.Close()+ if response.StatusCode != http.StatusOK {+ t.Fatalf("TLS entry did not share loopback room authority: %d", response.StatusCode)+ }+}++func TestLocalPortCollisionReleasesTheOtherEntry(t *testing.T) {+ addresses, err := lan.Addresses()+ if err != nil || len(addresses) == 0 {+ t.Skip("Local App integration needs an active IPv4 interface")+ }+ for _, test := range []struct{ network, address string }{+ {"tcp4", "127.0.0.1"}, {"tcp4", addresses[0]}, {"udp4", addresses[0]},+ } {+ t.Run(test.network+"/"+test.address, func(t *testing.T) {+ var occupied io.Closer+ var port int+ if test.network == "udp4" {+ socket, err := net.ListenPacket("udp4", net.JoinHostPort(test.address, "0"))+ if err != nil {+ t.Fatal(err)+ }+ occupied, port = socket, socket.LocalAddr().(*net.UDPAddr).Port+ } else {+ socket, err := net.Listen("tcp4", net.JoinHostPort(test.address, "0"))+ if err != nil {+ t.Fatal(err)+ }+ occupied, port = socket, socket.Addr().(*net.TCPAddr).Port+ }+ defer occupied.Close()+ control, err := loopback.Start(t.Context(), loopback.Options{})+ if err != nil {+ t.Fatal(err)+ }+ defer control.Close()+ err = runLocal(t.Context(), Options{Local: true, Port: port, LANAddress: addresses[0],+ DisableBrowser: true, console: newConsole(func() {}, true),+ Ready: func(string) { t.Error("occupied Local service reported readiness") },+ }, appconfig.Config{}, control)+ if !errors.Is(err, failure.LocalPort) {+ t.Fatalf("occupied entry error = %v", err)+ }+ for _, otherAddress := range []string{"127.0.0.1", addresses[0]} {+ if test.network == "tcp4" && otherAddress == test.address {+ continue+ }+ listener, err := net.Listen("tcp4", net.JoinHostPort(otherAddress, fmt.Sprint(port)))+ if err != nil {+ t.Fatalf("failed startup left another entry bound: %v", err)+ }+ _ = listener.Close()+ }+ })+ }+}diff --git a/internal/app/loopback/server.go b/internal/app/loopback/server.goindex 55b16768..8cd83de7 100644--- a/internal/app/loopback/server.go+++ b/internal/app/loopback/server.go@@ -83,7 +83,9 @@ type NativeMediaCapabilities struct {MaxVideoBitrate int `json:"maxVideoBitrate,omitempty"`MaxAudioBitrate int `json:"maxAudioBitrate,omitempty"`ReceiverReuse bool `json:"receiverReuse,omitempty"`+ MaxRelayChildren int `json:"maxRelayChildren,omitempty"`RemoteInput bool `json:"remoteInput,omitempty"`+ RemoteStopShortcut bool `json:"remoteStopShortcut,omitempty"`Video bool `json:"video"`CaptureBorderControl bool `json:"captureBorderControl,omitempty"`Microphone bool `json:"microphone,omitempty"`diff --git a/internal/app/loopback/server_test.go b/internal/app/loopback/server_test.goindex 37e0c60f..b2393c69 100644--- a/internal/app/loopback/server_test.go+++ b/internal/app/loopback/server_test.go@@ -21,7 +21,7 @@ const testOrigin = "https://share.example.com"func TestStartServesHealthAndStrictControlHandshake(t *testing.T) {expectedMedia := NativeMediaCapabilities{- Video: true, ProcessAudio: false, SystemAudio: true, HardwareH264: true,+ Video: true, ProcessAudio: false, SystemAudio: true, HardwareH264: true, MaxRelayChildren: 20,}server := startTestServerWithOptions(t, Options{AllowedOrigins: []string{testOrigin},diff --git a/internal/app/mediaedge/audio.go b/internal/app/mediaedge/audio.goindex a3b84050..af47688f 100644--- a/internal/app/mediaedge/audio.go+++ b/internal/app/mediaedge/audio.go@@ -44,7 +44,7 @@ type AudioSource struct {}func (engine *Engine) NewAudioSource(capacity, bitrate int) (*AudioSource, error) {- if capacity < 1 || capacity > 4 {+ if capacity < 1 || capacity > MaxRelayChildren+1 {return nil, errors.New("native audio source capacity is outside the route bound")}encoder, err := nativeaudio.NewEncoder(bitrate)@@ -71,7 +71,7 @@ func (engine *Engine) NewAudioSource(capacity, bitrate int) (*AudioSource, error}func (engine *Engine) NewRelayedAudioSource(capacity int) (*AudioSource, error) {- if capacity < 1 || capacity > 4 {+ if capacity < 1 || capacity > MaxRelayChildren+1 {return nil, errors.New("native audio source capacity is outside the route bound")}engine.mu.Lock()diff --git a/internal/app/mediaedge/engine.go b/internal/app/mediaedge/engine.goindex 390f3bad..a6ccf231 100644--- a/internal/app/mediaedge/engine.go+++ b/internal/app/mediaedge/engine.go@@ -153,12 +153,24 @@ func (engine *Engine) NewSource(codec string, capacity, layers int, requestKeyFrreturn engine.newSource(codec, capacity, layers, nil, requestKeyFrame)}+// MaxRelayChildren bounds a capable native peer's voluntary steady fanout.+const MaxRelayChildren = 20++// PhysicalSourceCapacity reserves the single route operation's overlap without+// changing the ordinary endpoint's existing admission bound.+func PhysicalSourceCapacity(children int) int {+ if children > 3 {+ return children + 1+ }+ return children+}+func (engine *Engine) newSource(codec string, capacity, layers int, relay *RelayOptions, requestKeyFrame func([]int)) (*Source, error) {_, supported := videoCodecs[codec]if !supported {return nil, errors.New("native video codec is unsupported")}- if capacity < 1 || capacity > 4 {+ if capacity < 1 || capacity > MaxRelayChildren+1 {return nil, errors.New("native media source capacity is outside the route bound")}if layers < 1 || layers > 3 {diff --git a/internal/app/mediaedge/relay_capacity_test.go b/internal/app/mediaedge/relay_capacity_test.gonew file mode 100644index 00000000..5866ddc3--- /dev/null+++ b/internal/app/mediaedge/relay_capacity_test.go@@ -0,0 +1,55 @@+package mediaedge++import (+ "errors"+ "fmt"+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/app/nativecapture"+)++func TestVolunteerFanoutSharesBoundedOutputsAndReleasesPhysicalCapacity(t *testing.T) {+ engine, err := NewEngine(EngineOptions{BindAddress: "127.0.0.1:0", IncludeLoopback: true})+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = engine.Close() })+ capacity := PhysicalSourceCapacity(MaxRelayChildren)+ source, err := engine.newSource("vp8", capacity, 2, &RelayOptions{}, nil)+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = source.Close() })+ audio, err := engine.NewRelayedAudioSource(capacity)+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = audio.Close() })+ if err := source.SetRelayProfile(nativecapture.VideoProfile{Width: 1280, Height: 720,+ Framerate: 30, Bitrate: 2_000_000, Preference: "balanced"}); err != nil {+ t.Fatal(err)+ }+ if len(source.outputBitrates) != 2+nativecapture.MaxOutputGroups {+ t.Fatalf("fanout allocated %d encoder outputs", len(source.outputBitrates))+ }+ var edges []*Edge+ for index := range capacity {+ edge, err := engine.NewEdge(source, EdgeOptions{ConnectionID: fmt.Sprintf("child-%d", index), Audio: audio})+ if err != nil {+ t.Fatalf("physical child %d: %v", index, err)+ }+ edges = append(edges, edge)+ }+ if _, err := engine.NewEdge(source, EdgeOptions{ConnectionID: "overflow", Audio: audio}); !errors.Is(err, ErrSourceCapacity) {+ t.Fatalf("overflow admission = %v", err)+ }+ if err := edges[0].Close(); err != nil {+ t.Fatal(err)+ }+ if _, err := engine.NewEdge(source, EdgeOptions{ConnectionID: "replacement", Audio: audio}); err != nil {+ t.Fatalf("retired child did not release both media capacities: %v", err)+ }+ if _, err := engine.NewSource("vp8", capacity+1, 2, nil); err == nil {+ t.Fatal("unbounded native source accepted")+ }+}diff --git a/internal/app/mediaedge/relay_derivation.go b/internal/app/mediaedge/relay_derivation.goindex 5936cd86..3bcb3075 100644--- a/internal/app/mediaedge/relay_derivation.go+++ b/internal/app/mediaedge/relay_derivation.go@@ -85,8 +85,8 @@ func (source *Source) configureRelayFormats() error {if width > 0 && height > 0 {lower.Width, lower.Height = min(width/4*2, lower.Width), min(height/4*2, lower.Height)}- if len(source.outputBitrates) != 2+source.capacity {- source.outputBitrates = make([]uint32, 2+source.capacity)+ if len(source.outputBitrates) != 2+source.outputGroupCapacity() {+ source.outputBitrates = make([]uint32, 2+source.outputGroupCapacity())}for slot := range source.outputBitrates {source.outputBitrates[slot] = lower.Bitrate@@ -220,7 +220,7 @@ func (run *relayRun) serve() {defer close(run.done)defer func() {if cause := context.Cause(run.ctx); cause != nil && !errors.Is(cause, context.Canceled) {- for slot := 0; slot < 2+run.owner.source.capacity; slot++ {+ for slot := 0; slot < 2+run.owner.source.outputGroupCapacity(); slot++ {if slot == 1 {continue}@@ -233,7 +233,7 @@ func (run *relayRun) serve() {}()backend, _ := relayBackend(run.owner.source.codec, &run.owner.options)backend.Preference = run.plan.profile.Preference- backend.Outputs = make([]nativecapture.OutputProfile, run.owner.source.capacity+1)+ backend.Outputs = make([]nativecapture.OutputProfile, run.owner.source.outputGroupCapacity()+1)for slot := range backend.Outputs {backend.Outputs[slot] = run.plan.output}@@ -360,7 +360,7 @@ func (run *relayRun) read(stream *nativecapture.Stream) {}}case nativecapture.FrameH264, nativecapture.FrameVP8:- if frame.Layer > source.capacity || (frame.Kind == nativecapture.FrameH264) != (source.codec == "h264") {+ if frame.Layer > source.outputGroupCapacity() || (frame.Kind == nativecapture.FrameH264) != (source.codec == "h264") {err = errors.New("native relay output does not match its source")break}diff --git a/internal/app/mediaedge/source.go b/internal/app/mediaedge/source.goindex 1e8a51a4..00efd8d4 100644--- a/internal/app/mediaedge/source.go+++ b/internal/app/mediaedge/source.go@@ -64,6 +64,12 @@ type Source struct {func (source *Source) Codec() string { return source.codec }+// Consumers share the existing bounded encoder groups; transport fanout does+// not allocate an encoder per child.+func (source *Source) outputGroupCapacity() int {+ return min(source.capacity, nativecapture.MaxOutputGroups)+}+func (source *Source) SetLowestLayerRateControlled(controlled bool) {source.writeMu.Lock()defer source.writeMu.Unlock()@@ -175,7 +181,7 @@ func (source *Source) beginFrame(timestamp time.Duration, at time.Time) (OutputP// ConfigureOutputs installs one validated capture generation's bitrate bounds.// A zero slot subsequently means that producer has failed, not a new preset.func (source *Source) ConfigureOutputs(ceilings []uint32) error {- if len(ceilings) < len(source.formats) || len(ceilings) > len(source.formats)+source.capacity ||+ if len(ceilings) < len(source.formats) || len(ceilings) > len(source.formats)+source.outputGroupCapacity() ||len(source.formats) != 2 && len(ceilings) != len(source.formats) {return errors.New("native output count does not match the source")}diff --git a/internal/app/nativecapture/stream.go b/internal/app/nativecapture/stream.goindex 16ee8889..ee7f83c2 100644--- a/internal/app/nativecapture/stream.go+++ b/internal/app/nativecapture/stream.go@@ -23,6 +23,7 @@ const (captureStopTimeout = time.SecondmaxPreviewBytes = 192 * 1024maxOutputs = 6+ MaxOutputGroups = maxOutputs - 2minOutputBitrate = 1_000 // Codec rate APIs use whole kbps.MaxVideoBitrate = 240_000_000 // H.264 Level 5.2 Constrained Baseline video bitrate.maxSources = 1024@@ -244,7 +245,7 @@ func PreviewSource(parent context.Context, executable string, target CaptureTargfunc StartVideo(parent context.Context, executable string, options VideoOptions) (*Stream, error) {if !options.Target.Valid() || !options.Profile.Valid() ||(options.Codec != "auto" && options.Codec != "h264" && options.Codec != "vp8") ||- options.OutputGroups < 0 || options.OutputGroups > maxOutputs-2 ||+ options.OutputGroups < 0 || options.OutputGroups > MaxOutputGroups ||len(options.RestoreToken) > 4096 || !utf8.ValidString(options.RestoreToken) ||strings.ContainsRune(options.RestoreToken, 0) {return nil, errors.New("native video target is invalid")diff --git a/internal/app/nativecontrol/session.go b/internal/app/nativecontrol/session.goindex 67e275fd..c843e93a 100644--- a/internal/app/nativecontrol/session.go+++ b/internal/app/nativecontrol/session.go@@ -34,7 +34,7 @@ const (maxSTUNURLBytes = 512maxICEServers = 8maxURLsPerServer = 8- maxEdgeCapacity = 3+ maxEdgeCapacity = mediaedge.MaxRelayChildren)var identityPattern = regexp.MustCompile("^[A-Za-z0-9_-]{8,256}$")@@ -262,6 +262,24 @@ func (session *Session) Handle(ctx context.Context, payload []byte) (result any,return nil, err}return response(envelope, "remote-control-set"), nil+ case "get-remote-stop-shortcut", "set-remote-stop-shortcut":+ var request remoteStopShortcutRequest+ if err := decodeStrict(payload, &request); err != nil || !validIdentities(request.ShareID) ||+ (envelope.Type == "get-remote-stop-shortcut" && request.Key != 0) ||+ (envelope.Type == "set-remote-stop-shortcut" && !remoteinput.ValidStopKey(request.Key)) {+ return nil, protocolViolation("native remote-control shortcut is invalid")+ }+ if session.current(request.ShareID) == nil || !session.remoteInput.SupportsStopShortcut() {+ return nil, errors.New("native remote-control shortcut is unavailable")+ }+ var state remoteinput.StopShortcut+ var err error+ if envelope.Type == "get-remote-stop-shortcut" {+ state, err = session.remoteInput.ReadStopShortcut()+ } else {+ state, err = session.remoteInput.SetStopShortcut(request.Key)+ }+ return remoteStopShortcutResponse{responseEnvelope{envelope.Version, envelope.ID, "remote-stop-shortcut"}, state}, errcase "set-microphone":var request microphoneRequestif err := decodeStrict(payload, &request); err != nil || !validIdentities(request.ShareID) ||diff --git a/internal/app/nativecontrol/session_test.go b/internal/app/nativecontrol/session_test.goindex 7a601c9f..ffa0267a 100644--- a/internal/app/nativecontrol/session_test.go+++ b/internal/app/nativecontrol/session_test.go@@ -104,6 +104,23 @@ func TestReceiveOfferReusePreservesLegacyResponseShape(t *testing.T) {}}+func TestRemoteStopShortcutRequiresAnOwnedShare(t *testing.T) {+ session := New("", nativecapture.Capabilities{}, false, nil)+ t.Cleanup(func() { _ = session.Close() })+ for _, command := range []string{"get-remote-stop-shortcut", "set-remote-stop-shortcut"} {+ key := 0+ if command == "set-remote-stop-shortcut" {+ key = 9+ }+ request := remoteStopShortcutRequest{requestEnvelope: requestEnvelope{10, "request_shortcut", command}, ShareID: "retired_share", Key: key}+ payload, _ := json.Marshal(request)+ result, err := session.Handle(t.Context(), payload)+ if _, ok := result.(requestFailedResponse); !ok || err != nil {+ t.Fatalf("missing share must fail the operation, not the connection: %#v, %v", result, err)+ }+ }+}+func TestMain(tests *testing.M) {if path := os.Getenv("PIIK_SOURCE_LIST_FIXTURE"); path != "" {payload, err := os.ReadFile(path)diff --git a/internal/app/nativecontrol/wire.go b/internal/app/nativecontrol/wire.goindex 2ec6ea6d..fe60456e 100644--- a/internal/app/nativecontrol/wire.go+++ b/internal/app/nativecontrol/wire.go@@ -88,6 +88,17 @@ type remoteControlStateEvent struct {remoteinput.State}+type remoteStopShortcutRequest struct {+ requestEnvelope+ ShareID string `json:"shareId"`+ Key int `json:"key,omitempty"`+}++type remoteStopShortcutResponse struct {+ responseEnvelope+ remoteinput.StopShortcut+}+type audioStateEvent struct {eventEnvelopeSourceAudio bool `json:"sourceAudio"`diff --git a/internal/app/nativehost/audio_test.go b/internal/app/nativehost/audio_test.goindex 13b7a0b6..89353d74 100644--- a/internal/app/nativehost/audio_test.go+++ b/internal/app/nativehost/audio_test.go@@ -6,6 +6,7 @@ import ("encoding/json""io""os"+ "path/filepath""sync/atomic""testing""time"@@ -81,7 +82,31 @@ func runAudioRecoveryCapture() {status, _ = json.Marshal(CaptureState{State: "active", Codec: "vp8",Width: 1280, Height: 720, FPS: 30, Outputs: outputs})}+ marker := os.Getenv("PIIK_AUDIO_WAIT_FOR_VIDEO")+ if audio && marker != "" {+ ticker := time.NewTicker(5 * time.Millisecond)+ defer ticker.Stop()+ for {+ if _, err := os.Stat(marker); err == nil {+ break+ }+ select {+ case <-stopped:+ return+ case <-ticker.C:+ }+ }+ }write(nativecapture.Frame{Kind: nativecapture.FrameStatus, Data: status})+ if !audio && marker != "" {+ // Exceed the OS pipe buffer before allowing audio initialization to finish.+ data := make([]byte, 256*1024)+ copy(data, sfu.VP8KeyFrame8x8)+ write(nativecapture.Frame{Kind: nativecapture.FrameBegin, Duration: period})+ write(nativecapture.Frame{Kind: nativecapture.FrameVP8, Layer: 1, Width: 8, Height: 8,+ Duration: period, KeyFrame: true, Data: data})+ _ = os.WriteFile(marker, nil, 0600)+ }if audio && os.Getenv("PIIK_AUDIO_STARTUP") == "silent" {<-stoppedreturn@@ -113,9 +138,12 @@ func TestAudioStartupDoesNotRequireSamplesOrStopVideo(t *testing.T) {if err != nil {t.Fatal(err)}- for _, mode := range []string{"silent", "no-ready"} {+ for _, mode := range []string{"silent", "no-ready", "drain-video"} {t.Run(mode, func(t *testing.T) {t.Setenv("PIIK_AUDIO_STARTUP", mode)+ if mode == "drain-video" {+ t.Setenv("PIIK_AUDIO_WAIT_FOR_VIDEO", filepath.Join(t.TempDir(), "video-drained"))+ }ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)defer cancel()video := nativecapture.VideoOptions{Codec: "vp8", Profile: audioRecoveryProfile(),@@ -127,7 +155,7 @@ func TestAudioStartupDoesNotRequireSamplesOrStopVideo(t *testing.T) {t.Fatal(err)}defer session.Close()- if session.Codec() != "vp8" || session.HasAudio() != (mode == "silent") {+ if session.Codec() != "vp8" || session.HasAudio() != (mode != "no-ready") {t.Fatalf("codec=%s audio=%v for %s", session.Codec(), session.HasAudio(), mode)}cancel()diff --git a/internal/app/nativehost/session.go b/internal/app/nativehost/session.goindex 5e4edfb4..6749a051 100644--- a/internal/app/nativehost/session.go+++ b/internal/app/nativehost/session.go@@ -119,6 +119,9 @@ func Start(parent context.Context, options Options) (*Session, error) {if options.ShareID == "" || len(options.ShareID) > 256 {return nil, errors.New("native share identity is invalid")}+ if options.EdgeCapacity < 1 || options.EdgeCapacity > mediaedge.MaxRelayChildren {+ return nil, errors.New("native share edge capacity is invalid")+ }if !options.Profile.Valid() || options.Video.Profile != options.Profile.Video {return nil, errors.New("native share profile is invalid")}@@ -131,25 +134,12 @@ func Start(parent context.Context, options Options) (*Session, error) {if err != nil {return nil, err}- options.Video.OutputGroups = options.EdgeCapacity+ options.Video.OutputGroups = min(options.EdgeCapacity, nativecapture.MaxOutputGroups)stream, err := nativecapture.StartVideo(parent, options.CaptureProcess, options.Video)if err != nil {_ = engine.Close()return nil, err}- var audioStream *nativecapture.Stream- if options.AudioEnabled {- var audioErr error- audioStream, audioErr = startAudioCapture(- parent,- options.CaptureProcess,- options.Video.Target,- options.ExcludeAudio,- )- if audioErr != nil {- slog.DebugContext(parent, "piik-client", "event", "capture-audio-unavailable", "share", diagnostics.ID(options.ShareID), diagnostics.Error(audioErr))- }- }ctx, cancel := context.WithCancel(parent)session := &Session{shareID: options.ShareID,@@ -158,7 +148,6 @@ func Start(parent context.Context, options Options) (*Session, error) {profile: options.Profile,edgeCapacity: options.EdgeCapacity,stream: stream,- audioStream: audioStream,engine: engine,events: options.Events,ctx: ctx,@@ -170,9 +159,44 @@ func Start(parent context.Context, options Options) (*Session, error) {remoteInput: options.RemoteInput.NewSession(),}session.syncRemoteInputSource(nil)+ // Drain video while the optional audio process initializes. Otherwise a full+ // video pipe can stall the platform capture service that audio also needs.+ videoDone := make(chan error, 1)+ go func() { videoDone <- session.runVideo() }()+ var timeout <-chan time.Time+ if options.Video.Target.Kind != "picker" {+ timer := time.NewTimer(startTimeout)+ defer timer.Stop()+ timeout = timer.C+ }+ select {+ case err = <-session.ready:+ case <-timeout:+ err = errors.New("native capture did not start in time")+ case <-parent.Done():+ err = parent.Err()+ }+ if err != nil {+ cancel()+ _ = stream.Close()+ <-videoDone+ session.retire()+ return nil, err+ }+ // Start the optional audio helper only after video initialization, avoiding+ // concurrent platform source enumeration while continuing to drain video.+ var audioStream *nativecapture.Stream+ if options.AudioEnabled {+ var audioErr error+ audioStream, audioErr = startAudioCapture(ctx, options.CaptureProcess, options.Video.Target, options.ExcludeAudio)+ if audioErr != nil {+ slog.DebugContext(ctx, "piik-client", "event", "capture-audio-unavailable", "share", diagnostics.ID(options.ShareID), diagnostics.Error(audioErr))+ }+ session.audioStream = audioStream+ }if audioStream != nil || options.MicrophoneMixing {audioSource, audioErr := engine.NewAudioSource(- options.EdgeCapacity, options.Profile.AudioBitrate,+ mediaedge.PhysicalSourceCapacity(options.EdgeCapacity), options.Profile.AudioBitrate,)if audioErr != nil {slog.DebugContext(ctx, "piik-client", "event", "capture-audio-source-failed", "share", diagnostics.ID(options.ShareID), diagnostics.Error(audioErr))@@ -189,34 +213,19 @@ func Start(parent context.Context, options Options) (*Session, error) {if session.audioSource == nil {cancel()_ = stream.Close()- _ = engine.Close()+ <-videoDone+ session.retire()return nil, errors.New("native mixed audio could not start")}session.mixer = &audioMix{ctx: ctx, output: session.audioSource, emit: session.emit, shareID: session.shareID, gain: 1}session.mixer.setSource(audioStream)}- go session.run()- var timeout <-chan time.Time- var timer *time.Timer- if options.Video.Target.Kind != "picker" {- timer = time.NewTimer(startTimeout)- timeout = timer.C- defer timer.Stop()- }- select {- case err = <-session.ready:- if err != nil {- _ = session.Close()- return nil, err- }- return session, nil- case <-timeout:- _ = session.Close()- return nil, errors.New("native capture did not start in time")- case <-parent.Done():+ go session.run(videoDone)+ if err := ctx.Err(); err != nil {_ = session.Close()- return nil, parent.Err()+ return nil, err}+ return session, nil}func (session *Session) ShareID() string {@@ -450,7 +459,7 @@ func (session *Session) ReplaceSource(options.Codec = session.videoOptions.Codecoptions.AdapterIndex = session.videoOptions.AdapterIndexoptions.EncoderIndex = session.videoOptions.EncoderIndex- options.OutputGroups = session.edgeCapacity+ options.OutputGroups = min(session.edgeCapacity, nativecapture.MaxOutputGroups)hasAudio := session.audioSource != nil && session.audioStream != nilcurrentTarget := session.videoOptions.TargetaudioOnly := options.Target.Kind != "picker" &&@@ -610,7 +619,7 @@ func (session *Session) prepareVideo(if err := ctx.Err(); err != nil {return nil, CaptureState{}, err}- options.OutputGroups = session.edgeCapacity+ options.OutputGroups = min(session.edgeCapacity, nativecapture.MaxOutputGroups)// Preparation can be cancelled independently. Installed capture always lives// with the share; cancelling a permission request must not kill its process.replacement, err := nativecapture.StartVideo(@@ -825,11 +834,7 @@ func (session *Session) edge(connectionID string) *mediaedge.Edge {return session.edges[connectionID]}-func (session *Session) run() {- videoDone := make(chan error, 1)- go func() {- videoDone <- session.runVideo()- }()+func (session *Session) run(videoDone <-chan error) {audioDone := make(chan struct{})qualityDone := make(chan struct{})go func() {@@ -937,7 +942,7 @@ func (session *Session) runVideo() error {session.mu.Unlock()return fail(errors.New("native capture codec was not applied"))}- source, sourceErr := session.engine.NewSource(status.Codec, session.edgeCapacity, min(2, len(status.Outputs)), func(layers []int) {+ source, sourceErr := session.engine.NewSource(status.Codec, mediaedge.PhysicalSourceCapacity(session.edgeCapacity), min(2, len(status.Outputs)), func(layers []int) {if stream := session.currentStream(); stream != nil {for _, layer := range layers {_ = stream.RequestKeyFrame(layer)@@ -1169,11 +1174,6 @@ func waitForCaptureProfile(return}if state.State == "active" {- if state.Width != profile.Width || state.Height != profile.Height ||- state.FPS != profile.Framerate {- send(result{stage: "profile-mismatch", err: errors.New("native capture profile was not applied")})- return- }state.AdapterIndex, state.EncoderIndex = starting.AdapterIndex, starting.EncoderIndexstate.unavailableLayers = unavailablesend(result{state: state})@@ -1341,11 +1341,12 @@ func decodeCaptureState(payload []byte) (CaptureState, error) {return CaptureState{}, errors.New("native capture starting state is incomplete")}original := state.Outputs[min(1, len(state.Outputs)-1)]+ // Output profiles are ceilings; aspect-preserving capture may be smaller.if state.State == "active" &&((state.Codec == "h264" && !nativecapture.SupportedH264ProfileLevelID(state.ProfileLevelID)) ||(state.Codec == "vp8" && state.ProfileLevelID != "") ||- state.Width != original.Width ||- state.Height != original.Height ||+ !nativecapture.ValidVideoSize(state.Width, state.Height) ||+ state.Width > original.Width || state.Height > original.Height ||state.FPS != original.Framerate ||len(state.RestoreToken) > 4096 || !utf8.ValidString(state.RestoreToken) ||strings.ContainsRune(state.RestoreToken, 0)) {diff --git a/internal/app/nativehost/session_test.go b/internal/app/nativehost/session_test.goindex 05802db2..490ac17b 100644--- a/internal/app/nativehost/session_test.go+++ b/internal/app/nativehost/session_test.go@@ -154,7 +154,9 @@ func TestCaptureCommitWaitsForReaderMetadataOrTermination(t *testing.T) {}return}- go session.run()+ videoDone := make(chan error, 1)+ go func() { videoDone <- session.runVideo() }()+ go session.run(videoDone)closed := make(chan error, 1)if mode == "closed" {go func() { closed <- session.Close() }()@@ -342,12 +344,21 @@ func TestPreparedCaptureOutlivesItsPermissionOperation(t *testing.T) {}}-func TestCaptureProfileRetainsSelectedBackendFromStarting(t *testing.T) {+func TestCaptureProfileRetainsSelectedBackendAndFittedSize(t *testing.T) {t.Setenv("PIIK_NATIVEHOST_PIPE_FIXTURE", "backend")t.Setenv("PIIK_CAPTURE_STARTING", string(captureStatePayload(t,`{"state":"starting","hardwareOnly":true,"codec":"h264","adapterIndex":1,"adapterName":"GPU","adapterIdentity":"0:1","encoderIndex":2,"encoderName":"H264","encoderIdentity":"encoder"}`)))- t.Setenv("PIIK_CAPTURE_ACTIVE", string(captureStatePayload(t,- `{"state":"active","hardwareOnly":true,"codec":"h264","profileLevelId":"42c01f","width":1280,"height":720,"fps":30}`)))+ var active CaptureState+ if err := json.Unmarshal(captureStatePayload(t,+ `{"state":"active","hardwareOnly":true,"codec":"h264","profileLevelId":"42c01f","width":1280,"height":720,"fps":30}`), &active); err != nil {+ t.Fatal(err)+ }+ active.Width, active.Height = 640, 480+ payload, err := json.Marshal(active)+ if err != nil {+ t.Fatal(err)+ }+ t.Setenv("PIIK_CAPTURE_ACTIVE", string(payload))executable, err := os.Executable()if err != nil {t.Fatal(err)@@ -376,6 +387,9 @@ func TestCaptureProfileRetainsSelectedBackendFromStarting(t *testing.T) {if state.AdapterIndex == nil || *state.AdapterIndex != 1 || state.EncoderIndex == nil || *state.EncoderIndex != 2 {t.Fatalf("active profile lost the actual hardware selection: %+v", state)}+ if state.Width != 640 || state.Height != 480 {+ t.Fatalf("active profile lost the actual fitted size: %+v", state)+ }var unavailable []intif failed != "" {layer, _ := strconv.Atoi(failed)@@ -487,11 +501,11 @@ func TestCaptureStateUsesOriginalSlotAndBoundsPhysicalGroups(t *testing.T) {if err != nil || len(state.Outputs) != 6 || state.Outputs[5] != state.Outputs[0] {t.Fatalf("independent output groups = %+v, %v", state, err)}- wrongOriginal := state- wrongOriginal.Width = state.Outputs[5].Width+ oversized := state+ oversized.Width = state.Outputs[1].Width + 2tooMany := statetooMany.Outputs = append(tooMany.Outputs, tooMany.Outputs[0])- for _, invalid := range []CaptureState{wrongOriginal, tooMany} {+ for _, invalid := range []CaptureState{oversized, tooMany} {payload, err := json.Marshal(invalid)if err != nil {t.Fatal(err)diff --git a/internal/app/nativeviewer/session.go b/internal/app/nativeviewer/session.goindex d31e1bb9..a7b4a233 100644--- a/internal/app/nativeviewer/session.go+++ b/internal/app/nativeviewer/session.go@@ -77,7 +77,7 @@ func Start(parent context.Context, options Options) (*Session, error) {parent = context.Background()}if options.ShareID == "" || len(options.ShareID) > 256 ||- options.EdgeCapacity < 1 || options.EdgeCapacity > 3 {+ options.EdgeCapacity < 1 || options.EdgeCapacity > mediaedge.MaxRelayChildren {return nil, errors.New("native Viewer session input is invalid")}engine, err := mediaedge.NewEngine(mediaedge.EngineOptions{@@ -176,7 +176,7 @@ func (session *Session) AcceptOffer(mediaReceiver, answer, err := session.engine.NewReceiver(mediaedge.ReceiverOptions{Offer: offer,ICEServers: iceServers,- EdgeCapacity: session.edgeCapacity,+ EdgeCapacity: mediaedge.PhysicalSourceCapacity(session.edgeCapacity),Relay: session.relay,PunchedSocket: punchedSocket,Events: mediaedge.ReceiverEvents{diff --git a/internal/app/remoteinput/manager.go b/internal/app/remoteinput/manager.goindex 71ffbd2f..7c58fe46 100644--- a/internal/app/remoteinput/manager.go+++ b/internal/app/remoteinput/manager.go@@ -57,12 +57,16 @@ type View struct {// One manager covers both native sessions: they operate the same physical desktop.type Manager struct {- mu sync.Mutex- sink inputSink- connections map[endpointKey]*connection- active *connection- closed bool- stop context.CancelFunc+ mu sync.Mutex+ sink inputSink+ connections map[endpointKey]*connection+ sessions map[*Session]struct{}+ active *connection+ closed bool+ stop context.CancelFunc+ stopKey int+ registerStop func(int) (func(), error)+ stopShortcut func()}type Session struct {@@ -107,13 +111,18 @@ func New(ctx context.Context, captureInput bool) (*Manager, error) {return nil, err}ctx, cancel := context.WithCancel(ctx)- m := &Manager{sink: sink, connections: make(map[endpointKey]*connection), stop: cancel}- if err := watchStopShortcut(ctx, func() { m.Revoke() }); err != nil {- cancel()- if closer, ok := sink.(io.Closer); ok {- _ = closer.Close()+ m := &Manager{sink: sink, connections: make(map[endpointKey]*connection), stop: cancel,+ stopKey: defaultStopKey}+ stopPressed := make(chan struct{}, 1)+ if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {+ m.registerStop = func(key int) (func(), error) {+ return watchStopShortcut(ctx, key, func() {+ select {+ case stopPressed <- struct{}{}:+ default:+ }+ })}- return nil, err}// Foreground changes must release held input even when the remote player// is holding a key without sending more events. Only an active grant polls.@@ -124,6 +133,8 @@ func New(ctx context.Context, captureInput bool) (*Manager, error) {select {case <-ctx.Done():return+ case <-stopPressed:+ m.Revoke()case <-ticker.C:m.mu.Lock()m.refreshActive()@@ -138,8 +149,17 @@ func (m *Manager) NewSession() *Session {if m == nil {return nil}+ m.mu.Lock()+ defer m.mu.Unlock()+ if m.closed {+ return nil+ }s := &Session{manager: m, changed: make(chan struct{}, 1), mode: "off"}s.route = inputroute.New(s.receivePacket)+ if m.sessions == nil {+ m.sessions = make(map[*Session]struct{})+ }+ m.sessions[s] = struct{}{}return s}@@ -500,6 +520,8 @@ func (s *Session) Close() {delete(m.connections, id)}}+ delete(m.sessions, s)+ m.releaseIdleShortcut()s.notify()m.mu.Unlock()s.route.Close()@@ -527,10 +549,15 @@ func (m *Manager) Close() {}m.closed = truem.release()+ stopShortcut := m.stopShortcut+ m.stopShortcut = nilif closer, ok := m.sink.(io.Closer); ok {_ = closer.Close()}m.mu.Unlock()+ if stopShortcut != nil {+ stopShortcut()+ }if m.stop != nil {m.stop()}diff --git a/internal/app/remoteinput/platform_darwin.go b/internal/app/remoteinput/platform_darwin.goindex 523aa86a..def982e3 100644--- a/internal/app/remoteinput/platform_darwin.go+++ b/internal/app/remoteinput/platform_darwin.go@@ -186,8 +186,12 @@ func (s *macSink) Close() error {return nil}-func watchStopShortcut(ctx context.Context, stop func()) error {+func watchStopShortcut(ctx context.Context, key int, stop func()) (func(), error) {+ ctx, cancel := context.WithCancel(ctx)+ done := make(chan struct{})+ code := macKeyCodes["F"+strconv.Itoa(key)]go func() {+ defer close(done)ticker := time.NewTicker(100 * time.Millisecond)defer ticker.Stop()held := false@@ -196,7 +200,7 @@ func watchStopShortcut(ctx context.Context, stop func()) error {case <-ctx.Done():returncase <-ticker.C:- pressed := bool(C.piik_input_stop_pressed())+ pressed := bool(C.piik_input_stop_pressed(C.uint16_t(code)))if pressed && !held {stop()}@@ -204,7 +208,7 @@ func watchStopShortcut(ctx context.Context, stop func()) error {}}}()- return nil+ return func() { cancel(); <-done }, nil}// Physical KeyboardEvent.code -> macOS virtual key, independent of text/IME.diff --git a/internal/app/remoteinput/platform_darwin.h b/internal/app/remoteinput/platform_darwin.hindex 95e4edec..86d612b8 100644--- a/internal/app/remoteinput/platform_darwin.h+++ b/internal/app/remoteinput/platform_darwin.h@@ -23,4 +23,4 @@ bool piik_input_pointer(CGEventSourceRef source, double x, double y,uint64_t flags, PiikInputClick *click);bool piik_input_scroll(CGEventSourceRef source, int32_t delta, uint64_t flags);bool piik_input_text(CGEventSourceRef source, const uint16_t *text, size_t length);-bool piik_input_stop_pressed(void);+bool piik_input_stop_pressed(uint16_t key);diff --git a/internal/app/remoteinput/platform_darwin.m b/internal/app/remoteinput/platform_darwin.mindex 69e23664..0c057544 100644--- a/internal/app/remoteinput/platform_darwin.m+++ b/internal/app/remoteinput/platform_darwin.m@@ -155,10 +155,12 @@ bool piik_input_text(CGEventSourceRef source, const uint16_t *text, size_t lengtreturn post(down, 0) && post(up, 0);}-bool piik_input_stop_pressed(void) {+bool piik_input_stop_pressed(uint16_t key) {// Inspect only the local emergency chord; no event tap or key log.CGEventSourceStateID state = kCGEventSourceStateHIDSystemState;return (CGEventSourceKeyState(state, 59) || CGEventSourceKeyState(state, 62)) &&(CGEventSourceKeyState(state, 58) || CGEventSourceKeyState(state, 61)) &&- CGEventSourceKeyState(state, 109); // Control + Option + F10+ !CGEventSourceKeyState(state, 54) && !CGEventSourceKeyState(state, 55) &&+ !CGEventSourceKeyState(state, 56) && !CGEventSourceKeyState(state, 60) &&+ CGEventSourceKeyState(state, key);}diff --git a/internal/app/remoteinput/platform_linux.go b/internal/app/remoteinput/platform_linux.goindex 5b5328c6..93d95fef 100644--- a/internal/app/remoteinput/platform_linux.go+++ b/internal/app/remoteinput/platform_linux.go@@ -85,7 +85,7 @@ func (s *portalSink) Reset() error {// The compositor owns its global stop shortcut. The page's stop action/chord// remains available; we do not grab global keys or request a second permission.-func watchStopShortcut(context.Context, func()) error { return nil }+func watchStopShortcut(context.Context, int, func()) (func(), error) { return func() {}, nil }func evdevCode(code string) uint16 {if scan := scanCodes[code]; scan > 0 && scan <= 0x58 {diff --git a/internal/app/remoteinput/platform_stub.go b/internal/app/remoteinput/platform_stub.goindex a6502b7d..f36fa227 100644--- a/internal/app/remoteinput/platform_stub.go+++ b/internal/app/remoteinput/platform_stub.go@@ -6,5 +6,5 @@ import ("context")-func newPlatformSink(bool) (inputSink, error) { return nil, nil }-func watchStopShortcut(context.Context, func()) error { return nil }+func newPlatformSink(bool) (inputSink, error) { return nil, nil }+func watchStopShortcut(context.Context, int, func()) (func(), error) { return func() {}, nil }diff --git a/internal/app/remoteinput/platform_windows.go b/internal/app/remoteinput/platform_windows.goindex bb59595f..704e7bf2 100644--- a/internal/app/remoteinput/platform_windows.go+++ b/internal/app/remoteinput/platform_windows.go@@ -182,9 +182,12 @@ func (s *windowsSink) Reset() error {// A native hotkey supplies local revocation even while a Browser has focus.// It observes this shortcut only; no keyboard hook or key recording is installed.-func watchStopShortcut(ctx context.Context, stop func()) error {+func watchStopShortcut(ctx context.Context, key int, stop func()) (func(), error) {+ ctx, cancel := context.WithCancel(ctx)ready := make(chan error, 1)+ done := make(chan struct{})go func() {+ defer close(done)runtime.LockOSThread()defer runtime.UnlockOSThread()tid := windows.GetCurrentThreadId()@@ -198,15 +201,13 @@ func watchStopShortcut(ctx context.Context, stop func()) error {Private uint32}user32.NewProc("PeekMessageW").Call(uintptr(unsafe.Pointer(&msg)), 0, 0, 0, 0)- ok, _, _ := user32.NewProc("RegisterHotKey").Call(0, 1, 0x4003, 0x79) // Ctrl+Alt+F10; no repeat.+ ok, _, _ := user32.NewProc("RegisterHotKey").Call(0, 1, 0x4003, uintptr(0x6f+key)) // Ctrl+Alt+Fn; no repeat.if ok == 0 {- ready <- errors.New("Ctrl+Alt+F10 is already in use")+ ready <- errors.New("remote-control shortcut is already in use")return}defer user32.NewProc("UnregisterHotKey").Call(0, 1)ready <- nil- done := make(chan struct{})- defer close(done)go func() {select {case <-ctx.Done():@@ -224,5 +225,10 @@ func watchStopShortcut(ctx context.Context, stop func()) error {}}}()- return <-ready+ if err := <-ready; err != nil {+ cancel()+ <-done+ return nil, err+ }+ return func() { cancel(); <-done }, nil}diff --git a/internal/app/remoteinput/platform_windows_test.go b/internal/app/remoteinput/platform_windows_test.goindex df426c7d..619ef3ff 100644--- a/internal/app/remoteinput/platform_windows_test.go+++ b/internal/app/remoteinput/platform_windows_test.go@@ -3,10 +3,55 @@package remoteinputimport (+ "context""testing""unsafe")+func TestNativeStopShortcutRegistrationLifetime(t *testing.T) {+ // Reserve an available chord through the OS API without injecting input.+ var reserved func()+ var key int+ for key = 1; key <= 11; key++ {+ var err error+ reserved, err = watchStopShortcut(t.Context(), key, func() {})+ if err == nil {+ break+ }+ }+ if reserved == nil {+ t.Fatal("no test shortcut is available")+ }+ t.Cleanup(reserved)+ m, err := New(t.Context(), false)+ if err != nil || m == nil {+ t.Fatalf("hotkey collision disabled the input backend: %v", err)+ }+ t.Cleanup(m.Close)+ m.stopKey = key+ state, err := m.ReadStopShortcut()+ if err != nil || state.Available {+ t.Fatalf("reserved chord was reported usable: %+v, %v", state, err)+ }+ reserved()+ state, err = m.ReadStopShortcut()+ if err != nil || !state.Available {+ t.Fatalf("released chord was not available: %+v, %v", state, err)+ }+ ctx, cancel := context.WithCancel(t.Context())+ stop, err := watchStopShortcut(ctx, key, func() {})+ if err != nil {+ t.Fatal(err)+ }+ cancel()+ stop()+ stop, err = watchStopShortcut(t.Context(), key, func() {})+ if err != nil {+ t.Fatalf("cancelled watcher retained its chord: %v", err)+ }+ stop()+}+func TestCommittedTextPackets(t *testing.T) {inputs := textInputs("A中😀")units := []uint16{0x41, 0x4e2d, 0xd83d, 0xde00}diff --git a/internal/app/remoteinput/policy.go b/internal/app/remoteinput/policy.goindex 11104b65..0436d469 100644--- a/internal/app/remoteinput/policy.go+++ b/internal/app/remoteinput/policy.go@@ -79,6 +79,11 @@ func (change *PolicyChange) Apply() error {if m.closed || s.closed || s.policyChange != change || change.ctx.Err() != nil || (change.mode != "off" && !s.available()) {return errors.New("remote input is unavailable")}+ if change.mode != "off" {+ if err := m.ensureStopShortcut(); err != nil {+ return err+ }+ }s.setPolicy(change.mode, change.password)return nil}@@ -101,6 +106,7 @@ func (s *Session) setPolicy(mode string, password [32]byte) {func (s *Session) applyPolicy(mode string, password [32]byte) {s.mode, s.password = mode, password+ s.manager.releaseIdleShortcut()for _, c := range s.manager.connections {if c.owner == s {s.manager.revoke(c)diff --git a/internal/app/remoteinput/shortcut.go b/internal/app/remoteinput/shortcut.gonew file mode 100644index 00000000..f23bc0be--- /dev/null+++ b/internal/app/remoteinput/shortcut.go@@ -0,0 +1,95 @@+package remoteinput++import "errors"++const defaultStopKey = 10++// F12 is reserved by Windows debuggers even when no debugger is running.+func ValidStopKey(key int) bool { return key >= 1 && key <= 11 }++type StopShortcut struct {+ Key int `json:"key"`+ Available bool `json:"available"`+}++func (m *Manager) SupportsStopShortcut() bool { return m != nil && m.registerStop != nil }++// Called with the grant lock held. Registration begins with an explicit Host+// action, so another application's hotkey cannot disable App startup or capture.+func (m *Manager) ensureStopShortcut() error {+ if m.registerStop == nil || m.stopShortcut != nil {+ return nil+ }+ stop, err := m.registerStop(m.stopKey)+ if err == nil {+ m.stopShortcut = stop+ }+ return err+}++// Caller holds mu. A configured chord belongs to enabled input sessions, not+// the App process: idle sharing must leave it available to other applications.+func (m *Manager) releaseIdleShortcut() {+ if m.stopShortcut == nil {+ return+ }+ for session := range m.sessions {+ if session.mode != "off" {+ return+ }+ }+ m.stopShortcut()+ m.stopShortcut = nil+}++func (m *Manager) ReadStopShortcut() (StopShortcut, error) {+ if !m.SupportsStopShortcut() {+ return StopShortcut{}, errors.New("remote-control shortcut is unavailable")+ }+ m.mu.Lock()+ defer m.mu.Unlock()+ if m.closed {+ return StopShortcut{}, errors.New("remote input is closed")+ }+ state := StopShortcut{Key: m.stopKey, Available: m.stopShortcut != nil}+ if !state.Available {+ stop, err := m.registerStop(m.stopKey)+ state.Available = err == nil+ if stop != nil {+ stop()+ }+ }+ return state, nil+}++func (m *Manager) SetStopShortcut(key int) (StopShortcut, error) {+ if !m.SupportsStopShortcut() || !ValidStopKey(key) {+ return StopShortcut{}, errors.New("remote-control shortcut is invalid or unavailable")+ }+ m.mu.Lock()+ defer m.mu.Unlock()+ if m.closed {+ return StopShortcut{}, errors.New("remote input is closed")+ }+ if key == m.stopKey && m.stopShortcut != nil {+ return StopShortcut{key, true}, nil+ }+ stop, err := m.registerStop(key)+ if err != nil {+ return StopShortcut{}, err+ }+ // Keep the old working chord until registration succeeds.+ if m.stopShortcut != nil {+ m.stopShortcut()+ }+ if m.stopShortcut == nil {+ stop()+ } else {+ m.stopShortcut = stop+ }+ m.stopKey = key+ for session := range m.sessions {+ session.notify()+ }+ return StopShortcut{key, true}, nil+}diff --git a/internal/app/remoteinput/shortcut_test.go b/internal/app/remoteinput/shortcut_test.gonew file mode 100644index 00000000..53394557--- /dev/null+++ b/internal/app/remoteinput/shortcut_test.go@@ -0,0 +1,64 @@+package remoteinput++import (+ "errors"+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/app/nativecapture"+)++func TestStopShortcutCollisionAndReplacement(t *testing.T) {+ registered := map[int]bool{10: true}+ m := &Manager{sink: &recordedInput{}, connections: map[endpointKey]*connection{}, stopKey: defaultStopKey}+ m.registerStop = func(key int) (func(), error) {+ if registered[key] {+ return nil, errors.New("occupied")+ }+ registered[key] = true+ return func() { delete(registered, key) }, nil+ }+ t.Cleanup(m.Close)+ s := m.NewSession()+ s.SetTarget(nativecapture.CaptureTarget{Kind: "display", SourceID: "1"}, nil)+ if err := setTestPolicy(s, "ask", ""); err == nil || s.State().Mode != "off" {+ t.Fatal("occupied shortcut enabled control")+ }+ state, err := m.ReadStopShortcut()+ if err != nil || state.Available || state.Key != 10 {+ t.Fatalf("collision was hidden: %+v, %v", state, err)+ }+ if _, err := m.SetStopShortcut(9); err != nil {+ t.Fatal(err)+ }+ if registered[9] {+ t.Fatal("idle configuration reserved the shortcut")+ }+ if err := setTestPolicy(s, "ask", ""); err != nil || s.State().Mode != "ask" || !registered[9] {+ t.Fatalf("changing the shortcut did not recover the same backend: %v", err)+ }+ if _, err := m.SetStopShortcut(10); err == nil || !registered[9] || m.stopKey != 9 {+ t.Fatal("a collision retired the working shortcut")+ }+ if _, err := m.SetStopShortcut(8); err != nil || !registered[8] || registered[9] || m.stopKey != 8 {+ t.Fatal("replacing the shortcut did not retire the old binding")+ }+ other := m.NewSession()+ other.SetTarget(nativecapture.CaptureTarget{Kind: "display", SourceID: "2"}, nil)+ if err := setTestPolicy(other, "ask", ""); err != nil {+ t.Fatal(err)+ }+ if err := setTestPolicy(s, "off", ""); err != nil || !registered[8] {+ t.Fatal("disabling one session released another session's shortcut")+ }+ other.Close()+ if registered[8] {+ t.Fatal("closing the last enabled session retained the shortcut")+ }+ if err := setTestPolicy(s, "ask", ""); err != nil || !registered[8] {+ t.Fatalf("a later control session did not reacquire the shortcut: %v", err)+ }+ m.Close()+ if registered[8] || !registered[10] {+ t.Fatal("shutdown leaked or released another owner's shortcut")+ }+}diff --git a/internal/media/forwarding/transport_test.go b/internal/media/forwarding/transport_test.goindex e38a1d5e..04d79139 100644--- a/internal/media/forwarding/transport_test.go+++ b/internal/media/forwarding/transport_test.go@@ -342,7 +342,10 @@ func testTransportVideoFeedbackAudioAndClose(t *testing.T, repair, withdrawDeman})delta, _ := transport.Output.probeDemand()transport.driveProbeLocked()- ended := transport.probe.Result.EndTime != 0 && !transport.prober.IsRunning()+ // Feedback may finalize the stopped probe in this same call, clearing+ // its identity and EndTime. Both retired states must stop sending.+ ended := !transport.prober.IsRunning() && (transport.probe.Id == ccutils.ProbeClusterIdInvalid ||+ transport.probe.Result.EndTime != 0)transport.mu.Unlock()check(err)if delta != 0 || !ended {diff --git a/internal/server/app/app.go b/internal/server/app/app.goindex f507d272..6c29dbb6 100644--- a/internal/server/app/app.go+++ b/internal/server/app/app.go@@ -18,6 +18,7 @@ package appimport ("context"+ "crypto/tls""errors""fmt""io/fs"@@ -51,9 +52,9 @@ const (type Options struct {// Config is the loaded server configuration; cmd owns config.Load / Local.Config config.Config- // Listener is optional prebound TCP ownership transferred on successful New.- // It lets the Local App reserve its HTTP port before opening a tunnel.- Listener *net.TCPListener+ // Listeners transfers prebound HTTP/TLS sockets on successful New. The Local+ // App serves its loopback and LAN entries through the same authority.+ Listeners []net.Listener// Assets is the built Browser UI. A nil FS serves the API only.Assets fs.FS// Now returns Unix milliseconds; nil uses the wall clock.@@ -85,9 +86,9 @@ type Server struct {mediaMux ice.UDPMuxsignalOptions signal.OptionshttpServer *http.Server- // Listen binds unless New received an already owned listener. Shutdown waits- // for startupDone before reading it; closing before Listen also releases it.- listener net.Listener+ // Listen binds unless New received owned listeners. Shutdown waits for+ // startupDone before reading them; closing before Listen also releases them.+ listeners []net.Listener// STUN shares the same startup/shutdown owner, never the advertised ICE URLs.stunServer *stun.Server@@ -142,9 +143,7 @@ func New(options Options) (*Server, error) {logger: logger,startupDone: make(chan struct{}),}- if options.Listener != nil {- server.listener = options.Listener- }+ server.listeners = append([]net.Listener(nil), options.Listeners...)if options.Assets != nil {server.frontend = staticHandler(options.Assets, http.HandlerFunc(notFoundJSON))}@@ -172,6 +171,7 @@ func New(options Options) (*Server, error) {}server.httpServer = &http.Server{Handler: server,+ ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelDebug),ReadHeaderTimeout: headersTimeout,ReadTimeout: requestTimeout,IdleTimeout: keepAliveTimeout,@@ -227,20 +227,24 @@ func (s *Server) Listen(ctx context.Context) (int, error) {func (s *Server) start(ctx context.Context) (int, error) {// Bind first. A listener owned by another process must fail before// the room database is opened.- listener := s.listenervar err error- if listener == nil {+ if len(s.listeners) == 0 {address := net.JoinHostPort(s.config.ListenHost, strconv.Itoa(s.config.Port))- listener, err = net.Listen("tcp", address)+ listener, err := net.Listen("tcp", address)if err != nil {return 0, err}+ if s.config.TLS != nil {+ listener = tls.NewListener(listener, s.config.TLS)+ }+ s.listeners = []net.Listener{listener}}- s.listener = listenerif len(s.config.STUNListenAddresses) > 0 {s.stunServer, err = stun.Listen(ctx, s.config.STUNListenAddresses)if err != nil {- _ = listener.Close()+ for _, listener := range s.listeners {+ _ = listener.Close()+ }return 0, fmt.Errorf("Piik STUN listener failed: %w", err)}}@@ -268,15 +272,17 @@ func (s *Server) start(ctx context.Context) (int, error) {IngressCapacity: room.Capacity, EgressCapacity: room.Capacity * s.config.MaxViewersPerRoom,})}}- go func() {- // Report permanent accept failures so an unexpectedly stopped HTTP- // listener is visible to the operator.- if err := s.httpServer.Serve(listener); !errors.Is(err, http.ErrServerClosed) {- s.logger.Error("Piik HTTP server stopped unexpectedly", "errorType", fmt.Sprintf("%T", err))- s.logger.Debug("http-listener-failed", diagnostics.Error(err))- }- }()- port := listener.Addr().(*net.TCPAddr).Port+ for _, listener := range s.listeners {+ go func() {+ // Report permanent accept failures so an unexpectedly stopped HTTP+ // listener is visible to the operator.+ if err := s.httpServer.Serve(listener); !errors.Is(err, http.ErrServerClosed) {+ s.logger.Error("Piik HTTP server stopped unexpectedly", "errorType", fmt.Sprintf("%T", err))+ s.logger.Debug("http-listener-failed", diagnostics.Error(err))+ }+ }()+ }+ port := s.listeners[0].Addr().(*net.TCPAddr).Portif err := s.reconcile(); err != nil {// Give the database and the listener back before reporting.@@ -304,8 +310,8 @@ func (s *Server) start(ctx context.Context) (int, error) {// already closed HTTP listener is harmless.func (s *Server) stopServing(ctx context.Context) error {err := s.httpServer.Shutdown(ctx)- if s.listener != nil {- _ = s.listener.Close()+ for _, listener := range s.listeners {+ _ = listener.Close()}if s.stunServer != nil {err = errors.Join(err, s.stunServer.Close())diff --git a/internal/server/app/app_test.go b/internal/server/app/app_test.goindex 0754de36..14baa9c0 100644--- a/internal/server/app/app_test.go+++ b/internal/server/app/app_test.go@@ -366,7 +366,7 @@ func TestCapabilitiesReportServicesDisabledByDefault(t *testing.T) {server := start(t, Options{Config: testConfig(t)})server.do(http.MethodGet, "/api/capabilities").- expect(http.StatusOK, `{"sfu":false,"natPrediction":false,"roomInteractions":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)+ expect(http.StatusOK, `{"sfu":false,"natPrediction":false,"roomInteractions":true,"roomVoice":true,"relayVolunteer":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)}@@ -376,7 +376,7 @@ func TestCapabilitiesReportSFUOnlyPolicy(t *testing.T) {configuration.NATPredictionEnabled = trueserver := start(t, Options{Config: configuration})server.do(http.MethodGet, "/api/capabilities").- expect(http.StatusOK, `{"sfu":true,"sfuOnly":true,"natPrediction":false,"roomInteractions":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)+ expect(http.StatusOK, `{"sfu":true,"sfuOnly":true,"natPrediction":false,"roomInteractions":true,"roomVoice":true,"relayVolunteer":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)}func TestCapabilitiesReportOptionalNATPredictionWithoutExposingConfiguration(t *testing.T) {@@ -387,7 +387,7 @@ func TestCapabilitiesReportOptionalNATPredictionWithoutExposingConfiguration(t *server := start(t, Options{Config: configuration})server.do(http.MethodGet, "/api/capabilities").- expect(http.StatusOK, `{"sfu":false,"natPrediction":true,"roomInteractions":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`).+ expect(http.StatusOK, `{"sfu":false,"natPrediction":true,"roomInteractions":true,"roomVoice":true,"relayVolunteer":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`).expectHeader("Cache-Control", "no-store").expectHeader("X-Content-Type-Options", "nosniff")@@ -430,7 +430,7 @@ func TestSFUListenerFollowsApplicationCloseAndEnd(t *testing.T) {t.Fatal("missing runtime owner")}server.do(http.MethodGet, "/api/capabilities").- expect(http.StatusOK, `{"sfu":true,"natPrediction":false,"roomInteractions":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)+ expect(http.StatusOK, `{"sfu":true,"natPrediction":false,"roomInteractions":true,"roomVoice":true,"relayVolunteer":true,"hostRoomSession":true,"remoteInput":true,"viewerRouteSelection":true,"audioPresence":true,"roomReactionIds":["thumbsup","thumbsdown","laugh","clown","eyeroll","eyes","wow","wave","heart","clap","party","fire","star","sleep","tomato","poop"]}`)var err errorif ending {@@ -747,6 +747,8 @@ func TestLocalSiteAcceptsTheExactPasswordThroughJSON(t *testing.T) {if err != nil {t.Fatal(err)}+ // The public test address is not an installed interface.+ configuration.STUNListenAddresses = []string{"127.0.0.1:0"}server := start(t, Options{Config: configuration})origin := config.Origin(configuration.PublicBaseURL)for _, wrong := range []string{"", password + "!"} {@@ -1473,35 +1475,43 @@ func TestUsesTheConfiguredListenHostByDefault(t *testing.T) {func TestPreboundListenerHasOneStartupAndShutdownOwner(t *testing.T) {for _, serve := range []bool{false, true} {t.Run(fmt.Sprintf("serve=%t", serve), func(t *testing.T) {- listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)})- if err != nil {- t.Fatal(err)+ var listeners []net.Listener+ for range 2 {+ listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)})+ if err != nil {+ t.Fatal(err)+ }+ listeners = append(listeners, listener)}- address := listener.Addr().(*net.TCPAddr)- server := newServer(t, Options{Listener: listener})+ address := listeners[0].Addr().(*net.TCPAddr)+ server := newServer(t, Options{Listeners: listeners})if serve {port, err := server.Listen(t.Context())- if err != nil || port != address.Port || server.listener != listener {+ if err != nil || port != address.Port || server.listeners[0] != listeners[0] {t.Fatalf("startup replaced the prebound listener: port=%d err=%v", port, err)}client := &http.Client{Timeout: time.Second}- response, err := client.Get("http://" + address.String() + "/healthz")- if err != nil {- t.Fatal(err)- }- _ = response.Body.Close()- if response.StatusCode != http.StatusOK {- t.Fatalf("prebound server health = %d", response.StatusCode)+ for _, listener := range listeners {+ response, err := client.Get("http://" + listener.Addr().String() + "/healthz")+ if err != nil {+ t.Fatal(err)+ }+ _ = response.Body.Close()+ if response.StatusCode != http.StatusOK {+ t.Fatalf("prebound server health = %d", response.StatusCode)+ }}}if err := server.Close(t.Context()); err != nil {t.Fatal(err)}- rebound, err := net.ListenTCP("tcp4", address)- if err != nil {- t.Fatalf("prebound listener survived shutdown: %v", err)+ for _, listener := range listeners {+ rebound, err := net.Listen("tcp4", listener.Addr().String())+ if err != nil {+ t.Fatalf("prebound listener survived shutdown: %v", err)+ }+ _ = rebound.Close()}- _ = rebound.Close()})}}@@ -1709,7 +1719,7 @@ func TestReportsAListenerThatDiesWhileServing(t *testing.T) {}// Out of band: no Shutdown, so Serve returns a real accept failure.- if err := server.listener.Close(); err != nil {+ if err := server.listeners[0].Close(); err != nil {t.Fatalf("close the listener: %v", err)}waitFor(t, "the serve failure to be reported", func() bool {diff --git a/internal/server/app/routes.go b/internal/server/app/routes.goindex 44f6f4df..685fcc4f 100644--- a/internal/server/app/routes.go+++ b/internal/server/app/routes.go@@ -81,6 +81,8 @@ func (s *Server) route(SfuOnly: s.config.SFU != nil && s.config.SFU.Only,NatPrediction: s.config.NATPredictionEnabled && !(s.config.SFU != nil && s.config.SFU.Only),RoomInteractions: true,+ RoomVoice: true,+ RelayVolunteer: true,RoomReactionIDs: protocol.RoomReactionIDs,RemoteInput: true,ViewerRouteSelection: true,diff --git a/internal/server/config/config.go b/internal/server/config/config.goindex 72da975f..624b306f 100644--- a/internal/server/config/config.go+++ b/internal/server/config/config.go@@ -3,6 +3,7 @@package configimport (+ "crypto/tls""errors""fmt""math"@@ -78,6 +79,8 @@ type Config struct {Port intListenHost stringPublicBaseURL *url.URL+ // TLS is optional direct HTTPS. Reverse-proxy deployments leave it nil.+ TLS *tls.Config// AllowedOrigins is a membership test only; map order is not observable.AllowedOrigins map[string]struct{}SiteAccessPassword string@@ -87,8 +90,8 @@ type Config struct {EndpointMediaCopyCapacity intSFU *SFUConfigSTUNURLs []string- // STUNListenAddresses is populated only by Hosted configuration. Local- // discovery URLs do not make the Client an externally reachable STUN server.+ // STUNListenAddresses belongs to the application lifecycle. Pure LAN binds+ // its selected interface; public-link discovery URLs never create listeners.STUNListenAddresses []stringNATPredictionEnabled bool// NATPredictionSTUNURLs is nil when unset, which IceConfig distinguishes@@ -200,12 +203,17 @@ func Load(env map[string]string) (Config, error) {if err != nil {return Config{}, err}+ transportTLS, err := loadTLS(env, publicBaseURL)+ if err != nil {+ return Config{}, err+ }return Config{Env: environment,Port: int(port),ListenHost: listenHost,PublicBaseURL: publicBaseURL,+ TLS: transportTLS,AllowedOrigins: allowedOrigins,SiteAccessPassword: siteAccessPassword,RoomDatabasePath: roomDatabasePath,diff --git a/internal/server/config/local.go b/internal/server/config/local.goindex 8bec5b97..1c5cd0e2 100644--- a/internal/server/config/local.go+++ b/internal/server/config/local.go@@ -15,11 +15,12 @@ import (// process environment.type LocalOptions struct {// Port 0 selects the default 8787.- Port int- PublicAddress string- PublicOrigin string- AllowedAddresses []string- SiteAccessPassword string+ Port int+ PublicAddress string+ PublicOrigin string+ AllowedAddresses []string+ SiteAccessPassword string+ // Public-link discovery only. Pure LAN uses its selected address and port.STUNURLs []stringNATPredictionSTUNURLs []string}@@ -62,6 +63,15 @@ func Local(options LocalOptions) (Config, error) {// Copy non-nil lists so configured-empty prediction does not derive auxiliary URLs.stunURLs := append([]string{}, options.STUNURLs...)natPredictionSTUNURLs := append([]string{}, options.NATPredictionSTUNURLs...)+ var stunListeners []string+ if options.PublicOrigin == "" {+ // Routed LANs may not carry Browser mDNS. Discover the actual address+ // through the existing Binding-only service, without public STUN.+ endpoint := net.JoinHostPort(publicAddress, fmt.Sprint(port))+ stunURLs = []string{"stun:" + endpoint}+ stunListeners = []string{endpoint}+ natPredictionSTUNURLs = []string{}+ }if len(stunURLs)+len(natPredictionSTUNURLs) > protocol.MaxIceServerURLs ||!allValidStunURLs(stunURLs) ||!allValidStunURLs(natPredictionSTUNURLs) ||@@ -71,8 +81,13 @@ func Local(options LocalOptions) (Config, error) {return Config{}, errors.New("Local STUN URLs are invalid")}- // Local is loopback/LAN HTTP; its origin always spells out the port.- origin := func(host string) string { return fmt.Sprintf("http://%s:%d", host, port) }+ // Loopback keeps the Host's stable HTTP origin. Local invitations use TLS;+ // the public tunnel still forwards the existing plain HTTP service.+ lanScheme := "https"+ if options.PublicOrigin != "" {+ lanScheme = "http"+ }+ origin := func(scheme, host string) string { return fmt.Sprintf("%s://%s:%d", scheme, host, port) }var publicBaseURL *url.URLif options.PublicOrigin != "" {parsed, err := publicHTTPSOrigin(options.PublicOrigin)@@ -81,15 +96,15 @@ func Local(options LocalOptions) (Config, error) {}publicBaseURL = parsed} else {- publicBaseURL = &url.URL{Scheme: "http", Host: fmt.Sprintf("%s:%d", publicAddress, port), Path: "/"}+ publicBaseURL = &url.URL{Scheme: "https", Host: fmt.Sprintf("%s:%d", publicAddress, port), Path: "/"}}allowedOrigins := map[string]struct{}{- origin("localhost"): {},- origin("127.0.0.1"): {},+ origin("http", "localhost"): {},+ origin("http", "127.0.0.1"): {},}for _, address := range allowedAddresses {- allowedOrigins[origin(address)] = struct{}{}+ allowedOrigins[origin(lanScheme, address)] = struct{}{}}allowedOrigins[Origin(publicBaseURL)] = struct{}{}@@ -103,6 +118,7 @@ func Local(options LocalOptions) (Config, error) {MaxViewersPerRoom: protocol.MaxViewersPerRoomLimit,EndpointMediaCopyCapacity: protocol.DefaultEndpointMediaCopyCapacity,STUNURLs: stunURLs,+ STUNListenAddresses: stunListeners,NATPredictionEnabled: len(natPredictionSTUNURLs) == protocol.MaxNatPredictionAuxiliaryStunURLs,NATPredictionSTUNURLs: natPredictionSTUNURLs,}, nildiff --git a/internal/server/config/local_test.go b/internal/server/config/local_test.goindex aff65c56..47a42478 100644--- a/internal/server/config/local_test.go+++ b/internal/server/config/local_test.go@@ -46,23 +46,23 @@ func TestLocalMapsClientInputs(t *testing.T) {if config.EndpointMediaCopyCapacity != 2 {t.Errorf("EndpointMediaCopyCapacity = %d", config.EndpointMediaCopyCapacity)}- if len(config.STUNURLs) != 0 {+ if !slices.Equal(config.STUNURLs, []string{"stun:192.168.1.10:9123"}) {t.Errorf("STUNURLs = %v", config.STUNURLs)}- if len(config.STUNListenAddresses) != 0 {- t.Fatalf("Local created STUN listeners: %v", config.STUNListenAddresses)+ if !slices.Equal(config.STUNListenAddresses, []string{"192.168.1.10:9123"}) {+ t.Fatalf("Local STUN listener = %v", config.STUNListenAddresses)}if config.NATPredictionEnabled {t.Error("NATPredictionEnabled = true")}- if got := config.PublicBaseURL.String(); got != "http://192.168.1.10:9123/" {+ if got := config.PublicBaseURL.String(); got != "https://192.168.1.10:9123/" {t.Errorf("PublicBaseURL = %q", got)}want := map[string]struct{}{- "http://localhost:9123": {},- "http://127.0.0.1:9123": {},- "http://192.168.1.10:9123": {},- "http://10.0.0.8:9123": {},+ "http://localhost:9123": {},+ "http://127.0.0.1:9123": {},+ "https://192.168.1.10:9123": {},+ "https://10.0.0.8:9123": {},}if !reflect.DeepEqual(config.AllowedOrigins, want) {t.Errorf("AllowedOrigins = %v, want %v", config.AllowedOrigins, want)@@ -149,7 +149,11 @@ func TestLocalDefaults(t *testing.T) {if config.Port != 8787 {t.Errorf("Port = %d, want the 8787 default", config.Port)}- if got := Origin(config.PublicBaseURL); got != "http://192.168.1.10:8787" {+ if !slices.Equal(config.STUNURLs, []string{"stun:192.168.1.10:8787"}) ||+ !slices.Equal(config.STUNListenAddresses, []string{"192.168.1.10:8787"}) {+ t.Fatalf("Local discovery does not use its default port: %+v", config)+ }+ if got := Origin(config.PublicBaseURL); got != "https://192.168.1.10:8787" {t.Errorf("public origin = %q", got)}// A configured (empty) prediction list stays non-nil so IceConfig does not@@ -207,20 +211,20 @@ func TestLocalRejects(t *testing.T) {{"unparsable public origin", LocalOptions{PublicAddress: "192.168.1.2",PublicOrigin: "public.example"},"Local public origin must be an HTTPS origin"},- {"invalid STUN URL", LocalOptions{PublicAddress: "192.168.1.2",+ {"invalid STUN URL", LocalOptions{PublicAddress: "192.168.1.2", PublicOrigin: "https://public.example.test",STUNURLs: []string{"turn:turn.test:3478"}},"Local STUN URLs are invalid"},- {"invalid prediction STUN URL", LocalOptions{PublicAddress: "192.168.1.2",+ {"invalid prediction STUN URL", LocalOptions{PublicAddress: "192.168.1.2", PublicOrigin: "https://public.example.test",STUNURLs: []string{"stun:a.test:3478"},NATPredictionSTUNURLs: []string{"stun:a.test:3479", "stuns:b.test:3480"}},"Local STUN URLs are invalid"},- {"single prediction STUN URL", LocalOptions{PublicAddress: "192.168.1.2",+ {"single prediction STUN URL", LocalOptions{PublicAddress: "192.168.1.2", PublicOrigin: "https://public.example.test",STUNURLs: []string{"stun:a.test:3478"}, NATPredictionSTUNURLs: []string{"stun:a.test:3479"}},"Local STUN URLs are invalid"},- {"prediction without ordinary STUN", LocalOptions{PublicAddress: "192.168.1.2",+ {"prediction without ordinary STUN", LocalOptions{PublicAddress: "192.168.1.2", PublicOrigin: "https://public.example.test",NATPredictionSTUNURLs: []string{"stun:a.test:3479", "stun:a.test:3480"}},"Local STUN URLs are invalid"},- {"more ICE URLs than the wire carries", LocalOptions{PublicAddress: "192.168.1.2",+ {"more ICE URLs than the wire carries", LocalOptions{PublicAddress: "192.168.1.2", PublicOrigin: "https://public.example.test",STUNURLs: []string{"stun:a.test:3478", "stun:b.test:3478", "stun:c.test:3478", "stun:d.test:3478","stun:e.test:3478", "stun:f.test:3478", "stun:g.test:3478",diff --git a/internal/server/config/tls.go b/internal/server/config/tls.gonew file mode 100644index 00000000..91f233ae--- /dev/null+++ b/internal/server/config/tls.go@@ -0,0 +1,51 @@+package config++import (+ "crypto/tls"+ "crypto/x509"+ "errors"+ "fmt"+ "net/url"+ "strings"+ "time"++ "github.com/TNTcraftHIM/Piik/internal/tlsconfig"+)++func loadTLS(env map[string]string, origin *url.URL) (*tls.Config, error) {+ selfSigned, err := parseBoolean(env["TLS_SELF_SIGNED"], "TLS_SELF_SIGNED")+ if err != nil {+ return nil, err+ }+ certificateFile, keyFile := strings.TrimSpace(env["TLS_CERT_FILE"]), strings.TrimSpace(env["TLS_KEY_FILE"])+ if certificateFile == "" && keyFile == "" && !selfSigned {+ return nil, nil+ }+ if origin.Scheme != "https" {+ return nil, errors.New("direct TLS requires PUBLIC_BASE_URL to use https")+ }+ if selfSigned {+ if certificateFile != "" || keyFile != "" {+ return nil, errors.New("choose TLS_SELF_SIGNED or TLS_CERT_FILE with TLS_KEY_FILE")+ }+ return tlsconfig.SelfSigned(origin.Hostname())+ }+ if certificateFile == "" || keyFile == "" {+ return nil, errors.New("TLS_CERT_FILE and TLS_KEY_FILE must be configured together")+ }+ certificate, err := tls.LoadX509KeyPair(certificateFile, keyFile)+ if err != nil {+ return nil, fmt.Errorf("could not load TLS_CERT_FILE and TLS_KEY_FILE: %w", err)+ }+ leaf, err := x509.ParseCertificate(certificate.Certificate[0])+ if err != nil {+ return nil, err+ }+ if err := leaf.VerifyHostname(origin.Hostname()); err != nil {+ return nil, fmt.Errorf("TLS_CERT_FILE does not cover PUBLIC_BASE_URL: %w", err)+ }+ if now := time.Now(); now.Before(leaf.NotBefore) || now.After(leaf.NotAfter) {+ return nil, errors.New("TLS_CERT_FILE is expired or not yet valid")+ }+ return &tls.Config{MinVersion: tls.VersionTLS12, Certificates: []tls.Certificate{certificate}}, nil+}diff --git a/internal/server/config/tls_test.go b/internal/server/config/tls_test.gonew file mode 100644index 00000000..74260f95--- /dev/null+++ b/internal/server/config/tls_test.go@@ -0,0 +1,60 @@+package config++import (+ "crypto/x509"+ "encoding/pem"+ "net/url"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/tlsconfig"+)++func TestDirectTLSConfiguration(t *testing.T) {+ origin, _ := url.Parse("https://192.0.2.10:8787")+ generated, err := loadTLS(map[string]string{"TLS_SELF_SIGNED": "true"}, origin)+ if err != nil {+ t.Fatal(err)+ }+ leaf, err := x509.ParseCertificate(generated.Certificates[0].Certificate[0])+ if err != nil || leaf.VerifyHostname(origin.Hostname()) != nil || leaf.IsCA {+ t.Fatal("self-signed TLS does not cover the configured origin")+ }+ directory := t.TempDir()+ certificateFile, keyFile := filepath.Join(directory, "cert.pem"), filepath.Join(directory, "key.pem")+ key, err := x509.MarshalPKCS8PrivateKey(generated.Certificates[0].PrivateKey)+ if err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(certificateFile, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: leaf.Raw}), 0600); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: key}), 0600); err != nil {+ t.Fatal(err)+ }+ loaded, err := loadTLS(map[string]string{"TLS_CERT_FILE": certificateFile, "TLS_KEY_FILE": keyFile}, origin)+ if err != nil || tlsconfig.Fingerprint(loaded) != tlsconfig.Fingerprint(generated) {+ t.Fatalf("configured certificate was not retained: %v", err)+ }+ for _, test := range []struct {+ name string+ env map[string]string+ origin string+ want string+ }{+ {"plaintext origin", map[string]string{"TLS_SELF_SIGNED": "true"}, "http://192.0.2.10:8787", "requires PUBLIC_BASE_URL"},+ {"mixed sources", map[string]string{"TLS_SELF_SIGNED": "true", "TLS_CERT_FILE": certificateFile}, origin.String(), "choose TLS_SELF_SIGNED"},+ {"missing key", map[string]string{"TLS_CERT_FILE": certificateFile}, origin.String(), "configured together"},+ {"unreadable pair", map[string]string{"TLS_CERT_FILE": certificateFile, "TLS_KEY_FILE": filepath.Join(directory, "missing.key")}, origin.String(), "could not load"},+ {"wrong host", map[string]string{"TLS_CERT_FILE": certificateFile, "TLS_KEY_FILE": keyFile}, "https://other.example", "does not cover PUBLIC_BASE_URL"},+ } {+ t.Run(test.name, func(t *testing.T) {+ origin, _ := url.Parse(test.origin)+ if _, err := loadTLS(test.env, origin); err == nil || !strings.Contains(err.Error(), test.want) {+ t.Fatalf("TLS configuration error = %v, want %q", err, test.want)+ }+ })+ }+}diff --git a/internal/server/protocol/client.go b/internal/server/protocol/client.goindex d34173be..faea27ed 100644--- a/internal/server/protocol/client.go+++ b/internal/server/protocol/client.go@@ -218,6 +218,16 @@ func DecodeClientMessage(data []byte) (ClientMessage, error) {return nil, err}switch messageType {+ case "set-relay-volunteer":+ return decodeSetRelayVolunteer(data)+ case "subscribe-room-voice":+ return decodeEmptyClientMessage(data, SubscribeRoomVoiceMessage{Type: messageType})+ case "room-voice-command":+ return decodeRoomVoiceCommand(data)+ case "room-voice-signal":+ return decodeRoomVoiceSignal(data)+ case "room-voice-transport":+ return decodeRoomVoiceTransport(data)case "set-viewer-route-preference":return decodeSetViewerRoutePreference(data)case "subscribe-audio-presence":diff --git a/internal/server/protocol/contract_test.go b/internal/server/protocol/contract_test.goindex 25ad37fc..2b211875 100644--- a/internal/server/protocol/contract_test.go+++ b/internal/server/protocol/contract_test.go@@ -449,6 +449,10 @@ func TestRouteDiagnosticSnapshot(t *testing.T) {// "keeps route messages strict alongside the single authenticated mode" and// "accepts every bounded hybrid upstream shape".func TestParticipantRouteAssignment(t *testing.T) {+ children := make([]string, MaxViewersPerRoomLimit+1)+ for index := range children {+ children[index] = fmt.Sprintf(`"child_%08d"`, index)+ }routeUpdate := func(assignment string) []byte {return []byte(`{"type":"route-update","revision":9,"phase":"active","assignment":` +assignment + `}`)@@ -470,7 +474,7 @@ func TestParticipantRouteAssignment(t *testing.T) {`{"upstream":{"kind":"peer","peerId":"parent_12345678"},"childPeerIds":[],` +`"sfuPublicationGeneration":"generation_12345678"}`, false},{"too many children", `{"upstream":{"kind":"none"},"childPeerIds":` +- `["child_12345678","child_87654321","child_third_1234","child_overflow_1"],` ++ `[` + strings.Join(children, ",") + `],` +`"sfuPublicationGeneration":null}`, false},{"duplicate children", `{"upstream":{"kind":"none"},` +`"childPeerIds":["child_12345678","child_12345678"],` +diff --git a/internal/server/protocol/relay_volunteer.go b/internal/server/protocol/relay_volunteer.gonew file mode 100644index 00000000..05d72644--- /dev/null+++ b/internal/server/protocol/relay_volunteer.go@@ -0,0 +1,37 @@+package protocol++import "errors"++type RelayVolunteerMessage struct {+ Type string `json:"type"`+ Enabled bool `json:"enabled"`+ Capacity Int `json:"capacity"`+}++func (RelayVolunteerMessage) isServerMessage() {}++type SetRelayVolunteerMessage RelayVolunteerMessage++func (SetRelayVolunteerMessage) isClientMessage() {}++func decodeRelayVolunteerFields(data []byte) (RelayVolunteerMessage, error) {+ var value RelayVolunteerMessage+ f, err := decodeObject(data, &value)+ if err != nil {+ return value, err+ }+ if err = f.require("type", "enabled", "capacity"); err != nil {+ return value, err+ }+ if !inRangeInt(value.Capacity, 0, MaxViewersPerRoomLimit) {+ return value, errors.New("invalid relay capacity")+ }+ return value, nil+}+func decodeRelayVolunteer(data []byte) (ServerMessage, error) {+ return decodeRelayVolunteerFields(data)+}+func decodeSetRelayVolunteer(data []byte) (ClientMessage, error) {+ value, err := decodeRelayVolunteerFields(data)+ return SetRelayVolunteerMessage(value), err+}diff --git a/internal/server/protocol/server.go b/internal/server/protocol/server.goindex 33bd1313..30015219 100644--- a/internal/server/protocol/server.go+++ b/internal/server/protocol/server.go@@ -249,6 +249,14 @@ func DecodeServerMessage(data []byte) (ServerMessage, error) {return nil, err}switch messageType {+ case "relay-volunteer":+ return decodeRelayVolunteer(data)+ case "room-voice-state":+ return decodeRoomVoiceState(data)+ case "room-voice-signal":+ return decodeRoomVoiceSignal(data)+ case "room-voice-error":+ return decodeRoomVoiceError(data)case "viewer-route-preference":return decodeViewerRoutePreference(data)case "audio-presence":diff --git a/internal/server/protocol/types.go b/internal/server/protocol/types.goindex 3a410c93..bc37aa3b 100644--- a/internal/server/protocol/types.go+++ b/internal/server/protocol/types.go@@ -189,6 +189,8 @@ type RuntimeCapabilities struct {SfuOnly bool `json:"sfuOnly,omitempty"`NatPrediction bool `json:"natPrediction"`RoomInteractions bool `json:"roomInteractions,omitempty"`+ RoomVoice bool `json:"roomVoice,omitempty"`+ RelayVolunteer bool `json:"relayVolunteer,omitempty"`HostRoomSession bool `json:"hostRoomSession,omitempty"`RemoteInput bool `json:"remoteInput,omitempty"`ViewerRouteSelection bool `json:"viewerRouteSelection,omitempty"`@@ -206,13 +208,15 @@ func (v *RuntimeCapabilities) UnmarshalJSON(data []byte) error {if present == nil {return errors.New("runtime capabilities must be an object")}- if err := present.optional("sfu", "sfuOnly", "roomInteractions", "hostRoomSession", "natPrediction", "remoteInput", "viewerRouteSelection", "audioPresence", "roomReactionIds"); err != nil {+ if err := present.optional("sfu", "sfuOnly", "roomInteractions", "roomVoice", "relayVolunteer", "hostRoomSession", "natPrediction", "remoteInput", "viewerRouteSelection", "audioPresence", "roomReactionIds"); err != nil {return err}for key, target := range map[string]*bool{"sfu": &v.Sfu, "sfuOnly": &v.SfuOnly, "natPrediction": &v.NatPrediction,"roomInteractions": &v.RoomInteractions, "hostRoomSession": &v.HostRoomSession,+ "roomVoice": &v.RoomVoice,+ "relayVolunteer": &v.RelayVolunteer,"remoteInput": &v.RemoteInput,"viewerRouteSelection": &v.ViewerRouteSelection,"audioPresence": &v.AudioPresence,@@ -629,7 +633,7 @@ func (v *ParticipantRouteAssignment) UnmarshalJSON(data []byte) error {if err := present.requireNullable("sfuPublicationGeneration"); err != nil {return err}- if len(v.ChildPeerIDs) > MaxEndpointMediaCopyCapacity {+ if len(v.ChildPeerIDs) > MaxViewersPerRoomLimit {return errors.New("childPeerIds holds too many entries")}seen := make(map[string]struct{}, len(v.ChildPeerIDs))diff --git a/internal/server/protocol/voice.go b/internal/server/protocol/voice.gonew file mode 100644index 00000000..b73465d4--- /dev/null+++ b/internal/server/protocol/voice.go@@ -0,0 +1,243 @@+package protocol++import "errors"++// Voice is an opted-in room capability; it does not change the video messages.+type SubscribeRoomVoiceMessage struct {+ Type string `json:"type"`+}++func (SubscribeRoomVoiceMessage) isClientMessage() {}++type RoomVoiceCommand struct {+ Action string `json:"action"`+ PublicationID string `json:"publicationId,omitempty"`+}++func (v RoomVoiceCommand) MarshalJSON() ([]byte, error) {+ value := map[string]any{"action": v.Action}+ if v.Action == "unpublish" {+ value["publicationId"] = v.PublicationID+ }+ return marshalJSON(value)+}++func (v *RoomVoiceCommand) UnmarshalJSON(data []byte) error {+ type plain RoomVoiceCommand+ f, err := decodeObject(data, (*plain)(v))+ if err != nil {+ return err+ }+ if err = f.require("action"); err != nil {+ return err+ }+ switch v.Action {+ case "join", "leave", "publish":+ if len(f) != 1 {+ return errors.New("unexpected voice command fields")+ }+ case "unpublish":+ if err = f.require("publicationId"); err != nil {+ return err+ }+ if len(f) != 2 || !ValidOpaqueID(v.PublicationID) {+ return errors.New("invalid voice publication")+ }+ default:+ return errors.New("unknown voice command")+ }+ return nil+}++type RoomVoiceCommandMessage struct {+ Type string `json:"type"`+ Command RoomVoiceCommand `json:"command"`+}++func (RoomVoiceCommandMessage) isClientMessage() {}++type VoiceTrack struct {+ MID string `json:"mid"`+ PublicationID string `json:"publicationId"`+}++func (v *VoiceTrack) UnmarshalJSON(data []byte) error {+ type plain VoiceTrack+ f, err := decodeObject(data, (*plain)(v))+ if err != nil {+ return err+ }+ if err = f.require("mid", "publicationId"); err != nil {+ return err+ }+ if len(v.MID) < 1 || len(v.MID) > 128 || !ValidOpaqueID(v.PublicationID) {+ return errors.New("invalid voice track")+ }+ return nil+}++type VoiceDescription struct {+ Revision Int `json:"revision"`+ SDP SessionDescription `json:"sdp"`+ Tracks []VoiceTrack `json:"tracks"`+}++func (v *VoiceDescription) UnmarshalJSON(data []byte) error {+ type plain VoiceDescription+ f, err := decodeObject(data, (*plain)(v))+ if err != nil {+ return err+ }+ if err = f.require("revision", "sdp", "tracks"); err != nil {+ return err+ }+ if v.Revision < 1 || len(v.Tracks) > MaxParticipantsPerRoomLimit*2 {+ return errors.New("invalid voice description")+ }+ return nil+}++type RoomVoiceSignalMessage struct {+ Type string `json:"type"`+ ConnectionID string `json:"connectionId"`+ Description *VoiceDescription `json:"description,omitempty"`+ Candidate *IceCandidate `json:"candidate,omitempty"`+ Renegotiate bool `json:"renegotiate,omitempty"`+}++func (RoomVoiceSignalMessage) isClientMessage() {}+func (RoomVoiceSignalMessage) isServerMessage() {}++type RoomVoiceTransportMessage struct {+ Type string `json:"type"`+ ConnectionID string `json:"connectionId"`+ State string `json:"state"`+}++func (RoomVoiceTransportMessage) isClientMessage() {}++type VoiceMember struct {+ PeerID string `json:"peerId"`+ Connected bool `json:"connected"`+ Joined bool `json:"joined"`+ Upstream MediaRouteUpstream `json:"upstream"`+ PublicationID string `json:"publicationId,omitempty"`+}+type VoicePublication struct {+ ID string `json:"id"`+ PeerID string `json:"peerId"`+}+type VoiceConnection struct {+ ConnectionID string `json:"connectionId"`+ ParentPeerID string `json:"parentPeerId,omitempty"`+ ChildPeerID string `json:"childPeerId"`+ Transport string `json:"transport"`+ Pending bool `json:"pending"`+ Revision Int `json:"revision"`+ Send []string `json:"send"`+ Receive []string `json:"receive"`+}+type RoomVoiceStateMessage struct {+ Type string `json:"type"`+ Revision Int `json:"revision"`+ Enabled bool `json:"enabled"`+ HostPeerID *string `json:"hostPeerId"`+ Members []VoiceMember `json:"members"`+ Publications []VoicePublication `json:"publications"`+ Connections []VoiceConnection `json:"connections"`+ Unavailable []string `json:"unavailable"`+}++func (RoomVoiceStateMessage) isServerMessage() {}++type RoomVoiceErrorMessage struct {+ Type string `json:"type"`+ Code string `json:"code"`+}++func (RoomVoiceErrorMessage) isServerMessage() {}++func decodeRoomVoiceCommand(data []byte) (ClientMessage, error) {+ var v RoomVoiceCommandMessage+ f, err := decodeObject(data, &v)+ if err != nil {+ return nil, err+ }+ if err = f.require("type", "command"); err != nil {+ return nil, err+ }+ return v, nil+}+func decodeRoomVoiceSignal(data []byte) (RoomVoiceSignalMessage, error) {+ var v RoomVoiceSignalMessage+ f, err := decodeObject(data, &v)+ if err != nil {+ return v, err+ }+ if err = f.require("type", "connectionId"); err != nil {+ return v, err+ }+ if err = f.optional("description", "candidate", "renegotiate"); err != nil {+ return v, err+ }+ n := 0+ if v.Description != nil {+ n+++ }+ if v.Candidate != nil {+ n+++ }+ if v.Renegotiate {+ n+++ }+ if !ValidOpaqueID(v.ConnectionID) || n != 1 || f.has("renegotiate") && !v.Renegotiate {+ return v, errors.New("invalid voice signal")+ }+ return v, nil+}+func decodeRoomVoiceTransport(data []byte) (ClientMessage, error) {+ var v RoomVoiceTransportMessage+ f, err := decodeObject(data, &v)+ if err != nil {+ return nil, err+ }+ if err = f.require("type", "connectionId", "state"); err != nil {+ return nil, err+ }+ if !ValidOpaqueID(v.ConnectionID) || !enumOf(v.State, "connected", "failed") {+ return nil, errors.New("invalid voice transport")+ }+ return v, nil+}+func decodeRoomVoiceState(data []byte) (ServerMessage, error) {+ var v RoomVoiceStateMessage+ f, err := decodeObject(data, &v)+ if err != nil {+ return nil, err+ }+ if err = f.require("type", "revision", "enabled", "members", "publications", "connections", "unavailable"); err != nil {+ return nil, err+ }+ if err = f.requireNullable("hostPeerId"); err != nil {+ return nil, err+ }+ if !validRevision(v.Revision) || v.HostPeerID != nil && !ValidOpaqueID(*v.HostPeerID) || len(v.Members) > MaxParticipantsPerRoomLimit ||+ len(v.Publications) > MaxParticipantsPerRoomLimit || len(v.Connections) > MaxParticipantsPerRoomLimit+1 || len(v.Unavailable) > MaxParticipantsPerRoomLimit {+ return nil, errors.New("invalid voice state")+ }+ return v, nil+}+func decodeRoomVoiceError(data []byte) (ServerMessage, error) {+ var v RoomVoiceErrorMessage+ f, err := decodeObject(data, &v)+ if err != nil {+ return nil, err+ }+ if err = f.require("type", "code"); err != nil {+ return nil, err+ }+ if !enumOf(v.Code, "not-allowed", "not-enabled", "connection-unavailable") {+ return nil, errors.New("invalid voice error")+ }+ return v, nil+}diff --git a/internal/server/route/api.go b/internal/server/route/api.goindex bc210a9f..48e927eb 100644--- a/internal/server/route/api.go+++ b/internal/server/route/api.go@@ -115,6 +115,7 @@ const (DemandDirectConvergence DemandReason = "direct-convergence"DemandQualityConvergence DemandReason = "quality-convergence"DemandRootConvergence DemandReason = "root-convergence"+ DemandPublicationAttach DemandReason = "publication-attach")// FinalRoute mirrors protocol RouteDiagnosticFinalRoute.@@ -223,7 +224,11 @@ type CommittedEdge struct {ConnectionID stringUsable boolPhysicalActive bool- Resource *Resource+ // Video attachment belongs to a publication, independently of room transport.+ VideoGeneration string+ VideoConnectionID string+ VideoReady bool+ Resource *Resource// The acquisition's session key stays fixed when signaling ownership rebinds.opportunityKey string}@@ -257,23 +262,30 @@ type CurrentAttempt struct {// OperationSnapshot is a deep copy of the in-flight operation plus the// derived WakeAtMs. Current is nil without a live attempt.type OperationSnapshot struct {- ChildPeerID string- ChildSessionID string- DemandPeerID string- Reason DemandReason- BaseRevision int64- FactVersion int64- Candidates []CandidatePlan- Cursor int- DeadlineAtMs int64- WakeAtMs int64- Current *CurrentAttempt+ // VideoGeneration fences decoded-frame proof. AttachConnectionID names+ // the retained room edge only for DemandPublicationAttach.+ VideoGeneration string+ AttachConnectionID string+ ChildPeerID string+ ChildSessionID string+ DemandPeerID string+ Reason DemandReason+ BaseRevision int64+ FactVersion int64+ Candidates []CandidatePlan+ Cursor int+ DeadlineAtMs int64+ WakeAtMs int64+ Current *CurrentAttempt}// RouteSnapshot is the committed graph as the router reads it.// UpstreamByViewer is a fresh insertion-ordered copy (child peerId -> edge);// HostPublication is a shallow copy or nil; Operation is nil when idle.type RouteSnapshot struct {+ RoomMedia bool+ VideoGeneration string+ VideoPaused boolRevision int64Paused boolFactVersion int64@@ -387,9 +399,11 @@ type BeginInput struct {HostSessionID string}-// CandidateProof carries the Viewer's one-shot relative quality approval.+// CandidateProof carries the decoded publication identity in room-media mode+// and the Viewer's one-shot relative quality approval when required.type CandidateProof struct {RelativeQualityApproved bool+ VideoGeneration string}// QualityUpstream names the upstream a receiver-side window was measured@@ -482,6 +496,10 @@ type Controller struct {factVersion int64nextJoinOrder int64paused bool+ roomMedia bool+ voiceListeners map[string]bool+ videoGeneration string+ videoPaused boolrouteTimings map[string]*routeTimingRecordqualityObservations map[string]*routeQualityObservationsenderQualityObservations map[string]*senderQualityObservationdiff --git a/internal/server/route/candidates.go b/internal/server/route/candidates.goindex 58668a23..585d576c 100644--- a/internal/server/route/candidates.go+++ b/internal/server/route/candidates.go@@ -54,7 +54,8 @@ func (c *Controller) buildCandidatePlans(childPeerID string, sfuOnly, preferUntrparents := []*participant{}for _, parent := range c.participants.Values() {if parent.sessionID != "" && !parent.departureConfirmed && parent.peerID != childPeerID &&- !slices.Contains(descendants, parent.peerID) && c.sourceUsable(parent.peerID) && c.targetFits(parent.peerID, childPeerID) {+ !slices.Contains(descendants, parent.peerID) && c.sourceUsable(parent.peerID) && c.sourceVideoReady(parent.peerID) &&+ c.voiceParentAllowed(childPeerID, parent.peerID) && c.targetFits(parent.peerID, childPeerID) {parents = append(parents, parent)}}@@ -142,7 +143,7 @@ func (c *Controller) planCandidate(childPeerID string, tuple CandidateTuple) *Caif copies+1 <= producer.effectiveDownstreamCapacity {return &CandidatePlan{Tuple: tuple, EndpointTransition: EndpointTransition{Kind: TransitionNone, ProducerPeerID: &producer0}}}- if copies+1 <= protocol.EndpointMediaCopyLimit(c.endpointMediaCopyCapacity, protocol.EndpointMediaCopyTransition) {+ if copies+1 <= c.transitionCopyLimit(producer) {return &CandidatePlan{Tuple: tuple, EndpointTransition: EndpointTransition{Kind: TransitionOverlap, ProducerPeerID: &producer0}}}retire := c.retirementFor(childPeerID, producerPeerID, tuple)@@ -198,8 +199,8 @@ func (c *Controller) candidateValid(childPeerID string, plan CandidatePlan, att}parent, _ := c.participants.Get(tuple.ParentPeerID)if parent == nil || parent.sessionID == "" || parent.departureConfirmed || (att != nil && parent.sessionID != att.parentSessionID) ||- slices.Contains(c.descendantsOf(childPeerID), parent.peerID) || !c.sourceUsable(parent.peerID) ||- !c.targetFits(parent.peerID, childPeerID) {+ slices.Contains(c.descendantsOf(childPeerID), parent.peerID) || !c.sourceUsable(parent.peerID) || !c.sourceVideoReady(parent.peerID) ||+ !c.voiceParentAllowed(childPeerID, parent.peerID) || !c.targetFits(parent.peerID, childPeerID) {return false}} else {diff --git a/internal/server/route/controller.go b/internal/server/route/controller.goindex af142c9a..eba72797 100644--- a/internal/server/route/controller.go+++ b/internal/server/route/controller.go@@ -36,6 +36,8 @@ type participant struct {departureConfirmed booljoinOrder int64effectiveDownstreamCapacity int+ reportedDownstreamCapacity int+ relayVolunteer boolavailabilityExhausted boolconsumedCandidateOpportunities ordered.Map[string, candidateOpportunity]bootstrapFailureReported bool@@ -84,6 +86,8 @@ type attempt struct {// operation is the single in-flight route operation.type operation struct {+ videoGeneration string+ attachConnectionID stringchildPeerID stringchildSessionID stringdemandPeerID string@@ -330,6 +334,9 @@ func (c *Controller) Snapshot() RouteSnapshot {publication = &copied}return RouteSnapshot{+ RoomMedia: c.roomMedia,+ VideoGeneration: c.videoGeneration,+ VideoPaused: c.videoPaused,Revision: c.revision,Paused: c.paused,FactVersion: c.factVersion,@@ -427,8 +434,9 @@ func (c *Controller) UpsertParticipant(input ParticipantInput, nowMs *int64) []*if (input.PeerID == c.hostPeerID) != (input.Role == protocol.RoleHost) {panic(errors.New("Route Host identity is inconsistent"))}- capacity := c.effectiveCapacity(input.EffectiveDownstreamCapacity)current, _ := c.participants.Get(input.PeerID)+ capacity := c.effectiveCapacity(input.EffectiveDownstreamCapacity,+ current != nil && current.sessionID == input.SessionID && current.relayVolunteer)released := []*Resource{}if current != nil && current.role != input.Role {panic(errors.New("Route role cannot change"))@@ -437,6 +445,7 @@ func (c *Controller) UpsertParticipant(input ParticipantInput, nowMs *int64) []*changed := falsepreviousSessionID := current.sessionIDif previousSessionID != input.SessionID {+ current.relayVolunteer = falsec.clearOpportunitiesForSessionChange(input.PeerID, input.Role)c.clearQualityForParticipant(input.PeerID)if c.operationUsesParticipantSession(input.PeerID) {@@ -452,8 +461,10 @@ func (c *Controller) UpsertParticipant(input ParticipantInput, nowMs *int64) []*current.departureConfirmed = falsechanged = true}+ current.reportedDownstreamCapacity = input.EffectiveDownstreamCapacityif current.effectiveDownstreamCapacity != capacity {current.effectiveDownstreamCapacity = capacity+ c.recordCapacityReduction(input.PeerID, nowMs)changed = true}if changed {@@ -485,6 +496,7 @@ func (c *Controller) UpsertParticipant(input ParticipantInput, nowMs *int64) []*role: input.Role,sessionID: input.SessionID,effectiveDownstreamCapacity: capacity,+ reportedDownstreamCapacity: input.EffectiveDownstreamCapacity,routePreference: input.RoutePreference,joinOrder: c.nextJoinOrder,})@@ -592,6 +604,8 @@ func (c *Controller) RebindHostIdentity(peerID, sessionID string, nowMs *int64)c.participants.Delete(previousPeerID)host.peerID = peerIDhost.sessionID = sessionID+ host.relayVolunteer = false+ host.effectiveDownstreamCapacity = c.effectiveCapacity(host.reportedDownstreamCapacity, false)host.departureConfirmed = falsec.participants.Set(peerID, host)c.hostPeerID = peerID@@ -655,16 +669,13 @@ func (c *Controller) SetEffectiveCapacity(peerID, sessionID string, value int, nif current == nil || !current.sessionIs(sessionID) {return false}- capacity := c.effectiveCapacity(value)+ capacity := c.effectiveCapacity(value, current.relayVolunteer)+ current.reportedDownstreamCapacity = valueif current.effectiveDownstreamCapacity == capacity {return true}current.effectiveDownstreamCapacity = capacity- if nowMs != nil {- for _, childPeerID := range c.overflowPeerChildren(peerID) {- c.recordDemand(childPeerID, *nowMs, DemandCapacityReduction)- }- }+ c.recordCapacityReduction(peerID, nowMs)c.touchFacts()c.debug("capacity-updated", "participant", c.debugPeer(peerID), "capacity", capacity)return true@@ -770,7 +781,14 @@ func (c *Controller) AdoptDirectConnection(input AdoptDirectConnectionInput, nowinput.NewConnectionID == "" {return result}- if input.NewConnectionID == edge.ConnectionID {+ activeConnectionID := edge.ConnectionID+ if c.roomMedia {+ if !edge.VideoReady || edge.VideoGeneration != c.videoGeneration || c.videoGeneration == "" {+ return result+ }+ activeConnectionID = edge.VideoConnectionID+ }+ if input.NewConnectionID == activeConnectionID {result.Accepted = truereturn result}@@ -781,10 +799,14 @@ func (c *Controller) AdoptDirectConnection(input AdoptDirectConnectionInput, nowresult.Released = c.abortOperation(&nowMs, RejectionAborted)}c.clearQualityForParticipant(input.ChildPeerID)- edge.ConnectionID = input.NewConnectionID- edge.opportunityKey = c.candidateOpportunityBase(input.ChildPeerID, CandidatePlan{- Tuple: CandidateTuple{Kind: edge.Kind, ParentPeerID: edge.ParentPeerID},- })+ if c.roomMedia {+ edge.VideoConnectionID = input.NewConnectionID+ } else {+ edge.ConnectionID = input.NewConnectionID+ edge.opportunityKey = c.candidateOpportunityBase(input.ChildPeerID, CandidatePlan{+ Tuple: CandidateTuple{Kind: edge.Kind, ParentPeerID: edge.ParentPeerID},+ })+ }if child, ok := c.participants.Get(input.ChildPeerID); ok {child.availabilityExhausted = false}@@ -830,6 +852,13 @@ func (c *Controller) RetireHostPublication(guard PublicationGuard) []*Resource {// SetPaused pauses (aborting the operation and clearing quality state) or// resumes; returns the aborted reservation's resources.func (c *Controller) SetPaused(paused bool, nowMs *int64) []*Resource {+ if c.roomMedia {+ now := int64(0)+ if nowMs != nil {+ now = *nowMs+ }+ return c.SetVideoPublication(c.videoGeneration, paused, now)+ }if c.paused == paused {return []*Resource{}}@@ -915,11 +944,15 @@ func (c *Controller) operationUsesParticipantSession(peerID string) bool {// effectiveCapacity panics "Effective capacity is invalid" for// a negative or unsafe value and clamps to the endpoint capacity.-func (c *Controller) effectiveCapacity(value int) int {+func (c *Controller) effectiveCapacity(value int, volunteer bool) int {if !isSafeInteger(int64(value)) || value < 0 {panic(errors.New("Effective capacity is invalid"))}- return min(value, c.endpointMediaCopyCapacity)+ limit := c.endpointMediaCopyCapacity+ if volunteer {+ limit = MaxRelayVolunteerChildren+ }+ return min(value, limit)}func (c *Controller) touchFacts() { c.factVersion++ }diff --git a/internal/server/route/graph.go b/internal/server/route/graph.goindex 8673ec70..7e1a3df3 100644--- a/internal/server/route/graph.go+++ b/internal/server/route/graph.go@@ -278,7 +278,9 @@ func (c *Controller) assertGraph() {}}for _, current := range c.participants.Values() {- if !protocol.EndpointMediaCopyCountFits(c.usedSlots(current.peerID), c.endpointMediaCopyCapacity, protocol.EndpointMediaCopySteady) {+ // Admission uses the participant's effective policy. Existing resources+ // drain through serial handoffs after withdrawal or capacity reduction.+ if c.usedSlots(current.peerID) > MaxRelayVolunteerChildren {panic(errors.New("Committed route exceeds endpoint capacity"))}}diff --git a/internal/server/route/operation.go b/internal/server/route/operation.goindex f7e70603..5eb43cc6 100644--- a/internal/server/route/operation.go+++ b/internal/server/route/operation.go@@ -32,7 +32,7 @@ func isBackgroundConvergence(reason DemandReason) bool {}func isAvailabilityOperation(reason DemandReason) bool {- return reason != DemandSfuBootstrap && !isBackgroundConvergence(reason)+ return reason != DemandPublicationAttach && reason != DemandSfuBootstrap && !isBackgroundConvergence(reason)}// operationRequiresNativeCandidateProof returns false for a nil operation.@@ -76,6 +76,11 @@ func (c *Controller) Reconcile(nowMs int64) ReconcileResult {Released: released,}}+ // Attach existing upstreams before asking them to supply a new video child.+ if c.startPublicationAttach(nowMs) {+ return ReconcileResult{Operation: c.operationSnapshot(), RemovedPeerIDs: removedPeerIDs,+ FailedPeerIDs: failedPeerIDs, Released: released}+ }// The loop bound is a count, not an order.for remaining := c.participants.Len(); remaining > 0; remaining-- {@@ -89,11 +94,11 @@ func (c *Controller) Reconcile(nowMs int64) ReconcileResult {continuation = c.selectDirectContinuation()}qualityChildPeerID := ""- if routeChildPeerID == "" && bootstrap == nil && continuation == nil {+ if routeChildPeerID == "" && bootstrap == nil && continuation == nil && c.videoWorkEnabled() {qualityChildPeerID = c.selectQualityChild(nowMs)}var rootConvergence *rootConvergencePick- if routeChildPeerID == "" && bootstrap == nil && continuation == nil && qualityChildPeerID == "" {+ if routeChildPeerID == "" && bootstrap == nil && continuation == nil && qualityChildPeerID == "" && c.videoWorkEnabled() {rootConvergence = c.takeRootConvergenceIntent()}childPeerID := routeChildPeerID@@ -203,6 +208,7 @@ func (c *Controller) Reconcile(nowMs int64) ReconcileResult {qualitySource = c.currentQualityOperationSource(childPeerID)}c.operation = &operation{+ videoGeneration: c.requiredVideoGeneration(),childPeerID: childPeerID,childSessionID: child.sessionID,demandPeerID: demandPeerID,@@ -235,7 +241,8 @@ func (c *Controller) Reconcile(nowMs int64) ReconcileResult {// BeginCurrentCandidate starts the candidate at the guarded cursor with the// caller's reservation; every rejection echoes the reservation back in-// Released. Panics on a reservation that does not match the tuple.+// Released. Publication attachment takes an empty reservation and preserves+// the committed edge. Other attempts panic on a mismatched reservation.func (c *Controller) BeginCurrentCandidate(input BeginInput) BeginResult {validation := c.validateOrAdvance(input.NowMs, nil)op := c.operation@@ -247,6 +254,9 @@ func (c *Controller) BeginCurrentCandidate(input BeginInput) BeginResult {FailedPeerIDs: failedPeerIDsFrom(validation),}}+ if op.reason == DemandPublicationAttach {+ return c.beginPublicationAttach(input, op, validation)+ }plan := op.planAt(op.cursor)if plan == nil || !c.operationCandidateValid(op, *plan, nil) {return BeginResult{@@ -364,6 +374,10 @@ func (c *Controller) SkipCurrentCandidate(guard CandidateCursorGuard, nowMs int6Released: validation.released,}}+ if op.reason == DemandPublicationAttach {+ c.finishPublicationAttach(op, false)+ return BeginResult{Accepted: true, FailedPeerIDs: []string{op.childPeerID}, Released: validation.released}+ }if bucket == RejectionCandidateFailed {if isAvailabilityOperation(op.reason) {c.consumeCandidateOpportunity(op.childPeerID, op.candidates[op.cursor])@@ -493,6 +507,16 @@ func (c *Controller) CandidateReady(guard CandidateGuard, nowMs int64, commitResReleased: validation.released,}}+ if c.roomMedia && op.videoGeneration != "" && proof.VideoGeneration != op.videoGeneration {+ return SettleResult{ActiveRevision: c.revision, Released: validation.released}+ }+ if c.roomMedia && op.videoGeneration == "" && !att.transportConnected {+ return SettleResult{ActiveRevision: c.revision, Released: validation.released}+ }+ if op.reason == DemandPublicationAttach {+ c.finishPublicationAttach(op, true)+ return SettleResult{Accepted: true, Committed: true, ActiveRevision: c.revision, Released: validation.released}+ }qualityPeer := op.reason == DemandQualityConvergence && att.tuple.Kind == UpstreamPeerrelativeP2pProof := qualityPeer && proof.RelativeQualityApprovedif relativeP2pProof && att.relativeQualityApprovedAtMs == nil {@@ -622,8 +646,9 @@ func (c *Controller) CandidateReady(guard CandidateGuard, nowMs int64, commitRes}}-// CandidateTransportConnected marks the guarded peer attempt as connected so-// it survives the direct head start until the operation deadline.+// CandidateTransportConnected records actual transport establishment. Peer+// attempts survive the direct head start; room-mode silent Peer/SFU attempts+// also require this evidence before CandidateReady may commit.func (c *Controller) CandidateTransportConnected(guard CandidateGuard, nowMs int64) SettleResult {validation := c.validateOrAdvance(nowMs, nil)op := c.operation@@ -631,7 +656,7 @@ func (c *Controller) CandidateTransportConnected(guard CandidateGuard, nowMs intif op != nil {att = op.current}- if op == nil || att == nil || att.tuple.Kind != UpstreamPeer || !c.guardMatches(guard, op, att) {+ if op == nil || att == nil || (att.tuple.Kind != UpstreamPeer && !c.roomMedia) || !c.guardMatches(guard, op, att) {return SettleResult{Accepted: false,FailedPeerIDs: failedPeerIDsFrom(validation),@@ -656,6 +681,11 @@ func (c *Controller) CandidateTransportConnected(guard CandidateGuard, nowMs int// and advancing the cursor; Accepted reports whether the guard was consumed.func (c *Controller) CandidateFailed(guard CandidateGuard, nowMs int64) SettleResult {op := c.operation+ if op != nil && op.reason == DemandPublicationAttach {+ validation := c.validateOrAdvance(nowMs, &guard)+ return SettleResult{Accepted: validation.consumedGuard, FailedPeerIDs: failedPeerIDsFrom(validation),+ ActiveRevision: c.revision, Released: validation.released}+ }if op != nil && op.current != nil && c.guardMatches(guard, op, op.current) {c.consumeCurrentAvailabilityOpportunity(op)c.debug("candidate-failed",@@ -717,6 +747,9 @@ func (c *Controller) validateOrAdvance(nowMs int64, failedGuard *CandidateGuard)if op == nil {return result}+ if op.reason == DemandPublicationAttach {+ return c.validatePublicationAttach(op, nowMs, failedGuard)+ }if !c.bootstrapOperationOwned(op) {if op.current != nil {result.released = append(result.released, reservationResources(op.current.reservation)...)@@ -1014,6 +1047,10 @@ func (c *Controller) commitAttempt(op *operation, att *attempt) []*Resource {c.directContinuations.Delete(op.childPeerID)}}+ if c.roomMedia && op.videoGeneration != "" {+ edge, _ := c.upstreamByViewer.Get(op.childPeerID)+ edge.VideoGeneration, edge.VideoConnectionID, edge.VideoReady = op.videoGeneration, att.connectionID, true+ }producerPeerIDs := []string{}if oldPeer {producerPeerIDs = append(producerPeerIDs, old.ParentPeerID)@@ -1176,16 +1213,18 @@ func (c *Controller) operationSnapshot() *OperationSnapshot {candidates = append(candidates, cloneCandidatePlan(candidate))}snapshot := &OperationSnapshot{- ChildPeerID: op.childPeerID,- ChildSessionID: op.childSessionID,- DemandPeerID: op.demandPeerID,- Reason: op.reason,- BaseRevision: op.baseRevision,- FactVersion: op.builtAtFactVersion,- Candidates: candidates,- Cursor: op.cursor,- DeadlineAtMs: op.deadlineAtMs,- WakeAtMs: c.operationWakeAt(op),+ VideoGeneration: op.videoGeneration,+ AttachConnectionID: op.attachConnectionID,+ ChildPeerID: op.childPeerID,+ ChildSessionID: op.childSessionID,+ DemandPeerID: op.demandPeerID,+ Reason: op.reason,+ BaseRevision: op.baseRevision,+ FactVersion: op.builtAtFactVersion,+ Candidates: candidates,+ Cursor: op.cursor,+ DeadlineAtMs: op.deadlineAtMs,+ WakeAtMs: c.operationWakeAt(op),}if op.current != nil {current := &CurrentAttempt{@@ -1241,6 +1280,9 @@ func (c *Controller) advanceExpiredDirectHeadStart(op *operation, nowMs int64, r}func (c *Controller) operationWakeAt(op *operation) int64 {+ if op.reason == DemandPublicationAttach {+ return op.deadlineAtMs+ }currentTuple := op.currentTuple()if currentTuple != nil && currentTuple.Kind == UpstreamPeer &&!(op.current != nil && op.current.transportConnected) &&@@ -1330,7 +1372,8 @@ func (c *Controller) selectNextChild() string {departedParents = append(departedParents, viewer.peerID)}}- if edge != nil && (!edge.Usable || !c.allowsIncoming(viewer.peerID, edge.Kind) || c.parentRouteRetired(edge)) {+ if edge != nil && (!edge.Usable || !c.allowsIncoming(viewer.peerID, edge.Kind) ||+ c.parentRouteRetired(edge) || c.voiceRouteMissing(viewer.peerID)) {unusable = append(unusable, viewer.peerID)}if edge != nil && edge.Kind == UpstreamSfu &&diff --git a/internal/server/route/policy.go b/internal/server/route/policy.gonew file mode 100644index 00000000..1b79d1aa--- /dev/null+++ b/internal/server/route/policy.go@@ -0,0 +1,41 @@+package route++import "github.com/TNTcraftHIM/Piik/internal/server/protocol"++// SetRoutePolicy applies the server-validated policy for a new share to the+// retained room controller. Existing routes stay physical while the ordinary+// operation proves their replacement; disallowed routes cannot attach video.+func (c *Controller) SetRoutePolicy(policy protocol.RoutePolicy, nowMs int64) []*Resource {+ sfuEnabled := !policy.PeerOnly+ if c.sfuEnabled == sfuEnabled && c.qualityConvergenceEnabled == policy.TopologyOptimization &&+ c.natPredictionEnabled == policy.NatPrediction {+ return nil+ }+ released := c.abortOperation(&nowMs, RejectionAborted)+ c.sfuEnabled, c.qualityConvergenceEnabled, c.natPredictionEnabled =+ sfuEnabled, policy.TopologyOptimization, policy.NatPrediction+ for _, current := range c.participants.Values() {+ if current.role != protocol.RoleViewer {+ continue+ }+ if !c.AllowsViewerRoutePreference(current.routePreference) {+ current.routePreference = protocol.ViewerRouteAuto+ }+ current.consumedCandidateOpportunities.Clear()+ current.availabilityExhausted = false+ current.bootstrapFailureReported = false+ current.sfuFirstAtNextRoute = false+ }+ c.directContinuations.Clear()+ c.sfuBootstrapIntent = nil+ c.consumedSfuBootstrapOpportunities.Clear()+ c.rootConvergenceRootPeerID = ""+ clear(c.qualityObservations)+ clear(c.qualityBaselinesPending)+ clear(c.senderQualityObservations)+ clear(c.senderQualityBaselines)+ clear(c.senderQualityRegenerationBlocks)+ c.sfuPublisherQualityObservation = nil+ c.touchFacts()+ return released+}diff --git a/internal/server/route/policy_test.go b/internal/server/route/policy_test.gonew file mode 100644index 00000000..fa8ee0ea--- /dev/null+++ b/internal/server/route/policy_test.go@@ -0,0 +1,77 @@+package route++import (+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+)++func TestRoomPolicyPeerOnlyRepairsRetainedSfuBeforeVideoAttachment(t *testing.T) {+ routes := newController(2, Options{SfuEnabled: true, QualityConvergenceEnabled: true})+ addViewer(routes, A, 0, nil)+ routes.hydrateHostPublication("room-publication", res("publication"), "old-publisher")+ routes.hydrateEdge(A, sfuEdge("room-publication", "room-a", "subscription"))+ routes.SetViewerRoutePreference(A, sessionOf(A), protocol.ViewerRouteSfu, ms(0))+ routes.SetVideoPublication("", false, 1)+ routes.SetVoiceListeners([]string{HOST, A}, 2)+ eq(t, len(routes.SetRoutePolicy(protocol.RoutePolicy{PeerOnly: true, NatPrediction: true}, 3)), 0)+ viewer, _ := routes.participants.Get(A)+ eq(t, viewer.routePreference, protocol.ViewerRouteAuto)+ eq(t, routes.qualityConvergenceEnabled, false)+ eq(t, routes.natPredictionEnabled, true)+ routes.SetVideoPublication("peer-only-share", false, 4)+ op := must(t, routes.Reconcile(5).Operation)+ eq(t, op.Reason, DemandEdgeUnavailable)+ eq(t, op.Candidates[0].Tuple.Kind, UpstreamPeer)+ eq(t, edgeOf(t, routes, A).ConnectionID, "room-a")+ eq(t, edgeOf(t, routes, A).Usable, true)+ prepared := beginOperation(t, routes, BeginInput{NowMs: 6, ConnectionID: "peer-a", Reservation: direct()})+ eq(t, prepared.Current.ConnectionAttempt.Current, 1)+ guard := guardFor(A, prepared.Current.Revision, "peer-a")+ settled := routes.CandidateReady(guard, 7, nil, CandidateProof{VideoGeneration: "peer-only-share"})+ eq(t, settled.Committed, true)+ eqSlice(t, labels(settled.Released), []string{"subscription", "publication"})+ eq(t, edgeOf(t, routes, A).Kind, UpstreamPeer)+ eq(t, edgeOf(t, routes, A).VideoGeneration, "peer-only-share")+ eq(t, routes.Snapshot().HostPublication == nil, true)+ noOperation(t, routes.Reconcile(8).Operation)+}++func TestRoomPolicyChangeCancelsOldAttachmentAndSamePolicyDoesNotCancelWork(t *testing.T) {+ routes := newController(2, Options{SfuEnabled: true})+ addViewer(routes, A, 0, nil)+ routes.hydrateHostPublication("publication", res("publication"), "publisher")+ routes.hydrateEdge(A, sfuEdge("publication", "room-a", "subscription"))+ routes.SetVideoPublication("", false, 1)+ routes.SetVideoPublication("share", false, 2)+ late := beginVideoAttach(t, routes, 3, A, "sfu-video-a")+ routes.SetRoutePolicy(protocol.RoutePolicy{PeerOnly: true}, 4)+ eq(t, routes.CandidateReady(late, 5, nil, CandidateProof{VideoGeneration: "share"}).Accepted, false)+ op := must(t, routes.Reconcile(6).Operation)+ eq(t, op.Candidates[0].Tuple.Kind, UpstreamPeer)+ prepared := beginOperation(t, routes, BeginInput{NowMs: 7, ConnectionID: "peer-a", Reservation: direct()})+ routes.SetRoutePolicy(protocol.RoutePolicy{PeerOnly: true}, 8)+ eq(t, must(t, routes.Operation()).Current.ConnectionID, prepared.Current.ConnectionID)+ eq(t, edgeOf(t, routes, A).ConnectionID, "room-a")+}++func TestRoomPolicyHybridReopensExistingAvailabilityAndSfuBootstrap(t *testing.T) {+ routes := newController(1, Options{})+ addViewer(routes, A, 0, nil)+ addViewer(routes, B, 0, nil)+ routes.hydrateEdge(A, peerEdge(HOST, "room-a"))+ routes.SetVideoPublication("", false, 1)+ routes.SetVoiceListeners([]string{HOST, A, B}, 2)+ noOperation(t, routes.Reconcile(3).Operation)+ b, _ := routes.participants.Get(B)+ eq(t, b.availabilityExhausted, true)+ routes.SetRoutePolicy(protocol.RoutePolicy{TopologyOptimization: true}, 4)+ eq(t, b.availabilityExhausted, false)+ eq(t, routes.qualityConvergenceEnabled, true)+ eq(t, routes.natPredictionEnabled, false)+ op := must(t, routes.Reconcile(5).Operation)+ eq(t, op.Reason, DemandSfuBootstrap)+ eq(t, op.ChildPeerID, A)+ eq(t, op.DemandPeerID, B)+ eq(t, edgeOf(t, routes, A).ConnectionID, "room-a")+}diff --git a/internal/server/route/publication.go b/internal/server/route/publication.gonew file mode 100644index 00000000..6efa907d--- /dev/null+++ b/internal/server/route/publication.go@@ -0,0 +1,191 @@+package route++// SetHostVideoConnectionID replaces only the physical video facet. The logical+// publication generation/resource continue to own room reachability and voice.+func (c *Controller) SetHostVideoConnectionID(id string) bool {+ if !c.roomMedia || c.hostPublication == nil || id == "" {+ return false+ }+ if c.hostPublication.ConnectionID != id {+ c.hostPublication.ConnectionID = id+ c.touchFacts()+ }+ return true+}++// SetVideoPublication opts this controller into room media. Room edges survive+// publication replacement, stop and pause. The returned resources belong only+// to the canceled operation; the caller retires video facets on stop/replacement.+// Calling it with an empty generation establishes an audio-only room.+func (c *Controller) SetVideoPublication(generation string, paused bool, nowMs int64) []*Resource {+ if generation == "" {+ paused = false+ }+ if c.roomMedia && c.videoGeneration == generation && c.videoPaused == paused {+ return nil+ }+ released := c.abortOperation(&nowMs, RejectionAborted)+ first := !c.roomMedia+ changed := first || c.videoGeneration != generation+ c.roomMedia, c.videoGeneration, c.videoPaused, c.paused = true, generation, paused, false+ if changed {+ for _, edge := range c.upstreamByViewer.Values() {+ edge.VideoGeneration, edge.VideoConnectionID, edge.VideoReady = "", "", false+ // Enabling voice during an accepted share must not reconstruct its+ // already-proven video transports.+ if first && generation != "" && edge.Usable && edge.PhysicalActive {+ edge.VideoGeneration, edge.VideoConnectionID, edge.VideoReady = generation, edge.ConnectionID, true+ }+ }+ }+ clear(c.qualityObservations)+ clear(c.qualityBaselinesPending)+ clear(c.senderQualityObservations)+ clear(c.senderQualityBaselines)+ clear(c.senderQualityRegenerationBlocks)+ c.sfuPublisherQualityObservation = nil+ c.rootConvergenceRootPeerID = ""+ c.touchFacts()+ return released+}++func (c *Controller) videoWorkEnabled() bool {+ return !c.roomMedia || c.videoGeneration != "" && !c.videoPaused+}++func (c *Controller) requiredVideoGeneration() string {+ if c.roomMedia && c.videoWorkEnabled() {+ return c.videoGeneration+ }+ return ""+}++func (c *Controller) qualityConnectionID(edge *CommittedEdge) string {+ if c.roomMedia {+ if edge.VideoReady && edge.VideoGeneration == c.videoGeneration {+ return edge.VideoConnectionID+ }+ return ""+ }+ return edge.ConnectionID+}++// sourceVideoReady is additional publication evidence, never room reachability.+func (c *Controller) sourceVideoReady(peerID string) bool {+ if c.requiredVideoGeneration() == "" || peerID == c.hostPeerID {+ return true+ }+ edge, ok := c.upstreamByViewer.Get(peerID)+ return ok && edge.VideoGeneration == c.videoGeneration && edge.VideoReady+}++func (c *Controller) startPublicationAttach(nowMs int64) bool {+ if !c.roomMedia || !c.videoWorkEnabled() {+ return false+ }+ for childID, edge := range c.upstreamByViewer.All() {+ child, _ := c.participants.Get(childID)+ if child == nil || !child.sessionIs(edge.ChildSessionID) || child.departureConfirmed ||+ !edge.Usable || !edge.PhysicalActive || !c.allowsIncoming(childID, edge.Kind) ||+ edge.VideoGeneration == c.videoGeneration {+ continue+ }+ tuple := CandidateTuple{Kind: edge.Kind, Transport: edge.Transport}+ if edge.Kind == UpstreamPeer {+ if !c.sourceUsable(edge.ParentPeerID) || !c.sourceVideoReady(edge.ParentPeerID) {+ continue+ }+ tuple.ParentPeerID = edge.ParentPeerID+ } else {+ if c.hostPublication == nil || !c.hostPublication.Usable || !c.hostPublication.PhysicalActive ||+ c.hostPublication.Generation != edge.PublicationGeneration {+ continue+ }+ tuple.Publication = PublicationReuse+ }+ c.operation = &operation{+ childPeerID: childID, childSessionID: child.sessionID,+ demandPeerID: childID, demandSessionID: child.sessionID,+ reason: DemandPublicationAttach, baseRevision: c.revision,+ builtAtFactVersion: c.factVersion, deadlineAtMs: nowMs + c.operationTimeoutMs,+ videoGeneration: c.videoGeneration, attachConnectionID: edge.ConnectionID,+ candidates: []CandidatePlan{{Tuple: tuple, EndpointTransition: EndpointTransition{Kind: TransitionNone}}},+ }+ return true+ }+ return false+}++func (c *Controller) publicationAttachOwned(op *operation) bool {+ if !c.roomMedia || !c.videoWorkEnabled() || op.videoGeneration != c.videoGeneration {+ return false+ }+ child, _ := c.participants.Get(op.childPeerID)+ edge, _ := c.upstreamByViewer.Get(op.childPeerID)+ if child == nil || !child.sessionIs(op.childSessionID) || child.departureConfirmed ||+ edge == nil || edge.ChildSessionID != op.childSessionID || edge.ConnectionID != op.attachConnectionID ||+ !edge.Usable || !edge.PhysicalActive || !c.allowsIncoming(op.childPeerID, edge.Kind) {+ return false+ }+ tuple := op.candidates[0].Tuple+ if tuple.Kind == UpstreamPeer {+ parent, _ := c.participants.Get(tuple.ParentPeerID)+ return edge.Kind == UpstreamPeer && edge.ParentPeerID == tuple.ParentPeerID &&+ parent != nil && parent.sessionIs(edge.ParentSessionID) &&+ c.sourceUsable(tuple.ParentPeerID) && c.sourceVideoReady(tuple.ParentPeerID)+ }+ return edge.Kind == UpstreamSfu && c.hostPublication != nil &&+ c.hostPublication.Generation == edge.PublicationGeneration &&+ c.hostPublication.PhysicalActive && c.hostPublication.Usable+}++func (c *Controller) beginPublicationAttach(input BeginInput, op *operation, checked validation) BeginResult {+ if input.ConnectionID == "" || input.Reservation.Kind != "" ||+ input.Reservation.Edge != nil || input.Reservation.Publication != nil ||+ input.Reservation.Overlap != nil || !c.publicationAttachOwned(op) {+ return BeginResult{Released: concatResources(checked.released, reservationResources(input.Reservation))}+ }+ edge, _ := c.upstreamByViewer.Get(op.childPeerID)+ op.current = &attempt{+ tuple: op.candidates[0].Tuple, revision: c.allocateRevision(),+ connectionID: input.ConnectionID, childSessionID: op.childSessionID,+ parentSessionID: edge.ParentSessionID, publicationGeneration: edge.PublicationGeneration,+ startedAtMs: input.NowMs, reservation: CandidateReservation{Kind: ReservationDirect},+ }+ return BeginResult{Accepted: true, Operation: c.operationSnapshot(), Released: checked.released}+}++// One attempt per exact edge/publication is sufficient for optional attachment.+// Failure records an unavailable publication, without consuming or resetting+// the healthy room transport's NAT opportunity. A new edge or publication gets+// its own attempt; unrelated reconciles never retry this failed attachment.+func (c *Controller) finishPublicationAttach(op *operation, ready bool) {+ edge, _ := c.upstreamByViewer.Get(op.childPeerID)+ edge.VideoGeneration, edge.VideoConnectionID, edge.VideoReady = op.videoGeneration, "", ready+ if ready {+ edge.VideoConnectionID = op.current.connectionID+ }+ if ready {+ c.revision = op.current.revision+ } else {+ c.advanceActiveRevision(op)+ }+ c.operation = nil+ c.touchFacts()+}++func (c *Controller) validatePublicationAttach(op *operation, nowMs int64, failed *CandidateGuard) validation {+ result := validation{}+ if !c.publicationAttachOwned(op) {+ c.advanceActiveRevision(op)+ c.operation = nil+ return result+ }+ result.consumedGuard = failed != nil && op.current != nil && c.guardMatches(*failed, op, op.current)+ result.expired = nowMs >= op.deadlineAtMs+ if result.expired || result.consumedGuard {+ c.finishPublicationAttach(op, false)+ result.exhaustedChildPeerID = op.childPeerID+ }+ return result+}diff --git a/internal/server/route/publication_test.go b/internal/server/route/publication_test.gonew file mode 100644index 00000000..7657e4df--- /dev/null+++ b/internal/server/route/publication_test.go@@ -0,0 +1,222 @@+package route++import "testing"++func TestRoomVideoRecoveryPreservesLogicalConnection(t *testing.T) {+ routes := voiceTree(t)+ routes.SetVideoPublication("share", false, 10)+ a := beginVideoAttach(t, routes, 11, A, "video-a")+ eq(t, routes.CandidateReady(a, 12, nil, CandidateProof{VideoGeneration: "share"}).Committed, true)+ // Optional downstream video attachment may remain pending while recovery+ // replaces the parent's video. Neither mutation replaces voice identity.+ before := edgeOf(t, routes, A)+ result := routes.AdoptDirectConnection(AdoptDirectConnectionInput{+ EdgeGuard: edgeGuard(A, "host_session", routes.Revision(), before.ConnectionID),+ NewConnectionID: "recovered-video",+ }, 13)+ eq(t, result.Accepted, true)+ after := edgeOf(t, routes, A)+ eq(t, after.ConnectionID, before.ConnectionID)+ eq(t, after.VideoConnectionID, "recovered-video")+ eq(t, after.VideoGeneration, "share")+ eq(t, after.VideoReady, true)+ eq(t, after.ParentSessionID, before.ParentSessionID)+ eq(t, after.opportunityKey, before.opportunityKey)+ routes.SetVideoPublication("", false, 14)+ eq(t, routes.AdoptDirectConnection(AdoptDirectConnectionInput{+ EdgeGuard: edgeGuard(A, "host_session", routes.Revision(), before.ConnectionID),+ NewConnectionID: "late-video",+ }, 15).Accepted, false)+ eq(t, edgeOf(t, routes, A).ConnectionID, before.ConnectionID)+}++func commitRoomPeer(t *testing.T, routes *Controller, at int64, connection string) CandidateGuard {+ t.Helper()+ must(t, routes.Reconcile(at).Operation)+ op := beginOperation(t, routes, BeginInput{NowMs: at, ConnectionID: connection, Reservation: direct()})+ guard := guardFor(op.ChildPeerID, op.Current.Revision, connection)+ eq(t, routes.CandidateReady(guard, at+1, nil, CandidateProof{}).Accepted, false)+ eq(t, routes.CandidateTransportConnected(guard, at+1).Accepted, true)+ eq(t, routes.CandidateReady(guard, at+2, nil, CandidateProof{}).Committed, true)+ return guard+}++func voiceTree(t *testing.T) *Controller {+ t.Helper()+ routes := newController(1, Options{})+ routes.SetVideoPublication("", false, 0)+ addViewer(routes, A, 1, ms(1))+ commitRoomPeer(t, routes, 2, "voice-a")+ addViewer(routes, B, 0, ms(5))+ commitRoomPeer(t, routes, 6, "voice-b")+ eq(t, edgeOf(t, routes, B).ParentPeerID, A)+ return routes+}++func beginVideoAttach(t *testing.T, routes *Controller, at int64, child, connection string) CandidateGuard {+ t.Helper()+ op := must(t, routes.Reconcile(at).Operation)+ eq(t, op.Reason, DemandPublicationAttach)+ eq(t, op.ChildPeerID, child)+ eq(t, op.AttachConnectionID, edgeOf(t, routes, child).ConnectionID)+ eq(t, op.Candidates[0].EndpointTransition.Kind, TransitionNone)+ begun := routes.BeginCurrentCandidate(BeginInput{+ Guard: cursorGuard(op), NowMs: at, ConnectionID: connection,+ })+ eq(t, begun.Accepted, true)+ eq(t, len(begun.Released), 0)+ return guardFor(child, begun.Operation.Current.Revision, connection)+}++func TestRoomVoiceTreeAttachesVideoSeriallyAndStopPreservesGraph(t *testing.T) {+ routes := voiceTree(t)+ before := routes.Snapshot()+ routes.SetVideoPublication("share-one", false, 10)+ a := beginVideoAttach(t, routes, 11, A, "video-a")+ eq(t, routes.CandidateReady(a, 12, nil, CandidateProof{VideoGeneration: "old-share"}).Accepted, false)+ eq(t, edgeOf(t, routes, A).VideoReady, false)+ // A connected transport alone does not complete video attachment.+ eq(t, routes.CandidateTransportConnected(a, 12).Accepted, true)+ eq(t, routes.Reconcile(13).Operation.ChildPeerID, A)+ eq(t, routes.CandidateReady(a, 14, nil, CandidateProof{VideoGeneration: "share-one"}).Committed, true)+ b := beginVideoAttach(t, routes, 15, B, "video-b")+ eq(t, routes.CandidateReady(b, 16, nil, CandidateProof{VideoGeneration: "share-one"}).Committed, true)+ noOperation(t, routes.Reconcile(17).Operation)+ for _, child := range []string{A, B} {+ edge := edgeOf(t, routes, child)+ previous, _ := before.UpstreamByViewer.Get(child)+ eq(t, edge.ConnectionID, previous.ConnectionID)+ eq(t, edge.ParentPeerID, previous.ParentPeerID)+ eq(t, edge.VideoGeneration, "share-one")+ eq(t, edge.VideoReady, true)+ }+ eq(t, len(routes.SetVideoPublication("", false, 18)), 0)+ for _, child := range []string{A, B} {+ edge := edgeOf(t, routes, child)+ eq(t, edge.Usable && edge.PhysicalActive, true)+ eq(t, edge.VideoGeneration, "")+ eq(t, edge.VideoConnectionID, "")+ eq(t, edge.VideoReady, false)+ }+ noOperation(t, routes.Reconcile(19).Operation)+ routes.SetVideoPublication("share-two", false, 20)+ a2 := beginVideoAttach(t, routes, 21, A, "video-a2")+ eq(t, routes.CandidateReady(a, 22, nil, CandidateProof{VideoGeneration: "share-one"}).Accepted, false)+ eq(t, routes.CandidateReady(a2, 22, nil, CandidateProof{VideoGeneration: "share-two"}).Committed, true)+}++func TestFailedPublicationAttachmentDoesNotRetryOrConsumeVoiceOpportunity(t *testing.T) {+ for _, failure := range []string{"failure", "timeout", "skip"} {+ t.Run(failure, func(t *testing.T) {+ routes := voiceTree(t)+ before := edgeOf(t, routes, A)+ routes.SetVideoPublication("share", false, 10)+ if failure == "skip" {+ op := must(t, routes.Reconcile(11).Operation)+ eq(t, routes.SkipCurrentCandidate(cursorGuard(op), 12, RejectionCandidateFailed).Accepted, true)+ } else {+ guard := beginVideoAttach(t, routes, 11, A, "video-a")+ if failure == "failure" {+ eq(t, routes.CandidateFailed(guard, 12).Accepted, true)+ } else {+ eq(t, routes.OperationExpired(routes.Operation().DeadlineAtMs).Accepted, true)+ }+ }+ edge := edgeOf(t, routes, A)+ eq(t, edge.ConnectionID, before.ConnectionID)+ eq(t, edge.Usable && edge.PhysicalActive, true)+ eq(t, edge.VideoGeneration, "share")+ eq(t, edge.VideoReady, false)+ eq(t, edge.VideoConnectionID, "")+ child, _ := routes.participants.Get(A)+ eq(t, child.availabilityExhausted, false)+ for _, at := range []int64{20_000, 40_000, 80_000} {+ noOperation(t, routes.Reconcile(at).Operation)+ }+ routes.SetVideoPublication("replacement", false, 80_001)+ beginVideoAttach(t, routes, 80_002, A, "replacement-a")+ })+ }+}++func TestStopCancelsAttachmentAndRejectsLateFrame(t *testing.T) {+ routes := voiceTree(t)+ routes.SetVideoPublication("share", false, 10)+ guard := beginVideoAttach(t, routes, 11, A, "video-a")+ eq(t, len(routes.SetVideoPublication("", false, 12)), 0)+ noOperation(t, routes.Operation())+ eq(t, routes.CandidateReady(guard, 13, nil, CandidateProof{VideoGeneration: "share"}).Accepted, false)+ eq(t, edgeOf(t, routes, A).ConnectionID, "voice-a")+ eq(t, edgeOf(t, routes, B).ConnectionID, "voice-b")+}++func TestVoiceOptInRetainsAlreadyProvenVideo(t *testing.T) {+ routes := newController(1, Options{})+ addViewer(routes, A, 0, ms(1))+ must(t, routes.Reconcile(1).Operation)+ commitCurrent(t, routes, 2, "existing-video")+ routes.SetVideoPublication("live-share", false, 4)+ edge := edgeOf(t, routes, A)+ eq(t, edge.VideoGeneration, "live-share")+ eq(t, edge.VideoConnectionID, "existing-video")+ eq(t, edge.VideoReady, true)+ noOperation(t, routes.Reconcile(5).Operation)+}++func TestPausedVideoStillAllowsRoomJoinAndResumeAttaches(t *testing.T) {+ routes := newController(1, Options{})+ routes.SetVideoPublication("", false, 0)+ routes.SetVideoPublication("share", true, 1)+ addViewer(routes, A, 0, ms(2))+ commitRoomPeer(t, routes, 3, "voice-a")+ eq(t, routes.Snapshot().Paused, false)+ eq(t, routes.Snapshot().VideoPaused, true)+ eq(t, edgeOf(t, routes, A).VideoReady, false)+ routes.SetPaused(false, ms(6))+ beginVideoAttach(t, routes, 7, A, "video-a")+}++func TestRoomSfuAttachmentKeepsItsAdmittedRoomResources(t *testing.T) {+ routes := newController(1, Options{SfuEnabled: true, SfuOnly: true})+ addViewer(routes, A, 0, ms(1))+ routes.hydrateHostPublication("room-ingress", res("ingress"), "ingress-pc")+ routes.hydrateEdge(A, sfuEdge("room-ingress", "voice-a", "subscription"))+ routes.SetVideoPublication("", false, 2)+ before := routes.Snapshot()+ routes.SetVideoPublication("share", false, 3)+ guard := beginVideoAttach(t, routes, 4, A, "video-a")+ eq(t, routes.CandidateReady(guard, 5, nil, CandidateProof{VideoGeneration: "share"}).Committed, true)+ eq(t, len(routes.SetVideoPublication("", false, 6)), 0)+ eq(t, routes.Publication().Resource, before.HostPublication.Resource)+ old, _ := before.UpstreamByViewer.Get(A)+ eq(t, edgeOf(t, routes, A).Resource, old.Resource)+ eq(t, edgeOf(t, routes, A).ConnectionID, old.ConnectionID)+}++func TestAttachedVideoQualityUsesPhysicalVideoIdentityAndNativeProof(t *testing.T) {+ routes := newController(2, Options{QualityConvergenceEnabled: true})+ routes.SetVideoPublication("", false, 0)+ addViewer(routes, A, 1, ms(1))+ commitRoomPeer(t, routes, 2, "voice-a")+ routes.SetVideoPublication("share", false, 5)+ guard := beginVideoAttach(t, routes, 6, A, "video-a")+ eq(t, routes.CandidateReady(guard, 7, nil, CandidateProof{VideoGeneration: "share"}).Committed, true)+ eq(t, observeSenderState(routes, senderState{+ childPeerID: A, connectionID: "voice-a", state: SenderQualityDegraded, acceptedAtMs: 8,+ }).Accepted, false)+ observePersistentDegraded(t, routes, A, "video-a", 10)+ op := must(t, routes.Reconcile(14).Operation)+ eq(t, op.Reason, DemandQualityConvergence)+ begun := beginOperation(t, routes, BeginInput{NowMs: 15, ConnectionID: "replacement", Reservation: direct()})+ candidate := guardFor(A, begun.Current.Revision, "replacement")+ eq(t, routes.CandidateReady(candidate, 16, nil, CandidateProof{+ RelativeQualityApproved: true, VideoGeneration: "share",+ }).Committed, false)+ eq(t, routes.ObserveSenderQualityEvidence(senderSample(+ HOST, A, begun.Current.Revision, "replacement", "replacement-sender", SenderQualityHealthy, 17), nil).Committed, true)+ eq(t, edgeOf(t, routes, A).VideoConnectionID, "replacement")+ routes.SetVideoPublication("", false, 18)+ eq(t, observeSenderState(routes, senderState{+ childPeerID: A, connectionID: "replacement", state: SenderQualityHealthy, acceptedAtMs: 19,+ }).Accepted, false)+}diff --git a/internal/server/route/quality.go b/internal/server/route/quality.goindex e8c9fce4..85be4a19 100644--- a/internal/server/route/quality.go+++ b/internal/server/route/quality.go@@ -10,7 +10,7 @@ import (// child's committed edge: rejected on any mismatch, accepted when consumed// without aggregation, observed when aggregated.func (c *Controller) ObserveQualityEvidence(input RouteQualityEvidenceInput) RouteQualityEvidenceResult {- if c.paused ||+ if c.paused || !c.videoWorkEnabled() ||input.RouteRevision != c.revision ||!isSafeInteger(input.PresentationEpoch) ||input.PresentationEpoch < 0 ||@@ -28,7 +28,7 @@ func (c *Controller) ObserveQualityEvidence(input RouteQualityEvidenceInput) Rou!edge.Usable ||!edge.PhysicalActive ||edge.ChildSessionID != input.ChildSessionID ||- edge.ConnectionID != input.ConnectionID ||+ c.qualityConnectionID(edge) != input.ConnectionID ||!qualityUpstreamMatches(edge, input.Upstream) ||!c.sourceUsableForQuality(edge) {return QualityEvidenceRejected@@ -124,7 +124,7 @@ func (c *Controller) ObserveSenderQualityEvidence(input SenderQualityEvidenceInpcommitReservation = func(CandidateReservation) bool { return true }}if !c.qualityConvergenceEnabled ||- c.paused ||+ (c.paused || !c.videoWorkEnabled()) ||!isSafeInteger(input.AcceptedAtMs) ||input.AcceptedAtMs < 0 {return c.senderRejected()@@ -168,7 +168,7 @@ func (c *Controller) ObserveSenderQualityEvidence(input SenderQualityEvidenceInpedge.ParentPeerID != input.ParentPeerID ||edge.ParentSessionID != input.ParentSessionID ||edge.ChildSessionID != child.sessionID ||- edge.ConnectionID != input.ConnectionID {+ c.qualityConnectionID(edge) != input.ConnectionID {return c.senderRejected()}previous := c.senderQualityObservations[input.ChildPeerID]@@ -277,7 +277,7 @@ func (c *Controller) ObserveSfuPublisherQualityEvidence(input SfuPublisherQualit}host, _ := c.participants.Get(c.hostPeerID)if !c.qualityConvergenceEnabled ||- c.paused ||+ (c.paused || !c.videoWorkEnabled()) ||input.HostPeerID != c.hostPeerID ||host == nil || host.sessionID == "" ||!host.sessionIs(input.HostSessionID) {@@ -369,7 +369,7 @@ func (c *Controller) ObserveSfuPublisherQualityEvidence(input SfuPublisherQualitresult := c.CandidateFailed(guard, input.AcceptedAtMs)settled = &result} else if consecutiveHealthyWindows >= persistentDegradedWindows {- result := c.CandidateReady(guard, input.AcceptedAtMs, commitReservation, CandidateProof{})+ result := c.CandidateReady(guard, input.AcceptedAtMs, commitReservation, CandidateProof{VideoGeneration: op.videoGeneration})settled = &result}if settled != nil {@@ -462,7 +462,7 @@ func (c *Controller) settleCandidateQuality(op *operation, att *attempt, state Ssettled = &result} else if att.mediaReady &&(att.tuple.Kind != UpstreamSfu || consecutiveHealthyWindows >= persistentDegradedWindows) {- result := c.CandidateReady(guard, acceptedAtMs, commitReservation, CandidateProof{})+ result := c.CandidateReady(guard, acceptedAtMs, commitReservation, CandidateProof{VideoGeneration: op.videoGeneration})settled = &result}if settled == nil {@@ -545,7 +545,7 @@ func (c *Controller) senderQualityState(childPeerID string, edge *CommittedEdge,edge.ChildSessionID == observation.childSessionID &&edge.ParentPeerID == observation.parentPeerID &&edge.ParentSessionID == observation.parentSessionID &&- edge.ConnectionID == observation.connectionID &&+ c.qualityConnectionID(edge) == observation.connectionID &&c.sourceUsableForQuality(edge) {return observation.state}@@ -563,7 +563,7 @@ func (c *Controller) currentQualityOperationSource(childPeerID string) *senderQuobservation.childSessionID != edge.ChildSessionID ||observation.parentPeerID != edge.ParentPeerID ||observation.parentSessionID != edge.ParentSessionID ||- observation.connectionID != edge.ConnectionID {+ observation.connectionID != c.qualityConnectionID(edge) {return nil}return &senderQualityIdentity{@@ -597,7 +597,7 @@ func (c *Controller) senderQualityRegenerationBlocked(childPeerID string, edge *if block.childSessionID != edge.ChildSessionID ||block.parentPeerID != edge.ParentPeerID ||block.parentSessionID != edge.ParentSessionID ||- block.connectionID != edge.ConnectionID {+ block.connectionID != c.qualityConnectionID(edge) {delete(c.senderQualityRegenerationBlocks, childPeerID)return false}@@ -662,7 +662,7 @@ func (c *Controller) decodedProgressFresh(childPeerID string, edge *CommittedEdgnowMs < *observation.lastDecodedProgressAtMs+qualityEvidenceExpiryMs &¤t != nil && current.sessionIs(observation.childSessionID) &&edge.ChildSessionID == observation.childSessionID &&- edge.ConnectionID == observation.connectionID &&+ c.qualityConnectionID(edge) == observation.connectionID &&qualityObservationMatchesEdge(observation, edge) &&c.sourceUsableForQuality(edge)}diff --git a/internal/server/route/relay_volunteer.go b/internal/server/route/relay_volunteer.gonew file mode 100644index 00000000..c0438e42--- /dev/null+++ b/internal/server/route/relay_volunteer.go@@ -0,0 +1,42 @@+package route++import "github.com/TNTcraftHIM/Piik/internal/server/protocol"++// MaxRelayVolunteerChildren is the steady fanout of a willing ordinary peer.+// The existing single operation may reserve one additional physical copy.+const MaxRelayVolunteerChildren = protocol.MaxViewersPerRoomLimit++// SetRelayVolunteer changes policy for this exact authenticated session. The+// endpoint's reported capacity remains the physical capability ceiling.+func (c *Controller) SetRelayVolunteer(peerID, sessionID string, enabled bool, nowMs *int64) bool {+ current, _ := c.participants.Get(peerID)+ if current == nil || !current.sessionIs(sessionID) {+ return false+ }+ if current.relayVolunteer == enabled {+ return true+ }+ current.relayVolunteer = enabled+ current.effectiveDownstreamCapacity = c.effectiveCapacity(current.reportedDownstreamCapacity, enabled)+ c.recordCapacityReduction(peerID, nowMs)+ c.touchFacts()+ return true+}++func (c *Controller) recordCapacityReduction(peerID string, nowMs *int64) {+ if nowMs != nil {+ for _, childPeerID := range c.overflowPeerChildren(peerID) {+ c.recordDemand(childPeerID, *nowMs, DemandCapacityReduction)+ }+ }+}++func (c *Controller) transitionCopyLimit(producer *participant) int {+ if producer.relayVolunteer && producer.effectiveDownstreamCapacity > c.endpointMediaCopyCapacity {+ if producer.effectiveDownstreamCapacity > 3 {+ return producer.effectiveDownstreamCapacity + 1+ }+ return 3+ }+ return protocol.EndpointMediaCopyLimit(c.endpointMediaCopyCapacity, protocol.EndpointMediaCopyTransition)+}diff --git a/internal/server/route/relay_volunteer_test.go b/internal/server/route/relay_volunteer_test.gonew file mode 100644index 00000000..a5bad6b5--- /dev/null+++ b/internal/server/route/relay_volunteer_test.go@@ -0,0 +1,95 @@+package route++import (+ "fmt"+ "testing"+)++func TestRelayVolunteerUsesReportedCapabilityAndExactSession(t *testing.T) {+ routes := newController(2, Options{})+ addViewer(routes, A, 20, nil)+ peer, _ := routes.participants.Get(A)+ eq(t, peer.effectiveDownstreamCapacity, 2)+ eq(t, routes.SetRelayVolunteer(A, "stale", true, nil), false)+ eq(t, routes.SetRelayVolunteer(A, sessionOf(A), true, nil), true)+ eq(t, peer.effectiveDownstreamCapacity, 20)+ routes.UpsertParticipant(viewerInput(A, sessionOf(A), 100), nil)+ eq(t, peer.effectiveDownstreamCapacity, 20)+ eq(t, routes.SetEffectiveCapacity(A, sessionOf(A), 3, nil), true)+ eq(t, peer.effectiveDownstreamCapacity, 3)+ eq(t, routes.transitionCopyLimit(peer), 3) // Older App cannot reserve a fourth copy.+ routes.SetEffectiveCapacity(A, sessionOf(A), 20, nil)+ eq(t, routes.transitionCopyLimit(peer), 21)+ routes.UpsertParticipant(viewerInput(A, "new-session", 20), nil)+ eq(t, peer.relayVolunteer, false)+ eq(t, peer.effectiveDownstreamCapacity, 2)+ eq(t, routes.SetRelayVolunteer(A, sessionOf(A), true, nil), false)+}++func TestRelayVolunteerFanoutAndWithdrawalKeepSingleRouteOperation(t *testing.T) {+ routes := newController(1, Options{})+ routes.SetVideoPublication("", false, 0)+ addViewer(routes, A, 20, ms(0))+ routes.Reconcile(0)+ commitRoomPeer(t, routes, 0, "host-to-relay")+ routes.SetRelayVolunteer(A, sessionOf(A), true, ms(1))+ // A relay is itself one of the twenty Viewers, so nineteen children is+ // the full room through an ordinary volunteering Viewer.+ for index := range 19 {+ child := fmt.Sprintf("child_%02d", index)+ addViewer(routes, child, 1, ms(int64(index+2)))+ op := must(t, routes.Reconcile(int64(index+2)).Operation)+ eq(t, op.Candidates[0].Tuple.ParentPeerID, A)+ commitRoomPeer(t, routes, int64(index+2), child+"-edge")+ }+ eq(t, routes.physicalCopies(A), 19)+ routes.SetRelayVolunteer(A, sessionOf(A), false, ms(100))+ eq(t, len(routes.overflowPeerChildren(A)), 18)+ // Each handoff preserves the incoming relay and remaining physical media;+ // no second planner or bulk teardown is needed to reduce its fanout.+ for index := range 18 {+ op := must(t, routes.Reconcile(int64(101+index)).Operation)+ eq(t, op.Reason, DemandCapacityReduction)+ if op.Candidates[0].Tuple.ParentPeerID == A {+ t.Fatal("withdrawn relay admitted a new child")+ }+ commitRoomPeer(t, routes, int64(101+index), fmt.Sprintf("handoff-%d", index))+ }+ eq(t, routes.physicalCopies(A), 1)+ eq(t, edgeOf(t, routes, A).ConnectionID, "host-to-relay")+}++func TestRelayVolunteerTwentyChildPhysicalOverlapRequiresOptIn(t *testing.T) {+ routes := newController(2, Options{})+ routes.SetVideoPublication("", false, 0)+ routes.SetEffectiveCapacity(HOST, "host_session", 20, nil)+ routes.SetRelayVolunteer(HOST, "host_session", true, nil)+ for index := range 20 {+ child := fmt.Sprintf("viewer_%02d", index)+ addViewer(routes, child, 0, ms(int64(index)))+ commitRoomPeer(t, routes, int64(index), child+"-edge")+ }+ plan := routes.planCandidate("viewer_00", regenerateTuple(HOST))+ if plan == nil || plan.EndpointTransition.Kind != TransitionOverlap {+ t.Fatalf("full volunteer replacement = %+v", plan)+ }+ routes.SetRelayVolunteer(HOST, "host_session", false, ms(100))+ if plan := routes.planCandidate("viewer_00", regenerateTuple(HOST)); plan != nil {+ t.Fatalf("withdrawn volunteer offered another physical copy: %+v", plan)+ }+}++func TestHostVideoConnectionIdentityPreservesRoomPublication(t *testing.T) {+ routes := newController(2, Options{})+ routes.hydrateHostPublication("logical-publication", res("publication"), "old-video")+ eq(t, routes.SetHostVideoConnectionID("new-video"), false)+ routes.SetVideoPublication("share", false, 0)+ publication := *routes.hostPublication+ eq(t, routes.SetHostVideoConnectionID(""), false)+ eq(t, routes.SetHostVideoConnectionID("new-video"), true)+ eq(t, routes.hostPublication.Generation, publication.Generation)+ eq(t, routes.hostPublication.Resource, publication.Resource)+ eq(t, routes.hostPublication.Usable, publication.Usable)+ eq(t, routes.hostPublication.PhysicalActive, publication.PhysicalActive)+ eq(t, routes.hostPublication.ConnectionID, "new-video")+}diff --git a/internal/server/route/sfu_bootstrap.go b/internal/server/route/sfu_bootstrap.goindex dd4845ae..43c36e88 100644--- a/internal/server/route/sfu_bootstrap.go+++ b/internal/server/route/sfu_bootstrap.go@@ -97,7 +97,7 @@ func (c *Controller) sfuBootstrapNeeded(demandPeerID string) bool {}demand, _ := c.participants.Get(demandPeerID)return demand != nil && demand.sessionID != "" &&- !c.usableRoute(demandPeerID) &&+ (!c.usableRoute(demandPeerID) || c.voiceRouteMissing(demandPeerID)) &&c.sfuOpportunityAvailable(demandPeerID)}diff --git a/internal/server/route/timing.go b/internal/server/route/timing.goindex 28d09f67..dc58bae6 100644--- a/internal/server/route/timing.go+++ b/internal/server/route/timing.go@@ -145,7 +145,7 @@ func (c *Controller) diagnosticParent(edge *CommittedEdge, ordinals map[string]ifunc (c *Controller) diagnosticQuality(childPeerID string, edge *CommittedEdge, nowMs int64) *protocol.RouteDiagnosticQuality {observation := c.qualityObservations[childPeerID]current, _ := c.participants.Get(childPeerID)- if c.paused ||+ if c.paused || !c.videoWorkEnabled() ||observation == nil ||observation.eligibleWindows == 0 ||nowMs >= observation.lastAcceptedAtMs+qualityEvidenceExpiryMs ||@@ -154,7 +154,7 @@ func (c *Controller) diagnosticQuality(childPeerID string, edge *CommittedEdge,edge == nil ||!edge.Usable ||!edge.PhysicalActive ||- edge.ConnectionID != observation.connectionID ||+ c.qualityConnectionID(edge) != observation.connectionID ||!qualityObservationMatchesEdge(observation, edge) ||!c.sourceUsableForQuality(edge) {return nildiff --git a/internal/server/route/voice.go b/internal/server/route/voice.gonew file mode 100644index 00000000..098538b6--- /dev/null+++ b/internal/server/route/voice.go@@ -0,0 +1,79 @@+package route++import (+ "maps"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+)++// SetVoiceListeners supplies current room permission, not a second topology.+// A permission change opens the existing bounded availability opportunities+// only for listeners whose route needs repair. Healthy video stays committed+// while the ordinary serial operation proves a permitted replacement.+func (c *Controller) SetVoiceListeners(peerIDs []string, nowMs int64) bool {+ if !c.roomMedia {+ return false+ }+ next := make(map[string]bool, len(peerIDs))+ for _, peerID := range peerIDs {+ next[peerID] = true+ }+ if maps.Equal(c.voiceListeners, next) {+ return false+ }+ previous := c.voiceListeners+ c.voiceListeners = next+ for _, current := range c.participants.Values() {+ if current.role != protocol.RoleViewer ||+ previous[current.peerID] == next[current.peerID] && !c.voiceRouteMissing(current.peerID) {+ continue+ }+ current.consumedCandidateOpportunities.Clear()+ current.availabilityExhausted = false+ current.bootstrapFailureReported = false+ c.directContinuations.Delete(current.peerID)+ c.clearSfuBootstrapForDemand(current.peerID)+ if c.voiceRouteMissing(current.peerID) {+ c.recordDemand(current.peerID, nowMs, DemandEdgeUnavailable)+ }+ }+ c.touchFacts()+ return true+}++func (c *Controller) voiceParentAllowed(childPeerID, parentPeerID string) bool {+ return !c.voiceListeners[childPeerID] || c.voiceSourceUsable(parentPeerID)+}++func (c *Controller) voiceRouteMissing(peerID string) bool {+ return c.voiceListeners[peerID] && !c.voiceSourceUsable(peerID)+}++// The permitted path ends at the listening Host or the admitted SFU junction.+// Checking every hop prevents an approved relay with unapproved upstream from+// becoming a candidate that can never receive the room's voice publications.+func (c *Controller) voiceSourceUsable(peerID string) bool {+ seen := make(map[string]bool)+ for {+ if !c.voiceListeners[peerID] || seen[peerID] {+ return false+ }+ seen[peerID] = true+ participant, _ := c.participants.Get(peerID)+ if participant == nil || participant.sessionID == "" || participant.departureConfirmed {+ return false+ }+ if peerID == c.hostPeerID {+ return true+ }+ edge, _ := c.upstreamByViewer.Get(peerID)+ if edge == nil || !edge.Usable || !edge.PhysicalActive {+ return false+ }+ if edge.Kind == UpstreamSfu {+ return c.hostPublication != nil && c.hostPublication.Usable &&+ c.hostPublication.PhysicalActive && c.hostPublication.Generation == edge.PublicationGeneration+ }+ peerID = edge.ParentPeerID+ }+}diff --git a/internal/server/route/voice_test.go b/internal/server/route/voice_test.gonew file mode 100644index 00000000..204323ca--- /dev/null+++ b/internal/server/route/voice_test.go@@ -0,0 +1,90 @@+package route++import "testing"++func videoTreeForVoice(t *testing.T, capacity int, options Options) *Controller {+ t.Helper()+ routes := newController(capacity, options)+ addViewer(routes, A, 1, nil)+ addViewer(routes, B, 1, nil)+ routes.hydrateEdge(A, peerEdge(HOST, "video-a"))+ routes.hydrateEdge(B, peerEdge(A, "video-b"))+ routes.SetVideoPublication("share", false, 1)+ return routes+}++func TestVoiceApprovalReparentsThroughTheExistingOperation(t *testing.T) {+ routes := videoTreeForVoice(t, 2, Options{})+ routes.SetVoiceListeners([]string{HOST, B}, 2)+ op := must(t, routes.Reconcile(3).Operation)+ eq(t, op.ChildPeerID, B)+ eq(t, op.Reason, DemandEdgeUnavailable)+ eq(t, op.Candidates[0].Tuple.ParentPeerID, HOST)+ eq(t, edgeOf(t, routes, B).ConnectionID, "video-b")+ eq(t, edgeOf(t, routes, B).VideoReady, true)+ prepared := beginOperation(t, routes, BeginInput{NowMs: 4, ConnectionID: "permitted-b", Reservation: direct()})+ guard := guardFor(B, prepared.Current.Revision, "permitted-b")+ eq(t, routes.CandidateReady(guard, 5, nil, CandidateProof{VideoGeneration: "share"}).Committed, true)+ eq(t, edgeOf(t, routes, B).ParentPeerID, HOST)+ eq(t, routes.voiceRouteMissing(B), false)+ noOperation(t, routes.Reconcile(6).Operation)+}++func TestVoiceReparentFailureRetainsVideoAndPermissionDeltaReopensOnlyDemand(t *testing.T) {+ routes := videoTreeForVoice(t, 2, Options{})+ routes.SetVoiceListeners([]string{HOST, A, B}, 2)+ noOperation(t, routes.Reconcile(3).Operation)+ routes.SetVoiceListeners([]string{HOST, B}, 4)+ must(t, routes.Reconcile(5).Operation)+ prepared := beginOperation(t, routes, BeginInput{NowMs: 5, ConnectionID: "failed-b", Reservation: direct()})+ eq(t, routes.CandidateFailed(guardFor(B, prepared.Current.Revision, "failed-b"), 6).Accepted, true)+ for _, now := range []int64{7, 20_000, 40_000} {+ noOperation(t, routes.Reconcile(now).Operation)+ eq(t, edgeOf(t, routes, B).ConnectionID, "video-b")+ eq(t, edgeOf(t, routes, B).Usable && edgeOf(t, routes, B).VideoReady, true)+ }+ eq(t, routes.SetVoiceListeners([]string{B, HOST}, 40_001), false)+ noOperation(t, routes.Reconcile(40_002).Operation)+ // A newly permitted relay is an actual new opportunity. Its existing+ // healthy route already restores the listener without any replacement.+ routes.SetVoiceListeners([]string{HOST, A, B}, 40_003)+ eq(t, routes.voiceRouteMissing(B), false)+ noOperation(t, routes.Reconcile(40_004).Operation)+ routes.SetVoiceListeners([]string{HOST, B}, 40_005)+ eq(t, must(t, routes.Reconcile(40_006).Operation).ChildPeerID, B)+}++func TestVoiceParentRequiresPermittedAncestorsAndLegacyRoutesRemainUnchanged(t *testing.T) {+ routes := videoTreeForVoice(t, 2, Options{})+ addViewer(routes, C, 0, nil)+ routes.hydrateEdge(C, peerEdge(B, "video-c"))+ // Hydrated test edge follows opt-in; mark its existing video evidence.+ edge, _ := routes.upstreamByViewer.Get(C)+ edge.VideoReady, edge.VideoGeneration, edge.VideoConnectionID = true, "share", "video-c"+ routes.SetVoiceListeners([]string{HOST, B, C}, 2)+ for _, plan := range routes.buildCandidates(C, false) {+ if plan.Tuple.Kind == UpstreamPeer && (plan.Tuple.ParentPeerID == A || plan.Tuple.ParentPeerID == B) {+ t.Fatal("candidate path traversed an unapproved listener")+ }+ }+ legacy := newController(1, Options{})+ addViewer(legacy, A, 1, nil)+ addViewer(legacy, B, 0, nil)+ legacy.hydrateEdge(A, peerEdge(HOST, "legacy-a"))+ legacy.hydrateEdge(B, peerEdge(A, "legacy-b"))+ eq(t, legacy.SetVoiceListeners([]string{HOST, B}, 2), false)+ noOperation(t, legacy.Reconcile(3).Operation)+}++func TestVoicePermissionRepairCanUseExistingSfuBootstrap(t *testing.T) {+ routes := videoTreeForVoice(t, 1, Options{SfuEnabled: true})+ routes.SetVoiceListeners([]string{HOST, B}, 2)+ // Host's only copy is occupied by video-only A. The ordinary bootstrap+ // operation moves A onto SFU while retaining its healthy video, opening+ // the admitted SFU junction for B's subsequent permission repair.+ op := must(t, routes.Reconcile(3).Operation)+ eq(t, op.Reason, DemandSfuBootstrap)+ eq(t, op.ChildPeerID, A)+ eq(t, op.DemandPeerID, B)+ eq(t, edgeOf(t, routes, A).Usable && edgeOf(t, routes, B).Usable, true)+}diff --git a/internal/server/sfu/media.go b/internal/server/sfu/media.goindex 56d3ba3a..44b91f34 100644--- a/internal/server/sfu/media.go+++ b/internal/server/sfu/media.go@@ -64,6 +64,7 @@ type Media struct {options MediaOptionsmu sync.Mutexpublications map[ResourceFence]*mediaPublication+ voice *voiceMediaclosed boolcloseOnce sync.OncecloseErr error@@ -102,18 +103,20 @@ type subscriptionKey struct {}type mediaSubscription struct {- key subscriptionKey- transport *forwarding.Transport- signaling sync.Mutex- ctx context.Context- cancel context.CancelFunc- prepared chan struct{}- closeOnce sync.Once- closeErr error+ key subscriptionKey+ // Admission belongs to the room edge; its video transport can be replaced.+ resourceConnectionID string+ transport *forwarding.Transport+ signaling sync.Mutex+ ctx context.Context+ cancel context.CancelFunc+ prepared chan struct{}+ closeOnce sync.Once+ closeErr error}func NewMedia(options MediaOptions) *Media {- return &Media{options: options, publications: make(map[ResourceFence]*mediaPublication)}+ return &Media{options: options, publications: make(map[ResourceFence]*mediaPublication), voice: newVoiceMedia(options.Settings)}}func (media *Media) HasPublication(fence ResourceFence, connectionID string) bool {@@ -553,7 +556,8 @@ func (media *Media) PrepareSubscriber(ctx context.Context, fence SubscriptionFenkey := subscriptionKey{peerID: fence.ViewerPeerID, connectionID: connectionID}// The route-operation context bounds preparation, not committed media lifetime.lifetime, cancel := context.WithCancel(context.Background())- subscriber := &mediaSubscription{key: key, ctx: lifetime, cancel: cancel, prepared: make(chan struct{})}+ subscriber := &mediaSubscription{key: key, resourceConnectionID: fence.ConnectionID,+ ctx: lifetime, cancel: cancel, prepared: make(chan struct{})}publication.mu.Lock()if publication.closed || publication.failure != nil || publication.subscribers[key] != nil {publication.mu.Unlock()@@ -708,12 +712,19 @@ func (media *Media) CloseSubscription(fence SubscriptionFence, connectionID stri}key := subscriptionKey{peerID: fence.ViewerPeerID, connectionID: connectionID}publication.mu.Lock()- subscriber := publication.subscribers[key]+ var subscribers []*mediaSubscription+ for _, subscriber := range publication.subscribers {+ if subscriber.key == key || connectionID == fence.ConnectionID &&+ subscriber.key.peerID == fence.ViewerPeerID && subscriber.resourceConnectionID == connectionID {+ subscribers = append(subscribers, subscriber)+ }+ }publication.mu.Unlock()- if subscriber != nil {- return publication.closeSubscriber(subscriber)+ var closeErr error+ for _, subscriber := range subscribers {+ closeErr = errors.Join(closeErr, publication.closeSubscriber(subscriber))}- return nil+ return closeErr}func (publication *mediaPublication) closeSubscriber(subscriber *mediaSubscription) error {@@ -749,6 +760,20 @@ func (media *Media) ClosePublication(fence ResourceFence) error {return err}+// RetirePublication detaches only the identified video publisher. Its logical+// room reservation remains admitted; a replacement may be prepared immediately.+// The caller owns scheduling and joining the returned physical close.+func (media *Media) RetirePublication(fence ResourceFence, connectionID string) func() error {+ media.mu.Lock()+ defer media.mu.Unlock()+ publication := media.publications[fence]+ if publication == nil || publication.connectionID != connectionID {+ return nil+ }+ delete(media.publications, fence)+ return publication.close+}+func (publication *mediaPublication) close() error {publication.closeOnce.Do(func() {publication.mu.Lock()@@ -794,6 +819,7 @@ func (media *Media) Close() error {publications := media.publicationsmedia.publications = nilmedia.mu.Unlock()+ media.closeErr = media.voice.close()for _, publication := range publications {media.closeErr = errors.Join(media.closeErr, publication.close())}diff --git a/internal/server/sfu/voice.go b/internal/server/sfu/voice.gonew file mode 100644index 00000000..d3fd4386--- /dev/null+++ b/internal/server/sfu/voice.go@@ -0,0 +1,193 @@+package sfu++import (+ "errors"+ "slices"+ "sort"+ "sync"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/pion/webrtc/v4"+)++const maxVoicePublications = protocol.MaxViewersPerRoomLimit + 1++// VoicePublication is an already-authorized source, including one relayed by a peer.+type VoicePublication struct {+ ID string `json:"id"`+ PeerID string `json:"peerId"`+}++// VoiceConnectionPlan supplies physical work for one junction of the room graph.+// The caller owns admission, publication authority, routing and eventual retirement.+type VoiceConnectionPlan struct {+ RoomID, PeerID, SessionID, ConnectionID string+ Publish, Subscribe []VoicePublication+}++type VoiceTrack struct {+ MID string `json:"mid"`+ PublicationID string `json:"publicationId"`+}++// Offers name both directions; answers name only tracks the peer actually sends.+// Revision fences an answer from earlier negotiation on the same connection.+type VoiceDescription struct {+ Revision uint64 `json:"revision"`+ SDP webrtc.SessionDescription `json:"sdp"`+ Tracks []VoiceTrack `json:"tracks"`+}++type VoiceSignal struct {+ Description *VoiceDescription `json:"description,omitempty"`+ Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`+ Renegotiate bool `json:"renegotiate,omitempty"`+}++type VoiceMediaEvent struct {+ RoomID, PeerID, SessionID, ConnectionID string+ Description *VoiceDescription+ Candidate *webrtc.ICECandidateInit+ State webrtc.PeerConnectionState+}++// VoiceRuntime leaves the existing video runtime and its implementations unchanged.+type VoiceRuntime interface {+ ConfigureVoice(VoiceConnectionPlan, func(VoiceMediaEvent)) error+ SignalVoice(room, peer, session, connection string, signal VoiceSignal) error+ CloseVoice(room, peer, session, connection string) error+}++type voiceKey struct{ room, peer, session, connection string }++func (p VoiceConnectionPlan) key() voiceKey {+ return voiceKey{p.RoomID, p.PeerID, p.SessionID, p.ConnectionID}+}++type voiceMedia struct {+ mu sync.Mutex+ settings webrtc.SettingEngine+ connections map[voiceKey]*voiceConnection+ closed bool+}++func newVoiceMedia(settings webrtc.SettingEngine) *voiceMedia {+ return &voiceMedia{settings: settings, connections: make(map[voiceKey]*voiceConnection)}+}++func normalizeVoicePlan(plan VoiceConnectionPlan) (VoiceConnectionPlan, error) {+ for _, id := range []string{plan.RoomID, plan.PeerID, plan.SessionID, plan.ConnectionID} {+ if id == "" || len(id) > 128 {+ return plan, errors.New("voice connection identity is invalid")+ }+ }+ if len(plan.Publish) > maxVoicePublications || len(plan.Subscribe) > maxVoicePublications {+ return plan, errors.New("voice publication count is invalid")+ }+ seen := make(map[string]bool)+ for _, list := range [][]VoicePublication{plan.Publish, plan.Subscribe} {+ for _, pub := range list {+ if pub.ID == "" || len(pub.ID) > 128 || pub.PeerID == "" || len(pub.PeerID) > 128 || seen[pub.ID] {+ return plan, errors.New("voice publication identity is invalid")+ }+ seen[pub.ID] = true+ }+ }+ plan.Publish, plan.Subscribe = slices.Clone(plan.Publish), slices.Clone(plan.Subscribe)+ for _, list := range [][]VoicePublication{plan.Publish, plan.Subscribe} {+ sort.Slice(list, func(i, j int) bool { return list[i].ID < list[j].ID })+ }+ return plan, nil+}++func (media *Media) ConfigureVoice(plan VoiceConnectionPlan, emit func(VoiceMediaEvent)) error {+ plan, err := normalizeVoicePlan(plan)+ if err != nil {+ return err+ }+ if emit == nil {+ return errors.New("voice callback is required")+ }+ v := media.voice+ v.mu.Lock()+ if v.closed {+ v.mu.Unlock()+ return errors.New("voice media is closed")+ }+ c := v.connections[plan.key()]+ if c == nil {+ // One committed connection per member. The room's one transition may+ // replace both the Host junction and its first child connection.+ roomCount := 0+ for key := range v.connections {+ if key.room == plan.RoomID {+ roomCount+++ }+ }+ if roomCount >= maxVoicePublications+2 {+ v.mu.Unlock()+ return errors.New("voice connection capacity is exhausted")+ }+ c, err = newVoiceConnection(v, plan, emit)+ if err != nil {+ v.mu.Unlock()+ return err+ }+ v.connections[plan.key()] = c+ }+ c.emit = emit+ changed := !slices.Equal(c.plan.Publish, plan.Publish) || !slices.Equal(c.plan.Subscribe, plan.Subscribe)+ c.plan = plan+ if changed {+ c.version+++ }+ // RTP authorization changes before any deferred SDP work. A removed sender+ // cannot continue delivering packets while an older answer remains pending.+ for id, out := range c.outgoing {+ if !slices.Contains(plan.Subscribe, out.source()) {+ out.disable()+ delete(c.outgoing, id)+ }+ }+ v.mu.Unlock()+ return c.negotiate(false)+}++func (media *Media) SignalVoice(room, peer, session, connection string, signal VoiceSignal) error {+ v := media.voice+ v.mu.Lock()+ c := v.connections[voiceKey{room, peer, session, connection}]+ v.mu.Unlock()+ if c == nil {+ return errors.New("voice connection is no longer current")+ }+ return c.signal(signal)+}++// A delayed retirement cannot close another connection or a replacement session.+func (media *Media) CloseVoice(room, peer, session, connection string) error {+ v := media.voice+ v.mu.Lock()+ c := v.connections[voiceKey{room, peer, session, connection}]+ if c != nil {+ delete(v.connections, c.key)+ }+ v.mu.Unlock()+ if c == nil {+ return nil+ }+ return c.close()+}++func (v *voiceMedia) close() error {+ v.mu.Lock()+ v.closed = true+ connections := v.connections+ v.connections = make(map[voiceKey]*voiceConnection)+ v.mu.Unlock()+ var err error+ for _, c := range connections {+ err = errors.Join(err, c.close())+ }+ return err+}diff --git a/internal/server/sfu/voice_connection.go b/internal/server/sfu/voice_connection.gonew file mode 100644index 00000000..132d29d4--- /dev/null+++ b/internal/server/sfu/voice_connection.go@@ -0,0 +1,476 @@+package sfu++import (+ "errors"+ "slices"+ "strings"+ "sync"++ "github.com/TNTcraftHIM/Piik/internal/media/forwarding"+ "github.com/pion/interceptor"+ "github.com/pion/rtp"+ "github.com/pion/webrtc/v4"+)++var voiceCodec = webrtc.RTPCodecCapability{+ MimeType: webrtc.MimeTypeOpus, ClockRate: 48_000, Channels: 2,+ SDPFmtpLine: "minptime=10;useinbandfec=1",+}++type voiceReceiveSlot struct {+ transceiver *webrtc.RTPTransceiver+ publication VoicePublication+ rtcp bool+}++type voiceSendSlot struct {+ mu sync.Mutex+ publication VoicePublication+ transceiver *webrtc.RTPTransceiver+ track *webrtc.TrackLocalStaticRTP+ active bool+}++func (s *voiceSendSlot) disable() {+ s.mu.Lock()+ s.active = false+ s.mu.Unlock()+}++func (s *voiceSendSlot) source() VoicePublication {+ s.mu.Lock()+ defer s.mu.Unlock()+ return s.publication+}++func (s *voiceSendSlot) write(publication VoicePublication, packet *rtp.Packet) {+ s.mu.Lock()+ defer s.mu.Unlock()+ if s.active && s.publication == publication {+ // A failed subscriber write belongs to that connection, not the source.+ _ = s.track.WriteRTP(packet)+ }+}++type voiceOffer struct {+ description VoiceDescription+ version uint64+ incoming map[string]VoicePublication+}++type voiceConnection struct {+ owner *voiceMedia+ key voiceKey+ pc *webrtc.PeerConnection+ // The owner mutex protects plans and the packet-forwarding view.+ plan VoiceConnectionPlan+ version uint64+ emit func(VoiceMediaEvent)+ outgoing map[string]*voiceSendSlot+ remote map[string]VoicePublication+ bindings map[string]*webrtc.TrackRemote+ closed bool+ readers sync.WaitGroup+ // SDP mutations are serialized independently of room signaling and RTP.+ signaling sync.Mutex+ receiveSlots []*voiceReceiveSlot+ sendSlots []*voiceSendSlot+ pending *voiceOffer+ sequence uint64+ negotiatedVersion uint64+ renegotiate bool+ candidates []webrtc.ICECandidateInit+ events chan VoiceMediaEvent+ stop chan struct{}+ closeOnce sync.Once+ closeErr error+ failureOnce sync.Once+}++func newVoiceConnection(owner *voiceMedia, plan VoiceConnectionPlan, emit func(VoiceMediaEvent)) (*voiceConnection, error) {+ engine := &webrtc.MediaEngine{}+ if err := engine.RegisterCodec(webrtc.RTPCodecParameters{RTPCodecCapability: voiceCodec, PayloadType: 111}, webrtc.RTPCodecTypeAudio); err != nil {+ return nil, err+ }+ registry := &interceptor.Registry{}+ if err := webrtc.RegisterDefaultInterceptors(engine, registry); err != nil {+ return nil, err+ }+ pc, err := webrtc.NewAPI(webrtc.WithMediaEngine(engine), webrtc.WithInterceptorRegistry(registry),+ webrtc.WithSettingEngine(owner.settings)).NewPeerConnection(webrtc.Configuration{})+ if err != nil {+ return nil, err+ }+ c := &voiceConnection{owner: owner, key: plan.key(), pc: pc, emit: emit,+ outgoing: make(map[string]*voiceSendSlot), remote: make(map[string]VoicePublication), bindings: make(map[string]*webrtc.TrackRemote),+ events: make(chan VoiceMediaEvent, 128), stop: make(chan struct{})}+ // A silent room still negotiates its admitted transport. The empty receive+ // slot is reused by a later authorized publication; it emits no audio.+ idle, err := pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio,+ webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly})+ if err != nil {+ _ = pc.Close()+ return nil, err+ }+ c.receiveSlots = []*voiceReceiveSlot{{transceiver: idle}}+ pc.OnDataChannel(func(channel *webrtc.DataChannel) { _ = channel.Close() })+ pc.OnICECandidate(func(candidate *webrtc.ICECandidate) {+ if candidate != nil {+ value := candidate.ToJSON()+ c.queue(VoiceMediaEvent{Candidate: &value})+ }+ })+ pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) { c.queue(VoiceMediaEvent{State: state}) })+ pc.OnTrack(c.consume)+ go c.deliver()+ return c, nil+}++// The bounded emitter lets authority call Configure while holding its own lock.+// No supplied callback runs under adapter locks or on Pion's close stack.+func (c *voiceConnection) queue(event VoiceMediaEvent) {+ select {+ case <-c.stop:+ return+ default:+ }+ select {+ case c.events <- event:+ case <-c.stop:+ default:+ c.failureOnce.Do(func() {+ go func() {+ c.dispatch(VoiceMediaEvent{State: webrtc.PeerConnectionStateFailed})+ _ = c.close()+ }()+ })+ }+}++func (c *voiceConnection) dispatch(event VoiceMediaEvent) {+ c.owner.mu.Lock()+ current := !c.closed && c.owner.connections[c.key] == c+ emit := c.emit+ c.owner.mu.Unlock()+ if current {+ event.RoomID, event.PeerID, event.SessionID, event.ConnectionID = c.key.room, c.key.peer, c.key.session, c.key.connection+ emit(event)+ }+}++func (c *voiceConnection) deliver() {+ for {+ select {+ case <-c.stop:+ return+ default:+ }+ select {+ case event := <-c.events:+ c.dispatch(event)+ case <-c.stop:+ return+ }+ }+}++func (c *voiceConnection) snapshotPlan() (VoiceConnectionPlan, uint64, error) {+ c.owner.mu.Lock()+ defer c.owner.mu.Unlock()+ if c.closed || c.owner.connections[c.key] != c {+ return VoiceConnectionPlan{}, 0, errors.New("voice connection is no longer current")+ }+ return c.plan, c.version, nil+}++func (c *voiceConnection) negotiate(force bool) error {+ c.signaling.Lock()+ defer c.signaling.Unlock()+ return c.offer(force)+}++// offer runs only under signaling. Changes arriving while an answer is pending+// update RTP authorization immediately and coalesce into the next offer.+func (c *voiceConnection) offer(force bool) error {+ plan, version, err := c.snapshotPlan()+ if err != nil {+ return err+ }+ c.renegotiate = c.renegotiate || force+ if c.pending != nil || c.sequence != 0 && version == c.negotiatedVersion && !c.renegotiate {+ return nil+ }+ if err = c.syncSlots(plan); err != nil {+ return err+ }+ offer, err := c.pc.CreateOffer(nil)+ if err != nil {+ return err+ }+ if err = c.pc.SetLocalDescription(offer); err != nil {+ return err+ }+ c.sequence+++ description := VoiceDescription{Revision: c.sequence, SDP: *c.pc.LocalDescription(), Tracks: []VoiceTrack{}}+ incoming := make(map[string]VoicePublication)+ for _, slot := range c.receiveSlots {+ if slot.publication.ID != "" {+ mid := slot.transceiver.Mid()+ description.Tracks = append(description.Tracks, VoiceTrack{MID: mid, PublicationID: slot.publication.ID})+ incoming[mid] = slot.publication+ }+ }+ for _, slot := range c.sendSlots {+ if slot.publication.ID != "" {+ description.Tracks = append(description.Tracks, VoiceTrack{MID: slot.transceiver.Mid(), PublicationID: slot.publication.ID})+ }+ }+ c.pending = &voiceOffer{description: description, incoming: incoming, version: version}+ c.renegotiate = false+ c.queue(VoiceMediaEvent{Description: &description})+ return nil+}++func (c *voiceConnection) syncSlots(plan VoiceConnectionPlan) error {+ for _, slot := range c.receiveSlots {+ if !slices.Contains(plan.Publish, slot.publication) {+ slot.publication = VoicePublication{}+ }+ }+ for _, pub := range plan.Publish {+ if slices.ContainsFunc(c.receiveSlots, func(slot *voiceReceiveSlot) bool { return slot.publication == pub }) {+ continue+ }+ index := slices.IndexFunc(c.receiveSlots, func(slot *voiceReceiveSlot) bool { return slot.publication.ID == "" })+ if index < 0 {+ transceiver, err := c.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionRecvonly})+ if err != nil {+ return err+ }+ c.receiveSlots = append(c.receiveSlots, &voiceReceiveSlot{transceiver: transceiver})+ index = len(c.receiveSlots) - 1+ }+ c.receiveSlots[index].publication = pub+ }+ for _, slot := range c.receiveSlots {+ if !slot.rtcp {+ slot.rtcp = true+ if c.startReader() {+ go func(receiver *webrtc.RTPReceiver) {+ defer c.readers.Done()+ for {+ if _, _, err := receiver.ReadRTCP(); err != nil {+ return+ }+ }+ }(slot.transceiver.Receiver())+ }+ }+ }+ for _, slot := range c.sendSlots {+ if slot.publication.ID != "" && !slices.Contains(plan.Subscribe, slot.publication) {+ slot.disable()+ if err := slot.transceiver.Sender().ReplaceTrack(nil); err != nil {+ return err+ }+ slot.mu.Lock()+ slot.publication, slot.track = VoicePublication{}, nil+ slot.mu.Unlock()+ }+ }+ for _, pub := range plan.Subscribe {+ if index := slices.IndexFunc(c.sendSlots, func(slot *voiceSendSlot) bool { return slot.publication == pub }); index >= 0 {+ c.authorizeOutput(c.sendSlots[index], pub)+ continue+ }+ track, err := webrtc.NewTrackLocalStaticRTP(voiceCodec, pub.ID, pub.PeerID)+ if err != nil {+ return err+ }+ index := slices.IndexFunc(c.sendSlots, func(slot *voiceSendSlot) bool { return slot.publication.ID == "" })+ if index < 0 {+ transceiver, err := c.pc.AddTransceiverFromTrack(track, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly})+ if err != nil {+ return err+ }+ c.sendSlots = append(c.sendSlots, &voiceSendSlot{transceiver: transceiver})+ index = len(c.sendSlots) - 1+ c.readRTCP(transceiver.Sender())+ } else if err = c.sendSlots[index].transceiver.Sender().ReplaceTrack(track); err != nil {+ return err+ }+ slot := c.sendSlots[index]+ slot.mu.Lock()+ slot.publication, slot.track = pub, track+ slot.mu.Unlock()+ c.authorizeOutput(slot, pub)+ }+ return nil+}++func (c *voiceConnection) authorizeOutput(slot *voiceSendSlot, pub VoicePublication) {+ c.owner.mu.Lock()+ defer c.owner.mu.Unlock()+ slot.mu.Lock()+ slot.active = !c.closed && slices.Contains(c.plan.Subscribe, pub)+ if slot.active {+ c.outgoing[pub.ID] = slot+ }+ slot.mu.Unlock()+}++func (c *voiceConnection) signal(signal VoiceSignal) error {+ c.signaling.Lock()+ defer c.signaling.Unlock()+ if _, _, err := c.snapshotPlan(); err != nil {+ return err+ }+ count := 0+ if signal.Description != nil {+ count+++ }+ if signal.Candidate != nil {+ count+++ }+ if signal.Renegotiate {+ count+++ }+ if count != 1 {+ return errors.New("one voice signal is required")+ }+ if signal.Renegotiate {+ return c.offer(true)+ }+ if signal.Candidate != nil {+ if c.pc.RemoteDescription() == nil {+ if len(c.candidates) >= 64 {+ return errors.New("too many pending voice candidates")+ }+ c.candidates = append(c.candidates, *signal.Candidate)+ return nil+ }+ return c.pc.AddICECandidate(*signal.Candidate)+ }+ answer := signal.Description+ if c.pending == nil || answer.Revision != c.pending.description.Revision || answer.SDP.Type != webrtc.SDPTypeAnswer ||+ len(answer.Tracks) > maxVoicePublications || len(answer.SDP.SDP) > 128*1024 {+ return errors.New("voice answer is stale or invalid")+ }+ remote := make(map[string]VoicePublication)+ seen := make(map[string]bool)+ for _, track := range answer.Tracks {+ pub, ok := c.pending.incoming[track.MID]+ if !ok || pub.ID != track.PublicationID || remote[track.MID].ID != "" || seen[pub.ID] {+ return errors.New("voice publication is not authorized for this media section")+ }+ remote[track.MID], seen[pub.ID] = pub, true+ }+ if err := c.pc.SetRemoteDescription(answer.SDP); err != nil {+ return err+ }+ c.owner.mu.Lock()+ c.remote = remote+ c.owner.mu.Unlock()+ for _, candidate := range c.candidates {+ if err := c.pc.AddICECandidate(candidate); err != nil {+ return err+ }+ }+ c.candidates = nil+ c.negotiatedVersion = c.pending.version+ c.pending = nil+ return c.offer(false)+}++func (c *voiceConnection) startReader() bool {+ c.owner.mu.Lock()+ defer c.owner.mu.Unlock()+ if c.closed {+ return false+ }+ c.readers.Add(1)+ return true+}++func (c *voiceConnection) readRTCP(sender *webrtc.RTPSender) {+ if !c.startReader() {+ return+ }+ go func() {+ defer c.readers.Done()+ for {+ if _, _, err := sender.ReadRTCP(); err != nil {+ return+ }+ }+ }()+}++func (c *voiceConnection) consume(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {+ if !strings.EqualFold(track.Codec().MimeType, webrtc.MimeTypeOpus) || track.Codec().ClockRate != 48_000 {+ return+ }+ mid := ""+ for _, transceiver := range c.pc.GetTransceivers() {+ if transceiver.Receiver() == receiver {+ mid = transceiver.Mid()+ break+ }+ }+ if mid == "" {+ return+ }+ c.owner.mu.Lock()+ if c.closed || c.bindings[mid] != nil || len(c.bindings) >= maxVoicePublications {+ c.owner.mu.Unlock()+ return+ }+ c.bindings[mid] = track+ c.readers.Add(1)+ c.owner.mu.Unlock()+ defer func() {+ c.owner.mu.Lock()+ delete(c.bindings, mid)+ c.owner.mu.Unlock()+ c.readers.Done()+ }()+ for {+ packet, _, err := forwarding.ReadRTP(track)+ if err != nil {+ return+ }+ c.owner.mu.Lock()+ pub := c.remote[mid]+ var outputs []*voiceSendSlot+ if !c.closed && pub.ID != "" && slices.Contains(c.plan.Publish, pub) {+ for _, other := range c.owner.connections {+ if other != c && !other.closed && other.key.room == c.key.room {+ if out := other.outgoing[pub.ID]; out != nil && slices.Contains(other.plan.Subscribe, pub) {+ outputs = append(outputs, out)+ }+ }+ }+ }+ c.owner.mu.Unlock()+ // Destination transports own their negotiated extensions and RTCP.+ packet.Extension, packet.ExtensionProfile, packet.Extensions = false, 0, nil+ for _, out := range outputs {+ out.write(pub, packet)+ }+ }+}++func (c *voiceConnection) close() error {+ c.closeOnce.Do(func() {+ c.owner.mu.Lock()+ c.closed = true+ for _, out := range c.outgoing {+ out.disable()+ }+ c.owner.mu.Unlock()+ close(c.stop)+ c.closeErr = c.pc.Close()+ c.readers.Wait()+ })+ return c.closeErr+}diff --git a/internal/server/sfu/voice_test.go b/internal/server/sfu/voice_test.gonew file mode 100644index 00000000..d48080bb--- /dev/null+++ b/internal/server/sfu/voice_test.go@@ -0,0 +1,515 @@+package sfu++import (+ "context"+ "errors"+ "fmt"+ "net"+ "slices"+ "sync"+ "sync/atomic"+ "testing"+ "time"++ "github.com/TNTcraftHIM/Piik/internal/media/forwarding"+ "github.com/pion/ice/v4"+ "github.com/pion/interceptor"+ "github.com/pion/rtp"+ "github.com/pion/webrtc/v4"+)++type voiceFixtureSource struct {+ track *webrtc.TrackLocalStaticRTP+ active atomic.Bool+}++type voiceFixturePeer struct {+ mu sync.Mutex+ api *webrtc.API+ pc *webrtc.PeerConnection+ service *Media+ plan VoiceConnectionPlan+ sources map[string]*voiceFixtureSource+ counts map[byte]int+ errors chan error+ held chan VoiceDescription+ hold atomic.Bool+ revision uint64+ ice []webrtc.ICECandidateInit+}++func (p *voiceFixturePeer) report(err error) {+ if err != nil {+ select {+ case p.errors <- err:+ default:+ }+ }+}++func (p *voiceFixturePeer) event(event VoiceMediaEvent) {+ if event.Description != nil {+ if p.hold.Load() {+ p.held <- *event.Description+ } else {+ p.report(p.answer(*event.Description, false))+ }+ } else if event.Candidate != nil {+ p.mu.Lock()+ if p.pc.RemoteDescription() == nil {+ p.ice = append(p.ice, *event.Candidate)+ } else {+ p.report(p.pc.AddICECandidate(*event.Candidate))+ }+ p.mu.Unlock()+ }+}++func (p *voiceFixturePeer) answer(offer VoiceDescription, rejectSpoof bool) error {+ p.mu.Lock()+ defer p.mu.Unlock()+ if err := p.pc.SetRemoteDescription(offer.SDP); err != nil {+ return err+ }+ tracks := []VoiceTrack{}+ for _, item := range offer.Tracks {+ source := p.sources[item.PublicationID]+ if source == nil {+ continue+ }+ for _, transceiver := range p.pc.GetTransceivers() {+ if transceiver.Mid() != item.MID {+ continue+ }+ if sender := transceiver.Sender(); sender != nil {+ if err := sender.ReplaceTrack(source.track); err != nil {+ return err+ }+ } else {+ sender, err := p.api.NewRTPSender(source.track, transceiver.Receiver().Transport())+ if err != nil {+ return err+ }+ if err = transceiver.SetSender(sender, source.track); err != nil {+ return err+ }+ }+ tracks = append(tracks, item)+ }+ }+ answer, err := p.pc.CreateAnswer(nil)+ if err != nil {+ return err+ }+ if err = p.pc.SetLocalDescription(answer); err != nil {+ return err+ }+ description := VoiceDescription{Revision: offer.Revision, SDP: *p.pc.LocalDescription(), Tracks: tracks}+ if rejectSpoof {+ spoof := description+ spoof.Tracks = []VoiceTrack{{MID: offer.Tracks[0].MID, PublicationID: "unapproved_publication"}}+ if err = p.service.SignalVoice(p.plan.RoomID, p.plan.PeerID, p.plan.SessionID, p.plan.ConnectionID, VoiceSignal{Description: &spoof}); err == nil {+ return errors.New("unapproved publication was accepted")+ }+ }+ if err = p.service.SignalVoice(p.plan.RoomID, p.plan.PeerID, p.plan.SessionID, p.plan.ConnectionID, VoiceSignal{Description: &description}); err != nil {+ return err+ }+ for _, candidate := range p.ice {+ if err = p.pc.AddICECandidate(candidate); err != nil {+ return err+ }+ }+ p.ice = nil+ p.revision = offer.Revision+ return nil+}++func (p *voiceFixturePeer) count(marker byte) int {+ p.mu.Lock()+ defer p.mu.Unlock()+ return p.counts[marker]+}++func newVoiceFixturePeer(t *testing.T, ctx context.Context, service *Media, settings webrtc.SettingEngine,+ plan VoiceConnectionPlan, markers map[string]byte) *voiceFixturePeer {+ t.Helper()+ engine := &webrtc.MediaEngine{}+ if err := engine.RegisterCodec(webrtc.RTPCodecParameters{RTPCodecCapability: voiceCodec, PayloadType: 111}, webrtc.RTPCodecTypeAudio); err != nil {+ t.Fatal(err)+ }+ registry := &interceptor.Registry{}+ if err := webrtc.RegisterDefaultInterceptors(engine, registry); err != nil {+ t.Fatal(err)+ }+ api := webrtc.NewAPI(webrtc.WithMediaEngine(engine), webrtc.WithInterceptorRegistry(registry), webrtc.WithSettingEngine(settings))+ pc, err := api.NewPeerConnection(webrtc.Configuration{})+ if err != nil {+ t.Fatal(err)+ }+ p := &voiceFixturePeer{api: api, pc: pc, service: service, plan: plan,+ sources: make(map[string]*voiceFixtureSource), counts: make(map[byte]int), errors: make(chan error, 8), held: make(chan VoiceDescription, 8)}+ pc.OnICECandidate(func(candidate *webrtc.ICECandidate) {+ if candidate != nil {+ value := candidate.ToJSON()+ p.report(service.SignalVoice(plan.RoomID, plan.PeerID, plan.SessionID, plan.ConnectionID, VoiceSignal{Candidate: &value}))+ }+ })+ pc.OnTrack(func(track *webrtc.TrackRemote, _ *webrtc.RTPReceiver) {+ for {+ packet, _, err := track.ReadRTP()+ if err != nil {+ return+ }+ if len(packet.Payload) > 0 {+ p.mu.Lock()+ p.counts[packet.Payload[0]]+++ p.mu.Unlock()+ }+ }+ })+ for id, marker := range markers {+ track, err := webrtc.NewTrackLocalStaticRTP(voiceCodec, id, plan.PeerID)+ if err != nil {+ t.Fatal(err)+ }+ source := &voiceFixtureSource{track: track}+ source.active.Store(true)+ p.sources[id] = source+ go func() {+ ticker := time.NewTicker(10 * time.Millisecond)+ defer ticker.Stop()+ var sequence uint16+ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ if source.active.Load() {+ sequence+++ _ = track.WriteRTP(&rtp.Packet{Header: rtp.Header{Version: 2, SequenceNumber: sequence, Timestamp: uint32(sequence) * 480}, Payload: []byte{marker, 0, 0}})+ }+ }+ }+ }()+ }+ t.Cleanup(func() { _ = pc.Close() })+ return p+}++func TestVoiceJunctionDuplexAuthorizationAndExactRetirement(t *testing.T) {+ ctx, cancel := context.WithTimeout(t.Context(), 12*time.Second)+ defer cancel()+ settings := webrtc.SettingEngine{}+ settings.SetNetworkTypes([]webrtc.NetworkType{webrtc.NetworkTypeUDP4})+ settings.SetIncludeLoopbackCandidate(true)+ settings.SetIPFilter(func(ip net.IP) bool { return ip.IsLoopback() })+ socket, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)})+ if err != nil {+ t.Fatal(err)+ }+ mux := forwarding.NewUDPMux(ice.UDPMuxParams{UDPConn: socket})+ defer mux.Close()+ serverSettings := settings+ serverSettings.SetICEUDPMux(mux)+ service := NewMedia(MediaOptions{Settings: serverSettings})+ defer service.Close()+ a1, a2, b1 := VoicePublication{"voice_a1", "speaker_a"}, VoicePublication{"voice_a2", "speaker_c"}, VoicePublication{"voice_b1", "speaker_b"}+ aPlan := VoiceConnectionPlan{RoomID: "1234", PeerID: "relay_a", SessionID: "session_a", ConnectionID: "connection_a", Publish: []VoicePublication{a1, a2}, Subscribe: []VoicePublication{b1}}+ bPlan := VoiceConnectionPlan{RoomID: "1234", PeerID: "relay_b", SessionID: "session_b", ConnectionID: "connection_b", Publish: []VoicePublication{b1}, Subscribe: []VoicePublication{a1, a2}}+ a := newVoiceFixturePeer(t, ctx, service, settings, aPlan, map[string]byte{a1.ID: 0xa1, a2.ID: 0xa2})+ b := newVoiceFixturePeer(t, ctx, service, settings, bPlan, map[string]byte{b1.ID: 0xb1})+ wait := func(condition func() bool) {+ t.Helper()+ ticker := time.NewTicker(5 * time.Millisecond)+ defer ticker.Stop()+ for !condition() {+ select {+ case err := <-a.errors:+ t.Fatal(err)+ case err := <-b.errors:+ t.Fatal(err)+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ case <-ticker.C:+ }+ }+ }+ // Pause the first answer to prove a forged publication cannot consume it.+ a.hold.Store(true)+ if err = service.ConfigureVoice(aPlan, a.event); err != nil {+ t.Fatal(err)+ }+ var first VoiceDescription+ select {+ case first = <-a.held:+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ }+ a.hold.Store(false)+ if err = a.answer(first, true); err != nil {+ t.Fatal(err)+ }+ if err = service.ConfigureVoice(bPlan, b.event); err != nil {+ t.Fatal(err)+ }+ wait(func() bool { return a.count(0xb1) >= 3 && b.count(0xa1) >= 3 && b.count(0xa2) >= 3 })+ if a.count(0xa1) != 0 || b.count(0xb1) != 0 {+ t.Fatal("voice was echoed to its incoming connection")+ }++ // A late close from a previous session cannot touch the current physical PC.+ if err = service.CloseVoice(aPlan.RoomID, aPlan.PeerID, "old_session", aPlan.ConnectionID); err != nil {+ t.Fatal(err)+ }+ before := b.count(0xa1)+ wait(func() bool { return b.count(0xa1) >= before+3 })+ if err = service.SignalVoice(aPlan.RoomID, aPlan.PeerID, aPlan.SessionID, aPlan.ConnectionID,+ VoiceSignal{Description: &VoiceDescription{Revision: first.Revision, SDP: webrtc.SessionDescription{Type: webrtc.SDPTypeAnswer}}}); err == nil {+ t.Fatal("old answer was accepted after its negotiation ended")+ }++ // Removing one publication takes effect even while its new answer is withheld.+ a.hold.Store(true)+ revoked := aPlan+ revoked.Publish = []VoicePublication{a2}+ if err = service.ConfigureVoice(revoked, a.event); err != nil {+ t.Fatal(err)+ }+ var pending VoiceDescription+ select {+ case pending = <-a.held:+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ }+ // A marker from the surviving source proves the same sender PC keeps flowing.+ beforeA2, beforeB := b.count(0xa2), a.count(0xb1)+ wait(func() bool { return b.count(0xa2) >= beforeA2+3 && a.count(0xb1) >= beforeB+3 })+ stopped := b.count(0xa1)+ beforeA2 = b.count(0xa2)+ wait(func() bool { return b.count(0xa2) >= beforeA2+5 })+ if b.count(0xa1) != stopped {+ t.Fatal("revoked voice continued before SDP acknowledgement")+ }+ a.hold.Store(false)+ if err = a.answer(pending, false); err != nil {+ t.Fatal(err)+ }++ // Reusing a grant must reuse its empty media section, not grow SDP forever.+ for range 2 {+ if err = service.ConfigureVoice(aPlan, a.event); err != nil {+ t.Fatal(err)+ }+ before = b.count(0xa1)+ wait(func() bool { return b.count(0xa1) >= before+3 })+ if err = service.ConfigureVoice(revoked, a.event); err != nil {+ t.Fatal(err)+ }+ wait(func() bool {+ a.mu.Lock()+ defer a.mu.Unlock()+ return a.revision >= pending.Revision+2+ })+ }+ service.voice.mu.Lock()+ connection := service.voice.connections[aPlan.key()]+ service.voice.mu.Unlock()+ if len(connection.pc.GetTransceivers()) != 3 {+ t.Fatal("repeated voice grants accumulated media sections")+ }++ // Revoke and regrant a subscription while another answer is pending. The+ // immediate packet gate must reopen when the retained desired set is applied.+ b.hold.Store(true)+ if err = service.SignalVoice(bPlan.RoomID, bPlan.PeerID, bPlan.SessionID, bPlan.ConnectionID, VoiceSignal{Renegotiate: true}); err != nil {+ t.Fatal(err)+ }+ var held VoiceDescription+ select {+ case held = <-b.held:+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ }+ withoutA2 := bPlan+ withoutA2.Subscribe = []VoicePublication{a1}+ if err = service.ConfigureVoice(withoutA2, b.event); err != nil {+ t.Fatal(err)+ }+ beforeB = a.count(0xb1)+ wait(func() bool { return a.count(0xb1) >= beforeB+3 })+ stopped = b.count(0xa2)+ beforeB = a.count(0xb1)+ wait(func() bool { return a.count(0xb1) >= beforeB+3 })+ if b.count(0xa2) != stopped {+ t.Fatal("revoked subscription kept receiving before SDP acknowledgement")+ }+ if err = service.ConfigureVoice(bPlan, b.event); err != nil {+ t.Fatal(err)+ }+ b.hold.Store(false)+ if err = b.answer(held, false); err != nil {+ t.Fatal(err)+ }+ wait(func() bool { return b.count(0xa2) >= stopped+3 })++ // Capture ending does not retire its relay connection or the other source.+ a.sources[a2.ID].active.Store(false)+ beforeB = a.count(0xb1)+ wait(func() bool { return a.count(0xb1) >= beforeB+3 })+ if err = service.CloseVoice(aPlan.RoomID, aPlan.PeerID, aPlan.SessionID, aPlan.ConnectionID); err != nil {+ t.Fatal(err)+ }+ if err = service.SignalVoice(aPlan.RoomID, aPlan.PeerID, aPlan.SessionID, aPlan.ConnectionID, VoiceSignal{Renegotiate: true}); err == nil {+ t.Fatal("closed connection accepted signaling")+ }+ service.voice.mu.Lock()+ remaining := len(service.voice.connections)+ service.voice.mu.Unlock()+ if remaining != 1 || b.pc.ConnectionState() == webrtc.PeerConnectionStateClosed {+ t.Fatal("exact close retired a sibling")+ }+}++func TestVoiceFullRoomAdmitsBothPublicationReplacementFacets(t *testing.T) {+ service := NewMedia(MediaOptions{})+ t.Cleanup(func() {+ if err := service.Close(); err != nil {+ t.Error(err)+ }+ })+ configure := func(peer, connection string) error {+ return service.ConfigureVoice(VoiceConnectionPlan{+ RoomID: "1234", PeerID: peer, SessionID: "session_" + peer, ConnectionID: connection,+ }, func(VoiceMediaEvent) {})+ }+ if err := configure("host", "committed_host"); err != nil {+ t.Fatal(err)+ }+ for i := range maxVoicePublications - 1 {+ if err := configure(fmt.Sprintf("viewer_%d", i), fmt.Sprintf("committed_%d", i)); err != nil {+ t.Fatal(err)+ }+ }+ // Publication replacement retains the full committed graph while the one+ // route operation connects both a new Host junction and its first child.+ if err := configure("host", "replacement_host"); err != nil {+ t.Fatalf("replacement Host facet was rejected: %v", err)+ }+ if err := configure("viewer_0", "replacement_child"); err != nil {+ t.Fatalf("replacement child facet was rejected: %v", err)+ }+ if err := configure("viewer_1", "excess_transition"); err == nil {+ t.Fatal("room admitted a connection beyond the publication replacement allowance")+ }+}++func TestVoicePlanBoundsAndMediaShutdown(t *testing.T) {+ service := NewMedia(MediaOptions{})+ plan := VoiceConnectionPlan{RoomID: "1234", PeerID: "peer", SessionID: "session", ConnectionID: "connection"}+ for i := range maxVoicePublications + 1 {+ plan.Publish = append(plan.Publish, VoicePublication{ID: fmt.Sprint("voice_", i), PeerID: "speaker"})+ }+ if err := service.ConfigureVoice(plan, func(VoiceMediaEvent) {}); err == nil {+ t.Fatal("oversized plan allocated a connection")+ }+ plan.Publish = slices.Clone(plan.Publish[:1])+ plan.Subscribe = slices.Clone(plan.Publish)+ if err := service.ConfigureVoice(plan, func(VoiceMediaEvent) {}); err == nil {+ t.Fatal("looping publication was admitted in both directions")+ }+ plan.Publish, plan.Subscribe = nil, nil+ closed := make(chan error, 1)+ if err := service.ConfigureVoice(plan, func(event VoiceMediaEvent) {+ if event.Description != nil {+ closed <- service.CloseVoice(plan.RoomID, plan.PeerID, plan.SessionID, plan.ConnectionID)+ }+ }); err != nil {+ t.Fatal(err)+ }+ select {+ case err := <-closed:+ if err != nil {+ t.Fatal(err)+ }+ case <-time.After(3 * time.Second):+ t.Fatal("voice callback could not retire its own connection")+ }+ plan.ConnectionID = "shutdown_connection"+ if err := service.ConfigureVoice(plan, func(VoiceMediaEvent) {}); err != nil {+ t.Fatal(err)+ }+ if err := service.Close(); err != nil {+ t.Fatal(err)+ }+ if err := service.ConfigureVoice(plan, func(VoiceMediaEvent) {}); err == nil {+ t.Fatal("closed media admitted voice")+ }+ service.voice.mu.Lock()+ defer service.voice.mu.Unlock()+ if len(service.voice.connections) != 0 {+ t.Fatal("media shutdown retained voice connections")+ }+}++func TestVoiceSilentTransportAcceptsLatePublicationOnSameConnection(t *testing.T) {+ ctx, cancel := context.WithTimeout(t.Context(), 8*time.Second)+ defer cancel()+ settings := webrtc.SettingEngine{}+ settings.SetNetworkTypes([]webrtc.NetworkType{webrtc.NetworkTypeUDP4})+ settings.SetIncludeLoopbackCandidate(true)+ settings.SetIPFilter(func(ip net.IP) bool { return ip.IsLoopback() })+ service := NewMedia(MediaOptions{Settings: settings})+ defer service.Close()+ pub := VoicePublication{ID: "late_voice", PeerID: "speaker"}+ aPlan := VoiceConnectionPlan{RoomID: "1234", PeerID: "a", SessionID: "session_a", ConnectionID: "connection_a"}+ bPlan := VoiceConnectionPlan{RoomID: "1234", PeerID: "b", SessionID: "session_b", ConnectionID: "connection_b"}+ a := newVoiceFixturePeer(t, ctx, service, settings, aPlan, map[string]byte{pub.ID: 0x71})+ b := newVoiceFixturePeer(t, ctx, service, settings, bPlan, nil)+ for _, peer := range []*voiceFixturePeer{a, b} {+ if err := service.ConfigureVoice(peer.plan, peer.event); err != nil {+ t.Fatal(err)+ }+ }+ wait := func(condition func() bool) {+ t.Helper()+ for !condition() {+ select {+ case err := <-a.errors:+ t.Fatal(err)+ case err := <-b.errors:+ t.Fatal(err)+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ case <-time.After(5 * time.Millisecond):+ }+ }+ }+ wait(func() bool {+ return a.pc.ConnectionState() == webrtc.PeerConnectionStateConnected && b.pc.ConnectionState() == webrtc.PeerConnectionStateConnected+ })+ if a.count(0x71) != 0 || b.count(0x71) != 0 {+ t.Fatal("silent transport sent unauthorized audio")+ }+ service.voice.mu.Lock()+ aConnection := service.voice.connections[aPlan.key()]+ bConnection := service.voice.connections[bPlan.key()]+ service.voice.mu.Unlock()+ if len(aConnection.pc.GetTransceivers()) != 1 || len(bConnection.pc.GetTransceivers()) != 1 {+ t.Fatal("silent transport did not reserve exactly one audio slot")+ }+ aPlan.Publish, bPlan.Subscribe = []VoicePublication{pub}, []VoicePublication{pub}+ if err := service.ConfigureVoice(aPlan, a.event); err != nil {+ t.Fatal(err)+ }+ if err := service.ConfigureVoice(bPlan, b.event); err != nil {+ t.Fatal(err)+ }+ wait(func() bool { return b.count(0x71) >= 3 })+ service.voice.mu.Lock()+ retained := service.voice.connections[aPlan.key()] == aConnection && service.voice.connections[bPlan.key()] == bConnection+ service.voice.mu.Unlock()+ if !retained || len(aConnection.pc.GetTransceivers()) != 1 {+ t.Fatal("late microphone replaced the admitted connection or missed its idle slot")+ }+}diff --git a/internal/server/signal/presence.go b/internal/server/signal/presence.goindex 229f0ab5..0fa7a7b8 100644--- a/internal/server/signal/presence.go+++ b/internal/server/signal/presence.go@@ -148,6 +148,7 @@ func (s *Server) handleDisconnect(sess *session) {return}s.router.disconnectParticipant(disconnected.RoomID, disconnected.PeerID, sess.sessionID)+ s.disconnectRoomVoice(disconnected.RoomID, disconnected.PeerID, sess.sessionID)s.sendRemoteInputPeers(disconnected.RoomID)if disconnected.Role == protocol.RoleHost {s.broadcastHostStatus(disconnected.RoomID, false, false)@@ -170,6 +171,10 @@ func (s *Server) handleDisconnect(sess *session) {}delete(s.viewerGraceTimers, key)if s.store.RemoveDisconnectedViewer(roomID, peerID) {+ if voice := s.voices[roomID]; voice != nil {+ delete(voice.members, peerID)+ s.syncRoomVoice(roomID)+ }s.clearViewerEvidence(roomID, peerID)s.router.removeViewer(roomID, peerID)}@@ -181,6 +186,12 @@ func (s *Server) handleDisconnect(sess *session) {// The share generation deliberately survives.func (s *Server) stopSharing(roomID string) {if current, ok := s.shares[roomID]; ok {+ if host, connected := s.store.GetConnectedHost(roomID); connected {+ if sess := s.sessionsByID[host.SessionID]; sess != nil && sess.authenticated != nil &&+ sess.authenticated.shareGeneration == current.generation {+ sess.authenticated.shareGeneration = ""+ }+ }s.shares[roomID] = roomShare{generation: current.generation}}s.broadcastAudioPresence(roomID)@@ -212,6 +223,7 @@ func (s *Server) abandonRoom(roomID string) error {// closeRoom closes the host session first, then// viewers in store order, each told room-closed then closed with 1000.func (s *Server) closeRoom(closed room.ClosedRoom) {+ s.closeRoomVoice(closed.RoomID)s.clearRoomGraceTimers(closed.RoomID)s.clearRoomViewerEvidence(closed.RoomID)s.router.deleteRoom(closed.RoomID)@@ -254,11 +266,15 @@ func (s *Server) revokeGrantViewers(roomID string, update room.ViewerGrantUpdate}for _, viewer := range update.RevokedViewers {- if viewer.SessionID == "" {- continue+ if viewer.SessionID != "" {+ s.closeRevokedViewerSession(viewer.SessionID)+ }+ if voice := s.voices[roomID]; voice != nil {+ delete(voice.members, viewer.PeerID)}- s.closeRevokedViewerSession(viewer.SessionID)}+ s.syncVoiceDemand(roomID)+ s.syncRoomVoice(roomID)}()s.sendViewerPresence(roomID)}diff --git a/internal/server/signal/relay_volunteer.go b/internal/server/signal/relay_volunteer.gonew file mode 100644index 00000000..bfa5882b--- /dev/null+++ b/internal/server/signal/relay_volunteer.go@@ -0,0 +1,24 @@+package signal++import "github.com/TNTcraftHIM/Piik/internal/server/protocol"++func (s *Server) setRelayVolunteer(sess *session, auth *authenticatedSession, message protocol.SetRelayVolunteerMessage) {+ if auth.role != protocol.RoleViewer {+ s.sendError(sess, "FORBIDDEN", "Only viewers may volunteer relay capacity")+ return+ }+ rm := s.router.room(auth.roomID)+ settings, _ := rm.viewerSettings.Get(auth.peerID)+ settings.capacity, settings.volunteer, settings.sessionID = int(message.Capacity), message.Enabled, sess.sessionID+ rm.viewerSettings.Set(auth.peerID, settings)+ capacity := min(settings.capacity, s.endpointMediaCopyCapacity)+ if settings.volunteer {+ capacity = settings.capacity+ }+ if rm.controller != nil {+ rm.controller.SetRelayVolunteer(auth.peerID, sess.sessionID, settings.volunteer, s.router.nowPtr())+ rm.controller.SetEffectiveCapacity(auth.peerID, sess.sessionID, settings.capacity, s.router.nowPtr())+ s.router.requestPump(auth.roomID)+ }+ s.send(sess, protocol.RelayVolunteerMessage{Type: "relay-volunteer", Enabled: settings.volunteer, Capacity: protocol.Int(capacity)})+}diff --git a/internal/server/signal/router.go b/internal/server/signal/router.goindex df112db6..6698a405 100644--- a/internal/server/signal/router.go+++ b/internal/server/signal/router.go@@ -63,9 +63,14 @@ type sfuFallback struct {// Every hook is called with mu held and must not block. shareGeneration// returns "" when no share exists; routesChanged may be nil.type routerHooks struct {- sendToSession func(sessionID string, message protocol.ServerMessage)- shareGeneration func(roomID string) string- routesChanged func(roomID string)+ sendToSession func(sessionID string, message protocol.ServerMessage)+ shareGeneration func(roomID string) string+ routesChanged func(roomID string)+ voiceAllowed func(roomID, peerID string) bool+ videoGeneration func(roomID string) string+ voiceDemandChanged func(roomID string)+ voiceCandidateReady func(roomID, connectionID string) bool+ voiceRouteFailed func(roomID, peerID string)}// routerOptions supplies the shared mutex and timer factory.@@ -145,8 +150,11 @@ type peerSignalDebugInput struct {// deadlineGeneration is bumped by every clearDeadline so// a callback that lost the Stop race sees it is stale.type roomRuntime struct {- hostPeerID string- controller *route.Controller+ hostPeerID string+ controller *route.Controller+ roomMedia bool+ mediaGeneration string+ pendingMedia *preparedCandidate// Viewer choices survive signaling recovery and share replacement, not leave.viewerSettings ordered.Map[string, viewerRouteSettings]requested bool@@ -156,7 +164,9 @@ type roomRuntime struct {}type viewerRouteSettings struct {- capacity int+ capacity int+ sessionID string+ volunteer bool// Empty means the page has not opted into route selection.preference protocol.ViewerRoutePreference}@@ -277,7 +287,9 @@ func (r *router) connectParticipant(input authenticatedRouteParticipant) hybridA}} else {settings, _ := rm.viewerSettings.Get(input.peerID)- settings.preference = ""+ if settings.sessionID != input.sessionID {+ settings.sessionID, settings.preference, settings.volunteer = input.sessionID, "", false+ }if input.routePreference != nil {settings.preference = *input.routePreferenceif !r.viewerRouteAllowed(input.roomID, settings.preference) {@@ -287,6 +299,10 @@ func (r *router) connectParticipant(input authenticatedRouteParticipant) hybridArm.viewerSettings.Set(input.peerID, settings)}if rm.controller != nil {+ if rm.roomMedia && input.role == protocol.RoleViewer && r.videoGeneration(input.roomID) == "" &&+ (r.hooks.voiceAllowed == nil || !r.hooks.voiceAllowed(input.roomID, input.peerID)) {+ return hybridAuthenticationState{routeAssignment: emptyAssignment()}+ }capacity := r.capacityvar preference protocol.ViewerRoutePreferenceif input.role != protocol.RoleHost {@@ -300,6 +316,10 @@ func (r *router) connectParticipant(input authenticatedRouteParticipant) hybridAEffectiveDownstreamCapacity: capacity,RoutePreference: preference,}, r.nowPtr()))+ if input.role == protocol.RoleViewer {+ settings, _ := rm.viewerSettings.Get(input.peerID)+ rm.controller.SetRelayVolunteer(input.peerID, input.sessionID, settings.volunteer, r.nowPtr())+ }}state := hybridAuthenticationState{routeAssignment: emptyAssignment()}if rm.controller != nil {@@ -330,7 +350,7 @@ func (r *router) setPaused(roomID string, paused bool) {if rm.controller.Revision() != before {r.broadcastActive(roomID, rm)}- if !paused {+ if !paused || rm.roomMedia {r.requestPump(roomID)}}@@ -561,7 +581,7 @@ func (r *router) resolveActiveViewerMediaEdge(roomID, childPeerID string) (activ}return activeViewerMediaEdge{revision: snapshot.Revision,- connectionID: edge.ConnectionID,+ connectionID: videoConnectionID(snapshot, edge),upstream: upstream,}, true}@@ -650,11 +670,15 @@ func (r *router) peerSignalAuthorization(input peerSignalInput) signalAuthorizatif !sessionsMatch {return signalAuthorizationDenied}+ activeConnectionID := videoConnectionID(snapshot, edge)+ if rm.roomMedia && (!edge.VideoReady || edge.VideoGeneration != snapshot.VideoGeneration || snapshot.VideoGeneration == "") {+ return signalAuthorizationDenied+ }if edge.Transport == route.TransportDirect &&parentToChild &&input.signalKind == "description" &&input.descriptionType == "offer" &&- input.connectionID != edge.ConnectionID {+ input.connectionID != activeConnectionID {if strings.HasPrefix(input.connectionID, candidateConnectionIDPrefix) {return signalAuthorizationDenied}@@ -678,7 +702,7 @@ func (r *router) peerSignalAuthorization(input peerSignalInput) signalAuthorizat}return signalAuthorizationDenied}- if input.connectionID == edge.ConnectionID {+ if input.connectionID == activeConnectionID {return signalAuthorizationAllowed}return signalAuthorizationDenied@@ -790,13 +814,20 @@ func (r *router) handleRouteReady(participant authenticatedRouteParticipant, mesreturn}current := operation.Current+ if rm.roomMedia && rm.pendingMedia != nil && rm.pendingMedia.connectionID == current.ConnectionID {+ ready := message+ rm.pendingMedia.videoReady = &ready+ if r.hooks.voiceCandidateReady != nil && !r.hooks.voiceCandidateReady(participant.roomID, current.ConnectionID) {+ return+ }+ }before := controller.Revision()settled := controller.CandidateReady(route.CandidateGuard{ChildPeerID: participant.peerID,ChildSessionID: participant.sessionID,Revision: revision,ConnectionID: current.ConnectionID,- }, r.now(), r.commitReservation, route.CandidateProof{RelativeQualityApproved: message.QualityApproved})+ }, r.now(), r.commitReservation, route.CandidateProof{RelativeQualityApproved: message.QualityApproved, VideoGeneration: operation.VideoGeneration})r.debug(participant.roomID, "route-ready-settled","participant", r.debugPeer(participant.roomID, participant.peerID),"revision", revision,@@ -949,16 +980,28 @@ func (r *router) handleRouteFailed(participant authenticatedRouteParticipant, meif revision > snapshot.Revision || (revision != snapshot.Revision && connectionID == "") {return}- if participant.role == protocol.RoleHost {- if connectionID != "" && controller.InvalidateDirectEdgeFromParent(route.ParentEdgeGuard{+ if connectionID != "" {+ logicalConnectionID := connectionID+ if snapshot.RoomMedia {+ logicalConnectionID = ""+ }+ for _, edge := range snapshot.UpstreamByViewer.Values() {+ if edge.Kind == route.UpstreamPeer && edge.ParentPeerID == participant.peerID && videoConnectionID(snapshot, edge) == connectionID {+ logicalConnectionID = edge.ConnectionID+ break+ }+ }+ if logicalConnectionID != "" && controller.InvalidateDirectEdgeFromParent(route.ParentEdgeGuard{ParentPeerID: participant.peerID,ParentSessionID: participant.sessionID,RouteRevision: snapshot.Revision,- ConnectionID: connectionID,+ ConnectionID: logicalConnectionID,}, r.nowPtr()) {r.requestPump(participant.roomID)return}+ }+ if participant.role == protocol.RoleHost {publication := snapshot.HostPublicationif publication == nil || publication.HostSessionID != participant.sessionID ||(connectionID != "" && connectionID != publication.ConnectionID) {@@ -970,12 +1013,14 @@ func (r *router) handleRouteFailed(participant authenticatedRouteParticipant, meGeneration: publication.Generation,ConnectionID: publication.ConnectionID,}, r.nowPtr())- r.releaseResources(controller.RetireHostPublication(route.PublicationGuard{- HostSessionID: participant.sessionID,- RouteRevision: controller.Revision(),- Generation: publication.Generation,- ConnectionID: publication.ConnectionID,- }))+ if !snapshot.RoomMedia {+ r.releaseResources(controller.RetireHostPublication(route.PublicationGuard{+ HostSessionID: participant.sessionID,+ RouteRevision: controller.Revision(),+ Generation: publication.Generation,+ ConnectionID: publication.ConnectionID,+ }))+ }r.broadcastActive(participant.roomID, rm)r.requestPump(participant.roomID)return@@ -983,7 +1028,7 @@ func (r *router) handleRouteFailed(participant authenticatedRouteParticipant, meedge, hasEdge := snapshot.UpstreamByViewer.Get(participant.peerID)if !hasEdge || edge.ChildSessionID != participant.sessionID ||- (connectionID != "" && connectionID != edge.ConnectionID) {+ (connectionID != "" && connectionID != videoConnectionID(snapshot, edge)) {return}guard := route.EdgeGuard{@@ -1031,6 +1076,10 @@ func (r *router) removeViewer(roomID, peerID string) {// stopRoom preserves Viewer settings across shares.func (r *router) stopRoom(roomID string) {+ if rm, _ := r.rooms.Get(roomID); rm != nil && rm.roomMedia && rm.controller != nil {+ r.setVideoPublication(roomID, "", false)+ return+ }var settings ordered.Map[string, viewerRouteSettings]if rm, _ := r.rooms.Get(roomID); rm != nil {settings = rm.viewerSettings@@ -1072,6 +1121,9 @@ func (r *router) createController(roomID string, rm *roomRuntime, host authenticQualityConvergenceEnabled: routePolicy != nil && routePolicy.TopologyOptimization,NatPredictionEnabled: routePolicy != nil && routePolicy.NatPrediction,})+ if rm.roomMedia {+ rm.controller.SetVideoPublication(r.videoGeneration(roomID), false, r.now())+ }rm.controller.UpsertParticipant(route.ParticipantInput{PeerID: host.peerID,Role: protocol.RoleHost,@@ -1079,6 +1131,10 @@ func (r *router) createController(roomID string, rm *roomRuntime, host authenticEffectiveDownstreamCapacity: r.capacity,}, r.nowPtr())for _, viewer := range r.store.GetConnectedViewers(roomID) {+ if rm.roomMedia && r.videoGeneration(roomID) == "" &&+ (r.hooks.voiceAllowed == nil || !r.hooks.voiceAllowed(roomID, viewer.PeerID)) {+ continue+ }settings, _ := rm.viewerSettings.Get(viewer.PeerID)if settings.preference != "" && !r.viewerRouteAllowed(roomID, settings.preference) {settings.preference = protocol.ViewerRouteAuto@@ -1092,6 +1148,7 @@ func (r *router) createController(roomID string, rm *roomRuntime, host authenticEffectiveDownstreamCapacity: settings.capacity,RoutePreference: settings.preference,}, r.nowPtr())+ rm.controller.SetRelayVolunteer(viewer.PeerID, viewer.SessionID, settings.volunteer, r.nowPtr())}}@@ -1154,6 +1211,9 @@ func (r *router) assignments(if !edge.PhysicalActive {continue}+ if snapshot.RoomMedia && (!edge.VideoReady || edge.VideoGeneration != snapshot.VideoGeneration || snapshot.VideoGeneration == "") {+ continue+ }if edge.Kind == route.UpstreamPeer {edges.Set(childPeerID, assignmentEdge{kind: route.UpstreamPeer, parentPeerID: edge.ParentPeerID})} else {@@ -1252,6 +1312,12 @@ func (r *router) assignments(// broadcastActive sends to the host first, then viewers in store order,// with one routesChanged call at the end.func (r *router) broadcastActive(roomID string, rm *roomRuntime) {+ if rm.roomMedia && r.videoGeneration(roomID) == "" {+ if r.hooks.routesChanged != nil {+ r.hooks.routesChanged(roomID)+ }+ return+ }if rm.controller == nil {return}@@ -1313,6 +1379,9 @@ func (r *router) pathIsPhysical(roomID string, snapshot route.RouteSnapshot, chiif !ok || !edge.PhysicalActive || !edge.Usable {return false}+ if snapshot.RoomMedia && (!edge.VideoReady || edge.VideoGeneration != snapshot.VideoGeneration || snapshot.VideoGeneration == "") {+ return false+ }if edge.Kind == route.UpstreamSfu {return snapshot.HostPublication != nil &&snapshot.HostPublication.PhysicalActive &&@@ -1513,6 +1582,15 @@ func (r *router) sendRoomError(roomID, code, message string) {}func (r *router) sendViewerRouteStatus(roomID, viewerPeerID string, message protocol.RouteStatusMessage) {+ if rm, _ := r.rooms.Get(roomID); rm != nil && rm.roomMedia && rm.controller != nil {+ snapshot := rm.controller.Snapshot()+ if snapshot.VideoGeneration == "" || snapshot.VideoPaused {+ if message.State == "failed" && r.hooks.voiceRouteFailed != nil {+ r.hooks.voiceRouteFailed(roomID, viewerPeerID)+ }+ return+ }+ }if viewer, ok := r.store.GetConnectedViewer(roomID, viewerPeerID); ok {r.hooks.sendToSession(viewer.SessionID, message)}diff --git a/internal/server/signal/router_failure_test.go b/internal/server/signal/router_failure_test.goindex 000ce570..b1b21d97 100644--- a/internal/server/signal/router_failure_test.go+++ b/internal/server/signal/router_failure_test.go@@ -5,9 +5,60 @@ import ("github.com/TNTcraftHIM/Piik/internal/server/protocol""github.com/TNTcraftHIM/Piik/internal/server/room"+ "github.com/TNTcraftHIM/Piik/internal/server/route""github.com/TNTcraftHIM/Piik/internal/server/sfu")+func TestRoomVideoFailuresCannotInvalidateAnotherPhysicalFacet(t *testing.T) {+ h := newRouterHarness(t, routerHarnessOptions{capacity: 2})+ created := h.createRoom()+ host := h.connectHost(created, nil, "", "")+ viewer := h.connectViewer(created, "room-video-replacement")+ h.locked(func() {+ h.doComplete(host)+ h.doComplete(viewer)+ })+ prepared := h.waitPrepared(viewer.sessionID)+ h.locked(func() {+ h.doReady(viewer, int64(prepared.Revision))+ rm, _ := h.router.rooms.Get(created.RoomID)+ controller := rm.controller+ old, _ := controller.Snapshot().UpstreamByViewer.Get(viewer.peerID)+ rm.roomMedia = true+ controller.SetVideoPublication(testShareGeneration, false, h.router.now())+ controller.SetVideoPublication("", false, h.router.now())+ controller.SetVideoPublication("room_video_replacement_123", false, h.router.now())+ op := controller.Reconcile(h.router.now()).Operation+ if op == nil || op.Reason != route.DemandPublicationAttach {+ t.Fatal("replacement did not prepare a video attachment")+ }+ begun := controller.BeginCurrentCandidate(route.BeginInput{Guard: cursorGuard(op, op.Candidates[op.Cursor]),+ NowMs: h.router.now(), ConnectionID: "replacement_video_connection_123"})+ if !begun.Accepted {+ t.Fatal("replacement attachment did not begin")+ }+ op = begun.Operation+ guard := route.CandidateGuard{ChildPeerID: viewer.peerID, ChildSessionID: viewer.sessionID,+ Revision: op.Current.Revision, ConnectionID: op.Current.ConnectionID}+ if !controller.CandidateReady(guard, h.router.now(), nil,+ route.CandidateProof{VideoGeneration: "room_video_replacement_123"}).Committed {+ t.Fatal("replacement attachment did not commit")+ }+ for _, participant := range []authenticatedRouteParticipant{host, viewer} {+ h.doFailed(participant, routeFailedMessage(int64(prepared.Revision), "active", old.ConnectionID))+ edge, ok := controller.Snapshot().UpstreamByViewer.Get(viewer.peerID)+ if !ok || !edge.Usable || !edge.VideoReady || edge.VideoConnectionID != guard.ConnectionID {+ t.Fatal("a retired video failure affected its replacement or room voice")+ }+ }+ h.doFailed(host, routeFailedMessage(controller.Revision(), "active", guard.ConnectionID))+ edge, _ := controller.Snapshot().UpstreamByViewer.Get(viewer.peerID)+ if edge.Usable {+ t.Fatal("the current parent video failure did not trigger normal route repair")+ }+ })+}+func TestRouterPreparesSfuForNewAndReauthenticatedViewers(t *testing.T) {for _, reauthenticate := range []bool{false, true} {name := "new-viewer"diff --git a/internal/server/signal/router_pump.go b/internal/server/signal/router_pump.goindex aefca2c8..bafd6b59 100644--- a/internal/server/signal/router_pump.go+++ b/internal/server/signal/router_pump.go@@ -21,6 +21,7 @@ type preparedCandidate struct {hostSessionID stringhostSfuConfig *protocol.SfuConfigMessageviewerSfuConfig *protocol.SfuConfigMessage+ videoReady *protocol.RouteReadyMessage}// prepareResult is one admitted candidate or a typed rejection.@@ -97,6 +98,9 @@ func (r *router) drivePump(roomID string, rm *roomRuntime, controller *route.Conif pending != nil && !pending.result.denied {r.releaseReservation(pending.result.prepared.reservation)}+ if current, _ := r.rooms.Get(roomID); current == rm && rm.controller != nil && rm.requested && !r.closing {+ r.requestPump(roomID)+ }return}if !failed {@@ -238,6 +242,7 @@ func (r *router) pumpRoom(r.sendRouteFailures(roomID, begun.FailedPeerIDs, controller.Revision())continue}+ rm.pendingMedia = &preparedr.sendPrepareMessages(roomID, controller, begun.Operation, prepared)r.debug(roomID, "candidate-prepare-sent","child", r.debugPeer(roomID, operation.ChildPeerID),@@ -300,10 +305,16 @@ func (r *router) prepareCandidate(snapshot := controller.Snapshot()child, hasChild := r.store.GetConnectedViewer(roomID, operation.ChildPeerID)shareGeneration := r.hooks.shareGeneration(roomID)+ if rm.roomMedia {+ shareGeneration = rm.mediaGeneration+ }if !hasChild || child.SessionID != operation.ChildSessionID || shareGeneration == "" {return denied(route.RejectionStale)}connectionID := candidateConnectionIDPrefix + opaqueID()+ if operation.AttachConnectionID != "" {+ return prepareResult{prepared: preparedCandidate{connectionID: connectionID}}+ }var overlap *route.Resourceif plan.EndpointTransition.Kind == route.TransitionOverlap {producerPeerID := ""@@ -414,6 +425,14 @@ func (r *router) sendPrepareMessages(operation *route.OperationSnapshot,prepared preparedCandidate,) {+ if rm, _ := r.rooms.Get(roomID); rm != nil && rm.roomMedia {+ if r.hooks.routesChanged != nil {+ r.hooks.routesChanged(roomID)+ }+ if operation.VideoGeneration == "" {+ return+ }+ }current := operation.Currentcandidate := preparedRouteCandidate(operation, current.Tuple, current.ConnectionID)tuple := current.Tuple@@ -447,6 +466,10 @@ func (r *router) sendPrepareMessages(r.hooks.sendToSession(host.SessionID, *prepared.hostSfuConfig)}r.hooks.sendToSession(child.SessionID, childUpdate)+ if operation.AttachConnectionID != "" {+ r.prepareSfuVideoAttachment(roomID, operation)+ return+ }if prepared.viewerSfuConfig != nil {r.hooks.sendToSession(child.SessionID, *prepared.viewerSfuConfig)if prepared.hostSfuConfig == nil {diff --git a/internal/server/signal/router_room_media.go b/internal/server/signal/router_room_media.gonew file mode 100644index 00000000..58bfbd29--- /dev/null+++ b/internal/server/signal/router_room_media.go@@ -0,0 +1,52 @@+package signal++import (+ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/route"+)++func videoConnectionID(snapshot route.RouteSnapshot, edge route.CommittedEdge) string {+ if snapshot.RoomMedia {+ return edge.VideoConnectionID+ }+ return edge.ConnectionID+}++func (r *router) videoGeneration(roomID string) string {+ if r.hooks.videoGeneration != nil {+ return r.hooks.videoGeneration(roomID)+ }+ return r.hooks.shareGeneration(roomID)+}++func (r *router) setVideoPublication(roomID, generation string, paused bool) {+ rm, _ := r.rooms.Get(roomID)+ if rm == nil || !rm.roomMedia || rm.controller == nil {+ return+ }+ previous := rm.controller.Snapshot().VideoGeneration+ if previous != generation {+ r.retireRoomVideo(roomID, rm)+ }+ r.releaseResources(rm.controller.SetVideoPublication(generation, paused, r.now()))+ if previous != generation && generation != "" {+ rm.controller.SetHostVideoConnectionID(opaqueID())+ }+ if generation != "" {+ for _, viewer := range r.store.GetConnectedViewers(roomID) {+ r.connectParticipant(authenticatedRouteParticipant{roomID: roomID, peerID: viewer.PeerID,+ sessionID: viewer.SessionID, role: protocol.RoleViewer})+ }+ }+ if generation == "" && r.hooks.voiceDemandChanged != nil {+ r.hooks.voiceDemandChanged(roomID)+ }+ if rm.controller == nil {+ if r.hooks.routesChanged != nil {+ r.hooks.routesChanged(roomID)+ }+ return+ }+ r.broadcastActive(roomID, rm)+ r.requestPump(roomID)+}diff --git a/internal/server/signal/router_sfu.go b/internal/server/signal/router_sfu.goindex 2af44f5a..551e4118 100644--- a/internal/server/signal/router_sfu.go+++ b/internal/server/signal/router_sfu.go@@ -12,15 +12,17 @@ import (type drainKind stringconst (- drainPublication drainKind = "publication"- drainSubscription drainKind = "subscription"+ drainPublication drainKind = "publication"+ drainSubscription drainKind = "subscription"+ drainVideoPublication drainKind = "video-publication")// sfuDrainTask owns one asynchronous exact physical close.type sfuDrainTask struct {- kind drainKind- fence sfu.SubscriptionFence- operation *drainOperation+ kind drainKind+ fence sfu.SubscriptionFence+ operation *drainOperation+ closeVideo func() error}// drainOperation is the promise runSfuDrain tracked: done is closed after err@@ -125,20 +127,43 @@ func (r *router) sendFreshSfuConfig(participant authenticatedRouteParticipant) {return}snapshot := rm.controller.Snapshot()+ if rm.roomMedia && snapshot.VideoGeneration == "" {+ return+ }publication := snapshot.HostPublicationif publication == nil || !publication.PhysicalActive {return}connectionID := publication.ConnectionID+ revision := snapshot.Revisionif participant.role == protocol.RoleViewer {edge, ok := snapshot.UpstreamByViewer.Get(participant.peerID)if !ok || edge.Kind != route.UpstreamSfu || !edge.PhysicalActive {return}connectionID = edge.ConnectionID+ if rm.roomMedia {+ operation := snapshot.Operation+ if operation != nil && operation.Current != nil && operation.Reason == route.DemandPublicationAttach &&+ operation.ChildPeerID == participant.peerID && operation.ChildSessionID == participant.sessionID &&+ operation.AttachConnectionID == edge.ConnectionID && operation.Current.Tuple.Kind == route.UpstreamSfu {+ connectionID = operation.Current.ConnectionID+ } else if edge.VideoReady && edge.VideoConnectionID != "" {+ connectionID = edge.VideoConnectionID+ } else {+ return+ }+ }+ }+ if rm.roomMedia {+ if operation := snapshot.Operation; operation != nil && operation.Current != nil &&+ operation.Current.Tuple.Kind == route.UpstreamSfu &&+ (participant.role == protocol.RoleHost || operation.ChildPeerID == participant.peerID) {+ revision = operation.Current.Revision+ }}r.hooks.sendToSession(participant.sessionID, protocol.SfuConfigMessage{- Type: "sfu-config", Revision: protocol.Int(snapshot.Revision),+ Type: "sfu-config", Revision: protocol.Int(revision),PublicationGeneration: publication.Generation, ConnectionID: connectionID,})if participant.role == protocol.RoleHost && publication.Resource != nil {@@ -152,6 +177,84 @@ func (r *router) sendFreshSfuConfig(participant authenticatedRouteParticipant) {}}+// prepareSfuVideoAttachment attaches video to an already admitted room edge.+// The pump has begun this exact operation and installed the current Host video+// connection identity before calling it.+func (r *router) prepareSfuVideoAttachment(roomID string, operation *route.OperationSnapshot) {+ rm, _ := r.rooms.Get(roomID)+ if r.sfu == nil || rm == nil || !rm.roomMedia || rm.controller == nil ||+ operation == nil || operation.Current == nil || operation.Reason != route.DemandPublicationAttach ||+ operation.Current.Tuple.Kind != route.UpstreamSfu {+ return+ }+ snapshot := rm.controller.Snapshot()+ current := snapshot.Operation+ publication := snapshot.HostPublication+ if current == nil || current.Current == nil || current.Current.ConnectionID != operation.Current.ConnectionID ||+ publication == nil || publication.Resource == nil || publication.ConnectionID == "" {+ return+ }+ host, hasHost := r.store.GetConnectedHost(roomID)+ child, hasChild := r.store.GetConnectedViewer(roomID, operation.ChildPeerID)+ if !hasHost || host.SessionID != publication.HostSessionID ||+ !hasChild || child.SessionID != operation.ChildSessionID {+ return+ }+ config := protocol.SfuConfigMessage{Type: "sfu-config", Revision: protocol.Int(operation.Current.Revision),+ PublicationGeneration: publication.Generation}+ config.ConnectionID = publication.ConnectionID+ r.hooks.sendToSession(host.SessionID, config)+ config.ConnectionID = operation.Current.ConnectionID+ r.hooks.sendToSession(child.SessionID, config)+ if r.sfu.media.HasPublication(resourceFence(publication.Resource), publication.ConnectionID) {+ r.prepareSfuSubscriber(roomID, operation, publication.Generation)+ }+}++// retireRoomVideo retains room admission and the independent voice transports.+func (r *router) retireRoomVideo(roomID string, rm *roomRuntime) {+ if r.sfu == nil || rm == nil || !rm.roomMedia || rm.controller == nil {+ return+ }+ publication := rm.controller.Publication()+ if publication == nil || publication.Resource == nil {+ return+ }+ fence := resourceFence(publication.Resource)+ if fence.RoomID == roomID {+ r.retireSfuVideoPublication(fence, publication.ConnectionID)+ }+}++func (r *router) retireSfuVideoPublication(fence sfu.ResourceFence, connectionID string) {+ if r.sfu == nil {+ return+ }+ var closeVideo func() error+ if media, ok := r.sfu.media.(interface {+ RetirePublication(sfu.ResourceFence, string) func() error+ }); ok {+ closeVideo = media.RetirePublication(fence, connectionID)+ } else {+ // Legacy runtimes cannot detach a reusable room-generation handle.+ // Their video-only publication fences are unique for each share.+ if rm, _ := r.rooms.Get(fence.RoomID); rm != nil && rm.roomMedia {+ return+ }+ media := r.sfu.media+ if media.HasPublication(fence, connectionID) {+ closeVideo = func() error { return media.ClosePublication(fence) }+ }+ }+ if closeVideo == nil {+ return+ }+ key := sfu.SubscriptionFence{ResourceFence: fence, ConnectionID: connectionID}+ task := &sfuDrainTask{kind: drainVideoPublication, fence: key, closeVideo: closeVideo}+ r.sfuDrainTasks.Set(key, task)+ r.runSfuDrain(key, task)+}+// scheduleSfuPublicationDrain deletes sibling subscription tasks during// the live iteration.func (r *router) scheduleSfuPublicationDrain(fence sfu.ResourceFence) {@@ -202,7 +305,9 @@ func (r *router) runSfuDrain(key sfu.SubscriptionFence, task *sfuDrainTask) *drar.inflight++go func() {var err error- if task.kind == drainPublication {+ if task.kind == drainVideoPublication {+ err = task.closeVideo()+ } else if task.kind == drainPublication {err = fallback.media.ClosePublication(task.fence.ResourceFence)} else {err = fallback.media.CloseSubscription(task.fence, task.fence.ConnectionID)diff --git a/internal/server/signal/router_sfu_room_media_test.go b/internal/server/signal/router_sfu_room_media_test.gonew file mode 100644index 00000000..fdb9a0f9--- /dev/null+++ b/internal/server/signal/router_sfu_room_media_test.go@@ -0,0 +1,218 @@+package signal++import (+ "context"+ "testing"+ "time"++ "github.com/TNTcraftHIM/Piik/internal/media/forwarding"+ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/route"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+ "github.com/pion/webrtc/v4"+)++func TestRoomSfuVideoFailureRetainsRoomAdmissionDuringReplacement(t *testing.T) {+ h := newRouterHarness(t, routerHarnessOptions{capacity: 1, withSfu: true})+ created := h.createRoom()+ host, first, _ := h.establishSfuRoom(created)+ h.settle()+ h.locked(func() {+ rm, _ := h.router.rooms.Get(created.RoomID)+ rm.roomMedia = true+ rm.controller.SetVideoPublication(testShareGeneration, false, h.router.now())+ publication := rm.controller.Publication()+ edge, _ := rm.controller.Snapshot().UpstreamByViewer.Get(first.peerID)+ fence := resourceFence(publication.Resource)+ h.router.handleRouteFailed(host, routeFailedMessage(rm.controller.Revision(), "active", publication.ConnectionID))+ current := rm.controller.Publication()+ if current == nil || current.Generation != publication.Generation || !current.PhysicalActive {+ t.Fatal("video failure retired the room publication before replacement")+ }+ if !h.admission.HasPublication(fence) || !h.admission.HasSubscription(subscriptionFence(edge.Resource)) {+ t.Fatal("video failure released room admission used by healthy voice")+ }+ })+}++func TestRoomSfuVideoAttachmentUsesExistingAdmissionAndExactPhysicalIdentity(t *testing.T) {+ h := newRouterHarness(t, routerHarnessOptions{capacity: 1, withSfu: true})+ created := h.createRoom()+ host, first, second := h.establishSfuRoom(created)+ h.settle()+ h.locked(func() {+ rm, _ := h.router.rooms.Get(created.RoomID)+ rm.roomMedia, rm.mediaGeneration = true, "room_media_12345678"+ rm.controller.SetVideoPublication(testShareGeneration, false, h.router.now())+ publication := rm.controller.Publication()+ originalHostID := publication.ConnectionID+ rm.controller.SetVideoPublication("", false, h.router.now())+ rm.controller.SetVideoPublication("video_next_12345678", false, h.router.now())+ rm.controller.SetHostVideoConnectionID("publisher_next_12345678")+ op := rm.controller.Reconcile(h.router.now()).Operation+ if op == nil || op.Reason != route.DemandPublicationAttach {+ t.Fatal("expected publication attachment")+ }+ child, other := first, second+ if op.ChildPeerID == second.peerID {+ child, other = second, first+ }+ edge, _ := rm.controller.Snapshot().UpstreamByViewer.Get(child.peerID)+ begun := rm.controller.BeginCurrentCandidate(route.BeginInput{+ Guard: cursorGuard(op, op.Candidates[op.Cursor]), NowMs: h.router.now(),+ ConnectionID: "subscriber_next_12345678",+ })+ if !begun.Accepted {+ t.Fatal("attachment did not begin")+ }+ op = begun.Operation+ message := protocol.SfuSignalMessage{Type: "sfu-signal", Kind: "candidate",+ Revision: protocol.Int(op.Current.Revision), PublicationGeneration: publication.Generation,+ ConnectionID: op.Current.ConnectionID}+ fence, allowed := h.router.sfuSignalAuthorized(child, message)+ if !allowed || fence.ConnectionID != edge.ConnectionID || fence.ResourceFence != resourceFence(publication.Resource) {+ t.Fatal("physical video attachment did not retain the exact logical reservation")+ }+ if _, allowed := h.router.sfuSignalAuthorized(other, message); allowed {+ t.Fatal("another viewer could use the admitted video facet")+ }+ stale := child+ stale.sessionID = "replaced_session_12345678"+ if _, allowed := h.router.sfuSignalAuthorized(stale, message); allowed {+ t.Fatal("stale session could signal an attachment")+ }+ voiceOnly := message+ voiceOnly.ConnectionID = edge.ConnectionID+ if _, allowed := h.router.sfuSignalAuthorized(child, voiceOnly); allowed {+ t.Fatal("room connection identity was accepted as the replacement video identity")+ }+ hostMessage := message+ hostMessage.ConnectionID = "publisher_next_12345678"+ if _, allowed := h.router.sfuSignalAuthorized(host, hostMessage); !allowed {+ t.Fatal("replacement publisher was rejected")+ }+ phase, revision := sfuConnectionPhase(rm.controller.Snapshot(), host.role, host.peerID,+ publication.Generation, hostMessage.ConnectionID)+ if phase != "prepare" || revision != op.Current.Revision {+ t.Fatal("publisher attachment lost its current operation phase")+ }+ h.router.prepareSfuVideoAttachment(created.RoomID, op)+ h.router.sendFreshSfuConfig(child)+ config, ok := h.sent[child.sessionID][len(h.sent[child.sessionID])-1].(protocol.SfuConfigMessage)+ if !ok || config.ConnectionID != message.ConnectionID || config.Revision != message.Revision {+ t.Fatal("reauthentication did not describe the pending physical attachment")+ }+ guard := route.CandidateGuard{ChildPeerID: child.peerID, ChildSessionID: child.sessionID,+ Revision: op.Current.Revision, ConnectionID: op.Current.ConnectionID}+ if !rm.controller.CandidateReady(guard, h.router.now(), nil,+ route.CandidateProof{VideoGeneration: "video_next_12345678"}).Committed {+ t.Fatal("video proof did not commit")+ }+ message.Revision = protocol.Int(rm.controller.Revision())+ if _, allowed := h.router.sfuSignalAuthorized(child, message); !allowed {+ t.Fatal("committed video facet was rejected")+ }+ h.router.handleSfuMediaEvent(sfu.MediaEvent{Fence: resourceFence(publication.Resource),+ ConnectionID: originalHostID, State: webrtc.PeerConnectionStateFailed})+ if current := rm.controller.Publication(); !current.Usable || current.ConnectionID != hostMessage.ConnectionID {+ t.Fatal("retired publisher callback invalidated its replacement")+ }+ rm.controller.SetVideoPublication("", false, h.router.now())+ if _, allowed := h.router.sfuSignalAuthorized(child, message); allowed {+ t.Fatal("stopped video retained signaling authority")+ }+ if !h.admission.HasSubscription(fence) || !h.admission.HasPublication(fence.ResourceFence) {+ t.Fatal("video stop released room admission")+ }+ })+}++func TestRoomSfuVideoRetirementDetachesBeforeCloseAndKeepsAdmission(t *testing.T) {+ h := newRouterHarness(t, routerHarnessOptions{capacity: 1, withSfu: true})+ created := h.createRoom()+ h.establishSfuRoom(created)+ h.settle()+ media := sfu.NewMedia(sfu.MediaOptions{})+ defer media.Close()+ h.locked(func() {+ rm, _ := h.router.rooms.Get(created.RoomID)+ rm.roomMedia, rm.mediaGeneration = true, "room_media_12345678"+ rm.controller.SetVideoPublication(testShareGeneration, false, h.router.now())+ publication := rm.controller.Publication()+ fence := resourceFence(publication.Resource)+ metadata := sfu.PublicationMedia{Codec: "vp8", RIDs: []string{""},+ Formats: []forwarding.LayerFormat{{Width: 640, Height: 360, Bitrate: 500_000}}}+ if err := media.PreparePublication(fence, publication.ConnectionID, metadata); err != nil {+ t.Fatal(err)+ }+ h.router.sfu.media = media+ h.router.retireRoomVideo(created.RoomID, rm)+ if media.HasPublication(fence, publication.ConnectionID) {+ t.Fatal("retired video remained visible while physical close was pending")+ }+ if !h.admission.HasPublication(fence) {+ t.Fatal("video retirement released room ingress")+ }+ if err := media.PreparePublication(fence, "replacement_publisher_12345678", metadata); err != nil {+ t.Fatal(err)+ }+ if retired := media.RetirePublication(fence, publication.ConnectionID); retired != nil {+ t.Fatal("old identity detached the replacement")+ }+ })+ h.settle()+ h.locked(func() {+ rm, _ := h.router.rooms.Get(created.RoomID)+ fence := resourceFence(rm.controller.Publication().Resource)+ if !media.HasPublication(fence, "replacement_publisher_12345678") {+ t.Fatal("old physical close removed the replacement")+ }+ if h.router.sfuDrainTasks.Len() != 0 {+ t.Fatal("retired physical close did not settle")+ }+ })+}++func TestSfuLogicalSubscriptionDrainClosesPendingPhysicalVideo(t *testing.T) {+ ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)+ defer cancel()+ demand := make(chan struct{}, 1)+ media := sfu.NewMedia(sfu.MediaOptions{Events: func(event sfu.MediaEvent) {+ if event.ActiveCount != nil {+ select {+ case demand <- struct{}{}:+ default:+ }+ }+ }})+ defer media.Close()+ fence := sfu.SubscriptionFence{ResourceFence: sfu.ResourceFence{RoomID: "1234",+ ShareGeneration: "room_media_12345678", PublicationGeneration: "publication_12345678"},+ ViewerPeerID: "viewer_12345678", ConnectionID: "logical_edge_12345678"}+ if err := media.PreparePublication(fence.ResourceFence, "publisher_12345678", sfu.PublicationMedia{+ Codec: "vp8", RIDs: []string{""}, Formats: []forwarding.LayerFormat{{Width: 640, Height: 360, Bitrate: 500_000}},+ }); err != nil {+ t.Fatal(err)+ }+ result := make(chan error, 1)+ go func() {+ _, err := media.PrepareSubscriber(ctx, fence, "physical_video_12345678")+ result <- err+ }()+ select {+ case <-demand:+ case <-ctx.Done():+ t.Fatal(ctx.Err())+ }+ if err := media.CloseSubscription(fence, fence.ConnectionID); err != nil {+ t.Fatal(err)+ }+ select {+ case err := <-result:+ if err == nil {+ t.Fatal("retired waiting subscriber was prepared")+ }+ case <-ctx.Done():+ t.Fatal("logical drain did not cancel physical video preparation")+ }+}diff --git a/internal/server/signal/router_sfu_signal.go b/internal/server/signal/router_sfu_signal.goindex b817be57..eaece889 100644--- a/internal/server/signal/router_sfu_signal.go+++ b/internal/server/signal/router_sfu_signal.go@@ -24,6 +24,18 @@ func (r *router) sfuSignalAuthorized(participant authenticatedRouteParticipant,return fence, false}snapshot := rm.controller.Snapshot()+ if rm.roomMedia {+ if snapshot.VideoGeneration == "" {+ return fence, false+ }+ fence.ShareGeneration = rm.mediaGeneration+ // Opting into voice during an existing share preserves its admitted+ // resource fence, even though subsequent publications are room-scoped.+ if publication := snapshot.HostPublication; publication != nil &&+ publication.Generation == message.PublicationGeneration && publication.Resource != nil {+ fence.ResourceFence = resourceFence(publication.Resource)+ }+ }latestRevision := snapshot.Revisionif snapshot.Operation != nil && snapshot.Operation.Current != nil {latestRevision = max(latestRevision, snapshot.Operation.Current.Revision)@@ -44,10 +56,32 @@ func (r *router) sfuSignalAuthorized(participant authenticatedRouteParticipant,r.sfu.admission.HasPublication(fence.ResourceFence)}fence.ViewerPeerID = participant.peerID+ if rm.roomMedia {+ operation := snapshot.Operation+ edge, hasEdge := snapshot.UpstreamByViewer.Get(participant.peerID)+ if hasEdge && edge.Kind == route.UpstreamSfu && edge.PhysicalActive &&+ edge.ChildSessionID == participant.sessionID && edge.PublicationGeneration == message.PublicationGeneration {+ active := edge.VideoReady && edge.VideoConnectionID == message.ConnectionID+ attaching := operation != nil && operation.Current != nil &&+ operation.Reason == route.DemandPublicationAttach &&+ operation.Current.Tuple.Kind == route.UpstreamSfu &&+ operation.ChildPeerID == participant.peerID && operation.ChildSessionID == participant.sessionID &&+ operation.AttachConnectionID == edge.ConnectionID &&+ operation.Current.Revision == int64(message.Revision) &&+ operation.Current.ConnectionID == message.ConnectionID+ if active || attaching {+ if edge.Resource == nil {+ return fence, false+ }+ fence = subscriptionFence(edge.Resource)+ return fence, r.sfu.admission.HasSubscription(fence)+ }+ }+ }if !r.sfu.admission.HasSubscription(fence) {return fence, false}- if edge, ok := snapshot.UpstreamByViewer.Get(participant.peerID); ok && edge.PhysicalActive && edge.Kind == route.UpstreamSfu &&+ if edge, ok := snapshot.UpstreamByViewer.Get(participant.peerID); !rm.roomMedia && ok && edge.PhysicalActive && edge.Kind == route.UpstreamSfu &&edge.PublicationGeneration == message.PublicationGeneration && edge.ConnectionID == message.ConnectionID && edge.ChildSessionID == participant.sessionID {return fence, true}@@ -113,7 +147,7 @@ func (r *router) handleSfuSignal(participant authenticatedRouteParticipant, mess})if _, allowed := r.sfuSignalAuthorized(participant, message); !allowed {if newPublication {- go media.ClosePublication(fence.ResourceFence)+ r.retireSfuVideoPublication(fence.ResourceFence, message.ConnectionID)}return}@@ -200,7 +234,10 @@ func sfuConnectionPhase(snapshot route.RouteSnapshot, role protocol.Role, peerIDoperation := snapshot.Operationif operation != nil && operation.Current != nil && operation.Current.Tuple.Kind == route.UpstreamSfu &&(role == protocol.RoleViewer && operation.ChildPeerID == peerID && operation.Current.ConnectionID == connectionID ||- role == protocol.RoleHost && connectionID == generation && (snapshot.HostPublication == nil || snapshot.HostPublication.Generation != generation)) {+ role == protocol.RoleHost && (connectionID == generation && (snapshot.HostPublication == nil || snapshot.HostPublication.Generation != generation) ||+ snapshot.RoomMedia && operation.Reason == route.DemandPublicationAttach &&+ snapshot.HostPublication != nil && snapshot.HostPublication.Generation == generation &&+ snapshot.HostPublication.ConnectionID == connectionID)) {return "prepare", operation.Current.Revision}return "active", snapshot.Revision@@ -215,7 +252,8 @@ func (s *Server) HandleSfuMediaEvent(event sfu.MediaEvent) {func (r *router) handleSfuMediaEvent(event sfu.MediaEvent) {rm, _ := r.rooms.Get(event.Fence.RoomID)- if r.closing || rm == nil || rm.controller == nil || r.hooks.shareGeneration(event.Fence.RoomID) != event.Fence.ShareGeneration {+ if r.closing || rm == nil || rm.controller == nil ||+ (!rm.roomMedia && r.hooks.shareGeneration(event.Fence.RoomID) != event.Fence.ShareGeneration) {return}peerID, role := event.ViewerPeerID, protocol.RoleViewer@@ -224,6 +262,16 @@ func (r *router) handleSfuMediaEvent(event sfu.MediaEvent) {}peer, connected := r.connectedPeer(event.Fence.RoomID, peerID)snapshot := rm.controller.Snapshot()+ if rm.roomMedia {+ publication := snapshot.HostPublication+ expectedGeneration := rm.mediaGeneration+ if publication != nil && publication.Generation == event.Fence.PublicationGeneration && publication.Resource != nil {+ expectedGeneration = publication.Resource.ShareGeneration+ }+ if snapshot.VideoGeneration == "" || expectedGeneration != event.Fence.ShareGeneration {+ return+ }+ }participant := authenticatedRouteParticipant{roomID: event.Fence.RoomID, role: role, peerID: peerID, sessionID: peer.SessionID}phase, revision := sfuConnectionPhase(snapshot, role, peerID, event.Fence.PublicationGeneration, event.ConnectionID)message := protocol.SfuSignalMessage{Type: "sfu-signal", Kind: "candidate", Revision: protocol.Int(revision), PublicationGeneration: event.Fence.PublicationGeneration, ConnectionID: event.ConnectionID}diff --git a/internal/server/signal/server.go b/internal/server/signal/server.goindex 8dfae2b1..a172b286 100644--- a/internal/server/signal/server.go+++ b/internal/server/signal/server.go@@ -184,6 +184,7 @@ type Server struct {senderQualityRateBySession map[string]*senderQualityRateWindow// shares keeps generation, settings, route policy and pause intent together.shares map[string]roomShare+ voices map[string]*roomVoicedeferredViewerPresenceRooms map[string]struct{}heartbeatStop func() bool@@ -265,7 +266,15 @@ func New(options Options) (*Server, error) {hooks: routerHooks{sendToSession: s.sendToSession,shareGeneration: func(roomID string) string { return s.shares[roomID].generation },- routesChanged: s.sendViewerPresence,+ routesChanged: func(roomID string) {+ s.sendViewerPresence(roomID)+ s.syncRoomVoice(roomID)+ },+ voiceAllowed: s.voiceAllowed,+ voiceDemandChanged: s.syncVoiceDemand,+ voiceCandidateReady: s.voiceCandidateReady,+ voiceRouteFailed: s.voiceRouteFailed,+ videoGeneration: s.activeHostShareGeneration,},now: s.now,afterFunc: s.afterFunc,@@ -417,6 +426,9 @@ func (s *Server) hasConnectionCapacity() bool {func (s *Server) Close(ctx context.Context) error {s.mu.Lock()s.closing = true+ for roomID := range s.voices {+ s.closeRoomVoice(roomID)+ }if s.heartbeatStop != nil {s.heartbeatStop()}@@ -1022,6 +1034,10 @@ func (s *Server) completeAuthentication(sess *session, request authRequest, part}if participant.Role == protocol.RoleHost && mediaActive {+ if rm, _ := s.router.rooms.Get(roomID); rm != nil && rm.roomMedia && rm.controller != nil &&+ rm.controller.Snapshot().VideoGeneration != shareGeneration {+ s.router.setVideoPublication(roomID, shareGeneration, s.shares[roomID].pausedGeneration == shareGeneration)+ }s.router.setPaused(roomID, s.shares[roomID].pausedGeneration == shareGeneration)}if participant.Role == protocol.RoleViewer || mediaActive {@@ -1145,6 +1161,18 @@ func (s *Server) connectRouteParticipant(participant authenticatedRouteParticipaassigned = false}}()+ if participant.role == protocol.RoleHost && participant.routePolicy != nil {+ if rm, _ := s.router.rooms.Get(participant.roomID); rm != nil && rm.roomMedia && rm.controller != nil {+ s.router.releaseResources(rm.controller.SetRoutePolicy(*participant.routePolicy, s.now()))+ for peerID, settings := range rm.viewerSettings.All() {+ if settings.preference != "" && !rm.controller.AllowsViewerRoutePreference(settings.preference) {+ settings.preference = protocol.ViewerRouteAuto+ rm.viewerSettings.Set(peerID, settings)+ s.router.sendViewerRoutePreference(participant.roomID, peerID, true)+ }+ }+ }+ }return s.router.connectParticipant(participant), true}@@ -1198,6 +1226,16 @@ func routeParticipant(sess *session, authenticated *authenticatedSession) authenfunc (s *Server) handleAuthenticatedMessage(sess *session, authenticated *authenticatedSession, message protocol.ClientMessage) {switch m := message.(type) {+ case protocol.SetRelayVolunteerMessage:+ s.setRelayVolunteer(sess, authenticated, m)+ case protocol.SubscribeRoomVoiceMessage:+ s.subscribeRoomVoice(sess, authenticated)+ case protocol.RoomVoiceCommandMessage:+ s.handleRoomVoiceCommand(sess, authenticated, m.Command)+ case protocol.RoomVoiceSignalMessage:+ s.handleRoomVoiceSignal(sess, authenticated, m)+ case protocol.RoomVoiceTransportMessage:+ s.handleRoomVoiceTransport(sess, authenticated, m)case protocol.SubscribeRemoteInputMessage:s.subscribeRemoteInput(sess, authenticated, m)case protocol.SubscribeRoomInteractionsMessage:@@ -1367,9 +1405,6 @@ func (s *Server) handleAuthenticatedMessage(sess *session, authenticated *authenreturn}s.stopSharing(authenticated.roomID)- // Room membership and its interaction stream outlive the media- // publication. The next start-sharing message claims a fresh generation.- authenticated.shareGeneration = ""s.sendViewerPresence(authenticated.roomID)case protocol.AbandonRoomMessage:if authenticated.role != protocol.RoleHost {@@ -1447,6 +1482,7 @@ func (s *Server) startSharing(sess *session, authenticated *authenticatedSessionQualitySettings: qualitySettings,Paused: share.pausedGeneration == shareGeneration,})+ s.router.setVideoPublication(authenticated.roomID, shareGeneration, share.pausedGeneration == shareGeneration)// Acknowledge publication authority before any media effects use it.s.router.setPaused(authenticated.roomID, share.pausedGeneration == shareGeneration)s.router.completeAuthentication(routeParticipant, routeState)diff --git a/internal/server/signal/session.go b/internal/server/signal/session.goindex c6677640..803326db 100644--- a/internal/server/signal/session.go+++ b/internal/server/signal/session.go@@ -54,6 +54,7 @@ type session struct {lastSignalingChallengeAtMs int64authenticated *authenticatedSessionroomInteractions bool+ roomVoice boolaudioPresence boolremoteInput boolinputEndpoint stringdiff --git a/internal/server/signal/voice.go b/internal/server/signal/voice.gonew file mode 100644index 00000000..e3da2fc6--- /dev/null+++ b/internal/server/signal/voice.go@@ -0,0 +1,240 @@+package signal++import (+ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/room"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+)++type voiceMember struct {+ sessionID string+ joined bool+ publicationID string+}++// Room authority owns voice activation and publication identity. Connections below+// are physical facets of router.controller's graph, never another topology.+type roomVoice struct {+ hostPeerID string+ revision int64+ members map[string]*voiceMember+ connections map[string]*voiceEdge+}++func (v *roomVoice) enabled() bool {+ host := v.members[v.hostPeerID]+ return host != nil && host.joined+}++func (v *roomVoice) leaveAll() {+ for _, member := range v.members {+ member.joined, member.publicationID = false, ""+ }+}++type voiceEdge struct {+ id, logicalID, parent, child, transport string+ parentSession, childSession string+ pending bool+ revision int64+ send map[string][]string+ connected map[string]bool+ sfuPlan *sfu.VoiceConnectionPlan+}++func (s *Server) voiceRoom(roomID string) *roomVoice {+ if s.voices == nil {+ s.voices = make(map[string]*roomVoice)+ }+ v := s.voices[roomID]+ if v == nil {+ v = &roomVoice{members: make(map[string]*voiceMember), connections: make(map[string]*voiceEdge)}+ s.voices[roomID] = v+ }+ if host, ok := s.store.GetConnectedHost(roomID); ok {+ if v.hostPeerID != "" && v.hostPeerID != host.PeerID {+ v.leaveAll()+ delete(v.members, v.hostPeerID)+ }+ v.hostPeerID = host.PeerID+ }+ return v+}++func (s *Server) subscribeRoomVoice(sess *session, auth *authenticatedSession) {+ sess.roomVoice = true+ v := s.voiceRoom(auth.roomID)+ m := v.members[auth.peerID]+ if m == nil {+ m = &voiceMember{}+ v.members[auth.peerID] = m+ }+ if m.sessionID != sess.sessionID {+ m.sessionID = sess.sessionID+ m.publicationID = ""+ }+ s.syncVoiceDemand(auth.roomID)+ s.syncRoomVoice(auth.roomID)+}++func (s *Server) voiceSession(roomID, peerID string) (*session, *voiceMember) {+ v := s.voices[roomID]+ if v == nil {+ return nil, nil+ }+ m := v.members[peerID]+ if m == nil {+ return nil, nil+ }+ sess := s.sessionsByID[m.sessionID]+ if sess == nil || !sess.roomVoice || !s.isCurrentSession(sess) || sess.authenticated == nil ||+ sess.authenticated.roomID != roomID || sess.authenticated.peerID != peerID {+ return nil, m+ }+ return sess, m+}++func (s *Server) voiceAllowed(roomID, peerID string) bool {+ sess, m := s.voiceSession(roomID, peerID)+ return sess != nil && s.voices[roomID].enabled() && m.joined+}++func (s *Server) handleRoomVoiceCommand(sess *session, auth *authenticatedSession, command protocol.RoomVoiceCommand) {+ if !sess.roomVoice {+ s.voiceError(sess, "not-allowed")+ return+ }+ v := s.voiceRoom(auth.roomID)+ m := v.members[auth.peerID]+ if m == nil || m.sessionID != sess.sessionID {+ return+ }+ switch command.Action {+ case "join":+ if auth.role != protocol.RoleHost && !v.enabled() {+ s.voiceError(sess, "not-enabled")+ return+ }+ m.joined = true+ case "leave":+ if auth.role == protocol.RoleHost {+ v.leaveAll()+ } else {+ m.joined, m.publicationID = false, ""+ }+ case "publish":+ if !v.enabled() || !m.joined {+ s.voiceError(sess, "not-allowed")+ return+ }+ if m.publicationID == "" {+ m.publicationID = opaqueID()+ }+ case "unpublish":+ if command.PublicationID == m.publicationID {+ m.publicationID = ""+ }+ }+ s.syncVoiceDemand(auth.roomID)+ s.syncRoomVoice(auth.roomID)+}++func (s *Server) voiceError(sess *session, code string) {+ s.send(sess, protocol.RoomVoiceErrorMessage{Type: "room-voice-error", Code: code})+}++func (s *Server) roomVoiceParticipants(roomID string) []room.ConnectedPeer {+ result := []room.ConnectedPeer{}+ if host, ok := s.store.GetConnectedHost(roomID); ok {+ result = append(result, host)+ }+ return append(result, s.store.GetConnectedViewers(roomID)...)+}++func (s *Server) syncVoiceDemand(roomID string) {+ v := s.voices[roomID]+ if v == nil {+ return+ }+ listeners := make([]string, 0, len(v.members))+ for peerID := range v.members {+ if s.voiceAllowed(roomID, peerID) {+ listeners = append(listeners, peerID)+ }+ }+ if len(listeners) == 0 {+ if rm, _ := s.router.rooms.Get(roomID); rm != nil && rm.roomMedia && rm.controller != nil {+ rm.controller.SetVoiceListeners(nil, s.now())+ if s.activeHostShareGeneration(roomID) == "" {+ s.router.clearDeadline(rm)+ s.router.releaseResources(rm.controller.Dispose())+ rm.controller = nil+ } else {+ s.router.requestPump(roomID)+ }+ }+ return+ }+ host, ok := s.store.GetConnectedHost(roomID)+ if !ok {+ return+ }+ rm := s.router.room(roomID)+ if !rm.roomMedia {+ rm.roomMedia = true+ rm.mediaGeneration = opaqueID()+ if rm.controller != nil {+ if publication := rm.controller.Snapshot().HostPublication; publication != nil && publication.Resource != nil {+ rm.mediaGeneration = publication.Resource.ShareGeneration+ }+ generation := s.activeHostShareGeneration(roomID)+ paused := generation != "" && s.shares[roomID].pausedGeneration == generation+ s.router.releaseResources(rm.controller.SetVideoPublication(generation, paused, s.now()))+ }+ }+ hostSession := s.sessionsByID[host.SessionID]+ if hostSession == nil || hostSession.authenticated == nil {+ return+ }+ participant := routeParticipant(hostSession, hostSession.authenticated)+ policy := s.routePolicyOf(roomID)+ participant.routePolicy = &policy+ s.router.connectParticipant(participant)+ generation := s.activeHostShareGeneration(roomID)+ paused := generation != "" && s.shares[roomID].pausedGeneration == generation+ s.router.releaseResources(rm.controller.SetVideoPublication(generation, paused, s.now()))+ for _, peer := range s.store.GetConnectedViewers(roomID) {+ if generation == "" && !s.voiceAllowed(roomID, peer.PeerID) {+ if rm.controller != nil {+ rm.controller.ConfirmDeparture(peer.PeerID, s.router.nowPtr())+ }+ continue+ }+ if current := s.sessionsByID[peer.SessionID]; current != nil && current.authenticated != nil {+ s.router.connectParticipant(routeParticipant(current, current.authenticated))+ }+ }+ rm.controller.SetVoiceListeners(listeners, s.now())+ s.router.requestPump(roomID)+}++func (s *Server) disconnectRoomVoice(roomID, peerID, sessionID string) {+ v := s.voices[roomID]+ if v == nil {+ return+ }+ if m := v.members[peerID]; m != nil && m.sessionID == sessionID {+ m.publicationID = ""+ }+ s.syncVoiceDemand(roomID)+ s.syncRoomVoice(roomID)+}++func (s *Server) closeRoomVoice(roomID string) {+ if v := s.voices[roomID]; v != nil {+ for _, edge := range v.connections {+ s.closeVoiceEdge(roomID, edge)+ }+ delete(s.voices, roomID)+ }+}diff --git a/internal/server/signal/voice_owner_test.go b/internal/server/signal/voice_owner_test.gonew file mode 100644index 00000000..4fba5148--- /dev/null+++ b/internal/server/signal/voice_owner_test.go@@ -0,0 +1,263 @@+package signal++import (+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+)++func TestVoiceFailureReplacesOnlyCompanionOfHealthyPicture(t *testing.T) {+ h, host, viewer, _, viewerID := joinedVoiceOwnerRoom(t)+ host.sendJSON(map[string]any{"type": "start-sharing", "shareGeneration": "voice_picture_123456",+ "qualitySettings": protocol.DefaultQualitySettings, "routePolicy": protocol.DefaultRoutePolicy, "sharingPaused": false})+ host.next("sharing-started")+ prepare := nextPreparedRoute(t, viewer)+ viewer.sendJSON(map[string]any{"type": "route-ready", "phase": "prepare", "revision": prepare.Revision})+ nextActiveRouteRevision(t, viewer, prepare.Revision)+ before := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && !state.Connections[0].Pending+ })+ oldID := before.Connections[0].ConnectionID+ viewer.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": oldID, "state": "failed"})+ after := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && state.Connections[0].ConnectionID != oldID+ })+ if after.Connections[0].Pending {+ t.Fatal("voice repair started another route operation")+ }+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ snapshot := rm.controller.Snapshot()+ edge, ok := snapshot.UpstreamByViewer.Get(viewerID.PeerID)+ if !ok || !edge.Usable || !edge.VideoReady || snapshot.Operation != nil || snapshot.Revision != int64(prepare.Revision) {+ t.Fatal("voice failure invalidated the current picture route")+ }+ })+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": after.Connections[0].ConnectionID, "state": "connected"})+ }+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ for _, member := range state.Members {+ if member.PeerID == viewerID.PeerID {+ return member.Upstream.Kind == "peer"+ }+ }+ return false+ })+}++func TestVoiceOwnerMustOpenBeforeViewersCanJoin(t *testing.T) {+ h := startHarness(t, harnessOptions{})+ host, viewer := openClient(t, h), openClient(t, h)+ authenticate(t, host, h.room, protocol.RoleHost, "voice_closed_host_123456", -1, "",+ presenceOptions{roomSession: true, roomOnly: true})+ authenticate(t, viewer, h.room, protocol.RoleViewer, "voice_closed_viewer_123456", 0, "", presenceOptions{})+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, client, nil)+ }+ voiceCommand(viewer, map[string]any{"action": "join"})+ message, err := protocol.DecodeServerMessage(viewer.next("room-voice-error").raw)+ if err != nil || message.(protocol.RoomVoiceErrorMessage).Code != "not-enabled" {+ t.Fatal("viewer could open voice without the Host")+ }+ voiceCommand(host, map[string]any{"action": "join"})+ state := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool { return state.Enabled })+ if len(state.Publications) != 0 || len(state.Connections) != 0 {+ t.Fatal("opening room voice started a microphone or joined a Viewer")+ }+ voiceCommand(viewer, map[string]any{"action": "join"})+ pending := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && state.Connections[0].Pending+ })+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": pending.Connections[0].ConnectionID, "state": "connected"})+ }+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && !state.Connections[0].Pending+ })+ voiceCommand(viewer, map[string]any{"action": "publish"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return len(state.Publications) == 1 })+ voiceCommand(host, map[string]any{"action": "leave"})+ state = nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool { return !state.Enabled })+ if len(state.Publications) != 0 || len(state.Connections) != 0 {+ t.Fatal("closing room voice retained media")+ }+ for _, member := range state.Members {+ if member.Joined || member.PublicationID != "" {+ t.Fatal("closing room voice retained a joined participant")+ }+ }+ voiceCommand(host, map[string]any{"action": "join"})+ state = nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool { return state.Enabled })+ if len(state.Publications) != 0 || len(state.Connections) != 0 {+ t.Fatal("reopening room voice restored former media")+ }+}++func joinedVoiceOwnerRoom(t *testing.T) (*harness, *testClient, *testClient, authenticatedMessage, authenticatedMessage) {+ t.Helper()+ h := startHarness(t, harnessOptions{viewerDisconnectGraceMs: 30_000})+ host, viewer := openClient(t, h), openClient(t, h)+ hostID := authenticate(t, host, h.room, protocol.RoleHost, "owner_host_123456", -1, "", presenceOptions{roomSession: true, roomOnly: true})+ viewerID := authenticate(t, viewer, h.room, protocol.RoleViewer, "owner_viewer_123456", 1, "", presenceOptions{})+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, client, nil)+ }+ voiceCommand(host, map[string]any{"action": "join"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return state.Enabled })+ voiceCommand(viewer, map[string]any{"action": "join"})+ pending := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && state.Connections[0].Pending+ })+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": pending.Connections[0].ConnectionID, "state": "connected"})+ }+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && !state.Connections[0].Pending+ })+ return h, host, viewer, hostID, viewerID+}++func TestVoiceOwnersRebindRoomOnlySessionsAndReleaseLastDisconnect(t *testing.T) {+ h, host, viewer, hostID, viewerID := joinedVoiceOwnerRoom(t)+ h.closeClient(viewer)+ viewer = openClient(t, h)+ reboundViewer := authenticate(t, viewer, h.room, protocol.RoleViewer, "owner_viewer_123456", 1, "", presenceOptions{})+ if reboundViewer.PeerID != viewerID.PeerID {+ t.Fatal("viewer identity did not survive grace")+ }+ viewer.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool { return len(state.Connections) == 1 })+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ edge, ok := rm.controller.Snapshot().UpstreamByViewer.Get(viewerID.PeerID)+ peer, _ := h.store.GetConnectedViewer(h.room.RoomID, viewerID.PeerID)+ if !ok || edge.ChildSessionID != peer.SessionID || !h.server.voiceAllowed(h.room.RoomID, viewerID.PeerID) {+ t.Fatal("subscription did not rebind approved viewer route")+ }+ })+ h.closeClient(host)+ host = openClient(t, h)+ reboundHost := authenticate(t, host, h.room, protocol.RoleHost, "owner_host_123456", -1, "", presenceOptions{roomSession: true, roomOnly: true})+ if reboundHost.PeerID != hostID.PeerID {+ t.Fatal("host identity changed on room reconnect")+ }+ host.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return len(state.Connections) == 1 })+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ edge, ok := rm.controller.Snapshot().UpstreamByViewer.Get(viewerID.PeerID)+ peer, _ := h.store.GetConnectedHost(h.room.RoomID)+ if !ok || edge.ParentSessionID != peer.SessionID {+ t.Fatal("subscription did not rebind room-only host route")+ }+ })+ h.closeClient(viewer)+ h.closeClient(host)+ h.locked(func() {+ if rm, _ := h.server.router.rooms.Get(h.room.RoomID); rm != nil && rm.controller != nil {+ t.Fatal("last disconnected voice participant retained idle room resources")+ }+ })+}++func TestVoiceOwnerCanCloseWhileViewerIsDisconnected(t *testing.T) {+ h, host, viewer, _, viewerID := joinedVoiceOwnerRoom(t)+ h.closeClient(viewer)+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool {+ for _, member := range state.Members {+ if member.PeerID == viewerID.PeerID {+ return !member.Connected+ }+ }+ return false+ })+ voiceCommand(host, map[string]any{"action": "leave"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool {+ for _, member := range state.Members {+ if member.PeerID == viewerID.PeerID {+ return !state.Enabled && !member.Joined+ }+ }+ return false+ })+ viewer = openClient(t, h)+ authenticate(t, viewer, h.room, protocol.RoleViewer, "owner_viewer_123456", 1, "", presenceOptions{})+ viewer.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ state := nextVoiceState(t, viewer, nil)+ for _, member := range state.Members {+ if member.PeerID == viewerID.PeerID && (state.Enabled || member.Joined || member.PublicationID != "") {+ t.Fatal("reconnection restored closed room voice")+ }+ }+}++func TestVoiceOwnersOptInPreservesPausedPublication(t *testing.T) {+ h := startHarness(t, harnessOptions{})+ host := openClient(t, h)+ authenticate(t, host, h.room, protocol.RoleHost, "owner_paused_host_123456", -1, "owner_paused_share_123456",+ presenceOptions{sharingPaused: boolPointer(true)})+ host.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, host, nil)+ voiceCommand(host, map[string]any{"action": "join"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool {+ return state.Enabled && len(state.Members) == 1 && state.Members[0].Joined+ })+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ snapshot := rm.controller.Snapshot()+ if !snapshot.RoomMedia || !snapshot.VideoPaused || snapshot.VideoGeneration != "owner_paused_share_123456" {+ t.Fatal("voice opt-in resumed a paused screen publication")+ }+ })+}++func TestVoiceOwnersGrantRevocationRemovesPermanentMember(t *testing.T) {+ h, host, viewer, _, viewerID := joinedVoiceOwnerRoom(t)+ voiceCommand(viewer, map[string]any{"action": "publish"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return len(state.Publications) == 1 })+ h.updateRoomAccess(protocol.RevokeViewerGrantRequest{Action: "revoke-viewer-grant"})+ viewer.next("viewer-grant-revoked")+ expectCloseCode(t, viewer, 4004)+ state := nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Members) == 1 && len(state.Publications) == 0+ })+ if len(state.Connections) != 0 {+ t.Fatal("revoked member retained a voice connection")+ }+ h.locked(func() {+ if _, exists := h.server.voices[h.room.RoomID].members[viewerID.PeerID]; exists {+ t.Fatal("permanently revoked identity retained voice permission")+ }+ })+}++func TestVoiceOwnersStopDropsVideoOnlyCandidateDemand(t *testing.T) {+ h, host, viewer, _, viewerID := joinedVoiceOwnerRoom(t)+ legacy := openClient(t, h)+ legacyID := authenticate(t, legacy, h.room, protocol.RoleViewer, "owner_legacy_123456", 0, "", presenceOptions{})+ host.sendJSON(map[string]any{"type": "start-sharing", "shareGeneration": "owner_share_123456",+ "qualitySettings": protocol.DefaultQualitySettings, "routePolicy": protocol.DefaultRoutePolicy, "sharingPaused": false})+ host.next("sharing-started")+ prepare := nextPreparedRoute(t, viewer)+ viewer.sendJSON(map[string]any{"type": "route-ready", "phase": "prepare", "revision": prepare.Revision})+ nextActiveRouteRevision(t, viewer, prepare.Revision)+ nextPreparedRoute(t, legacy)+ host.sendJSON(map[string]any{"type": "stop-sharing", "shareGeneration": "owner_share_123456"})+ viewer.next("sharing-stopped")+ if !waitFor(t, defaultWait, func() bool {+ settled := false+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ snapshot := rm.controller.Snapshot()+ edge, ok := snapshot.UpstreamByViewer.Get(viewerID.PeerID)+ _, legacyEdge := snapshot.UpstreamByViewer.Get(legacyID.PeerID)+ settled = !rm.pumping && snapshot.Operation == nil && ok && edge.Usable && !edge.VideoReady && !legacyEdge+ })+ return settled+ }) {+ t.Fatal("video-only viewer retained voice candidate demand after share stop")+ }+}diff --git a/internal/server/signal/voice_plan.go b/internal/server/signal/voice_plan.gonew file mode 100644index 00000000..70001783--- /dev/null+++ b/internal/server/signal/voice_plan.go@@ -0,0 +1,250 @@+package signal++import (+ "reflect"+ "sort"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/route"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+)++func (s *Server) syncRoomVoice(roomID string) {+ v := s.voices[roomID]+ if v == nil {+ return+ }+ v.revision+++ s.voiceRoom(roomID)+ for peerID, m := range v.members {+ if sess, _ := s.voiceSession(roomID, peerID); sess == nil {+ m.publicationID = ""+ }+ }+ pubs := make([]protocol.VoicePublication, 0, len(v.members))+ for peerID, m := range v.members {+ if m.publicationID != "" && s.voiceAllowed(roomID, peerID) {+ pubs = append(pubs, protocol.VoicePublication{ID: m.publicationID, PeerID: peerID})+ }+ }+ sort.Slice(pubs, func(i, j int) bool { return pubs[i].ID < pubs[j].ID })+ edges := s.roomVoiceEdges(roomID, v)+ for _, edge := range v.connections {+ if _, keep := edges[edge.logicalID]; !keep {+ s.closeVoiceEdge(roomID, edge)+ }+ }+ v.connections = edges+ unavailable := s.projectVoiceFlows(roomID, v, pubs)+ for _, edge := range edges {+ if edge.transport == "sfu" {+ s.configureVoiceJunction(roomID, edge, pubs)+ }+ }+ members := make([]protocol.VoiceMember, 0, len(v.members))+ ids := make([]string, 0, len(v.members))+ for peerID := range v.members {+ ids = append(ids, peerID)+ }+ sort.Strings(ids)+ for _, peerID := range ids {+ m := v.members[peerID]+ sess, _ := s.voiceSession(roomID, peerID)+ upstream := protocol.NoUpstream()+ for _, edge := range edges {+ if edge.child == peerID && !edge.pending && edge.connected[edge.child] && edge.connected[edge.parent] {+ upstream = protocol.SfuUpstream()+ if edge.transport == "peer" {+ upstream = protocol.PeerUpstream(edge.parent)+ }+ break+ }+ }+ members = append(members, protocol.VoiceMember{PeerID: peerID, Connected: sess != nil,+ Joined: m.joined, Upstream: upstream, PublicationID: m.publicationID})+ }+ var hostID *string+ if v.hostPeerID != "" {+ hostID = &v.hostPeerID+ }+ for _, peerID := range ids {+ sess, _ := s.voiceSession(roomID, peerID)+ if sess == nil {+ continue+ }+ connections := []protocol.VoiceConnection{}+ for _, edge := range edges {+ if peerID != edge.parent && peerID != edge.child {+ continue+ }+ other := edge.parent+ if peerID == edge.parent {+ other = edge.child+ }+ connections = append(connections, protocol.VoiceConnection{ConnectionID: edge.id,+ ParentPeerID: edge.parent, ChildPeerID: edge.child, Transport: edge.transport,+ Pending: edge.pending, Revision: protocol.Int(edge.revision),+ Send: append([]string{}, edge.send[peerID]...), Receive: append([]string{}, edge.send[other]...)})+ }+ sort.Slice(connections, func(i, j int) bool { return connections[i].ConnectionID < connections[j].ConnectionID })+ s.send(sess, protocol.RoomVoiceStateMessage{Type: "room-voice-state", Revision: protocol.Int(v.revision), Enabled: v.enabled(),+ HostPeerID: hostID, Members: members, Publications: pubs, Connections: connections,+ Unavailable: append([]string{}, unavailable[peerID]...)})+ }+}++func (s *Server) roomVoiceEdges(roomID string, v *roomVoice) map[string]*voiceEdge {+ next := make(map[string]*voiceEdge)+ rm, _ := s.router.rooms.Get(roomID)+ if rm == nil || rm.controller == nil || !rm.roomMedia {+ return next+ }+ snapshot := rm.controller.Snapshot()+ add := func(logical, parent, child, transport string, pending bool, revision int64) {+ if !s.voiceAllowed(roomID, child) || parent != "" && !s.voiceAllowed(roomID, parent) {+ return+ }+ childSession, _ := s.voiceSession(roomID, child)+ parentID := ""+ if parent != "" {+ parentSession, _ := s.voiceSession(roomID, parent)+ parentID = parentSession.sessionID+ }+ edge := v.connections[logical]+ if edge != nil && (edge.parentSession != parentID || edge.childSession != childSession.sessionID) {+ s.closeVoiceEdge(roomID, edge)+ edge = nil+ }+ if edge == nil {+ edge = &voiceEdge{id: opaqueID(), logicalID: logical, parent: parent, child: child,+ transport: transport, parentSession: parentID, childSession: childSession.sessionID, connected: make(map[string]bool)}+ }+ edge.pending, edge.revision = pending, revision+ edge.send = map[string][]string{parent: {}, child: {}}+ next[logical] = edge+ }+ if publication := snapshot.HostPublication; publication != nil && publication.PhysicalActive {+ add(publication.Generation, "", rm.hostPeerID, "sfu", false, snapshot.Revision)+ }+ for child, edge := range snapshot.UpstreamByViewer.All() {+ if !edge.PhysicalActive {+ continue+ }+ parent, transport := edge.ParentPeerID, "peer"+ if edge.Kind == route.UpstreamSfu {+ parent, transport = "", "sfu"+ }+ add(edge.ConnectionID, parent, child, transport, false, snapshot.Revision)+ }+ if op := snapshot.Operation; op != nil && op.Current != nil && op.AttachConnectionID == "" {+ parent, transport := op.Current.Tuple.ParentPeerID, "peer"+ if op.Current.Tuple.Kind == route.UpstreamSfu {+ parent, transport = "", "sfu"+ if prepared := rm.pendingMedia; prepared != nil && prepared.connectionID == op.Current.ConnectionID &&+ prepared.publicationConnectionID != "" {+ add(prepared.publicationGeneration, "", rm.hostPeerID, "sfu", true, op.Current.Revision)+ }+ }+ add(op.Current.ConnectionID, parent, op.ChildPeerID, transport, true, op.Current.Revision)+ }+ return next+}++// Every publication takes the unique path in the committed room tree. A relay+// outside voice is not a permissible decoded-audio hop.+func (s *Server) projectVoiceFlows(roomID string, v *roomVoice, pubs []protocol.VoicePublication) map[string][]string {+ type hop struct {+ from, to string+ edge *voiceEdge+ }+ adjacent := make(map[string][]hop)+ for _, edge := range v.connections {+ if edge.pending {+ continue+ }+ adjacent[edge.parent] = append(adjacent[edge.parent], hop{edge.parent, edge.child, edge})+ adjacent[edge.child] = append(adjacent[edge.child], hop{edge.child, edge.parent, edge})+ }+ unavailable := make(map[string][]string)+ for _, pub := range pubs {+ paths := map[string][]hop{pub.PeerID: {}}+ queue := []string{pub.PeerID}+ for len(queue) > 0 {+ from := queue[0]+ queue = queue[1:]+ for _, step := range adjacent[from] {+ if _, seen := paths[step.to]; seen {+ continue+ }+ paths[step.to] = append(append([]hop{}, paths[from]...), step)+ queue = append(queue, step.to)+ }+ }+ used := make(map[string]bool)+ for peerID := range v.members {+ if peerID == pub.PeerID || !s.voiceAllowed(roomID, peerID) {+ continue+ }+ path, found := paths[peerID]+ if !found {+ unavailable[peerID] = append(unavailable[peerID], pub.ID)+ continue+ }+ for _, step := range path {+ if !used[step.edge.id] {+ step.edge.send[step.from] = append(step.edge.send[step.from], pub.ID)+ used[step.edge.id] = true+ }+ }+ }+ }+ return unavailable+}++func (s *Server) voiceRuntime() sfu.VoiceRuntime {+ if s.sfuFallback == nil {+ return nil+ }+ runtime, _ := s.sfuFallback.Media.(sfu.VoiceRuntime)+ return runtime+}++func (s *Server) configureVoiceJunction(roomID string, edge *voiceEdge, pubs []protocol.VoicePublication) {+ runtime := s.voiceRuntime()+ if runtime == nil {+ return+ }+ plan := sfu.VoiceConnectionPlan{RoomID: roomID, PeerID: edge.child, SessionID: edge.childSession, ConnectionID: edge.id,+ Publish: []sfu.VoicePublication{}, Subscribe: []sfu.VoicePublication{}}+ for _, pub := range pubs {+ item := sfu.VoicePublication{ID: pub.ID, PeerID: pub.PeerID}+ for _, id := range edge.send[edge.child] {+ if id == pub.ID {+ plan.Publish = append(plan.Publish, item)+ }+ }+ for _, id := range edge.send[""] {+ if id == pub.ID {+ plan.Subscribe = append(plan.Subscribe, item)+ }+ }+ }+ if edge.sfuPlan != nil && reflect.DeepEqual(*edge.sfuPlan, plan) {+ return+ }+ edge.sfuPlan = &plan+ if err := runtime.ConfigureVoice(plan, s.onVoiceMediaEvent); err != nil {+ edge.sfuPlan = nil+ if sess, _ := s.voiceSession(roomID, edge.child); sess != nil {+ s.voiceError(sess, "connection-unavailable")+ }+ }+}++func (s *Server) closeVoiceEdge(roomID string, edge *voiceEdge) {+ if edge.transport == "sfu" {+ if runtime := s.voiceRuntime(); runtime != nil {+ _ = runtime.CloseVoice(roomID, edge.child, edge.childSession, edge.id)+ }+ }+}diff --git a/internal/server/signal/voice_policy_test.go b/internal/server/signal/voice_policy_test.gonew file mode 100644index 00000000..5132ebba--- /dev/null+++ b/internal/server/signal/voice_policy_test.go@@ -0,0 +1,75 @@+package signal++import (+ "testing"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/route"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu/sfutest"+)++func TestRoomVoicePolicyFollowsNewShareOnStartAndHostAuthentication(t *testing.T) {+ for _, transition := range []string{"start", "authenticate"} {+ t.Run(transition, func(t *testing.T) {+ h := startHarness(t, harnessOptions{+ sfu: &SfuFallback{Media: sfutest.New(), Admission: sfu.NewAdmission(sfu.AdmissionOptions{+ IngressCapacity: 1, EgressCapacity: 2,+ })},+ })+ host, viewer := openClient(t, h), openClient(t, h)+ authenticate(t, host, h.room, protocol.RoleHost, "policy_owner_host_123456", -1, "",+ presenceOptions{roomSession: true, roomOnly: true})+ preference := protocol.ViewerRouteSfu+ viewerID := authenticate(t, viewer, h.room, protocol.RoleViewer, "policy_owner_viewer_123456", 0, "",+ presenceOptions{routePreference: &preference})+ host.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, host, nil)+ voiceCommand(host, map[string]any{"action": "join"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Members) == 1 && state.Members[0].Joined+ })+ var previous *route.Controller+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ previous = rm.controller+ if !previous.AllowsViewerRoutePreference(protocol.ViewerRouteSfu) {+ t.Fatal("voice room did not begin with available SFU")+ }+ })+ policy := protocol.RoutePolicy{PeerOnly: true}+ if transition == "start" {+ host.sendJSON(map[string]any{"type": "start-sharing", "shareGeneration": "policy_share_123456",+ "qualitySettings": protocol.DefaultQualitySettings, "routePolicy": policy, "sharingPaused": false})+ host.next("sharing-started")+ } else {+ replacement := openClient(t, h)+ authenticate(t, replacement, h.room, protocol.RoleHost, "policy_owner_host_123456", -1, "policy_share_123456",+ presenceOptions{roomSession: true, routePolicy: &policy})+ }+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ if rm.controller != previous || rm.controller.AllowsViewerRoutePreference(protocol.ViewerRouteSfu) {+ t.Fatal("new share failed to update policy on retained room controller")+ }+ settings, _ := rm.viewerSettings.Get(viewerID.PeerID)+ if settings.preference != protocol.ViewerRouteAuto {+ t.Fatal("new peer-only policy retained incompatible Viewer SFU preference")+ }+ })+ for {+ message, err := protocol.DecodeServerMessage(viewer.next("viewer-route-preference").raw)+ if err != nil {+ t.Fatal(err)+ }+ if message.(protocol.ViewerRoutePreferenceMessage).Preference == protocol.ViewerRouteAuto {+ break+ }+ }+ prepared := nextPreparedRoute(t, viewer)+ if prepared.Candidate.Transport != "direct" {+ t.Fatal("peer-only publication prepared SFU video")+ }+ })+ }+}diff --git a/internal/server/signal/voice_signal.go b/internal/server/signal/voice_signal.gonew file mode 100644index 00000000..31f9e71c--- /dev/null+++ b/internal/server/signal/voice_signal.go@@ -0,0 +1,266 @@+package signal++import (+ "encoding/json"+ "slices"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/route"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+ "github.com/pion/webrtc/v4"+)++func (s *Server) voiceRouteFailed(roomID, peerID string) {+ if sess, _ := s.voiceSession(roomID, peerID); sess != nil {+ s.voiceError(sess, "connection-unavailable")+ }+}++func (s *Server) voiceConnection(roomID, peerID, sessionID, id string) *voiceEdge {+ v := s.voices[roomID]+ if v == nil {+ return nil+ }+ for _, edge := range v.connections {+ if edge.id == id && (edge.parent == peerID && edge.parentSession == sessionID ||+ edge.child == peerID && edge.childSession == sessionID) {+ return edge+ }+ }+ return nil+}++func (s *Server) handleRoomVoiceSignal(sess *session, auth *authenticatedSession, message protocol.RoomVoiceSignalMessage) {+ if !sess.roomVoice {+ return+ }+ edge := s.voiceConnection(auth.roomID, auth.peerID, sess.sessionID, message.ConnectionID)+ if edge == nil || !s.voiceAllowed(auth.roomID, auth.peerID) {+ return+ }+ if edge.transport == "sfu" {+ runtime := s.voiceRuntime()+ if runtime == nil {+ return+ }+ var incoming sfu.VoiceSignal+ encoded, err := json.Marshal(message)+ if err == nil {+ err = json.Unmarshal(encoded, &incoming)+ }+ if err == nil {+ err = runtime.SignalVoice(auth.roomID, auth.peerID, sess.sessionID, edge.id, incoming)+ }+ if err != nil {+ s.voiceError(sess, "connection-unavailable")+ }+ return+ }+ other := edge.parent+ if auth.peerID == edge.parent {+ other = edge.child+ }+ target, _ := s.voiceSession(auth.roomID, other)+ if target == nil {+ return+ }+ if description := message.Description; description != nil {+ if (description.SDP.Type == "offer") != (auth.peerID == edge.parent) {+ return+ }+ seen := make(map[string]bool)+ tracks := make([]protocol.VoiceTrack, 0, len(description.Tracks))+ for _, track := range description.Tracks {+ if seen[track.MID] || seen[track.PublicationID] {+ s.voiceError(sess, "not-allowed")+ return+ }+ seen[track.MID], seen[track.PublicationID] = true, true+ if slices.Contains(edge.send[auth.peerID], track.PublicationID) {+ tracks = append(tracks, track)+ }+ }+ // Leaving voice can overtake an offer already in flight. Finish+ // its SDP transaction without reviving a retired publication binding.+ pruned := *description+ pruned.Tracks = tracks+ message.Description = &pruned+ }+ if message.Renegotiate && auth.peerID != edge.child {+ return+ }+ s.send(target, message)+}++func (s *Server) onVoiceMediaEvent(event sfu.VoiceMediaEvent) {+ s.mu.Lock()+ defer s.mu.Unlock()+ if s.closing {+ return+ }+ edge := s.voiceConnection(event.RoomID, event.PeerID, event.SessionID, event.ConnectionID)+ if edge == nil || edge.transport != "sfu" {+ return+ }+ sess, _ := s.voiceSession(event.RoomID, event.PeerID)+ if sess == nil {+ return+ }+ if event.Description != nil || event.Candidate != nil {+ message := protocol.RoomVoiceSignalMessage{Type: "room-voice-signal", ConnectionID: edge.id}+ encoded, err := json.Marshal(sfu.VoiceSignal{Description: event.Description, Candidate: event.Candidate})+ if err == nil {+ err = json.Unmarshal(encoded, &message)+ }+ if err == nil {+ s.send(sess, message)+ }+ }+ if event.State == webrtc.PeerConnectionStateConnected {+ edge.connected[""] = true+ s.commitVoiceCandidate(event.RoomID)+ s.syncRoomVoice(event.RoomID)+ }+ if event.State == webrtc.PeerConnectionStateFailed {+ s.failVoiceConnection(event.RoomID, edge)+ }+}++func (s *Server) handleRoomVoiceTransport(sess *session, auth *authenticatedSession, message protocol.RoomVoiceTransportMessage) {+ if !sess.roomVoice {+ return+ }+ edge := s.voiceConnection(auth.roomID, auth.peerID, sess.sessionID, message.ConnectionID)+ if edge == nil {+ return+ }+ if message.State == "failed" {+ s.failVoiceConnection(auth.roomID, edge)+ return+ }+ edge.connected[auth.peerID] = true+ s.commitVoiceCandidate(auth.roomID)+ s.syncRoomVoice(auth.roomID)+}++func (s *Server) commitVoiceCandidate(roomID string) {+ rm, _ := s.router.rooms.Get(roomID)+ if rm == nil || rm.controller == nil || !rm.roomMedia {+ return+ }+ op := rm.controller.Operation()+ if op == nil || op.Current == nil || op.AttachConnectionID != "" {+ return+ }+ v := s.voices[roomID]+ if v == nil {+ return+ }+ edge := v.connections[op.Current.ConnectionID]+ if edge == nil || !s.voiceCandidateReady(roomID, op.Current.ConnectionID) {+ return+ }+ if op.VideoGeneration != "" {+ if prepared := rm.pendingMedia; prepared != nil && prepared.connectionID == op.Current.ConnectionID && prepared.videoReady != nil {+ if child, ok := s.store.GetConnectedViewer(roomID, op.ChildPeerID); ok && child.SessionID == op.ChildSessionID {+ s.router.handleRouteReady(authenticatedRouteParticipant{roomID: roomID, role: protocol.RoleViewer, peerID: child.PeerID, sessionID: child.SessionID}, *prepared.videoReady)+ }+ }+ return+ }+ guard := route.CandidateGuard{ChildPeerID: op.ChildPeerID, ChildSessionID: op.ChildSessionID,+ Revision: op.Current.Revision, ConnectionID: op.Current.ConnectionID}+ progress := rm.controller.CandidateTransportConnected(guard, s.now())+ s.router.releaseResources(progress.Released)+ if !progress.Accepted {+ return+ }+ settled := rm.controller.CandidateReady(guard, s.now(), s.router.commitReservation, route.CandidateProof{})+ s.router.releaseResources(settled.Released)+ if settled.Accepted {+ s.router.broadcastActive(roomID, rm)+ s.router.requestPump(roomID)+ }+}++func (s *Server) voiceCandidateReady(roomID, connectionID string) bool {+ v := s.voices[roomID]+ if v == nil {+ return true+ }+ edge := v.connections[connectionID]+ if edge == nil {+ return true+ }+ if !edge.connected[edge.parent] || !edge.connected[edge.child] {+ return false+ }+ if edge.transport != "sfu" {+ return true+ }+ rm, _ := s.router.rooms.Get(roomID)+ if rm == nil || rm.controller == nil {+ return false+ }+ if op := rm.controller.Operation(); op != nil && op.Current != nil && op.Current.ConnectionID == connectionID && op.Current.Tuple.Publication != route.PublicationReuse {+ if prepared := rm.pendingMedia; prepared != nil && prepared.connectionID == connectionID {+ if root := v.connections[prepared.publicationGeneration]; root != nil {+ return root.connected[""] && root.connected[root.child]+ }+ return !s.voiceAllowed(roomID, rm.hostPeerID)+ }+ return false+ }+ return true+}++func (s *Server) failVoiceConnection(roomID string, edge *voiceEdge) {+ rm, _ := s.router.rooms.Get(roomID)+ if rm == nil || rm.controller == nil {+ return+ }+ op := rm.controller.Operation()+ if edge.pending && op != nil && op.Current != nil {+ guard := route.CandidateGuard{ChildPeerID: op.ChildPeerID, ChildSessionID: op.ChildSessionID,+ Revision: op.Current.Revision, ConnectionID: op.Current.ConnectionID}+ failed := rm.controller.CandidateFailed(guard, s.now())+ s.router.releaseResources(failed.Released)+ s.router.broadcastActive(roomID, rm)+ s.router.requestPump(roomID)+ return+ }+ edge.connected[edge.child], edge.connected[edge.parent] = false, false+ snapshot := rm.controller.Snapshot()+ // A companion audio connection is not evidence that the committed picture+ // path failed. Recreate that physical facet on the proven route; only the+ // route owner may replace neighbours or retire the picture connection.+ for child, current := range snapshot.UpstreamByViewer.All() {+ if !current.Usable || !current.PhysicalActive || !current.VideoReady ||+ snapshot.VideoGeneration == "" || current.VideoGeneration != snapshot.VideoGeneration {+ continue+ }+ childFacet := child == edge.child && current.ConnectionID == edge.logicalID+ rootFacet := edge.child == rm.hostPeerID && edge.transport == "sfu" &&+ current.Kind == route.UpstreamSfu && current.PublicationGeneration == edge.logicalID+ if childFacet || rootFacet {+ s.closeVoiceEdge(roomID, edge)+ delete(s.voices[roomID].connections, edge.logicalID)+ s.syncRoomVoice(roomID)+ return+ }+ }+ if current, ok := snapshot.UpstreamByViewer.Get(edge.child); ok && current.ConnectionID == edge.logicalID {+ rm.controller.InvalidateEdge(route.EdgeGuard{ChildPeerID: edge.child, ChildSessionID: current.ChildSessionID,+ ParentSessionID: current.ParentSessionID, RouteRevision: snapshot.Revision, ConnectionID: current.ConnectionID}, s.router.nowPtr())+ s.router.requestPump(roomID)+ } else if publication := snapshot.HostPublication; publication != nil && edge.transport == "sfu" && edge.child == rm.hostPeerID && edge.logicalID == publication.Generation {+ rm.controller.InvalidateHostPublication(route.PublicationGuard{HostSessionID: publication.HostSessionID, RouteRevision: snapshot.Revision,+ Generation: publication.Generation, ConnectionID: publication.ConnectionID}, s.router.nowPtr())+ s.router.requestPump(roomID)+ }+ for _, peerID := range []string{edge.parent, edge.child} {+ if sess, _ := s.voiceSession(roomID, peerID); sess != nil {+ s.voiceError(sess, "connection-unavailable")+ }+ }+}diff --git a/internal/server/signal/voice_test.go b/internal/server/signal/voice_test.gonew file mode 100644index 00000000..67ec7d3d--- /dev/null+++ b/internal/server/signal/voice_test.go@@ -0,0 +1,238 @@+package signal++import (+ "testing"+ "time"++ "github.com/TNTcraftHIM/Piik/internal/server/protocol"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu"+ "github.com/TNTcraftHIM/Piik/internal/server/sfu/sfutest"+)++func nextVoiceState(t *testing.T, client *testClient, matches func(protocol.RoomVoiceStateMessage) bool) protocol.RoomVoiceStateMessage {+ t.Helper()+ for {+ message, err := protocol.DecodeServerMessage(client.next("room-voice-state").raw)+ if err != nil {+ t.Fatal(err)+ }+ state := message.(protocol.RoomVoiceStateMessage)+ if matches == nil || matches(state) {+ return state+ }+ }+}++func TestVoiceOnlySfuPreparesWithoutVideoPublication(t *testing.T) {+ h := startHarness(t, harnessOptions{sfuOnly: true, endpointMediaCopyCapacity: 1,+ sfu: &SfuFallback{Media: sfutest.New(), Admission: sfu.NewAdmission(sfu.AdmissionOptions{IngressCapacity: 1, EgressCapacity: 2})}})+ host, viewer := openClient(t, h), openClient(t, h)+ authenticate(t, host, h.room, protocol.RoleHost, "voice_sfu_host_123", -1, "", presenceOptions{roomSession: true, roomOnly: true})+ authenticate(t, viewer, h.room, protocol.RoleViewer, "voice_sfu_viewer_123", 1, "", presenceOptions{})+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, client, nil)+ }+ voiceCommand(host, map[string]any{"action": "join"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return state.Enabled })+ voiceCommand(viewer, map[string]any{"action": "join"})+ state := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool { return len(state.Connections) > 0 })+ if len(state.Connections) != 1 || state.Connections[0].Transport != "sfu" || !state.Connections[0].Pending {+ t.Fatalf("invalid SFU preparation: %+v", state.Connections)+ }+}++func voiceCommand(client *testClient, command map[string]any) {+ client.sendJSON(map[string]any{"type": "room-voice-command", "command": command})+}++func TestVoiceOnlyRouteFailureDoesNotChangeVideoStatus(t *testing.T) {+ h, _, viewer, _, viewerID := joinedVoiceOwnerRoom(t)+ h.locked(func() {+ for _, state := range []string{"waiting", "failed"} {+ h.server.router.sendViewerRouteStatus(h.room.RoomID, viewerID.PeerID,+ protocol.RouteStatusMessage{Type: "route-status", Revision: 1, State: state, Reason: "route-exhausted"})+ }+ })+ viewer.next("room-voice-error")+ if _, ok := viewer.tryNext("route-status", 30*time.Millisecond); ok {+ t.Fatal("voice-only routing changed video status")+ }+}++func TestRoomCandidateWaitsForBothPictureAndVoice(t *testing.T) {+ for _, pictureFirst := range []bool{true, false} {+ name := "voice-first"+ if pictureFirst {+ name = "picture-first"+ }+ t.Run(name, func(t *testing.T) {+ h := startHarness(t, harnessOptions{})+ host, viewer := openClient(t, h), openClient(t, h)+ authenticate(t, host, h.room, protocol.RoleHost, "composite_host_123456", -1, "", presenceOptions{roomSession: true, roomOnly: true})+ host.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, host, nil)+ voiceCommand(host, map[string]any{"action": "join"})+ host.sendJSON(map[string]any{"type": "start-sharing", "shareGeneration": "composite_video_123456",+ "qualitySettings": protocol.DefaultQualitySettings, "routePolicy": protocol.DefaultRoutePolicy, "sharingPaused": false})+ host.next("sharing-started")+ authenticate(t, viewer, h.room, protocol.RoleViewer, "composite_viewer_123456", 1, "", presenceOptions{})+ viewer.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ voiceCommand(viewer, map[string]any{"action": "join"})+ pending := nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && state.Connections[0].Pending+ })+ voice := pending.Connections[0]+ for prepared := nextPreparedRoute(t, viewer); prepared.Revision != int64(voice.Revision); prepared = nextPreparedRoute(t, viewer) {+ }+ picture := func() {+ viewer.sendJSON(map[string]any{"type": "route-ready", "phase": "prepare", "revision": voice.Revision})+ }+ audio := func() {+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": voice.ConnectionID, "state": "connected"})+ }+ }+ barriers := []*testClient{viewer}+ if pictureFirst {+ picture()+ } else {+ audio()+ barriers = append(barriers, host)+ }+ for _, client := range barriers {+ client.sendJSON(map[string]any{"type": "signaling-challenge", "sequence": 1})+ client.next("signaling-challenge-response")+ }+ h.locked(func() {+ rm, _ := h.server.router.rooms.Get(h.room.RoomID)+ if op := rm.controller.Operation(); op == nil || op.Current == nil || protocol.Int(op.Current.Revision) != voice.Revision {+ t.Fatal("only one media facet committed the room route")+ }+ })+ if pictureFirst {+ audio()+ } else {+ picture()+ }+ nextActiveRouteRevision(t, viewer, int64(voice.Revision))+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ return len(state.Connections) == 1 && !state.Connections[0].Pending+ })+ })+ }+}++func TestRoomVoiceUsesNormalRoomAuthorityAndKeepsGraphAcrossVideo(t *testing.T) {+ h := startHarness(t, harnessOptions{})+ host, viewer, old := openClient(t, h), openClient(t, h), openClient(t, h)+ hostID := authenticate(t, host, h.room, protocol.RoleHost, "voice_host_123456", -1, "", presenceOptions{roomSession: true, roomOnly: true})+ viewerID := authenticate(t, viewer, h.room, protocol.RoleViewer, "voice_viewer_123456", 1, "", presenceOptions{})+ authenticate(t, old, h.room, protocol.RoleViewer, "voice_old_page_123456", 1, "", presenceOptions{})+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "subscribe-room-voice"})+ nextVoiceState(t, client, nil)+ }+ voiceCommand(viewer, map[string]any{"action": "join"})+ viewer.next("room-voice-error")+ voiceCommand(viewer, map[string]any{"action": "publish"})+ viewer.next("room-voice-error")+ voiceCommand(host, map[string]any{"action": "join"})+ nextVoiceState(t, host, func(state protocol.RoomVoiceStateMessage) bool { return state.Enabled })+ voiceCommand(viewer, map[string]any{"action": "join"})+ pending := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Connections) == 1 && s.Connections[0].Pending+ })+ voiceID := pending.Connections[0].ConnectionID+ for _, client := range []*testClient{host, viewer} {+ client.sendJSON(map[string]any{"type": "room-voice-transport", "connectionId": voiceID, "state": "connected"})+ }+ active := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Connections) == 1 && !s.Connections[0].Pending+ })+ if active.Connections[0].ConnectionID != voiceID {+ t.Fatal("voice commit replaced the physical transport")+ }+ voiceCommand(host, map[string]any{"action": "publish"})+ publication := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Publications) == 1 && len(s.Connections[0].Receive) == 1+ })+ pubID := publication.Publications[0].ID+ if publication.Publications[0].PeerID != hostID.PeerID {+ t.Fatal("publication sender was not authenticated")+ }+ voiceCommand(viewer, map[string]any{"action": "publish"})+ nextVoiceState(t, host, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Publications) == 2 && len(s.Connections[0].Receive) == 1+ })+ viewerPub := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool { return len(s.Publications) == 2 })+ for _, pub := range viewerPub.Publications {+ if pub.PeerID == viewerID.PeerID {+ voiceCommand(viewer, map[string]any{"action": "unpublish", "publicationId": pub.ID})+ }+ }+ nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Publications) == 1 && s.Publications[0].ID == pubID+ })+ if _, ok := old.tryNext("room-voice-state", 30*time.Millisecond); ok {+ t.Fatal("voice sent to a page without capability opt-in")+ }++ h.server.mu.Lock()+ runtime, _ := h.server.router.rooms.Get(h.room.RoomID)+ logical := runtime.controller.Snapshot().UpstreamByViewer.Values()[0].ConnectionID+ h.server.mu.Unlock()+ host.sendJSON(map[string]any{"type": "start-sharing", "shareGeneration": "voice_video_generation_1",+ "qualitySettings": protocol.DefaultQualitySettings, "routePolicy": protocol.DefaultRoutePolicy, "sharingPaused": false})+ host.next("sharing-started")+ prepare := nextPreparedRoute(t, viewer)+ if prepare.Candidate.ConnectionID == logical {+ t.Fatal("video attachment reused room transport identity")+ }+ viewer.sendJSON(map[string]any{"type": "route-ready", "phase": "prepare", "revision": prepare.Revision})+ nextActiveRouteRevision(t, viewer, prepare.Revision)+ h.server.mu.Lock()+ edge, _ := runtime.controller.Snapshot().UpstreamByViewer.Get(viewerID.PeerID)+ h.server.mu.Unlock()+ if !edge.VideoReady || edge.ConnectionID != logical || edge.VideoConnectionID != prepare.Candidate.ConnectionID {+ t.Fatal("video did not attach to retained room edge")+ }+ host.sendJSON(map[string]any{"type": "stop-sharing", "shareGeneration": "voice_video_generation_1"})+ viewer.next("sharing-stopped")+ state := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Publications) == 1 && len(s.Connections) == 1 && !s.Connections[0].Pending+ })+ if state.Connections[0].ConnectionID != voiceID || state.Publications[0].ID != pubID {+ t.Fatal("video stop retired room voice")+ }+ h.server.mu.Lock()+ edge, _ = runtime.controller.Snapshot().UpstreamByViewer.Get(viewerID.PeerID)+ h.server.mu.Unlock()+ if edge.VideoReady || edge.ConnectionID != logical || !edge.Usable {+ t.Fatal("video stop corrupted room graph")+ }+ // A late stop for a former source cannot retire a replacement microphone.+ voiceCommand(host, map[string]any{"action": "unpublish", "publicationId": pubID})+ nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool { return len(s.Publications) == 0 })+ voiceCommand(host, map[string]any{"action": "publish"})+ newState := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool { return len(s.Publications) == 1 })+ voiceCommand(host, map[string]any{"action": "unpublish", "publicationId": pubID})+ last := nextVoiceState(t, viewer, func(s protocol.RoomVoiceStateMessage) bool {+ return len(s.Publications) == 1 && s.Publications[0].ID == newState.Publications[0].ID+ })+ if last.Publications[0].ID == pubID {+ t.Fatal("publication identity was reused")+ }+ voiceCommand(viewer, map[string]any{"action": "leave"})+ nextVoiceState(t, viewer, func(state protocol.RoomVoiceStateMessage) bool {+ for _, member := range state.Members {+ if member.PeerID == viewerID.PeerID {+ return !member.Joined+ }+ }+ return false+ })++ viewer.sendJSON(map[string]any{"type": "signaling-challenge", "sequence": 42})+ viewer.next("signaling-challenge-response")+}diff --git a/internal/thirdparty/README.md b/internal/thirdparty/README.mdindex 46f43cd6..56413add 100644--- a/internal/thirdparty/README.md+++ b/internal/thirdparty/README.md@@ -47,6 +47,10 @@ advances in send order with a receive-time watermark, while older ACKs repaircounts without rewinding it. Reset reseeds that delay baseline without discardingdelivery history. Piik's sharedforwarding package uses this copy for both individual transports and publications.+Delay inference tolerates ordinary clock-rate skew using RFC 6817 A.2's+500 ppm virtual-sender-clock allowance; packet timestamps, acknowledged traffic+and loss remain unadjusted. Long, lossless TWCC controls and real queue/loss+recovery controls fence this measurement repair.Its regression checks use real TWCC feedback and retain the no-feedback andidle-before-probe controls. The[media research owner](../../docs/research/node-local-media-design.md#send-queue-recovery)diff --git a/internal/thirdparty/livekit/sendsidebwe/clock_skew_test.go b/internal/thirdparty/livekit/sendsidebwe/clock_skew_test.gonew file mode 100644index 00000000..0c2f987e--- /dev/null+++ b/internal/thirdparty/livekit/sendsidebwe/clock_skew_test.go@@ -0,0 +1,79 @@+package sendsidebwe++import (+ "fmt"+ "testing"++ "github.com/livekit/livekit-server/pkg/sfu/bwe"+ "github.com/livekit/livekit-server/pkg/sfu/ccutils"+ "github.com/livekit/protocol/logger"+ "github.com/livekit/protocol/utils/mono"+ "github.com/pion/interceptor/pkg/twcc"+ "github.com/pion/rtcp"+)++func TestClockRateSkewDoesNotAccumulateCongestion(t *testing.T) {+ for _, ppm := range []int64{0, 67, -67, 200, -200, 400} {+ t.Run(fmt.Sprintf("%dppm", ppm), func(t *testing.T) {+ c := newCongestionDetector(congestionDetectorParams{Config: defaultCongestionDetectorConfig, Logger: logger.GetDiscardLogger()})+ c.estimatedAvailableChannelCapacity = 8_000_000+ start := mono.UnixMicro()+ c.RecordPacketSendAndGetSequenceNumber(start, 1200, false, ccutils.ProbeClusterIdInvalid, false)+ recorder := twcc.NewRecorder(1)+ for elapsed := int64(1500); elapsed <= 1_800_000_000; elapsed += 1500 {+ sn := c.RecordPacketSendAndGetSequenceNumber(start+elapsed, 1200, false, ccutils.ProbeClusterIdInvalid, false)+ recorder.Record(1, sn, 1_000_000+elapsed+elapsed*ppm/1_000_000)+ if elapsed%150_000 != 0 {+ continue+ }+ for _, packet := range recorder.BuildFeedbackPacket() {+ c.HandleTWCCFeedback(packet.(*rtcp.TransportLayerCC))+ }+ if c.CongestionState() != bwe.CongestionStateNone {+ t.Fatalf("clock skew became congestion after %.2fs", float64(elapsed)/1e6)+ }+ }+ if !c.CanProbe() || c.estimatedAvailableChannelCapacity != 8_000_000 {+ t.Fatalf("healthy transport lost recovery: probe=%v capacity=%d", c.CanProbe(), c.estimatedAvailableChannelCapacity)+ }+ last := c.packetGroups[len(c.packetGroups)-1]+ t.Logf("30-minute delay=%dus acknowledged=%dbps", last.PropagatedQueuingDelay(), last.Traffic().AcknowledgedBitrate())+ })+ }+}++func TestClockTolerancePreservesCongestionAndRecovery(t *testing.T) {+ c := newCongestionDetector(congestionDetectorParams{Config: defaultCongestionDetectorConfig, Logger: logger.GetDiscardLogger()})+ c.estimatedAvailableChannelCapacity = 8_000_000+ start := mono.UnixMicro()+ c.RecordPacketSendAndGetSequenceNumber(start, 1200, false, ccutils.ProbeClusterIdInvalid, false)+ recorder := twcc.NewRecorder(1)+ queueDetected, lossDetected := false, false+ for elapsed := int64(1500); elapsed <= 30_000_000; elapsed += 1500 {+ sn := c.RecordPacketSendAndGetSequenceNumber(start+elapsed, 1200, false, ccutils.ProbeClusterIdInvalid, false)+ queue := int64(0)+ if elapsed >= 8_000_000 && elapsed < 11_000_000 {+ queue = (elapsed - 8_000_000) / 25 // a real queue growing by 40ms/s+ }+ loss := elapsed >= 18_000_000 && elapsed < 20_000_000+ if !loss || (elapsed/1500)%2 == 0 {+ recorder.Record(1, sn, 1_000_000+elapsed+elapsed*67/1_000_000+queue)+ }+ if elapsed%150_000 != 0 {+ continue+ }+ for _, packet := range recorder.BuildFeedbackPacket() {+ c.HandleTWCCFeedback(packet.(*rtcp.TransportLayerCC))+ }+ if c.CongestionState() == bwe.CongestionStateCongested {+ queueDetected = queueDetected || elapsed >= 8_000_000 && elapsed < 11_000_000+ lossDetected = lossDetected || loss+ }+ if (elapsed >= 12_000_000 && elapsed < 18_000_000 || elapsed >= 22_000_000) && !c.CanProbe() {+ t.Fatalf("cleared congestion still blocked probing at %.2fs: %v", float64(elapsed)/1e6, c.CongestionState())+ }+ }+ if !queueDetected || !lossDetected || c.estimatedAvailableChannelCapacity >= 8_000_000 {+ t.Fatalf("real congestion was hidden: queue=%v loss=%v capacity=%d", queueDetected, lossDetected, c.estimatedAvailableChannelCapacity)+ }+}diff --git a/internal/thirdparty/livekit/sendsidebwe/congestion_detector_test.go b/internal/thirdparty/livekit/sendsidebwe/congestion_detector_test.goindex 6ed2e628..c630b187 100644--- a/internal/thirdparty/livekit/sendsidebwe/congestion_detector_test.go+++ b/internal/thirdparty/livekit/sendsidebwe/congestion_detector_test.go@@ -50,8 +50,8 @@ func TestHandleTWCCFeedbackReorderingDrainsQueue(t *testing.T) {recorder.Record(1, sns[0], 1_100_000)recorder.Record(1, sns[1], 1_210_000)report(recorder.BuildFeedbackPacket())- if got := c.packetGroups[len(c.packetGroups)-1].PropagatedQueuingDelay(); got != 100_000 {- t.Fatalf("fixture queue = %d, want 100000", got)+ if got := c.packetGroups[len(c.packetGroups)-1].PropagatedQueuingDelay(); got < 99_000 || got > 100_000 {+ t.Fatalf("fixture queue = %d, want approximately 100ms", got)}c.congestionState = bwe.CongestionStateCongestedwantDelay, wantState := int64(0), bwe.CongestionStateNone@@ -65,7 +65,12 @@ func TestHandleTWCCFeedbackReorderingDrainsQueue(t *testing.T) {}}last := c.packetGroups[len(c.packetGroups)-1]- if delay := last.PropagatedQueuingDelay(); delay != wantDelay || c.CongestionState() != wantState {+ delay := last.PropagatedQueuingDelay()+ validDelay := delay == 0+ if sustained {+ validDelay = delay >= 90_000 && delay <= wantDelay+ }+ if !validDelay || c.CongestionState() != wantState {t.Fatalf("incorrect queue recovery: delay=%v state=%v, want %v/%v", time.Duration(delay)*time.Microsecond, c.CongestionState(), time.Duration(wantDelay)*time.Microsecond, wantState)}if rate := last.Traffic().AcknowledgedBitrate(); rate != 960_000 {diff --git a/internal/thirdparty/livekit/sendsidebwe/packet_group.go b/internal/thirdparty/livekit/sendsidebwe/packet_group.goindex 946b809e..f22aac71 100644--- a/internal/thirdparty/livekit/sendsidebwe/packet_group.go+++ b/internal/thirdparty/livekit/sendsidebwe/packet_group.go@@ -14,6 +14,7 @@// Modified by Piik: use feedback state; the first receive timestamp can be zero.// Track loss membership for the full packet history, independently of ACK count.+// Tolerate ordinary clock-rate skew in delay inference, retaining raw traffic measurements.package sendsidebweimport (@@ -231,11 +232,12 @@ func (p *packetGroup) SendWindow() (int64, int64) {}func (p *packetGroup) PropagatedQueuingDelay() int64 {- if p.inheritedQueuingDelay+p.aggregateRecvDelta-p.aggregateSendDelta > 0 {- return p.inheritedQueuingDelay + p.aggregateRecvDelta - p.aggregateSendDelta- }-- return max(0, p.aggregateRecvDelta-p.aggregateSendDelta)+ // A faster virtual sender clock prevents normal oscillator skew from+ // accumulating as a permanent queue. RFC 6817 A.2 uses 500 ppm; this changes+ // only delay inference, never acknowledged rates, packet times or loss.+ const clockSkewTolerance = 500 // microseconds per second+ delta := p.aggregateRecvDelta - p.aggregateSendDelta - p.aggregateSendDelta*clockSkewTolerance/1_000_000+ return max(0, p.inheritedQueuingDelay+delta)}func (p *packetGroup) FinalizedPropagatedQueuingDelay() (int64, bool) {diff --git a/internal/tlsconfig/certificate.go b/internal/tlsconfig/certificate.gonew file mode 100644index 00000000..bf83cd39--- /dev/null+++ b/internal/tlsconfig/certificate.go@@ -0,0 +1,55 @@+// Package tlsconfig supplies process-local certificates for private HTTPS entry.+package tlsconfig++import (+ "crypto/ecdsa"+ "crypto/elliptic"+ "crypto/rand"+ "crypto/sha256"+ "crypto/tls"+ "crypto/x509"+ "crypto/x509/pkix"+ "fmt"+ "math/big"+ "net"+ "time"+)++// SelfSigned creates a server certificate for the exact invitation host. The+// key stays in memory; callers never install a CA or silently change trust.+func SelfSigned(host string) (*tls.Config, error) {+ key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)+ if err != nil {+ return nil, err+ }+ serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))+ if err != nil {+ return nil, err+ }+ now := time.Now()+ certificate := &x509.Certificate{+ SerialNumber: serial,+ Subject: pkix.Name{CommonName: "Piik Local"},+ NotBefore: now.Add(-5 * time.Minute),+ NotAfter: now.AddDate(1, 0, 0),+ KeyUsage: x509.KeyUsageDigitalSignature,+ ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},+ BasicConstraintsValid: true,+ }+ if address := net.ParseIP(host); address != nil {+ certificate.IPAddresses = []net.IP{address}+ } else {+ certificate.DNSNames = []string{host}+ }+ der, err := x509.CreateCertificate(rand.Reader, certificate, certificate, &key.PublicKey, key)+ if err != nil {+ return nil, err+ }+ return &tls.Config{MinVersion: tls.VersionTLS12,+ Certificates: []tls.Certificate{{Certificate: [][]byte{der}, PrivateKey: key}}}, nil+}++// Fingerprint identifies the configured leaf certificate for manual comparison.+func Fingerprint(configuration *tls.Config) string {+ return fmt.Sprintf("%X", sha256.Sum256(configuration.Certificates[0].Certificate[0]))+}diff --git a/native/capture/darwin/main.swift b/native/capture/darwin/main.swiftindex 747a37f0..5cca7671 100644--- a/native/capture/darwin/main.swift+++ b/native/capture/darwin/main.swift@@ -1,6 +1,7 @@import AVFoundationimport AudioToolboximport CoreAudio+import CoreGraphicsimport CoreMediaimport CoreVideoimport Darwin@@ -267,7 +268,9 @@ private func target(for display: SCDisplay) -> CaptureTarget {}private func shareableContent() async throws -> SCShareableContent {- try await SCShareableContent.excludingDesktopWindows(+ // Initialize the display service before ScreenCaptureKit builds filters.+ _ = CGMainDisplayID()+ return try await SCShareableContent.excludingDesktopWindows(false,onScreenWindowsOnly: true)@@ -2105,7 +2108,11 @@ private func captureAudio(_ arguments: [String]) async throws {})?.0 else {throw CaptureFailure(description: "audio target identity changed")}- filter = SCContentFilter(desktopIndependentWindow: selected)+ guard let application = selected.owningApplication,+ let display = content.displays.first else {+ throw CaptureFailure(description: "audio application is unavailable")+ }+ filter = SCContentFilter(display: display, including: [application], exceptingWindows: [])} else if kind == "display" {guard pid == 0, creationTime == "0",let selected = content.displays.first else {diff --git a/native/capture/linux/main.c b/native/capture/linux/main.cindex 392540d0..ead441b7 100644--- a/native/capture/linux/main.c+++ b/native/capture/linux/main.c@@ -14,6 +14,10 @@#include "portal.h"+// Desktop pixels are square. Constrain the source before downstream scaling+// advertises a PAR range that PipeWire can fixate to 1/G_MAXINT.+static const char desktop_source_caps[] = "video/x-raw,pixel-aspect-ratio=1/1";+enum {kCaptureProtocol = 7,kMaxOutputs = 6,@@ -1199,9 +1203,9 @@ static int capture_video(int count, char **values) {} else {char *target = pipewire_target(&portal);g_string_append_printf(pipeline_text,- "pipewiresrc name=source fd=%d %s do-timestamp=true ! "+ "pipewiresrc name=source fd=%d %s do-timestamp=true ! %s ! ""videorate drop-only=true ! video/x-raw,framerate=%u/1 ! tee name=frames ",- portal.pipewire_fd, target, run.profile.frame_rate);+ portal.pipewire_fd, target, desktop_source_caps, run.profile.frame_rate);g_free(target);}for (guint index = 0; index < run.output_count; ++index) {diff --git a/native/capture/linux/main.test.c b/native/capture/linux/main.test.cindex 32cfe4a1..683f49e9 100644--- a/native/capture/linux/main.test.c+++ b/native/capture/linux/main.test.c@@ -307,6 +307,56 @@ static GstState branch_state(VideoOutput *output) {return state;}+static void check_desktop_source_pixel_aspect(void) {+ const VideoProfile profile = {.width = 1920, .height = 1080};+ GString *description = g_string_new("appsrc name=source format=time ! ");+ g_string_append_printf(description, "%s ! ", desktop_source_caps);+ append_video_scale(description, &profile);+ g_string_append(description, "appsink name=output sync=false async=false");+ GError *error = NULL;+ GstElement *pipeline = gst_parse_launch(description->str, &error);+ g_string_free(description, TRUE);+ g_assert_no_error(error);+ GstElement *source = gst_bin_get_by_name(GST_BIN(pipeline), "source");+ GstElement *sink = gst_bin_get_by_name(GST_BIN(pipeline), "output");+ GstPad *pad = gst_element_get_static_pad(source, "src");+ GstCaps *peer = gst_pad_peer_query_caps(pad, NULL);+ // Reproduce PipeWire choosing from a downstream scaler's broad PAR range.+ GstCaps *offer = gst_caps_from_string(+ "video/x-raw,format=BGRA,width=3840,height=2160,framerate=30/1,"+ "pixel-aspect-ratio=(fraction)[1/2147483647,2147483647/1]");+ GstCaps *caps = gst_caps_fixate(gst_caps_intersect_full(+ offer, peer, GST_CAPS_INTERSECT_FIRST));+ GstVideoInfo input;+ g_assert_true(gst_video_info_from_caps(&input, caps));+ g_assert_cmpint(input.par_n, ==, 1);+ g_assert_cmpint(input.par_d, ==, 1);+ gst_app_src_set_caps(GST_APP_SRC(source), caps);+ g_assert_cmpint(gst_element_set_state(pipeline, GST_STATE_PLAYING), !=,+ GST_STATE_CHANGE_FAILURE);+ GstBuffer *buffer = gst_buffer_new_allocate(NULL, input.size, NULL);+ GST_BUFFER_PTS(buffer) = 0;+ GST_BUFFER_DURATION(buffer) = GST_SECOND / 30;+ g_assert_cmpint(gst_app_src_push_buffer(GST_APP_SRC(source), buffer), ==, GST_FLOW_OK);+ GstSample *sample = gst_app_sink_try_pull_sample(GST_APP_SINK(sink), GST_SECOND);+ g_assert_nonnull(sample);+ GstVideoInfo output;+ g_assert_true(gst_video_info_from_caps(&output, gst_sample_get_caps(sample)));+ g_assert_cmpint(output.width, ==, 1920);+ g_assert_cmpint(output.height, ==, 1080);+ g_assert_cmpint(output.par_n, ==, 1);+ g_assert_cmpint(output.par_d, ==, 1);+ gst_sample_unref(sample);+ gst_element_set_state(pipeline, GST_STATE_NULL);+ gst_caps_unref(caps);+ gst_caps_unref(offer);+ gst_caps_unref(peer);+ gst_object_unref(pad);+ gst_object_unref(source);+ gst_object_unref(sink);+ gst_object_unref(pipeline);+}+static void check_source_geometry(guint max_width, guint max_height) {const VideoProfile profile = {.width = max_width, .height = max_height};GString *description = g_string_new("appsrc name=source format=time ! ");@@ -598,6 +648,7 @@ int main(int argc, char **argv) {check_encoder_admission_and_control();check_bus_error_retains_primary_cause();check_slot_profiles();+ check_desktop_source_pixel_aspect();check_source_geometry(1920, 1080);check_source_geometry(2, 2);check_encoder_timestamp_segment(1000ULL * 60 * 60 * GST_SECOND);diff --git a/native/capture/windows/frame_converter.probe.cpp b/native/capture/windows/frame_converter.probe.cppindex 10da3098..0fe77c53 100644--- a/native/capture/windows/frame_converter.probe.cpp+++ b/native/capture/windows/frame_converter.probe.cpp@@ -88,6 +88,38 @@ void CheckColors(const DeviceContext& device, ID3D11Texture2D* texture) {if (!correct) throw std::runtime_error("SDR range or matrix changed");}+void CheckEncoderProbeTextures(const DeviceContext& device) {+ const VideoProfile profile{256, 128, 30, 3'000'000};+ const auto textures = PrepareEncoderProbeTextures(device.device.Get(), profile);+ std::array<UINT64, 8> fingerprints{};+ for (size_t index = 0; index < textures.size(); ++index) {+ D3D11_TEXTURE2D_DESC description{};+ textures[index]->GetDesc(&description);+ if (description.Width != profile.width || description.Height != profile.height ||+ description.Format != DXGI_FORMAT_NV12 ||+ description.BindFlags != D3D11_BIND_RENDER_TARGET)+ throw std::runtime_error("Encoder probe does not use live converter surfaces");+ description.Usage = D3D11_USAGE_STAGING;+ description.BindFlags = 0;+ description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;+ ComPtr<ID3D11Texture2D> staging;+ Check(device.device->CreateTexture2D(&description, nullptr, &staging), "probe-readback");+ device.context->CopyResource(staging.Get(), textures[index].Get());+ D3D11_MAPPED_SUBRESOURCE mapped{};+ Check(device.context->Map(staging.Get(), 0, D3D11_MAP_READ, 0, &mapped), "probe-map");+ UINT64 fingerprint = 14695981039346656037ull;+ const auto* bytes = static_cast<const UINT8*>(mapped.pData);+ for (UINT32 row = 0; row < profile.height * 3 / 2; ++row)+ for (UINT32 column = 0; column < profile.width; ++column)+ fingerprint = (fingerprint ^ bytes[row * mapped.RowPitch + column]) * 1099511628211ull;+ device.context->Unmap(staging.Get(), 0);+ for (size_t earlier = 0; earlier < index; ++earlier)+ if (textures[index].Get() == textures[earlier].Get() || fingerprints[earlier] == fingerprint)+ throw std::runtime_error("Encoder probe frames lost their distinct retained contents");+ fingerprints[index] = fingerprint;+ }+}+ComPtr<ID3D11Texture2D> LinearBars(const DeviceContext& device, UINT width,UINT height, const std::array<float, 8>& nits) {std::vector<UINT16> pixels(static_cast<size_t>(width) * height * 4);@@ -178,6 +210,7 @@ int main() {if (adapters.empty()) throw std::runtime_error("A physical D3D11 adapter is required");for (const auto& adapter : adapters) {auto device = CreateDevice(adapter);+ CheckEncoderProbeTextures(device);for (const UINT output_width : {256u, 128u}) {VideoProfile profile;profile.width = output_width;diff --git a/native/capture/windows/main.cpp b/native/capture/windows/main.cppindex 3b0e6c35..16ee25c5 100644--- a/native/capture/windows/main.cpp+++ b/native/capture/windows/main.cpp@@ -144,6 +144,7 @@ void PrintAdapters(const std::vector<Adapter>& adapters) {}}+#ifdef PIIK_H264_FIXTUREstd::vector<UINT8> SyntheticNv12(UINT32 frame_index, const VideoProfile& profile = kDefaultVideoProfile) {const auto width = profile.width;@@ -191,7 +192,6 @@ ComPtr<ID3D11Texture2D> CreateSyntheticTexture(return texture;}-#ifdef PIIK_H264_FIXTUREComPtr<IMFSample> CreateInputSample(ID3D11Device* device, UINT32 frame_index) {auto texture = CreateSyntheticTexture(device, frame_index);return CreateSurfaceSample(texture.Get(),@@ -795,6 +795,49 @@ class FrameConverter final {DXGI_COLOR_SPACE_TYPE input_color_ = kDesktopColor;};+ComPtr<ID3D11Texture2D> CreateEncoderProbeTexture(+ ID3D11Device* device, FrameConverter& converter, UINT32 frame_index,+ const VideoProfile& profile) {+ std::vector<UINT32> pixels(static_cast<size_t>(profile.width) * profile.height);+ const UINT32 bar_start = (frame_index * 11) % profile.width;+ for (UINT32 y = 0; y < profile.height; ++y) {+ for (UINT32 x = 0; x < profile.width; ++x) {+ const UINT32 distance = (x + profile.width - bar_start) % profile.width;+ const UINT32 base = 16 + ((x / 8 + y / 8 + frame_index) % 180);+ pixels[static_cast<size_t>(y) * profile.width + x] = distance < 96+ ? 0xffebebeb : 0xff000000 | base |+ ((96 + frame_index % 64) << 8) | ((160 - frame_index % 64) << 16);+ }+ }+ D3D11_TEXTURE2D_DESC description{};+ description.Width = profile.width;+ description.Height = profile.height;+ description.MipLevels = description.ArraySize = description.SampleDesc.Count = 1;+ description.Format = DXGI_FORMAT_B8G8R8A8_UNORM;+ description.Usage = D3D11_USAGE_DEFAULT;+ description.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;+ D3D11_SUBRESOURCE_DATA initial{};+ initial.pSysMem = pixels.data();+ initial.SysMemPitch = profile.width * 4;+ ComPtr<ID3D11Texture2D> source;+ Check(device->CreateTexture2D(&description, &initial, &source), "codec-probe-source");+ // Match live capture's GPU-produced NV12 input instead of probing a separate+ // initialized NV12 upload path. Each conversion owns its output surface.+ return converter.Convert(source.Get(), profile.width, profile.height,+ {static_cast<LONG>(profile.width), static_cast<LONG>(profile.height)}, kDesktopColor);+}++using EncoderProbeTextures = std::array<ComPtr<ID3D11Texture2D>, 8>;++EncoderProbeTextures PrepareEncoderProbeTextures(ID3D11Device* device,+ const VideoProfile& profile) {+ FrameConverter converter(device, profile);+ EncoderProbeTextures textures;+ for (UINT32 index = 0; index < textures.size(); ++index)+ textures[index] = CreateEncoderProbeTexture(device, converter, index * 7, profile);+ return textures;+}+winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DDeviceCreateCaptureDevice(ID3D11Device* device) {ComPtr<IDXGIDevice> dxgi_device;@@ -1270,15 +1313,11 @@ class ProbeEncoder final : public VideoEncoder {};bool SustainsEncodedCadence(VideoEncoder& hardware, ID3D11Device* device,- const VideoProfile& profile, EncoderClock::time_point deadline) {+ const VideoProfile& profile, EncoderClock::time_point deadline,+ const EncoderProbeTextures& textures) {RequireEncoderTime(deadline);const auto [warmup_frames, sample_frames, interval] = CadenceTiming(profile);const UINT32 lag = CadenceLagFrames(profile.frame_rate);- // Synthesis is CPU work of the probe, not the encoder; prepare it before pacing.- std::array<ComPtr<ID3D11Texture2D>, 8> textures;- for (UINT32 index = 0; index < textures.size(); ++index) {- textures[index] = CreateSyntheticTexture(device, index * 7, profile);- }AdaptiveEncoder encoder(OutputKind::h264, profile, device,[&](const VideoProfile& selected) -> std::unique_ptr<VideoEncoder> {if (selected.width != profile.width || selected.height != profile.height ||@@ -1389,14 +1428,19 @@ VideoEncoderSelection SelectVideoEncoder(const auto encoders = EnumerateHardwareEncoders(adapter);auto selected = ActivateTransform(encoders, candidate.second, next_device.manager.Get());auto next = std::make_unique<LiveEncoder>(std::move(selected), arguments.profile);- if (arguments.codec == "auto" && !SustainsEncodedCadence(- *next,- next_device.device.Get(), arguments.profile, deadline)) {- Fail("codec-probe-cadence", "hardware H264 did not sustain the target frame rate");+ if (arguments.codec == "auto") {+ RequireEncoderTime(deadline);+ // Synthesis/conversion belongs to setup, outside the paced measurement.+ const auto textures = PrepareEncoderProbeTextures(next_device.device.Get(), arguments.profile);+ if (!SustainsEncodedCadence(*next, next_device.device.Get(),+ arguments.profile, deadline, textures))+ Fail("codec-probe-cadence", "hardware H264 did not sustain the target frame rate");}if (arguments.codec == "h264") {// Explicit H264 validates output without Auto's cadence measurement.- const auto texture = CreateSyntheticTexture(next_device.device.Get(), 0, arguments.profile);+ FrameConverter converter(next_device.device.Get(), arguments.profile);+ const auto texture = CreateEncoderProbeTexture(+ next_device.device.Get(), converter, 0, arguments.profile);next->Encode(texture.Get(), 0, true, deadline);}RequireEncoderTime(deadline);diff --git a/native/capture/windows/output_worker.test.cpp b/native/capture/windows/output_worker.test.cppindex 76bacdd3..6cedca3f 100644--- a/native/capture/windows/output_worker.test.cpp+++ b/native/capture/windows/output_worker.test.cpp@@ -285,12 +285,19 @@ void CheckAutoCadenceProbe(ID3D11Device* device) {VideoProfile profile;profile.width = 64;profile.height = 64;+ // WARP checks cadence independently of hardware video-processor support.+ DeviceContext context;+ context.device = device;+ const std::vector<BYTE> pixels(profile.width * profile.height * 3 / 2, 128);+ EncoderProbeTextures textures;+ for (auto& texture : textures)+ texture = UploadDecodedNV12(context, pixels.data(), profile.width, profile.height);UINT32 calls = 0;auto probe = [&](std::chrono::milliseconds latency, UINT32 dropped,EncoderClock::time_point deadline, bool cold_only = false) {calls = 0;CadenceFixtureEncoder encoder(latency, dropped, cold_only, calls);- return SustainsEncodedCadence(encoder, device, profile, deadline);+ return SustainsEncodedCadence(encoder, device, profile, deadline, textures);};const auto deadline = EncoderClock::now() + std::chrono::seconds(30);// Valid output at a fraction of the source rate is the driver defect Auto rejects.@@ -339,7 +346,10 @@ void CheckOutputSampleAlignment() {void CheckSurfaceSample(ID3D11Device* device) {Runtime runtime;const VideoProfile profile{64, 64, 30, 3'000'000};- auto texture = CreateSyntheticTexture(device, 0, profile);+ DeviceContext context;+ context.device = device;+ const std::vector<BYTE> pixels(profile.width * profile.height * 3 / 2, 128);+ auto texture = UploadDecodedNV12(context, pixels.data(), profile.width, profile.height);auto sample = CreateSurfaceSample(texture.Get(), 1'000'000, 333'333);ComPtr<IMFMediaBuffer> buffer;Check(sample->GetBufferByIndex(0, &buffer), "fixture-sample-buffer");diff --git a/package-lock.json b/package-lock.jsonindex 85335e21..d669affc 100644--- a/package-lock.json+++ b/package-lock.json@@ -22,7 +22,7 @@"semver": "7.8.5","tsx": "4.23.13","typescript": "~6.0.3",- "vite": "8.2.1",+ "vite": "8.2.4","vitest": "4.1.11","ws": "8.21.3","zod": "4.4.3"@@ -1705,16 +1705,16 @@"license": "MIT"},"node_modules/vite": {- "version": "8.2.1",- "resolved": "https://registry.npmjs.org/vite/-/vite-8.2.1.tgz",- "integrity": "sha512-EU/eS7BH3XROHh2YnBefjM6DBKA6ZeMZEYQbj7NLWg5wHYlhB8B/Mayd5XsgWq+NFYccDOTemRpdETWR6Ka/lw==",+ "version": "8.2.4",+ "resolved": "https://registry.npmjs.org/vite/-/vite-8.2.4.tgz",+ "integrity": "sha512-lfauXnrf2x0p+UoA+wXh0dgFWnUjCyG6Js95KBkgaCwUU9k0DAHI4W6Q0WCx+h+5g+Alce1y4Zi2QjjK0UvGBw==","dev": true,"license": "MIT","dependencies": {"lightningcss": "^1.33.0","picomatch": "^4.0.5",- "postcss": "^8.5.25",- "rolldown": "~1.2.1",+ "postcss": "^8.5.26",+ "rolldown": "~1.2.4","tinyglobby": "^0.2.17"},"bin": {@@ -1731,7 +1731,7 @@},"peerDependencies": {"@types/node": "^20.19.0 || >=22.12.0",- "@vitejs/devtools": "^0.4.0",+ "@vitejs/devtools": "^0.4.0 || ^0.5.0","esbuild": "^0.27.0 || ^0.28.0","jiti": ">=1.21.0","less": "^4.0.0",diff --git a/package.json b/package.jsonindex 83499dae..35fd0960 100644--- a/package.json+++ b/package.json@@ -27,6 +27,7 @@"gate:app-native-host": "tsx scripts/app-native-host-gate.ts","gate:app-browser-fanout": "tsx scripts/app-browser-fanout-gate.ts","gate:embedded-sfu": "tsx scripts/embedded-sfu-gate.ts",+ "gate:room-voice": "tsx scripts/room-voice-gate.ts","gate:app-link": "tsx scripts/app-link-gate.ts","gate:peer-topology-loopback": "tsx scripts/peer-assisted-benchmark.ts","gate:sfu-admission": "vitest run tests/sfu-client.test.ts tests/route-transition.test.ts && go test ./internal/server/...",@@ -54,7 +55,7 @@"semver": "7.8.5","tsx": "4.23.13","typescript": "~6.0.3",- "vite": "8.2.1",+ "vite": "8.2.4","vitest": "4.1.11","ws": "8.21.3","zod": "4.4.3"diff --git a/scripts/app-local-gate.ts b/scripts/app-local-gate.tsindex ab616a35..ed1b5eaa 100644--- a/scripts/app-local-gate.ts+++ b/scripts/app-local-gate.ts@@ -28,6 +28,10 @@ interface GateReport {bootstrapRemoved: boolean;hostReady: boolean;lanInvite: boolean;+ lanSecureContext: boolean;+ lanMicrophone: boolean;+ lanEncryptedInput: boolean;+ lanSignalingConnected: boolean;appExited: boolean;browserExited: boolean;portsClosed: boolean;@@ -74,6 +78,10 @@ async function main(): Promise<void> {bootstrapRemoved: false,hostReady: false,lanInvite: false,+ lanSecureContext: false,+ lanMicrophone: false,+ lanEncryptedInput: false,+ lanSignalingConnected: false,appExited: false,browserExited: false,portsClosed: false,@@ -132,6 +140,8 @@ async function main(): Promise<void> {"--no-first-run","--no-proxy-server","--disable-logging",+ "--use-fake-device-for-media-stream",+ "--use-fake-ui-for-media-stream",]);browser.stdout.resume();browser.stderr.resume();@@ -156,7 +166,7 @@ async function main(): Promise<void> {value.hostReady,15_000,);- report.lanInvite = await evaluate<boolean>(+ const invitation = await evaluate<string>(cdp,page,`fetch('/api/rooms', {@@ -164,13 +174,43 @@ async function main(): Promise<void> {headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ codeEntryPolicy: 'open' }),}).then(async (response) => {- if (!response.ok) return false;+ if (!response.ok) throw new Error('Room creation failed');const room = await response.json();- return typeof room.inviteUrl === 'string' &&- room.inviteUrl.startsWith(${JSON.stringify(`http://${lanAddress}:${appPort}/r/`)});+ return room.inviteUrl;})`,Date.now() + 5_000,);+ report.lanInvite = invitation.startsWith(`https://${lanAddress}:${appPort}/r/`);+ const viewer = await createPage(cdp, invitation, `(() => {+ const NativeWS=WebSocket;+ window.WebSocket=class extends NativeWS {+ constructor(...args){super(...args);this.addEventListener('message',event=>{+ try {if(JSON.parse(event.data).type==='authenticated')window.__localGateAuthenticated=true;}catch{}+ });}+ };+ })()`);+ // Exercise Chrome's actual certificate exception. No global TLS bypass or+ // browser trust-store change is part of this gate or the shipped App.+ await evaluate(cdp, viewer, `document.getElementById('details-button')?.click();+ document.getElementById('proceed-link')?.click();`, Date.now() + 5_000);+ await waitForSample(deadline => evaluate(cdp!, viewer,+ "Boolean(window.__localGateAuthenticated)", deadline), Boolean, 15_000);+ report.lanSignalingConnected = true;+ const capabilities = await evaluate<{ secure: boolean; microphone: boolean; encryption: boolean }>(cdp, viewer,+ `(async()=>{+ const stream=await navigator.mediaDevices.getUserMedia({audio:true});+ const microphone=stream.getAudioTracks().some(track=>track.readyState==='live');+ stream.getTracks().forEach(track=>track.stop());+ const key=await crypto.subtle.generateKey({name:'AES-GCM',length:128},false,['encrypt','decrypt']);+ const iv=crypto.getRandomValues(new Uint8Array(12));+ const text=new TextEncoder().encode('Piik LAN input');+ const ciphertext=await crypto.subtle.encrypt({name:'AES-GCM',iv},key,text);+ const plaintext=await crypto.subtle.decrypt({name:'AES-GCM',iv},key,ciphertext);+ return {secure:isSecureContext,microphone,encryption:new TextDecoder().decode(plaintext)==='Piik LAN input'};+ })()`, Date.now() + 5_000);+ report.lanSecureContext = capabilities.secure;+ report.lanMicrophone = capabilities.microphone;+ report.lanEncryptedInput = capabilities.encryption;} catch (error) {report.error = error instanceof Error ? error.message : String(error);} finally {@@ -189,7 +229,8 @@ async function main(): Promise<void> {}report.passed = report.appStarted && report.localServerReady &&report.bootstrapAuthenticated && report.bootstrapRemoved && report.hostReady &&- report.lanInvite && report.appExited && report.browserExited &&+ report.lanInvite && report.lanSecureContext && report.lanMicrophone &&+ report.lanEncryptedInput && report.lanSignalingConnected && report.appExited && report.browserExited &&report.portsClosed && report.profileRemoved && report.error === null;process.stdout.write(`${JSON.stringify(report)}\n`);if (!report.passed) process.exitCode = 1;diff --git a/scripts/app-native-host-gate.ts b/scripts/app-native-host-gate.tsindex cce5eb81..f93d8e9a 100644--- a/scripts/app-native-host-gate.ts+++ b/scripts/app-native-host-gate.ts@@ -598,6 +598,7 @@ async function main(): Promise<void> {? remoteOptions() : null;const chromePath = process.env.CHROME_PATH?.trim();if (!chromePath) throw new Error("CHROME_PATH is required");+ const lanAddress = process.env.PIIK_CLIENT_GATE_LAN_ADDRESS?.trim();const go = process.env.PIIK_GO?.trim() || "go";const tunnel = process.env.PIIK_CLOUDFLARED?.trim() || join(BUILD_ROOT,@@ -712,7 +713,7 @@ async function main(): Promise<void> {mode === "one-link" ? "--link" : "--local",...(mode === "one-link"? ["--tunnel-process", tunnel]- : []),+ : lanAddress ? ["--lan-address", lanAddress] : []),"--capture-process", captureBinary,"--config", appConfig,"--port", String(appPort),diff --git a/scripts/check-go.mjs b/scripts/check-go.mjsindex 0fbdc98e..47844611 100644--- a/scripts/check-go.mjs+++ b/scripts/check-go.mjs@@ -80,7 +80,7 @@ function checkCore() {["piik-app", "piik-peer-gate"].map((command) => ({ target, command })),);builds.push(...SERVER_PACKAGE_TARGETS.map(target => ({- target: { ...target, id: `linux-${target.goarch}`, cgo: false }, command: "piik-server",+ target: { ...target, id: `${target.goos}-${target.goarch}`, cgo: false }, command: "piik-server",})));for (const { target, command } of builds) {const outputName = target.goos === "windows"diff --git a/scripts/network-lab.ts b/scripts/network-lab.tsindex 3dac158e..b3dc69e6 100644--- a/scripts/network-lab.ts+++ b/scripts/network-lab.ts@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { parseArgs } from "node:util";import { setTimeout as delay } from "node:timers/promises";-import { cleanupRun, withDeadline } from "./browser-gate-harness";+import { cleanupRun, waitForSample, withDeadline } from "./browser-gate-harness";import { endpointWorker } from "./network-lab/endpoint";import { Endpoint } from "./network-lab/endpoint-client";import { command, LabNetwork, SITE_IP, SITE_IPV6, SITE_ORIGIN } from "./network-lab/network";@@ -46,6 +46,14 @@ async function runCase(scenario: Scenario, seed: number, prediction: boolean, ouconst sample = { elapsedMs: performance.now() - started, host: host!, viewer: viewer!, sibling };samples.push(sample); return sample;};+ const proveVoice = async () => {+ type VoiceSample = { energy: number; samples: number; playing: number; publications: number };+ const baseline = await Promise.all(endpoints.slice(0, 2).map(endpoint => endpoint.call<VoiceSample>("voice-sample")));+ let voice: VoiceSample[] = [];+ await waitForSample(async () => voice = await Promise.all(endpoints.slice(0, 2).map(endpoint => endpoint.call<VoiceSample>("voice-sample"))),+ states => states.every((state, index) => state.playing > 0 && state.energy > 0 && state.samples > baseline[index]!.samples && state.publications === 2), 40_000);+ result.voice = { baseline, received: voice };+ };const addresses = () => endpoints.map((_, index) => scenario.ipv6 ? network.ipv6(index) : network.publicIP(index));const observeQuality = async (name: string, durationMs: number, baseline?: MediaSample) => {stage(name);@@ -162,6 +170,11 @@ async function runCase(scenario: Scenario, seed: number, prediction: boolean, ouconst { viewer: next, sibling: healthy } = await sampleAll();checkContinuity(first, next);checkAppPaths();+ if (scenario.voice) {+ stage("room-voice");+ await endpoints[0]!.call("voice-open"); await endpoints[1]!.call("voice-join");+ await proveVoice();+ }mediaWindows.push({ name: "baseline", startMs: steadyStart, endMs: Date.now(), addresses: addresses() });if (values.negative === "frozen-picture") {stage("negative-control");@@ -247,10 +260,12 @@ async function runCase(scenario: Scenario, seed: number, prediction: boolean, ouif (qualityBaseline) await observeQuality("quality-restored", 90_000, qualityBaseline);}}+ if (scenario.voice && connected) { stage("voice-continuity"); await proveVoice(); }await endpoints[1]!.call("screenshot", { output: join(output, "viewer.png") });result.finalCounters = counters();if (!scenario.duringShare) checkFaultHit(scenario.fault, counters().faultDrops);await endpoints[0]!.call("stop");+ if (scenario.voice && connected) { stage("voice-without-picture"); await proveVoice(); }signal.throwIfAborted();result.passed = true; stage("done");} catch (error) { result.error = error instanceof Error ? error.message : String(error); }diff --git a/scripts/network-lab/endpoint.ts b/scripts/network-lab/endpoint.tsindex 77594dbc..081c9c79 100644--- a/scripts/network-lab/endpoint.ts+++ b/scripts/network-lab/endpoint.ts@@ -28,7 +28,7 @@ export async function endpointWorker(): Promise<void> {const sample = () => evaluate<MediaSample>(cdp!, page!, "networkLab.sample()", Date.now() + 5000);const click = async (selector: string) => {await waitForSample(deadline => evaluate<boolean>(cdp!, page!,- `Boolean(document.querySelector(${JSON.stringify(selector)}))`, deadline), Boolean, 10_000);+ `(()=>{const node=document.querySelector(${JSON.stringify(selector)});return !!node&&!node.disabled&&node.getAttribute('aria-disabled')!=='true';})()`, deadline), Boolean, 10_000);await evaluate(cdp!, page!, `document.querySelector(${JSON.stringify(selector)}).click()`, Date.now() + 5000);};try {@@ -61,6 +61,7 @@ export async function endpointWorker(): Promise<void> {chrome = await launchChrome(process.env.CHROME_PATH!, debugPort, profile, ["--headless=new", "--no-sandbox", "--disable-dev-shm-usage", "--no-first-run", "--no-default-browser-check","--no-proxy-server", "--autoplay-policy=no-user-gesture-required", "--disable-background-timer-throttling",+ "--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream","--disable-renderer-backgrounding", "--disable-backgrounding-occluded-windows",`--unsafely-treat-insecure-origin-as-secure=${origin}`,]);@@ -130,6 +131,15 @@ export async function endpointWorker(): Promise<void> {result = logs;} else if (request.action === "stop") {await click('button[aria-label="Stop sharing"]'); result = true;+ } else if (request.action === "voice-open" || request.action === "voice-join") {+ await click('button[aria-label="Interact"]');+ await click('[role="tab"][id$="-voice-tab"]');+ await click(`button[aria-label="${request.action === "voice-open" ? "Open room voice" : "Join voice"}"]`);+ await waitForSample(deadline => evaluate<boolean>(cdp!, page!,+ `Boolean(document.querySelector('button[aria-label="Microphone"][aria-pressed="false"]'))`, deadline), Boolean, 10_000);+ await click('button[aria-label="Microphone"][aria-pressed="false"]'); result = true;+ } else if (request.action === "voice-sample") {+ result = await evaluate(cdp!, page!, "networkLab.voiceSample()", Date.now() + 5000);} else if (request.action === "screenshot") {const shot = await cdp!.call<{ data: string }>("Page.captureScreenshot", { format: "png" }, page!.sessionId, Date.now() + 5000);await writeFile(request.output!, Buffer.from(shot.data, "base64")); result = true;diff --git a/scripts/network-lab/page.ts b/scripts/network-lab/page.tsindex 6bd640df..9e1675a9 100644--- a/scripts/network-lab/page.ts+++ b/scripts/network-lab/page.ts@@ -3,7 +3,7 @@export const pageProbe = String.raw`(() => {localStorage.setItem('piik:ui-lang','en'); localStorage.setItem('piik:ui-mode','text');const peers=[], sockets=[], events=[], errors=[], controls=[];- let route=null,natPrediction=null,freezeCapture=()=>{},resumeCapture=()=>{},peerSignalDelay=0,peerSignalReleaseAt=0;+ let route=null,natPrediction=null,voice=null,freezeCapture=()=>{},resumeCapture=()=>{},peerSignalDelay=0,peerSignalReleaseAt=0;let observedVideo=null,frameCallback=0,renderedFrames=0,lastFrameAt=0,maxFrameGapMs=0;const observeVideo=video=>{if(video===observedVideo)return;@@ -32,6 +32,7 @@ export const pageProbe = String.raw`(() => {let message; try{message=JSON.parse(event.data);}catch{return;}if(typeof message.routePolicy?.natPrediction==='boolean')natPrediction=message.routePolicy.natPrediction;if(message.type==='route-update'&&message.phase==='active')route=message.assignment.upstream.kind;+ if(message.type==='room-voice-state')voice=message;const value={at:performance.now(),type:message.type,state:message.state,reason:message.reason,scope,phase:message.phase,route:message.assignment?.upstream?.kind,connectionId:message.connectionId};if(message.type==='punch-prepared')value.predictionStep=message.prediction?.step;@@ -78,7 +79,16 @@ export const pageProbe = String.raw`(() => {sound.stop=()=>{if(stopped)return;stopped=true;osc.stop();void ac.close();stopSound();};stream.addTrack(sound);return stream;};- window.networkLab={freezeCapture:()=>freezeCapture(),resumeCapture:()=>resumeCapture(),delayPeerSignals:ms=>{peerSignalDelay=ms;peerSignalReleaseAt=0;},+ window.networkLab={async voiceSample(){+ const audio=[...document.querySelectorAll('audio')].filter(node=>node.srcObject);+ const ids=new Set(audio.flatMap(node=>node.srcObject.getAudioTracks().map(track=>track.id)));+ let energy=0,samples=0;+ for(const peer of peers)if(peer.connectionState==='connected')for(const row of (await peer.getStats()).values())+ if(row.type==='inbound-rtp'&&row.kind==='audio'&&ids.has(row.trackIdentifier)){+ energy+=row.totalAudioEnergy||0;samples+=row.totalSamplesDuration||0;+ }+ return {energy,samples,playing:audio.length,publications:voice?.publications.length||0};+ },freezeCapture:()=>freezeCapture(),resumeCapture:()=>resumeCapture(),delayPeerSignals:ms=>{peerSignalDelay=ms;peerSignalReleaseAt=0;},resetPlaybackProgress:()=>{renderedFrames=0;lastFrameAt=performance.now();maxFrameGapMs=0;},async signalProbe(){const socket=sockets.findLast(s=>!s.url.includes('/control')&&s.readyState===WS.OPEN);if(!socket)return false;diff --git a/scripts/network-lab/scenarios.ts b/scripts/network-lab/scenarios.tsindex 6b8c5e24..8571b5d1 100644--- a/scripts/network-lab/scenarios.ts+++ b/scripts/network-lab/scenarios.ts@@ -19,6 +19,7 @@ export interface Scenario {sibling?: boolean;remap?: boolean;qualityRecovery?: boolean;+ voice?: boolean;}export interface TrialSummary {@@ -60,6 +61,11 @@ export const scenarios: readonly Scenario[] = [{ ...baseline, id: "app-browser", host: "app", viewer: "browser" },{ ...baseline, id: "browser-app", host: "browser", viewer: "app" },{ ...baseline, id: "app-app", host: "app", viewer: "app" },+ ...(["browser", "app"] as const).flatMap(host => (["browser", "app"] as const).map(viewer => ({+ ...baseline, id: `voice-${host}-${viewer}`, host, viewer, voice: true,+ }))),+ { ...baseline, id: "voice-sfu-fallback", host: "browser", viewer: "browser", voice: true, fault: "peer-block", sfu: true },+ { ...baseline, id: "voice-media-outage", host: "app", viewer: "app", voice: true, fault: "udp-block", duringShare: true },{ ...baseline, id: "delayed-browser", host: "browser", viewer: "browser", fault: "delay" },{ ...baseline, id: "lossy-browser", host: "browser", viewer: "browser", fault: "loss" },{ ...baseline, id: "stun-backup", host: "browser", viewer: "browser", fault: "stun-primary" },@@ -129,7 +135,8 @@ export function checkAppPath(sample: MediaSample, action: "prepare-edge" | "receevent.connectionId === control.connectionId)?.state === "connected");const local = (row: MediaSample["stats"][number]) => localAddresses.includes(String(row.remoteAddress)) ||["127.0.0.1", "::1", "0:0:0:0:0:0:0:1"].includes(String(row.remoteAddress));- const pairs = sample.stats.filter(row => row.type === "selected-pair");+ const videoPeers = new Set(sample.stats.filter(row => row.kind === "video").map(row => row.peerId));+ const pairs = sample.stats.filter(row => row.type === "selected-pair" && videoPeers.has(row.peerId));const browserWAN = pairs.some(row => !local(row));const playbackBridge = action !== "receive-offer" || pairs.some(row => row.peerId === sample.playbackPeerId && local(row));if (!sample.controlOpen || !connected || browserWAN || !playbackBridge) {diff --git a/scripts/package-server-release.mjs b/scripts/package-server-release.mjsindex f3668259..b2835770 100644--- a/scripts/package-server-release.mjs+++ b/scripts/package-server-release.mjs@@ -20,16 +20,23 @@ import { fileURLToPath } from "node:url";import { parseArgs } from "node:util";import { writeServerLicenseNotices } from "./package-licenses.mjs";-import { tarExecutable } from "./archive-tool.mjs";+import { createZip, extractZip, tarExecutable } from "./archive-tool.mjs";import { assertCleanRevision, resetBuildWorkspace } from "./build-workspace.mjs";import { buildVersion } from "./release-version.mjs";import { SERVER_PACKAGE_TARGETS } from "./server-package-targets.mjs";-const SERVER_NAME = "piik-server";+// A Windows build ships the same archive shape with an `.exe` binary, so the+// binary name, the manifest allowlist and the archive allowlist all follow the+// selected target instead of a single constant.+function serverBinaryName(target) {+ return target.goos === "windows" ? "piik-server.exe" : "piik-server";+}// Everything the archive may contain. deploy/release-server.sh enforces the same// four names in its entry allowlist and manifest pattern; both change together.-const RUNTIME_PATHS = ["REVISION", "LICENSE", "THIRD-PARTY-NOTICES.txt", SERVER_NAME];+function runtimePaths(target) {+ return ["REVISION", "LICENSE", "THIRD-PARTY-NOTICES.txt", serverBinaryName(target)];+}// The Vite output the server embeds. Its index.html names the main asset the// deployment postflight proves over HTTP.@@ -105,10 +112,10 @@ function regularFiles(root) {);}-function recordsFor(root) {+function recordsFor(root, paths) {return regularFiles(root).map((absolute) => {const path = normalizedRelative(root, absolute);- if (!RUNTIME_PATHS.includes(path)) fail(`Unexpected packaged file: ${path}`);+ if (!paths.includes(path)) fail(`Unexpected packaged file: ${path}`);return { path, size: statSync(absolute).size, sha256: sha256(absolute) };});}@@ -128,7 +135,7 @@ function compareRecords(expected, actual) {}}-function validateArchiveEntries(entries) {+function validateArchiveEntries(entries, paths) {for (const rawEntry of entries.split(/\r?\n/)) {let entry = rawEntry;while (entry.startsWith("./")) entry = entry.slice(2);@@ -141,7 +148,7 @@ function validateArchiveEntries(entries) {) {fail(`Invalid archive entry: ${rawEntry}`);}- if (!RUNTIME_PATHS.includes(entry)) fail(`Unexpected archive entry: ${rawEntry}`);+ if (!paths.includes(entry)) fail(`Unexpected archive entry: ${rawEntry}`);}}@@ -160,13 +167,19 @@ function mainAssetOf(distributionRoot) {const { values, positionals } = parseArgs({ allowPositionals: true, options: {arch: { type: "string", default: "amd64" },+ os: { type: "string", default: "linux" },"container-image": { type: "string" },} });-const target = SERVER_PACKAGE_TARGETS.find(target => target.goarch === values.arch);+const target = SERVER_PACKAGE_TARGETS.find(+ candidate => candidate.goarch === values.arch && candidate.goos === values.os,+);if (positionals.length !== 1 || !target) {- fail("Usage: node scripts/package-server-release.mjs <new-output-directory> [--arch amd64|arm64] [--container-image <tag>]");+ fail("Usage: node scripts/package-server-release.mjs <new-output-directory> [--os linux|windows] [--arch amd64|arm64] [--container-image <tag>]");}const containerImage = values["container-image"];+if (containerImage && target.goos !== "linux") {+ fail("--container-image requires a linux target");+}if (containerImage && !/^[a-z0-9][a-z0-9._/:+-]*$/.test(containerImage)) {fail("Container image tag is invalid");}@@ -199,7 +212,8 @@ try {mkdirSync(runtimeRoot, { recursive: true });copyFileSync(join(repositoryRoot, "LICENSE"), join(runtimeRoot, "LICENSE"));const goCommand = process.env.PIIK_GO?.trim() || "go";- const serverPath = join(runtimeRoot, SERVER_NAME);+ const binaryName = serverBinaryName(target);+ const serverPath = join(runtimeRoot, binaryName);run(goCommand, ["build","-trimpath",@@ -214,7 +228,7 @@ try {GOARCH: target.goarch,CGO_ENABLED: "0",});- chmodSync(serverPath, 0o755);+ if (target.goos !== "windows") chmodSync(serverPath, 0o755);writeServerLicenseNotices(repositoryRoot,join(runtimeRoot, "THIRD-PARTY-NOTICES.txt"),@@ -224,10 +238,12 @@ try {assertCleanRevision(repositoryRoot, revision);writeFileSync(join(runtimeRoot, "REVISION"), `${revision}\n`, "ascii");- const records = recordsFor(runtimeRoot);+ const paths = runtimePaths(target);+ const records = recordsFor(runtimeRoot, paths);const stem = `piik-${releaseId}${target.suffix}`;const manifestName = `${stem}.manifest.tsv`;- const artifactName = `${stem}-runtime.tar.gz`;+ const archiveKind = target.goos === "windows" ? "zip" : "tar.gz";+ const artifactName = `${stem}-runtime.${archiveKind}`;const descriptorName = `${stem}.release.json`;mkdirSync(outputRoot, { recursive: false, mode: 0o700 });outputOwned = true;@@ -240,12 +256,18 @@ try {"ascii",);- const tar = tarExecutable();- run(tar, ["-czf", artifactPath, "-C", runtimeRoot, "."], repositoryRoot);- validateArchiveEntries(run(tar, ["-tzf", artifactPath], repositoryRoot));- mkdirSync(verifyRoot);- run(tar, ["-xzf", artifactPath, "-C", verifyRoot], repositoryRoot);- compareRecords(records, recordsFor(verifyRoot));+ if (archiveKind === "zip") {+ createZip(runtimeRoot, artifactPath);+ mkdirSync(verifyRoot);+ extractZip(artifactPath, verifyRoot);+ } else {+ const tar = tarExecutable();+ run(tar, ["-czf", artifactPath, "-C", runtimeRoot, "."], repositoryRoot);+ validateArchiveEntries(run(tar, ["-tzf", artifactPath], repositoryRoot), paths);+ mkdirSync(verifyRoot);+ run(tar, ["-xzf", artifactPath, "-C", verifyRoot], repositoryRoot);+ }+ compareRecords(records, recordsFor(verifyRoot, paths));const descriptor = {schema: 2,diff --git a/scripts/publish-container.mjs b/scripts/publish-container.mjsindex 1e077ef9..91d51a65 100644--- a/scripts/publish-container.mjs+++ b/scripts/publish-container.mjs@@ -9,6 +9,9 @@ if (process.argv.length !== 6 || !image) {throw new Error("Usage: node scripts/publish-container.mjs <local-image-prefix> <artifacts> <version> <full-SHA>");}const { servers } = readReleaseArtifacts(directory, version, revision);+// Only the Linux Server packages have a container image; a Windows Server+// package shares the `amd64` arch but is a ZIP with no image of its own.+const linuxServers = servers.filter(server => server.goos === "linux");const repository = process.env.GITHUB_REPOSITORY || "TNTcraftHIM/Piik";const destination = `ghcr.io/${repository.toLowerCase()}`;const run = (command, ...args) => execFileSync(command, args, {@@ -47,20 +50,20 @@ function manifest(reference) {function verifyIndex(reference, index) {assert.deepEqual(index.manifests.map(item => `${item.platform.os}/${item.platform.architecture}`).sort(),- servers.map(server => `linux/${server.arch}`).sort(), "Container platforms differ from the release");- for (const server of servers) {+ linuxServers.map(server => `linux/${server.arch}`).sort(), "Container platforms differ from the release");+ for (const server of linuxServers) {run("docker", "pull", "--platform", `linux/${server.arch}`, reference);verifyImage(reference, server);}}-for (const server of servers) verifyImage(`${image}-${server.arch}`, server);+for (const server of linuxServers) verifyImage(`${image}-${server.arch}`, server);const existing = manifest(tag);if (existing) {verifyIndex(tag, existing);process.stdout.write(`${tag} already exists; retained without replacement.\n`);} else {- const parts = servers.map(server => ({ server, tag: `${tag}-${server.arch}` }));+ const parts = linuxServers.map(server => ({ server, tag: `${tag}-${server.arch}` }));// Validate every existing platform before publishing any missing sibling.for (const part of parts) {part.exists = manifest(part.tag) !== null;diff --git a/scripts/release-artifacts.mjs b/scripts/release-artifacts.mjsindex 595f75f7..643f999b 100644--- a/scripts/release-artifacts.mjs+++ b/scripts/release-artifacts.mjs@@ -43,7 +43,7 @@ export function readReleaseArtifacts(directory, version, revision) {if (asset(descriptor.manifest).sha256 !== descriptor.manifestSha256) {throw new Error("Server manifest checksum mismatch");}- servers.push({ ...archive, arch: serverTarget.goarch });+ servers.push({ ...archive, arch: serverTarget.goarch, goos: serverTarget.goos });} else if (readFileSync(asset(`${descriptor.artifact}.sha256`).path, "utf8").trim() !==`${descriptor.artifactSha256} ${descriptor.artifact}`) {throw new Error(`App checksum file mismatch: ${target}`);diff --git a/scripts/release-headline.mjs b/scripts/release-headline.mjsindex 83a20944..8d98a2b5 100644--- a/scripts/release-headline.mjs+++ b/scripts/release-headline.mjs@@ -1,11 +1,25 @@-// The release editor owns two leading bold paragraphs: English, then Chinese.-// Read only that pair; older release prose is not an inferred headline.+// Each language opens with a bold title and one plain description paragraph.+// Published title-only pairs remain readable; ordinary release prose is not a headline.+const gap = String.raw`[ \t]*\r?\n(?:[ \t]*\r?\n)+`;+const title = String.raw`\*\*([^*\r\n]+)\*\*`;+const description = String.raw`([^*#<>\r\n]+)`;+const end = `(?:${gap}|[ \\t]*$)`;+const explainedOpening = new RegExp(`^\\s*${title}${gap}${description}${gap}${title}${gap}${description}${end}`);+const titleOpening = new RegExp(`^\\s*${title}${gap}${title}${end}`);+export function splitReleaseHeadline(body) {if (typeof body !== "string") return { headline: null, notes: "" };- const opening = /^\s*\*\*([^*\r\n]+)\*\*[ \t]*\r?\n(?:[ \t]*\r?\n)+\*\*([^*\r\n]+)\*\*(?:[ \t]*\r?\n(?:[ \t]*\r?\n)+|[ \t]*$)/.exec(body);- if (!opening || !opening[1].trim() || !opening[2].trim()) return { headline: null, notes: body };+ const explained = explainedOpening.exec(body);+ const opening = explained ?? titleOpening.exec(body);+ if (!opening || opening.slice(1).some(text => !text.trim())) return { headline: null, notes: body };return {- headline: { en: opening[1].trim(), "zh-CN": opening[2].trim() },+ headline: explained ? {+ en: { title: opening[1].trim(), description: opening[2].trim() },+ "zh-CN": { title: opening[3].trim(), description: opening[4].trim() },+ } : {+ en: { title: opening[1].trim(), description: "" },+ "zh-CN": { title: opening[2].trim(), description: "" },+ },notes: body.slice(opening[0].length).trimStart(),};}diff --git a/scripts/release-notes.mjs b/scripts/release-notes.mjsindex 64f0a18a..89faa49e 100644--- a/scripts/release-notes.mjs+++ b/scripts/release-notes.mjs@@ -53,7 +53,8 @@ export function releaseNotes(root, version, revision, repository, { allowEmpty =const source = previous? `[Full changelog / 完整变更](${url}/compare/${previous}...${revision})`: `[Source / 源代码](${url}/tree/${revision})`;- const opening = headline ? `**${headline.en}**\n\n**${headline["zh-CN"]}**\n\n` : "";+ const opening = headline ? [headline.en, headline["zh-CN"]]+ .map(({ title, description }) => `**${title}**${description ? `\n\n${description}` : ""}`).join("\n\n") + "\n\n" : "";return `${opening}${bodies.join("\n\n")}\n\n---\n\n${source}\n`;}diff --git a/scripts/room-voice-gate.ts b/scripts/room-voice-gate.tsnew file mode 100644index 00000000..afb7731a--- /dev/null+++ b/scripts/room-voice-gate.ts@@ -0,0 +1,444 @@+// Normal Host/Viewer acceptance: room activation, capture and real WebRTC.+import { spawn, execFile, type ChildProcessWithoutNullStreams } from "node:child_process";+import { createSocket } from "node:dgram";+import { mkdir, mkdtemp, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join, resolve } from "node:path";+import { promisify } from "node:util";+import { createServer as createViteServer, type ViteDevServer } from "vite";+import type { RoomVoiceState } from "../src/shared/protocol";+import { CdpConnection, cleanupRun, evaluate, fetchJsonBefore, launchChrome,+ reservePort, waitForSample, waitForVersion, type PageHandle } from "./browser-gate-harness";++const ROOT = resolve(import.meta.dirname, "..");+const OUTPUT = join(ROOT, "build", "voice-integration");+const runFile = promisify(execFile);+const redact = (value: string) => value.replace(/#v=[A-Za-z0-9_-]+/g, "#v=[redacted]");+type Page = PageHandle & { targetId: string; session: string };+type Sample = { voice: RoomVoiceState | null; peerId: string | null; inviteUrl: string | null; authentications: number;+ energy: number; samples: number; bytes: number; playing: number; mutedPlayback: number; enabled: boolean; liveMicrophones: number; videoFrames: number; text: string; controls: string[] };++// Observe the normal browser boundary; no alternate session or control protocol.+const probe = (name: string) => `(() => {+ localStorage.setItem('piik:ui-lang','en'); localStorage.setItem('piik:ui-mode','text');+ localStorage.setItem('piik:display-name:v1',${JSON.stringify(name)});+ const peers=[], sockets=[], captures=[], NativePC=RTCPeerConnection, NativeWS=WebSocket;+ const gate=window.__roomVoiceGate={peers,sockets,captures,voice:null,peerId:null,inviteUrl:null,wire:[],authentications:0};+ const record=(direction,m)=>{+ if(!m.type.startsWith('room-voice-')&&!['room-interaction','route-diagnostic-snapshot','peer-state'].includes(m.type))return;+ const summary={...m};+ if(m.description)summary.description={revision:m.description.revision,type:m.description.sdp.type,tracks:m.description.tracks,+ media:m.description.sdp.sdp.split('\\r\\n').filter(line=>/^m=|^a=mid:|^a=(sendrecv|sendonly|recvonly|inactive)/.test(line))};+ if(m.candidate)summary.candidate=m.candidate.candidate.split(' ').slice(0,8).join(' ');+ gate.wire.push({direction,time:Date.now(),...summary});if(gate.wire.length>120)gate.wire.shift();+ };+ window.RTCPeerConnection=class extends NativePC { constructor(...a){super(...a);const index=peers.length;peers.push(this);+ this.addEventListener('iceconnectionstatechange',async()=>{+ const state={type:'peer-state',index,ice:this.iceConnectionState,connection:this.connectionState,+ gathering:this.iceGatheringState,signaling:this.signalingState};+ try{const stats=await this.getStats();state.stats=[...stats.values()].filter(row=>['transport','candidate-pair','local-candidate','remote-candidate'].includes(row.type))+ .map(row=>Object.fromEntries(['id','type','state','iceState','dtlsState','selectedCandidatePairId','localCandidateId','remoteCandidateId','candidateType','address','port','protocol','nominated','requestsSent','responsesReceived','requestsReceived','responsesSent'].filter(key=>key in row).map(key=>[key,row[key]])));}catch{}+ record('browser',state);+ });+ }};+ window.WebSocket=class extends NativeWS { constructor(...a){super(...a);sockets.push(this);+ this.addEventListener('message',event=>{try{const m=JSON.parse(event.data);+ record('receive',m);if(m.type==='room-voice-state')gate.voice=m;+ if(m.type==='authenticated'){gate.peerId=m.peerId;gate.authentications++;gate.voice=null;}+ }catch{}});+ }send(data){try{record('send',JSON.parse(data));}catch{}return super.send(data);}};+ const originalFetch=window.fetch;+ window.fetch=async(...a)=>{const response=await originalFetch(...a);+ if(String(a[0]).endsWith('/api/rooms')&&a[1]?.method==='POST') {+ const created=await response.clone().json();gate.inviteUrl=created.inviteUrl;+ }return response;+ };+ const gum=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);+ navigator.mediaDevices.getUserMedia=async(...a)=>{const stream=await gum(...a);captures.push(stream);return stream;};+ gate.sample=async()=>{+ const audio=[...document.querySelectorAll('audio')].filter(node=>node.srcObject);+ const ids=new Set(audio.flatMap(node=>node.srcObject.getAudioTracks().map(track=>track.id)));+ let energy=0, samples=0, bytes=0;+ for(const peer of peers)if(peer.connectionState==='connected')for(const row of (await peer.getStats()).values())+ if(row.type==='inbound-rtp'&&row.kind==='audio'&&ids.has(row.trackIdentifier)){+ energy+=row.totalAudioEnergy||0;samples+=row.totalSamplesReceived||0;bytes+=row.bytesReceived||0;+ }+ return {voice:gate.voice,peerId:gate.peerId,inviteUrl:gate.inviteUrl,authentications:gate.authentications,energy,samples,bytes,wire:gate.wire,+ playing:audio.length,mutedPlayback:audio.filter(node=>node.muted).length,enabled:audio.every(node=>node.srcObject.getAudioTracks().every(t=>t.enabled)),+ tracks:audio.flatMap(node=>node.srcObject.getAudioTracks().map(t=>({readyState:t.readyState,muted:t.muted,currentTime:node.currentTime}))),+ connections:peers.map(p=>({state:p.connectionState,signaling:p.signalingState,senders:p.getSenders().map(s=>s.track&&({kind:s.track.kind,readyState:s.track.readyState,enabled:s.track.enabled,muted:s.track.muted}))})),+ liveMicrophones:captures.flatMap(s=>s.getAudioTracks()).filter(t=>t.readyState==='live').length,+ videoFrames:[...document.querySelectorAll('video')].reduce((sum,node)=>sum+(node.getVideoPlaybackQuality?.().totalVideoFrames||0),0),+ text:document.body.innerText.slice(-1200),controls:[...document.querySelectorAll('button[aria-label]')].map(node=>node.getAttribute('aria-label'))};+ };+})()`;++function audioFixture(): Buffer {+ const rate = 48000, samples = rate * 2, data = Buffer.alloc(44 + samples * 2);+ data.write("RIFF"); data.writeUInt32LE(data.length - 8, 4); data.write("WAVEfmt ", 8);+ data.writeUInt32LE(16, 16); data.writeUInt16LE(1, 20); data.writeUInt16LE(1, 22);+ data.writeUInt32LE(rate, 24); data.writeUInt32LE(rate * 2, 28); data.writeUInt16LE(2, 32);+ data.writeUInt16LE(16, 34); data.write("data", 36); data.writeUInt32LE(samples * 2, 40);+ for (let i = 0; i < samples; i++) {+ const time = i / rate, pulse = .4 + .6 * Math.sin(2 * Math.PI * 3.3 * time) ** 2;+ const pitch = 180 * time + 13 * Math.sin(time * 5);+ data.writeInt16LE(Math.round(2400 * pulse * (Math.sin(2 * Math.PI * pitch) + .4 * Math.sin(4 * Math.PI * pitch))), 44 + i * 2);+ }+ return data;+}++async function udpPort(): Promise<number> {+ const socket = createSocket("udp4");+ return new Promise((accept, reject) => {+ socket.once("error", reject);+ socket.bind(0, "127.0.0.1", () => { const port = socket.address().port; socket.close(() => accept(port)); });+ });+}++async function main(): Promise<void> {+ if (process.env.PIIK_ROOM_VOICE_GATE !== "true") throw new Error("Set PIIK_ROOM_VOICE_GATE=true for this local acceptance gate");+ const executable = process.env.PIIK_SERVER_EXE || join(OUTPUT, `piik-server${process.platform === "win32" ? ".exe" : ""}`);+ const chromePath = process.env.CHROME_PATH;+ if (!chromePath) throw new Error("CHROME_PATH is required");+ const agentBrowser = process.env.AGENT_BROWSER_PATH || (process.platform === "win32"+ ? join(process.env.APPDATA!, "npm/node_modules/agent-browser/bin/agent-browser-win32-x64.exe") : "agent-browser");+ const sfuOnly = process.env.PIIK_ROOM_VOICE_SFU === "true";+ const arm = sfuOnly ? "sfu" : "peer";+ const serverPort = Number(process.env.PIIK_ROOM_VOICE_PORT || (sfuOnly ? 19162 : 19161));+ const [vitePort, debugPort, mediaPort] = await Promise.all([reservePort(), reservePort(), udpPort()]);+ const origin = `http://127.0.0.1:${vitePort}`, backend = `http://127.0.0.1:${serverPort}`;+ const legacyRoot = process.env.PIIK_ROOM_VOICE_LEGACY_WEB;+ const legacyPort = legacyRoot ? await reservePort() : null;+ const legacyOrigin = legacyPort ? `http://127.0.0.1:${legacyPort}` : null;+ const legacyRevision = legacyRoot ? (await runFile("git", ["-C", legacyRoot, "rev-parse", "HEAD"], { windowsHide: true })).stdout.trim() : null;+ const profile = await mkdtemp(join(tmpdir(), "piik-client-media-"));+ await mkdir(OUTPUT, { recursive: true });+ const audio = join(OUTPUT, "microphone.wav");+ await writeFile(audio, audioFixture());+ let server: ChildProcessWithoutNullStreams | null = null, chrome: ChildProcessWithoutNullStreams | null = null;+ let cdp: CdpConnection | null = null, vite: ViteDevServer | null = null, legacyVite: ViteDevServer | null = null;+ let serverLog = "";+ const pages: Page[] = [];+ const result = { arm, legacyRevision, passed: false, stage: "start", checks: [] as string[], error: null as string | null,+ diagnostics: [] as unknown[], cleanup: null as unknown };+ const ui = async (page: Page, ...args: string[]) => {+ if (args[0] === "click") await waitForSample(() => evaluate<boolean>(cdp!, page,+ `!!document.querySelector(${JSON.stringify(args[1])})`, Date.now() + 3000), Boolean, 15_000);+ const response = await runFile(agentBrowser, ["--session", page.session, "--cdp", String(debugPort), ...args],+ { cwd: ROOT, timeout: 15_000, windowsHide: true, maxBuffer: 1024 * 1024 });+ return response.stdout;+ };+ const sample = (page: Page) => evaluate<Sample>(cdp!, page, "window.__roomVoiceGate.sample()", Date.now() + 4000);+ const until = async (page: Page, accept: (state: Sample) => boolean, label: string) => {+ result.stage = label;+ let last: Sample | null = null;+ try { await waitForSample(() => sample(page), value => { last = value; return accept(value); }, 25_000, 200); }+ catch { const failed = last as Sample | null; throw new Error(`${label}: ${JSON.stringify(failed && {+ revision: failed.voice?.revision, connections: failed.voice?.connections.length, unavailable: failed.voice?.unavailable.length,+ energy: failed.energy, samples: failed.samples, bytes: failed.bytes, liveMicrophones: failed.liveMicrophones, text: failed.text,+ })}`); }+ return last!;+ };+ const button = (page: Page, name: string) => ui(page, "find", "role", "button", "click", "--name", name, "--exact");+ const memberButton = async (page: Page, name: string, action: string) => {+ let index = -1;+ await waitForSample(() => evaluate<number>(cdp!, page,+ `[...document.querySelectorAll('.lr-voice-member')].findIndex(node=>node.querySelector('b')?.textContent.includes(${JSON.stringify(name)})&&node.querySelector('button[aria-label=${JSON.stringify(action)}]'))`,+ Date.now() + 3000), value => { index = value; return value >= 0; }, 5000);+ const selector = `.lr-voice-member:nth-child(${index + 1}) button[aria-label=${JSON.stringify(action)}]`;+ await ui(page, "scrollintoview", selector);+ return ui(page, "click", selector);+ };+ const openVoice = async (page: Page) => {+ await button(page, "Interact");+ await waitForSample(() => evaluate<boolean>(cdp!, page,+ `!!document.querySelector('[role="tab"][id$="-voice-tab"]')`, Date.now() + 3000), Boolean, 5000);+ await ui(page, "find", "role", "tab", "click", "--name", "Voice", "--exact");+ };+ const check = (label: string) => { result.checks.push(label); process.stdout.write(`${arm}: ${label}\n`); };+ try {+ server = spawn(executable, [], { cwd: ROOT, stdio: "pipe", windowsHide: true,+ env: { PATH: process.env.PATH, SystemRoot: process.env.SystemRoot, PIIK_ENV: "development",+ LISTEN_HOST: "127.0.0.1", PORT: String(serverPort), PIIK_LOG_DIR: join(OUTPUT, `${arm}-logs`),+ ROOM_DATABASE_PATH: join(profile, "rooms.sqlite"), PIIK_DEBUG: "route",+ PUBLIC_BASE_URL: origin, ALLOWED_ORIGINS: [origin, legacyOrigin].filter(Boolean).join(","), SFU_LISTEN_HOST: "127.0.0.1",+ SFU_UDP_PORT: String(mediaPort), SFU_PUBLIC_IP: "127.0.0.1", SFU_ONLY: String(sfuOnly),+ ENDPOINT_MEDIA_COPY_CAPACITY: "1" } });+ server.stdout.resume();+ server.stderr.on("data", (data: Buffer) => { serverLog = (serverLog + data.toString()).slice(-12000); });+ await waitForSample(deadline => fetchJsonBefore(`${backend}/healthz`, deadline), () => true, 15_000);+ vite = await createViteServer({ root: ROOT, logLevel: "error", server: { host: "127.0.0.1", port: vitePort, watch: null,+ strictPort: true, proxy: { "/api": { target: backend }, "/healthz": { target: backend }, "/signal": { target: backend, ws: true } } } });+ await vite.listen();+ if (legacyRoot && legacyPort) {+ legacyVite = await createViteServer({ root: legacyRoot, logLevel: "error", optimizeDeps: { entries: ["index.html"] }, server: { host: "127.0.0.1", port: legacyPort,+ watch: null, strictPort: true, proxy: { "/api": { target: backend }, "/healthz": { target: backend }, "/signal": { target: backend, ws: true } } } });+ await legacyVite.listen();+ }+ chrome = await launchChrome(chromePath, debugPort, profile, ["--headless=new", "--no-first-run",+ "--window-size=1280,900",+ // Chromium excludes loopback ICE by default; this gate's SFU binds only localhost.+ // https://chromium.googlesource.com/chromium/src/+/HEAD/content/public/common/content_switches.cc+ "--allow-loopback-in-peer-connection",+ "--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream", "--autoplay-policy=no-user-gesture-required",+ `--use-file-for-fake-audio-capture=${audio}`]);+ const version = await waitForVersion(debugPort, chrome);+ cdp = await CdpConnection.connect(version.webSocketDebuggerUrl, Date.now() + 10_000);+ const page = async (url: string, name: string): Promise<Page> => {+ const { browserContextId } = await cdp!.call<{ browserContextId: string }>("Target.createBrowserContext", {}, undefined, Date.now() + 5000);+ const { targetId } = await cdp!.call<{ targetId: string }>("Target.createTarget", { url: "about:blank", browserContextId }, undefined, Date.now() + 5000);+ const { sessionId } = await cdp!.call<{ sessionId: string }>("Target.attachToTarget", { targetId, flatten: true }, undefined, Date.now() + 5000);+ const current = { targetId, sessionId, session: `piik-voice-${arm}-${process.pid}-${pages.length}` };+ pages.push(current);+ await cdp!.call("Page.enable", {}, sessionId, Date.now() + 5000);+ await cdp!.call("Page.addScriptToEvaluateOnNewDocument", { source: probe(name) }, sessionId, Date.now() + 5000);+ await cdp!.call("Page.navigate", { url }, sessionId, Date.now() + 5000);+ await ui(current, "--pin-tab", "tab", targetId);+ return current;+ };+ const host = await page(origin, "Voice Host");+ await until(host, state => state.controls.includes("Create room"), "idle Host");+ if ((await sample(host)).inviteUrl) throw new Error("Page visit allocated a room");+ await ui(host, "screenshot", join(OUTPUT, `${arm}-idle-room.png`), "--full");+ await button(host, "Create room");+ const created = await until(host, state => !!state.inviteUrl && !!state.voice, "create idle room");+ if (created.liveMicrophones) throw new Error("Room creation started a microphone");+ await openVoice(host);+ const viewer = await page(created.inviteUrl!, "Voice Viewer");+ await until(viewer, state => !!state.voice, "Viewer authenticates before sharing");+ await openVoice(viewer);+ if (await evaluate<boolean>(cdp, viewer,+ `!document.querySelector('button[aria-label="Join voice"]')?.matches(':disabled,[aria-disabled="true"]')`, Date.now() + 3000)) throw new Error("Viewer can join before Host opens room voice");+ await button(host, "Open room voice");+ await until(viewer, state => !!state.voice?.enabled, "Host opens room voice");+ await button(viewer, "Join voice");+ await until(viewer, state => !!state.voice?.members.find(member => member.peerId === state.peerId)?.joined, "Viewer joins without approval");+ if ((await sample(host)).liveMicrophones || (await sample(viewer)).liveMicrophones) throw new Error("Joining started a microphone");+ await button(host, "Microphone");+ await button(viewer, "Microphone");+ await until(host, state => state.energy > 0 && state.voice?.publications.length === 2, "Host receives Viewer");+ const initial = await until(viewer, state => state.energy > 0 && state.voice?.publications.length === 2, "Viewer receives Host");+ if (!initial.voice?.connections.some(connection => connection.transport === (sfuOnly ? "sfu" : "peer"))) throw new Error("Wrong transport");+ check("Host opens voice, Viewer joins freely, explicit microphones carry bidirectional audio");+ await cdp.call("Page.bringToFront", {}, host.sessionId, Date.now() + 3000);+ const microphonePoint = await evaluate<{ x: number; y: number }>(cdp, host,+ `(()=>{const r=document.querySelector('.lr-voice-quick-controls button[aria-label="Microphone"]').getBoundingClientRect();return{x:r.x+r.width/2,y:r.y+r.height/2}})()`, Date.now() + 3000);+ await cdp.call("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 1 }, host.sessionId, Date.now() + 3000);+ await cdp.call("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [microphonePoint] }, host.sessionId, Date.now() + 3000);+ await waitForSample(() => evaluate<boolean>(cdp!, host,+ `!!document.querySelector('.lr-audio-volume-popover:popover-open')`, Date.now() + 3000), Boolean, 5000, 50);+ await cdp.call("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }, host.sessionId, Date.now() + 3000);+ await ui(host, "focus", '.lr-audio-volume-popover:popover-open input[aria-label="Microphone volume"]');+ await ui(host, "press", "End");+ await ui(host, "press", "Escape");+ await cdp.call("Emulation.setTouchEmulationEnabled", { enabled: false }, host.sessionId, Date.now() + 3000);+ const afterVolume = await sample(host);+ if (afterVolume.liveMicrophones !== 1 || afterVolume.voice?.publications.length !== 2 || !await evaluate<boolean>(cdp, host,+ `!document.querySelector('.lr-audio-volume-popover:popover-open')&&!!document.querySelector('.lr-interaction-panel:popover-open')`, Date.now() + 3000)) {+ throw new Error("Touch volume adjustment toggled the microphone or closed its containing voice window");+ }+ check("touch hold opens volume without muting; keyboard adjustment and Escape retain the voice window");+ let leaf: Page | null = null;+ if (!sfuOnly) {+ leaf = await page(created.inviteUrl!, "Voice Listener");+ await until(leaf, state => !!state.voice, "third normal Viewer authenticates");+ await openVoice(leaf);+ await button(leaf, "Join voice");+ const relay = await sample(viewer);+ await until(leaf, state => state.playing === 2 && state.energy > 0 && !!state.voice?.connections.some(connection =>+ connection.parentPeerId === relay.peerId && !connection.pending && connection.receive.length === 2), "two speakers through normal Viewer relay");+ check("two simultaneous publications decoded by a third Viewer through shared relay graph");+ }+ let legacyViewer: Page | null = null;+ if (legacyOrigin) {+ const invitation = new URL(created.inviteUrl!);+ legacyViewer = await page(`${legacyOrigin}${invitation.pathname}${invitation.hash}`, "Older Viewer");+ await until(legacyViewer, state => state.authentications === 1 && state.controls.includes("Interact"), "older Viewer joins before picture sharing");+ }+ result.stage = "voice-only topology";+ for (const [index, participant] of [host, viewer].entries()) {+ await button(participant, "Hide interaction window");+ await button(participant, "Show connection topology");+ await waitForSample(() => evaluate<boolean>(cdp!, participant, `(() => {+ const state=window.__roomVoiceGate.voice, tree=document.getElementById('room-topology');+ const expected=state?.members.filter(member=>member.peerId!==state.hostPeerId&&member.connected&&member.joined&&member.upstream.kind!=='none').length;+ return expected>0&&tree?.querySelectorAll('.lr-route-edge:not(.is-pending)').length>=expected;+ })()`, Date.now() + 3000), Boolean, 5000);+ await ui(participant, "screenshot", join(OUTPUT, `${arm}-voice-topology-${index}.png`), "--full");+ await button(participant, "Hide connection topology");+ await openVoice(participant);+ }+ check("Host and Viewer topology display connected voice routes before picture sharing");+ await button(host, "Interact with Voice Viewer");+ await waitForSample(() => evaluate<boolean>(cdp!, host, `(() => {+ const menu=document.querySelector('.lr-quick-reactions'), roster=document.querySelector('.lr-voice-history');+ return !!menu?.matches(':popover-open')&&menu.querySelectorAll('.lr-reaction-grid button').length===4&&+ !!roster?.getClientRects().length&&!!document.querySelector('.lr-voice-toolbar')?.getClientRects().length;+ })()`, Date.now() + 3000), Boolean, 5000);+ await button(host, "Toss poop");+ await waitForSample(() => evaluate<boolean>(cdp!, viewer,+ `window.__roomVoiceGate.wire.some(message=>message.direction==='receive'&&message.type==='room-interaction'&&message.payload.kind==='reaction'&&message.payload.reaction==='poop'&&message.payload.targetPeerId===window.__roomVoiceGate.peerId)`,+ Date.now() + 3000), Boolean, 5000);+ await ui(viewer, "screenshot", join(OUTPUT, `${arm}-voice-reaction.png`));+ check("voice participant picker sends a correctly targeted reaction to the other normal page");+ await button(host, "Voice settings");+ await button(host, "Back");+ const beforeMute = await sample(host);+ const oldPublication = beforeMute.voice!.publications.find(publication => publication.peerId === beforeMute.peerId)!.id;+ const voiceConnections = beforeMute.voice!.connections.filter(connection => !connection.pending).map(connection => connection.connectionId).sort();+ await button(host, "Microphone");+ await until(host, state => state.liveMicrophones === 0 && state.voice?.publications.length === 1 &&+ !!state.voice.members.find(member => member.peerId === state.peerId)?.joined, "microphone off retains voice membership");+ await until(viewer, state => state.playing === 0 && state.voice?.publications.length === 1, "retired microphone removed from playback");+ await button(host, "Microphone");+ await until(host, state => state.liveMicrophones === 1 && state.voice?.publications.length === 2, "microphone restarts within joined channel");+ const restarted = await until(viewer, state => state.playing === 1 && state.energy > 0 && state.voice?.publications.length === 2,+ "replacement microphone produces decoded audio");+ await until(viewer, state => state.samples > restarted.samples, "replacement microphone continues producing samples");+ const afterMute = await sample(host);+ if (afterMute.voice!.publications.find(publication => publication.peerId === afterMute.peerId)!.id === oldPublication ||+ JSON.stringify(afterMute.voice!.connections.filter(connection => !connection.pending).map(connection => connection.connectionId).sort()) !== JSON.stringify(voiceConnections)) {+ throw new Error("Microphone restart reused retired publication or replaced the room route");+ }+ if (leaf) await until(leaf, state => state.playing === 2 && state.voice?.publications.length === 2, "relay receives replacement microphone exactly once");+ check("microphone restart replaces its publication without leaving voice, duplicating playback or replacing the route");+ await memberButton(viewer, "Voice Host", "Listen to this person");+ const muted = await sample(viewer);+ await until(viewer, state => state.enabled && state.samples > muted.samples, "local mute retains received media");+ if (leaf) {+ const before = await sample(leaf);+ await until(leaf, state => state.playing === 2 && state.samples > before.samples, "relay continues after local playback mute");+ }+ check("local mute retains enabled incoming track and media progress");+ await button(viewer, "Listen to voice");+ const deafened = await until(viewer, state => state.liveMicrophones === 1 && state.playing > 0 &&+ state.mutedPlayback === state.playing && state.voice?.publications.length === 2, "pause listening preserves microphone");+ await until(viewer, state => state.enabled && state.samples > deafened.samples, "deafen retains incoming media");+ if (leaf) {+ const before = await sample(leaf);+ await until(leaf, state => state.playing === 2 && state.samples > before.samples, "relay still forwards both speakers while not listening");+ }+ await button(viewer, "Listen to voice");+ const listening = await sample(viewer);+ if (listening.liveMicrophones !== 1 || listening.mutedPlayback !== listening.playing) throw new Error("Resuming listening changed microphone or per-person mute");+ await memberButton(viewer, "Voice Host", "Listen to this person");+ await until(viewer, state => state.mutedPlayback === 0, "individual mute remains independent of deafen");+ if (leaf) await until(leaf, state => state.playing === 2, "relay listeners regain both speakers");+ check("local listening, microphone and per-person mute remain independent and preserve forwarding");+ await button(host, "Voice settings");+ await ui(host, "focus", '.lr-interaction-settings input[aria-label="Microphone volume"]');+ await ui(host, "press", "End");+ await button(host, "Back");+ check("one room microphone setting surface supplies device, gain and speech processing");+ const beforeVideo = await sample(viewer);+ await button(host, "Hide interaction window");+ await button(host, "Start sharing");+ await ui(host, "find", "role", "tab", "click", "--name", "Camera", "--exact");+ await ui(host, "click", 'button[aria-label^="Share camera:"]');+ await until(host, state => state.text.includes("Stop sharing"), "camera sharing starts alongside voice");+ await until(viewer, state => state.samples > beforeVideo.samples && state.voice?.publications.length === 2, "voice survives video start");+ if (legacyViewer) await until(legacyViewer, state => state.videoFrames > 0 && state.voice === null && state.authentications === 1,+ "older Viewer receives picture without unsupported voice events");+ await button(host, "Stop sharing");+ const stopped = await sample(viewer);+ await until(viewer, state => state.samples > stopped.samples && state.voice?.publications.length === 2, "voice survives video stop");+ await button(host, "Start sharing");+ await ui(host, "find", "role", "tab", "click", "--name", "Camera", "--exact");+ await ui(host, "click", 'button[aria-label^="Share camera:"]');+ await until(host, state => state.text.includes("Stop sharing"), "camera sharing restarts");+ await until(viewer, state => state.videoFrames > 0, "Viewer decodes picture alongside room voice");+ await button(host, "Interact");+ check("camera share start/stop/restart preserves room microphones and voice");+ for (const width of [320, 390, 1280]) {+ await cdp.call("Emulation.setDeviceMetricsOverride", { width, height: 840, deviceScaleFactor: 1, mobile: width < 500 }, host.sessionId, Date.now() + 5000);+ await ui(host, "screenshot", join(OUTPUT, `${arm}-voice-${width}.png`));+ }+ check("mobile and desktop voice screenshots");+ await button(host, "Open in always-on-top window");+ await waitForSample(() => evaluate<boolean>(cdp!, host,+ "!!documentPictureInPicture.window?.document.querySelector('.lr-room-voice')", Date.now() + 3000), Boolean, 5000);+ const detached = await sample(viewer);+ await until(viewer, state => state.samples > detached.samples, "detached panel preserves voice");+ const { targetInfos } = await cdp.call<{ targetInfos: { targetId: string; title: string }[] }>("Target.getTargets", {}, undefined, Date.now() + 5000);+ const popup = targetInfos.find(target => target.title === "Interactions · Piik");+ if (!popup) throw new Error("Detached interaction window target missing");+ await ui(host, "--pin-tab", "tab", popup.targetId);+ await ui(host, "screenshot", join(OUTPUT, `${arm}-voice-detached.png`));+ await ui(host, "--pin-tab", "tab", host.targetId);+ await evaluate(cdp, host, "documentPictureInPicture.window.close()", Date.now() + 5000);+ await until(host, state => state.controls.includes("Microphone") && state.liveMicrophones === 1, "panel returns from detached window");+ check("actual detached shared voice window preserves capture and audio");+ await button(host, "Close room voice");+ for (const participant of [host, viewer, ...(leaf ? [leaf] : [])]) {+ await until(participant, state => !state.voice?.enabled && !state.liveMicrophones && !state.playing && !state.voice?.connections.length,+ "Host closes room voice and retires every participant's capture and playback");+ }+ const closedVoice = await sample(viewer);+ await until(viewer, state => state.videoFrames > closedVoice.videoFrames, "picture continues after channel close");+ if (legacyViewer) {+ const legacyBefore = await sample(legacyViewer);+ await until(legacyViewer, state => state.videoFrames > legacyBefore.videoFrames && state.voice === null && state.authentications === 1,+ "older Viewer retains picture after voice closes");+ check("older Web keeps picture sharing across voice activation and retirement without unsupported messages");+ }+ await button(host, "Open room voice");+ await until(viewer, state => !!state.voice?.enabled, "Host reopens room voice");+ if ((await sample(viewer)).liveMicrophones || (await sample(viewer)).voice?.members.find(member => member.peerId === (beforeVideo.peerId))?.joined) {+ throw new Error("Reopening restored Viewer membership or microphone automatically");+ }+ await button(viewer, "Join voice");+ await until(viewer, state => !!state.voice?.members.find(member => member.peerId === state.peerId)?.joined, "Viewer explicitly rejoins");+ await button(host, "Microphone");+ await button(viewer, "Microphone");+ await until(viewer, state => state.liveMicrophones === 1 && state.voice?.publications.length === 2, "explicit microphone restart");+ const restartedVoice = await sample(viewer);+ await until(viewer, state => state.samples > restartedVoice.samples && state.videoFrames > restartedVoice.videoFrames, "voice activates on an existing picture route");+ check("closing voice preserves picture; reopening adds voice to the existing picture route");+ for (const participant of [viewer, host]) {+ await evaluate(cdp, participant, `(() => {+ const connection=window.__roomVoiceGate.peers.find(peer=>peer.connectionState==='connected'&&peer.getTransceivers().length&&+ peer.getTransceivers().every(transceiver=>transceiver.receiver.track.kind==='audio'));+ if(!connection)throw new Error('No independent voice transport');+ connection.close();connection.dispatchEvent(new Event('connectionstatechange'));+ })()`, Date.now() + 5000);+ const failedVoice = await sample(viewer);+ await until(viewer, state => state.videoFrames > failedVoice.videoFrames, "voice transport failure leaves picture progressing");+ await until(viewer, state => state.energy > 0 && state.playing > 0 && !!state.voice?.connections.some(connection => !connection.pending), "voice transport recovers through room route owner");+ }+ check("independent voice transport failure retains healthy picture and uses ordinary room recovery");+ const beforeDisconnect = await sample(viewer);+ await evaluate(cdp, viewer, "window.__roomVoiceGate.sockets.at(-1).close()", Date.now() + 5000);+ await until(viewer, state => !state.liveMicrophones, "session loss stops capture");+ await until(viewer, state => state.authentications > beforeDisconnect.authentications &&+ !!state.voice?.members.find(member => member.peerId === state.peerId)?.connected, "normal signaling reconnect");+ if ((await sample(viewer)).liveMicrophones) throw new Error("Reconnect restored microphone automatically");+ check("closing room voice retires all audio; reopening and reconnect never restart microphones");+ result.passed = true;+ } catch (error) {+ result.error = redact(error instanceof Error ? error.message : String(error));+ if (pages[0]) try {+ await evaluate(cdp!, pages[0], `window.__roomVoiceGate.sockets.at(-1).send(JSON.stringify({type:'request-route-diagnostic'}))`, Date.now() + 3000);+ await new Promise(resolveWait => setTimeout(resolveWait, 150));+ } catch { /* disconnected sessions cannot request diagnostics */ }+ for (const [index, page] of pages.entries()) try {+ result.diagnostics.push(await sample(page));+ await ui(page, "screenshot", join(OUTPUT, `${arm}-failure-${index}.png`));+ } catch { /* page may have closed */ }+ process.stderr.write(`${result.error}\n${redact(serverLog)}\n`);+ } finally {+ for (const page of pages) try { await ui(page, "close"); } catch { /* cleanupRun owns remaining Chrome */ }+ if (legacyVite) await legacyVite.close();+ if (vite) await vite.close();+ const cleanup = await cleanupRun({ cdp, native: null, chrome, server, profile, ports: [serverPort, vitePort, debugPort, ...(legacyPort ? [legacyPort] : [])] });+ result.cleanup = cleanup;+ if (!Object.values(cleanup).every(Boolean)) {+ result.passed = false;+ result.error ??= "Gate resource cleanup failed";+ }+ await writeFile(join(OUTPUT, `${arm}-server.log`), redact(serverLog));+ await writeFile(join(OUTPUT, `${arm}-report.json`), `${redact(JSON.stringify(result, null, 2))}\n`);+ }+ if (!result.passed) process.exitCode = 1;+}++await main();diff --git a/scripts/server-package-targets.mjs b/scripts/server-package-targets.mjsindex 9826a848..5421677e 100644--- a/scripts/server-package-targets.mjs+++ b/scripts/server-package-targets.mjs@@ -1,5 +1,8 @@// Keep the published x64 archive name; additional architectures are explicit.+// A Windows target ships the same four runtime files with an `.exe` binary and a+// ZIP container, so `--os windows` selects it without touching the Linux names.export const SERVER_PACKAGE_TARGETS = [{ id: "server", goos: "linux", goarch: "amd64", suffix: "" },{ id: "server-linux-arm64", goos: "linux", goarch: "arm64", suffix: "-linux-arm64" },+ { id: "server-windows-amd64", goos: "windows", goarch: "amd64", suffix: "-windows-amd64" },];diff --git a/scripts/tsconfig.json b/scripts/tsconfig.jsonindex 127a721d..74843978 100644--- a/scripts/tsconfig.json+++ b/scripts/tsconfig.json@@ -31,6 +31,7 @@"app-media-gate.ts","app-native-host-gate.ts","embedded-sfu-gate.ts",+ "room-voice-gate.ts","embedded-sfu-page.ts","app-loopback-gate.ts","app-local-gate.ts",diff --git a/site/docs/pages.mjs b/site/docs/pages.mjsindex e573cb32..29d8f76f 100644--- a/site/docs/pages.mjs+++ b/site/docs/pages.mjs@@ -4,15 +4,19 @@ import { posix } from 'node:path';export const pages = [['docs/guide/README.md', 'index.md', 'Documentation', 'Start here'],['docs/guide/getting-started.md', 'getting-started.md', 'Getting started', 'Start here'],- ['docs/guide/troubleshooting.md', 'troubleshooting.md', 'Troubleshooting', 'Start here'],- ['cmd/piik-app/README.md', 'app.md', 'App reference', 'Start here'],+ ['docs/guide/sharing.md', 'sharing.md', 'Sharing and playback', 'Using Piik'],+ ['docs/guide/room-tools.md', 'room-tools.md', 'Chat, voice and remote control', 'Using Piik'],+ ['cmd/piik-app/README.md', 'app.md', 'App reference', 'Using Piik'],+ ['docs/guide/troubleshooting.md', 'troubleshooting.md', 'Troubleshooting', 'Get help'],['docs/operations/self-hosting.md', 'self-hosting.md', 'Deploy a site', 'Self-hosting'],['docs/operations/service-management.md', 'service-management.md', 'Run and update', 'Self-hosting'],['docs/guide/translating.md', 'translating.md', 'Translate Piik', 'Contribute'],['docs/guide/README.zh-CN.md', 'zh/index.md', '文档中心', '开始使用'],['docs/guide/getting-started.zh-CN.md', 'zh/getting-started.md', '快速上手', '开始使用'],- ['docs/guide/troubleshooting.zh-CN.md', 'zh/troubleshooting.md', '问题排查', '开始使用'],- ['cmd/piik-app/README.zh-CN.md', 'zh/app.md', 'App 使用参考', '开始使用'],+ ['docs/guide/sharing.zh-CN.md', 'zh/sharing.md', '分享与播放', '使用 Piik'],+ ['docs/guide/room-tools.zh-CN.md', 'zh/room-tools.md', '聊天、语音与远程控制', '使用 Piik'],+ ['cmd/piik-app/README.zh-CN.md', 'zh/app.md', 'App 使用参考', '使用 Piik'],+ ['docs/guide/troubleshooting.zh-CN.md', 'zh/troubleshooting.md', '问题排查', '遇到问题'],['docs/operations/self-hosting.zh-CN.md', 'zh/self-hosting.md', '部署站点', '自部署'],['docs/operations/service-management.zh-CN.md', 'zh/service-management.md', '运行与更新', '自部署'],['docs/guide/translating.zh-CN.md', 'zh/translating.md', '参与翻译', '参与项目'],diff --git a/site/film/ui/main.tsx b/site/film/ui/main.tsxindex 100f1262..948b998a 100644--- a/site/film/ui/main.tsx+++ b/site/film/ui/main.tsx@@ -15,8 +15,7 @@ import {import { CaptureSourcePicker } from "../../../src/client/components/living/CaptureSourcePicker";import { RoomInteractions } from "../../../src/client/components/living/RoomInteractions";import { RoomInteractionSession } from "../../../src/client/lib/room-interactions";-import { RoomChatOverlaySettings, RoomChatToggle } from "../../../src/client/components/living/RoomChatOverlay";-import { HostMicrophone } from "../../../src/client/components/living/HostMicrophone";+import { RoomChatToggle } from "../../../src/client/components/living/RoomChatOverlay";import { HostShareControls } from "../../../src/client/components/living/HostShareControls";import { PlaybackControlsView } from "../../../src/client/components/living/PlaybackControls";import { StatusIndicator } from "../../../src/client/components/living/StatusIndicator";@@ -236,7 +235,7 @@ function Screen({ shot }: { shot: Shot }) {picture={{ supported: true, active: false, failed: false, toggle: async () => {} }}togglePlayback={noop} toggleFullscreen={noop} toggleMute={noop} setLevel={noop}onToggleTheater={noop} onReconnect={noop} reconnectAvailable- overlayAction={<RoomChatToggle session={session} />} overlaySettings={<RoomChatOverlaySettings session={session} />} />}+ overlayAction={<RoomChatToggle session={session} />} />}{shot === "picker" && (<CaptureSourcePickernativeSources={{@@ -280,7 +279,6 @@ function Screen({ shot }: { shot: Shot }) {)}</StageTv>{!viewer && <HostShareControls actions={live ? <>- <HostMicrophone enabled={false} volume={1} onToggle={noop} /><Btn icon="switchSource" cap="host.switchSource" title="host.switchSource" hint="hint-switch-source" /></> : null}settings={<Btn icon="sliders" cap="host.settings.button" title="host.advanced" hint="hint-advanced" expanded={false} />}@@ -320,7 +318,7 @@ function Screen({ shot }: { shot: Shot }) {<Btn icon="pencil" cap="common.edit" title="host.nameEdit" hint="hint-rename" /></div><div className={`lr-row-group lr-group-actions ${viewer ? "lr-viewer-actions-slot" : "lr-host-diagnostics-slot"}`}>- <Btn icon="gauge" cap="host.details" title="host.details" hint="hint-details" disabled={!live} />+ <Btn icon="gauge" cap="host.details" title="host.details.show" hint="hint-details" disabled={!live} /><Btn icon="network" cap="host.topology" title="host.topology.show" hint="hint-topology" /></div></div>diff --git a/site/index.html b/site/index.htmlindex 9ab2bcc0..1e170254 100644--- a/site/index.html+++ b/site/index.html@@ -730,7 +730,7 @@><span lang="zh-CN">在电脑上运行 Piik App,在浏览器里操作。<br />观看朋友的分享,无须安装 Piik App。</span></p><a class="download-release" href="https://github.com/TNTcraftHIM/Piik/releases/latest">- <span class="download-headline" id="download-headline" hidden><span lang="en"></span><span lang="zh-CN"></span></span>+ <span class="download-headline" id="download-headline" hidden><span lang="en"><strong></strong><span></span></span><span lang="zh-CN"><strong></strong><span></span></span></span><span class="download-release-meta"><span id="download-release" hidden><span><span lang="en">Latest </span><span lang="zh-CN">最新版本 </span><b></b></span>diff --git a/site/main.js b/site/main.jsindex 4d8cecba..3bdfdfa3 100644--- a/site/main.js+++ b/site/main.js@@ -39,7 +39,12 @@ if (releaseLabel) {const { headline } = splitReleaseHeadline(metadata.body);if (headline) {const label = document.getElementById('download-headline');- for (const text of label.querySelectorAll('[lang]')) text.textContent = headline[text.lang];+ for (const text of label.querySelectorAll('[lang]')) {+ text.querySelector('strong').textContent = headline[text.lang].title;+ const description = text.querySelector('span');+ description.textContent = headline[text.lang].description;+ description.hidden = !headline[text.lang].description;+ }label.hidden = false;}}).catch(() => {}).finally(() => clearTimeout(timeout));diff --git a/site/styles.css b/site/styles.cssindex dfe8614c..440e7a91 100644--- a/site/styles.css+++ b/site/styles.css@@ -107,7 +107,10 @@ h3 { font-size: 21px; font-weight: 700; letter-spacing: -.03em; line-height: 1.3.steps li > p:last-child { margin-top: 12px; font-size: 14px; line-height: 1.75; color: var(--muted); }.download-section { padding-block: 76px 60px; }.download-release { display: inline-flex; max-width: 100%; flex-direction: column; align-items: center; gap: 5px; margin-top: 20px; color: var(--muted); font-size: 12px; text-decoration: none; }-.download-headline { max-width: 40em; color: var(--ink); font-size: 17px; font-weight: 650; text-wrap: balance; overflow-wrap: anywhere; }+.download-headline { max-width: 40em; text-wrap: balance; overflow-wrap: anywhere; }+.download-headline [lang] { display: flex; flex-direction: column; gap: 5px; }+.download-headline strong { color: var(--ink); font-size: 17px; font-weight: 650; }+.download-headline [lang] > span { color: var(--muted); font-size: 13px; line-height: 1.6; }.download-release-meta, #download-release:not([hidden]) { display: inline-flex; justify-content: center; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }#download-release > span, #download-release time { white-space: nowrap; }#download-release b { color: var(--ink); font-weight: 650; }diff --git a/src/client/components/living/AppConnectionButton.tsx b/src/client/components/living/AppConnectionButton.tsxindex 42cd9389..c3cb5f95 100644--- a/src/client/components/living/AppConnectionButton.tsx+++ b/src/client/components/living/AppConnectionButton.tsx@@ -5,6 +5,8 @@ import { useCopy } from "../../ui/copy";import { Glyph } from "../../ui/icons";import { Tooltip } from "./Tooltip";import { Comic } from "./Comic";+import { HintComic } from "./hints";+import { LoadingStatus } from "./WaitingStatus";import { useAnchoredPopover } from "./use-anchored-popover";interface AppConnectionProps {@@ -12,6 +14,13 @@ interface AppConnectionProps {onConnected?: () => void;}+interface ConnectionAttempt {+ controller: AbortController;+ popup: Window | null;+ open?: () => void;+ cancel?: () => void;+}+export function AppConnectionButton(props: AppConnectionProps) {// This is a desktop-package entry, not a test of Browser capture support.// iPad's desktop UA still identifies a touch-capable Mac platform.@@ -25,14 +34,14 @@ export function AppConnectionButton(props: AppConnectionProps) {function AppConnectionControl({ sourcePicker = false, onConnected }: AppConnectionProps) {const { t, vis } = useCopy();- const [state, setState] = useState<"idle" | "busy" | "ready" | "unavailable" | "incompatible">("idle");+ const [state, setState] = useState<"idle" | "busy" | "approval" | "approving" | "ready" | "unavailable" | "incompatible">("idle");const [helpOpen, setHelpOpen] = useState(false);const downloadURL = useProjectLink("/#download", "https://github.com/TNTcraftHIM/Piik/releases/latest", helpOpen);const helpId = useId();const trigger = useRef<HTMLButtonElement>(null);const help = useRef<HTMLDivElement>(null);useAnchoredPopover(trigger, help);- const pending = useRef<{ controller: AbortController; popup: Window | null } | null>(null);+ const pending = useRef<ConnectionAttempt | null>(null);const healthCheck = useRef<AbortController | null>(null);useEffect(() => {if (sourcePicker) return;@@ -66,20 +75,20 @@ function AppConnectionControl({ sourcePicker = false, onConnected }: AppConnecti}async function connect(): Promise<void> {- if (pending.current) return;+ if (pending.current) { pending.current.open?.(); return; }const manage = state === "ready";- help.current?.hidePopover();healthCheck.current?.abort();- // Reserve the window during the click, before local-network discovery waits.- const attempt = { controller: new AbortController(), popup: window.open("about:blank", "_blank") };- if (!attempt.popup) { setState("unavailable"); showHelp(); return; }+ // Discovery and its browser permission prompt stay in the current tab.+ // A fresh click opens the real approval page without reserving a blank tab.+ const attempt: ConnectionAttempt = { controller: new AbortController(), popup: null };pending.current = attempt;setState("busy");+ showHelp();const signal = attempt.controller.signal;let native: typeof import("../../native/client") | undefined;let approving = false;const onMessage = async (event: MessageEvent) => {- if (approving || event.source !== attempt.popup || !approvalOrigin || event.origin !== approvalOrigin ||+ if (approving || !attempt.popup || event.source !== attempt.popup || !approvalOrigin || event.origin !== approvalOrigin ||event.data?.type !== "piik-app-approved" || event.data.site !== window.location.origin) return;approving = true;// The approval message only asks us to recheck the App-owned permission.@@ -101,8 +110,10 @@ function AppConnectionControl({ sourcePicker = false, onConnected }: AppConnectipending.current = null;setState(result);if (result === "unavailable" || result === "incompatible") showHelp();+ else help.current?.hidePopover();}};+ attempt.cancel = () => finish(manage ? "ready" : "idle");const onFocus = () => {if (attempt.popup?.closed && !approving) finish("idle");};@@ -118,61 +129,69 @@ function AppConnectionControl({ sourcePicker = false, onConnected }: AppConnecticonst url = await native.discoverNativeConnect(signal);if (signal.aborted) return;if (!url) { finish("unavailable"); return; }- if (manage) {- const launcher = new URL(url);- launcher.searchParams.delete("site");- attempt.popup.location.replace(launcher.href);- finish("ready", true);- return;- }approvalOrigin = new URL(url).origin;- attempt.popup.location.replace(url);+ attempt.open = () => {+ if (signal.aborted || attempt.popup) return;+ const destination = new URL(url);+ if (manage) destination.searchParams.delete("site");+ attempt.popup = window.open(destination.href, "_blank");+ if (!attempt.popup) { finish("unavailable"); return; }+ attempt.open = undefined;+ if (manage) finish("ready", true);+ else { setState("approving"); help.current?.hidePopover(); }+ };+ setState("approval");} catch (error) {if (!signal.aborted) finish(native && error instanceof native.NativeCompatibilityError ? "incompatible" : "unavailable");}}- const label = t(state === "ready" ? "client.connect.manage" : state === "incompatible" ? "native.incompatible" :+ const busy = state === "busy" || state === "approving";+ const label = t(state === "busy" ? "client.connect.discovering" : state === "approving" ? "client.connect.approving" : state === "approval" ? "client.connect.found" :+ state === "ready" ? "client.connect.manage" : state === "incompatible" ? "native.incompatible" :state === "unavailable" ? "client.connect.unavailable" : "client.connect.action");const failed = state === "unavailable" || state === "incompatible";return <><Tooltip kind={state === "ready" ? "hint-app-ready" : state === "unavailable" ? "signal-failed" : state === "incompatible" ? "warning" : "hint-client-site"}text={vis ? undefined : label} disabled={helpOpen}place={sourcePicker ? "above" : "below"} align="end"><button ref={trigger} type="button" className={`${sourcePicker ? "lr-btn is-dense lr-source-picker-refresh lr-source-app-connect" : "lr-btn is-compact lr-app-connect"}${state === "ready" ? " is-ready" : ""}`}- aria-label={sourcePicker ? t("client.connect.action") : label} aria-busy={state === "busy" || undefined}- popoverTarget={failed ? helpId : undefined} aria-haspopup={failed ? "dialog" : undefined}- onClick={failed ? undefined : event => {+ aria-label={sourcePicker ? t("client.connect.action") : label} aria-busy={busy || undefined}+ popoverTarget={failed || state === "approval" ? helpId : undefined} aria-haspopup="dialog"+ onClick={failed || state === "approval" ? undefined : event => {// Failure may attach popoverTarget during this click; do not toggle the// recovery card closed immediately after opening it.event.preventDefault();void connect();- }} disabled={state === "busy"}>- <Glyph name={state === "ready" ? "check" : state === "busy" ? "loader" : state === "unavailable" || state === "incompatible" ? "alert" : "window"}- size={16} className={state === "busy" ? "lr-spin" : undefined} />+ }} disabled={busy}>+ <Glyph name={state === "ready" ? "check" : busy ? "loader" : state === "unavailable" || state === "incompatible" ? "alert" : "window"}+ size={16} className={busy ? "lr-spin" : undefined} />{vis ? null : <span className="lr-cap">App</span>}</button></Tooltip><div ref={help} id={helpId} popover="auto" role="dialog" aria-label={t("client.connect.action")} aria-describedby={`${helpId}-message`}className="lr-anchored-card lr-app-connect-help" onToggle={event => {setHelpOpen(event.newState === "open");+ if (event.newState === "closed" && !pending.current?.popup) pending.current?.cancel?.();if (event.newState !== "open" || !trigger.current) return;event.currentTarget.querySelector<HTMLButtonElement>("button")?.focus();}}><div className="lr-app-connect-head">- <div className="lr-app-connect-scene" aria-hidden="true">{helpOpen && <Comic kind={state === "incompatible" ? "warning" : "signal-failed"} theme="paper" />}</div>+ {state === "busy" ? <LoadingStatus label="client.connect.discovering" /> :+ <div className="lr-app-connect-scene" aria-hidden="true">{helpOpen && (state === "approval" ? <HintComic kind="hint-client-site" /> :+ <Comic kind={state === "incompatible" ? "warning" : "signal-failed"} theme="paper" />)}</div>}<button type="button" className="lr-btn is-dense is-quiet lr-app-connect-close" aria-label={t("common.close")}popoverTarget={helpId} popoverTargetAction="hide"><Glyph name="x" size={16} /></button></div>- <p id={`${helpId}-message`} className={vis ? "visually-hidden" : undefined}>{label}</p>+ <p id={`${helpId}-message`} className={vis ? "visually-hidden" : undefined}>{state === "busy" ? t("client.connect.permissionHint") : label}</p><div className="lr-app-connect-actions">- <button type="button" className="lr-btn" aria-label={t("common.retry")} onClick={() => void connect()}>- <Glyph name="refresh" size={16} /><span className={vis ? "visually-hidden" : undefined}>{t("common.retry")}</span>- </button>- <a className="lr-btn" href={downloadURL} target="_blank" rel="noopener noreferrer" aria-label={t("client.connect.download")}>+ {state !== "busy" && <button type="button" className="lr-btn" aria-label={t(state === "approval" ? "client.connect.open" : "common.retry")} onClick={() => void connect()}>+ <Glyph name={state === "approval" ? "arrowRight" : "refresh"} size={16} /><span className={vis ? "visually-hidden" : undefined}>{t(state === "approval" ? "client.connect.open" : "common.retry")}</span>+ </button>}+ {failed && <a className="lr-btn" href={downloadURL} target="_blank" rel="noopener noreferrer" aria-label={t("client.connect.download")}><Glyph name="arrowDown" size={16} /><span className={vis ? "visually-hidden" : undefined}>{t("client.connect.download")}</span>- </a>+ </a>}</div><p className={vis ? "visually-hidden" : "lr-app-connect-optional"}>{t("client.connect.browserHint")}</p></div>diff --git a/src/client/components/living/AudioVolumeControl.tsx b/src/client/components/living/AudioVolumeControl.tsxnew file mode 100644index 00000000..f0750a13--- /dev/null+++ b/src/client/components/living/AudioVolumeControl.tsx@@ -0,0 +1,24 @@+import { useId, type CSSProperties } from "react";+import { Tooltip } from "./Tooltip";+import type { HintKind } from "./hints";+import { Glyph, type GlyphName } from "../../ui/icons";+import { useCopy, type CopyKey } from "../../ui/copy";++export function AudioVolumeControl({ volume, onVolume, disabled, label, icon, hint, hintText }: {+ volume: number; onVolume: (volume: number) => void; disabled?: boolean;+ label: CopyKey; icon: GlyphName; hint?: HintKind; hintText?: CopyKey;+}) {+ const { t, vis } = useCopy();+ const id = useId(), percent = Math.round(volume * 100);+ const slider = <input id={id} type="range" min={0} max={200} step={1} value={percent} disabled={disabled}+ style={{ "--range-fill": `${percent / 2}%` } as CSSProperties}+ aria-label={t(label)} aria-valuetext={`${percent}%`}+ onChange={event => onVolume(Number(event.target.value) / 100)} />;+ return <>+ <label htmlFor={id}>+ <span>{vis ? <Glyph name={icon} size={18} /> : t(label)}</span>+ <output htmlFor={id}>{percent}%</output>+ </label>+ {hint ? <Tooltip kind={hint} text={vis ? undefined : t(hintText ?? label)}>{slider}</Tooltip> : slider}+ </>;+}diff --git a/src/client/components/living/AudioVolumeMenu.tsx b/src/client/components/living/AudioVolumeMenu.tsxnew file mode 100644index 00000000..561b47de--- /dev/null+++ b/src/client/components/living/AudioVolumeMenu.tsx@@ -0,0 +1,96 @@+import { useLayoutEffect, useRef, type ReactNode } from "react";+import { AudioVolumeControl } from "./AudioVolumeControl";+import { HOVER_ENTER_MS, HOVER_EXIT_GRACE_MS, LONG_PRESS_MS } from "./Tooltip";+import { useAnchoredPopover } from "./use-anchored-popover";+import { useSurfaceDocument } from "../../ui/panel-window";+import { useCopy, type CopyKey } from "../../ui/copy";+import type { GlyphName } from "../../ui/icons";++// The icon keeps its direct mute action; its attached slider never reflows the row.+export function AudioVolumeMenu({ volume, onVolume, label, icon, heading, disabled, children }: {+ volume: number; onVolume: (volume: number) => void; label: CopyKey; icon: GlyphName;+ heading?: string; disabled?: boolean; children: ReactNode;+}) {+ const { t } = useCopy();+ const ownerDocument = useSurfaceDocument(), view = ownerDocument?.defaultView;+ const anchor = useRef<HTMLSpanElement>(null), panel = useRef<HTMLDivElement>(null);+ const enter = useRef<number | null>(null), leave = useRef<number | null>(null);+ const touch = useRef<{ x: number; y: number } | null>(null), held = useRef(false);+ useAnchoredPopover(anchor, panel, { side: "above", align: "center" });+ const clear = () => {+ if (enter.current !== null) view?.clearTimeout(enter.current);+ if (leave.current !== null) view?.clearTimeout(leave.current);+ enter.current = leave.current = null;+ };+ const close = () => { clear(); if (panel.current?.matches(":popover-open")) panel.current.hidePopover(); };+ const open = () => {+ clear();+ if (!disabled && panel.current && !panel.current.matches(":popover-open")) {+ panel.current.showPopover({ source: anchor.current?.querySelector("button") ?? anchor.current! });+ }+ };+ useLayoutEffect(() => {+ const menu = panel.current;+ return () => { clear(); if (menu?.matches(":popover-open")) menu.hidePopover(); };+ }, [ownerDocument]);+ useLayoutEffect(() => { if (disabled) close(); }, [disabled]);+ return <span ref={anchor} className="lr-audio-volume-menu"+ onPointerEnter={event => {+ if (event.pointerType === "touch" || event.buttons || disabled) return;+ clear();+ if (!panel.current?.matches(":popover-open")) enter.current = view?.setTimeout(open, HOVER_ENTER_MS) ?? null;+ }}+ onPointerLeave={event => {+ if (event.pointerType === "touch") return;+ clear();+ if (event.buttons) return;+ const focused = ownerDocument?.activeElement;+ if (focused && event.currentTarget.contains(focused) && focused.matches(":focus-visible")) return;+ leave.current = view?.setTimeout(close, HOVER_EXIT_GRACE_MS) ?? null;+ }}+ onFocusCapture={event => {+ if (!event.currentTarget.contains(event.relatedTarget) && event.target.matches(":focus-visible")) open();+ }}+ onBlurCapture={event => { if (!event.currentTarget.contains(event.relatedTarget)) close(); }}+ onPointerDownCapture={event => {+ clear(); held.current = false;+ if (disabled || event.pointerType !== "touch" || panel.current?.contains(event.target as Node)) return;+ touch.current = { x: event.clientX, y: event.clientY };+ enter.current = view?.setTimeout(() => { held.current = true; open(); }, LONG_PRESS_MS) ?? null;+ }}+ onPointerMoveCapture={event => {+ if (touch.current && Math.hypot(event.clientX - touch.current.x, event.clientY - touch.current.y) > 8) {+ clear(); touch.current = null;+ }+ }}+ onPointerCancel={() => { clear(); touch.current = null; held.current = false; }}+ onPointerUpCapture={event => {+ clear(); touch.current = null;+ if (held.current) {+ event.preventDefault();+ // Native auto-popover dismissal runs after touch release outside the+ // slider. Reopen after that event without sending the icon's click.+ enter.current = view?.setTimeout(open, 0) ?? null;+ return;+ }+ const inside = [anchor.current, panel.current].some(element => {+ const rect = element?.getBoundingClientRect();+ return rect && event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;+ });+ if (!inside) close();+ }}+ onClickCapture={event => {+ if (held.current) { held.current = false; event.preventDefault(); event.stopPropagation(); }+ }}+ onKeyDownCapture={() => { held.current = false; }}+ onContextMenu={event => {+ if (!disabled && !panel.current?.contains(event.target as Node)) { event.preventDefault(); open(); }+ }}>+ {children}+ <div ref={panel} popover="auto" role="dialog" aria-label={heading ?? t(label)}+ className="lr-floating-surface lr-audio-settings lr-audio-volume-popover">+ {heading && <b>{heading}</b>}+ <AudioVolumeControl volume={volume} onVolume={onVolume} label={label} icon={icon} />+ </div>+ </span>;+}diff --git a/src/client/components/living/Couch.tsx b/src/client/components/living/Couch.tsxindex aa2712fe..039aec9c 100644--- a/src/client/components/living/Couch.tsx+++ b/src/client/components/living/Couch.tsx@@ -49,7 +49,7 @@ export function Couch({participantAction,footerAction,}: CouchProps) {- const { t } = useCopy();+ const { t, vis } = useCopy();const [couchRef, containerWidth] = useElementWidth();const count = entries.length + (host ? 1 : 0);const capacity = Math.max(2, Math.min(8, Math.floor((containerWidth - 64) / 72)));@@ -65,6 +65,10 @@ export function Couch({? [host.name, host.name === t("common.host") ? null : t("common.host"),host.you ? t("common.you") : null].filter(Boolean).join(" · "): undefined;+ const personHint = (name: string) => participantAction+ ? { kind: "hint-reaction-picker" as const, text: vis ? undefined : t("interaction.express"),+ overflow: { text: name, selector: ".lr-pawn-name" } }+ : { overflow: { text: name, selector: ".lr-pawn-name" } };return (<div ref={couchRef} className="lr-couch">@@ -87,7 +91,7 @@ export function Couch({aria-label={`${t("common.host")} · ${t("common.viewers")}`}>{host ? (- <span className="lr-seat" data-room-peer={host.key} style={seatStyle(0)}><Tooltip overflow={{ text: host.name, selector: ".lr-pawn-name" }}>+ <span className="lr-seat" data-room-peer={host.key} style={seatStyle(0)}><Tooltip {...personHint(host.name)}>{host.onSelect || participantAction ? (<buttontype="button"@@ -151,7 +155,7 @@ export function Couch({</button>);return (- <span key={entry.key} className="lr-seat" data-room-peer={entry.key} style={seatStyle(index + (host ? 1 : 0))}><Tooltip overflow={{ text: entry.name, selector: ".lr-pawn-name" }}>+ <span key={entry.key} className="lr-seat" data-room-peer={entry.key} style={seatStyle(index + (host ? 1 : 0))}><Tooltip {...personHint(entry.name)}>{pawn}</Tooltip></span>);diff --git a/src/client/components/living/FloatingPanel.tsx b/src/client/components/living/FloatingPanel.tsxindex 1e32ddc6..ec933bc2 100644--- a/src/client/components/living/FloatingPanel.tsx+++ b/src/client/components/living/FloatingPanel.tsx@@ -120,8 +120,8 @@ export function FloatingPanel({ id, trigger, title, icon, compact = false, anchoconst preferredHeight = preferredSize.current.height;panel.style.height = preferredHeight === undefined ? "auto" : `${Math.min(preferredHeight, maxHeight)}px`;const freeX = Math.max(0, maxWidth - panel.offsetWidth), freeY = Math.max(0, maxHeight - panel.offsetHeight);- // Keep the chosen relative position when the keyboard or viewport changes.- // Only deliberate movement writes it; a narrow viewport must not erase it.+ // Coordinates preserve the chosen corner after movement or content changes;+ // a viewport-only resize retains the stored relative position.if (point) {if (freeX) position.current.x = Math.max(0, Math.min(1, (point.x - left) / freeX));if (freeY) position.current.y = Math.max(0, Math.min(1, (point.y - top) / freeY));@@ -144,8 +144,9 @@ export function FloatingPanel({ id, trigger, title, icon, compact = false, anchoviewport?.addEventListener("resize", resize);viewport?.addEventListener("scroll", resize);window.addEventListener("resize", resize);- // Content-sized palettes still fit after a target, language or status change.- const observer = new ResizeObserver(resize);+ // Content changes keep the chosen top-left corner; viewport changes above+ // retain relative placement. Both still constrain the panel to the viewport.+ const observer = new ResizeObserver(() => place({ x: panel.offsetLeft, y: panel.offsetTop }));observer.observe(panel);return () => {placePanel.current = null;diff --git a/src/client/components/living/Header.tsx b/src/client/components/living/Header.tsxindex fa53a8d3..509ba734 100644--- a/src/client/components/living/Header.tsx+++ b/src/client/components/living/Header.tsx@@ -1,5 +1,5 @@// App header: brand mark, LED connection state, language selection and theme.-import { useId, useRef, useState, useSyncExternalStore } from "react";+import { useId, useRef, useState, useSyncExternalStore, type ComponentProps } from "react";import { createPortal } from "react-dom";import { browserDebugEnabled, debugError, downloadBrowserDebug, withBrowserDebug } from "../../lib/debug";import { BrandMark } from "./BrandMark";@@ -12,6 +12,7 @@ import { Glyph } from "../../ui/icons";import { AppConnectionButton } from "./AppConnectionButton";import { useAnchoredPopover } from "./use-anchored-popover";import { useProjectLink } from "../../lib/use-project-link";+import { Btn } from "./primitives";export type LedState = "live" | "busy" | "warn" | "bad" | "off";@@ -25,6 +26,7 @@ export function LedStrip({comic: ComicKind;}) {const { vis } = useCopy();+ const tone = state === "busy" ? "warn" : state;const strip = (<buttontype="button"@@ -32,15 +34,13 @@ export function LedStrip({data-state={state}aria-label={label}>- <i />- <i />- <i />+ <span className="lr-connection-bars" aria-hidden="true"><i /><i /><i /></span>{vis ? null : <span className="lr-leds-label">{label}</span>}</button>);return (<span role="status">- <Tooltip toggleOnClick kind={comic} tone={state} motion={state === "busy" || state === "warn" ? "progress" : "still"} text={vis ? undefined : label} place="below" align="start">+ <Tooltip toggleOnClick kind={comic} tone={tone} motion={state === "busy" || state === "warn" ? "progress" : "still"} text={vis ? undefined : label} place="below" align="start">{strip}</Tooltip></span>@@ -48,15 +48,18 @@ export function LedStrip({}/** Shared explicit opt-in/export action; starting diagnostics reloads the page. */-export function BrowserDiagnosticsButton({ quiet = false }: { quiet?: boolean } = {}) {+export function BrowserDiagnosticsButton({ quiet, size }: Pick<ComponentProps<typeof Btn>, "quiet" | "size"> = {}) {const { vis, t } = useCopy();const [debugExport, setDebugExport] = useState<"idle" | "busy" | "failed">("idle");- const debugTitle = t(!browserDebugEnabled ? "debug.startHint" :- debugExport === "failed" ? "debug.exportFailed" : "debug.exportHint");+ const title = !browserDebugEnabled ? "debug.startHint" :+ debugExport === "failed" ? "debug.exportFailed" : "debug.exportHint";+ const debugTitle = t(title);const debugButton = (- <button- type="button" className={`lr-btn is-compact${quiet ? " is-quiet" : ""}${browserDebugEnabled ? " is-on" : ""}`} disabled={debugExport === "busy"}- aria-label={debugTitle} aria-busy={debugExport === "busy" || undefined}+ <Btn+ size={size} quiet={quiet} tone={browserDebugEnabled ? "on" : undefined}+ title={title} disabled={debugExport === "busy"} busy={debugExport === "busy"}+ icon={!browserDebugEnabled ? "cpu" : debugExport === "failed" ? "alert" : "arrowDown"}+ cap={!browserDebugEnabled ? "debug.start" : debugExport === "failed" ? "common.retry" : "debug.export"}onClick={() => {if (!browserDebugEnabled) {// Start collection before connection owners attach their observers.@@ -70,14 +73,7 @@ export function BrowserDiagnosticsButton({ quiet = false }: { quiet?: boolean }debugError("export", "collector-failed", error, { collector: "download" });setDebugExport("failed");});- }}- >- <Glyph name={!browserDebugEnabled ? "cpu" :- debugExport === "busy" ? "loader" : debugExport === "failed" ? "alert" : "arrowDown"}- size={16} className={debugExport === "busy" ? "lr-spin" : undefined} />- {vis ? null : <span className="lr-cap">{t(!browserDebugEnabled ? "debug.start" :- debugExport === "failed" ? "common.retry" : "debug.export")}</span>}- </button>+ }} />);return <Tooltip kind={!browserDebugEnabled ? "debug-start" : debugExport === "failed" ? "debug-export-failed" : "hint-debug-export"}tone={debugExport === "failed" ? "bad" : debugExport === "busy" ? "busy" : "off"}@@ -120,7 +116,7 @@ function BrowserHelpMenu() {<Glyph name="book" size={16} />{!vis && <span className="lr-cap">{t("help.troubleshooting")}</span>}</a></Tooltip>- <BrowserDiagnosticsButton quiet />+ <BrowserDiagnosticsButton size="compact" quiet /></>}</nav></div>, document.body)}diff --git a/src/client/components/living/HostMicrophone.tsx b/src/client/components/living/HostMicrophone.tsxdeleted file mode 100644index 602a69de..00000000--- a/src/client/components/living/HostMicrophone.tsx+++ /dev/null@@ -1,60 +0,0 @@-import { useId, type CSSProperties } from "react";-import { Btn, SwitchItem } from "./primitives";-import { Tooltip } from "./Tooltip";-import { Glyph } from "../../ui/icons";-import { useCopy } from "../../ui/copy";-import type { CaptureDevice } from "../../media/capture-devices";-import { MicrophoneDeviceSelect } from "./MicrophoneDeviceSelect";--export function HostMicrophone({ enabled, pending, disabled, paused, unavailable, volume, onToggle }: {- enabled: boolean; pending?: boolean; disabled?: boolean;- paused?: boolean;- volume: number;- unavailable?: boolean; onToggle: () => void;-}) {- return <Btn icon={enabled ? "microphone" : "microphoneOff"}- cap="host.microphone.label"- title={unavailable ? "host.microphone.browserOnly" : pending ? "host.microphone.pending"- : paused ? "host.microphone.paused" : disabled ? "host.microphone.busy"- : enabled && volume === 0 ? "host.microphone.zeroVolume"- : enabled ? "host.microphone.mute" : "host.microphone.enable"}- hint={unavailable ? "hint-capture-browser" : paused ? "host-paused" : enabled ? "hint-microphone-off" : "hint-microphone-on"}- hintTone={unavailable ? "warn" : pending || disabled ? "busy" : undefined}- hintMotion={pending || disabled ? "progress" : undefined}- pressed={enabled} busy={pending}- disabled={unavailable || pending || disabled || paused} onClick={onToggle} />;-}--export function HostMicrophoneSettings({ enabled, disabled, volume, onVolume, deviceId, onDevice, loadDevices, native, voiceProcessing, onVoiceProcessing }: {- enabled: boolean; disabled?: boolean; native?: boolean;- volume: number; onVolume: (volume: number) => void;- deviceId: string; onDevice: (id: string) => void; loadDevices: () => Promise<CaptureDevice[]>;- voiceProcessing: boolean; onVoiceProcessing: (enabled: boolean) => void;-}) {- const { t, vis } = useCopy();- const id = useId();- const percent = Math.round(volume * 100);- return <div className="lr-door-group lr-microphone-settings" role="group" aria-label={t("host.microphone.settings")}>- <MicrophoneDeviceSelect value={deviceId} load={loadDevices}- onChange={onDevice} disabled={disabled} revision={enabled} browser={!native} />- <label htmlFor={id}>- <span>{vis ? <Glyph name="microphone" size={18} /> : t("host.microphone.volume")}</span>- <output htmlFor={id}>{percent}%</output>- </label>- <Tooltip kind="hint-microphone-volume" text={vis ? undefined : t("host.microphone.settings")}>- <input id={id} type="range" min={0} max={200} step={1} value={percent} disabled={disabled}- style={{ "--range-fill": `${percent / 2}%` } as CSSProperties}- aria-label={t("host.microphone.volume")} aria-valuetext={`${percent}%`}- onChange={event => onVolume(Number(event.target.value) / 100)} />- </Tooltip>- {!native && <>- <div className="lr-row-group">- {vis ? <Glyph name="microphone" size={18} /> : null}- <SwitchItem checked={voiceProcessing} onChange={onVoiceProcessing} disabled={disabled}- label={t("host.microphone.voiceProcessing")} note={t("host.microphone.voiceProcessingHint")}- hint="hint-microphone-processing" />- </div>- {!vis && <small>{t("host.microphone.voiceProcessingUsage")}</small>}- </>}- </div>;-}diff --git a/src/client/components/living/HostRemoteControl.tsx b/src/client/components/living/HostRemoteControl.tsxindex d19f08a0..b142f67a 100644--- a/src/client/components/living/HostRemoteControl.tsx+++ b/src/client/components/living/HostRemoteControl.tsx@@ -1,6 +1,6 @@import { useEffect, useId, useRef, useState, type CSSProperties } from "react";import { createPortal } from "react-dom";-import type { RemoteControlRequest } from "../../native/wire";+import type { RemoteControlRequest, RemoteStopShortcut } from "../../native/wire";import type { RemoteControlMode, RemoteInputPlatform } from "../../remote-control/protocol";import { readRoomPreferences, saveRoomPreferences } from "../../lib/room-preferences";import { useCopy } from "../../ui/copy";@@ -8,16 +8,18 @@ import { Glyph } from "../../ui/icons";import { Btn, NameTag, SwitchItem } from "./primitives";import { FloatingPanel } from "./FloatingPanel";import { Tooltip } from "./Tooltip";+import { RemoteShortcutSelect } from "./RemoteShortcutSelect";import "./remote-control.css";// Form drafts stay here; the App snapshot owns applied authorization.-export function HostRemoteControl({ mode, platform, requests, disabled, onPolicy, onDecide }: {+export function HostRemoteControl({ mode, platform, requests, disabled, onPolicy, onDecide, onShortcut }: {mode: RemoteControlMode;platform: RemoteInputPlatform;requests: (RemoteControlRequest & { name: string })[];disabled?: boolean;onPolicy: (mode: RemoteControlMode, password?: string) => Promise<void>;onDecide: (id: string, allow: boolean) => Promise<void>;+ onShortcut?: (key?: number) => Promise<RemoteStopShortcut>;}) {const { t, vis } = useCopy();const id = useId();@@ -33,6 +35,19 @@ export function HostRemoteControl({ mode, platform, requests, disabled, onPolicyconst busy = pendingActions.size > 0;const pending = requests.filter(request => request.state === "pending").length;const controller = requests.find(request => request.state !== "pending");+ const policyAction = mode !== "off" ? "remote.apply" : draft === "room" ? "remote.enableRoom" : "remote.enable";+ const [shortcut, setShortcut] = useState<RemoteStopShortcut | null>(null);+ const shortcutUnavailable = mode === "off" && Boolean(onShortcut) && !shortcut?.available;+ useEffect(() => {+ if (!open || !onShortcut) return;+ let current = true;+ setShortcut(null);+ // Restore this Site's choice before allowing a new permission request.+ const key = readRoomPreferences().remoteStopKey;+ const load = mode === "off" ? onShortcut(key).catch(() => ({ key, available: false })) : onShortcut();+ void load.then(value => { if (current) setShortcut(value); }, () => { if (current) setShortcut(null); });+ return () => { current = false; };+ }, [open, mode, onShortcut]);useEffect(() => {setDraft(mode === "off" ? readRoomPreferences().remoteControlMode : mode);setPassword(""); setPreparing(false);@@ -56,7 +71,10 @@ export function HostRemoteControl({ mode, platform, requests, disabled, onPolicyif (nextMode === "off") setPendingActions(current => {const next = new Map(current); next.delete("enable"); return next;});- return perform(nextMode !== "off" && mode === "off" ? "enable" : "policy", () => onPolicy(nextMode, password));+ return perform(nextMode !== "off" && mode === "off" ? "enable" : "policy", async () => {+ try { await onPolicy(nextMode, password); }+ finally { if (onShortcut) setShortcut(await onShortcut().catch(() => null)); }+ });};return <><span className="lr-remote-trigger">@@ -72,15 +90,17 @@ export function HostRemoteControl({ mode, platform, requests, disabled, onPolicysetOpen(opened);setSurfaceDocument(owner);if (!opened) {+ setShortcut(null);setPassword(""); setPreparing(false);setDraft(mode === "off" ? readRoomPreferences().remoteControlMode : mode);}}}><div className="lr-floating-scroll lr-remote-panel-body"><SwitchItem checked={mode !== "off"} label={t("remote.title")} hint="hint-remote-control"- disabled={mode === "off" && (busy || disabled)}+ disabled={mode === "off" && (busy || disabled || shortcutUnavailable)}onChange={enabled => {- if (enabled && draft === "password" && !password) setPreparing(true);+ // A remembered automatic grant is not consent for this audience.+ if (enabled && (draft === "room" || draft === "password" && !password)) setPreparing(true);else void applyPolicy(enabled ? draft : "off", enabled && draft === "password" ? password : undefined);}} />{pendingActions.has("enable") && mode === "off" && <div className="lr-remote-enable-pending" role="status">@@ -128,18 +148,28 @@ export function HostRemoteControl({ mode, platform, requests, disabled, onPolicydisabled={busy || disabled} onChange={event => setPassword(event.target.value)} /></label>}{(draft !== mode || draft === "password") && <div className="lr-remote-policy-actions">- {preparing && !busy && <Btn icon="x" title="common.cancel" cap="common.cancel" size="compact" onClick={() => {+ {preparing && !busy && <Btn icon="x" title="common.cancel" cap="common.cancel" size="compact" hint="hint-close" onClick={() => {setPreparing(false); setPassword(""); setDraft(readRoomPreferences().remoteControlMode);(surfaceDocument ?? document).getElementById(id)?.querySelector<HTMLButtonElement>('[role="switch"]')?.focus();}} />}- <Btn icon="check" title="remote.apply" cap="remote.apply" type="submit" tone="primary" size="compact"- hint="hint-remote-control" disabled={busy || disabled || (draft === "password" && !password)} />+ <Btn icon="check" title={policyAction} cap={policyAction}+ type="submit" tone="primary" size="compact" hint="hint-remote-control" hintText={`remote.help.${draft}`}+ disabled={busy || disabled || shortcutUnavailable || (draft === "password" && !password)} /></div>}</form>}{failedId === "policy" && <p role="alert"><Glyph name="alert" size={14} /><span className={vis ? "visually-hidden" : undefined}>{t(platform === "darwin" && mode === "off" ? "remote.macPermission" : "remote.decisionFailed")}</span></p>}{!vis && <p className="lr-remote-note">{t(platform === "linux" && mode === "off" ? "remote.linuxEnable" : "remote.policyLifetime")}</p>}- {(mode === "room" || mode === "password" || requests.some(request => request.state !== "pending")) && <p className="lr-remote-note">+ {onShortcut && shortcut && <>+ <RemoteShortcutSelect host mac={platform === "darwin"} value={shortcut.key} disabled={busy || disabled}+ onChange={key => void perform("shortcut", async () => {+ setShortcut(await onShortcut(key));+ saveRoomPreferences({ remoteStopKey: key });+ })} />+ {(!shortcut.available || failedId === "shortcut") && <p role="alert"><Glyph name="alert" size={14} />+ <span className={vis ? "visually-hidden" : undefined}>{t("remote.shortcutFailed")}</span></p>}+ </>}+ {!onShortcut && (mode === "room" || mode === "password" || requests.some(request => request.state !== "pending")) && <p className="lr-remote-note">{platform === "linux" ? <><Glyph name="mouse" size={14} /> <span className={vis ? "visually-hidden" : undefined}>{t("remote.linuxStop")}</span></>: <>{vis ? <Glyph name="keyboard" size={14} /> : t("remote.shortcut")} <kbd>{platform === "darwin" ? "Ctrl + Option + F10" : "Ctrl + Alt + F10"}</kbd></>}</p>}diff --git a/src/client/components/living/LauncherForm.tsx b/src/client/components/living/LauncherForm.tsxindex ca31b5e2..9d587793 100644--- a/src/client/components/living/LauncherForm.tsx+++ b/src/client/components/living/LauncherForm.tsx@@ -126,7 +126,7 @@ export function LauncherForm({<div className="lr-client-site-actions"><Btn icon="star" title="client.connect.openOnStart" size="dense" pressed={openSiteOnStart}hint="hint-client-site" disabled={siteBusy} onClick={onToggleStartupSite} />- <Btn icon="x" title="client.connect.remove" size="dense" hint="hint-client-site" disabled={siteBusy} onClick={onRemoveSite} />+ <Btn icon="x" title="client.connect.remove" size="dense" hint="hint-close" disabled={siteBusy} onClick={onRemoveSite} /></div></div>}</section>@@ -222,6 +222,9 @@ export function LauncherForm({) : null}</div>+ {mode === "local" && <p className={vis ? "visually-hidden" : "lr-client-access-hint"}>+ {t("client.launch.localHTTPS")}+ </p>}<Btnicon="arrowRight"title="client.launch.go"diff --git a/src/client/components/living/Metrics.tsx b/src/client/components/living/Metrics.tsxindex 84b03f07..b6ad523d 100644--- a/src/client/components/living/Metrics.tsx+++ b/src/client/components/living/Metrics.tsx@@ -230,7 +230,7 @@ export function MetricCells({}}><Glyph name="chevron" size={15} />- {vis ? null : <span className="lr-cap">{moreTitle}</span>}+ {vis ? null : <span className="lr-cap">{t("stats.more")}</span>}</button>);diff --git a/src/client/components/living/MicrophoneDeviceSelect.tsx b/src/client/components/living/MicrophoneDeviceSelect.tsxindex cd07f41a..099f2edc 100644--- a/src/client/components/living/MicrophoneDeviceSelect.tsx+++ b/src/client/components/living/MicrophoneDeviceSelect.tsx@@ -2,6 +2,7 @@ import { useEffect, useId, useState } from "react";import type { CaptureDevice } from "../../media/capture-devices";import { useCopy } from "../../ui/copy";import { Glyph } from "../../ui/icons";+import { Tooltip } from "./Tooltip";// Shared presentation only: the caller owns capture and device replacement.export function MicrophoneDeviceSelect({ value, load, onChange, disabled, revision, browser = true }: {@@ -14,6 +15,7 @@ export function MicrophoneDeviceSelect({ value, load, onChange, disabled, revisiconst [busy, setBusy] = useState(true);const [failed, setFailed] = useState(false);const [refresh, setRefresh] = useState(0);+ const unavailable = browser && !navigator.mediaDevices?.getUserMedia;useEffect(() => {let current = true;let request = 0;@@ -38,7 +40,7 @@ export function MicrophoneDeviceSelect({ value, load, onChange, disabled, revisireturn <div className="lr-capture-device"><label htmlFor={id}>{vis ? <Glyph name="microphone" size={18} /> : t("host.device.microphone")}</label><div className="lr-capture-device-controls">- <select id={id} value={value} disabled={disabled || busy} aria-label={t("host.device.microphone")}+ <select id={id} value={value} disabled={disabled || busy || unavailable} aria-label={t("host.device.microphone")}onChange={event => onChange(event.target.value)}><option value="">{t("host.device.default")}</option>{missing && <option value={value} disabled>{t("host.device.missing")}</option>}@@ -46,12 +48,15 @@ export function MicrophoneDeviceSelect({ value, load, onChange, disabled, revisi{device.label || `${t("host.device.microphone")} ${index + 1}`}</option>)}</select>- <button type="button" className="lr-btn lr-device-refresh" disabled={busy || disabled}+ <Tooltip kind="hint-refresh-sources" text={vis ? undefined : t("host.device.refresh")}>+ <button type="button" className="lr-btn lr-device-refresh" disabled={busy || disabled || unavailable}aria-label={t("host.device.refresh")} onClick={() => setRefresh(value => value + 1)}><Glyph name="refresh" size={16} className={busy ? "lr-spin" : undefined} /></button>+ </Tooltip></div>- {failed ? <small role="status">{t("host.device.listFailed")}</small>+ {unavailable ? <small role="status">{t("voice.error.microphoneUnavailable")}</small>+ : failed ? <small role="status">{t("host.device.listFailed")}</small>: !vis && browser && !busy && devices.every(device => !device.label) ? <small>{t("host.device.permission.microphone")}</small> : null}</div>;}diff --git a/src/client/components/living/MicrophoneSettings.tsx b/src/client/components/living/MicrophoneSettings.tsxnew file mode 100644index 00000000..b4827c53--- /dev/null+++ b/src/client/components/living/MicrophoneSettings.tsx@@ -0,0 +1,28 @@+import { SwitchItem } from "./primitives";+import { Glyph } from "../../ui/icons";+import { useCopy } from "../../ui/copy";+import type { CaptureDevice } from "../../media/capture-devices";+import { MicrophoneDeviceSelect } from "./MicrophoneDeviceSelect";+import { AudioVolumeControl } from "./AudioVolumeControl";++export function MicrophoneSettings({ enabled, disabled, volume, onVolume, deviceId, onDevice, loadDevices, voiceProcessing, onVoiceProcessing, host }: {+ enabled: boolean; disabled?: boolean; host: boolean;+ volume: number; onVolume: (volume: number) => void;+ deviceId: string; onDevice: (id: string) => void; loadDevices: () => Promise<CaptureDevice[]>;+ voiceProcessing: boolean; onVoiceProcessing: (enabled: boolean) => void;+}) {+ const { t, vis } = useCopy();+ return <div className="lr-door-group lr-audio-settings" role="group" aria-label={t("host.microphone.settings")}>+ <MicrophoneDeviceSelect value={deviceId} load={loadDevices}+ onChange={onDevice} disabled={disabled} revision={enabled} />+ <AudioVolumeControl volume={volume} onVolume={onVolume} disabled={disabled}+ label="host.microphone.volume" icon="microphone"+ hint={host ? "hint-microphone-volume" : "hint-voice-microphone-volume"} />+ <div className="lr-row-group">+ {vis ? <Glyph name="microphone" size={18} /> : null}+ <SwitchItem checked={voiceProcessing} onChange={onVoiceProcessing} disabled={disabled}+ label={t("host.microphone.voiceProcessing")} note={t("host.microphone.voiceProcessingHint")}+ hint={host ? "hint-microphone-processing" : "hint-voice-microphone-processing"} />+ </div>+ </div>;+}diff --git a/src/client/components/living/PlaybackControls.tsx b/src/client/components/living/PlaybackControls.tsxindex e9eedac0..c91679ee 100644--- a/src/client/components/living/PlaybackControls.tsx+++ b/src/client/components/living/PlaybackControls.tsx@@ -11,6 +11,7 @@ import { useAnchoredPopover } from "./use-anchored-popover";import { usePlaybackControlsVisibility } from "./use-playback-controls-visibility";import { usePictureInPicture } from "./use-picture-in-picture";import { bindPlaybackGestures } from "./playback-gestures";+import { useVideoRotation } from "./use-video-rotation";import { toggleVideoFullscreen, videoFullscreenState, type FullscreenVideo } from "./video-fullscreen";import "./playback-controls.css";import "./floating-panel.css";@@ -22,7 +23,7 @@ type PlaybackVisibility = ReturnType<typeof usePlaybackControlsVisibility>;export function PlaybackControls({videoRef, stream, audioTrackKey, audioAvailable, canPlay, theaterMode, onPlay,onToggleTheater, onReconnect, reconnectAvailable,- overlayAction, overlaySettings, remoteActions, settings,+ overlayAction, remoteActions, settings,}: {videoRef: RefObject<HTMLVideoElement | null>;stream: MediaStream | null;@@ -35,7 +36,6 @@ export function PlaybackControls({onReconnect: () => void;reconnectAvailable: boolean;overlayAction?: ReactNode;- overlaySettings?: ReactNode;remoteActions?: ReactNode;settings?: ViewerPlaybackSettingsProps;}) {@@ -50,6 +50,7 @@ export function PlaybackControls({const [fullscreenFailed, setFullscreenFailed] = useState(false);const visibility = usePlaybackControlsVisibility(videoRef, controlsRef, paused || !canPlay);const picture = usePictureInPicture(videoRef);+ useVideoRotation(videoRef, settings?.pictureFit, settings?.pictureRotation ?? 0);const togglePlayback = () => {if (!canPlay) return;@@ -134,14 +135,14 @@ export function PlaybackControls({audioRef.current?.setLevel(level);audioRef.current?.setMuted(false);}} onToggleTheater={onToggleTheater} onReconnect={onReconnect}- reconnectAvailable={reconnectAvailable} overlayAction={overlayAction} overlaySettings={overlaySettings} remoteActions={remoteActions} settings={settings} />;+ reconnectAvailable={reconnectAvailable} overlayAction={overlayAction} remoteActions={remoteActions} settings={settings} />;}// The film shares the rendered controls; the component above alone owns media effects.export function PlaybackControlsView({controlsRef, visibility, audio, paused, hasAudio, canPlay, theaterMode,fullscreen, fullscreenFailed, picture, togglePlayback, toggleFullscreen,- toggleMute, setLevel, onToggleTheater, onReconnect, reconnectAvailable, overlayAction, overlaySettings, remoteActions, settings,+ toggleMute, setLevel, onToggleTheater, onReconnect, reconnectAvailable, overlayAction, remoteActions, settings,}: {controlsRef?: RefObject<HTMLDivElement | null>; visibility?: PlaybackVisibility;audio: ViewerAudioSnapshot; paused: boolean; hasAudio: boolean; canPlay: boolean;@@ -150,7 +151,7 @@ export function PlaybackControlsView({picture: Pick<ReturnType<typeof usePictureInPicture>, "active" | "supported" | "failed" | "toggle">;togglePlayback: () => void; toggleFullscreen: () => void; toggleMute: () => void;setLevel: (level: number) => void; onToggleTheater: () => void; onReconnect: () => void;- reconnectAvailable: boolean; overlayAction?: ReactNode; overlaySettings?: ReactNode; remoteActions?: ReactNode;+ reconnectAvailable: boolean; overlayAction?: ReactNode; remoteActions?: ReactNode;settings?: ViewerPlaybackSettingsProps;}) {const { t, vis } = useCopy();@@ -162,7 +163,7 @@ export function PlaybackControlsView({useEffect(() => {setChin(barRef.current?.closest(".lr-tv")?.querySelector<HTMLElement>(".lr-tv-chin") ?? null);}, [barRef]);- useAnchoredPopover(barRef, menuRef, { align: "center", minVisibleHeight: settings || overlaySettings ? 160 : Infinity });+ useAnchoredPopover(barRef, menuRef, { align: "center", minVisibleHeight: settings ? 160 : Infinity });const silent = audio.muted || audio.level === 0;const percent = Math.round(audio.level * 100);const pipTitle = picture.failed ? "playback.pipFailed" : !picture.supported ? "playback.pipUnavailable"@@ -214,7 +215,7 @@ export function PlaybackControlsView({</span>{remoteActions}<span className="lr-playback-view">- <PlaybackMore panel={menuRef} settings={settings} overlaySettings={overlaySettings} onReconnect={onReconnect} reconnectAvailable={reconnectAvailable}>+ <PlaybackMore panel={menuRef} settings={settings} onReconnect={onReconnect} reconnectAvailable={reconnectAvailable}>{displayActions(true)}</PlaybackMore><span className="lr-playback-secondary">{displayActions(false)}</span>@@ -238,12 +239,11 @@ export function PlaybackControlsView({// Native popover owns dismissal and focus return. The same actions above render// directly on wide players and in this compact disclosure on narrow players.-function PlaybackMore({ panel, children, settings, overlaySettings, onReconnect, reconnectAvailable }: {+function PlaybackMore({ panel, children, settings, onReconnect, reconnectAvailable }: {panel: RefObject<HTMLDivElement | null>; children: ReactNode; settings?: ViewerPlaybackSettingsProps;- overlaySettings?: ReactNode;onReconnect: () => void; reconnectAvailable: boolean;}) {- const { t, vis } = useCopy();+ const { t } = useCopy();const id = useId();const [open, setOpen] = useState(false);const reconnect = <Btn icon="refresh" title="viewer.reconnect" size="dense" hint="hint-reconnect" draw="playback-reconnect"@@ -254,17 +254,13 @@ function PlaybackMore({ panel, children, settings, overlaySettings, onReconnect,const display = <div className="lr-playback-display-menu">{children}</div>;return <span className="lr-playback-more"><Btn icon="sliders" title="playback.more" hint="hint-advanced" popoverTarget={id} expanded={open} controls={id} />- <div id={id} ref={panel} className={`lr-floating-surface lr-playback-menu${settings || overlaySettings ? " lr-playback-settings" : ""}`} popover="auto" aria-label={t("playback.more")}+ <div id={id} ref={panel} className={`lr-floating-surface lr-playback-menu${settings ? " lr-playback-settings" : ""}`} popover="auto" aria-label={t("playback.more")}onToggle={event => { if (event.target === event.currentTarget) setOpen(event.newState === "open"); }}onClick={event => {if (!event.defaultPrevented && event.target instanceof Element && event.target.closest(".lr-playback-display-menu button")) panel.current?.hidePopover();}}>{settings ? <ViewerPlaybackSettings {...settings} displayActions={display} reconnect={reconnect} />: <div className="lr-playback-menu-actions">{display}{reconnect}</div>}- {overlaySettings && <section className="lr-playback-overlay-settings" aria-label={t("playback.overlay")}>- <h3><Glyph name="danmaku" size={17} /><span className={vis ? "visually-hidden" : undefined}>{t("playback.overlay")}</span></h3>- {overlaySettings}- </section>}</div></span>;}diff --git a/src/client/components/living/RemoteControl.tsx b/src/client/components/living/RemoteControl.tsxindex d1650c9d..c0c75ffe 100644--- a/src/client/components/living/RemoteControl.tsx+++ b/src/client/components/living/RemoteControl.tsx@@ -3,21 +3,24 @@ import { createPortal } from "react-dom";import { useCopy, type CopyKey } from "../../ui/copy";import { Glyph } from "../../ui/icons";import type { InputTransport } from "../../remote-control/input-route";-import { RemoteInputSession, picturePoint, pictureRect, type RemoteInputState, type RemoteInputEvent } from "../../remote-control/input-session";+import { RemoteInputSession, type RemoteInputState, type RemoteInputEvent } from "../../remote-control/input-session";import { RemoteTouchpad } from "../../remote-control/touchpad";import { RemoteViewport } from "../../remote-control/viewport";+import { matchesRemoteShortcut } from "../../remote-control/protocol";+import { readRoomPreferences, saveRoomPreferences } from "../../lib/room-preferences";import { RemoteKeyboard } from "./RemoteKeyboard";import { Btn } from "./primitives";import { videoFullscreenState, type FullscreenVideo } from "./video-fullscreen";-import type { VideoFit } from "../../media/video-geometry";+import { picturePoint, pictureRect, rotatePicturePoint, rotatePictureDelta, videoRotation, type VideoFit, type VideoRotation } from "../../media/video-geometry";import "./remote-control.css";// The video keeps its existing media owner. This temporary surface handles// input only while its current routed endpoint holds a local App grant.-export function RemoteControl({ channel, videoRef, available, pictureFit }: {+export function RemoteControl({ channel, videoRef, available, pictureFit, pictureRotation = 0 }: {channel: InputTransport | null; videoRef: RefObject<HTMLVideoElement | null>;available: boolean;pictureFit?: VideoFit;+ pictureRotation?: VideoRotation;}) {const { t, vis } = useCopy();const [state, setState] = useState<RemoteInputState | null>(null);@@ -31,6 +34,7 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {const keyboardDetached = Boolean(keyboardDocument && keyboardDocument !== document);const [touch, setTouch] = useState(false);const [zoomed, setZoomed] = useState(false);+ const [releaseKey, setReleaseKey] = useState(() => readRoomPreferences().remoteReleaseKey);const session = useRef<RemoteInputSession | null>(null);const surface = useRef<HTMLDivElement | null>(null);const cursor = useRef<SVGSVGElement | null>(null);@@ -82,8 +86,9 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {const picture = pictureRect(video);const rect = surface.current?.getBoundingClientRect();if (!picture || !rect || !cursor.current) return;- cursor.current.style.left = `${picture.left - rect.left + current.position.x * picture.width}px`;- cursor.current.style.top = `${picture.top - rect.top + current.position.y * picture.height}px`;+ const position = rotatePicturePoint(current.position, videoRotation(video));+ cursor.current.style.left = `${picture.left - rect.left + position.x * picture.width}px`;+ cursor.current.style.top = `${picture.top - rect.top + position.y * picture.height}px`;};const view = new RemoteViewport(video, element, zoomed => {setZoomed(zoomed);@@ -92,7 +97,10 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {});viewport.current = view;const current = new RemoteTouchpad(- () => pictureRect(video),+ () => {+ const picture = pictureRect(video);+ return picture && { ...picture, rotation: videoRotation(video) };+ },event => session.current?.input(event),delta => session.current?.scroll(delta, 0),updateCursor,@@ -110,6 +118,9 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {};}, [controlled, channel, videoRef]);useEffect(() => { viewport.current?.refresh(); }, [pictureFit]);+ useEffect(() => {+ reset(); viewport.current?.reset(); viewport.current?.refresh();+ }, [pictureRotation, reset]);useEffect(() => {const video = videoRef.current as FullscreenVideo | null;if (!video) return;@@ -167,6 +178,16 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {hidden();return () => owners.forEach(owner => owner.removeEventListener("visibilitychange", hidden));}, [controlled, keyboardDocument, release, reset]);+ useEffect(() => {+ if (!controlled) return;+ const owners = [...new Set([document, ...(keyboardDocument ? [keyboardDocument] : [])])];+ const stop = (event: KeyboardEvent) => {+ if (!matchesRemoteShortcut(event, releaseKey)) return;+ event.preventDefault(); event.stopImmediatePropagation(); release();+ };+ owners.forEach(owner => owner.addEventListener("keydown", stop, true));+ return () => owners.forEach(owner => owner.removeEventListener("keydown", stop, true));+ }, [controlled, keyboardDocument, release, releaseKey]);if (!channel || channel.readyState !== "open" || !state || state.mode === "off") return null;const point = (clientX: number, clientY: number) => {@@ -244,7 +265,8 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {}setTouch(false);if (document.pointerLockElement === surface.current) {- input({ type: "relative", dx: event.movementX, dy: event.movementY });+ const delta = rotatePictureDelta({ x: event.movementX, y: event.movementY }, pictureRotation, true);+ input({ type: "relative", dx: delta.x, dy: delta.y });} else {const position = point(event.clientX, event.clientY);if (position) {@@ -287,7 +309,6 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {onBlur={reset}onKeyDown={event => {event.preventDefault(); event.stopPropagation();- if (event.code === "F10" && event.ctrlKey && event.altKey) { release(); return; }if (!event.nativeEvent.isComposing) input({ type: "key", code: event.code, down: true });}}onKeyUp={event => { event.preventDefault(); event.stopPropagation(); input({ type: "key", code: event.code, down: false }); }}>@@ -300,6 +321,7 @@ export function RemoteControl({ channel, videoRef, available, pictureFit }: {onClick={() => { reset(); viewport.current?.reset(); surface.current?.focus({ preventScroll: true }); }}>1×</button></div>}{active && keyboardOpen && <RemoteKeyboard input={input} touch={touchControls} platform={state.platform}+ releaseKey={releaseKey} onReleaseKeyChange={key => { setReleaseKey(key); saveRoomPreferences({ remoteReleaseKey: key }); }}onSurfaceChange={keyboardSurfaceChanged}mouseControl={!touchControls && "requestPointerLock" in HTMLElement.prototype && <span className="lr-remote-game-mouse"><Btn icon="gamepad" size="compact"title={lockFailed ? "remote.lockFailed" : locked ? "remote.releaseMouse" : "remote.gameMouse"}diff --git a/src/client/components/living/RemoteKeyboard.tsx b/src/client/components/living/RemoteKeyboard.tsxindex 662f0f3a..d5b6e44c 100644--- a/src/client/components/living/RemoteKeyboard.tsx+++ b/src/client/components/living/RemoteKeyboard.tsx@@ -10,6 +10,7 @@ import { panelWindowAPI, SurfaceDocument, usePanelWindow } from "../../ui/panel-import { navigateTabs } from "../../ui/tab-navigation";import { Btn, Chip } from "./primitives";import { Tooltip } from "./Tooltip";+import { RemoteShortcutSelect } from "./RemoteShortcutSelect";import "./floating-panel.css";type Key = readonly [label: string, code: string, shifted?: string];@@ -32,11 +33,12 @@ const PAGES = REMOTE_KEYBOARD_PAGES;// The local input owns IME composition. Committed text and physical keys use// their existing input operations, without clipboard access or another channel.-export function RemoteKeyboard({ input, close, mouseControl, touch, platform, onSurfaceChange }: {+export function RemoteKeyboard({ input, close, mouseControl, touch, platform, onSurfaceChange, releaseKey, onReleaseKeyChange }: {input: (event: RemoteInputEvent) => void; close: () => void;mouseControl?: ReactNode; touch: boolean;platform: RemoteInputPlatform;onSurfaceChange?: (owner: Document) => void;+ releaseKey: number; onReleaseKeyChange: (key: number) => void;}) {const { t, vis } = useCopy();const id = useId();@@ -208,6 +210,7 @@ export function RemoteKeyboard({ input, close, mouseControl, touch, platform, on</div></>}</div>+ <RemoteShortcutSelect value={releaseKey} onChange={onReleaseKeyChange} mac={navigator.platform.startsWith("Mac")} />{!panelWindow.detached && mouseControl}{!vis && touch && <p>{t("remote.touchHelp")}</p>}</section></SurfaceDocument.Provider>;diff --git a/src/client/components/living/RemoteShortcutSelect.tsx b/src/client/components/living/RemoteShortcutSelect.tsxnew file mode 100644index 00000000..22c044ef--- /dev/null+++ b/src/client/components/living/RemoteShortcutSelect.tsx@@ -0,0 +1,23 @@+import { useId } from "react";+import { REMOTE_SHORTCUT_KEYS } from "../../remote-control/protocol";+import { useCopy } from "../../ui/copy";+import { Glyph } from "../../ui/icons";+import { Tooltip } from "./Tooltip";++export function RemoteShortcutSelect({ value, onChange, host = false, mac = false, disabled }: {+ value: number; onChange: (value: number) => void; host?: boolean; mac?: boolean; disabled?: boolean;+}) {+ const { t, vis } = useCopy();+ const id = useId();+ const label = t(host ? "remote.hostStopKey" : "remote.releaseKey");+ return <div className="lr-capture-device lr-remote-shortcut">+ <Tooltip kind="hint-remote-stop" text={vis ? undefined : t(host ? "remote.hostStopKeyHelp" : "remote.releaseKeyHelp")}>+ <label htmlFor={id}><Glyph name="keyboard" size={16} />{vis ? null : label}</label>+ </Tooltip>+ <div className="lr-capture-device-controls">+ <select id={id} aria-label={label} value={value} disabled={disabled} onChange={event => onChange(Number(event.target.value))}>+ {REMOTE_SHORTCUT_KEYS.map(key => <option key={key} value={key}>Ctrl + {mac ? "Option" : "Alt"} + F{key}</option>)}+ </select>+ </div>+ </div>;+}diff --git a/src/client/components/living/RoomChatSettings.tsx b/src/client/components/living/RoomChatSettings.tsxindex ec53bc2f..395305d5 100644--- a/src/client/components/living/RoomChatSettings.tsx+++ b/src/client/components/living/RoomChatSettings.tsx@@ -5,21 +5,22 @@ import { formatChatTranscript } from "../../lib/room-chat-export";import { useCopy } from "../../ui/copy";import { Btn } from "./primitives";import { RoomChatOverlaySettings } from "./RoomChatOverlay";+import { Tooltip } from "./Tooltip";export function RoomChatSettings({ session }: { session: RoomInteractionSession }) {const { messages } = useSyncExternalStore(session.subscribe, session.getSnapshot);const { t, vis } = useCopy();- return <div className="lr-floating-scroll lr-chat-settings">+ return <div className="lr-floating-scroll lr-interaction-settings lr-chat-settings">{!vis && <p>{t("interaction.settingsHint")}</p>}<RoomChatOverlaySettings session={session} /><div className="lr-chat-export">{!vis && <p>{t("interaction.ephemeral")}</p>}- <Btn icon="save" title="interaction.export" cap="interaction.export" hint="hint-chat-export"- hintText="interaction.exportHint" disabled={!messages.length} onClick={() => {+ <Tooltip kind="hint-chat-export" text={vis ? undefined : t("interaction.exportLimit", { count: String(CHAT_HISTORY_LIMIT) })}>+ <Btn icon="save" title="interaction.export" cap="interaction.export" disabled={!messages.length} onClick={() => {downloadBlob(new Blob([formatChatTranscript(messages)], { type: "text/plain;charset=utf-8" }),`piik-chat-${new Date().toISOString().replace(/[:.]/g, "-")}.txt`);}} />- {!vis && <small>{t("interaction.exportLimit", { count: String(CHAT_HISTORY_LIMIT) })}</small>}+ </Tooltip></div></div>;}diff --git a/src/client/components/living/RoomChip.tsx b/src/client/components/living/RoomChip.tsxindex 92921c88..5c631683 100644--- a/src/client/components/living/RoomChip.tsx+++ b/src/client/components/living/RoomChip.tsx@@ -19,14 +19,34 @@ function LcdDigits({ code }: { code: string }) {);}-export function RoomCodePlaceholder() {- const { t } = useCopy();+export function RoomCodePlaceholder({ onCreate, disabled, busy }: {+ onCreate?: () => void;+ disabled?: boolean;+ busy?: boolean;+}) {+ const { t, vis } = useCopy();+ const contents = <>+ <LcdDigits code="----" />+ <span className="lr-lcd-action" aria-hidden="true">+ <Glyph name={onCreate ? busy ? "loader" : "plus" : "copy"} size={16}+ className={busy ? "lr-spin" : undefined} />+ </span>+ </>;+ if (onCreate) return (+ <Tooltip kind="hint-create-room" text={vis ? undefined : t("host.createRoomHint")}>+ <button type="button" className="lr-lcd is-empty is-create"+ aria-label={t("host.createRoom")} aria-busy={busy || undefined} disabled={disabled}+ onClick={event => {+ onCreate();+ if (event.detail !== 0) event.currentTarget.blur();+ }}>+ {contents}+ </button>+ </Tooltip>+ );return (<span className="lr-lcd is-empty" role="img" aria-label={t("host.roomCodePending")}>- <LcdDigits code="----" />- <span className="lr-lcd-copy-placeholder" aria-hidden="true">- <Glyph name="copy" size={16} />- </span>+ {contents}</span>);}diff --git a/src/client/components/living/RoomInteractions.tsx b/src/client/components/living/RoomInteractions.tsxindex 3cdbae60..a04985ac 100644--- a/src/client/components/living/RoomInteractions.tsx+++ b/src/client/components/living/RoomInteractions.tsx@@ -1,23 +1,34 @@-import { useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore, type KeyboardEvent, type RefObject } from "react";+import { useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode, type RefObject } from "react";import { normalizeChatText, MAX_CHAT_CODE_POINTS, isThrow, type ReactionId } from "../../../shared/room-interactions";import { RoomInteractionSession } from "../../lib/room-interactions";+import { labelParticipantNames } from "../../lib/viewer-presence";import { readRoomPreferences, saveRoomPreferences } from "../../lib/room-preferences";import { useCopy } from "../../ui/copy";import { Glyph } from "../../ui/icons";-import { Btn, SwitchItem } from "./primitives";+import { BackButton, Btn, SwitchItem } from "./primitives";import { participantColor } from "./participant-color";import { FloatingPanel } from "./FloatingPanel";import { PawnSvg } from "./Pawn";import { Couch, type CouchProps } from "./Couch";import { RoomReaction } from "./RoomReaction";-import { RoomReactionGrid, RoomReactionPicker, type InteractionParticipant } from "./RoomReactionPicker";+import { RoomReactionPicker, type InteractionParticipant } from "./RoomReactionPicker";+import { RoomQuickReactions } from "./RoomQuickReactions";import { RoomReactionActivity } from "./RoomReactionActivity";-import { Tooltip } from "./Tooltip";import { RoomChatToggle } from "./RoomChatOverlay";import { RoomChatSettings } from "./RoomChatSettings";+import { Tooltip } from "./Tooltip";+import { navigateTabs } from "../../ui/tab-navigation";import "./room-interactions.css";-type Props = CouchProps & { session: RoomInteractionSession | null };+type Props = CouchProps & {+ session: RoomInteractionSession | null;+ /** The room voice owner supplies controls; moving the panel never moves capture ownership. */+ voice?: {+ content: (onSelect: (peerId: string, trigger: HTMLButtonElement) => void) => ReactNode;+ settings: ReactNode;+ controls: ReactNode;+ };+};export function RoomInteractions(props: Props) {return props.session ? <ConnectedRoomInteractions key={props.session.key} {...props} session={props.session} /> : <Couch {...props} />;@@ -30,26 +41,24 @@ function ConnectedRoomInteractions(props: ConnectedProps) {return state.peerId ? <InteractionPanel {...props} state={state} /> : <Couch {...props} />;}-function InteractionPanel({ session, state, ...couch }: ConnectedProps & {+function InteractionPanel({ session, state, voice, ...couch }: ConnectedProps & {state: ReturnType<RoomInteractionSession["getSnapshot"]>;}) {const { t, vis } = useCopy();const [chatOpen, setChatOpen] = useState(false);const [chatDocument, setChatDocument] = useState<Document | null>(null);const detached = Boolean(chatDocument && chatDocument !== document);- const [settingsOpen, setSettingsOpen] = useState(false);+ const [settingsOpen, setSettingsOpen] = useState<"chat" | "voice" | null>(null);+ const [page, setPage] = useState<"chat" | "voice">("chat");const [effects, setEffects] = useState(() => readRoomPreferences().interactionEffects);const [target, setTarget] = useState<string | null>(null);- const [panelTarget, setPanelTarget] = useState<string | null>(null);+ const [panelTarget, setPanelTarget] = useState<{ peerId: string; trigger: HTMLElement } | null>(null);const [draft, setDraft] = useState("");const [lastSeen, setLastSeen] = useState<string | null>(null);const [visible, setVisible] = useState(false);const [following, setFollowing] = useState(true);const area = useRef<HTMLDivElement>(null);- const panelArea = useRef<HTMLDivElement>(null);const anchor = useRef<HTMLButtonElement | null>(null);- const panelAnchor = useRef<HTMLElement | null>(null);- const enterPanelPicker = useRef(false);const log = useRef<HTMLDivElement>(null);const readingPosition = useRef(0);const id = useId();@@ -59,13 +68,16 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {...couch.entries.map(entry => ({ peerId: entry.key, displayName: entry.name })),];const latest = state.messages.at(-1)?.id ?? null;+ const authors = labelParticipantNames(state.messages.map(message => message.sender));const unseenIndex = state.messages.findIndex(message => message.id === lastSeen);const unread = latest === lastSeen ? 0 : state.messages.length - unseenIndex - 1;const canSend = state.ready && !state.pending && !state.coolingDown;const person = participants.find(person => person.peerId === target);- const panelPerson = participants.find(person => person.peerId === panelTarget);+ const panelPerson = participants.find(person => person.peerId === panelTarget?.peerId);+ const expressing = panelTarget?.trigger.id === `${id}-express`;const latestReaction = state.reactions.at(-1);- const showChat = !settingsOpen;+ const showVoice = Boolean(voice && page === "voice");+ const showChat = !settingsOpen && !showVoice;const rosterKey = participants.map(person => person.peerId).join(",");const inspect = target === couch.host?.key && couch.host.onSelect ? () => { if (!couch.host?.selected) couch.host?.onSelect?.(); }: couch.entries.some(entry => entry.key === target && entry.selectable !== false) && couch.onSelect@@ -81,14 +93,6 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {useEffect(() => {if (panelTarget && !panelPerson) setPanelTarget(null);}, [panelTarget, panelPerson]);- useLayoutEffect(() => {- if (!panelTarget) return;- const selected = panelArea.current?.querySelector<HTMLButtonElement>('[aria-pressed="true"]');- selected?.scrollIntoView({ block: "nearest", inline: "nearest" });- // Enter the tray on opening, without stealing focus when retargeting.- if (enterPanelPicker.current) selected?.focus({ preventScroll: true });- enterPanelPicker.current = false;- }, [panelTarget, chatDocument]);useLayoutEffect(() => {const popup = document.getElementById(menuId);if (!popup) return;@@ -106,17 +110,7 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {session.send({ kind: "reaction", reaction, ...(targetPeerId ? { targetPeerId } : {}) });}function openPanelReactions(key: string, trigger: HTMLElement | null) {- enterPanelPicker.current = !panelPerson;- panelAnchor.current = trigger;- setPanelTarget(key);- }- function dismissPicker(event: KeyboardEvent) {- if (event.key !== "Escape" || event.defaultPrevented || event.nativeEvent.isComposing || !panelPerson) return;- event.preventDefault();- setPanelTarget(null);- const opener = panelAnchor.current?.isConnected ? panelAnchor.current- : event.currentTarget.ownerDocument.getElementById(`${id}-express`);- opener?.focus({ preventScroll: true });+ if (trigger) setPanelTarget(current => current?.peerId === key && current.trigger === trigger ? null : { peerId: key, trigger });}useLayoutEffect(() => {// Moving a popover between documents resets its native scroll offset.@@ -150,7 +144,7 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {!log.current?.getClientRects().length) return;setLastSeen(latest);log.current.scrollTop = log.current.scrollHeight;- }, [latest, chatOpen, visible, following, chatDocument, showChat, panelTarget]);+ }, [latest, chatOpen, visible, following, chatDocument, showChat]);return <div className="lr-room-interactions"><div className="visually-hidden" role="log" aria-label={t("interaction.reactions")}@@ -163,15 +157,32 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {})}</p>)}</div>- <FloatingPanel id={id} trigger={`${id}-toggle`} icon="chat" className="lr-interaction-panel" detachable- title={t(settingsOpen ? "interaction.settings" : "interaction.title")}- onOpenChange={(open, owner) => { setChatOpen(open); setChatDocument(owner); }}>- {settingsOpen && <>- <div className="lr-interaction-back"><Btn icon="chat" title="interaction.back" cap="interaction.back" size="dense"- hint="hint-chat-open" onClick={() => setSettingsOpen(false)} /></div>- <RoomChatSettings session={session} />- </>}- <div className="lr-interaction-conversation" hidden={!showChat} ref={panelArea} onKeyDown={dismissPicker}>+ <FloatingPanel id={id} trigger={`${id}-toggle`} icon={settingsOpen ? "sliders" : "chat"} className="lr-interaction-panel" detachable+ title={t(settingsOpen === "voice" ? "voice.settings" : settingsOpen ? "interaction.settings" : "interaction.title")}+ onOpenChange={(open, owner) => { setChatOpen(open); setChatDocument(owner); setPanelTarget(null); }}>+ {!settingsOpen && <div className="lr-interaction-navigation">+ {voice && <div className="lr-toggle lr-interaction-tabs" role="tablist" aria-label={t("interaction.title")}+ style={{ "--lr-segments": 2, "--lr-selected-index": showVoice ? 1 : 0 } as CSSProperties} onKeyDown={navigateTabs}>+ {(["chat", "voice"] as const).map(value => <button key={value} type="button" role="tab" id={`${id}-${value}-tab`}+ aria-selected={page === value} aria-controls={`${id}-${value}-page`} tabIndex={page === value ? 0 : -1}+ className={page === value ? "is-selected" : undefined} onClick={() => { setPanelTarget(null); setPage(value); }}>+ <Glyph name={value === "chat" ? "chat" : "microphone"} size={16} />+ <span className={vis ? "visually-hidden" : undefined}>{t(`interaction.${value}`)}</span>+ </button>)}+ </div>}+ <Btn icon="sliders" quiet size="dense" title={showVoice ? "voice.settings" : "interaction.settings"}+ hint={showVoice ? "hint-advanced" : "hint-chat-settings"}+ onClick={() => { setPanelTarget(null); setSettingsOpen(showVoice ? "voice" : "chat"); }} />+ </div>}+ {settingsOpen && <div className="lr-interaction-back"><BackButton onClick={() => setSettingsOpen(null)} /></div>}+ {settingsOpen && (settingsOpen === "voice" ? voice?.settings : <RoomChatSettings session={session} />)}+ {panelTarget && panelPerson && <RoomQuickReactions key={panelTarget.peerId} id={`${id}-reactions`}+ trigger={panelTarget.trigger} person={panelPerson} selfPeerId={state.peerId} hostPeerId={couch.host?.key}+ reactionIds={state.reactionIds} canSend={canSend} onSend={sendReaction}+ onClose={() => setPanelTarget(current => current === panelTarget ? null : current)} />}+ <div className="lr-interaction-page" id={`${id}-chat-page`} role={voice ? "tabpanel" : undefined}+ aria-labelledby={voice ? `${id}-chat-tab` : undefined} hidden={!showChat}>+ <div className="lr-interaction-conversation"><div className="lr-chat-history"><div className="lr-chat-log" role="log" aria-label={t("interaction.chat")} aria-live="polite" aria-relevant="additions" tabIndex={0} ref={log}onScroll={event => {@@ -187,52 +198,31 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {const participant = participants.find(person => person.peerId === message.sender.peerId);const avatar = <PawnSvg color={participantColor(message.sender.peerId)} host={message.sender.role === "host"} />;return <div key={message.id} className={`lr-chat-message${message.isSelf ? " is-self" : ""}${continuation ? " is-continuation" : ""}`}>- {!continuation && (participant ? <button type="button" className="lr-chat-avatar"+ {!continuation && (participant ? <Tooltip className="lr-chat-avatar" kind="hint-reaction-picker"+ text={vis ? undefined : t("interaction.withPerson", { name: participant.displayName })}>+ <button type="button"aria-label={t("interaction.withPerson", { name: participant.displayName })}- aria-expanded={panelTarget === participant.peerId} aria-controls={`${id}-reactions`}- onClick={event => openPanelReactions(participant.peerId, event.currentTarget)}>{avatar}</button>+ aria-expanded={panelTarget?.peerId === participant.peerId} aria-controls={`${id}-reactions`}+ onClick={event => openPanelReactions(participant.peerId, event.currentTarget)}>{avatar}</button></Tooltip>: <span className="lr-chat-avatar" aria-hidden="true">{avatar}</span>)}<div className="lr-chat-bubble">- <span className={continuation ? "visually-hidden" : "lr-chat-author"}>{message.sender.displayName}+ <span className={continuation ? "visually-hidden" : "lr-chat-author"}>{authors[index]!.label}{message.sender.role === "host" && <span className="visually-hidden"> · {t("common.host")}</span>}</span><p>{message.payload.kind === "chat" && message.payload.text}</p></div></div>;})}</div>- {!following && !panelPerson && state.messages.length > 0 && <button type="button" className="lr-chat-latest" onClick={() => {+ {!following && state.messages.length > 0 && <button type="button" className="lr-chat-latest" onClick={() => {setFollowing(true); log.current?.focus({ preventScroll: true });}}><Glyph name="arrowDown" size={15} /><span className={vis ? "visually-hidden" : undefined}>{unread ? t("interaction.unread", { count: String(unread) }) : t("interaction.latest")}</span></button>}- {chatOpen && !settingsOpen && effects && !panelPerson && latestReaction &&+ {chatOpen && showChat && effects && latestReaction &&<RoomReactionActivity key={latestReaction.id} reaction={latestReaction} participants={participants}hostPeerId={couch.host?.key} now={session.now} />}</div>- <div id={`${id}-reactions`} className="lr-floating-scroll lr-interaction-picker" hidden={!panelPerson}>- <div className="lr-interaction-people-scroll">- <div className="lr-interaction-people" role="group" aria-label={t("interaction.participant")}>- {participants.map(person => {- const name = person.peerId === state.peerId && !vis ? t("common.you") : person.displayName;- return <span key={person.peerId} data-room-peer={person.peerId}>- <Tooltip overflow={{ text: name, selector: ".lr-pawn-name" }}>- <button type="button" className={`lr-pawn${person.peerId === state.peerId ? " is-you" : ""}`}- aria-label={t("interaction.withPerson", { name: person.displayName })}- aria-pressed={panelTarget === person.peerId}- onClick={() => setPanelTarget(person.peerId)}>- <PawnSvg color={participantColor(person.peerId)} identity={person.peerId} host={person.peerId === couch.host?.key} />- <span className="lr-pawn-name">{name}</span>- </button>- </Tooltip>- </span>;- })}- </div>- </div>- <RoomReactionGrid person={panelPerson} selfPeerId={state.peerId} reactionIds={state.reactionIds} canSend={canSend} onSend={sendReaction} /></div>- {chatOpen && !settingsOpen && panelPerson && effects &&- <ReactionEffects state={state} participants={participants} area={panelArea} now={session.now} />}- </div>- <form className="lr-chat-compose" hidden={!showChat} onKeyDown={dismissPicker} onSubmit={event => {+ <form className="lr-chat-compose" onSubmit={event => {event.preventDefault();const text = normalizeChatText(draft);if (text && canSend) { setFollowing(true); session.send({ kind: "chat", text }); }@@ -240,7 +230,7 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {<div className="lr-chat-input-row"><input value={draft} onChange={event => setDraft(event.target.value)} maxLength={MAX_CHAT_CODE_POINTS * 2}aria-label={t("interaction.placeholder")} placeholder={vis ? "···" : t("interaction.placeholder")}- name="message" autoComplete="off" onFocus={() => setPanelTarget(null)}+ name="message" autoComplete="off"onKeyDown={event => { if (event.key === "Enter" && event.nativeEvent.isComposing) event.preventDefault(); }} /><Btn type="submit" icon="send" title="interaction.send" hint="hint-chat-send" tone="primary" size="compact" busy={state.pending?.payload.kind === "chat"}disabled={!canSend || !normalizeChatText(draft)} />@@ -248,18 +238,26 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {<div className="lr-chat-tools"><Btn id={`${id}-express`} icon="smile" title="interaction.express" cap="interaction.express" size="dense" quiethint="hint-reaction-picker"- expanded={Boolean(panelPerson)} controls={`${id}-reactions`} tone={panelPerson ? "on" : undefined}- onClick={() => {- if (panelPerson) setPanelTarget(null);- else openPanelReactions(state.peerId!, panelArea.current?.ownerDocument.getElementById(`${id}-express`) ?? null);- }} />+ expanded={expressing} controls={`${id}-reactions`} tone={expressing ? "on" : undefined}+ onClick={() => openPanelReactions(state.peerId!, (chatDocument ?? document).getElementById(`${id}-express`))} /><RoomChatToggle session={session} size="dense" quiet /><span className="lr-chat-count" aria-hidden="true" style={{ visibility: draft ? undefined : "hidden" }}>{Array.from(draft).length} / {MAX_CHAT_CODE_POINTS}</span>- <Btn icon="sliders" title="interaction.settings" hint="hint-chat-settings" size="dense" quiet- onClick={() => { setPanelTarget(null); setSettingsOpen(true); }} /></div></form>+ </div>+ {voice && <>+ <div className="lr-interaction-page" id={`${id}-voice-page`} role="tabpanel"+ aria-labelledby={`${id}-voice-tab`} hidden={!showVoice || settingsOpen !== null}>+ <div className="lr-interaction-conversation">+ <div className="lr-floating-scroll lr-voice-history">{chatOpen && showVoice && !settingsOpen && voice.content(openPanelReactions)}</div>+ {chatOpen && showVoice && effects && latestReaction &&+ <RoomReactionActivity key={latestReaction.id} reaction={latestReaction} participants={participants}+ hostPeerId={couch.host?.key} now={session.now} />}+ </div>+ </div>+ <div className="lr-interaction-voice-controls">{voice.controls}</div>+ </>}{(state.error || !state.ready) && <div className="lr-interaction-status" role="status"><Glyph name={state.error ? "alert" : "network"} size={14} /><span className={vis ? "visually-hidden" : undefined}>{t(state.error ? `interaction.error.${state.error}` : "interaction.reconnecting")}</span>@@ -286,10 +284,11 @@ function InteractionPanel({ session, state, ...couch }: ConnectedProps & {<Glyph name={state.error ? "alert" : "network"} size={14} /><span className={vis ? "visually-hidden" : undefined}>{t(state.error ? `interaction.error.${state.error}` : "interaction.reconnecting")}</span></div> : null}- {inspect && <button type="button" className="lr-person-menu-details" onClick={() => { document.getElementById(menuId)?.hidePopover(); inspect(); }}>+ {inspect && <Tooltip className="lr-person-menu-details-hint" kind="hint-details" text={vis ? undefined : t("host.details")}>+ <button type="button" className="lr-person-menu-details" onClick={() => { document.getElementById(menuId)?.hidePopover(); inspect(); }}><Glyph name="gauge" size={16} />{!vis && t("host.details")}<span className="visually-hidden">{vis && t("host.details")}</span>- </button>}+ </button></Tooltip>}{target === state.peerId && <div className="lr-interaction-effects"><SwitchItem checked={effects} onChange={enabled => {setEffects(enabled); saveRoomPreferences({ interactionEffects: enabled });diff --git a/src/client/components/living/RoomQuickReactions.tsx b/src/client/components/living/RoomQuickReactions.tsxnew file mode 100644index 00000000..b249b8fa--- /dev/null+++ b/src/client/components/living/RoomQuickReactions.tsx@@ -0,0 +1,44 @@+import { useLayoutEffect, useMemo, useRef, useState } from "react";+import type { ReactionId } from "../../../shared/room-interactions";+import { useCopy } from "../../ui/copy";+import { BackButton, Btn } from "./primitives";+import { RoomReactionGrid, RoomReactionTarget, type InteractionParticipant } from "./RoomReactionPicker";+import { useAnchoredPopover } from "./use-anchored-popover";++const QUICK_REACTIONS: readonly ReactionId[] = ["thumbsup", "thumbsdown", "tomato", "poop"];+const SELF_QUICK_REACTIONS: readonly ReactionId[] = ["thumbsup", "thumbsdown", "laugh", "heart"];++/** Brief person actions leave the conversation and composer available. */+export function RoomQuickReactions({ id, trigger, person, selfPeerId, hostPeerId, reactionIds, canSend, onSend, onClose }: {+ id: string; trigger: HTMLElement; person: InteractionParticipant; selfPeerId: string | null; hostPeerId?: string;+ reactionIds: readonly ReactionId[]; canSend: boolean;+ onSend: (reaction: ReactionId, targetPeerId?: string) => void; onClose: () => void;+}) {+ const { t } = useCopy();+ const [expanded, setExpanded] = useState(false);+ const anchor = useMemo(() => ({ current: trigger }), [trigger]);+ const panel = useRef<HTMLDivElement>(null);+ useAnchoredPopover(anchor, panel, { side: "above", align: "center" });+ useLayoutEffect(() => {+ const menu = panel.current!;+ if (menu.matches(":popover-open")) menu.hidePopover();+ menu.showPopover({ source: trigger });+ }, [trigger]);+ const quick = person.peerId === selfPeerId ? SELF_QUICK_REACTIONS : QUICK_REACTIONS;+ const choices = expanded ? reactionIds : quick.filter(id => reactionIds.includes(id));+ return <div id={id} ref={panel} popover="auto" role="dialog"+ aria-label={t("interaction.withPerson", { name: person.displayName })}+ className={`lr-floating-surface lr-quick-reactions${expanded ? " is-expanded" : ""}`}+ onToggle={event => {+ if (event.target === event.currentTarget && !event.currentTarget.matches(":popover-open")) onClose();+ }}>+ <div className="lr-quick-reactions-heading">+ {expanded ? <BackButton onClick={() => setExpanded(false)} />+ : <Btn icon="smile" title="interaction.moreReactions" size="dense" quiet hint="hint-reaction-picker"+ onClick={() => setExpanded(true)} />}+ <RoomReactionTarget person={person} selfPeerId={selfPeerId} hostPeerId={hostPeerId} />+ </div>+ <RoomReactionGrid person={person} selfPeerId={selfPeerId} reactionIds={choices} canSend={canSend}+ onSend={onSend} compact={!expanded} />+ </div>;+}diff --git a/src/client/components/living/RoomReactionPicker.tsx b/src/client/components/living/RoomReactionPicker.tsxindex e771fb13..76110d6b 100644--- a/src/client/components/living/RoomReactionPicker.tsx+++ b/src/client/components/living/RoomReactionPicker.tsx@@ -17,41 +17,48 @@ export function RoomReactionPicker({ person, selfPeerId, hostPeerId, reactionIdscanSend: boolean;onSend: (reaction: ReactionId, targetPeerId?: string) => void;}) {- const { t, vis } = useCopy();- const self = person?.peerId === selfPeerId;return <>- <div className="lr-person-menu-target" role="group"- aria-label={person ? t("interaction.withPerson", { name: person.displayName }) : t("interaction.express")}>- <span className="lr-person-menu-name">- <span className="lr-person-menu-portrait">{person- ? <PawnSvg color={participantColor(person.peerId)} host={person.peerId === hostPeerId} />- : <Glyph name="smile" size={22} />}</span>- <span>{!vis && <small>{t(self ? "interaction.express" : "interaction.toPerson")}</small>}- <Tooltip overflow={{ text: person?.displayName ?? t("interaction.participant"), selector: "b" }}>- <b>{person?.displayName ?? t("interaction.participant")}</b>- </Tooltip></span>- </span>- </div>+ <RoomReactionTarget person={person} selfPeerId={selfPeerId} hostPeerId={hostPeerId} /><RoomReactionGrid person={person} selfPeerId={selfPeerId} reactionIds={reactionIds} canSend={canSend} onSend={onSend} /></>;}-export function RoomReactionGrid({ person, selfPeerId, reactionIds, canSend, onSend }: {+export function RoomReactionTarget({ person, selfPeerId, hostPeerId }: {+ person: InteractionParticipant | undefined; selfPeerId: string | null; hostPeerId?: string;+}) {+ const { t, vis } = useCopy();+ const self = person?.peerId === selfPeerId;+ return <div className="lr-person-menu-target" role="group"+ aria-label={person ? t("interaction.withPerson", { name: person.displayName }) : t("interaction.express")}>+ <span className="lr-person-menu-name">+ <span className="lr-person-menu-portrait">{person+ ? <PawnSvg color={participantColor(person.peerId)} host={person.peerId === hostPeerId} />+ : <Glyph name="smile" size={22} />}</span>+ <span>{!vis && <small>{t(self ? "interaction.express" : "interaction.toPerson")}</small>}+ <Tooltip overflow={{ text: person?.displayName ?? t("interaction.participant"), selector: "b" }}>+ <b>{person?.displayName ?? t("interaction.participant")}</b>+ </Tooltip></span>+ </span>+ </div>;+}++export function RoomReactionGrid({ person, selfPeerId, reactionIds, canSend, onSend, compact = false }: {person: InteractionParticipant | undefined;selfPeerId: string | null;reactionIds: readonly ReactionId[];canSend: boolean;onSend: (reaction: ReactionId, targetPeerId?: string) => void;+ compact?: boolean;}) {const { t, vis } = useCopy();const self = person?.peerId === selfPeerId;- return <div className="lr-reaction-grid">+ return <div className={`lr-reaction-grid${compact ? " is-compact" : ""}`}>{reactionIds.filter(reaction => !isThrow(reaction) || (person && !self)).map(reaction => <button key={reaction} type="button"- className={isThrow(reaction) ? "lr-btn lr-reaction-prop" : "lr-reaction-option"}+ className={isThrow(reaction) ? `lr-btn lr-reaction-prop${compact ? " is-compact" : ""}` : "lr-btn is-compact is-quiet lr-reaction-option"}aria-label={t(`interaction.reaction.${reaction}`)} aria-disabled={!canSend || !person}onClick={() => { if (canSend && person) onSend(reaction, self ? undefined : person.peerId); }}><ReactionIcon reaction={reaction} />- {isThrow(reaction) && !vis && <span>{t(`interaction.reaction.${reaction}`)}</span>}+ {isThrow(reaction) && !vis && !compact && <span>{t(`interaction.reaction.${reaction}`)}</span>}</button>)}</div>;}diff --git a/src/client/components/living/RouteTree.tsx b/src/client/components/living/RouteTree.tsxindex 779cdc04..a902339d 100644--- a/src/client/components/living/RouteTree.tsx+++ b/src/client/components/living/RouteTree.tsx@@ -1,9 +1,10 @@// The connection topology as a real tree: the host roots direct P2P// viewers and the SFU node; relay children hang off their parent viewer.// Data comes from deriveParticipantTopology.-import { memo, useState } from "react";+import { memo, useState, useSyncExternalStore } from "react";import type { LabeledViewerPresence } from "../../lib/viewer-presence";+import type { RoomVoiceSession } from "../../room-voice/session";import { useElementWidth } from "../../lib/use-element-width";import {deriveParticipantTopology,@@ -30,6 +31,8 @@ interface TreeNode {const ROW_BASE = 40;const DEFAULT_TOPOLOGY_WIDTH = 640;+const noVoiceSubscription = () => () => {};+const noVoiceSnapshot = () => null;const PAWN_CENTER_X = 20;const PAWN_SCALE = 0.82;const PAWN_CENTER_Y = 24;@@ -92,6 +95,7 @@ export const RouteTree = memo(function RouteTree({hostIdentity,hostLabel,viewers,+ voice,selfPeerId,selectedPeerId,selectablePeerIds,@@ -102,6 +106,7 @@ export const RouteTree = memo(function RouteTree({hostIdentity?: string | null;hostLabel: string;viewers: readonly LabeledViewerPresence[];+ voice?: Pick<RoomVoiceSession, "subscribe" | "getSnapshot"> | null;selfPeerId?: string | null;selectedPeerId?: string | null;selectablePeerIds?: readonly string[];@@ -111,7 +116,16 @@ export const RouteTree = memo(function RouteTree({const [routeRef, containerWidth] = useElementWidth(DEFAULT_TOPOLOGY_WIDTH);const [hoveredPeerId, setHoveredPeerId] = useState<string | null>(null);const layoutConfig = topologyLayoutForWidth(containerWidth);- const topology = deriveParticipantTopology(hostPeerId, viewers);+ const roomVoice = useSyncExternalStore(voice?.subscribe ?? noVoiceSubscription, voice?.getSnapshot ?? noVoiceSnapshot, noVoiceSnapshot)?.room;+ // Presence retains picture readiness. Only this diagram projects the shared+ // room graph, including connected voice while no picture is being published.+ const topologyViewers = viewers.map((viewer): LabeledViewerPresence => {+ if (viewer.mediaReady || !roomVoice?.enabled) return viewer;+ const member = roomVoice.members.find(member => member.peerId === viewer.peerId);+ return member?.connected && member.joined && member.upstream.kind !== "none"+ ? { ...viewer, upstream: member.upstream, mediaReady: true } : viewer;+ });+ const topology = deriveParticipantTopology(hostPeerId, topologyViewers);const selectable = new Set(selectablePeerIds ?? (onSelectPeer ? viewers.map((viewer) => viewer.peerId) : []),);diff --git a/src/client/components/living/Tooltip.tsx b/src/client/components/living/Tooltip.tsxindex f558356b..05411e86 100644--- a/src/client/components/living/Tooltip.tsx+++ b/src/client/components/living/Tooltip.tsx@@ -33,13 +33,13 @@ import { replaySvgAnimations } from "../../ui/animation";import { useSurfaceDocument } from "../../ui/panel-window";import { comicStyle, getComicPresentation, type ComicTone, type ComicMotion } from "./comic-presentation";-const LONG_PRESS_MS = 500;+export const LONG_PRESS_MS = 500;const TOUCH_HIDE_MS = 1500;const PANEL_EXIT_MS = 160;-const HOVER_ENTER_MS = 500;+export const HOVER_ENTER_MS = 500;// Minimum clearance the re-picked alignment keeps to each viewport edge.const EDGE_MARGIN = 8;-const HOVER_EXIT_GRACE_MS = 160;+export const HOVER_EXIT_GRACE_MS = 160;// Paper panel before its mounted content is measured.const FALLBACK_PANEL_HEIGHT = 96;@@ -123,21 +123,26 @@ export function Tooltip({useLayoutEffect(() => {const element = overflow ? wrapRef.current?.querySelector<HTMLElement>(overflow.selector) : null;- if (!element || !overflow) {+ const view = element?.ownerDocument.defaultView;+ if (!element || !overflow || !view) {setOverflowing(false);return;}- let disposed = false;+ let disposed = false, frame = 0;const measure = () => {// SVG topology labels are shortened before rendering; HTML names use CSS.if (!disposed) setOverflowing(element.textContent !== overflow.text || element.scrollWidth > element.clientWidth);};measure();- const observer = new ResizeObserver(measure);+ // A clipped label can change its focus wrapper; measure outside resize delivery.+ const observer = new ResizeObserver(() => {+ view.cancelAnimationFrame(frame);+ frame = view.requestAnimationFrame(measure);+ });observer.observe(element);// Font loading can change scrollWidth without changing the clipped box.void element.ownerDocument.fonts?.ready.then(measure);- return () => { disposed = true; observer.disconnect(); };+ return () => { disposed = true; observer.disconnect(); view.cancelAnimationFrame(frame); };}, [overflow?.selector, overflow?.text, trigger?.type, trigger?.key, ownerDocument]);useLayoutEffect(() => {diff --git a/src/client/components/living/ViewerPlaybackSettings.tsx b/src/client/components/living/ViewerPlaybackSettings.tsxindex 1142ca4a..8125b76b 100644--- a/src/client/components/living/ViewerPlaybackSettings.tsx+++ b/src/client/components/living/ViewerPlaybackSettings.tsx@@ -1,13 +1,15 @@import type { ReactNode } from "react";import type { ViewerRoutePreference } from "../../../shared/protocol";-import type { VideoFit } from "../../media/video-geometry";+import type { VideoFit, VideoRotation } from "../../media/video-geometry";import { useCopy } from "../../ui/copy";import { Glyph } from "../../ui/icons";-import { Cap, Chip, Pill, RowGroup } from "./primitives";+import { Btn, Cap, Chip, Pill, RowGroup, SwitchItem } from "./primitives";export interface ViewerPlaybackSettingsProps {pictureFit: VideoFit;setPictureFit: (fit: VideoFit) => void;+ pictureRotation: VideoRotation;+ setPictureRotation: (rotation: VideoRotation) => void;route?: {preference: ViewerRoutePreference;sfuAvailable: boolean;@@ -17,10 +19,16 @@ export interface ViewerPlaybackSettingsProps {rejected: boolean;onChange: (preference: ViewerRoutePreference) => void;};+ relayVolunteer?: {+ enabled: boolean;+ pending: boolean;+ disabled: boolean;+ onChange: (enabled: boolean) => void;+ };}-// Local display and incoming-route intent only; media and routing keep their owners.-export function ViewerPlaybackSettings({ pictureFit, setPictureFit, route, displayActions, reconnect }: ViewerPlaybackSettingsProps & {+// Local display and connection intent; media and routing keep their owners.+export function ViewerPlaybackSettings({ pictureFit, setPictureFit, pictureRotation, setPictureRotation, route, relayVolunteer, displayActions, reconnect }: ViewerPlaybackSettingsProps & {displayActions: ReactNode; reconnect: ReactNode;}) {const { t, vis } = useCopy();@@ -29,7 +37,12 @@ export function ViewerPlaybackSettings({ pictureFit, setPictureFit, route, displ: `playback.routeHint.${route.preference}` as const;return <div className="lr-viewer-settings"><section aria-label={t("playback.pictureFit")}>- <div className="lr-viewer-settings-heading"><h3><Glyph name="tv" size={17} /><span className={vis ? "visually-hidden" : undefined}>{t("playback.pictureFit")}</span></h3></div>+ <div className="lr-viewer-settings-heading">+ <h3><Glyph name="tv" size={17} /><span className={vis ? "visually-hidden" : undefined}>{t("playback.pictureFit")}</span></h3>+ <Btn icon="rotatePicture" title="playback.rotation" cap="playback.rotation" size="dense"+ hint="hint-picture-rotation" hintText="playback.rotationHint" pressed={pictureRotation !== 0}+ onClick={() => setPictureRotation(pictureRotation === 0 ? 90 : 0)} />+ </div><RowGroup>{(["contain", "cover", "fill"] as const).map(fit => <Chip key={fit}selected={pictureFit === fit} title={t(`playback.fit.${fit}`)} hint={`hint-fit-${fit}`} onClick={() => setPictureFit(fit)}>{vis && <Glyph name={fit === "contain" ? "fitContain" : fit === "cover" ? "fitCover" : "fitStretch"} size={20} />}@@ -51,8 +64,8 @@ export function ViewerPlaybackSettings({ pictureFit, setPictureFit, route, displselected={route.preference === preference} title={t(`playback.route.${preference}`)}disabled={route.disabled || Boolean(locked)}hint={locked ? preference === "p2p" ? "hint-route-sfu-required" : "hint-route-p2p-required"- : preference === "auto" ? undefined : preference === "p2p" ? "hint-route-p2p" : "hint-route-sfu"}- hintText={locked ? t(locked) : undefined}+ : preference === "auto" ? "hint-route-auto" : preference === "p2p" ? "hint-route-p2p" : "hint-route-sfu"}+ hintText={t(locked ?? `playback.routeHint.${preference}`)}onClick={() => { if (route.preference !== preference) route.onChange(preference); }}>{vis && <Glyph name={preference === "auto" ? "branch" : preference === "p2p" ? "link" : "server"} size={17} />}<Cap k={`playback.route.${preference}`} />@@ -61,6 +74,15 @@ export function ViewerPlaybackSettings({ pictureFit, setPictureFit, route, displ{!vis && <p className={route.rejected ? "is-error" : undefined} role={route.rejected ? "status" : undefined}>{t(routeHint)}</p>}{vis && route.rejected && <Pill icon="alert" tone="bad" label={t(routeHint)} comic="settings-failed" />}</>}+ {relayVolunteer && <div className="lr-viewer-relay-setting" aria-busy={relayVolunteer.pending}>+ <RowGroup>+ {vis && <Glyph name="branch" size={18} />}+ <SwitchItem checked={relayVolunteer.enabled} disabled={relayVolunteer.disabled}+ onChange={relayVolunteer.onChange} label={t("playback.relayVolunteer")}+ note={t("playback.relayVolunteerHint")} hint="hint-relay-volunteer" />+ </RowGroup>+ {!vis && <p>{t("playback.relayVolunteerHint")}</p>}+ </div>}</section></div>;}diff --git a/src/client/components/living/button.css b/src/client/components/living/button.cssindex 3a16d8f1..81626e82 100644--- a/src/client/components/living/button.css+++ b/src/client/components/living/button.css@@ -13,6 +13,7 @@}button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }.lr-btn {+ position: relative;display: inline-grid;grid-auto-flow: column;align-items: center;diff --git a/src/client/components/living/comic-presentation.ts b/src/client/components/living/comic-presentation.tsindex ce47a6ea..83e32fdb 100644--- a/src/client/components/living/comic-presentation.ts+++ b/src/client/components/living/comic-presentation.ts@@ -71,6 +71,9 @@ const PRESENTATIONS: Partial<Record<ComicKind | HintKind, ComicPresentation>> ="hint-no-audio": LIMITED,"hint-pip-unavailable": LIMITED,"hint-fullscreen-unavailable": LIMITED,+ "hint-voice-closed": LIMITED,+ "hint-voice-host-microphone-unavailable": LIMITED,+ "hint-voice-microphone-unavailable": LIMITED,"hint-share-audio-fixed": LIMITED,"hint-silent-share-fixed": LIMITED,};diff --git a/src/client/components/living/hints/index.tsx b/src/client/components/living/hints/index.tsxindex c1872653..4662d82d 100644--- a/src/client/components/living/hints/index.tsx+++ b/src/client/components/living/hints/index.tsx@@ -7,7 +7,7 @@// by the tsx preview harness, which uses the classic JSX runtime.import { createElement, memo, type CSSProperties } from "react";-import type { HintKind, HintScene, MetricHintKind, InteractionHintKind, RemoteHintKind } from "../../../ui/visual-kinds";+import type { HintKind, HintScene, MetricHintKind, InteractionHintKind, RemoteHintKind, VoiceHintKind } from "../../../ui/visual-kinds";import { SET1_SCENES } from "./set1";import { SET2_SCENES } from "./set2";import { SET3_SCENES } from "./set3";@@ -18,6 +18,8 @@ import { METRIC_SCENES } from "./metrics";import { ADMISSION_SCENES } from "./admission";import { INTERACTION_SCENES } from "./interactions";import { REMOTE_SCENES } from "./remote-control";+import { RELAY_SCENES } from "./relay";+import { VOICE_SCENES } from "./voice";import { comicStyle, getComicPresentation, type ComicTone, type ComicMotion } from "../comic-presentation";export type { HintKind, HintScene };@@ -26,6 +28,7 @@ export const HINT_KINDS: readonly HintKind[] = ["hint-fit-contain","hint-fit-cover","hint-fit-fill",+ "hint-picture-rotation","hint-share-start","hint-share-stop","hint-microphone-on",@@ -43,6 +46,7 @@ export const HINT_KINDS: readonly HintKind[] = ["hint-reconnect","hint-copy-code","hint-shuffle-code",+ "hint-create-room","hint-copy-invite","hint-invite-link","hint-client-link",@@ -82,10 +86,12 @@ export const HINT_KINDS: readonly HintKind[] = ["hint-join-go","hint-theater","hint-theater-exit",+ "hint-route-auto","hint-route-p2p","hint-route-p2p-required","hint-route-sfu-required","hint-route-sfu",+ "hint-relay-volunteer","hint-client-local","hint-app-ready","hint-client-site",@@ -109,6 +115,7 @@ export const HINT_KINDS: readonly HintKind[] = [...Object.keys(METRIC_SCENES) as MetricHintKind[],...Object.keys(INTERACTION_SCENES) as InteractionHintKind[],...Object.keys(REMOTE_SCENES) as RemoteHintKind[],+ ...Object.keys(VOICE_SCENES) as VoiceHintKind[],];export const HINT_SCENES: Record<HintKind, HintScene> = {@@ -122,6 +129,8 @@ export const HINT_SCENES: Record<HintKind, HintScene> = {...ADMISSION_SCENES,...INTERACTION_SCENES,...REMOTE_SCENES,+ ...RELAY_SCENES,+ ...VOICE_SCENES,};const HINT_KIND_SET: ReadonlySet<string> = new Set(HINT_KINDS);diff --git a/src/client/components/living/hints/playback.tsx b/src/client/components/living/hints/playback.tsxindex 162ff81e..0676915d 100644--- a/src/client/components/living/hints/playback.tsx+++ b/src/client/components/living/hints/playback.tsx@@ -28,6 +28,7 @@ function PlaybackMotion() {.vls-pb-popout{animation:vlsPbPopout var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}.vls-pb-popin{animation:vlsPbPopin var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}.vls-pb-unavailable{animation:vlsPbUnavailable var(--comic-duration,3.2s) ease-in-out var(--comic-repeat,1) both}+.vls-pb-rotate{transform-box:fill-box;transform-origin:center;transform:rotate(90deg);animation:vlsPbRotate var(--comic-duration,3.2s) ease-in-out var(--comic-repeat,1) both}@keyframes vlsPbCue{0%,8%,34%,100%{transform:scale(1)}16%{transform:scale(.86)}25%{transform:scale(1.08)}}@keyframes vlsPbPlay{0%,18%{transform:translateX(-12px)}40%,100%{transform:none}}@keyframes vlsPbFreeze{0%{transform:translateX(-12px)}18%,100%{transform:none}}@@ -42,6 +43,7 @@ function PlaybackMotion() {@keyframes vlsPbPopout{0%,8%{transform:translate(-28px,-14px) scale(1.4)}34%,100%{transform:none}}@keyframes vlsPbPopin{0%,8%{transform:translate(32px,16px) scale(.65)}34%,100%{transform:none}}@keyframes vlsPbUnavailable{0%,8%,36%,100%{transform:none}16%{transform:translateX(-4px)}26%{transform:translateX(3px)}}+@keyframes vlsPbRotate{0%,8%{transform:rotate(0)}34%,100%{transform:rotate(90deg)}}${rmBlock(["vls-pb-cue", "vls-pb-play", "vls-pb-freeze", "vls-pb-waves .vls-pb-wave","vls-pb-waves.is-muting .vls-pb-wave", "vls-pb-cross",@@ -50,6 +52,7 @@ ${rmBlock([".vls-pb-waves.is-muting .vls-pb-wave,.vls-pb-chrome-out", "opacity:0"],[".vls-pb-cross,.vls-pb-chrome-in", "opacity:1"]],)}+${rmBlock(["vls-pb-rotate"], [[".vls-pb-rotate", "transform:rotate(90deg)"]])}${rmBlock(["vls-pb-listen", "vls-pb-flat", "vls-pb-unavailable"], [[".vls-pb-listen,.vls-pb-unavailable", "transform:none"],[".vls-pb-flat", "stroke-dashoffset:0;opacity:1"],@@ -213,10 +216,31 @@ function PictureFitHint({ theme, fit }: Parameters<HintScene>[0] & { fit: "conta</>;}+const PictureRotationHint: HintScene = ({ theme }) => <>+ <PlaybackMotion />+ {[0, 1].map(index => {+ const x = index * 160;+ return <g key={index}>+ <Frame x={x + 4} w={152} theme={theme} result={index === 1} />+ <MiniTv x={x + 48} y={13} w={96} h={70} />+ <g transform={`translate(${x + 96} 48)`}>+ <g className={index ? "vls-pb-rotate" : undefined}>+ <rect x={-32} y={-18} width={64} height={36} rx={2} fill="var(--wall-2)" />+ <circle cx={18} cy={-8} r={5} fill={SKY} />+ <path d="M-32 18-14-5 1 12 12 2 32 18Z" fill={YOU} />+ <rect x={-32} y={-18} width={64} height={36} rx={2} fill="none" stroke={FAINT} strokeWidth={1.5} />+ </g>+ </g>+ <Pawn x={x + 26} yb={81} s={11} color={YOU} eyes />+ </g>;+ })}+</>;+export const PLAYBACK_SCENES: Record<PlaybackHintKind, HintScene> = {"hint-fit-contain": props => <PictureFitHint {...props} fit="contain" />,"hint-fit-cover": props => <PictureFitHint {...props} fit="cover" />,"hint-fit-fill": props => <PictureFitHint {...props} fit="fill" />,+ "hint-picture-rotation": PictureRotationHint,"hint-local-play": (props) => <PlaybackHint {...props} paused={false} />,"hint-local-pause": (props) => <PlaybackHint {...props} paused />,"hint-volume": (props) => <AudioHint {...props} action="volume" />,diff --git a/src/client/components/living/hints/relay.tsx b/src/client/components/living/hints/relay.tsxnew file mode 100644index 00000000..a8d9ca90--- /dev/null+++ b/src/client/components/living/hints/relay.tsx@@ -0,0 +1,36 @@+import { FAINT, Frame, MiniTv, Pawn, SKY, YOU, rmBlock } from "../Comic";+import type { HintScene, RelayHintKind } from "../../../ui/visual-kinds";++// The same ordinary Viewer watches and passes the picture on in both panels.+// A voluntary switch adds outgoing branches, without another participant role.+const HintRelayVolunteer: HintScene = ({ theme }) => <>+ <style>{`+.vls-relay-more-a{animation:vlsRelayMoreA var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+.vls-relay-more-b{animation:vlsRelayMoreB var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+@keyframes vlsRelayMoreA{0%,10%,100%{opacity:0}24%,99.9%{opacity:1}}+@keyframes vlsRelayMoreB{0%,24%,100%{opacity:0}38%,99.9%{opacity:1}}+${rmBlock(["vls-relay-more-a", "vls-relay-more-b"], [[".vls-relay-more-a,.vls-relay-more-b", "opacity:1"]])}+ `}</style>+ {[0, 160].map((offset, index) => <g key={offset}>+ <Frame x={offset + 4} w={152} theme={theme} result={Boolean(index)} />+ <MiniTv x={offset + 18} y={22} w={34} h={23} />+ <Pawn x={offset + 49} yb={82} s={14} eyes gaze={-2} />+ <rect x={offset + 62} y={12} width={22} height={11} rx={5.5}+ fill="var(--wall-2)" stroke="var(--ink)" strokeWidth={1.5} />+ <circle cx={offset + (index ? 78 : 68)} cy={17.5} r={3.5} fill={index ? YOU : FAINT} />+ {(index ? [20, 40, 60, 80] : [32, 72]).map((y, child) => {+ const extra = index && (child === 1 || child === 2);+ return <g key={y} className={extra ? child === 1 ? "vls-relay-more-a" : "vls-relay-more-b" : undefined}>+ <path d={`M${offset + 64} 53 C${offset + 81} 53 ${offset + 86} ${y} ${offset + 106} ${y}`}+ fill="none" stroke={FAINT} strokeWidth={2} strokeLinecap="round" />+ <path d={`m${offset + 101} ${y - 3} 5 3-5 3`} fill="none" stroke={FAINT} strokeWidth={1.5} strokeLinejoin="round" />+ <MiniTv x={offset + 109} y={y - 6} w={15} h={11} />+ <Pawn x={offset + 139} yb={y + (index ? 9 : 10)} s={index ? 6 : 7} color={SKY} eyes gaze={-1} />+ </g>;+ })}+ </g>)}+</>;++export const RELAY_SCENES: Record<RelayHintKind, HintScene> = {+ "hint-relay-volunteer": HintRelayVolunteer,+};diff --git a/src/client/components/living/hints/set1.tsx b/src/client/components/living/hints/set1.tsxindex 18b50223..b1975999 100644--- a/src/client/components/living/hints/set1.tsx+++ b/src/client/components/living/hints/set1.tsx@@ -322,7 +322,7 @@ ${rmBlock(["vls-capture-choice"], [[".vls-capture-choice", "opacity:1;transform:</>;}-function MicrophoneHint({ theme, mode }: Parameters<HintScene>[0] & { mode: "on" | "off" | "volume" | "processing" }) {+export function MicrophoneHint({ theme, mode, host = true }: Parameters<HintScene>[0] & { mode: "on" | "off" | "volume" | "processing" | "unavailable"; host?: boolean }) {return <><style>{`.vls-mic-voice{animation:vlsMicVoice var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}@@ -331,16 +331,22 @@ function MicrophoneHint({ theme, mode }: Parameters<HintScene>[0] & { mode: "on"@keyframes vlsMicGain{0%,12%{transform:translateX(0)}40%,100%{transform:translateX(28px)}}.vls-mic-noise{animation:vlsMicNoise var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}@keyframes vlsMicNoise{0%,12%{opacity:.6}40%,100%{opacity:0}}+.vls-mic-unavailable{transform-box:fill-box;transform-origin:center;animation:vlsMicUnavailable var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+@keyframes vlsMicUnavailable{0%,10%{transform:translateX(-2px) rotate(-8deg)}26%{transform:translateX(1px) rotate(4deg)}42%,100%{transform:none}}${rmBlock(["vls-mic-voice"], [[".vls-mic-voice", "opacity:1;transform:none"]])}${rmBlock(["vls-mic-gain"], [[".vls-mic-gain", "transform:translateX(28px)"]])}${rmBlock(["vls-mic-noise"], [[".vls-mic-noise", "opacity:0"]])}+${rmBlock(["vls-mic-unavailable"], [[".vls-mic-unavailable", "transform:none"]], false)}`}</style><Frame x={4} w={152} theme={theme} /><Frame x={164} w={152} theme={theme} result />{[0, 160].map((x, index) => <g key={x} transform={`translate(${x} 0)`}>- <Pawn x={53} yb={76} s={14} eyes host />- <g transform="translate(78 38)"><Glyph name="microphone" size={27} /></g>- {mode === "processing" ? <>+ <Pawn x={53} yb={76} s={14} eyes host={host} />+ <g transform="translate(78 38)"><g className={mode === "unavailable" && index === 1 ? "vls-mic-unavailable" : undefined}>+ <Glyph name="microphone" size={27} />+ </g></g>+ {mode === "unavailable" ? <path d="m77 67 31-33" stroke={index ? "var(--comic-tone)" : FAINT} strokeWidth={3} strokeLinecap="round" />+ : mode === "processing" ? <><path className={index === 1 ? "vls-mic-voice" : undefined} d="M113 44q7 8 0 16m7-21q12 13 0 26" stroke={MINT} strokeWidth={2.5} strokeLinecap="round" fill="none" /><path className={index === 1 ? "vls-mic-noise" : undefined} d="m37 24 3-4 3 4 3-4m28 1 4 3 4-3 4 3m28 56 3-4 3 4 3-4" stroke={FAINT} strokeWidth={2} strokeLinecap="round" fill="none" opacity={index === 1 ? 0 : .6} /></> : mode === "volume" ? <>diff --git a/src/client/components/living/hints/set2.tsx b/src/client/components/living/hints/set2.tsxindex 65a3f93a..31927cb5 100644--- a/src/client/components/living/hints/set2.tsx+++ b/src/client/components/living/hints/set2.tsx@@ -127,9 +127,9 @@ ${rmBlock();/* ------------------------------------------------------------------ */-/* hint-shuffle-code: slots at rest → slots mid-roll + spark. */+/* Create/replace a code: empty/resting slots → rolling slots + spark. *//* ------------------------------------------------------------------ */-const SceneShuffleCode: HintScene = ({ theme }) => (+const RoomCodeHint = ({ theme, create = false }: Parameters<HintScene>[0] & { create?: boolean }) => (<><RoomResultMotion /><style>{`@@ -149,7 +149,9 @@ ${rmBlock(<Frame x={4} w={152} theme={theme} /><Frame x={164} w={152} theme={theme} result /><LcdBase x={41} y={25} />- <LcdSlots x={41} y={25} />+ {create ? <g stroke={INK_STAGE} strokeWidth={2} strokeLinecap="round">+ {SLOT_DX.map((dx) => <path key={dx} d={`M${42 + dx} 48h7`} />)}+ </g> : <LcdSlots x={41} y={25} />}<g className="vls-room-result"><LcdBase x={201} y={25} /><LcdSlots x={201} y={25} className="vls-shuf-slots" />@@ -296,7 +298,8 @@ ${rmBlock(["vls-pass-input"], [[".vls-pass-input", "transform:none;opacity:1"]])export const SET2_SCENES: Record<Set2Kind, HintScene> = {"hint-copy-code": SceneCopyCode,- "hint-shuffle-code": SceneShuffleCode,+ "hint-shuffle-code": RoomCodeHint,+ "hint-create-room": (props) => <RoomCodeHint {...props} create />,"hint-copy-invite": SceneCopyInvite,"hint-invite-link": (props) => <InviteLinkHint {...props} />,"hint-client-link": HintClientLink,diff --git a/src/client/components/living/hints/set4.tsx b/src/client/components/living/hints/set4.tsxindex 18470870..8db54ef6 100644--- a/src/client/components/living/hints/set4.tsx+++ b/src/client/components/living/hints/set4.tsx@@ -294,6 +294,28 @@ const HintTheaterExit: HintScene = ({ theme }) => (<TheaterHint theme={theme} exit />);+const HintRouteAuto: HintScene = ({ theme }) => <>+ <style>{`+.vls-auto-direct{animation:vlsAutoDirect var(--comic-duration,3.2s) ease-in-out var(--comic-repeat,1) both}+.vls-auto-forward{animation:vlsAutoForward var(--comic-duration,3.2s) ease-in-out var(--comic-repeat,1) both}+@keyframes vlsAutoDirect{0%,12%,62%,100%{opacity:0}26%,48%{opacity:1}}+@keyframes vlsAutoForward{0%,56%{opacity:0}74%,100%{opacity:1}}+${rmBlock(["vls-auto-direct", "vls-auto-forward"], [[".vls-auto-direct", "opacity:1"], [".vls-auto-forward", "opacity:0"]])}+ `}</style>+ {[0, 160].map((x, index) => <g key={x}>+ <Frame x={x + 4} w={152} theme={theme} result={Boolean(index)} />+ <path d={`M${x + 38} 59h84M${x + 38} 55l30-25m24 0 30 25`} fill="none"+ stroke={FAINT} strokeWidth={2} strokeDasharray="3 4" />+ <ServerBox x={x + 66} y={17} w={28} h={24} />+ {index === 1 && <>+ <path className="vls-auto-direct" d={`M${x + 38} 59h84`} fill="none" stroke={INK} strokeWidth={3} strokeLinecap="round" />+ <path className="vls-auto-forward" d={`M${x + 38} 55l30-25m24 0 30 25`} fill="none" stroke={INK} strokeWidth={3} strokeLinecap="round" />+ </>}+ <Pawn x={x + 32} yb={80} s={10} eyes host gaze={1} />+ <Pawn x={x + 128} yb={80} s={10} color={SKY} eyes gaze={-1} />+ </g>)}+</>;+/* hint-route-p2p: [two pawns apart] → [direct neutral arc pawn→pawn,route dot on the apex]. Demo: arc draws 6-28%, both pawns hop 30-42%,panel-1 pair blinks at 64%; rest ~58%. */@@ -465,6 +487,7 @@ export const SET4_SCENES: Record<Set4Kind, HintScene> = {"hint-join-go": HintJoinGo,"hint-theater": HintTheater,"hint-theater-exit": HintTheaterExit,+ "hint-route-auto": HintRouteAuto,"hint-route-p2p": HintRouteP2p,"hint-route-p2p-required": HintRouteP2pRequired,"hint-route-sfu": HintRouteSfu,diff --git a/src/client/components/living/hints/voice.tsx b/src/client/components/living/hints/voice.tsxnew file mode 100644index 00000000..6e75557b--- /dev/null+++ b/src/client/components/living/hints/voice.tsx@@ -0,0 +1,71 @@+import { FAINT, Frame, Pawn, SKY, rmBlock } from "../Comic";+import { Glyph } from "../../../ui/icons";+import type { ComicTheme, HintScene, VoiceHintKind } from "../../../ui/visual-kinds";+import { MicrophoneHint } from "./set1";++function VoiceMotion() {+ return <style>{`+.vls-voice-step{animation:vlsVoiceStep var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+.vls-voice-exit{animation-name:vlsVoiceExit}+.vls-voice-blocked{animation:vlsVoiceBlocked var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+.vls-voice-listen{animation:vlsVoiceListen var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}+@keyframes vlsVoiceStep{0%,10%{transform:translateX(-16px)}32%{transform:translate(2px,-3px)}44%,100%{transform:none}}+@keyframes vlsVoiceExit{0%,10%{transform:translateX(16px)}32%{transform:translate(-2px,-3px)}44%,100%{transform:none}}+@keyframes vlsVoiceBlocked{0%,10%{transform:translateX(-6px)}28%{transform:translateX(3px)}42%,100%{transform:none}}+@keyframes vlsVoiceListen{0%,12%,72%,100%{opacity:0}26%,56%{opacity:1}}+${rmBlock(["vls-voice-step", "vls-voice-exit", "vls-voice-listen"], [+ [".vls-voice-step,.vls-voice-exit", "transform:none"],+ [".vls-voice-listen", "opacity:1"],+])}+${rmBlock(["vls-voice-blocked"], [[".vls-voice-blocked", "transform:none"]], false)}+ `}</style>;+}++function MembershipHint({ theme, leave = false, host = false, closed = false }: { theme: ComicTheme; leave?: boolean; host?: boolean; closed?: boolean }) {+ return <><VoiceMotion />{[0, 160].map((x, index) => {+ const joined = !closed && Boolean(index) !== leave;+ return <g key={x}>+ <Frame x={x + 4} w={152} theme={theme} result={Boolean(index)} />+ <path d={`M${x + 65} 78h73V28H65`} fill="none" stroke={FAINT} strokeWidth={2} strokeDasharray="3 5" />+ <Pawn x={x + 117} yb={78} s={11} color={SKY} eyes host={closed} gaze={-1} />+ {closed && <g color={index ? "var(--comic-tone)" : "var(--ink)"}>+ <path d={`M${x + 65} 28v50`} fill="none" stroke="currentColor" strokeWidth={2.5} />+ <rect x={x + 53} y={42} width={24} height={27} rx={4} fill="var(--paper)" />+ <g transform={`translate(${x + 54} 43)`}><Glyph name="lock" size={22} /></g>+ </g>}+ <g className={index ? closed ? "vls-voice-blocked" : leave ? "vls-voice-step vls-voice-exit" : "vls-voice-step" : undefined}>+ <Pawn x={x + (joined ? 82 : 36)} yb={78} s={13} host={host} eyes gaze={joined ? 1 : -1} />+ <g transform={`translate(${x + (joined ? 73 : 27)} 17)`}><Glyph name="headphones" size={18} /></g>+ </g>+ </g>;+ })}</>;+}++function ListeningHint({ theme, deafen }: { theme: ComicTheme; deafen: boolean }) {+ return <><VoiceMotion />{[0, 160].map((x, index) => {+ const listening = Boolean(index) === !deafen;+ return <g key={x}>+ <Frame x={x + 4} w={152} theme={theme} result={Boolean(index)} />+ <Pawn x={x + 67} yb={79} s={14} eyes />+ <g transform={`translate(${x + 54} 17)`}><Glyph name={listening ? "headphones" : "headphonesOff"} size={26} /></g>+ {listening && <path className="vls-voice-listen" d={`M${x + 31} 26q-6 6 0 12m-6-16q-10 10 0 20`}+ fill="none" stroke={SKY} strokeWidth={2} strokeLinecap="round" />}+ </g>;+ })}</>;+}++export const VOICE_SCENES: Record<VoiceHintKind, HintScene> = {+ "hint-voice-open": props => <MembershipHint {...props} host />,+ "hint-voice-close": props => <MembershipHint {...props} host leave />,+ "hint-voice-closed": props => <MembershipHint {...props} closed />,+ "hint-voice-join": props => <MembershipHint {...props} />,+ "hint-voice-leave": props => <MembershipHint {...props} leave />,+ "hint-voice-microphone-on": props => <MicrophoneHint {...props} mode="on" host={false} />,+ "hint-voice-microphone-off": props => <MicrophoneHint {...props} mode="off" host={false} />,+ "hint-voice-host-microphone-unavailable": props => <MicrophoneHint {...props} mode="unavailable" />,+ "hint-voice-microphone-unavailable": props => <MicrophoneHint {...props} mode="unavailable" host={false} />,+ "hint-voice-microphone-volume": props => <MicrophoneHint {...props} mode="volume" host={false} />,+ "hint-voice-microphone-processing": props => <MicrophoneHint {...props} mode="processing" host={false} />,+ "hint-voice-deafen": props => <ListeningHint {...props} deafen />,+ "hint-voice-undeafen": props => <ListeningHint {...props} deafen={false} />,+};diff --git a/src/client/components/living/playback-controls.css b/src/client/components/living/playback-controls.cssindex 74d009f4..2466b225 100644--- a/src/client/components/living/playback-controls.css+++ b/src/client/components/living/playback-controls.css@@ -20,7 +20,8 @@.lr-tv-screen:has(> .lr-playback) { display: grid; width: 100%; aspect-ratio: auto; grid-template: minmax(0, 1fr) auto auto / minmax(0, 1fr); }/* Keep the primary status readable above compact controls. */.lr-tv-screen:has(> .lr-playback):has(> .lr-tv-overlay) { min-height: 168px; }-.lr-tv-screen:has(> .lr-playback) > video { grid-area: 1 / 1 / 3 / 2; min-height: 0; aspect-ratio: 16 / 9; height: auto; }+.lr-tv-screen:has(> .lr-playback) > video { grid-area: 1 / 1 / 3 / 2; min-height: 0; aspect-ratio: 16 / 9; height: auto; transform: var(--picture-transform, none); }+.lr-tv-screen:has(> .lr-playback) > video:is([data-picture-rotation="90"], [data-picture-rotation="270"]) { aspect-ratio: 9 / 16; }.lr-room.is-theater .lr-tv-screen:has(> .lr-playback) > video,.lr-tv-screen:fullscreen:has(> .lr-playback) > video { aspect-ratio: auto; height: 100%; }.lr-tv-screen > .lr-remote-input-surface { grid-area: 1 / 1 / 3 / 2; }@@ -65,13 +66,14 @@.lr-viewer-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; width: 100%; }.lr-viewer-settings section { min-width: 0; }.lr-viewer-settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: var(--control-dense-size); margin-bottom: 12px; }-.lr-viewer-settings h3, .lr-playback-overlay-settings h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; font-weight: 650; }+.lr-viewer-settings h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; font-weight: 650; }.lr-viewer-settings-heading .lr-btn { width: auto; }.lr-viewer-settings .lr-row-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }.lr-viewer-settings .lr-row-group > * { min-width: 0; }+.lr-viewer-settings .lr-row-group:has(.lr-switch-item) { display: flex; align-items: center; }+.lr-viewer-settings .lr-switch-item .lr-cap { white-space: normal; line-height: 1.4; }+.lr-viewer-relay-setting { margin-top: 14px; }.lr-viewer-settings .lr-chip { display: flex; align-items: center; justify-content: center; gap: 5px; width: 100%; min-height: 40px; padding: 6px; font-size: 12px; white-space: nowrap; }-.lr-playback-overlay-settings { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--control-edge); }-.lr-playback-overlay-settings .lr-chat-overlay-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-top: 8px; }.lr-viewer-settings p { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 10px 0 0; }.lr-viewer-settings p.is-error { color: var(--danger); }.lr-playback-display-menu { display: none; }diff --git a/src/client/components/living/primitives.tsx b/src/client/components/living/primitives.tsxindex e533d941..cd0f4079 100644--- a/src/client/components/living/primitives.tsx+++ b/src/client/components/living/primitives.tsx@@ -35,6 +35,10 @@ export function Cap({ k }: { k: CopyKey }) {return vis ? null : <span className="lr-cap">{t(k)}</span>;}+export function BackButton({ onClick }: { onClick: () => void }) {+ return <Btn icon="arrowLeft" title="common.back" cap="common.back" size="dense" quiet hint="hint-collapse" onClick={onClick} />;+}+export function Btn({id,icon,@@ -56,6 +60,7 @@ export function Btn({hintTone,hintMotion,draw,+ iconOverlay,}: {id?: string;icon: GlyphName;@@ -80,6 +85,8 @@ export function Btn({hintMotion?: ComicMotion;/** Draw-in spot id for state-beat toggle icons (see Glyph). */draw?: string;+ /** Noninteractive artwork that moves with the icon, such as its input meter. */+ iconOverlay?: ReactNode;}) {const { t, vis } = useCopy();const label = t(title);@@ -118,6 +125,7 @@ export function Btn({draw={draw}className={busy ? "lr-spin" : undefined}/>+ {iconOverlay}{cap ? <Cap k={cap} /> : null}</button>);diff --git a/src/client/components/living/remote-control.css b/src/client/components/living/remote-control.cssindex 3b87a0c1..41ed08fe 100644--- a/src/client/components/living/remote-control.css+++ b/src/client/components/living/remote-control.css@@ -19,7 +19,8 @@.lr-remote-modes > .lr-comic-tip-wrap { min-width: 0; }.lr-remote-modes button { min-width: 0; padding: 6px 4px; line-height: 1.3; white-space: normal; }.lr-remote-policy-actions { display: flex; align-items: center; gap: 8px; }-.lr-remote-settings > .lr-remote-policy-actions > * { flex: 1; }+.lr-remote-settings > .lr-remote-policy-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }+.lr-remote-settings > .lr-remote-policy-actions > * { min-width: 0; }.lr-remote-settings .lr-remote-policy-actions .lr-btn { width: 100%; }.lr-remote-policy-actions .lr-input { flex: 1; min-width: 0; }.lr-remote-policy-actions .lr-input input { min-width: 0; width: 100%; }@@ -41,6 +42,7 @@.lr-remote-request-actions > .lr-comic-tip-wrap { flex: 1; }.lr-remote-request-actions .lr-btn { width: 100%; }.lr-remote-note kbd { white-space: nowrap; font: 12px var(--mono); }+.lr-remote-shortcut { margin-block: 12px; text-align: start; }.lr-remote-touch-cursor { position: absolute; width: 22px; height: 26px; left: 50%; top: 50%; pointer-events: none; filter: drop-shadow(0 1px 2px #0008); }.lr-remote-touch-cursor path { fill: #fff; stroke: #22313e; stroke-width: 1.5; stroke-linejoin: round; }.lr-remote-zoom { grid-area: 1 / 1 / 2 / 2; z-index: 4; align-self: start; justify-self: end; padding: 8px; }diff --git a/src/client/components/living/room-interactions.css b/src/client/components/living/room-interactions.cssindex 70a2443b..0ec48a37 100644--- a/src/client/components/living/room-interactions.css+++ b/src/client/components/living/room-interactions.css@@ -1,24 +1,16 @@.lr-room-interactions { position: relative; width: min(960px, 100%); margin: 0 auto; }+.lr-interaction-navigation { display: flex; flex: none; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }+.lr-interaction-tabs { flex: 1; min-width: 0; }+.lr-interaction-navigation > .lr-comic-tip-wrap { flex: none; }+.lr-interaction-page { display: flex; flex: 1; flex-direction: column; min-height: 0; }+.lr-interaction-page[hidden] { display: none; }+.lr-voice-history { position: relative; flex: 1; }+.lr-interaction-voice-controls { display: flex; flex: none; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--control-edge); }.lr-interaction-couch { position: relative; }-.lr-interaction-conversation { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; --gift-arc: 40px; --gift-lift: 32px; }+.lr-interaction-conversation { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; }.lr-interaction-conversation[hidden] { display: none; }.lr-interaction-conversation .lr-reaction-flight { overflow: hidden; }-/* The picker belongs to the composer; opening it never moves the input or reading position. */-.lr-interaction-people-scroll { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 4px 0; margin-bottom: 4px; border-bottom: 1px solid var(--wall-2); }-.lr-interaction-people { display: flex; gap: 4px; width: max-content; min-width: 100%; }-.lr-interaction-people > span { display: flex; flex: none; max-width: 148px; }-.lr-interaction-people .lr-comic-tip-wrap { width: 100%; }-.lr-interaction-people .lr-pawn { display: flex; width: 100%; min-width: 0; min-height: 44px; gap: 6px; padding: 6px 10px; border-radius: 14px; transition: transform 150ms var(--spring), background-color 140ms ease; }-.lr-interaction-people .lr-pawn.is-you::after { display: none; }-.lr-interaction-people .lr-person { flex: none; width: 22px; height: 28px; }-.lr-interaction-panel .lr-interaction-people .lr-pawn-name { min-width: 0; max-width: 100%; margin: 0; padding: 0; font-size: 12px; font-weight: 600; line-height: 1.4; background: none; color: inherit; box-shadow: none; }-.lr-interaction-panel .lr-interaction-people .lr-pawn:is(:hover, :focus-visible) { background: var(--control-hover); }-.lr-interaction-people .lr-pawn:focus-visible { outline-offset: -3px; }-.lr-interaction-panel .lr-interaction-people .lr-pawn[aria-pressed="true"] { background: var(--control-selected); color: var(--control-selected-ink); box-shadow: inset 0 0 0 1px var(--action); }-.lr-interaction-picker { flex: 0 1 auto; max-height: calc(100% - 60px); padding-block: 4px 6px; border-top: 1px solid var(--wall-2); }-.lr-interaction-picker[hidden] { display: none; }-.lr-interaction-picker:not([hidden]) { transform-origin: center bottom; animation: lr-floating-enter 150ms var(--spring); }-.lr-interaction-back { flex: none; padding: 14px 0 0; }+.lr-interaction-back { flex: none; padding: 8px 0 0; }.lr-interaction-activity { position: absolute; z-index: 2; right: 4px; bottom: 8px; max-width: calc(100% - 8px); padding-top: 68px; pointer-events: none; --gift-arc: 30px; --gift-lift: 30px; }.lr-interaction-activity-people, .lr-interaction-activity-people > span { display: flex; align-items: center; gap: 12px; min-width: 0; }.lr-interaction-activity-people { padding: 8px 12px; border: 1px solid var(--control-edge); border-radius: 18px; background: color-mix(in srgb, var(--paper) 96%, transparent); box-shadow: var(--control-shadow); }@@ -44,9 +36,9 @@.lr-chat-message.is-continuation { margin-top: 4px; }.lr-chat-avatar { position: absolute; top: 1px; left: 0; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 12px; background: transparent; color: inherit; }.lr-chat-avatar .lr-person { width: 28px; height: 34px; }-button.lr-chat-avatar { cursor: pointer; transition: background-color 140ms ease; }-button.lr-chat-avatar:is(:hover, :focus-visible) { background: var(--control-hover); }-button.lr-chat-avatar:focus-visible { outline-offset: -3px; }+.lr-chat-avatar > button { display: grid; place-items: center; width: 100%; height: 100%; padding: 0; border: 0; border-radius: inherit; background: transparent; cursor: pointer; transition: background-color 140ms ease; }+.lr-chat-avatar > button:is(:hover, :focus-visible) { background: var(--control-hover); }+.lr-chat-avatar > button:focus-visible { outline-offset: -3px; }.lr-chat-message.is-self .lr-chat-avatar { left: auto; right: 0; }.lr-chat-bubble { min-width: 0; }.lr-chat-author { display: block; margin: 0 4px 5px; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }@@ -63,12 +55,11 @@ button.lr-chat-avatar:focus-visible { outline-offset: -3px; }.lr-chat-tools .lr-btn { flex: none; }.lr-chat-tools .lr-chat-count { padding: 0 4px; }.lr-chat-compose[hidden] { display: none; }-.lr-chat-settings { flex: 1; padding-block: 18px; }-.lr-chat-settings > p { margin: 0 0 20px; color: var(--muted); font-size: 12px; line-height: 1.6; }-.lr-chat-settings > .lr-chat-overlay-settings { margin-bottom: 22px; }-.lr-chat-export { display: grid; justify-items: start; gap: 8px; padding-top: 16px; border-top: 1px solid var(--wall-2); }+.lr-interaction-settings { flex: 1; padding-block: 4px 0; }+.lr-chat-settings > p { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }+.lr-chat-settings > .lr-chat-overlay-settings { margin-bottom: 16px; }+.lr-chat-export { display: grid; justify-items: start; gap: 8px; padding-top: 12px; border-top: 1px solid var(--wall-2); }.lr-chat-export > p { margin: 0 0 6px; color: var(--muted); font-size: 12px; line-height: 1.6; }-.lr-chat-export small { color: var(--muted); font-size: 12px; line-height: 1.6; }.lr-chat-count { flex: none; margin-left: auto; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }.lr-interaction-status { display: flex; flex: none; align-items: center; gap: 6px; min-height: 24px; margin-top: 6px; font-size: 11px; line-height: 1.5; color: var(--muted); }.lr-interaction-status > svg { flex: none; }@@ -82,16 +73,23 @@ button.lr-chat-avatar:focus-visible { outline-offset: -3px; }.lr-person-menu-name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; }.lr-person-menu-portrait { display: grid; place-items: center; width: 34px; height: 40px; flex: none; }.lr-person-menu-portrait .lr-person { width: 30px; height: 36px; }+.lr-quick-reactions { position: fixed; inset: auto; width: 264px; max-width: calc(100vw - 16px); margin: 0; padding: 8px; border-radius: 18px; overflow: auto; overscroll-behavior: contain; }+.lr-quick-reactions.is-expanded { width: 288px; }+.lr-quick-reactions-heading { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }+.lr-quick-reactions-heading > .lr-person-menu-target { flex: 1; min-width: 0; margin: 0; }+.lr-quick-reactions:not(.is-expanded) .lr-person-menu-target { order: -1; }+.lr-quick-reactions-heading > .lr-comic-tip-wrap { flex: none; }+.lr-quick-reactions .lr-person-menu-portrait { width: 24px; height: 30px; }+.lr-quick-reactions .lr-person-menu-portrait .lr-person { width: 20px; height: 26px; }.lr-reaction-grid { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; }-.lr-reaction-grid button { min-width: 0; min-height: 44px; cursor: pointer; touch-action: manipulation; }-.lr-reaction-option { grid-column: span 2; display: grid; place-items: center; padding: 4px; border: 1px solid transparent; background: transparent; color: inherit; border-radius: 14px; font-size: 26px; line-height: 1; transition: background-color 140ms ease, border-color 140ms ease; }-.lr-reaction-prop { grid-column: span 7; height: auto; margin-top: 6px; padding: 6px 4px; gap: 4px; border-width: 1px; border-radius: 14px; background: var(--wall); font-size: 12px; font-weight: 600; line-height: 1.3; white-space: normal; text-wrap: balance; }+.lr-reaction-grid.is-compact { display: flex; align-items: center; }+.lr-reaction-grid button { min-width: 0; min-height: var(--control-compact-size); cursor: pointer; touch-action: manipulation; }+.lr-reaction-grid.is-compact button { flex: 1; width: var(--control-compact-size); height: var(--control-compact-size); margin: 0; padding: 0; }+.lr-reaction-option { grid-column: span 2; padding: 4px 0; font-size: 26px; line-height: 1; }+.lr-reaction-prop { grid-column: span 7; display: grid; place-items: center; height: auto; margin-top: 6px; padding: 6px 4px; gap: 4px; border-width: 1px; border-radius: 14px; background: var(--wall); font-size: 12px; font-weight: 600; line-height: 1.3; white-space: normal; text-wrap: balance; }.lr-reaction-prop > svg { width: 26px; height: 26px; }.lr-reaction-grid button[aria-disabled="true"] { opacity: .4; cursor: default; }-.lr-reaction-option > :first-child { transition: transform 180ms var(--spring); }-.lr-reaction-option:is(:hover, :focus-visible):not([aria-disabled="true"]) { background: var(--control-hover); border-color: var(--action); }-.lr-reaction-option:is(:hover, :focus-visible):not([aria-disabled="true"]) > :first-child { transform: translateY(-2px); }-.lr-reaction-option:active:not([aria-disabled="true"]) > :first-child { transform: scale(.9); }+.lr-person-menu-details-hint { width: 100%; }.lr-person-menu-details { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 40px; padding: 8px; margin-top: 8px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }.lr-person-menu-details:is(:hover, :focus-visible) { background: var(--control-hover); color: var(--ink); }.lr-person-menu .lr-interaction-effects { font-size: 11px; }@@ -217,14 +215,10 @@ button.lr-chat-avatar:focus-visible { outline-offset: -3px; }[data-comic-reduced-motion] .lr-reaction-body { transform: none !important; }[data-comic-reduced-motion] .lr-reaction-glyph { animation: none; }[data-comic-reduced-motion] .lr-reaction-accents { display: none; }-[data-comic-reduced-motion] .lr-reaction-grid button > :first-child { transition: none; transform: none !important; }-[data-comic-reduced-motion] .lr-interaction-picker { animation: none; }@media (prefers-reduced-motion: reduce) {- .lr-interaction-picker { animation: none !important; }.lr-reaction-projectile { animation: none; transform: translate(var(--to-x), calc(var(--to-y) - 33px)); }.is-gift .lr-reaction-projectile { transform: translate(var(--to-x), calc(var(--to-y) - var(--gift-lift, 76px))); }.lr-reaction-body { transform: none !important; }.lr-reaction-glyph { animation: none; }.lr-reaction-accents { display: none; }- .lr-reaction-grid button > :first-child { transition: none; transform: none !important; }}diff --git a/src/client/components/living/use-anchored-popover.ts b/src/client/components/living/use-anchored-popover.tsindex eab8c326..3d39e5d5 100644--- a/src/client/components/living/use-anchored-popover.ts+++ b/src/client/components/living/use-anchored-popover.ts@@ -1,4 +1,5 @@import { useLayoutEffect, type RefObject } from "react";+import { useSurfaceDocument } from "../../ui/panel-window";// Native popovers own visibility, dismissal and focus. This only places a// menu beside its anchor, within the document displaying it.@@ -9,6 +10,7 @@ export function useAnchoredPopover(maxHeight?: number; minVisibleHeight?: number; enabled?: boolean;} = {},) {+ const ownerDocument = useSurfaceDocument();useLayoutEffect(() => {const anchor = trigger.current, menu = panel.current;if (!enabled || !anchor || !menu) return;@@ -69,5 +71,5 @@ export function useAnchoredPopover(viewport?.removeEventListener("resize", schedule);viewport?.removeEventListener("scroll", schedule);};- }, [trigger, panel, side, align, maxHeight, minVisibleHeight, enabled]);+ }, [trigger, panel, side, align, maxHeight, minVisibleHeight, enabled, ownerDocument]);}diff --git a/src/client/components/living/use-video-rotation.ts b/src/client/components/living/use-video-rotation.tsnew file mode 100644index 00000000..7eee0ef1--- /dev/null+++ b/src/client/components/living/use-video-rotation.ts@@ -0,0 +1,20 @@+import { useLayoutEffect, type RefObject } from "react";+import { applyVideoRotation, type VideoFit, type VideoRotation } from "../../media/video-geometry";++export function useVideoRotation(videoRef: RefObject<HTMLVideoElement | null>, fit: VideoFit | undefined, rotation: VideoRotation): void {+ useLayoutEffect(() => {+ const video = videoRef.current;+ if (!video) return;+ const refresh = () => applyVideoRotation(video, rotation);+ refresh();+ const observer = new ResizeObserver(refresh);+ observer.observe(video);+ video.addEventListener("resize", refresh);+ video.addEventListener("loadedmetadata", refresh);+ return () => {+ observer.disconnect();+ video.removeEventListener("resize", refresh);+ video.removeEventListener("loadedmetadata", refresh);+ };+ }, [videoRef, fit, rotation]);+}diff --git a/src/client/lib/room-preferences.ts b/src/client/lib/room-preferences.tsindex 1619dc8b..d4407dbb 100644--- a/src/client/lib/room-preferences.ts+++ b/src/client/lib/room-preferences.ts@@ -1,6 +1,6 @@import { z } from "zod";import { viewerRoutePreferenceSchema } from "../../shared/protocol";-import { remoteControlModeSchema } from "../remote-control/protocol";+import { remoteControlModeSchema, remoteShortcutKeySchema } from "../remote-control/protocol";const STORAGE_KEY = "piik:room-preferences:v1";export const CHAT_OVERLAY_LIMITS = { scale: [.8, 1.3], opacity: [.4, 1] } as const;@@ -8,6 +8,7 @@ export const REMOTE_KEYBOARD_PAGES = ["letters", "symbols", "functions", "text"]const roomPreferencesSchema = z.object({pictureFit: z.enum(["contain", "cover", "fill"]).default("contain"),+ pictureRotation: z.union([z.literal(0), z.literal(90), z.literal(180), z.literal(270)]).catch(0).default(0),routePreference: viewerRoutePreferenceSchema.default("auto"),overlayEnabled: z.boolean().default(false),overlayAppearance: z.object({@@ -15,8 +16,13 @@ const roomPreferencesSchema = z.object({opacity: z.number().min(CHAT_OVERLAY_LIMITS.opacity[0]).max(CHAT_OVERLAY_LIMITS.opacity[1]),}).default({ scale: 1, opacity: 1 }),interactionEffects: z.boolean().default(true),+ voiceInput: z.object({ deviceId: z.string(), volume: z.number().min(0).max(2), voiceProcessing: z.boolean() })+ .default({ deviceId: "", volume: 1, voiceProcessing: true }),+ voiceListeningVolume: z.number().min(0).max(2).default(1),keyboardPage: z.enum(REMOTE_KEYBOARD_PAGES).default("letters"),combineKeys: z.boolean().default(false),+ remoteReleaseKey: remoteShortcutKeySchema.default(10),+ remoteStopKey: remoteShortcutKeySchema.default(10),remoteControlMode: remoteControlModeSchema.exclude(["off"]).default("ask"),});export type RoomPreferences = z.infer<typeof roomPreferencesSchema>;diff --git a/src/client/lib/signaling.ts b/src/client/lib/signaling.tsindex b7ea4bb1..043a68db 100644--- a/src/client/lib/signaling.ts+++ b/src/client/lib/signaling.ts@@ -8,11 +8,13 @@ import {type RoutePolicy,type ViewerRoutePreference,type ServerMessage,+ type IceConfig,} from "../../shared/protocol";import type { SignalConnectionState } from "../types";import { qualitySettingsEqual } from "../media/quality";import { debugEvent } from "./debug";import { RoomInteractionSession } from "./room-interactions";+import { RoomVoiceSession } from "../room-voice/session";import { getSiteAccess } from "./api";type WithoutProtocolEnvelope<T> = T extends {@@ -82,6 +84,8 @@ export class SignalingClient {private audioPresenceEnabled = false;private hostAudioAvailable: boolean | null = null;interactions: RoomInteractionSession | null = null;+ roomVoice: RoomVoiceSession | null = null;+ private voiceIceConfig: IceConfig = { iceServers: [] };private socket: WebSocket | null = null;private stopped = false;private authenticatedPeerId: string | null = null;@@ -100,6 +104,7 @@ export class SignalingClient {private visibilityListenerAttached = false;private hostQualityIntent: HostQualityIntent | null = null;private pendingShareGeneration: string | null = null;+ private relayVolunteerIntent: { enabled: boolean; capacity: number } | null = null;constructor(private readonly identity: SignalingIdentity,@@ -129,6 +134,18 @@ export class SignalingClient {if (this.authenticatedPeerId) this.send({ type: "subscribe-remote-input" });}+ enableRoomVoice(): RoomVoiceSession | null {+ if (this.stopped) return null;+ if (!this.roomVoice) {+ this.roomVoice = new RoomVoiceSession(message => this.send(message), this.voiceIceConfig);+ if (this.authenticatedPeerId) {+ this.roomVoice.authenticated(this.authenticatedPeerId, this.identity.role);+ this.send({ type: "subscribe-room-voice" });+ }+ }+ return this.roomVoice;+ }+enableAudioPresence(): void {if (this.stopped) return;this.audioPresenceEnabled = true;@@ -160,6 +177,20 @@ export class SignalingClient {this.send({ type: "set-viewer-route-preference", preference });}+ get relayVolunteerRequest(): Readonly<{ enabled: boolean; capacity: number }> | null {+ return this.relayVolunteerIntent;+ }++ setRelayVolunteer(enabled: boolean, capacity: number): boolean {+ if (this.stopped || this.identity.role !== "viewer") return false;+ this.relayVolunteerIntent = { enabled, capacity };+ return this.authenticatedPeerId === null || this.flushRelayVolunteerIntent();+ }++ private flushRelayVolunteerIntent(): boolean {+ return this.relayVolunteerIntent !== null && this.send({ type: "set-relay-volunteer", ...this.relayVolunteerIntent });+ }+start(): void {if (this.socket || this.stopped) {return;@@ -172,6 +203,7 @@ export class SignalingClient {stop(): void {this.interactions?.close();+ this.roomVoice?.close();this.stopped = true;this.authenticatedPeerId = null;this.clearTimers();@@ -179,6 +211,7 @@ export class SignalingClient {this.terminalMessage = null;this.hostQualityIntent = null;this.pendingShareGeneration = null;+ this.relayVolunteerIntent = null;const socket = this.socket;this.socket = null;if (socket && socket.readyState < WebSocket.CLOSING) {@@ -429,6 +462,12 @@ export class SignalingClient {debugEvent("signal", "authenticated", { role: this.identity.role, generation });this.refreshSignalingWatchdog();this.interactions?.authenticated(message.peerId);+ this.voiceIceConfig = message.iceConfig;+ if (this.roomVoice) {+ this.roomVoice.updateIceConfig(message.iceConfig);+ this.roomVoice.authenticated(message.peerId, this.identity.role);+ this.send({ type: "subscribe-room-voice" });+ }if (this.remoteInputEnabled) this.send({ type: "subscribe-remote-input" });// Discovery can complete after the authentication request was sent.if (!routeSelectionRequestedAtAuth && this.identity.role === "viewer" && this.identity.routePreference !== undefined) {@@ -453,6 +492,7 @@ export class SignalingClient {this.hostQualityIntent = null;}if (this.interactions?.receive(message)) return;+ if (this.roomVoice?.receive(message)) return;if (message.type === "host-status" &&this.identity.role === "host" &&@@ -463,6 +503,9 @@ export class SignalingClient {}this.events.onMessage(message);if (message.type === "authenticated") {+ // The page first sends its ordinary relay report. Restore only this+ // page's explicit intent after that legacy report, in wire order.+ this.flushRelayVolunteerIntent();this.reconcileHostQualityIntent(message);}});@@ -477,6 +520,7 @@ export class SignalingClient {this.socket = null;this.authenticatedPeerId = null;this.interactions?.disconnected();+ this.roomVoice?.disconnected();debugEvent("signal", "closed", { role: this.identity.role, code: event.code,reconnecting: !this.stopped && shouldReconnectSignaling(event.code) });this.clearSignalingWatchdog();@@ -785,6 +829,7 @@ export class SignalingClient {this.socket = null;this.authenticatedPeerId = null;this.interactions?.disconnected();+ this.roomVoice?.disconnected();this.clearAuthenticationTimer();this.clearSignalingWatchdog();if (socket && socket.readyState < WebSocket.CLOSING) {diff --git a/src/client/lib/viewer-presence.ts b/src/client/lib/viewer-presence.tsindex 6d7795e8..9d4ddc1b 100644--- a/src/client/lib/viewer-presence.ts+++ b/src/client/lib/viewer-presence.ts@@ -33,19 +33,18 @@ function comparePeerIdentity(return left.peerId < right.peerId ? -1 : left.peerId > right.peerId ? 1 : 0;}-function labelPresence<T extends PresenceIdentity>(+export function labelParticipantNames<T extends PresenceIdentity>(entries: readonly T[],): LabeledPresence<T>[] {- const nameCounts = new Map<string, number>();+ const peersByName = new Map<string, Set<string>>();entries.forEach((entry) => {- nameCounts.set(- entry.displayName,- (nameCounts.get(entry.displayName) ?? 0) + 1,- );+ const peers = peersByName.get(entry.displayName) ?? new Set<string>();+ peers.add(entry.peerId);+ peersByName.set(entry.displayName, peers);});const duplicateNames = new Set(- [...nameCounts.entries()]- .filter(([, count]) => count > 1)+ [...peersByName.entries()]+ .filter(([, peers]) => peers.size > 1).map(([displayName]) => displayName),);const suffixLengths = entries.map((entry) =>@@ -66,7 +65,7 @@ function labelPresence<T extends PresenceIdentity>(});let extended = false;for (const indexes of collisions.values()) {- if (indexes.length < 2) {+ if (new Set(indexes.map(index => entries[index].peerId)).size < 2) {continue;}for (const index of indexes) {@@ -96,7 +95,7 @@ function labelPresence<T extends PresenceIdentity>(export function labelParticipantSnapshot(participants: readonly ParticipantPresenceEntry[],): LabeledParticipantSnapshot {- const labeled = labelPresence(participants);+ const labeled = labelParticipantNames(participants);return {host:labeled.find(diff --git a/src/client/locales/en.ts b/src/client/locales/en.tsindex 1788cfde..8ca3ba9d 100644--- a/src/client/locales/en.ts+++ b/src/client/locales/en.ts@@ -56,11 +56,13 @@ export const en: Record<CopyKey, string> = {"remote.mode.room": "Room Viewers","remote.mode.password": "Password","remote.help.ask": "Decide whether to allow each control request.",- "remote.help.room": "Any Viewer in this room can control this computer when no one else is controlling it.",+ "remote.help.room": "Any room Viewer can take control when no one else has it.","remote.help.password": "Viewers can control this computer after entering the control password.","remote.policyLifetime": "Applies to this shared source only. Changing sources or stopping turns remote control off.","remote.password": "Control password","remote.apply": "Apply",+ "remote.enable": "Enable",+ "remote.enableRoom": "Allow Viewers","remote.connecting": "Connecting control","remote.reason.password": "Incorrect control password","remote.reason.retry": "Please wait a moment and try again",@@ -91,13 +93,22 @@ export const en: Record<CopyKey, string> = {"remote.consent": "Allowing control gives this Viewer access to this computer's mouse and keyboard.","remote.waiting": "Requesting control","remote.shortcut": "Stop immediately on this computer:",+ "remote.hostStopKey": "Host stop shortcut",+ "remote.hostStopKeyHelp": "Stops control from any app on this computer. Saved for this site.",+ "remote.releaseKey": "Exit control shortcut",+ "remote.releaseKeyHelp": "Ends your control from this page or its detached keyboard. Saved in this browser.",+ "remote.shortcutFailed": "Shortcut unavailable. Choose another and try again.","common.loading": "Loading","playback.controls": "Player controls","playback.showControls": "Show playback controls","playback.overlay": "On-screen chat","playback.more": "Playback settings","playback.pictureFit": "Picture fit",+ "playback.rotation": "Rotate picture",+ "playback.rotationHint": "Switch the page's picture between landscape and portrait without device auto-rotation.","playback.connection": "Connection",+ "playback.relayVolunteer": "Help relay to more viewers",+ "playback.relayVolunteerHint": "Uses more upload bandwidth for this visit.","playback.fit.contain": "Fit","playback.fit.cover": "Fill","playback.fit.fill": "Stretch",@@ -143,10 +154,13 @@ export const en: Record<CopyKey, string> = {"common.roomCode": "Room code","host.roomCodePending": "A room code appears when sharing starts",+ "host.createRoom": "Create room",+ "host.createRoomHint": "Create a room for chat and voice. Sharing can start later.","common.copy": "Copy","common.copied": "Copied","common.copyFailed": "Copy failed","common.cancel": "Cancel",+ "common.back": "Back","common.retry": "Retry","common.refresh": "Refresh page","common.edit": "Edit",@@ -173,6 +187,11 @@ export const en: Record<CopyKey, string> = {"client.launch.linkHint": "Create one temporary public invitation link","client.launch.room": "Create a room on this device","client.connect.action": "Connect Piik App",+ "client.connect.discovering": "Looking for Piik App…",+ "client.connect.permissionHint": "If your browser asks, allow access to this device or local network to find App.",+ "client.connect.found": "Piik App found. Open its page to continue.",+ "client.connect.open": "Open App page",+ "client.connect.approving": "Waiting for App approval…","client.connect.standby": "App is ready","client.connect.guide": "Connect a site","client.connect.standbyHint": "Click App at the top right of a Piik site, then choose Allow access.",@@ -195,6 +214,7 @@ export const en: Record<CopyKey, string> = {"client.launch.lanAddress": "Local invitation address","client.launch.chooseAddress": "Choose an address","client.launch.lanHint": "Choose an address on the same network as your friends.",+ "client.launch.localHTTPS": "Local invitations use HTTPS. Confirm the local certificate on your first visit.","client.launch.lanUnavailable": "No local network address is available. Connect to a network and refresh this page.","client.launch.localAccess": "Site passphrase (optional)","client.launch.accessSettings": "Site passphrase",@@ -258,8 +278,6 @@ export const en: Record<CopyKey, string> = {"host.sourcePicker.camera": "Share camera: {title}","host.camera.denied": "Camera access was not allowed. Allow it in your browser and try again.","host.camera.unavailable": "The camera is unavailable. Check that it is connected and not in use by another app.",- "host.microphone.enable": "Turn on microphone",- "host.microphone.label": "Microphone","host.microphone.settings": "Microphone settings","host.device.microphone": "Microphone","host.device.camera": "Camera",@@ -270,19 +288,58 @@ export const en: Record<CopyKey, string> = {"host.device.permission.microphone": "Turn on the microphone and allow access to see the available devices here.","host.microphone.volume": "Microphone volume","host.microphone.voiceProcessing": "Noise & echo reduction",- "host.microphone.voiceProcessingHint": "When on, the browser reduces microphone noise and echo and adjusts volume automatically. When off, these features are disabled.",- "host.microphone.voiceProcessingUsage": "On for speech; off for music or virtual audio.",+ "host.microphone.voiceProcessingHint": "Reduce microphone noise and echo and adjust volume automatically. Turn this off if your input already processes voice.","interaction.open": "Interact","interaction.title": "Interactions","interaction.chat": "Chat",+ "interaction.voice": "Voice",+ "voice.join": "Join voice",+ "voice.settings": "Voice settings",+ "voice.listening": "Listen to voice",+ "voice.listeningVolume": "Master voice volume",+ "voice.personVolume": "Individual volume",+ "voice.listenPerson": "Listen to this person",+ "voice.listeningVolumeHint": "Adjust room voice volume for you, from 0% to 200%. Shared source audio is unchanged.",+ "voice.open": "Open room voice",+ "voice.openHint": "Room members can join freely. Microphones stay off until turned on.",+ "voice.close": "Close room voice",+ "voice.closeHint": "End voice for everyone. Sharing and chat continue.",+ "voice.closedHint": "The Host has not opened room voice.",+ "voice.deafen": "Pause listening",+ "voice.undeafen": "Resume listening",+ "voice.deafenHint": "Pause room voice playback for you. Your microphone and forwarding continue.",+ "voice.undeafenHint": "Resume room voice playback without changing your microphone.",+ "voice.leave": "Leave voice",+ "voice.microphoneOn": "Turn on microphone",+ "voice.microphoneOff": "Turn off microphone",+ "voice.captureCancel": "Cancel microphone request",+ "voice.play": "Play voice audio",+ "voice.muteForMe": "Mute for me",+ "voice.unmuteForMe": "Unmute for me",+ "voice.self": "you",+ "voice.participant": "Participant",+ "voice.outside": "Outside voice",+ "voice.offline": "Disconnected",+ "voice.microphoneInactive": "Microphone off",+ "voice.microphoneActive": "Microphone on",+ "voice.speaking": "Speaking",+ "voice.participants": "Participants",+ "host.sourceAudio.unavailable": "Source audio stopped. Picture sharing continues.",+ "voice.unavailable": "Some voice paths are unavailable. Chat and sharing remain available.",+ "voice.reconnecting": "Reconnecting room voice",+ "voice.error.microphoneDenied": "Microphone permission was not granted. Check your browser settings.",+ "voice.error.microphoneUnavailable": "The microphone is unavailable on this page. Use HTTPS or a localhost address.",+ "voice.error.microphoneMissing": "No available microphone was found.",+ "voice.error.microphoneFailed": "The microphone could not be started. Try again.",+ "voice.error.transport": "Voice could not connect. The room remains open.",+ "voice.error.rejected": "The voice action was not accepted. Rejoin voice and try again.",+ "voice.error.closed": "The Host has not opened room voice.","interaction.settings": "Chat settings","interaction.settingsHint": "On-screen chat settings apply only to your picture.",- "interaction.back": "Back to chat","interaction.overlay.scale": "Text size","interaction.overlay.opacity": "Opacity","interaction.export": "Export chat",- "interaction.exportHint": "Save messages received on this page as a text file.",- "interaction.exportLimit": "Exports up to the latest {count} messages kept on this page.",+ "interaction.exportLimit": "Save up to the latest {count} messages received on this page as text.","interaction.close": "Hide interaction window","interaction.focus": "Show interaction window","floating.detach": "Open in always-on-top window",@@ -303,6 +360,7 @@ export const en: Record<CopyKey, string> = {"interaction.send": "Send","interaction.reactions": "Reactions","interaction.express": "React",+ "interaction.moreReactions": "More reactions","interaction.toPerson": "To","interaction.withPerson": "Interact with {name}","interaction.participant": "a room participant",@@ -333,15 +391,7 @@ export const en: Record<CopyKey, string> = {"interaction.reaction.sleep": "Sleepy","interaction.reaction.tomato": "Toss tomato","interaction.reaction.poop": "Toss poop",- "host.microphone.mute": "Mute microphone",- "host.microphone.pending": "Opening microphone",- "host.microphone.browserOnly": "This capture method does not support a microphone yet. Choose Browser or Camera.",- "host.microphone.paused": "Audio and video sharing is paused. Resume to toggle the microphone.",- "host.microphone.busy": "Sharing settings are being updated. Please wait.",- "host.microphone.zeroVolume": "Microphone enabled at 0% volume. Select to mute.","host.shareControls": "Sharing controls",- "host.microphone.denied": "Microphone access was not allowed. Allow Piik to use it and try again.",- "host.microphone.unavailable": "The microphone is unavailable. Check its connection and microphone permissions.","host.sourcePicker.tab.camera": "Camera","host.sourcePicker.tab.browser": "Browser","host.sourcePicker.tab.window": "Apps / Windows",@@ -535,7 +585,8 @@ export const en: Record<CopyKey, string> = {"host.advanced.codec.vp8Hint": "Compatibility first","host.advanced.codec.h264Hint": "Hardware first",- "host.details": "Show connection details",+ "host.details": "Connection details",+ "host.details.show": "Show connection details","host.details.hide": "Hide connection details","host.topology": "Connection topology","host.topology.show": "Show connection topology",diff --git a/src/client/locales/zh.ts b/src/client/locales/zh.tsindex 576c7892..209ba2cc 100644--- a/src/client/locales/zh.ts+++ b/src/client/locales/zh.ts@@ -56,11 +56,13 @@ export const zh = {"remote.mode.room": "房间观众","remote.mode.password": "控制密码","remote.help.ask": "收到请求后,由你决定是否允许控制。",- "remote.help.room": "本房间观众可直接取得空闲控制权,操作这台电脑。",+ "remote.help.room": "无人控制时,房间观众可直接操作电脑。","remote.help.password": "观众输入控制密码后,可操作这台电脑。","remote.policyLifetime": "仅当前分享来源有效;换源或停播后关闭远控。","remote.password": "控制密码","remote.apply": "应用",+ "remote.enable": "开启远控",+ "remote.enableRoom": "允许观众控制","remote.connecting": "正在取得控制权","remote.reason.password": "控制密码不正确","remote.reason.retry": "请稍等片刻后重试",@@ -91,13 +93,22 @@ export const zh = {"remote.consent": "允许后,对方可以操作这台电脑的鼠标和键盘。","remote.waiting": "请求控制","remote.shortcut": "本机立即结束控制:",+ "remote.hostStopKey": "房主停止快捷键",+ "remote.hostStopKeyHelp": "在本机任何应用中按下即可停止控制,设置保存在当前站点。",+ "remote.releaseKey": "退出控制快捷键",+ "remote.releaseKeyHelp": "在当前页面或独立键盘窗口中退出控制,由当前浏览器保存。",+ "remote.shortcutFailed": "快捷键不可用,请更换后重试。","common.loading": "正在加载","playback.controls": "播放器控件","playback.showControls": "显示播控","playback.overlay": "弹幕","playback.more": "播放设置","playback.pictureFit": "画面显示",+ "playback.rotation": "横竖切换",+ "playback.rotationHint": "网页画面横竖切换,无需开启手机自动旋转。","playback.connection": "连接",+ "playback.relayVolunteer": "帮助更多观众转发",+ "playback.relayVolunteerHint": "仅本次观看生效,会使用更多上行带宽。","playback.fit.contain": "完整显示","playback.fit.cover": "等比铺满","playback.fit.fill": "拉伸铺满",@@ -143,10 +154,13 @@ export const zh = {"common.roomCode": "房间号","host.roomCodePending": "开始分享后生成房间号",+ "host.createRoom": "创建房间",+ "host.createRoomHint": "创建房间后即可聊天和语音,稍后再开始分享。","common.copy": "复制","common.copied": "已复制","common.copyFailed": "复制失败","common.cancel": "取消",+ "common.back": "返回","common.retry": "重试","common.refresh": "刷新页面","common.edit": "编辑",@@ -173,6 +187,11 @@ export const zh = {"client.launch.linkHint": "生成一个临时公网邀请链接","client.launch.room": "在这台设备上创建房间","client.connect.action": "连接 Piik App",+ "client.connect.discovering": "正在查找 Piik App…",+ "client.connect.permissionHint": "如果浏览器询问,请允许访问此设备或本地网络,以查找 App。",+ "client.connect.found": "已找到 Piik App,请打开 App 页面继续。",+ "client.connect.open": "打开 App 页面",+ "client.connect.approving": "正在等待 App 授权…","client.connect.standby": "App 已就绪","client.connect.guide": "如何连接站点","client.connect.standbyHint": "在 Piik 站点右上角点击 App,再选择「允许使用」。",@@ -195,6 +214,7 @@ export const zh = {"client.launch.lanAddress": "局域网邀请地址","client.launch.chooseAddress": "选择地址","client.launch.lanHint": "选择与朋友处于同一网络的地址。",+ "client.launch.localHTTPS": "局域网邀请使用本地 HTTPS;首次访问需确认本地证书。","client.launch.lanUnavailable": "没有可用的局域网地址,请连接网络后刷新页面","client.launch.localAccess": "站点口令(可选)","client.launch.accessSettings": "站点口令",@@ -258,8 +278,6 @@ export const zh = {"host.sourcePicker.camera": "分享摄像头:{title}","host.camera.denied": "未获得摄像头权限,请在浏览器中允许访问后重试。","host.camera.unavailable": "暂时无法使用摄像头,请检查连接,以及是否正被其他应用占用。",- "host.microphone.enable": "开启麦克风",- "host.microphone.label": "麦克风","host.microphone.settings": "麦克风设置","host.device.microphone": "麦克风","host.device.camera": "摄像头",@@ -270,19 +288,58 @@ export const zh = {"host.device.permission.microphone": "开启麦克风并允许访问后,可以在这里选择设备。","host.microphone.volume": "麦克风音量","host.microphone.voiceProcessing": "降噪与回声消除",- "host.microphone.voiceProcessingHint": "开启后,浏览器会降低麦克风杂音、消除回声并自动调节音量;关闭后停用这些处理。",- "host.microphone.voiceProcessingUsage": "说话时开启;音乐或虚拟声卡输入时关闭。",+ "host.microphone.voiceProcessingHint": "开启后由浏览器降低杂音、消除回声并自动调节音量;输入设备已有语音处理时可关闭。","interaction.open": "互动","interaction.title": "互动","interaction.chat": "聊天",+ "interaction.voice": "语音",+ "voice.join": "加入语音",+ "voice.settings": "语音设置",+ "voice.listening": "收听语音",+ "voice.listeningVolume": "总收听音量",+ "voice.personVolume": "个人音量",+ "voice.listenPerson": "收听此人",+ "voice.listeningVolumeHint": "调整你听到的房间语音,范围 0%–200%,不影响分享来源的声音。",+ "voice.open": "开启房间语音",+ "voice.openHint": "房间成员可自行加入,麦克风仍需手动开启。",+ "voice.close": "关闭房间语音",+ "voice.closeHint": "结束所有人的语音,画面分享和聊天不受影响。",+ "voice.closedHint": "房主尚未开启房间语音。",+ "voice.deafen": "暂停收听",+ "voice.undeafen": "恢复收听",+ "voice.deafenHint": "仅暂停你这里的语音播放,麦克风与转发继续。",+ "voice.undeafenHint": "恢复房间语音收听,不改变麦克风状态。",+ "voice.leave": "退出语音",+ "voice.microphoneOn": "打开麦克风",+ "voice.microphoneOff": "关闭麦克风",+ "voice.captureCancel": "取消打开麦克风",+ "voice.play": "播放语音",+ "voice.muteForMe": "本地静音",+ "voice.unmuteForMe": "恢复声音",+ "voice.self": "你",+ "voice.participant": "参与者",+ "voice.outside": "尚未加入语音",+ "voice.offline": "已断开连接",+ "voice.microphoneInactive": "麦克风已关闭",+ "voice.microphoneActive": "麦克风已开启",+ "voice.speaking": "正在说话",+ "voice.participants": "参与者",+ "host.sourceAudio.unavailable": "来源声音已停止,画面分享继续。",+ "voice.unavailable": "部分语音线路暂不可用,聊天和画面分享仍可使用。",+ "voice.reconnecting": "正在重新连接房间语音",+ "voice.error.microphoneDenied": "未获得麦克风权限,请检查浏览器设置。",+ "voice.error.microphoneUnavailable": "此页面无法使用麦克风,请通过 HTTPS 或本机地址访问。",+ "voice.error.microphoneMissing": "没有找到可用的麦克风。",+ "voice.error.microphoneFailed": "未能打开麦克风,请重试。",+ "voice.error.transport": "语音未能连接,房间仍可继续使用。",+ "voice.error.rejected": "语音操作未获接受,请重新加入语音后重试。",+ "voice.error.closed": "房主尚未开启房间语音。","interaction.settings": "聊天设置","interaction.settingsHint": "弹幕设置仅影响自己的画面。",- "interaction.back": "返回聊天","interaction.overlay.scale": "弹幕字号","interaction.overlay.opacity": "不透明度","interaction.export": "导出聊天记录",- "interaction.exportHint": "将本页收到的聊天记录保存为文本文件。",- "interaction.exportLimit": "导出本页保留的最近 {count} 条消息。",+ "interaction.exportLimit": "将本页保留的最近 {count} 条消息保存为文本文件。","interaction.close": "收起互动窗口","interaction.focus": "显示互动窗口","floating.detach": "在置顶窗口中打开",@@ -303,6 +360,7 @@ export const zh = {"interaction.send": "发送","interaction.reactions": "表情与小道具","interaction.express": "发表情",+ "interaction.moreReactions": "更多表情","interaction.toPerson": "送给","interaction.withPerson": "与 {name} 互动","interaction.participant": "房间成员",@@ -333,15 +391,7 @@ export const zh = {"interaction.reaction.sleep": "困了","interaction.reaction.tomato": "丢番茄","interaction.reaction.poop": "丢便便",- "host.microphone.mute": "关闭麦克风",- "host.microphone.pending": "正在开启麦克风",- "host.microphone.browserOnly": "此采集方式暂不支持麦克风,可改用浏览器或摄像头。",- "host.microphone.paused": "音视频分享已暂停,恢复后可开关麦克风。",- "host.microphone.busy": "正在调整分享设置,请稍候。",- "host.microphone.zeroVolume": "麦克风已开启,音量为 0%;点击可静音。","host.shareControls": "分享控制",- "host.microphone.denied": "未获得麦克风权限,请允许 Piik 使用麦克风后重试。",- "host.microphone.unavailable": "暂时无法使用麦克风,请检查设备连接和麦克风权限。","host.sourcePicker.tab.camera": "摄像头","host.sourcePicker.tab.browser": "浏览器","host.sourcePicker.tab.window": "程序 / 窗口",@@ -535,7 +585,8 @@ export const zh = {"host.advanced.codec.vp8Hint": "兼容优先","host.advanced.codec.h264Hint": "硬件优先",- "host.details": "显示连接详情",+ "host.details": "连接详情",+ "host.details.show": "显示连接详情","host.details.hide": "隐藏连接详情","host.topology": "连接拓扑","host.topology.show": "显示连接拓扑",diff --git a/src/client/media/host-audio.ts b/src/client/media/host-audio.tsindex 77075484..6eef82f6 100644--- a/src/client/media/host-audio.ts+++ b/src/client/media/host-audio.ts@@ -1,162 +1,31 @@import type { BrowserCaptureSource } from "./quality";-import { audioInputConstraints } from "./audio-capture";-// The Host session owns capture and lifetime. This helper owns only the raw-// audio inputs and mixer; transports borrow its single output track.+// The Host owns the video lifecycle. This helper owns source-audio retirement+// and reports input availability independently of playback or room voice.export class HostAudio {- private source: MediaStream;- private microphone: MediaStreamTrack | null = null;- private context: AudioContext | null = null;- private destination: MediaStreamAudioDestinationNode | null = null;- private inputs: MediaStreamAudioSourceNode[] = [];- private microphoneGain: GainNode | null = null;- private microphoneVolume = 1;- private microphoneDevice = "";- private voiceProcessing = true;- private closed = false;-- constructor(source: MediaStream, private changed: (enabled: boolean) => void,- private kind: BrowserCaptureSource = "browser", private availabilityChanged: (available: boolean) => void = () => {}) {- this.source = source;+ constructor(private source: MediaStream, private kind: BrowserCaptureSource = "browser",+ private availabilityChanged: (available: boolean) => void = () => {}) {this.watchSource();}-- /** Capture facts come from the input, never the mixer destination track. */get sourceStream(): MediaStream { return this.source; }get sourceKind(): BrowserCaptureSource { return this.kind; }- get audioAvailable(): boolean {- return this.source.getAudioTracks().some(track => track.readyState === "live") ||- Boolean(this.microphone?.enabled && this.microphone.readyState === "live");- }+ get audioAvailable(): boolean { return this.source.getAudioTracks().some(track => track.readyState === "live"); }private reportAvailability = () => this.availabilityChanged(this.audioAvailable);- private watchSource() {+ private watchSource(): void {this.source.getAudioTracks().forEach(track => track.addEventListener("ended", this.reportAvailability));}- private unwatchSource() {+ private unwatchSource(): void {this.source.getAudioTracks().forEach(track => track.removeEventListener("ended", this.reportAvailability));}-attach(source: MediaStream, kind = this.kind): MediaStream {const previous = this.source;- this.unwatchSource();- this.source = source;- this.watchSource();- this.kind = kind;- const output = this.compose();+ this.unwatchSource(); this.source = source; this.kind = kind; this.watchSource();this.reportAvailability();- if (previous !== source) previous.getAudioTracks().forEach((track) => track.stop());- return output;- }-- setMicrophoneVolume(volume: number) {- if (this.closed || !Number.isFinite(volume)) return;- this.microphoneVolume = Math.max(0, Math.min(2, volume));- if (this.microphoneGain && this.context) {- this.microphoneGain.gain.setTargetAtTime(this.microphoneVolume, this.context.currentTime, 0.01);- }+ if (previous !== source) previous.getAudioTracks().forEach(track => track.stop());+ return source;}-- toggleMicrophone(deviceId = this.microphoneDevice): Promise<MediaStream | null> {- return this.setMicrophone(!this.microphone?.enabled, deviceId);- }-- async setMicrophone(enabled: boolean, deviceId: string, voiceProcessing = this.voiceProcessing): Promise<MediaStream | null> {- if (this.closed) return null;- const sameInput = deviceId === this.microphoneDevice && voiceProcessing === this.voiceProcessing;- if (!enabled || (this.microphone && sameInput)) {- if (this.microphone && !sameInput) {- this.microphone.stop();- this.microphone = null;- this.compose();- }- this.microphoneDevice = deviceId;- this.voiceProcessing = voiceProcessing;- if (this.microphone) this.microphone.enabled = enabled;- this.changed(enabled);- this.reportAvailability();- return null;- }- const hadContext = !!this.context;- if (!this.context) {- this.context = new AudioContext();- this.destination = this.context.createMediaStreamDestination();- this.microphoneGain = this.context.createGain();- this.microphoneGain.gain.value = this.microphoneVolume;- this.microphoneGain.connect(this.destination);- }- const resumed = this.context.resume().then(() => true, () => false);- let stream: MediaStream | null = null;- try {- stream = await navigator.mediaDevices.getUserMedia({ audio: {- ...audioInputConstraints(voiceProcessing),- ...(deviceId ? { deviceId: { exact: deviceId } } : {}),- } });- if (this.closed) return null;- if (!await resumed) throw new Error("Audio context unavailable");- if (this.closed) return null;- const microphone = stream.getAudioTracks()[0];- if (!microphone || microphone.readyState === "ended") throw new Error("No live microphone");- const previous = this.microphone;- this.microphone = microphone;- this.microphoneDevice = deviceId;- this.voiceProcessing = voiceProcessing;- microphone.onended = () => {- if (this.closed || this.microphone !== microphone) return;- this.microphone = null;- this.compose();- this.changed(false);- this.reportAvailability();- };- const output = this.compose();- previous?.stop();- stream = null;- this.changed(true);- this.reportAvailability();- // Existing senders already borrow this destination. A device change is- // local input work, not another media/route replacement.- return hadContext ? null : output;- } catch (error) {- if (!hadContext && !this.microphone) this.closeMixer();- throw error;- } finally {- stream?.getTracks().forEach((track) => track.stop());- }- }-- private compose(): MediaStream {- if (!this.context || !this.destination) return this.source;- this.inputs.forEach((input) => input.disconnect());- this.inputs = [...this.source.getAudioTracks(), this.microphone]- .filter((track): track is MediaStreamTrack => !!track && track.readyState === "live")- .map((track) => {- const input = this.context!.createMediaStreamSource(new MediaStream([track]));- // Only the microphone follows the input-volume control. Source audio- // and the Viewer's playback volume have separate owners.- input.connect(track === this.microphone ? this.microphoneGain! : this.destination!);- return input;- });- const audio = this.destination.stream.getAudioTracks()[0]!;- audio.contentHint = "music";- return new MediaStream([...this.source.getVideoTracks(), audio]);- }-- private closeMixer() {- this.inputs.forEach((input) => input.disconnect());- this.inputs = [];- this.microphoneGain?.disconnect();- this.microphoneGain = null;- this.destination?.stream.getTracks().forEach((track) => track.stop());- void this.context?.close().catch(() => {});- this.context = null;- this.destination = null;- }-- dispose() {- this.closed = true;+ dispose(): void {this.unwatchSource();- this.microphone?.stop();- this.microphone = null;- this.source.getAudioTracks().forEach((track) => track.stop());- this.closeMixer();+ this.source.getAudioTracks().forEach(track => track.stop());}}diff --git a/src/client/media/microphone-input.ts b/src/client/media/microphone-input.tsnew file mode 100644index 00000000..07fb7a14--- /dev/null+++ b/src/client/media/microphone-input.ts@@ -0,0 +1,37 @@+// A single microphone capture owns its device, gain and output. Transports+// borrow the output track; replacing a device never changes room authority.+export class MicrophoneInput {+ readonly stream: MediaStream;+ private readonly gain: GainNode;+ private readonly analyser: AnalyserNode;+ private readonly samples = new Float32Array(256);+ private closed = false;++ constructor(private readonly captured: MediaStream, private readonly context: AudioContext,+ volume: number, ended: () => void) {+ this.gain = this.context.createGain();+ this.gain.gain.value = volume;+ this.analyser = this.context.createAnalyser();+ this.analyser.fftSize = this.samples.length;+ const source = this.context.createMediaStreamSource(captured);+ const destination = this.context.createMediaStreamDestination();+ source.connect(this.gain); this.gain.connect(destination); this.gain.connect(this.analyser);+ this.stream = destination.stream;+ this.stream.getAudioTracks()[0]!.contentHint = "speech";+ captured.getAudioTracks()[0]!.onended = ended;+ }++ volume(value: number): void { this.gain.gain.setTargetAtTime(value, this.context.currentTime, .01); }+ level(): number {+ if (this.closed) return 0;+ this.analyser.getFloatTimeDomainData(this.samples);+ return Math.sqrt(this.samples.reduce((sum, value) => sum + value * value, 0) / this.samples.length);+ }+ close(): void {+ if (this.closed) return;+ this.closed = true;+ this.captured.getTracks().forEach(track => { track.onended = null; track.stop(); });+ this.stream.getTracks().forEach(track => track.stop());+ void this.context.close().catch(() => {});+ }+}diff --git a/src/client/media/video-geometry.ts b/src/client/media/video-geometry.tsindex 73b19c52..6fb4bf21 100644--- a/src/client/media/video-geometry.ts+++ b/src/client/media/video-geometry.ts@@ -1,9 +1,69 @@export type VideoFit = "contain" | "cover" | "fill";+export type VideoRotation = 0 | 90 | 180 | 270;+export type PicturePoint = { x: number; y: number };++export function videoBoxSize(video: HTMLVideoElement): { width: number; height: number } {+ const style = getComputedStyle(video);+ // clientWidth/clientHeight round fractional grid cells, which shifts input+ // and distorts fit after a quarter-turn.+ return { width: parseFloat(style.width), height: parseFloat(style.height) };+}++export function videoRotation(video: HTMLVideoElement): VideoRotation {+ return Number(video.dataset.pictureRotation ?? 0) as VideoRotation;+}++// Rotation is clockwise in screen coordinates. Points and motion share the+// same axes, but motion has no translation around the picture's center.+export function rotatePicturePoint(point: PicturePoint, rotation: VideoRotation, inverse = false): PicturePoint {+ const delta = rotatePictureDelta({ x: point.x - .5, y: point.y - .5 }, rotation, inverse);+ return { x: delta.x + .5, y: delta.y + .5 };+}++export function rotatePictureDelta(point: PicturePoint, rotation: VideoRotation, inverse = false): PicturePoint {+ const turn = inverse ? (360 - rotation) % 360 : rotation;+ if (turn === 90) return { x: -point.y, y: point.x };+ if (turn === 180) return { x: -point.x, y: -point.y };+ if (turn === 270) return { x: point.y, y: -point.x };+ return point;+}// Playback, remote input and magnification share the rendered picture dimensions.-export function videoPictureSize(video: HTMLVideoElement, width: number, height: number): { width: number; height: number } {+export function videoPictureSize(video: HTMLVideoElement, width: number, height: number, rotation = videoRotation(video)): { width: number; height: number } {if (video.style.objectFit === "fill") return { width, height };+ const sourceWidth = video.videoWidth || 16, sourceHeight = video.videoHeight || 9;+ const sideways = rotation === 90 || rotation === 270;+ const pictureWidth = sideways ? sourceHeight : sourceWidth, pictureHeight = sideways ? sourceWidth : sourceHeight;const fit = video.style.objectFit === "cover" ? Math.max : Math.min;- const scale = fit(width / video.videoWidth, height / video.videoHeight);- return { width: video.videoWidth * scale, height: video.videoHeight * scale };+ const scale = fit(width / pictureWidth, height / pictureHeight);+ return { width: pictureWidth * scale, height: pictureHeight * scale };+}++// Keep the existing video cell and parent (fullscreen and overlays own them).+// Its fitted picture rotates into that cell; zoom composes this same transform.+export function applyVideoRotation(video: HTMLVideoElement, rotation: VideoRotation): void {+ video.dataset.pictureRotation = String(rotation);+ const { width, height } = videoBoxSize(video);+ if (!width || !height) return;+ const original = videoPictureSize(video, width, height, 0);+ const picture = videoPictureSize(video, width, height, rotation);+ const sideways = rotation === 90 || rotation === 270;+ const scaleX = (sideways ? picture.height : picture.width) / original.width;+ const scaleY = (sideways ? picture.width : picture.height) / original.height;+ video.style.setProperty("--picture-transform", `rotate(${rotation}deg) scale(${scaleX}, ${scaleY})`);+}++export function pictureRect(video: HTMLVideoElement): { left: number; top: number; width: number; height: number } | null {+ if (!video.videoWidth || !video.videoHeight) return null;+ const rect = video.getBoundingClientRect();+ const { width, height } = videoPictureSize(video, rect.width, rect.height);+ if (!width || !height) return null;+ return { left: rect.left + (rect.width - width) / 2, top: rect.top + (rect.height - height) / 2, width, height };+}++export function picturePoint(video: HTMLVideoElement, clientX: number, clientY: number): PicturePoint | null {+ const rect = pictureRect(video);+ if (!rect) return null;+ const x = (clientX - rect.left) / rect.width, y = (clientY - rect.top) / rect.height;+ return x >= 0 && x <= 1 && y >= 0 && y <= 1 ? rotatePicturePoint({ x, y }, videoRotation(video), true) : null;}diff --git a/src/client/media/viewer-audio.ts b/src/client/media/viewer-audio.tsindex 5e906a38..d740c940 100644--- a/src/client/media/viewer-audio.ts+++ b/src/client/media/viewer-audio.ts@@ -15,8 +15,11 @@ export class ViewerAudio {private disposed = false;constructor(- private readonly video: HTMLVideoElement,+ private readonly video: HTMLMediaElement,private readonly onChange: (snapshot: ViewerAudioSnapshot) => void,+ // Room voice lends one context to all its local playback sinks.+ private readonly createContext?: () => AudioContext,+ private readonly maxLevel = 2,) {this.level = video.volume;this.muted = video.muted;@@ -48,12 +51,12 @@ export class ViewerAudio {setLevel(level: number): void {if (this.disposed || !Number.isFinite(level)) return;- this.level = Math.max(0, Math.min(this.boostAvailable ? 2 : 1, level));+ this.level = Math.max(0, Math.min(this.boostAvailable ? this.maxLevel : 1, level));// iPhone video.volume is system-owned. Explicit adjustment uses the same// gain node below and above 100%; untouched playback stays native.if (this.level !== 1 && this.boostAvailable && !this.context) {try {- this.context = new AudioContext();+ this.context = this.createContext ? this.createContext() : new AudioContext();this.gain = this.context.createGain();this.gain.gain.value = 0;this.gain.connect(this.context.destination);@@ -167,7 +170,7 @@ export class ViewerAudio {this.context = null;if (context) {context.removeEventListener("statechange", this.sync);- void context.close().catch(() => undefined);+ if (!this.createContext) void context.close().catch(() => undefined);}}}diff --git a/src/client/native/client.ts b/src/client/native/client.tsindex b7ac074d..8e34fe57 100644--- a/src/client/native/client.ts+++ b/src/client/native/client.ts@@ -18,6 +18,7 @@ import {captureOptionsResponseSchema,edgeOfferResponseSchema,nativeAckResponseSchema,+ remoteStopShortcutResponseSchema,nativeEventSchema,nativeDiscoveryIdentitySchema,nativeConnectSchema,@@ -45,6 +46,7 @@ import {type NativeCaptureTarget,type NativeIceCandidate,type NativeVideoCodec,+ type RemoteStopShortcut,} from "./wire";const REQUEST_TIMEOUT_MS = 8_000;@@ -338,6 +340,7 @@ export class NativeClient {{...shareInput,...(excludeAudio ? { excludeAudio } : {}),+ // Keep a stable output for source-audio toggles during sharing....(this.health.nativeMedia.microphone ? { microphoneMixing: true } : {}),...(this.health.nativeMedia.remoteInput ? { remoteInput: true } : {}),...(this.health.nativeMedia.captureBorderControl ? { showCaptureBorder } : {}),@@ -709,6 +712,12 @@ export class NativeClient {await this.request("set-remote-control-policy", { shareId, mode, ...(password !== undefined ? { password } : {}) }, nativeAckResponseSchema, null);}+ async remoteStopShortcut(shareId: string, key?: number): Promise<RemoteStopShortcut> {+ if (!this.health.nativeMedia.remoteStopShortcut) throw new Error("Piik App shortcut settings are unavailable");+ return this.request(key === undefined ? "get-remote-stop-shortcut" : "set-remote-stop-shortcut",+ { shareId, ...(key === undefined ? {} : { key }) }, remoteStopShortcutResponseSchema);+ }+async setRemoteInputPeers(shareId: string, peers: { peerId: string; endpointId: string; secret: string }[]): Promise<void> {await this.request("set-remote-input-peers", { shareId, peers }, nativeAckResponseSchema);}diff --git a/src/client/native/native-punch.ts b/src/client/native/native-punch.tsindex 1db76668..4ce832dd 100644--- a/src/client/native/native-punch.ts+++ b/src/client/native/native-punch.ts@@ -1,10 +1,12 @@import type { IceConfig, PunchPrediction, PunchSignal, SignalPayload } from "../../shared/protocol";import { debugEvent } from "../lib/debug";import { natPredictionSurveyUrls } from "../webrtc/nat-prediction";+import { nativeRelayCapacity, type NativeHealth } from "./wire";const PREPARATION_TIMEOUT_MS = 3_500;export interface NativePunchControl {+ readonly health?: Pick<NativeHealth, "nativeMedia">;preparePunch(shareId: string, connectionId: string, ice: IceConfig, secret: string,edgeCapacity?: number, sourceConnectionId?: string): Promise<PunchPrediction | null>;runPunch(shareId: string, connectionId: string, remote: PunchPrediction): Promise<boolean>;@@ -117,7 +119,8 @@ export class NativePunchReceiver {if (this.closed) return;this.control = control;const prediction = control- ? await control.preparePunch(this.shareId, this.connectionId, this.ice, secret, this.capacity).catch(() => null)+ ? await control.preparePunch(this.shareId, this.connectionId, this.ice, secret,+ nativeRelayCapacity(this.capacity, control.health)).catch(() => null): null;if (this.closed) return;this.ready = prediction !== null;diff --git a/src/client/native/native-viewer-peer.ts b/src/client/native/native-viewer-peer.tsindex 8f752e43..5a3cc996 100644--- a/src/client/native/native-viewer-peer.ts+++ b/src/client/native/native-viewer-peer.ts@@ -27,7 +27,7 @@ import {} from "../webrtc/nat-prediction";import { NativeClient } from "./client";import { NativeMediaBridge } from "./media-bridge";-import type { NativeClientEvent, NativeVideoCodec } from "./wire";+import { nativeRelayCapacity, type NativeClientEvent, type NativeVideoCodec } from "./wire";import { NativePunchReceiver, punchIceConfig } from "./native-punch";@@ -146,7 +146,7 @@ export class NativeCapableViewerPeer implements ViewerMediaPeer {this.options,client,this.nativeSessionId,- this.edgeCapacity,+ nativeRelayCapacity(this.edgeCapacity, client.health),this.onNativeUnavailable,): this.newBrowserPeer();diff --git a/src/client/native/wire.ts b/src/client/native/wire.tsindex cdc65317..38286775 100644--- a/src/client/native/wire.ts+++ b/src/client/native/wire.ts@@ -1,5 +1,5 @@import { z } from "zod";-import { remoteControlModeSchema, remoteInputPlatformSchema } from "../remote-control/protocol";+import { remoteControlModeSchema, remoteInputPlatformSchema, remoteShortcutKeySchema } from "../remote-control/protocol";import { sfuMediaSchema, positiveUint32Schema, qualityResolutionSchema, punchPredictionSchema,nullableSafeEvidenceNumber, nullableSafeEvidenceInteger } from "../../shared/protocol";@@ -42,7 +42,9 @@ export const nativeHealthSchema = nativeDiscoveryIdentitySchema.extend({maxVideoFramerate: z.number().positive().max(Number.MAX_SAFE_INTEGER).optional(),maxVideoBitrate: positiveUint32Schema.optional(),receiverReuse: z.boolean().default(false),+ maxRelayChildren: z.number().int().min(1).max(20).optional(),remoteInput: z.boolean().optional(),+ remoteStopShortcut: z.boolean().optional(),video: z.boolean().default(false),processAudio: z.boolean().default(false),systemAudio: z.boolean().default(false),@@ -57,6 +59,12 @@ export const nativeHealthSchema = nativeDiscoveryIdentitySchema.extend({});export type NativeHealth = z.infer<typeof nativeHealthSchema>;+// Native receiver lifetime uses the selected backend's physical capability;+// room authority independently limits admitted children until the user opts in.+export function nativeRelayCapacity(capacity: number, health?: Pick<NativeHealth, "nativeMedia">): number {+ return Math.min(capacity, health?.nativeMedia.maxRelayChildren ?? 3);+}+export const nativeConnectSchema = nativeDiscoveryIdentitySchema.extend({protocol: z.literal(NATIVE_CLIENT_PROTOCOL),connectURL: z.string().url().max(256),@@ -127,6 +135,10 @@ const responseBase = {id: opaqueIdentifierSchema,};+export const remoteStopShortcutSchema = z.object({ key: remoteShortcutKeySchema, available: z.boolean() });+export type RemoteStopShortcut = z.infer<typeof remoteStopShortcutSchema>;+export const remoteStopShortcutResponseSchema = remoteStopShortcutSchema.extend({ ...responseBase, type: z.literal("remote-stop-shortcut") }).strict();+export const punchPreparedResponseSchema = z.object({...responseBase, type: z.literal("punch-prepared"), prediction: punchPredictionSchema.nullable(),}).strict();diff --git a/src/client/pages/AppLauncherPage.tsx b/src/client/pages/AppLauncherPage.tsxindex d2413730..ab6245fa 100644--- a/src/client/pages/AppLauncherPage.tsx+++ b/src/client/pages/AppLauncherPage.tsx@@ -309,7 +309,7 @@ export function AppLauncherPage() {<span className={vis ? "visually-hidden" : undefined}>{t("client.connect.openOnStart")}</span></label>}<div className="lr-client-approval-actions">- <Btn icon="x" title={approvalCurrent ? "client.connect.close" : "common.cancel"} cap={approvalCurrent ? "client.connect.close" : "common.cancel"}+ <Btn icon="x" title={approvalCurrent ? "client.connect.close" : "common.cancel"} cap={approvalCurrent ? "client.connect.close" : "common.cancel"} hint="hint-close"onClick={() => window.close()} />{!approvalCurrent && <Btn icon="check" title="client.connect.approve" cap="client.connect.approve" tone="primary"hint="hint-client-site" busy={siteBusy} disabled={!validSite || siteBusy} onClick={() => void changeSite(requestedSite, "site", openOnApproval)} />}diff --git a/src/client/pages/ControlsPreview.tsx b/src/client/pages/ControlsPreview.tsxindex c68d832f..cd6db942 100644--- a/src/client/pages/ControlsPreview.tsx+++ b/src/client/pages/ControlsPreview.tsx@@ -1,15 +1,14 @@import { useEffect, useRef, useState } from "react";-import type { VideoFit } from "../media/video-geometry";-import { Btn, Chip, NameTag, Pill, SwitchItem } from "../components/living/primitives";+import type { VideoFit, VideoRotation } from "../media/video-geometry";+import { BackButton, Btn, Chip, NameTag, Pill, SwitchItem } from "../components/living/primitives";import { RoomChip, RoomCodePlaceholder, RoomAdmissionBadge } from "../components/living/RoomChip";import { CaptureSourcePicker, type NativeSourceList } from "../components/living/CaptureSourcePicker";import { LedStrip } from "../components/living/Header";import { StageOverlay, StageTv } from "../components/living/Stage";-import { HostMicrophone, HostMicrophoneSettings } from "../components/living/HostMicrophone";import { LiveAudioExclusion } from "../components/living/AudioExclusionSelect";import type { NativeCaptureTarget } from "../native/wire";import { RoomInteractions } from "../components/living/RoomInteractions";-import { RoomChatOverlay, RoomChatOverlaySettings, RoomChatToggle } from "../components/living/RoomChatOverlay";+import { RoomChatOverlay, RoomChatToggle } from "../components/living/RoomChatOverlay";import { RoomInteractionSession } from "../lib/room-interactions";import { createOpaqueId } from "../lib/opaque-id";import type { InteractionPayload } from "../../shared/protocol";@@ -34,6 +33,7 @@ import { Glyph } from "../ui/icons";import { useCopy } from "../ui/copy";import { PeoplePreview } from "./PeoplePreview";import { RemoteControlsPreview } from "./RemoteControlsPreview";+import { useRoomVoicePreview } from "./RoomVoicePreview";import "./controls-preview.css";const POSTER = `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360"><rect width="640" height="360" fill="#e8eee6"/><rect x="100" y="60" width="440" height="240" rx="20" fill="#fffdf6"/><path d="M100 100h440" stroke="#c9d7cf" stroke-width="2"/><circle cx="128" cy="81" r="6" fill="#ed9e65"/><circle cx="320" cy="190" r="46" fill="#65b099"/><path d="m310 191 9 9 16-22" fill="none" stroke="#fffdf6" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/></svg>')}`;@@ -48,7 +48,6 @@ const previewCameras: typeof loadCameraPreviews = async (_signal, publish) => pu{ id: "built-in", label: "Built-in camera", preview: `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 320"><rect width="180" height="320" fill="#dce9e5"/><rect x="106" y="26" width="58" height="102" rx="7" fill="#fbfcf3"/><path d="M135 26v102M106 76h58" stroke="#b2cbc2" stroke-width="4"/><path d="M36 255q0-100 54-100t54 100" fill="#449986"/><circle cx="90" cy="124" r="29" fill="#449986"/><path d="M81 122v4m18-4v4" stroke="#203c3a" stroke-width="5" stroke-linecap="round"/><path d="M0 259h180v61H0" fill="#d8b898"/><rect x="142" y="241" width="21" height="23" rx="5" fill="#fff7e9"/></svg>')}` },{ id: "usb", label: "USB Camera", preview: `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 180"><rect width="320" height="180" fill="#e2c5a8"/><path d="M0 25h320M0 157h320" stroke="#cda987" stroke-width="2"/><rect x="53" y="27" width="163" height="124" rx="5" fill="#fffaf0" transform="rotate(-8 135 89)"/><path d="m97 112 30-35 23 25 18-12 18 19" fill="none" stroke="#689b8a" stroke-width="5" stroke-linejoin="round"/><circle cx="166" cy="57" r="11" fill="#ebbd63"/><path d="m245 64 8 77" stroke="#477b73" stroke-width="7" stroke-linecap="round"/><circle cx="266" cy="35" r="19" fill="#f9f5df"/><circle cx="266" cy="35" r="12" fill="#8c6651"/></svg>')}` },]);-const previewMicrophones = async () => [{ id: "headset", label: "USB Headset" }, { id: "desk", label: "Desk Microphone" }];const previewApplications = async () => SOURCES.sources;export function ControlsPreview() {@@ -57,10 +56,6 @@ export function ControlsPreview() {const displayPreview = new URLSearchParams(window.location.search).get("source") === "display";const [sound, setSound] = useState(true);const [excludedAudio, setExcludedAudio] = useState<NativeCaptureTarget | undefined>(SOURCES.sources[2]);- const [microphone, setMicrophone] = useState(false);- const [microphoneVolume, setMicrophoneVolume] = useState(1);- const [voiceProcessing, setVoiceProcessing] = useState(true);- const [microphoneDevice, setMicrophoneDevice] = useState("");const [sharingSettings, setSharingSettings] = useState(false);const [remoteMode, setRemoteMode] = useState<RemoteControlMode>("off");const [quality, setQuality] = useState<QualityProfile>(QUALITY_PROFILES["1080p30"]);@@ -89,6 +84,7 @@ export function ControlsPreview() {const [dial, setDial] = useState("60");const [theater, setTheater] = useState(false);const [pictureFit, setPictureFit] = useState<VideoFit>("contain");+ const [pictureRotation, setPictureRotation] = useState<VideoRotation>(0);const [viewerRoute, setViewerRoute] = useState<"auto" | "p2p" | "sfu">("auto");const video = useRef<HTMLVideoElement>(null);const notify = () => setFeedback(en ? "Got it. This is a preview." : "收到,只在预览里演示。" );@@ -98,11 +94,12 @@ export function ControlsPreview() {<header><span className="cp-number">01</span><h2>{en ? "Buttons, with a little give" : "按钮,按下去有回应。"}</h2></header><p>{en ? "Hover, press, or use Tab and Enter. The disabled one keeps its explanation." : "悬停、按下,或用 Tab 和回车试试。禁用时也能查看原因。"}</p><div className="cp-tools">+ <BackButton onClick={notify} /><Btn icon="cast" tone="primary" title="host.start" cap="host.start" hint="hint-share-start" onClick={notify} /><Btn icon="stop" tone="danger" title="host.stop" cap="host.stop" hint="hint-share-stop" onClick={notify} /><Btn icon={paused ? "play" : "pause"} title={paused ? "host.resume" : "host.pause"} cap={paused ? "host.resume" : "host.pause"}hint={paused ? "hint-resume" : "hint-pause"} draw="preview-pause" pressed={paused} onClick={() => setPaused(!paused)} />- <Btn icon="gauge" tone="on" title="host.details" cap="host.details" hint="hint-details" pressed onClick={notify} />+ <Btn icon="gauge" tone="on" title="host.details.hide" cap="host.details" hint="hint-collapse" pressed onClick={notify} /><Btn icon="refresh" title="viewer.reconnect" cap="viewer.reconnect" hint="hint-reconnect" disabled /><Btn icon="cast" title="host.starting" cap="host.starting" busy disabled hint="hint-share-start" /></div>@@ -110,7 +107,7 @@ export function ControlsPreview() {<Btn icon="switchSource" title="host.switchSource" hint="hint-switch-source" onClick={notify} /><Btn icon="link" title="host.invite.copy" hint="hint-copy-invite" onClick={notify} /><Btn icon="linkOff" title="host.invite.revoke" hint="hint-revoke-invite" onClick={notify} />- <Btn icon="network" title="host.topology" hint="hint-topology" onClick={notify} />+ <Btn icon="network" title="host.topology.show" hint="hint-topology" onClick={notify} /><Btn icon="sliders" title="host.advanced" hint="hint-advanced" onClick={notify} /></div><p>{en ? "The same button family has regular, compact and dense sizes. Quiet actions keep a usable target without a visible frame."@@ -129,8 +126,6 @@ export function ControlsPreview() {<section id="sharing-preview" className="cp-card cp-sharing-preview"><header><h2>{t("host.advanced")}</h2></header><HostShareControls actions={<>- <HostMicrophone enabled={microphone} paused={paused} volume={microphoneVolume}- onToggle={() => setMicrophone(value => !value)} /><Btn icon="switchSource" title="host.switchSource" cap="host.switchSource" hint="hint-switch-source" onClick={notify} /></>}settings={<Btn icon="sliders" cap="host.settings.button" title={sharingSettings ? "host.advanced.hide" : "host.advanced"}@@ -170,9 +165,7 @@ export function ControlsPreview() {<SwitchItem checked={sound} onChange={setSound} label={t("host.sourcePicker.systemAudio")}hint={sound ? "hint-stop-audio" : "hint-share-audio"} /><LiveAudioExclusion load={previewApplications} value={excludedAudio} onChange={setExcludedAudio} disabled={!sound || paused} />- </div><HostMicrophoneSettings deviceId={microphoneDevice} onDevice={setMicrophoneDevice} loadDevices={previewMicrophones}- native enabled={microphone} disabled={paused} volume={microphoneVolume} onVolume={setMicrophoneVolume}- voiceProcessing={voiceProcessing} onVoiceProcessing={setVoiceProcessing} />+ </div><AudioBitrateControl value={quality.maxAudioBitrate ?? QUALITY_PROFILES["1080p30"].maxAudioBitrate} max={MAX_SCREEN_AUDIO_BITRATE}disabled={false} onChange={maxAudioBitrate => setQuality(current => ({ ...current, maxAudioBitrate }))} /></>}@@ -246,7 +239,9 @@ export function ControlsPreview() {<SwitchItem checked={invalid} onChange={setInvalid} label={en ? "Show error" : "看看错误态"} /></div>{invalid ? <p id="preview-input-error" className="cp-input-error" role="alert">{en ? "That password did not match. Try again." : "密码没对上,再试一次。"}</p> : null}- <div className="cp-tools"><RoomCodePlaceholder /><RoomChip roomId={roomCode} onReplace={() => setRoomCode(code => code === "6020" ? "2048" : "6020")} /></div>+ <div className="cp-tools"><RoomCodePlaceholder /><RoomCodePlaceholder onCreate={notify} />+ <RoomCodePlaceholder onCreate={notify} disabled busy />+ <RoomChip roomId={roomCode} onReplace={() => setRoomCode(code => code === "6020" ? "2048" : "6020")} /></div><RoomCodeInput value={dial} onChange={setDial} /></section><section id="feedback-preview" className="cp-card">@@ -254,6 +249,7 @@ export function ControlsPreview() {<div className="cp-tools"><LedStrip state="live" label={t("state.signal.connected")} comic="signal-connected" /><LedStrip state="busy" label={t("state.signal.connecting")} comic="signal-connecting" />+ <LedStrip state="warn" label={t("state.signal.reconnecting")} comic="signal-recovering" /><LedStrip state="off" label={t("state.signal.offline")} comic="signal-offline" /></div><div className="cp-tools"><Pill icon="check" tone="live" label={t("common.copied")} comic="hint-copy-code" />@@ -300,7 +296,7 @@ export function ControlsPreview() {<video ref={video} poster={POSTER} playsInline inert style={{ objectFit: pictureFit }} /><StageOverlay dim waiting icon={STATUS_CATALOG.joining.icon} message={t(STATUS_CATALOG.joining.labelKey)} comic={STATUS_CATALOG.joining.comic} /><PlaybackControls videoRef={video} stream={null} canPlay={false} theaterMode={theater} onPlay={notify}- settings={{ pictureFit, setPictureFit, route: { preference: viewerRoute, onChange: setViewerRoute,+ settings={{ pictureFit, setPictureFit, pictureRotation, setPictureRotation, route: { preference: viewerRoute, onChange: setViewerRoute,sfuAvailable: true, sfuOnly: false, peerOnly: false, disabled: false, rejected: false } }}onToggleTheater={() => setTheater(!theater)} onReconnect={notify} reconnectAvailable /></StageTv></div>@@ -332,7 +328,7 @@ export function ControlsPreview() {</section><section id="interaction-preview" className="cp-section"><header className="cp-section-head"><span className="cp-number">09</span><div><h2>{en ? "A little company" : "聊两句,丢个番茄。"}</h2>- <p>{en ? "Chat and react in one window. Open reactions beside the message input; supported browsers can keep this window on top." : "聊天和表情都在一个窗口里。点输入区的「发表情」选择互动对象;支持的浏览器可以将窗口置顶。"}</p></div></header>+ <p>{en ? "Chat, reactions and room voice share one window. This catalogue simulates voice controls without opening your microphone." : "聊天、表情与房间语音共用一个窗口。这里的语音控件仅作演示,不会打开麦克风。"}</p></div></header><InteractionControlsPreview /></section><RemoteControlsPreview />@@ -342,6 +338,7 @@ export function ControlsPreview() {function InteractionControlsPreview() {const [session, setSession] = useState<RoomInteractionSession | null>(null);const [viewer, setViewer] = useState(false);+ const voice = useRoomVoicePreview(viewer);const [crowded, setCrowded] = useState(false);const [reaction, setReaction] = useState<ReactionId>("heart");const [theater, setTheater] = useTheaterMode();@@ -388,8 +385,8 @@ function InteractionControlsPreview() {<RoomChatOverlay session={session} visible /><PlaybackControls videoRef={video} stream={null} canPlay={false} onPlay={() => {}}theaterMode={theater} onToggleTheater={() => setTheater(value => !value)} onReconnect={() => {}} reconnectAvailable={false}- overlayAction={<RoomChatToggle session={session} />} overlaySettings={session && <RoomChatOverlaySettings session={session} />} />- </StageTv><RoomInteractions session={session}+ overlayAction={<RoomChatToggle session={session} />} />+ </StageTv><RoomInteractions session={session} voice={voice}view={viewer ? "viewer" : "host"} host={{ key: "preview-host", name: "Piik", you: !viewer }} entries={Array.from({ length: crowded ? 20 : 1 }, (_, index) => ({key: index ? `preview-friend-${index}` : "preview-friend", name: index ? `Friend ${index + 1}` : "Piik friend",diff --git a/src/client/pages/HostPage.tsx b/src/client/pages/HostPage.tsxindex 0834befc..88f26ae3 100644--- a/src/client/pages/HostPage.tsx+++ b/src/client/pages/HostPage.tsx@@ -21,17 +21,17 @@ import {type CodeEntryPolicy,type RoutePolicy,} from "../../shared/protocol";-import { browserCaptureDevices } from "../media/capture-devices";import { AppHeader, LedStrip } from "../components/living/Header";import { WelcomeLine } from "../components/living/WelcomeLine";import type { CouchEntry } from "../components/living/Couch";import { SharingSettings } from "../components/living/SharingSettings";import { HostShareControls } from "../components/living/HostShareControls";-import { HostMicrophone, HostMicrophoneSettings } from "../components/living/HostMicrophone";import { LiveAudioExclusion } from "../components/living/AudioExclusionSelect";import { RoomInteractions } from "../components/living/RoomInteractions";import { RoomChatOverlay } from "../components/living/RoomChatOverlay";import type { RoomInteractionSession } from "../lib/room-interactions";+import type { RoomVoiceSession } from "../room-voice/session";+import { RoomVoicePanel, RoomVoiceControls, RoomVoiceSettings } from "../room-voice/RoomVoicePanel";import { HostAudio } from "../media/host-audio";import {CaptureSourcePicker,@@ -382,19 +382,17 @@ export function HostPage({const [stream, setStream] = useState<MediaStream | null>(null);const hostAudioRef = useRef<HostAudio | null>(null);const audioAvailableRef = useRef(false);- const [microphoneEnabled, setMicrophoneEnabled] = useState(false);const [interactionSession, setInteractionSession] = useState<RoomInteractionSession | null>(null);- const [microphoneVolume, setMicrophoneVolume] = useState(1);- const [microphoneVoiceProcessing, setMicrophoneVoiceProcessing] = useState(true);- const [microphonePending, setMicrophonePending] = useState(false);- const [microphoneDevices, setMicrophoneDevices] = useState({ browser: "", native: "" });+ const [roomVoiceSession, setRoomVoiceSession] = useState<RoomVoiceSession | null>(null);const [cameraDevice, setCameraDevice] = useState("");- const loadMicrophones = useCallback(() => {- const client = nativeModeRef.current ? nativeClientRef.current : null;- return client ? client.microphones() : browserCaptureDevices("audioinput");- }, []);const [nativeActive, setNativeActive] = useState(false);const [remoteControlState, setRemoteControlState] = useState<RemoteControlState | null>(null);+ const remoteStopShortcut = useCallback(async (key?: number) => {+ const client = nativeClientRef.current;+ const shareId = nativeShareGenerationRef.current;+ if (!client || !shareId) throw new Error("Native share is unavailable");+ return client.remoteStopShortcut(shareId, key);+ }, []);const remoteInputPeersRef = useRef<Extract<ServerMessage, { type: "remote-input-peers" }>["peers"]>([]);const [showCaptureBorder, setShowCaptureBorder] = useState(false);const [nativeSources, setNativeSources] =@@ -461,7 +459,7 @@ export function HostPage({useState<HostCreationProfile>(readCreationProfile);const creationProfileRef = useRef(creationProfile);const [roomMutation, setRoomMutation] = useState<- "access" | "replacement" | "sharing" | null+ "access" | "replacement" | "sharing" | "creation" | null>(null);const roomMutating = roomMutation !== null;const [viewerPasswordEnabled, setViewerPasswordEnabled] = useState(false);@@ -941,8 +939,6 @@ export function HostPage({hostAudioRef.current?.dispose();hostAudioRef.current = null;audioAvailableRef.current = false;- setMicrophoneEnabled(false);- setMicrophonePending(false);streamRef.current?.getTracks().forEach((track) => track.stop());retiringStreamRef.current?.getTracks().forEach((track) => track.stop());streamRef.current = null;@@ -985,7 +981,7 @@ export function HostPage({}function beginRoomMutation(- kind: "access" | "replacement" | "sharing",+ kind: "access" | "replacement" | "sharing" | "creation",): object | null {if (roomMutationRef.current) {return null;@@ -1042,6 +1038,36 @@ export function HostPage({}}+ async function createIdleRoom(): Promise<void> {+ if (!hostRoomSessionAvailable || roomRef.current || phase === "starting") return;+ const mutation = beginRoomMutation("creation");+ if (!mutation) return;+ try {+ await roomInitializationRef.current;+ if (roomMutationRef.current !== mutation || roomRef.current) return;+ const profile = creationProfileRef.current;+ const response = await createRoom(+ profile.codeEntryPolicy, profile.roomPassword, readPreferredRoomId(),+ );+ const created = hostRoomFromCreated(response);+ if (roomMutationRef.current !== mutation) {+ closeAbandonedRoom(created);+ return;+ }+ if (!(await writeHostRoom(created, () => roomMutationRef.current === mutation))) {+ closeAbandonedRoom(created);+ throw new Error("Host room is already open in another tab");+ }+ roomRef.current = created;+ setRoom(created);+ setViewerPasswordEnabled(profile.roomPassword !== null);+ } catch (error) {+ if (roomMutationRef.current === mutation) setNoticeError(error, "room");+ } finally {+ finishRoomMutation(mutation);+ }+ }+async function replaceCurrentRoom(): Promise<void> {const activeRoom = roomRef.current;if (!activeRoom || roomMutationRef.current || phase === "starting") {@@ -1278,9 +1304,8 @@ export function HostPage({nativeSourceAudioRef.current = event.sourceAudio;audioAvailableRef.current = event.sourceAudio || event.microphone;signalRef.current?.setAudioAvailable(audioAvailableRef.current);- setMicrophoneEnabled(event.microphone);setDetails(previous => previous ? { ...previous, hasSourceAudio: event.sourceAudio } : previous);- if (event.failed) setNoticeValue({ kind: "key", key: "host.microphone.unavailable", target: "operation", comic: "warning", tone: "warn" });+ if (event.failed) setNoticeValue({ kind: "key", key: "host.sourceAudio.unavailable", target: "operation", comic: "warning", tone: "warn" });}if (event.type === "share-ended") {endSharing(@@ -2710,6 +2735,7 @@ export function HostPage({remoteInputPeersRef.current = [];void getRuntimeCapabilities().then(capabilities => {if (signalRef.current === signal && capabilities.roomInteractions) setInteractionSession(signal.enableRoomInteractions(capabilities.roomReactionIds));+ if (signalRef.current === signal && capabilities.roomVoice) setRoomVoiceSession(signal.enableRoomVoice());if (signalRef.current === signal && capabilities.remoteInput) signal.enableRemoteInput();if (signalRef.current === signal && capabilities.audioPresence) signal.enableAudioPresence();}).catch(() => { /* Optional input does not block sharing. */ });@@ -2808,7 +2834,7 @@ export function HostPage({}if (captured) {if (selection.kind === "browser") {- hostAudioRef.current = new HostAudio(captured, setMicrophoneEnabled, selection.source ?? "browser", available => {+ hostAudioRef.current = new HostAudio(captured, selection.source ?? "browser", available => {if (!isCurrentShare(generation, shareGeneration)) return;audioAvailableRef.current = available;signalRef.current?.setAudioAvailable(available);@@ -3078,45 +3104,6 @@ export function HostPage({failureCode: hostFailureCode(error, action, "camera") });}- async function changeMicrophone(enabled: boolean, deviceId: string, voiceProcessing = microphoneVoiceProcessing): Promise<void> {- const audio = hostAudioRef.current;- const generation = activeGenerationRef.current;- const client = nativeModeRef.current ? nativeClientRef.current : null;- const shareId = nativeShareGenerationRef.current;- if ((!audio && !(client?.health.nativeMedia.microphone && shareId)) || generation === null || sourceSwitchRef.current || qualityChangeRef.current || sharingPausedRef.current) return;- const token = {};- sourceSwitchRef.current = token;- setMicrophonePending(true);- setNoticeValue(null);- try {- if (client && shareId) {- await client.setMicrophone(shareId, enabled, microphoneVolume, deviceId);- if (isCurrentGeneration(generation) && nativeClientRef.current === client && sourceSwitchRef.current === token) {- setMicrophoneDevices(previous => ({ ...previous, native: deviceId }));- }- return;- }- if (!audio) return;- audio.setMicrophoneVolume(microphoneVolume);- const mixed = await audio.setMicrophone(enabled, deviceId, voiceProcessing);- if (!isCurrentGeneration(generation) || hostAudioRef.current !== audio) return;- setMicrophoneDevices(previous => ({ ...previous, browser: deviceId }));- setMicrophoneVoiceProcessing(voiceProcessing);- if (mixed) await replaceBrowserStream(mixed, generation, token);- } catch (error) {- if (isCurrentGeneration(generation) && sourceSwitchRef.current === token) {- debugError("capture", "microphone-failed", error);- setNoticeValue({ kind: "key", key: error instanceof DOMException && error.name === "NotAllowedError"- ? "host.microphone.denied" : "host.microphone.unavailable", target: "operation", comic: "warning", tone: "warn" });- }- } finally {- if (sourceSwitchRef.current === token) {- setMicrophonePending(false);- finishSourceSwitch(token);- }- }- }-async function replaceBrowserStream(captured: MediaStream, generation: number, token: object): Promise<void> {// The caller retires its operation; this function owns only stream resources.const previousStream = streamRef.current;@@ -3128,8 +3115,7 @@ export function HostPage({retiringStreamRef.current = previousStream;const videoChanged = captured.getVideoTracks()[0] !== previousStream.getVideoTracks()[0];- // HostAudio owns raw inputs and mixed output. Adding a mixer must not stop- // the old stream's audio: that track is still feeding the new output.+ // HostAudio retires source audio; this operation retires replaced video.const retirePrevious = () => previousStream.getVideoTracks().forEach((track) => {if (!captured.getTracks().includes(track)) track.stop();});@@ -3692,7 +3678,7 @@ export function HostPage({: nativeSourceAudioRef.current ?? false: true}- audioLocked={nativeActive && !nativeClientRef.current?.health.nativeMedia.microphone}+ audioLocked={false}initialShowCaptureBorder={showCaptureBorder}initialExcludeAudio={nativeSourceSelectionRef.current?.excludeAudio}/>@@ -3791,23 +3777,20 @@ export function HostPage({</StageTv><HostShareControlsactions={phase === "live" ? <>- <HostMicrophone enabled={microphoneEnabled} pending={microphonePending}- unavailable={nativeActive && !nativeClientRef.current?.health.nativeMedia.microphone} paused={sharingPaused} disabled={switchingSource || changingQuality}- volume={microphoneVolume}- onToggle={() => void changeMicrophone(!microphoneEnabled, microphoneDevices[nativeActive ? "native" : "browser"])} /><Btnid="host-switch-source"icon="switchSource"cap={switchingSource && !sourceSwitchRef.current?.audioOnly ? "host.switching" : "host.switchSource"}title="host.switchSource"hint="hint-switch-source"- disabled={switchingSource || changingQuality || microphonePending}+ disabled={switchingSource || changingQuality}onClick={() => void switchSource()}/></> : null}remote={nativeActive && remoteControlState && <HostRemoteControlmode={remoteControlState.mode}platform={remoteControlState.platform}+ onShortcut={nativeClientRef.current?.health.nativeMedia.remoteStopShortcut ? remoteStopShortcut : undefined}disabled={sharingPaused || switchingSource}requests={remoteControlState.requests.map(request => {return { ...request, name: viewers.find(viewer => viewer.peerId === request.peerId)?.label ?? t("common.name.viewerDefault") };@@ -3842,7 +3825,7 @@ export function HostPage({title={sharingPaused ? "host.resume" : "host.pause"}hint={sharingPaused ? "hint-resume" : "hint-pause"}draw="host-share-toggle"- disabled={switchingSource || changingQuality || microphonePending}+ disabled={switchingSource || changingQuality}onClick={toggleSharingPause}/>}ending={phase === "live" ? (@@ -3924,37 +3907,13 @@ export function HostPage({<div className="lr-door-group lr-source-audio-settings"><SwitchItem checked={nativeSourceSelectionRef.current.audio}label={t("host.sourcePicker.systemAudio")} hint={nativeSourceSelectionRef.current.audio ? "hint-stop-audio" : "hint-share-audio"}- disabled={microphonePending || switchingSource || changingQuality || sharingPaused}+ disabled={switchingSource || changingQuality || sharingPaused}onChange={audio => changeNativeSourceAudio(audio, nativeSourceSelectionRef.current?.excludeAudio)} /><LiveAudioExclusion load={loadAudioApplications} value={nativeSourceSelectionRef.current.excludeAudio}- disabled={!nativeSourceSelectionRef.current.audio || microphonePending || switchingSource || changingQuality || sharingPaused}+ disabled={!nativeSourceSelectionRef.current.audio || switchingSource || changingQuality || sharingPaused}onChange={target => changeNativeSourceAudio(true, target)} /></div>) : null}- {phase === "live" && (!nativeActive || nativeClientRef.current?.health.nativeMedia.microphone) ? (- <HostMicrophoneSettings enabled={microphoneEnabled}- disabled={microphonePending || switchingSource || changingQuality || sharingPaused}- volume={microphoneVolume} onVolume={volume => {- setMicrophoneVolume(volume);- hostAudioRef.current?.setMicrophoneVolume(volume);- const client = nativeClientRef.current;- const shareId = nativeShareGenerationRef.current;- if (nativeModeRef.current && client && shareId) {- void client.setMicrophoneVolume(shareId, volume).catch(error => {- if (nativeClientRef.current === client && nativeShareGenerationRef.current === shareId) {- debugError("capture", "microphone-volume-failed", error);- setNoticeValue({ kind: "key", key: "host.microphone.unavailable", target: "operation", comic: "warning", tone: "warn" });- }- });- }- }}- native={nativeActive} loadDevices={loadMicrophones}- deviceId={microphoneDevices[nativeActive ? "native" : "browser"]}- onDevice={deviceId => void changeMicrophone(microphoneEnabled, deviceId)}- voiceProcessing={microphoneVoiceProcessing}- onVoiceProcessing={enabled => void changeMicrophone(microphoneEnabled, microphoneDevices.browser, enabled)}- />- ) : null}<AudioBitrateControl value={screenAudioBitrate(advancedQuality.maxAudioBitrate)}max={audioBitrateCeiling} disabled={phase === "starting" || switchingSource}onChange={changeMaxAudioBitrate} />@@ -3999,6 +3958,12 @@ export function HostPage({}/><RoomInteractions session={room ? interactionSession : null}+ voice={room && roomVoiceSession ? {+ content: onSelect => <RoomVoicePanel session={roomVoiceSession} onSelectParticipant={onSelect}+ names={new Map(participantPresence.map(person => [person.peerId, person.displayName]))} />,+ settings: <RoomVoiceSettings session={roomVoiceSession} />,+ controls: <RoomVoiceControls session={roomVoiceSession} />,+ } : undefined}view="host"host={{key: hostIdentity,@@ -4046,7 +4011,11 @@ export function HostPage({passwordEnabled={viewerPasswordEnabled}/>) : null}- </> : <RoomCodePlaceholder />}+ </> : <RoomCodePlaceholder+ onCreate={hostRoomSessionAvailable ? () => void createIdleRoom() : undefined}+ disabled={roomMutating || phase === "starting"}+ busy={roomMutation === "creation"}+ />}</div><div className="lr-host-personal-controls"><div className="lr-row-group lr-group-name lr-host-identity-slot">@@ -4128,7 +4097,7 @@ export function HostPage({title={showConnectionDetails? "host.details.hide"- : "host.details"+ : "host.details.show"}hint={showConnectionDetails ? "hint-collapse" : "hint-details"}tone={showConnectionDetails ? "on" : undefined}@@ -4442,6 +4411,7 @@ export function HostPage({<Row sub><RouteTreehostPeerId={hostPeerId}+ voice={roomVoiceSession}hostIdentity={hostIdentity}hostLabel={labeledHostPresence?.label ?? displayName}viewers={viewers}diff --git a/src/client/pages/PlaybackPreviewPage.tsx b/src/client/pages/PlaybackPreviewPage.tsxindex 90ddd23d..c60ebbb0 100644--- a/src/client/pages/PlaybackPreviewPage.tsx+++ b/src/client/pages/PlaybackPreviewPage.tsx@@ -1,5 +1,5 @@import { useEffect, useRef, useState } from "react";-import type { VideoFit } from "../media/video-geometry";+import type { VideoFit, VideoRotation } from "../media/video-geometry";import { AppHeader } from "../components/living/Header";import { PlaybackControls } from "../components/living/PlaybackControls";import { StageOverlay, StageTv } from "../components/living/Stage";@@ -7,15 +7,16 @@ import { StatusIndicator } from "../components/living/StatusIndicator";import { STATUS_CATALOG } from "../ui/media-status";import { useCopy } from "../ui/copy";-function testMedia(withAudio: boolean) {+function testMedia(withAudio: boolean, portrait: boolean) {const canvas = document.createElement("canvas");- canvas.width = 640;+ canvas.width = portrait ? 480 : 640;// A 4:3 picture makes contain, crop and stretch visible in the 16:9 player.- canvas.height = 480;+ canvas.height = portrait ? 640 : 480;const paint = canvas.getContext("2d")!;const started = performance.now();let animation = 0;function draw(now: number) {+ paint.setTransform(canvas.width / 640, 0, 0, canvas.height / 480, 0, 0);const seconds = (now - started) / 1000;paint.fillStyle = "#172c3b";paint.fillRect(0, 0, 640, 480);@@ -28,6 +29,11 @@ function testMedia(withAudio: boolean) {paint.fillStyle = "#dfe8f2";paint.font = "24px monospace";paint.fillText(`${seconds.toFixed(1)} s`, 28, 44);+ paint.font = "18px monospace";+ paint.fillText("TOP LEFT", 28, 76);+ paint.fillText("TOP RIGHT", 510, 44);+ paint.fillText("BOTTOM LEFT", 28, 452);+ paint.fillText("BOTTOM RIGHT", 480, 452);animation = requestAnimationFrame(draw);}draw(started);@@ -65,10 +71,12 @@ export function PlaybackPreviewPage() {const [stream, setStream] = useState<MediaStream | null>(null);const [theaterMode, setTheaterMode] = useState(false);const [pictureFit, setPictureFit] = useState<VideoFit>("contain");+ const [pictureRotation, setPictureRotation] = useState<VideoRotation>(0);const [viewerRoute, setViewerRoute] = useState<"auto" | "p2p" | "sfu">("auto");const [error, setError] = useState("");const [waiting, setWaiting] = useState(true);const [audioAvailable, setAudioAvailable] = useState(false);+ const [portraitSource, setPortraitSource] = useState(false);const hasAudio = Boolean(stream?.getAudioTracks().length);function play() {@@ -79,9 +87,9 @@ export function PlaybackPreviewPage() {});}- function start(withAudio: boolean) {+ function start(withAudio: boolean, portrait = portraitSource) {mediaRef.current?.stop();- const media = testMedia(withAudio);+ const media = testMedia(withAudio, portrait);mediaRef.current = media;setError("");setWaiting(false);@@ -125,6 +133,9 @@ export function PlaybackPreviewPage() {{hasAudio ? (english ? "Remove audio track" : "移除音轨") : (english ? "Add quiet test tone" : "加入轻音量测试音")}</button><button className="lr-btn" type="button" disabled={!stream} onClick={() => start(hasAudio)}>{english ? "Rebind new stream" : "重新绑定新流"}</button>+ <button className="lr-btn" type="button" disabled={!stream} onClick={() => {+ setPortraitSource(!portraitSource); start(hasAudio, !portraitSource);+ }}>{portraitSource ? (english ? "Use landscape source" : "切换横向画面") : (english ? "Use portrait source" : "切换竖向画面")}</button><button className="lr-btn" type="button" disabled={!hasAudio} onClick={() => {mediaRef.current?.setAudioInput(!audioAvailable);setAudioAvailable(!audioAvailable);@@ -140,7 +151,7 @@ export function PlaybackPreviewPage() {aria-label={english ? "Local test video" : "本机测试视频"} />{waiting && <StageOverlay dim waiting icon={STATUS_CATALOG.joining.icon} message={t(STATUS_CATALOG.joining.labelKey)} comic={STATUS_CATALOG.joining.comic} />}<PlaybackControls videoRef={videoRef} stream={stream} audioAvailable={audioAvailable}- settings={{ pictureFit, setPictureFit, route: { preference: viewerRoute, onChange: setViewerRoute,+ settings={{ pictureFit, setPictureFit, pictureRotation, setPictureRotation, route: { preference: viewerRoute, onChange: setViewerRoute,sfuAvailable: true, sfuOnly: false, peerOnly: false, disabled: false, rejected: false } }}audioTrackKey={stream?.getAudioTracks().map((track) => track.id).join(",")}canPlay={Boolean(stream) && !waiting} theaterMode={theaterMode} onPlay={play}diff --git a/src/client/pages/RemoteControlsPreview.tsx b/src/client/pages/RemoteControlsPreview.tsxindex f574189e..2c77b8af 100644--- a/src/client/pages/RemoteControlsPreview.tsx+++ b/src/client/pages/RemoteControlsPreview.tsx@@ -15,6 +15,12 @@ export function RemoteControlsPreview() {const [requests, setRequests] = useState<(RemoteControlRequest & { name: string })[]>([]);const [keyboardOpen, setKeyboardOpen] = useState(false);const [lastInput, setLastInput] = useState("");+ const [releaseKey, setReleaseKey] = useState(10);+ const [stopKey, setStopKey] = useState(10);+ const shortcut = useCallback(async (key?: number) => {+ if (key !== undefined) setStopKey(key);+ return { key: key ?? stopKey, available: true };+ }, [stopKey]);const input = useCallback((event: RemoteInputEvent) => setLastInput(JSON.stringify(event)), []);const closeKeyboard = () => {setKeyboardOpen(false);@@ -34,6 +40,7 @@ export function RemoteControlsPreview() {</select></label><HostRemoteControl mode={mode} platform={platform} requests={requests}+ onShortcut={platform === "linux" ? undefined : shortcut}onPolicy={async value => { setMode(value); setRequests([]); }}onDecide={async (id, allow) => setRequests(current => allow? current.map(request => request.id === id ? { ...request, state: "active" } : request)@@ -46,7 +53,8 @@ export function RemoteControlsPreview() {expanded={keyboardOpen} controls="preview-remote-keyboard" onClick={() => setKeyboardOpen(value => !value)} /></div><div id="preview-remote-keyboard" className="cp-keyboard" hidden={!keyboardOpen}>- {keyboardOpen && <RemoteKeyboard key={platform} platform={platform} touch={false} input={input} close={closeKeyboard} />}+ {keyboardOpen && <RemoteKeyboard key={platform} platform={platform} touch={false} input={input} close={closeKeyboard}+ releaseKey={releaseKey} onReleaseKeyChange={setReleaseKey} />}</div><p className="cp-input-output"><span>{en ? "Latest input" : "最近一次输入"}</span><output>{lastInput || (en ? "Open the keyboard to try it." : "打开键盘即可试用。")}</output>diff --git a/src/client/pages/RoomVoicePreview.tsx b/src/client/pages/RoomVoicePreview.tsxnew file mode 100644index 00000000..bb4fb5b7--- /dev/null+++ b/src/client/pages/RoomVoicePreview.tsx@@ -0,0 +1,68 @@+import { useEffect, useMemo, useState } from "react";+import { RoomVoiceControls, RoomVoicePanel, RoomVoiceSettings, type RoomVoiceView } from "../room-voice/RoomVoicePanel";+import type { RoomVoiceSnapshot } from "../room-voice/session";+import type { RoomVoiceCommand } from "../../shared/protocol";++const names = new Map([["preview-host", "Piik"], ["preview-friend", "Piik friend"]]);+function initialState(viewer: boolean): RoomVoiceSnapshot {+ return { peerId: viewer ? "preview-friend" : "preview-host", role: viewer ? "viewer" : "host", connected: true,+ microphone: false, capturePending: false, deafened: false, listeningVolume: 1, peerVolumes: new Map(), autoplayBlocked: false, error: null, muted: new Set(),+ input: { deviceId: "", volume: 1, voiceProcessing: true },+ room: { type: "room-voice-state", revision: 1, enabled: true, hostPeerId: "preview-host", publications: [], connections: [], unavailable: [],+ members: [+ { peerId: "preview-host", connected: true, joined: true,+ publicationId: viewer ? "preview-host-publication" : undefined, upstream: { kind: "none" } },+ { peerId: "preview-friend", connected: true, joined: true,+ publicationId: viewer ? undefined : "preview-friend-publication", upstream: { kind: "peer", peerId: "preview-host" } },+ ] },+ };+}++// The catalogue stages the real view without opening a microphone or transport.+export function useRoomVoicePreview(viewer: boolean) {+ const [state, setState] = useState(() => initialState(viewer));+ useEffect(() => setState(initialState(viewer)), [viewer]);+ const session = useMemo<RoomVoiceView>(() => {+ const snapshot: RoomVoiceSnapshot = { ...state, room: state.room && { ...state.room,+ members: state.room.members.map(member => member.peerId === state.peerId+ ? { ...member, publicationId: state.microphone ? "preview-publication" : undefined } : member),+ } };+ const command = (command: RoomVoiceCommand) => {+ if (command.action === "join" || command.action === "leave") {+ const joined = command.action === "join";+ setState(current => ({ ...current, microphone: joined && current.microphone,+ room: current.room && { ...current.room,+ enabled: current.role === "host" ? joined : current.room.enabled,+ members: current.room.members.map(member => member.peerId === current.peerId || current.role === "host" && !joined+ ? { ...member, joined, publicationId: undefined } : member),+ },+ }));+ }+ return true;+ };+ return {+ subscribe: () => () => {}, getSnapshot: () => snapshot, command, resumeAudio: () => {},+ startMicrophone: async () => { setState(current => ({ ...current, microphone: true })); },+ stopMicrophone: () => setState(current => ({ ...current, microphone: false })),+ deafen: deafened => setState(current => ({ ...current, deafened })),+ configureInput: async patch => { setState(current => ({ ...current, input: { ...current.input, ...patch } })); },+ setVolume: volume => setState(current => ({ ...current, input: { ...current.input, volume } })),+ setListeningVolume: listeningVolume => setState(current => ({ ...current, listeningVolume })),+ setPeerVolume: (peerId, volume) => setState(current => ({ ...current, peerVolumes: new Map(current.peerVolumes).set(peerId, volume) })),+ activity: async (localOnly = false) => new Map((snapshot.room?.members ?? [])+ .filter(member => member.joined && member.publicationId && (!localOnly || member.peerId === state.peerId))+ .map((member, index) => [member.peerId, Math.max(0, Math.sin(performance.now() / 350 + index * 2)) * .18+ * (member.peerId === state.peerId ? state.input.volume : 1)])),+ microphones: async () => [{ id: "headset", label: "USB Headset" }, { id: "desk", label: "Desk Microphone" }],+ muteVoice: peerId => setState(current => {+ const muted = new Set(current.muted);+ if (muted.has(peerId)) muted.delete(peerId); else muted.add(peerId);+ return { ...current, muted };+ }),+ };+ }, [state]);+ return { controls: <RoomVoiceControls session={session} />,+ settings: <RoomVoiceSettings session={session} />,+ content: (onSelect: (peerId: string, trigger: HTMLButtonElement) => void) =>+ <RoomVoicePanel session={session} names={names} onSelectParticipant={onSelect} /> };+}diff --git a/src/client/pages/ViewerPage.tsx b/src/client/pages/ViewerPage.tsxindex 9de845de..c5bd3e14 100644--- a/src/client/pages/ViewerPage.tsx+++ b/src/client/pages/ViewerPage.tsx@@ -11,6 +11,7 @@ import {DEFAULT_QUALITY_SETTINGS,DEFAULT_ROUTE_POLICY,MAX_VIEWER_PASSWORD_LENGTH,+ MAX_VIEWERS_PER_ROOM_LIMIT,viewerPasswordSchema,type IceConfig,type ParticipantPresenceEntry,@@ -27,8 +28,10 @@ import {import { AppHeader, LedStrip } from "../components/living/Header";import type { CouchEntry } from "../components/living/Couch";import { RoomInteractions } from "../components/living/RoomInteractions";-import { RoomChatOverlay, RoomChatOverlaySettings, RoomChatToggle } from "../components/living/RoomChatOverlay";+import { RoomChatOverlay, RoomChatToggle } from "../components/living/RoomChatOverlay";import type { RoomInteractionSession } from "../lib/room-interactions";+import type { RoomVoiceSession } from "../room-voice/session";+import { RoomVoicePanel, RoomVoiceControls, RoomVoiceSettings } from "../room-voice/RoomVoicePanel";import { getRuntimeCapabilities } from "../lib/api";import { participantColor } from "../components/living/participant-color";import { MetricCells } from "../components/living/Metrics";@@ -129,6 +132,7 @@ import {NativeCapableViewerPeer,} from "../native/native-viewer-peer";import { NativeSenderPeer } from "../native/native-sender-peer";+import { nativeRelayCapacity } from "../native/wire";interface ViewerPageProps {roomId: string;@@ -272,13 +276,24 @@ export function ViewerPage({const viewerSfuRouteRef = useRef<ViewerSfuRoute | null>(null);const signalRef = useRef<SignalingClient | null>(null);const [interactionSession, setInteractionSession] = useState<RoomInteractionSession | null>(null);+ const [roomVoiceSession, setRoomVoiceSession] = useState<RoomVoiceSession | null>(null);const [pictureFit, setPictureFit] = useState<VideoFit>(() => readRoomPreferences().pictureFit);+ const [pictureRotation, setPictureRotation] = useState(() => readRoomPreferences().pictureRotation);const [routeOptions, setRouteOptions] = useState<{ sfu: boolean; sfuOnly: boolean } | null>(null);const [routePreference, setRoutePreference] = useState<ViewerRoutePreference>("auto");const [routePreferencePending, setRoutePreferencePending] = useState(false);const [routePreferenceRejected, setRoutePreferenceRejected] = useState(false);+ const [relayVolunteerSupported, setRelayVolunteerSupported] = useState(false);+ const [relayVolunteerEnabled, setRelayVolunteerEnabled] = useState(false);+ const [relayVolunteerPending, setRelayVolunteerPending] = useState(false);+ const requestRelayVolunteerRef = useRef<((enabled: boolean) => void) | null>(null);const [peerOnly, setPeerOnly] = useState(false);- useEffect(() => { if (signalStatus !== "connected") setRoutePreferencePending(false); }, [signalStatus]);+ useEffect(() => {+ if (signalStatus !== "connected") {+ setRoutePreferencePending(false);+ setRelayVolunteerPending(false);+ }+ }, [signalStatus]);const presentationStateRef = useRef(presentationState);presentationStateRef.current = presentationState;function dispatchPresentation(action: ViewerPresentationAction): void {@@ -473,6 +488,8 @@ export function ViewerPage({connectionId: string;} | null = null;let endpointMediaCopyCapacity = MAX_ENDPOINT_MEDIA_CHILDREN;+ let relayBackendCapacity: number | null = null;+ let relayVolunteerAvailable = false;let viewerAuthorizationGeneration: string | null = null;let currentQualitySettings: QualitySettings = DEFAULT_QUALITY_SETTINGS;let currentRoutePolicy: RoutePolicy = DEFAULT_ROUTE_POLICY;@@ -544,7 +561,7 @@ export function ViewerPage({acquireNativeClient,() => { nativeViewerAvailable = false; },nativeViewerSessionId,- MAX_ENDPOINT_MEDIA_CHILDREN,+ MAX_VIEWERS_PER_ROOM_LIMIT,);}@@ -622,10 +639,39 @@ export function ViewerPage({);setInteractionSession(null);setRouteOptions(null);+ setRelayVolunteerSupported(false);+ setRelayVolunteerEnabled(false);+ setRelayVolunteerPending(false);+ requestRelayVolunteerRef.current = enabled => {+ setRelayVolunteerPending(true);+ // Keep consent in the signaling owner before asynchronous App discovery.+ // Until its backend is known, an App gets only the legacy physical bound.+ const capacity = relayBackendCapacity ?? (clientActivationRef.current ? MAX_ENDPOINT_MEDIA_CHILDREN : MAX_VIEWERS_PER_ROOM_LIMIT);+ if (!signal.setRelayVolunteer(enabled, capacity)) setRelayVolunteerPending(false);+ void acquireNativeClient().then(client => {+ if (!active || relayBackendCapacity !== null) return;+ const actualCapacity = client+ ? nativeRelayCapacity(MAX_VIEWERS_PER_ROOM_LIMIT, client.health) : MAX_VIEWERS_PER_ROOM_LIMIT;+ const intent = signal.relayVolunteerRequest;+ if (intent && intent.capacity !== actualCapacity) {+ setRelayVolunteerPending(true);+ signal.setRelayVolunteer(intent.enabled, actualCapacity);+ }+ });+ };setAudioAvailable(null);void getRuntimeCapabilities().then(capabilities => {if (active && capabilities.audioPresence) signal.enableAudioPresence();if (active && capabilities.roomInteractions) setInteractionSession(signal.enableRoomInteractions(capabilities.roomReactionIds));+ if (active && capabilities.roomVoice) setRoomVoiceSession(signal.enableRoomVoice());+ if (active) {+ relayVolunteerAvailable = capabilities.relayVolunteer && !capabilities.sfuOnly;+ setRelayVolunteerSupported(relayVolunteerAvailable);+ if (relayVolunteerAvailable && relayBackendCapacity !== null) {+ setRelayVolunteerPending(true);+ signal.setRelayVolunteer(signal.relayVolunteerRequest?.enabled ?? false, relayBackendCapacity);+ }+ }if (active && capabilities.remoteInput) inputRoute.enable(identity => signal.send({ type: "subscribe-remote-input", ...identity }));if (active && capabilities.viewerRouteSelection) {const saved = readRoomPreferences().routePreference;@@ -744,6 +790,15 @@ export function ViewerPage({if (!remoteMediaRef.current?.stream) {return null;}+ const capacity = source+ ? nativeRelayCapacity(MAX_VIEWERS_PER_ROOM_LIMIT, source.client.health) : MAX_VIEWERS_PER_ROOM_LIMIT;+ if (relayBackendCapacity !== capacity) {+ relayBackendCapacity = capacity;+ if (relayVolunteerAvailable) {+ setRelayVolunteerPending(true);+ signal.setRelayVolunteer(signal.relayVolunteerRequest?.enabled ?? false, capacity);+ }+ }const sourceKey = source? `native:${source.sessionId}:${source.connectionId}:${source.generation}`: "browser";@@ -1501,6 +1556,17 @@ export function ViewerPage({message: ServerMessage,authorityToken: number,): Promise<void> {+ if (message.type === "relay-volunteer") {+ setRelayVolunteerEnabled(message.enabled);+ const intent = signal.relayVolunteerRequest;+ setRelayVolunteerPending(intent !== null && (intent.enabled !== message.enabled ||+ message.enabled && intent.capacity !== message.capacity));+ // Withdrawal is a controller handoff. Retain physical room for old+ // children until its assignments retire them, including on reauth.+ endpointMediaCopyCapacity = Math.max(endpointMediaCopyCapacity, message.capacity);+ viewerRelay?.updateCapacity(endpointMediaCopyCapacity);+ return;+ }if (message.type === "viewer-route-preference") {setRoutePreference(message.preference);setRoutePreferencePending(false);@@ -1513,9 +1579,11 @@ export function ViewerPage({setViewerPasswordDraft("");setViewerPasswordError(null);relayChildEvidenceStore.clear();+ endpointMediaCopyCapacity = currentPeerId === null ? message.endpointMediaCopyCapacity+ : Math.max(endpointMediaCopyCapacity, message.endpointMediaCopyCapacity);currentPeerId = message.peerId;setSelfPeerId(message.peerId);- endpointMediaCopyCapacity = message.endpointMediaCopyCapacity;+ setRelayVolunteerPending(signal.relayVolunteerRequest !== null);currentAssignment = limitMediaAssignment(currentAssignment,endpointMediaCopyCapacity,@@ -1857,6 +1925,7 @@ export function ViewerPage({signal.start();return () => {active = false;+ requestRelayVolunteerRef.current = null;document.removeEventListener("freeze", suspendForPageLifecycle);document.removeEventListener("resume", recoverFromPageLifecycle);document.removeEventListener("visibilitychange", handleVisibilityChange);@@ -2262,11 +2331,12 @@ export function ViewerPage({/><PlaybackControlsoverlayAction={<RoomChatToggle session={interactionSession} />}- overlaySettings={interactionSession && <RoomChatOverlaySettings session={interactionSession} />}remoteActions={<RemoteControl channel={inputRoute.current} videoRef={videoRef}- pictureFit={pictureFit}+ pictureFit={pictureFit} pictureRotation={pictureRotation}available={presentation.overlay === "none" && presentation.hasCurrentFrame} />}- settings={{ pictureFit, setPictureFit: fit => {+ settings={{ pictureFit, pictureRotation, setPictureRotation: rotation => {+ setPictureRotation(rotation); saveRoomPreferences({ pictureRotation: rotation });+ }, setPictureFit: fit => {setPictureFit(fit); saveRoomPreferences({ pictureFit: fit });},route: routeOptions ? {@@ -2281,6 +2351,11 @@ export function ViewerPage({}},} : undefined,+ relayVolunteer: relayVolunteerSupported ? {+ enabled: relayVolunteerEnabled, pending: relayVolunteerPending,+ disabled: signalStatus !== "connected" || relayVolunteerPending,+ onChange: enabled => requestRelayVolunteerRef.current?.(enabled),+ } : undefined,}}videoRef={videoRef}stream={remoteMedia?.stream ?? null}@@ -2351,6 +2426,12 @@ export function ViewerPage({)}</div><RoomInteractions session={interactionSession}+ voice={roomVoiceSession ? {+ content: onSelect => <RoomVoicePanel session={roomVoiceSession} onSelectParticipant={onSelect}+ names={new Map((participantPresence ?? []).map(person => [person.peerId, person.displayName]))} />,+ settings: <RoomVoiceSettings session={roomVoiceSession} />,+ controls: <RoomVoiceControls session={roomVoiceSession} />,+ } : undefined}view="viewer"host={labeledHostPresence@@ -2466,7 +2547,7 @@ export function ViewerPage({icon="gauge"cap="host.details"title={- showConnectionDetails ? "host.details.hide" : "host.details"+ showConnectionDetails ? "host.details.hide" : "host.details.show"}hint={showConnectionDetails ? "hint-collapse" : "hint-details"}tone={showConnectionDetails ? "on" : undefined}@@ -2568,6 +2649,7 @@ export function ViewerPage({<Row sub><RouteTreehostPeerId={labeledHostPresence.peerId}+ voice={roomVoiceSession}hostLabel={labeledHostPresence.label}viewers={viewers}selfPeerId={selfPeerId}diff --git a/src/client/remote-control/input-session.ts b/src/client/remote-control/input-session.tsindex afe92bd4..e659b863 100644--- a/src/client/remote-control/input-session.ts+++ b/src/client/remote-control/input-session.ts@@ -1,5 +1,4 @@import type { InputTransport } from "./input-route";-import { videoPictureSize } from "../media/video-geometry";import { remoteInputStateSchema, type RemoteInputState } from "./protocol";export type { RemoteInputState } from "./protocol";export type RemoteInputEvent =@@ -147,21 +146,3 @@ export class RemoteInputSession {this.channel.removeEventListener("close", this.closed);}}--// The input surface can include letterboxing. Its bars are not clickable-// picture pixels; use the same local fit as Viewer playback, including cropping.-export function pictureRect(video: HTMLVideoElement): { left: number; top: number; width: number; height: number } | null {- if (!video.videoWidth || !video.videoHeight) return null;- const rect = video.getBoundingClientRect();- const { width, height } = videoPictureSize(video, rect.width, rect.height);- if (!width || !height) return null;- return { left: rect.left + (rect.width - width) / 2, top: rect.top + (rect.height - height) / 2, width, height };-}--export function picturePoint(video: HTMLVideoElement, clientX: number, clientY: number): { x: number; y: number } | null {- const rect = pictureRect(video);- if (!rect) return null;- const x = (clientX - rect.left) / rect.width;- const y = (clientY - rect.top) / rect.height;- return x >= 0 && x <= 1 && y >= 0 && y <= 1 ? { x, y } : null;-}diff --git a/src/client/remote-control/protocol.ts b/src/client/remote-control/protocol.tsindex ab2d9887..8a1dff92 100644--- a/src/client/remote-control/protocol.ts+++ b/src/client/remote-control/protocol.ts@@ -2,6 +2,13 @@ import { z } from "zod";// A text submission still fits one encrypted input packet and the existing queue.export const REMOTE_TEXT_BYTES = 2048;+// F12 is reserved by Windows debuggers, including for global modified chords.+export const remoteShortcutKeySchema = z.number().int().min(1).max(11);+export const REMOTE_SHORTCUT_KEYS = Array.from({ length: 11 }, (_, index) => index + 1);++export function matchesRemoteShortcut(event: Pick<KeyboardEvent, "code" | "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "isComposing">, key: number): boolean {+ return !event.isComposing && event.ctrlKey && event.altKey && !event.shiftKey && !event.metaKey && event.code === `F${key}`;+}export const remoteControlModeSchema = z.enum(["off", "ask", "room", "password"]);export type RemoteControlMode = z.infer<typeof remoteControlModeSchema>;diff --git a/src/client/remote-control/touchpad.ts b/src/client/remote-control/touchpad.tsindex 6cad2cad..ee0f0b00 100644--- a/src/client/remote-control/touchpad.ts+++ b/src/client/remote-control/touchpad.ts@@ -1,5 +1,6 @@import type { RemoteInputEvent } from "./input-session";import type { RemoteViewport } from "./viewport";+import { rotatePictureDelta, type VideoRotation } from "../media/video-geometry";type Point = { x: number; y: number };type Contact = Point & { start: Point };@@ -19,7 +20,7 @@ export class RemoteTouchpad {private frame: number | null = null;constructor(- private readonly picture: () => { width: number; height: number } | null,+ private readonly picture: () => { width: number; height: number; rotation: VideoRotation } | null,private readonly input: (event: RemoteInputEvent) => void,private readonly scroll: (deltaY: number) => void,private readonly changed: (position: Point) => void,@@ -71,9 +72,10 @@ export class RemoteTouchpad {contact.x = x; contact.y = y;const picture = this.picture();if (!picture?.width || !picture.height) return;+ const delta = rotatePictureDelta({ x: dx / picture.width, y: dy / picture.height }, picture.rotation, true);this.position = this.viewport.visiblePosition({- x: Math.max(0, Math.min(1, this.position.x + dx / picture.width)),- y: Math.max(0, Math.min(1, this.position.y + dy / picture.height)),+ x: Math.max(0, Math.min(1, this.position.x + delta.x)),+ y: Math.max(0, Math.min(1, this.position.y + delta.y)),});this.input({ type: "move", ...this.position });this.changed(this.position);diff --git a/src/client/remote-control/viewport.ts b/src/client/remote-control/viewport.tsindex 4d7cbfe7..84a6e2c8 100644--- a/src/client/remote-control/viewport.ts+++ b/src/client/remote-control/viewport.ts@@ -1,5 +1,4 @@-import { pictureRect } from "./input-session";-import { videoPictureSize } from "../media/video-geometry";+import { pictureRect, rotatePicturePoint, videoBoxSize, videoPictureSize, videoRotation } from "../media/video-geometry";type Point = { x: number; y: number };@@ -37,12 +36,18 @@ export class RemoteViewport {const limitY = Math.max(0, (picture.height * this.scale - height) / 2);const x = this.offset.x = Math.max(-limitX, Math.min(limitX, this.offset.x));const y = this.offset.y = Math.max(-limitY, Math.min(limitY, this.offset.y));- style.transform = this.scale > 1 ? `translate(${x}px, ${y}px) scale(${this.scale})` : "";+ style.transform = this.scale > 1 ? `translate(${x}px, ${y}px) scale(${this.scale}) var(--picture-transform)` : "";// Clip to the original video cell, including when a keyboard occupies the// next grid cell. Inverse-transform its edges into the video's local space.- const insets = [height / 2 - (height / 2 + y) / this.scale, width / 2 - (width / 2 - x) / this.scale,- height / 2 - (height / 2 - y) / this.scale, width / 2 - (width / 2 + x) / this.scale];- style.clipPath = this.scale > 1 ? `inset(${insets.map(value => `${value}px`).join(" ")})` : "";+ const bounds = this.video.getBoundingClientRect(), surface = this.surface.getBoundingClientRect();+ const box = videoBoxSize(this.video);+ const corners = [[surface.left, surface.top], [surface.right, surface.bottom]].map(([x, y]) =>+ rotatePicturePoint({ x: (x - bounds.left) / bounds.width, y: (y - bounds.top) / bounds.height }, videoRotation(this.video), true));+ const insets = [Math.min(...corners.map(point => point.y)) * box.height,+ (1 - Math.max(...corners.map(point => point.x))) * box.width,+ (1 - Math.max(...corners.map(point => point.y))) * box.height,+ Math.min(...corners.map(point => point.x)) * box.width];+ style.clipPath = `inset(${insets.map(value => `${value}px`).join(" ")})`;this.changed(this.scale > 1);}@@ -51,12 +56,13 @@ export class RemoteViewport {if (!picture) return position;// Keep the local touch cursor in view while panning. No remote input is// emitted until the user next moves or clicks, at this visible position.- return {+ const rotated = rotatePicturePoint(position, videoRotation(this.video));+ return rotatePicturePoint({x: Math.max(0, Math.min(1, Math.max((rect.left - picture.left) / picture.width,- Math.min((rect.right - picture.left) / picture.width, position.x)))),+ Math.min((rect.right - picture.left) / picture.width, rotated.x)))),y: Math.max(0, Math.min(1, Math.max((rect.top - picture.top) / picture.height,- Math.min((rect.bottom - picture.top) / picture.height, position.y)))),- };+ Math.min((rect.bottom - picture.top) / picture.height, rotated.y)))),+ }, videoRotation(this.video), true);}reset(): void {diff --git a/src/client/room-voice/RoomVoicePanel.tsx b/src/client/room-voice/RoomVoicePanel.tsxnew file mode 100644index 00000000..cdb84087--- /dev/null+++ b/src/client/room-voice/RoomVoicePanel.tsx@@ -0,0 +1,163 @@+import { useEffect, useId, useState, useSyncExternalStore } from "react";+import { Btn } from "../components/living/primitives";+import { MicrophoneSettings } from "../components/living/MicrophoneSettings";+import { AudioVolumeControl } from "../components/living/AudioVolumeControl";+import { AudioVolumeMenu } from "../components/living/AudioVolumeMenu";+import { PawnSvg } from "../components/living/Pawn";+import { Tooltip } from "../components/living/Tooltip";+import { participantColor } from "../components/living/participant-color";+import { labelParticipantNames } from "../lib/viewer-presence";+import { useCopy, type CopyKey } from "../ui/copy";+import { Glyph, type GlyphName } from "../ui/icons";+import type { RoomVoiceSession, RoomVoiceSnapshot } from "./session";+import "./room-voice.css";++export type RoomVoiceView = Pick<RoomVoiceSession, "subscribe" | "getSnapshot" | "resumeAudio" | "command" |+ "startMicrophone" | "stopMicrophone" | "muteVoice" | "deafen" | "configureInput" | "setVolume" | "setListeningVolume" | "setPeerVolume" | "activity" | "microphones">;+interface Props { session: RoomVoiceView }++function useVoiceLevels(session: RoomVoiceView, enabled: boolean, localOnly = false): ReadonlyMap<string, number> {+ const [levels, setLevels] = useState<ReadonlyMap<string, number>>(new Map());+ useEffect(() => {+ if (!enabled) { setLevels(new Map()); return; }+ let current = true, timer: ReturnType<typeof setTimeout>;+ const sample = async () => {+ try { const levels = await session.activity(localOnly); if (current) setLevels(levels); }+ catch { if (current) setLevels(new Map()); }+ finally { if (current) timer = setTimeout(() => void sample(), 150); }+ };+ void sample();+ return () => { current = false; clearTimeout(timer); };+ }, [session, enabled, localOnly]);+ return levels;+}++export function RoomVoiceControls({ session }: Props) {+ const { t, vis } = useCopy();+ const state = useSyncExternalStore(session.subscribe, session.getSnapshot);+ const me = state.room?.members.find(member => member.peerId === state.peerId);+ const levels = useVoiceLevels(session, state.microphone, true), meterId = useId();+ const level = Math.min(1, (levels.get(state.peerId) ?? 0) * 5);+ const microphoneUnavailable = !state.microphone && !state.capturePending && !navigator.mediaDevices?.getUserMedia;+ const joined = Boolean(me?.joined);+ const host = state.role === "host";+ const voiceClosed = !host && state.room?.enabled === false;+ const actionTitle = host ? joined ? "voice.close" : "voice.open" : joined ? "voice.leave" : "voice.join";+ const actionHint = host ? joined ? "hint-voice-close" : "hint-voice-open"+ : joined ? "hint-voice-leave" : voiceClosed ? "hint-voice-closed" : "hint-voice-join";+ const actionExplanation = host ? joined ? "voice.closeHint" : "voice.openHint" : voiceClosed ? "voice.closedHint" : undefined;+ return <>+ <div className="lr-voice-toolbar lr-media-controls" role="group" aria-label={t("interaction.voice")}>+ {joined && <div className="lr-voice-quick-controls">+ <AudioVolumeMenu volume={state.input.volume} onVolume={volume => session.setVolume(volume)}+ label="host.microphone.volume" icon="microphone" disabled={microphoneUnavailable || state.capturePending}>+ <Btn icon={state.microphone ? "microphone" : "microphoneOff"} title="host.device.microphone"+ size="compact" hint={microphoneUnavailable ? host ? "hint-voice-host-microphone-unavailable" : "hint-voice-microphone-unavailable"+ : state.capturePending ? "hint-close" : undefined}+ hintText={microphoneUnavailable ? "voice.error.microphoneUnavailable" : "voice.captureCancel"}+ pressed={state.microphone} busy={state.capturePending} disabled={!state.connected || microphoneUnavailable}+ iconOverlay={state.microphone && !state.capturePending && <svg className="lr-voice-mic-level" viewBox="0 0 24 24" aria-hidden="true">+ <defs><clipPath id={meterId}><rect x="9.7" y="2.7" width="4.6" height="11.6" rx="2.3" /></clipPath></defs>+ <rect x="9.7" y={14.3 - 11.6 * level} width="4.6" height={11.6 * level} clipPath={`url(#${meterId})`} />+ </svg>}+ onClick={() => {+ session.resumeAudio();+ if (state.microphone || state.capturePending) session.stopMicrophone(); else void session.startMicrophone();+ }} />+ </AudioVolumeMenu>+ <AudioVolumeMenu volume={state.listeningVolume} onVolume={volume => session.setListeningVolume(volume)}+ label="voice.listeningVolume" icon="headphones">+ <Btn icon={state.deafened ? "headphonesOff" : "headphones"} title="voice.listening"+ size="compact"+ pressed={!state.deafened} onClick={() => session.deafen(!state.deafened)} />+ </AudioVolumeMenu>+ </div>}+ <Btn icon={!joined ? "headphones" : host ? "stop" : "door"}+ title={actionTitle} cap={actionTitle} tone={joined && host ? "danger" : undefined} size="compact"+ hint={actionHint} hintText={actionExplanation}+ disabled={!state.connected || !state.room || !joined && !host && !state.room.enabled}+ onClick={() => { if (!joined) session.resumeAudio(); session.command({ action: joined ? "leave" : "join" }); }} />+ </div>+ {state.autoplayBlocked && <Btn icon="play" title="voice.play" cap="voice.play" size="compact" hint="hint-local-play" onClick={() => session.resumeAudio()} />}+ {state.error && <p className="lr-voice-control-error" role="alert"><Glyph name="alert" size={16} />+ <span className={vis ? "visually-hidden" : undefined}>{t(`voice.error.${state.error}`)}</span></p>}+ </>;+}++function memberStatus(member: NonNullable<RoomVoiceSnapshot["room"]>["members"][number]): { label: CopyKey; icon: GlyphName } {+ if (!member.connected) return { label: "voice.offline", icon: "wifiOff" };+ if (member.publicationId) return { label: "voice.microphoneActive", icon: "microphone" };+ return member.joined ? { label: "voice.microphoneInactive", icon: "microphoneOff" } : { label: "voice.outside", icon: "door" };+}++// Capture and transport belong to the session above this movable window.+export function RoomVoiceSettings({ session }: Props) {+ const state = useSyncExternalStore(session.subscribe, session.getSnapshot);+ const { t } = useCopy();+ return <div className="lr-floating-scroll lr-interaction-settings lr-voice-settings">+ <MicrophoneSettings host={state.role === "host"} enabled={state.microphone} disabled={state.capturePending}+ loadDevices={session.microphones} deviceId={state.input.deviceId} onDevice={deviceId => void session.configureInput({ deviceId })}+ volume={state.input.volume} onVolume={value => session.setVolume(value)}+ voiceProcessing={state.input.voiceProcessing} onVoiceProcessing={voiceProcessing => void session.configureInput({ voiceProcessing })} />+ <div className="lr-door-group lr-audio-settings" role="group" aria-label={t("voice.listening")}>+ <AudioVolumeControl volume={state.listeningVolume} onVolume={value => session.setListeningVolume(value)}+ label="voice.listeningVolume" icon="headphones" hint="hint-volume" hintText="voice.listeningVolumeHint" />+ </div>+ </div>;+}++export function RoomVoicePanel({ session, names, onSelectParticipant }: Props & {+ names?: ReadonlyMap<string, string>;+ onSelectParticipant?: (peerId: string, trigger: HTMLButtonElement) => void;+}) {+ const state = useSyncExternalStore(session.subscribe, session.getSnapshot);+ const { t, vis } = useCopy();+ const me = state.room?.members.find(member => member.peerId === state.peerId);+ const levels = useVoiceLevels(session, Boolean(me?.joined));+ const members = labelParticipantNames((state.room?.members ?? []).map(member => ({+ ...member, displayName: names?.get(member.peerId) ?? t("voice.participant"),+ })));+ return <div className="lr-room-voice">+ <div className="lr-voice-panel-heading">+ <span>{vis && <Glyph name="users" size={16} />}+ <span className={vis ? "visually-hidden" : undefined}>{t("voice.participants")}</span></span>+ </div>+ {!vis && state.role === "viewer" && !state.room?.enabled && <p className="lr-voice-hint">{t("voice.closedHint")}</p>}+ {state.room?.unavailable.length ? <p className="lr-voice-hint" role="status"><Glyph name="network" size={16} />+ <span className={vis ? "visually-hidden" : undefined}>{t("voice.unavailable")}</span></p> : null}+ {!state.connected && <p className="lr-voice-hint" role="status"><Glyph name="network" size={16} />+ <span className={vis ? "visually-hidden" : undefined}>{t("voice.reconnecting")}</span></p>}+ <div className="lr-voice-members">+ {members.map(member => {+ const status = memberStatus(member);+ const speaking = !!member.publicationId && (levels.get(member.peerId) ?? 0) > .01;+ return <article className="lr-voice-member" key={member.peerId} data-room-peer={member.peerId}>+ <div className="lr-voice-identity">+ {onSelectParticipant && member.connected ? <Tooltip kind="hint-reaction-picker"+ text={vis ? undefined : t("interaction.withPerson", { name: member.label })}>+ <button type="button" className="lr-voice-avatar"+ aria-label={t("interaction.withPerson", { name: member.label })}+ onClick={event => onSelectParticipant(member.peerId, event.currentTarget)}>+ <PawnSvg color={participantColor(member.peerId)} identity={member.peerId} host={member.peerId === state.room?.hostPeerId} />+ </button></Tooltip> : <PawnSvg color={participantColor(member.peerId)} identity={member.peerId} host={member.peerId === state.room?.hostPeerId} />}+ <div><Tooltip overflow={{ text: member.label, selector: ".lr-voice-name" }}><b><span className="lr-voice-name">{member.label}</span>{member.peerId === state.peerId && <span className={vis ? "visually-hidden" : undefined}>{` · ${t("voice.self")}`}</span>}</b></Tooltip>+ <small><Glyph name={status.icon} size={14} />+ <span className="lr-voice-activity" data-speaking={speaking || undefined} aria-hidden="true" />+ <span className={vis ? "visually-hidden" : undefined}>{t(status.label)}</span>+ {speaking && <span className="visually-hidden">{t("voice.speaking")}</span>}</small></div>+ </div>+ {member.peerId !== state.peerId && me?.joined && member.joined && <div className="lr-voice-member-controls">+ <span className="lr-voice-person-volume" aria-hidden="true">{Math.round((state.peerVolumes.get(member.peerId) ?? 1) * 100)}%</span>+ <AudioVolumeMenu volume={state.peerVolumes.get(member.peerId) ?? 1} onVolume={volume => session.setPeerVolume(member.peerId, volume)}+ label="voice.personVolume" icon="speaker" heading={member.label}>+ <Btn icon={state.muted.has(member.peerId) ? "speakerOff" : "speaker"} size="dense"+ title="voice.listenPerson"+ pressed={!state.muted.has(member.peerId)} onClick={() => session.muteVoice(member.peerId)} />+ </AudioVolumeMenu>+ </div>}+ </article>;+ })}+ </div>+ {vis && <span className="visually-hidden">{t("interaction.voice")}</span>}+ </div>;+}diff --git a/src/client/room-voice/browser-endpoint.ts b/src/client/room-voice/browser-endpoint.tsnew file mode 100644index 00000000..b8310a09--- /dev/null+++ b/src/client/room-voice/browser-endpoint.ts@@ -0,0 +1,366 @@+import type { ClientMessage, IceConfig, RoomVoiceState, VoiceConnection, VoiceDescription } from "../../shared/protocol";+import { observeDebugConnection } from "../lib/debug-webrtc";+import { waitForConnectionOperation } from "../webrtc/connection-operation";+import type { MicrophoneInput } from "../media/microphone-input";+import { ViewerAudio } from "../media/viewer-audio";+import { addRemoteIceCandidate, iceServersWithNatPrediction, natPredictionSurveyUrls, NatPredictionCandidateEmitter } from "../webrtc/nat-prediction";++type VoiceSignal = Extract<ClientMessage, { type: "room-voice-signal" }>;+interface Connection {+ config: VoiceConnection;+ pc: RTCPeerConnection;+ lifetime: AbortController;+ candidates: NatPredictionCandidateEmitter;+ queuedCandidates: NonNullable<VoiceSignal["candidate"]>[];+ localCandidates: NonNullable<VoiceSignal["candidate"]>[];+ senders: Map<string, RTCRtpSender>;+ remote: Map<string, string>;+ dirty: boolean;+ requested: boolean;+ descriptionSent: boolean;+ offerRevision: number;+ remoteRevision: number;+ reported: RTCPeerConnectionState | null;+}+interface Received {+ connectionId: string;+ publicationId: string;+ track: MediaStreamTrack;+ audio?: HTMLAudioElement;+ playback?: ViewerAudio;+ blocked: boolean;+}++// One authorized room plan owns these audio transports. This adapter neither+// chooses neighbours nor creates a recovery planner beside the room controller.+export class BrowserVoiceEndpoint {+ private connections = new Map<string, Connection>();+ private received = new Map<string, Received>();+ private source: { publicationId: string; input: MicrophoneInput } | null = null;+ private state: RoomVoiceState | null = null;+ private peerId = "";+ private generation = 0;+ private playbackContext: AudioContext | null = null;+ private listeningVolume = 1;+ private readonly createPlaybackContext = (): AudioContext => this.playbackContext ??= new AudioContext();+ readonly muted = new Set<string>();+ readonly peerVolumes = new Map<string, number>();+ deafened = false;++ constructor(private iceConfig: IceConfig, private readonly send: (message: ClientMessage) => boolean, private readonly changed: () => void) {}++ get microphone(): boolean { return !!this.source; }+ get input(): MicrophoneInput | null { return this.source?.input ?? null; }+ get connected(): boolean {+ const active = this.state?.connections.filter(connection => !connection.pending) ?? [];+ return active.length > 0 && active.every(config => this.connections.get(config.connectionId)?.pc.connectionState === "connected");+ }+ async levels(localOnly = false): Promise<ReadonlyMap<string, number>> {+ const levels = new Map<string, number>();+ if (this.source) levels.set(this.peerId, this.source.input.level());+ if (localOnly) return levels;+ const connections = [...this.connections.values()].filter(connection => !connection.config.pending && connection.pc.connectionState === "connected");+ await Promise.all(connections.map(async connection => {+ const stats = await connection.pc.getStats();+ if (!this.current(connection)) return;+ for (const binding of this.received.values()) {+ if (binding.connectionId !== connection.config.connectionId) continue;+ const publisher = this.state?.publications.find(pub => pub.id === binding.publicationId)?.peerId;+ if (!publisher) continue;+ for (const row of stats.values()) if (row.type === "inbound-rtp" && row.kind === "audio" && row.trackIdentifier === binding.track.id) {+ levels.set(publisher, Math.max(levels.get(publisher) ?? 0, row.audioLevel ?? 0));+ }+ }+ }));+ return levels;+ }+ get autoplayBlocked(): boolean { return !this.deafened && [...this.received.values()].some(binding => binding.blocked); }+ updateIceConfig(config: IceConfig): void { this.iceConfig = config; }++ setAuthority(state: RoomVoiceState | null, peerId: string): void {+ this.state = state; this.peerId = peerId;+ const allowed = new Map(state?.connections.map(config => [config.connectionId, config]));+ for (const [id, connection] of this.connections) {+ const config = allowed.get(id);+ if (!config) this.retire(connection);+ else {+ if (connection.config.send.join() !== config.send.join() || connection.config.receive.join() !== config.receive.join()) connection.dirty = true;+ connection.config = config;+ for (const [publicationId, sender] of connection.senders) if (!config.send.includes(publicationId)) {+ connection.pc.removeTrack(sender); connection.senders.delete(publicationId);+ }+ }+ }+ const me = state?.members.find(member => member.peerId === peerId);+ if (this.source && (!state?.enabled || !me?.joined || !state.publications.some(pub => pub.id === this.source!.publicationId && pub.peerId === peerId))) this.stopMicrophone();+ for (const [key, binding] of this.received) {+ const config = allowed.get(binding.connectionId);+ if (!config?.receive.includes(binding.publicationId)) this.removeReceived(key);+ else if (config.pending && binding.audio) this.removePlayback(binding);+ }+ for (const muted of this.muted) if (!state?.members.some(member => member.peerId === muted)) this.muted.delete(muted);+ for (const peer of this.peerVolumes.keys()) if (!state?.members.some(member => member.peerId === peer)) this.peerVolumes.delete(peer);+ }++ attach(publicationId: string, input: MicrophoneInput): void {+ const me = this.state?.members.find(member => member.peerId === this.peerId);+ if (!this.state?.enabled || !me?.joined || !this.state.publications.some(pub => pub.id === publicationId && pub.peerId === this.peerId)) throw new Error("Microphone publication is not authorized");+ this.stopMicrophone();+ this.source = { publicationId, input };+ }+ stopMicrophone(): void {+ const source = this.source; this.source = null;+ source?.input.close();+ }++ private current(connection: Connection): boolean { return this.connections.get(connection.config.connectionId) === connection && !connection.lifetime.signal.aborted; }+ private wait<T>(connection: Connection, action: () => Promise<T>): Promise<T> { return waitForConnectionOperation(connection.lifetime.signal, action); }+ private isOfferer(config: VoiceConnection): boolean { return config.transport === "peer" && config.parentPeerId === this.peerId; }+ private signal(connection: Connection, values: Omit<VoiceSignal, "type" | "connectionId">): boolean {+ return this.current(connection) && this.send({ type: "room-voice-signal", connectionId: connection.config.connectionId, ...values });+ }+ private report(connection: Connection, state: "connected" | "failed"): void {+ if (connection.reported === state) return;+ if (this.send({ type: "room-voice-transport", connectionId: connection.config.connectionId, state })) connection.reported = state;+ }+ private create(config: VoiceConnection): Connection {+ const prediction = config.transport === "peer" && !!this.iceConfig.natPredictionStunUrls?.length;+ const pc = new RTCPeerConnection({ iceServers: config.transport === "sfu" ? [] : iceServersWithNatPrediction(this.iceConfig.iceServers, prediction, this.iceConfig.natPredictionStunUrls) });+ const connection: Connection = { config, pc, lifetime: new AbortController(),+ candidates: new NatPredictionCandidateEmitter(prediction, candidate => {+ if (!candidate || !this.current(connection) || /\sTCP\s/i.test(candidate.candidate)) return;+ if (connection.localCandidates.length >= 64) { this.report(connection, "failed"); return; }+ connection.localCandidates.push(candidate); this.flushCandidates(connection);+ }, natPredictionSurveyUrls(this.iceConfig.iceServers, this.iceConfig.natPredictionStunUrls)),+ queuedCandidates: [], localCandidates: [], senders: new Map(), remote: new Map(), dirty: this.isOfferer(config),+ requested: false, descriptionSent: false, offerRevision: 0, remoteRevision: 0, reported: null };+ this.connections.set(config.connectionId, connection);+ observeDebugConnection(pc, { connectionId: config.connectionId, role: "room-voice" });+ pc.onicecandidate = event => { if (this.current(connection)) connection.candidates.add(event.candidate); };+ pc.onicegatheringstatechange = () => { if (this.current(connection) && pc.iceGatheringState === "complete") connection.candidates.gatheringComplete(); };+ pc.onnegotiationneeded = () => { if (this.current(connection)) { connection.dirty = true; this.changed(); } };+ pc.ontrack = () => { if (this.current(connection)) { this.bindReceivers(connection); this.changed(); } };+ pc.onconnectionstatechange = () => { if (this.current(connection)) this.changed(); };+ if (this.isOfferer(config)) {+ pc.addTransceiver("audio", { direction: "recvonly" });+ pc.createDataChannel("piik-room-voice");+ }+ return connection;+ }++ private flushCandidates(connection: Connection): void {+ if (!connection.descriptionSent) return;+ while (connection.localCandidates[0] && this.signal(connection, { candidate: connection.localCandidates[0] })) connection.localCandidates.shift();+ }+ private sourceTrack(publicationId: string): MediaStreamTrack | undefined {+ if (this.source?.publicationId === publicationId) return this.source.input.stream.getAudioTracks()[0];+ return [...this.received.values()].find(binding => binding.publicationId === publicationId && this.connections.get(binding.connectionId)?.config.pending === false)?.track;+ }+ private async syncSenders(connection: Connection): Promise<void> {+ const { pc, config } = connection;+ for (const [publicationId, sender] of connection.senders) {+ const track = config.send.includes(publicationId) ? this.sourceTrack(publicationId) : undefined;+ if (!track) {+ await this.wait(connection, () => sender.replaceTrack(null));+ pc.removeTrack(sender); connection.senders.delete(publicationId); connection.dirty = true;+ } else if (sender.track !== track) {+ await this.wait(connection, () => sender.replaceTrack(track));+ if (!connection.config.send.includes(publicationId) || this.sourceTrack(publicationId) !== track) {+ pc.removeTrack(sender); connection.senders.delete(publicationId); connection.dirty = true;+ }+ }+ }+ for (const publicationId of connection.config.send) {+ const track = this.sourceTrack(publicationId);+ if (!track || connection.senders.has(publicationId)) continue;+ const transceiver = pc.getTransceivers().find(item => item.direction !== "stopped" && !item.sender.track &&+ (config.transport !== "sfu" || connection.remote.get(item.mid ?? "") === publicationId));+ if (!transceiver && config.transport === "sfu") continue;+ const stream = new MediaStream([track]);+ const sender = transceiver?.sender ?? pc.addTrack(track, stream);+ if (transceiver) {+ await this.wait(connection, () => sender.replaceTrack(track));+ if (!connection.config.send.includes(publicationId) || this.sourceTrack(publicationId) !== track) { pc.removeTrack(sender); continue; }+ sender.setStreams(stream);+ transceiver.direction = transceiver.direction === "recvonly" || transceiver.direction === "sendrecv" ? "sendrecv" : "sendonly";+ }+ connection.senders.set(publicationId, sender); connection.dirty = true;+ }+ if (this.isOfferer(config)) {+ const receiving = pc.getTransceivers().filter(item => item.direction !== "stopped" && (item.direction === "recvonly" || item.direction === "sendrecv")).length;+ for (let index = receiving; index < config.receive.length; index++) { pc.addTransceiver("audio", { direction: "recvonly" }); connection.dirty = true; }+ }+ }++ private removePlayback(binding: Received): void {+ if (binding.audio) {+ binding.audio.pause(); binding.playback?.dispose(); binding.playback = undefined;+ binding.audio.srcObject = null; binding.audio.remove(); binding.audio = undefined;+ }+ if (![...this.received.values()].some(received => received.playback)) {+ const context = this.playbackContext; this.playbackContext = null;+ if (context) void context.close().catch(() => {});+ }+ binding.blocked = false;+ }+ private removeReceived(key: string): void {+ const binding = this.received.get(key);+ if (binding) this.removePlayback(binding);+ this.received.delete(key);+ }+ private bindReceivers(connection: Connection): void {+ const retained = new Set<string>();+ for (const transceiver of connection.pc.getTransceivers()) {+ const publicationId = connection.remote.get(transceiver.mid ?? ""), track = transceiver.receiver.track;+ if (!publicationId || !connection.config.receive.includes(publicationId) || track.kind !== "audio" || track.readyState === "ended") continue;+ const key = `${connection.config.connectionId}/${publicationId}`;+ retained.add(key);+ let binding = this.received.get(key);+ if (binding?.track !== track) {+ this.removeReceived(key);+ binding = { connectionId: connection.config.connectionId, publicationId, track, blocked: false };+ this.received.set(key, binding);+ }+ if (!connection.config.pending && !binding.audio) {+ const audio = binding.audio = new Audio();+ audio.autoplay = true; audio.hidden = true;+ const stream = new MediaStream([track]);+ audio.srcObject = stream;+ // Independent 0–200% master and person controls compose to at most 4×.+ binding.playback = new ViewerAudio(audio, () => {}, this.createPlaybackContext, 4);+ binding.playback.bind(stream);+ this.syncPlayback();+ document.body.append(audio);+ void this.play(binding);+ }+ }+ for (const [key, binding] of this.received) if (binding.connectionId === connection.config.connectionId && !retained.has(key)) this.removeReceived(key);+ }+ private async play(binding: Received): Promise<void> {+ const audio = binding.audio;+ if (!audio) return;+ binding.playback?.resume();+ try { await audio.play(); if (binding.audio !== audio) return; binding.blocked = false; }+ catch { if (binding.audio !== audio) return; binding.blocked = true; }+ this.changed();+ }+ async resume(): Promise<void> { await Promise.all([...this.received.values()].map(binding => this.play(binding))); }+ mute(peerId: string, muted: boolean): void {+ if (muted) this.muted.add(peerId); else this.muted.delete(peerId);+ this.syncPlayback();+ }+ deafen(deafened: boolean): void {+ this.deafened = deafened;+ this.syncPlayback();+ }+ setListeningVolume(volume: number): void {+ this.listeningVolume = volume;+ this.syncPlayback();+ }+ setPeerVolume(peerId: string, volume: number): void {+ if (volume === 1) this.peerVolumes.delete(peerId); else this.peerVolumes.set(peerId, volume);+ this.syncPlayback();+ }+ private syncPlayback(): void {+ for (const binding of this.received.values()) if (binding.playback) {+ const publisher = this.state?.publications.find(pub => pub.id === binding.publicationId)?.peerId;+ binding.playback.setMuted(this.deafened || !!publisher && this.muted.has(publisher));+ binding.playback.setLevel(this.listeningVolume * (publisher ? this.peerVolumes.get(publisher) ?? 1 : 1));+ }+ }++ private async description(connection: Connection, sdp: RTCSessionDescriptionInit, revision: number): Promise<VoiceDescription> {+ connection.descriptionSent = false;+ await this.wait(connection, () => connection.pc.setLocalDescription(sdp));+ const local = connection.pc.localDescription!;+ const tracks: VoiceDescription["tracks"] = [];+ for (const [publicationId, sender] of connection.senders) {+ const mid = connection.pc.getTransceivers().find(item => item.sender === sender)?.mid;+ if (mid === null || mid === undefined || !connection.config.send.includes(publicationId)) continue;+ tracks.push({ mid, publicationId });+ const parameters = sender.getParameters();+ if (parameters.encodings.length) { parameters.encodings[0]!.maxBitrate = 32_000; await this.wait(connection, () => sender.setParameters(parameters)); }+ }+ return { revision, sdp: { type: local.type as "offer" | "answer", sdp: local.sdp }, tracks };+ }+ private sendDescription(connection: Connection, description: VoiceDescription): void {+ if (!this.signal(connection, { description })) throw new Error("Voice signaling unavailable");+ connection.descriptionSent = true; this.flushCandidates(connection);+ }++ async reconcile(): Promise<void> {+ const generation = this.generation;+ for (const config of this.state?.connections ?? []) {+ if (generation !== this.generation) return;+ const connection = this.connections.get(config.connectionId) ?? this.create(config);+ try {+ await this.syncSenders(connection);+ this.bindReceivers(connection);+ if (connection.pc.connectionState === "connected") this.report(connection, "connected");+ else if (connection.pc.connectionState === "failed" || connection.pc.connectionState === "closed") { this.report(connection, "failed"); continue; }+ if (!connection.dirty || connection.pc.signalingState !== "stable") continue;+ if (this.isOfferer(config)) {+ connection.dirty = false;+ const offer = await this.wait(connection, () => connection.pc.createOffer());+ this.sendDescription(connection, await this.description(connection, offer, ++connection.offerRevision));+ } else if (!connection.requested) {+ if (this.signal(connection, { renegotiate: true })) connection.requested = true;+ }+ } catch (error) { if (this.current(connection)) { this.report(connection, "failed"); throw error; } }+ }+ }++ async receive(message: Extract<ClientMessage, { type: "room-voice-signal" }>): Promise<void> {+ const connection = this.connections.get(message.connectionId);+ if (!connection) return;+ try { await this.receiveSignal(connection, message); }+ catch (error) { if (this.current(connection)) { this.report(connection, "failed"); throw error; } }+ }+ private async receiveSignal(connection: Connection, message: VoiceSignal): Promise<void> {+ if (message.renegotiate) { if (this.isOfferer(connection.config)) connection.dirty = true; return; }+ if (message.candidate) {+ if (connection.pc.remoteDescription) await this.wait(connection, () => addRemoteIceCandidate(connection.pc, message.candidate!));+ else if (connection.queuedCandidates.length < 64) connection.queuedCandidates.push(message.candidate);+ else throw new Error("Too many voice ICE candidates");+ return;+ }+ const description = message.description;+ if (!description) return;+ const offer = description.sdp.type === "offer";+ if (offer === this.isOfferer(connection.config) || description.revision <= connection.remoteRevision ||+ (!offer && (description.revision !== connection.offerRevision || connection.pc.signalingState !== "have-local-offer"))) return;+ const mids = new Set<string>();+ const publications = new Set<string>();+ const allowed = connection.config.transport === "sfu" && offer ? [...connection.config.send, ...connection.config.receive] : connection.config.receive;+ for (const track of description.tracks) {+ if (mids.has(track.mid) || publications.has(track.publicationId)) throw new Error("Duplicate voice track mapping");+ mids.add(track.mid); publications.add(track.publicationId);+ }+ await this.wait(connection, () => connection.pc.setRemoteDescription(description.sdp));+ // A newer authority state can retire a source while its SDP is in flight.+ // Complete transport negotiation, but never bind from the manifest alone.+ connection.remote = new Map(description.tracks.filter(track => allowed.includes(track.publicationId)).map(track => [track.mid, track.publicationId]));+ connection.remoteRevision = description.revision;+ for (const candidate of connection.queuedCandidates.splice(0)) await this.wait(connection, () => addRemoteIceCandidate(connection.pc, candidate));+ this.bindReceivers(connection);+ if (offer) {+ connection.requested = false;+ await this.syncSenders(connection);+ connection.dirty = false;+ const answer = await this.wait(connection, () => connection.pc.createAnswer());+ this.sendDescription(connection, await this.description(connection, answer, description.revision));+ }+ }++ private retire(connection: Connection): void {+ this.connections.delete(connection.config.connectionId);+ connection.lifetime.abort(); connection.candidates.discard(); connection.pc.close();+ for (const [key, binding] of this.received) if (binding.connectionId === connection.config.connectionId) this.removeReceived(key);+ }+ close(): void {+ this.generation++;+ this.state = null; this.stopMicrophone();+ for (const connection of this.connections.values()) this.retire(connection);+ for (const key of this.received.keys()) this.removeReceived(key);+ }+}diff --git a/src/client/room-voice/room-voice.css b/src/client/room-voice/room-voice.cssnew file mode 100644index 00000000..ebf7bafe--- /dev/null+++ b/src/client/room-voice/room-voice.css@@ -0,0 +1,28 @@+.lr-room-voice { padding-block: 14px 4px; }+.lr-voice-settings { display: grid; align-content: start; gap: 16px; }+.lr-voice-panel-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }+.lr-voice-mic-level { position: absolute; left: 50%; top: 50%; width: var(--control-icon-size); height: var(--control-icon-size); transform: translate(-50%, -50%); pointer-events: none; fill: var(--live); }+.lr-voice-activity { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--control-edge); transition: background-color 140ms ease, box-shadow 140ms ease; }+.lr-voice-activity[data-speaking] { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 15%, transparent); }+.lr-voice-hint { display: flex; align-items: flex-start; gap: 6px; margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.7; }+.lr-voice-hint > svg, .lr-voice-control-error > svg { flex: none; margin-top: 2px; }+.lr-voice-member { display: flex; align-items: center; gap: 10px; padding-block: 12px; border-bottom: 1px solid var(--control-edge); }+.lr-voice-member:last-child { border-bottom: 0; }+.lr-voice-identity { display: flex; flex: 1; min-width: 0; align-items: center; gap: 10px; }+.lr-voice-identity > svg { flex: none; width: 28px; height: 34px; }+.lr-voice-avatar { display: grid; place-items: center; flex: none; width: var(--control-compact-size); height: var(--control-compact-size); padding: 0; border: 0; border-radius: 12px; background: transparent; color: inherit; cursor: pointer; transition: background-color 140ms ease; }+.lr-voice-avatar:is(:hover, :focus-visible) { background: var(--control-hover); }+.lr-voice-avatar:focus-visible { outline-offset: -3px; }+.lr-voice-avatar > svg { width: 28px; height: 34px; }+.lr-voice-identity > div { min-width: 0; }+.lr-voice-identity b { display: flex; font-size: 13px; white-space: nowrap; }+.lr-voice-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }+.lr-voice-name + span { flex: none; }+.lr-voice-identity small { display: flex; align-items: center; gap: 5px; margin-top: 3px; color: var(--muted); font-size: 12px; }+.lr-voice-identity small > svg { flex: none; }+.lr-voice-member-controls { display: flex; flex: none; gap: 6px; align-items: center; }+.lr-voice-person-volume { min-width: 4ch; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }+.lr-voice-control-error { display: flex; flex-basis: 100%; gap: 6px; align-items: flex-start; margin: 0; color: var(--danger); font-size: 12px; line-height: 1.7; }+.lr-voice-toolbar { display: flex; flex: 1; align-items: center; gap: 6px; min-width: 0; }+.lr-voice-toolbar > .lr-comic-tip-wrap { flex: none; margin-left: auto; }+.lr-voice-quick-controls { display: flex; flex: none; gap: 6px; align-items: center; }diff --git a/src/client/room-voice/session.ts b/src/client/room-voice/session.tsnew file mode 100644index 00000000..25311c5c--- /dev/null+++ b/src/client/room-voice/session.ts@@ -0,0 +1,220 @@+import type { ClientMessage, IceConfig, RoomVoiceCommand, RoomVoiceState, ServerMessage } from "../../shared/protocol";+import { audioInputConstraints } from "../media/audio-capture";+import { debugError } from "../lib/debug";+import { BrowserVoiceEndpoint } from "./browser-endpoint";+import { MicrophoneInput } from "../media/microphone-input";+import { browserCaptureDevices } from "../media/capture-devices";+import { readRoomPreferences, saveRoomPreferences, type RoomPreferences } from "../lib/room-preferences";++export type RoomVoiceError = "microphoneUnavailable" | "microphoneDenied" | "microphoneMissing" | "microphoneFailed" | "transport" | "rejected" | "closed";+export interface RoomVoiceSnapshot {+ peerId: string;+ role: "host" | "viewer";+ connected: boolean;+ room: RoomVoiceState | null;+ capturePending: boolean;+ microphone: boolean;+ deafened: boolean;+ autoplayBlocked: boolean;+ muted: ReadonlySet<string>;+ error: RoomVoiceError | null;+ input: RoomPreferences["voiceInput"];+ listeningVolume: number;+ peerVolumes: ReadonlyMap<string, number>;+}+interface CaptureRequest { input?: MicrophoneInput; context?: AudioContext; settings: RoomPreferences["voiceInput"] }++// One normal room signaling session owns voice. Sharing/capture generations do+// not enter this lifetime, and joining never starts microphone capture.+export class RoomVoiceSession {+ readonly endpoint: BrowserVoiceEndpoint;+ private listeners = new Set<() => void>();+ private state: RoomVoiceSnapshot = { peerId: "", role: "viewer", connected: false, room: null,+ capturePending: false, microphone: false, deafened: false, autoplayBlocked: false, muted: new Set(), error: null,+ input: readRoomPreferences().voiceInput, listeningVolume: readRoomPreferences().voiceListeningVolume, peerVolumes: new Map() };+ private capture: CaptureRequest | null = null;+ private publishing: CaptureRequest | null = null;+ private retiredPublications = new Set<string>();+ private serial = Promise.resolve();+ private scheduled = false;+ private closed = false;+ private epoch = 0;++ constructor(private readonly send: (message: ClientMessage) => boolean, iceConfig: IceConfig) {+ this.endpoint = new BrowserVoiceEndpoint(iceConfig, message => this.state.connected && this.send(message), () => {+ this.refresh(); this.schedule();+ });+ this.endpoint.setListeningVolume(this.state.listeningVolume);+ }+ getSnapshot = (): RoomVoiceSnapshot => this.state;+ subscribe = (listener: () => void): (() => void) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };+ get microphone(): boolean { return this.endpoint.microphone; }+ activity = (localOnly = false): Promise<ReadonlyMap<string, number>> => this.endpoint.levels(localOnly);+ microphones = () => browserCaptureDevices("audioinput");+ private update(patch: Partial<RoomVoiceSnapshot>): void {+ this.state = { ...this.state, ...patch };+ this.listeners.forEach(listener => listener());+ }+ private refresh(): void {+ this.update({ microphone: this.endpoint.microphone, capturePending: !!this.capture || !!this.publishing,+ deafened: this.endpoint.deafened, autoplayBlocked: this.endpoint.autoplayBlocked, muted: new Set(this.endpoint.muted),+ peerVolumes: new Map(this.endpoint.peerVolumes),+ ...(this.state.error === "transport" && !this.state.room?.unavailable.length && this.endpoint.connected ? { error: null } : {}) });+ }+ updateIceConfig(config: IceConfig): void { this.endpoint.updateIceConfig(config); }+ authenticated(peerId: string, role: "host" | "viewer"): void {+ if (this.closed) return;+ this.disconnected();+ this.update({ peerId, role, connected: true, room: null, error: null });+ }+ private enqueue(action: () => Promise<void>): void {+ const epoch = this.epoch;+ this.serial = this.serial.then(async () => {+ if (!this.closed && this.state.connected && epoch === this.epoch) await action();+ }).catch(error => {+ if (!this.closed && this.state.connected && epoch === this.epoch) {+ debugError("room-voice", "transport-failed", error);+ this.update({ error: "transport" });+ }+ });+ }+ private schedule(): void {+ if (this.scheduled || this.closed || !this.state.connected) return;+ this.scheduled = true;+ this.enqueue(async () => { this.scheduled = false; await this.endpoint.reconcile(); this.refresh(); });+ }+ receive(message: ServerMessage): boolean {+ if (this.closed || !["room-voice-state", "room-voice-signal", "room-voice-error"].includes(message.type)) return false;+ if (!this.state.connected) return true;+ if (message.type === "room-voice-state") {+ if (message.revision < (this.state.room?.revision ?? 0)) return true;+ const me = message.members.find(member => member.peerId === this.state.peerId);+ if (!message.enabled || !me?.joined) { this.cancelCapture(); this.publishing = null; }+ this.update({ room: message, ...(!message.enabled || this.state.error === "closed" ? { error: null } : {}) });+ // Authority retirement is synchronous even if an SDP operation is pending.+ this.endpoint.setAuthority(message, this.state.peerId);+ const publication = message.publications.find(pub => pub.peerId === this.state.peerId);+ if (publication && this.publishing) {+ const request = this.publishing; this.publishing = null;+ if (this.capture === request && request.input && message.enabled && me?.joined) {+ if (request.input.stream.getAudioTracks()[0]?.readyState === "live") {+ this.endpoint.attach(publication.id, request.input);+ this.rememberInput(request.settings);+ this.capture = null;+ } else this.cancelCapture();+ }+ }+ // A cancelled or former page's publication cannot revive a microphone.+ if (publication && !this.endpoint.microphone && !this.publishing && !this.retiredPublications.has(publication.id)) {+ this.retiredPublications.add(publication.id);+ this.command({ action: "unpublish", publicationId: publication.id });+ }+ for (const id of this.retiredPublications) if (!message.publications.some(pub => pub.id === id)) this.retiredPublications.delete(id);+ this.refresh(); this.schedule();+ } else if (message.type === "room-voice-signal") {+ this.enqueue(async () => { await this.endpoint.receive(message); await this.endpoint.reconcile(); this.refresh(); });+ } else if (message.type === "room-voice-error") {+ if (message.code === "not-allowed") { this.cancelCapture(); this.publishing = null; }+ this.update({ error: message.code === "connection-unavailable" ? "transport" : message.code === "not-enabled" ? "closed" : "rejected" });+ this.refresh();+ }+ return true;+ }+ command(command: RoomVoiceCommand): boolean {+ if (this.closed || !this.state.connected) return false;+ if (command.action === "leave") this.stopMicrophone();+ this.update({ error: null });+ if (this.send({ type: "room-voice-command", command })) return true;+ this.update({ error: "transport" }); return false;+ }+ private cancelCapture(): void {+ const request = this.capture; this.capture = null;+ request?.input?.close();+ if (request?.context) void request.context.close().catch(() => {});+ }+ private rememberInput(input: RoomPreferences["voiceInput"]): void {+ this.update({ input }); saveRoomPreferences({ voiceInput: input });+ }+ setVolume(volume: number): void {+ this.endpoint.input?.volume(volume); this.capture?.input?.volume(volume);+ if (this.capture) this.capture.settings.volume = volume;+ this.rememberInput({ ...this.state.input, volume });+ }+ setListeningVolume(volume: number): void {+ this.endpoint.setListeningVolume(volume);+ this.update({ listeningVolume: volume }); saveRoomPreferences({ voiceListeningVolume: volume });+ }+ setPeerVolume(peerId: string, volume: number): void { this.endpoint.setPeerVolume(peerId, volume); this.refresh(); }+ async configureInput(patch: Partial<Pick<RoomPreferences["voiceInput"], "deviceId" | "voiceProcessing">>): Promise<void> {+ const settings = { ...this.state.input, ...patch };+ if (this.microphone) await this.startMicrophone(settings);+ else this.rememberInput(settings);+ }+ async startMicrophone(settings = this.state.input): Promise<void> {+ const me = this.state.room?.members.find(member => member.peerId === this.state.peerId);+ if (this.closed || !this.state.connected || !this.state.room?.enabled || !me?.joined || this.capture || this.publishing) return;+ if (!navigator.mediaDevices?.getUserMedia) {+ this.update({ error: "microphoneUnavailable" }); return;+ }+ const request: CaptureRequest = { settings: { ...settings } }; this.capture = request;+ this.update({ error: null }); this.refresh();+ let stream: MediaStream | undefined;+ try {+ // Resume during the gesture, before a device-permission prompt can consume+ // user activation. The capture owns this context until input takes it over.+ const context = request.context = new AudioContext();+ const resumed = context.resume().then(() => true, () => false);+ // Device permission must never block the serialized SDP/authority queue.+ stream = await navigator.mediaDevices.getUserMedia({ audio: { ...audioInputConstraints(settings.voiceProcessing),+ channelCount: 1, ...(settings.deviceId ? { deviceId: { exact: settings.deviceId } } : {}) }, video: false });+ if (this.capture !== request) return;+ const track = stream.getAudioTracks()[0];+ if (!track || track.readyState !== "live") throw new DOMException("No live microphone", "NotFoundError");+ const input = request.input = new MicrophoneInput(stream, context, request.settings.volume, () => {+ if (this.endpoint.input === input || this.capture === request) this.stopMicrophone();+ });+ request.context = undefined;+ if (!await resumed) throw new Error("Microphone audio context could not start");+ if (this.capture !== request) return;+ const publication = this.state.room?.publications.find(pub => pub.peerId === this.state.peerId);+ if (publication && this.microphone) {+ this.endpoint.attach(publication.id, input); this.capture = null;+ this.rememberInput(request.settings); this.schedule(); return;+ }+ this.publishing = request;+ if (!this.command({ action: "publish" })) { this.publishing = null; this.cancelCapture(); }+ } catch (error) {+ if (this.capture === request) {+ this.cancelCapture(); this.publishing = null;+ const name = error instanceof Error ? error.name : "";+ this.update({ error: name === "NotAllowedError" ? "microphoneDenied" : name === "NotFoundError" ? "microphoneMissing" : "microphoneFailed" });+ }+ } finally {+ if (!request.input) stream?.getTracks().forEach(track => track.stop());+ this.refresh();+ }+ }+ stopMicrophone(): void {+ this.cancelCapture(); this.endpoint.stopMicrophone();+ const publication = this.state.room?.publications.find(pub => pub.peerId === this.state.peerId);+ if (publication && !this.retiredPublications.has(publication.id)) {+ this.retiredPublications.add(publication.id);+ this.command({ action: "unpublish", publicationId: publication.id });+ }+ this.refresh(); this.schedule();+ }+ muteVoice(peerId: string): void { this.endpoint.mute(peerId, !this.endpoint.muted.has(peerId)); this.refresh(); }+ deafen(deafened: boolean): void {+ this.endpoint.deafen(deafened);+ if (!deafened) this.resumeAudio();+ this.refresh();+ }+ resumeAudio(): void { void this.endpoint.resume(); }+ disconnected(): void {+ this.epoch++;+ this.cancelCapture(); this.publishing = null; this.endpoint.close();+ this.retiredPublications.clear(); this.scheduled = false;+ this.update({ connected: false, capturePending: false, microphone: false, autoplayBlocked: false });+ }+ close(): void { if (!this.closed) { this.disconnected(); this.closed = true; this.update({ room: null, peerId: "" }); } }+}diff --git a/src/client/styles.css b/src/client/styles.cssindex e7ed0e15..c86e3549 100644--- a/src/client/styles.css+++ b/src/client/styles.css@@ -116,7 +116,7 @@ ul { margin: 0; padding: 0; list-style: none; }.lr-top-right { display: inline-flex; gap: 10px; align-items: center; }.lr-top > .lr-top-right { margin-left: auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }-/* LED state strip */+/* Discrete signaling state, independent of picture quality. */.lr-leds {display: inline-flex;gap: 7px;@@ -127,21 +127,22 @@ ul { margin: 0; padding: 0; list-style: none; }background: var(--wall-2);}.lr-leds i {- width: 9px; height: 9px;- border-radius: 50%;+ width: 6px; height: 5px;+ border-radius: 2px;background: color-mix(in srgb, var(--ink) 58%, var(--wall-2));transition: background 300ms ease;}-.lr-leds[data-state="live"] i { background: color-mix(in srgb, var(--live) 80%, var(--ink)); opacity: .35; }-.lr-leds[data-state="live"] i:first-child { opacity: 1; animation: lr-led-beat 2.8s ease-in-out infinite; }-.lr-leds[data-state="busy"] i { animation: lr-led-chase 1s ease-in-out infinite; background: var(--busy); }+.lr-connection-bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 15px; }+.lr-connection-bars i:nth-child(2) { height: 9px; }+.lr-connection-bars i:nth-child(3) { height: 13px; }+.lr-leds[data-state="live"] i { background: var(--live); }+.lr-leds[data-state="busy"] i:nth-child(-n+2) { animation: lr-led-chase 1s ease-in-out infinite; background: var(--warn); }.lr-leds[data-state="busy"] i:nth-child(2) { animation-delay: .15s; }-.lr-leds[data-state="busy"] i:nth-child(3) { animation-delay: .3s; }-.lr-leds[data-state="warn"] i { background: color-mix(in srgb, var(--warn) 72%, var(--ink)); animation: lr-led-beat 1.1s ease-in-out infinite; }-.lr-leds[data-state="bad"] i { background: var(--danger); }+.lr-leds[data-state="warn"] i:nth-child(-n+2) { background: var(--warn); animation: lr-led-beat 1.1s ease-in-out infinite; }+.lr-leds[data-state="bad"] i:first-child { background: var(--danger); }.lr-leds-label { margin-left: 4px; font-size: 11.5px; font-weight: 700; opacity: .8; white-space: nowrap; }-/* Informative dots retain contrast throughout their small status gesture. */+/* Informative bars retain contrast throughout their small status gesture. */@keyframes lr-led-beat { 50% { transform: scale(.8); } }@keyframes lr-led-chase { 50% { transform: translateY(-2px); } }@@ -798,7 +799,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }:is(.lr-host-summary-row, .lr-viewer-summary-row):has(.lr-group-name > [role="alert"]) { align-items: flex-start; }.lr-viewer-room-slot { flex: 0 0 auto; }.lr-viewer-host-slot {- flex: 0 1 auto;+ flex: 1 1 96px;min-width: 0;max-width: 180px;min-height: 52px;@@ -816,7 +817,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }}.lr-viewer-self-slot {display: flex;- flex: 0 0 auto;+ flex: 0 1 auto;align-items: center;gap: 8px;margin-left: 0;@@ -894,12 +895,15 @@ body.lr-theater-open .lr-top { visibility: hidden; }text-indent: .15em;}.lr-lcd.is-empty { border-style: dashed; border-color: var(--control-edge); background: var(--wall-2); color: var(--muted); }-.lr-lcd button, .lr-lcd-copy-placeholder {+.lr-lcd.is-create { transition: var(--control-motion), background-color 140ms ease, border-color 140ms ease; }+.lr-lcd.is-create:is(:hover, :focus-visible):not(:disabled) { background: var(--control-hover); border-color: var(--ink); color: var(--ink); transform: var(--control-hover-transform); }+.lr-lcd.is-create:active:not(:disabled) { transform: var(--control-press-transform); transition-duration: 80ms; }+.lr-lcd button, .lr-lcd-action {display: grid;width: 34px; height: 34px;place-items: center;}-.lr-lcd-copy-placeholder { opacity: .45; }+.lr-lcd.is-empty:not(.is-create) .lr-lcd-action { opacity: .45; }.lr-lcd button {border: 0;border-radius: 8px;@@ -1123,7 +1127,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }height: 40px;border-radius: 999px;}-.lr-group-name { width: 280px; max-width: 100%; }+.lr-group-name { width: 224px; max-width: 100%; }.lr-group-name > [role="alert"] { flex-basis: 100%; }.lr-group-name > .lr-name-hint { flex: 1; width: 0; }.lr-group-name .lr-name-tag { width: 100%; }@@ -1712,7 +1716,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }.lr-meter-cell { justify-content: flex-start; }.lr-group-name .lr-name-tag { flex: 1; }.lr-viewer-self-slot .lr-name-tag { flex: 0 1 auto; }- .lr-toggle { flex: 1; }+ .lr-row-group > .lr-toggle { flex: 1; }.lr-invite-hint, .lr-invite-url { flex: 0 1 auto; max-width: none; min-height: 44px; }.lr-invite-field { flex: none; width: 100%; }.lr-door-body { padding: 12px; }@@ -1768,10 +1772,8 @@ body.lr-theater-open .lr-top { visibility: hidden; }.lr-sharing-section .lr-row-group { gap: 8px; }.lr-sharing-section .lr-chip { min-height: 40px; padding: 7px 12px; }.lr-sharing-audio-controls { display: grid; gap: 20px; min-width: 0; }-.lr-sharing-audio-controls:has(> .lr-source-audio-settings):has(> .lr-microphone-settings) { grid-template-columns: repeat(2, minmax(0, 1fr)); }.lr-sharing-audio-controls > .lr-audio-quality { grid-column: 1 / -1; }.lr-sharing-audio-controls > .lr-audio-quality:not(:first-child) { padding-top: 18px; border-top: 1px solid var(--wall-2); }-.lr-sharing-panel .lr-microphone-settings { max-width: none; }.lr-sharing-panel input[type="range"] { appearance: none; background: transparent; }.lr-sharing-panel input[type="range"]:disabled { opacity: .55; cursor: default; }.lr-sharing-panel input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: linear-gradient(to right, var(--action) var(--range-fill), var(--wall-2) var(--range-fill)); }@@ -1796,7 +1798,7 @@ details[open] > summary > .lr-sharing-chevron { transform: rotate(180deg); }@media (prefers-reduced-motion: reduce) { .lr-sharing-panel { animation: none; } .lr-sharing-chevron { transition: none; } }@container sharing-settings (max-width: 600px) {.lr-sharing-panel { padding: 16px; border-radius: 20px; }- .lr-sharing-limits, .lr-sharing-audio-controls:has(> .lr-source-audio-settings):has(> .lr-microphone-settings),+ .lr-sharing-limits,.lr-sharing-connection .lr-row-group:has(.lr-switch-item) { grid-template-columns: 1fr; gap: 20px; }.lr-sharing-section .lr-tiles { gap: 8px; }.lr-sharing-section .lr-tile { padding: 10px 4px; }@@ -1826,18 +1828,22 @@ details[open] > summary > .lr-sharing-chevron { transform: rotate(180deg); }.lr-host-action-dock + .lr-host-tool-dock { padding-inline-start: 8px; border-inline-start: 1px solid var(--control-edge); }.lr-host-control-group { display: flex; align-items: center; gap: 4px; }.lr-host-control-group + .lr-host-control-group { padding-inline-start: 4px; }-.lr-microphone-settings { min-width: 0; max-width: 440px; gap: 6px; }-.lr-microphone-settings .lr-capture-device { padding: 0; }+.lr-audio-settings { min-width: 0; max-width: 440px; gap: 6px; }+.lr-audio-volume-menu { display: inline-flex; flex: none; }+.lr-audio-volume-popover { position: fixed; inset: auto; margin: 0; width: 224px; padding: 12px; border-radius: 16px; }+.lr-audio-volume-popover:is(:popover-open, .\:popover-open) { display: grid; }+.lr-audio-volume-popover > b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }+.lr-audio-settings .lr-capture-device { padding: 0; }.lr-source-audio-settings .lr-capture-device { padding: 0; }.lr-audio-exclusion-select label { display: flex; align-items: center; gap: 6px; cursor: default; }-.lr-microphone-settings > label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }-.lr-microphone-settings > .lr-comic-tip-wrap { display: flex; width: 100%; }-.lr-microphone-settings input { width: 100%; min-width: 32px; height: 36px; padding: 0; accent-color: var(--action); cursor: pointer; }-.lr-microphone-settings input:disabled { cursor: default; }-.lr-microphone-settings output { min-width: 4ch; font-variant-numeric: tabular-nums; text-align: right; }-.lr-microphone-settings .lr-switch-item .lr-cap { white-space: normal; }+.lr-audio-settings > label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }+.lr-audio-settings > .lr-comic-tip-wrap { display: flex; width: 100%; }+.lr-audio-settings input { width: 100%; min-width: 32px; height: 36px; padding: 0; accent-color: var(--action); cursor: pointer; }+.lr-audio-settings input:disabled { cursor: default; }+.lr-audio-settings output { min-width: 4ch; font-variant-numeric: tabular-nums; text-align: right; }+.lr-audio-settings .lr-switch-item .lr-cap { white-space: normal; }.lr-capture-device { display: grid; gap: 6px; min-width: 0; padding: 4px 10px 10px; }-.lr-capture-device label { font-size: 12px; padding: 0; color: var(--muted); }+.lr-capture-device label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 0; color: var(--muted); }.lr-capture-device-controls { display: flex; align-items: center; gap: 6px; min-width: 0; }.lr-capture-device select {flex: 1; min-width: 0; width: 100%; min-height: 40px; padding: 8px 12px;@@ -1849,7 +1855,7 @@ details[open] > summary > .lr-sharing-chevron { transform: rotate(180deg); }.lr-capture-device .lr-device-refresh { min-width: 40px; width: 40px; height: 40px; padding: 0; border-width: 1px; }.lr-capture-device select:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }.lr-capture-device select:disabled { opacity: .55; cursor: default; }-.lr-capture-device small, .lr-microphone-settings > small { color: var(--muted); font-size: 11px; line-height: 1.5; }+.lr-capture-device small, .lr-audio-settings > small { color: var(--muted); font-size: 11px; line-height: 1.5; }.lr-source-picker-body > .lr-capture-device { margin-bottom: 10px; }@container host-controls (max-width: 920px) {.lr-host-share-controls { gap: 4px; }@@ -1898,7 +1904,6 @@ details[open] > summary > .lr-sharing-chevron { transform: rotate(180deg); }.lr-top-right { gap: 4px; }.lr-brand { gap: 0; padding-inline: 0; }.lr-home-arrow { width: 10px; }- .lr-leds i { width: 8px; height: 8px; }.lr-tiles .lr-tile { padding-inline: 4px; }.lr-tiles .lr-tile small { font-size: 10px; letter-spacing: 0; }}diff --git a/src/client/ui/icons.tsx b/src/client/ui/icons.tsxindex 2efb29d0..6f552903 100644--- a/src/client/ui/icons.tsx+++ b/src/client/ui/icons.tsx@@ -15,6 +15,7 @@ const PATHS = {fitContain: { body: (<><rect pathLength={1} x="2" y="3" width="20" height="18" rx="2"/><path pathLength={1} d="M2 7h20M2 17h20m-15-5h10"/></>) },fitCover: { body: (<><rect pathLength={1} x="2" y="3" width="20" height="18" rx="2"/><path pathLength={1} d="M7 3v18M17 3v18m-7-9h4"/></>) },fitStretch: { body: (<><rect pathLength={1} x="2" y="3" width="20" height="18" rx="2"/><path pathLength={1} d="M6 12h12M9 9l-3 3 3 3m6-6 3 3-3 3"/></>) },+ rotatePicture: { body: (<><rect pathLength={1} x="3" y="11" width="13" height="9" rx="2"/><path pathLength={1} d="M6 7a8 8 0 0 1 15 2m-4-3 4 3 1-5"/></>) },keyboard: { body: (<><rect pathLength={1} x="2" y="5" width="20" height="14" rx="3"/><path pathLength={1} d="M6 9h.01M10 9h.01M14 9h.01M18 9h.01M6 12h.01M10 12h.01M14 12h.01M18 12h.01M7 16h10"/></>) },mouse: { body: (<><rect pathLength={1} x="6" y="2" width="12" height="20" rx="6"/><path pathLength={1} d="M12 2v7M6 10h12"/></>) },star: { body: <path pathLength={1} d="m12 3 2.8 5.7 6.3.9-4.5 4.4 1.1 6.3-5.7-3-5.7 3 1.1-6.3L3.1 9.6l6.3-.9Z" /> },@@ -27,6 +28,8 @@ const PATHS = {camera: { body: (<><rect pathLength={1} x="2" y="6" width="14" height="12" rx="3"/><path pathLength={1} d="m16 10 6-3v10l-6-3"/></>) },microphone: { body: (<><rect pathLength={1} x="9" y="2" width="6" height="13" rx="3"/><path pathLength={1} d="M5 10v2a7 7 0 0 0 14 0v-2M12 19v3m-4 0h8"/></>) },microphoneOff: { body: (<><path pathLength={1} d="M9 5a3 3 0 0 1 6 0v5m0 4a3 3 0 0 1-6-2V9M5 10v2a7 7 0 0 0 12 5m2-5v-2M12 19v3m-4 0h8M3 3l18 18"/></>) },+ headphones: { body: (<><path pathLength={1} d="M3 14v-2a9 9 0 0 1 18 0v2"/><rect pathLength={1} x="3" y="12" width="5" height="9" rx="2"/><rect pathLength={1} x="16" y="12" width="5" height="9" rx="2"/></>) },+ headphonesOff: { body: (<><path pathLength={1} d="M3 14v-2c0-2 .6-3.8 1.7-5.3M9 3.5A9 9 0 0 1 21 12v3M3 3l18 18"/><rect pathLength={1} x="3" y="12" width="5" height="9" rx="2"/><path pathLength={1} d="M16 16v3a2 2 0 0 0 2 2h1m2-4v-3a2 2 0 0 0-2-2h-1"/></>) },couch: { body: (<><path pathLength={1} d="M5 12V8a3 3 0 0 1 3-3h8a3 3 0 0 1 3 3v4M6 19v2m12-2v2"/><path pathLength={1} d="M5 15h14v-3a2 2 0 0 1 4 0v5a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-5a2 2 0 0 1 4 0Z"/></>) },gamepad: { body: (<><path pathLength={1} d="M8 7h8c3 0 4 2 5 6l1 5c.3 2-2 3-3.5 1.5L16 17H8l-2.5 2.5C4 21 1.7 20 2 18l1-5c1-4 2-6 5-6Z"/><path pathLength={1} d="M6 12h4m-2-2v4m8-3h.01M18 14h.01"/></>) },save: { body: (<><path pathLength={1} d="M5 3h12l4 4v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2Z"/><path pathLength={1} d="M7 3v6h9V3M7 21v-7h10v7"/></>) },@@ -37,6 +40,7 @@ const PATHS = {flag: { body: (<><path pathLength={1} d="M5 22V3h14l-4 5 4 5H5"/></>) },heart: { body: (<><path pathLength={1} d="M12 21 3.6 12.6C-2 7 5.5.5 12 7 18.5.5 26 7 20.4 12.6Z"/></>) },bulb: { body: (<><path pathLength={1} d="M8 17v-2c-6-5-3-13 4-13s10 8 4 13v2ZM9 21h6m-3-4v-7m-3 0 3 3 3-3"/></>) },+ plus: { body: <path pathLength={1} d="M12 5v14M5 12h14" /> },copy: { body: (<><rect pathLength={1} x="9" y="9" width="12" height="12" rx="2"/><path pathLength={1} d="M5 15V5a2 2 0 0 1 2-2h10"/></>) },check: { body: (<><path pathLength={1} d="M4 12.5 9.5 18 20 6.5"/></>) },refresh: { body: (<><path pathLength={1} d="M3 12a9 9 0 0 1 9-9 9.7 9.7 0 0 1 6.7 2.7L21 8"/><path pathLength={1} d="M21 3v5h-5"/><path pathLength={1} d="M21 12a9 9 0 0 1-9 9 9.7 9.7 0 0 1-6.7-2.7L3 16"/><path pathLength={1} d="M8 16H3v5"/></>) },@@ -60,6 +64,7 @@ const PATHS = {link: { body: (<><path pathLength={1} d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path pathLength={1} d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></>) },linkOff: { body: (<><path pathLength={1} d="M10 13a5 5 0 0 0 7.54.54l1.1-1.1M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/><path pathLength={1} d="m3 3 18 18"/></>) },arrowRight: { body: (<><path pathLength={1} d="M4 12h16m-6.5-6.5L20 12l-6.5 6.5"/></>) },+ arrowLeft: { body: (<><path pathLength={1} d="M20 12H4m6.5-6.5L4 12l6.5 6.5"/></>) },arrowUp: { body: (<><path pathLength={1} d="M12 20V4m-6.5 6.5L12 4l6.5 6.5"/></>) },arrowDown: { body: (<><path pathLength={1} d="M12 4v16m-6.5-6.5L12 20l6.5-6.5"/></>) },key: { body: (<><circle pathLength={1} cx="7.5" cy="15.5" r="4.5"/><path pathLength={1} d="m11 12.5 9.5-9.5M14.5 6l3 3M17.5 3l3 3"/></>) },diff --git a/src/client/ui/visual-kinds.ts b/src/client/ui/visual-kinds.tsindex cee69ad5..0219e974 100644--- a/src/client/ui/visual-kinds.ts+++ b/src/client/ui/visual-kinds.ts@@ -62,6 +62,7 @@ export type Set1Kind =export type Set2Kind =| "hint-copy-code"| "hint-shuffle-code"+ | "hint-create-room"| "hint-copy-invite"| "hint-invite-link"| "hint-client-link"@@ -98,6 +99,7 @@ export type Set4Kind =| "hint-join-go"| "hint-theater"| "hint-theater-exit"+ | "hint-route-auto"| "hint-route-p2p"| "hint-route-p2p-required"| "hint-route-sfu-required"@@ -110,6 +112,7 @@ export type PlaybackHintKind =| "hint-fit-contain"| "hint-fit-cover"| "hint-fit-fill"+ | "hint-picture-rotation"| "hint-local-play"| "hint-local-pause"| "hint-volume"@@ -166,6 +169,23 @@ export type RemoteHintKind =| "hint-remote-mouse-lock"| "hint-remote-mouse-release";+export type RelayHintKind = "hint-relay-volunteer";++export type VoiceHintKind =+ | "hint-voice-open"+ | "hint-voice-close"+ | "hint-voice-closed"+ | "hint-voice-join"+ | "hint-voice-leave"+ | "hint-voice-microphone-on"+ | "hint-voice-microphone-off"+ | "hint-voice-host-microphone-unavailable"+ | "hint-voice-microphone-unavailable"+ | "hint-voice-microphone-volume"+ | "hint-voice-microphone-processing"+ | "hint-voice-deafen"+ | "hint-voice-undeafen";+export type HintKind =| Set1Kind| Set2Kind@@ -176,6 +196,8 @@ export type HintKind =| MetricHintKind| InteractionHintKind| RemoteHintKind+ | RelayHintKind+ | VoiceHintKind| ControlHintKind;export type ComicTheme = "stage" | "paper";diff --git a/src/shared/protocol.ts b/src/shared/protocol.tsindex c1caa47e..fe8335a9 100644--- a/src/shared/protocol.ts+++ b/src/shared/protocol.ts@@ -235,6 +235,8 @@ export const runtimeCapabilitiesSchema = z.object({sfuOnly: z.boolean().optional(),natPrediction: z.boolean().default(false),roomInteractions: z.boolean().default(false),+ roomVoice: z.boolean().default(false),+ relayVolunteer: z.boolean().default(false),roomReactionIds: z.array(z.string().max(32).regex(/^[a-z][a-z0-9-]*$/)).max(64).optional(),hostRoomSession: z.boolean().default(false),remoteInput: z.boolean().default(false),@@ -330,6 +332,48 @@ const iceCandidateSchema = z}).strict();+export const voiceDescriptionSchema = z.object({+ revision: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),+ sdp: sessionDescriptionSchema,+ tracks: z.array(z.object({ mid: z.string().min(1).max(128), publicationId: opaqueIdSchema }).strict())+ .max(MAX_PARTICIPANTS_PER_ROOM_LIMIT * 2),+}).strict();+export type VoiceDescription = z.infer<typeof voiceDescriptionSchema>;++const voiceSignalShape = {+ connectionId: opaqueIdSchema,+ description: voiceDescriptionSchema.optional(),+ candidate: iceCandidateSchema.optional(),+ renegotiate: z.literal(true).optional(),+};+export const roomVoiceCommandSchema = z.discriminatedUnion("action", [+ z.object({ action: z.literal("join") }).strict(),+ z.object({ action: z.literal("leave") }).strict(),+ z.object({ action: z.literal("publish") }).strict(),+ z.object({ action: z.literal("unpublish"), publicationId: opaqueIdSchema }).strict(),+]);+export type RoomVoiceCommand = z.infer<typeof roomVoiceCommandSchema>;+export const roomVoiceStateSchema = z.object({+ type: z.literal("room-voice-state"),+ revision: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),+ enabled: z.boolean(),+ hostPeerId: opaqueIdSchema.nullable(),+ members: z.array(z.object({ peerId: opaqueIdSchema, connected: z.boolean(), joined: z.boolean(),+ upstream: mediaRouteUpstreamSchema, publicationId: opaqueIdSchema.optional() }).strict())+ .max(MAX_PARTICIPANTS_PER_ROOM_LIMIT),+ publications: z.array(z.object({ id: opaqueIdSchema, peerId: opaqueIdSchema }).strict())+ .max(MAX_PARTICIPANTS_PER_ROOM_LIMIT),+ connections: z.array(z.object({ connectionId: opaqueIdSchema, parentPeerId: opaqueIdSchema.optional(),+ childPeerId: opaqueIdSchema, transport: z.enum(["peer", "sfu"]), pending: z.boolean(),+ revision: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),+ send: z.array(opaqueIdSchema).max(MAX_PARTICIPANTS_PER_ROOM_LIMIT),+ receive: z.array(opaqueIdSchema).max(MAX_PARTICIPANTS_PER_ROOM_LIMIT),+ }).strict()).max(MAX_PARTICIPANTS_PER_ROOM_LIMIT + 1),+ unavailable: z.array(opaqueIdSchema).max(MAX_PARTICIPANTS_PER_ROOM_LIMIT),+}).strict();+export type RoomVoiceState = z.infer<typeof roomVoiceStateSchema>;+export type VoiceConnection = RoomVoiceState["connections"][number];+export const punchPredictionSchema = z.object({address: z.ipv4(),port: z.number().int().min(1024).max(65535),@@ -589,7 +633,7 @@ export const participantRouteAssignmentSchema = zupstream: mediaRouteUpstreamSchema,childPeerIds: z.array(opaqueIdSchema)- .max(MAX_ENDPOINT_MEDIA_COPY_CAPACITY)+ .max(MAX_VIEWERS_PER_ROOM_LIMIT).refine((peerIds) => new Set(peerIds).size === peerIds.length),sfuPublicationGeneration: sfuPublicationGenerationSchema.nullable(),})@@ -883,6 +927,13 @@ const signalingChallengeSequenceSchema = z.max(Number.MAX_SAFE_INTEGER);export const clientMessageSchema = z.union([+ z.object({ type: z.literal("set-relay-volunteer"), enabled: z.boolean(), capacity: z.number().int().min(0).max(MAX_VIEWERS_PER_ROOM_LIMIT) }).strict(),+ z.object({ type: z.literal("subscribe-room-voice") }).strict(),+ z.object({ type: z.literal("room-voice-command"), command: roomVoiceCommandSchema }).strict(),+ z.object({ type: z.literal("room-voice-signal"), ...voiceSignalShape }).strict()+ .refine(value => Number(!!value.description) + Number(!!value.candidate) + Number(!!value.renegotiate) === 1),+ z.object({ type: z.literal("room-voice-transport"), connectionId: opaqueIdSchema,+ state: z.enum(["connected", "failed"]) }).strict(),z.object({ type: z.literal("set-viewer-route-preference"), preference: viewerRoutePreferenceSchema }).strict(),z.object({ type: z.literal("subscribe-audio-presence") }).strict(),z.object({ type: z.literal("set-audio-presence"), shareGeneration: opaqueIdSchema, available: z.boolean() }).strict(),@@ -1065,6 +1116,12 @@ const authenticatedMessageSchema = z.union([]);export const serverMessageSchema = z.union([+ z.object({ type: z.literal("relay-volunteer"), enabled: z.boolean(), capacity: z.number().int().min(0).max(MAX_VIEWERS_PER_ROOM_LIMIT) }).strict(),+ roomVoiceStateSchema,+ z.object({ type: z.literal("room-voice-signal"), ...voiceSignalShape }).strict()+ .refine(value => Number(!!value.description) + Number(!!value.candidate) + Number(!!value.renegotiate) === 1),+ z.object({ type: z.literal("room-voice-error"),+ code: z.enum(["not-allowed", "not-enabled", "connection-unavailable"]) }).strict(),z.object({ type: z.literal("viewer-route-preference"), preference: viewerRoutePreferenceSchema, accepted: z.boolean() }).strict(),z.object({ type: z.literal("audio-presence"), available: z.boolean().nullable() }).strict(),z.object({ type: z.literal("remote-input-peers"), peers: z.array(z.object({ peerId: opaqueIdSchema,diff --git a/tests/app-connection-button.test.ts b/tests/app-connection-button.test.tsindex 4b94d1a6..ad4ca4e7 100644--- a/tests/app-connection-button.test.ts+++ b/tests/app-connection-button.test.ts@@ -67,14 +67,14 @@ const site = "https://site.example";const approval = `http://127.0.0.1:39721/client?site=${encodeURIComponent(site)}`;function mount(activated = false, state: "idle" | "ready" = "idle") {- const popup = { closed: false, close: vi.fn(() => { popup.closed = true; }), location: { replace: vi.fn() } };+ const popup = { closed: false, close: vi.fn(() => { popup.closed = true; }) };const window = Object.assign(new EventTarget(), { open: vi.fn((): typeof popup | null => popup), location: { origin: site } });const native = {discoverNativeConnect: vi.fn(async (_signal: AbortSignal): Promise<string | null> => approval),discoverNativeHealth: vi.fn(async (_options: { signal: AbortSignal }): Promise<object | null> => ({})),NativeCompatibilityError: class extends Error {},};- const pending = { current: null as { controller: AbortController } | null };+ const pending = { current: null as { controller: AbortController; cancel?: () => void } | null };const healthCheck = { current: null as AbortController | null };const help = { current: { hidePopover: vi.fn(), matches: vi.fn(() => false) } };const showHelp = vi.fn();@@ -99,14 +99,58 @@ function mount(activated = false, state: "idle" | "ready" = "idle") {}));}const activateElsewhere = () => { activated = true; window.dispatchEvent(new Event("activation")); };- return { ...operation, popup, window, native, pending, help, showHelp, setState, activateClient, activateElsewhere, onConnected, message };+ const openApproval = async () => { await operation.connect(); await operation.connect(); };+ return { ...operation, openApproval, popup, window, native, pending, help, showHelp, setState, activateClient, activateElsewhere, onConnected, message };}describe("App connection approval", () => {+ it("keeps permission discovery in the original tab and opens only on a later click", async () => {+ const page = mount();+ let complete!: (url: string) => void;+ page.native.discoverNativeConnect.mockImplementation(() => new Promise(resolve => { complete = resolve; }));+ const connecting = page.connect();+ await settle();+ expect(page.setState).toHaveBeenLastCalledWith("busy");+ expect(page.showHelp).toHaveBeenCalledOnce();+ expect(page.window.open).not.toHaveBeenCalled();+ complete(approval);+ await connecting;+ expect(page.setState).toHaveBeenLastCalledWith("approval");+ expect(page.window.open).not.toHaveBeenCalled();+ page.message({ source: null });+ expect(page.native.discoverNativeHealth).not.toHaveBeenCalled();+ await page.connect();+ expect(page.window.open).toHaveBeenCalledWith(approval, "_blank");+ expect(page.setState).toHaveBeenLastCalledWith("approving");+ page.cleanup();+ });++ it("cancels dismissed discovery and ignores its late result before a retry", async () => {+ const page = mount();+ let complete!: (url: string) => void;+ page.native.discoverNativeConnect.mockImplementationOnce(() => new Promise(resolve => { complete = resolve; }));+ const connecting = page.connect();+ await settle();+ const first = page.pending.current!;+ first.cancel!();+ expect(first.controller.signal.aborted).toBe(true);+ expect(page.pending.current).toBeNull();+ expect(page.setState).toHaveBeenLastCalledWith("idle");+ await page.connect();+ complete(approval);+ await connecting;+ expect(page.setState).toHaveBeenLastCalledWith("approval");+ expect(page.pending.current).not.toBe(first);+ expect(page.window.open).not.toHaveBeenCalled();+ await page.connect();+ expect(page.window.open).toHaveBeenCalledOnce();+ page.cleanup();+ });+it("opens the launcher for an already connected Site without changing approval", async () => {const page = mount(true, "ready");- await page.connect();- expect(page.popup.location.replace).toHaveBeenCalledWith("http://127.0.0.1:39721/client");+ await page.openApproval();+ expect(page.window.open).toHaveBeenCalledWith("http://127.0.0.1:39721/client", "_blank");expect(page.setState).toHaveBeenLastCalledWith("ready");expect(page.pending.current).toBeNull();expect(page.activateClient).not.toHaveBeenCalled();@@ -120,8 +164,8 @@ describe("App connection approval", () => {page.native.discoverNativeConnect.mockResolvedValue(null);await page.connect();expect(page.setState).toHaveBeenLastCalledWith("unavailable");- expect(page.showHelp).toHaveBeenCalledOnce();- expect(page.popup.closed).toBe(true);+ expect(page.showHelp).toHaveBeenCalledTimes(2);+ expect(page.window.open).not.toHaveBeenCalled();expect(page.pending.current).toBeNull();expect(page.activateClient).not.toHaveBeenCalled();page.cleanup();@@ -130,10 +174,10 @@ describe("App connection approval", () => {it("offers recovery when the browser blocks the approval window", async () => {const page = mount();page.window.open.mockReturnValue(null);- await page.connect();+ await page.openApproval();expect(page.setState).toHaveBeenLastCalledWith("unavailable");- expect(page.showHelp).toHaveBeenCalledOnce();- expect(page.native.discoverNativeConnect).not.toHaveBeenCalled();+ expect(page.showHelp).toHaveBeenCalledTimes(2);+ expect(page.native.discoverNativeConnect).toHaveBeenCalledOnce();expect(page.activateClient).not.toHaveBeenCalled();page.cleanup();});@@ -142,10 +186,10 @@ describe("App connection approval", () => {const page = mount();let complete!: (health: object) => void;page.native.discoverNativeHealth.mockImplementation(() => new Promise(resolve => { complete = resolve; }));- await page.connect();+ await page.openApproval();await page.connect();expect(page.window.open).toHaveBeenCalledOnce();- expect(page.popup.location.replace).toHaveBeenCalledWith(approval);+ expect(page.window.open).toHaveBeenCalledWith(approval, "_blank");for (const invalid of [{ source: {} }, { origin: "http://127.0.0.1:39722" },{ data: { type: "piik-app-approved", site: "https://another.example" } },@@ -172,7 +216,7 @@ describe("App connection approval", () => {const page = mount();if (result === "absent") page.native.discoverNativeHealth.mockResolvedValue(null);else page.native.discoverNativeHealth.mockRejectedValue(new Error("network unavailable"));- await page.connect();+ await page.openApproval();page.message();await settle();expect(page.activateClient).not.toHaveBeenCalled();@@ -180,7 +224,7 @@ describe("App connection approval", () => {expect(page.setState).toHaveBeenLastCalledWith("unavailable");expect(page.popup.closed).toBe(true);expect(page.pending.current).toBeNull();- await page.connect();+ await page.openApproval();expect(page.window.open).toHaveBeenCalledTimes(2);page.cleanup();});@@ -189,7 +233,7 @@ describe("App connection approval", () => {const page = mount();let complete!: (health: object) => void;page.native.discoverNativeHealth.mockImplementation(() => new Promise(resolve => { complete = resolve; }));- await page.connect();+ await page.openApproval();page.message();page.cleanup();complete({});@@ -200,10 +244,10 @@ describe("App connection approval", () => {expect(page.onConnected).not.toHaveBeenCalled();expect(page.popup.closed).toBe(true);expect(page.native.discoverNativeHealth.mock.calls[0]![0].signal.aborted).toBe(true);- expect(page.setState).toHaveBeenLastCalledWith("busy");+ expect(page.setState).toHaveBeenLastCalledWith("approving");});- it("never navigates the popup when discovery completes after unmount", async () => {+ it("never opens an approval page when discovery completes after unmount", async () => {const page = mount();let complete!: (url: string) => void;page.native.discoverNativeConnect.mockImplementation(() => new Promise(resolve => { complete = resolve; }));@@ -212,21 +256,20 @@ describe("App connection approval", () => {page.cleanup();complete(approval);await connecting;- expect(page.popup.location.replace).not.toHaveBeenCalled();- expect(page.popup.closed).toBe(true);+ expect(page.window.open).not.toHaveBeenCalled();expect(page.activateClient).not.toHaveBeenCalled();});it("releases a closed approval window on focus and permits retry", async () => {const page = mount();- await page.connect();+ await page.openApproval();page.popup.closed = true;page.window.dispatchEvent(new Event("focus"));expect(page.pending.current).toBeNull();expect(page.setState).toHaveBeenLastCalledWith("idle");page.message();expect(page.native.discoverNativeHealth).not.toHaveBeenCalled();- await page.connect();+ await page.openApproval();expect(page.window.open).toHaveBeenCalledTimes(2);page.cleanup();});@@ -264,7 +307,7 @@ describe("App connection approval", () => {let complete!: (health: object | null) => void;page.native.discoverNativeHealth.mockImplementationOnce(() => new Promise(resolve => { complete = resolve; }));await settle();- await page.connect();+ await page.openApproval();expect(page.native.discoverNativeHealth.mock.calls[0]![0].signal.aborted).toBe(true);page.message();await settle();diff --git a/tests/client-state.test.ts b/tests/client-state.test.tsindex 737c38ea..7cfd62ce 100644--- a/tests/client-state.test.ts+++ b/tests/client-state.test.ts@@ -47,7 +47,7 @@ import {SignalingClient,} from "../src/client/lib/signaling.ts";import { deriveParticipantTopology } from "../src/client/lib/participant-topology.ts";-import { labelParticipantSnapshot } from "../src/client/lib/viewer-presence.ts";+import { labelParticipantNames, labelParticipantSnapshot } from "../src/client/lib/viewer-presence.ts";import { qualityEvidenceWindowFromMetrics } from "../src/client/media/viewer-quality-evidence.ts";import {collectConnectionMetrics,@@ -83,6 +83,18 @@ function routeAuthenticated(}describe("browser-local display name", () => {+ it("disambiguates distinct chat senders while retaining repeated and historical names", () => {+ const first = { peerId: "viewer_AAAAAAsuffix", displayName: "观众" };+ const other = { peerId: "viewer_BBBBBBsuffix", displayName: "观众" };+ expect(labelParticipantNames([first, first]).map(sender => sender.label)).toEqual(["观众", "观众"]);+ const senders = labelParticipantNames([first, first, other, { ...first, displayName: "新昵称" }]);+ expect(senders[0].label).toBe(senders[1].label);+ expect(senders[0].label).not.toBe(senders[2].label);+ expect(senders[0].peerIdSuffix.length).toBeGreaterThan(6);+ expect(senders.map(sender => sender.displayName)).toEqual(["观众", "观众", "观众", "新昵称"]);+ expect(senders[3].label).toBe("新昵称");+ });+it("localizes text defaults and uses visual emoji identities", () => {setCopy({ lang: "zh", vis: false });expect(defaultViewerDisplayName(false)).toBe("观众");diff --git a/tests/host-audio.test.ts b/tests/host-audio.test.tsindex 95b7697e..0cd68fc9 100644--- a/tests/host-audio.test.ts+++ b/tests/host-audio.test.ts@@ -18,61 +18,28 @@ class Stream {const media = (...tracks: Track[]) => new Stream(tracks) as unknown as MediaStream;function setup() {- const contexts: Context[] = [];- class Context {- output = new Stream([new Track("audio")]);- inputs: Stream[] = [];- nodes: { connect: ReturnType<typeof vi.fn>; disconnect: ReturnType<typeof vi.fn> }[] = [];- currentTime = 0;- gain = { gain: { value: 1, setTargetAtTime: vi.fn() }, connect: vi.fn(), disconnect: vi.fn() };- constructor() { contexts.push(this); }- createMediaStreamDestination() { return { stream: this.output }; }- createGain() { return this.gain; }- createMediaStreamSource(stream: Stream) {- this.inputs.push(stream);- const node = { connect: vi.fn(), disconnect: vi.fn() };- this.nodes.push(node);- return node;- }- resume = vi.fn(async () => {});- close = vi.fn(async () => {});- }- vi.stubGlobal("MediaStream", Stream);- vi.stubGlobal("AudioContext", Context);const getUserMedia = vi.fn();vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });- return { contexts, getUserMedia };+ return { getUserMedia };}afterEach(() => vi.unstubAllGlobals());-test("input availability follows source and microphone independently of the retained mixer track", async () => {- const { getUserMedia } = setup();- const source = new Track("audio"), microphone = new Track("audio");- const changed = vi.fn();- const audio = new HostAudio(media(new Track("video"), source), vi.fn(), "browser", changed);+test("source-audio availability follows live input and replacement without owning video or room voice", () => {+ const video = new Track("video"), sound = new Track("audio"), next = new Track("audio");+ const changed = vi.fn(), audio = new HostAudio(media(video, sound), "browser", changed);expect(audio.audioAvailable).toBe(true);- source.stop();- source.dispatchEvent(new Event("ended"));- expect(changed).toHaveBeenLastCalledWith(false);- getUserMedia.mockResolvedValue(media(microphone));- const mixed = (await audio.toggleMicrophone())!;- expect(changed).toHaveBeenLastCalledWith(true); // Microphone only.- const replaced = audio.attach(media(new Track("video")));- expect(replaced.getAudioTracks()).toEqual(mixed.getAudioTracks());- expect(changed).toHaveBeenLastCalledWith(true); // Source switch keeps the microphone.- await audio.toggleMicrophone();+ sound.stop(); sound.dispatchEvent(new Event("ended"));expect(changed).toHaveBeenLastCalledWith(false);- expect(mixed.getAudioTracks()[0].readyState).toBe("live");- await audio.toggleMicrophone();- microphone.stop(); microphone.onended!();- expect(changed).toHaveBeenLastCalledWith(false);- const next = new Track("audio");- audio.attach(media(new Track("video"), next));+ const replacement = media(video, next);+ expect(audio.attach(replacement, "camera")).toBe(replacement);+ expect(audio.sourceStream).toBe(replacement);+ expect(audio.sourceKind).toBe("camera");expect(changed).toHaveBeenLastCalledWith(true);- next.enabled = false; // Share pause does not change input availability.+ next.enabled = false;expect(audio.audioAvailable).toBe(true);- audio.dispose();- changed.mockClear();+ audio.dispose(); changed.mockClear();+ expect(next.stop).toHaveBeenCalledOnce();+ expect(video.stop).not.toHaveBeenCalled();next.dispatchEvent(new Event("ended"));expect(changed).not.toHaveBeenCalled();});@@ -90,131 +57,6 @@ test("camera is a bounded video source and never implicitly requests a microphon} });});-test("mixing and source changes retain one audio track, microphone intent and the capture-owned video", async () => {- const { contexts, getUserMedia } = setup();- const video = new Track("video"), sound = new Track("audio"), microphone = new Track("audio");- const change = vi.fn();- const audio = new HostAudio(media(video, sound), change);- getUserMedia.mockResolvedValue(media(microphone));- const mixed = (await audio.toggleMicrophone())!;- expect(mixed.getVideoTracks()).toEqual([video]);- expect(mixed.getAudioTracks()).toHaveLength(1);- await audio.toggleMicrophone();- expect(microphone.enabled).toBe(false);- expect(change).toHaveBeenLastCalledWith(false);- const camera = new Track("video");- const replaced = audio.attach(media(camera));- expect(audio.sourceStream.getAudioTracks()).toHaveLength(0);- expect(replaced.getAudioTracks()).toEqual(mixed.getAudioTracks());- expect(replaced.getVideoTracks()).toEqual([camera]);- expect(sound.stop).toHaveBeenCalledOnce();- expect(video.stop).not.toHaveBeenCalled(); // Host owns picture retirement.- await audio.toggleMicrophone();- microphone.stop(); microphone.onended!();- expect(getUserMedia).toHaveBeenCalledOnce(); // Mute/unmute must not open a second microphone.- expect(change).toHaveBeenLastCalledWith(false);- expect(mixed.getAudioTracks()[0].readyState).toBe("live");- expect(camera.stop).not.toHaveBeenCalled();- audio.dispose();- expect(contexts[0].close).toHaveBeenCalledOnce();- expect(mixed.getAudioTracks()[0].readyState).toBe("ended");-});--test("source audio facts are independent of mixed voice, mute, volume and share pause", async () => {- const { getUserMedia } = setup();- const camera = new Track("video"), microphone = new Track("audio");- const source = media(camera);- const audio = new HostAudio(source, vi.fn());- getUserMedia.mockResolvedValue(media(microphone));- const mixed = (await audio.toggleMicrophone())!;- expect(mixed.getAudioTracks()).toHaveLength(1);- expect(audio.sourceStream).toBe(source);- expect(audio.sourceStream.getAudioTracks()).toHaveLength(0);- await audio.toggleMicrophone();- audio.setMicrophoneVolume(0);- mixed.getTracks().forEach(track => { track.enabled = false; });- expect(audio.sourceStream.getAudioTracks()).toHaveLength(0);- const sourceSound = new Track("audio");- sourceSound.enabled = false;- const nextSource = media(new Track("video"), sourceSound);- audio.attach(nextSource);- expect(audio.sourceStream).toBe(nextSource);- expect(audio.sourceStream.getAudioTracks()).toHaveLength(1);- expect(microphone.enabled).toBe(false);- audio.dispose();- expect(sourceSound.stop).toHaveBeenCalledOnce();-});--test("microphone denial leaves source audio/video alone; late permission cannot revive a retired share", async () => {- const { contexts, getUserMedia } = setup();- const video = new Track("video"), sound = new Track("audio");- const changed = vi.fn();- const audio = new HostAudio(media(video, sound), changed);- getUserMedia.mockRejectedValueOnce(new DOMException("Denied", "NotAllowedError"));- await expect(audio.toggleMicrophone()).rejects.toThrow("Denied");- expect(contexts[0].close).toHaveBeenCalledOnce();- expect(video.stop).not.toHaveBeenCalled();- expect(sound.stop).not.toHaveBeenCalled();- let grant!: (stream: MediaStream) => void;- getUserMedia.mockImplementationOnce(() => new Promise<MediaStream>((resolve) => { grant = resolve; }));- const request = audio.toggleMicrophone();- audio.dispose();- const lateMicrophone = new Track("audio");- grant(media(lateMicrophone));- expect(await request).toBeNull();- expect(lateMicrophone.stop).toHaveBeenCalledOnce();- expect(changed).not.toHaveBeenCalled();- expect(contexts[1].close).toHaveBeenCalledOnce();-});--test("microphone volume changes only the microphone input without replacing the shared output", async () => {- const { contexts, getUserMedia } = setup();- const sound = new Track("audio"), microphone = new Track("audio");- const audio = new HostAudio(media(new Track("video"), sound), vi.fn());- audio.setMicrophoneVolume(0.5);- getUserMedia.mockResolvedValue(media(microphone));- const mixed = (await audio.toggleMicrophone())!;- const context = contexts[0];- expect(context.gain.gain.value).toBe(0.5);- expect(context.nodes[0].connect).not.toHaveBeenCalledWith(context.gain);- expect(context.nodes[1].connect).toHaveBeenCalledWith(context.gain);- audio.setMicrophoneVolume(1.5);- expect(context.gain.gain.setTargetAtTime).toHaveBeenLastCalledWith(1.5, 0, 0.01);- audio.setMicrophoneVolume(Number.NaN);- expect(context.gain.gain.setTargetAtTime).toHaveBeenCalledOnce();- await audio.toggleMicrophone();- const changed = audio.attach(media(new Track("video")));- expect(changed.getAudioTracks()).toEqual(mixed.getAudioTracks());- expect(microphone.enabled).toBe(false);- expect(getUserMedia).toHaveBeenCalledOnce();- audio.dispose();- expect(context.gain.disconnect).toHaveBeenCalledOnce();-});--test("switching microphone preserves output and leaves the old input on failure", async () => {- const { getUserMedia } = setup();- const video = new Track("video"), first = new Track("audio"), second = new Track("audio");- const audio = new HostAudio(media(video), vi.fn());- getUserMedia.mockResolvedValueOnce(media(first));- const output = (await audio.setMicrophone(true, "first"))!;- getUserMedia.mockRejectedValueOnce(new DOMException("missing", "NotFoundError"));- await expect(audio.setMicrophone(true, "missing")).rejects.toThrow("missing");- expect(first.stop).not.toHaveBeenCalled();- expect(video.stop).not.toHaveBeenCalled();- getUserMedia.mockResolvedValueOnce(media(second));- const replacement = await audio.setMicrophone(true, "second");- expect(getUserMedia).toHaveBeenLastCalledWith({ audio: expect.objectContaining({ deviceId: { exact: "second" } }) });- expect(replacement).toBeNull(); // No transport update for an input-only change.- expect(output.getAudioTracks()[0].readyState).toBe("live");- expect(first.stop).toHaveBeenCalledOnce();- first.onended!(); // Retired input cannot mute its replacement.- expect(second.enabled).toBe(true);- await audio.setMicrophone(false, "first");- expect(second.stop).toHaveBeenCalledOnce();- expect(getUserMedia).toHaveBeenCalledTimes(3); // Selecting while muted never captures.- audio.dispose();-});-test("camera selection requests one exact device without microphone permission", async () => {const { getUserMedia } = setup();getUserMedia.mockResolvedValue(media(new Track("video")));@@ -223,62 +65,3 @@ test("camera selection requests one exact device without microphone permission",expect(getUserMedia.mock.calls[0][0].video).toHaveProperty("resizeMode", { exact: "none" });expect(getUserMedia.mock.calls[0][0].video).not.toHaveProperty("facingMode");});--test("voice processing replaces only the input and commits only after successful capture", async () => {- const { getUserMedia } = setup();- const video = new Track("video"), first = new Track("audio"), raw = new Track("audio");- const audio = new HostAudio(media(video), vi.fn(), "camera");- getUserMedia.mockResolvedValueOnce(media(first));- const output = (await audio.setMicrophone(true, "virtual-input"))!;- expect(getUserMedia).toHaveBeenLastCalledWith({ audio: {- echoCancellation: true, noiseSuppression: true, autoGainControl: true,- deviceId: { exact: "virtual-input" },- } });- getUserMedia.mockRejectedValueOnce(new DOMException("Device busy", "NotReadableError"));- await expect(audio.setMicrophone(true, "virtual-input", false)).rejects.toThrow("Device busy");- expect(first.stop).not.toHaveBeenCalled();- await audio.setMicrophone(true, "virtual-input"); // Failure must retain the previous configuration.- expect(getUserMedia).toHaveBeenCalledTimes(2);-- getUserMedia.mockResolvedValueOnce(media(raw));- expect(await audio.setMicrophone(true, "virtual-input", false)).toBeNull();- expect(getUserMedia).toHaveBeenLastCalledWith({ audio: {- echoCancellation: false, noiseSuppression: false, autoGainControl: false,- voiceIsolation: false, channelCount: { ideal: 2 }, deviceId: { exact: "virtual-input" },- } });- expect(first.stop).toHaveBeenCalledOnce();- expect(video.stop).not.toHaveBeenCalled();- expect(output.getAudioTracks()[0].readyState).toBe("live");- expect(audio.attach(media(video)).getAudioTracks()).toEqual(output.getAudioTracks());- await audio.setMicrophone(false, "virtual-input");- await audio.toggleMicrophone();- expect(raw.enabled).toBe(true);- expect(getUserMedia).toHaveBeenCalledTimes(3); // Mute and source replacement retain processing intent.-- await audio.setMicrophone(false, "virtual-input", true);- expect(raw.stop).toHaveBeenCalledOnce();- expect(getUserMedia).toHaveBeenCalledTimes(3); // A settings change while muted never opens the input.- getUserMedia.mockResolvedValueOnce(media(new Track("audio")));- await audio.toggleMicrophone();- expect(getUserMedia).toHaveBeenLastCalledWith({ audio: expect.objectContaining({ echoCancellation: true }) });- audio.dispose();-});--test("share retirement also cancels a pending processing change", async () => {- const { getUserMedia } = setup();- const first = new Track("audio"), late = new Track("audio");- const changed = vi.fn();- const audio = new HostAudio(media(new Track("video")), changed);- getUserMedia.mockResolvedValueOnce(media(first));- const output = (await audio.setMicrophone(true, ""))!;- let complete!: (stream: MediaStream) => void;- getUserMedia.mockImplementationOnce(() => new Promise<MediaStream>(resolve => { complete = resolve; }));- const replacing = audio.setMicrophone(true, "", false);- audio.dispose();- complete(media(late));- expect(await replacing).toBeNull();- expect(first.stop).toHaveBeenCalledOnce();- expect(late.stop).toHaveBeenCalledOnce();- expect(output.getAudioTracks()[0].readyState).toBe("ended");- expect(changed).toHaveBeenCalledOnce();-});diff --git a/tests/host-quality-ownership.test.ts b/tests/host-quality-ownership.test.tsindex 792adb1e..9067b02a 100644--- a/tests/host-quality-ownership.test.ts+++ b/tests/host-quality-ownership.test.ts@@ -27,7 +27,7 @@ const owners = new Set(["changeQuality", "commitQuality", "rememberQuality", "lo"acquireNativeClient", "requestSharing", "startNativeShare", "startBrowserNativeIngress","ownNativeClient", "discardNativeClient", "releaseUnusedNativeClient", "closeCaptureSourcePicker","openCaptureSourcePicker", "startBrowserShareFromPicker", "startNativeShareFromPicker",- "startSharing", "connectRoomSignal", "createReplacementRoom", "beginRoomMutation", "finishRoomMutation", "setCaptureError", "changeMicrophone", "toggleSharingPause",+ "startSharing", "connectRoomSignal", "createReplacementRoom", "beginRoomMutation", "finishRoomMutation", "setCaptureError", "toggleSharingPause","startPeer", "reconcileHostChildren", "setNotice", "setNoticeKey", "setStatusNotice", "setNoticeError", "setNoticeErrorKey", "endSharing", "disposeResources", "hostTerminationKey", "copyRoomLink", "isCurrentRoomAuthority","handleRoomAccessFailure", "replaceCurrentRoom", "forgetRoom", "endRoomSession", "readableError"]);@@ -103,7 +103,6 @@ function fixture(launchedByClient = true) {qualityPreferenceEditedRef: ref(false), pendingAppQualityPreferenceRef: ref<QualitySettings | null>(null),activeGenerationRef: ref<number | null>(1), streamRef: ref<typeof stream | null>(stream), sourceSwitchRef: ref<object | null>(null),nativeSourceAudioRef: ref<boolean | undefined>(undefined), audioAvailableRef: ref(false), setMicrophoneEnabled: vi.fn(),- microphoneVoiceProcessing: true, setMicrophoneVoiceProcessing: vi.fn(),nativeSourceSelectionRef: ref<Record<string, unknown> | null>(null), nativeCaptureTargetKey,nativeModeRef: ref(false), nativeClientRef: ref<typeof client | null>(client), nativeShareGenerationRef: ref<string | null>("share"),hostAudioRef: ref<{ sourceStream: MediaStream } | null>(null),@@ -719,7 +718,7 @@ describe("Host quality ownership", () => {expect(setMediaPaused).toHaveBeenLastCalledWith(current.streamRef.current, true);}});- it("refreshes source details from the capture input after microphone mixing", async () => {+ it("refreshes source details from the capture input", async () => {const current = fixture(false);const source = {} as MediaStream;current.hostAudioRef.current = { sourceStream: source };@@ -940,77 +939,6 @@ describe("Host quality ownership", () => {expect(report).toHaveBeenCalledWith("capture", "failed", cause, { action: "capture", source });});- it.each(["success", "replace-failed", "stopped"])("retires the whole microphone operation after stream replacement: %s", async outcome => {- const current = fixture();- const permission = deferred<MediaStream>();- const video = { stop: vi.fn() };- const raw = { getVideoTracks: () => [video], getAudioTracks: () => [], getTracks: () => [video] };- const mixed = { ...raw, getAudioTracks: () => [{}] } as unknown as MediaStream;- const pending = vi.fn();- Object.assign(current.context, {- hostAudioRef: ref({ sourceStream: raw, setMicrophoneVolume: vi.fn(), setMicrophone: () => permission.promise }),- streamRef: ref(raw), retiringStreamRef: ref(null), sharingPausedRef: ref(false),- microphoneVolume: 1, setMicrophonePending: pending, setMicrophoneDevices: vi.fn(),- setStream: vi.fn(), setMediaPaused: vi.fn(), peersRef: ref(new Map()),- hostSfuRouteRef: ref(outcome === "replace-failed" ? { replaceStream: async () => { throw Error("replacement failed"); } } : null),- });- const changing = current.context.changeMicrophone(true, "");- expect(pending).toHaveBeenLastCalledWith(true);- if (outcome === "stopped") {- current.activeGenerationRef.current = null;- current.sourceSwitchRef.current = {};- pending.mockClear();- }- permission.resolve(mixed);- await changing;- if (outcome === "stopped") {- expect(pending).not.toHaveBeenCalled();- expect(current.context.setStream).not.toHaveBeenCalled();- } else {- expect(pending).toHaveBeenLastCalledWith(false);- expect(current.sourceSwitchRef.current).toBeNull();- expect(video.stop).not.toHaveBeenCalled();- if (outcome === "replace-failed") expect(current.setNoticeValue).toHaveBeenLastCalledWith(- expect.objectContaining({ key: "host.microphone.unavailable", target: "operation" }));- }- });-- it("keeps microphone denial as operation feedback without retiring video", async () => {- const current = fixture();- Object.assign(current.context, {- hostAudioRef: ref({ setMicrophoneVolume: vi.fn(), setMicrophone: vi.fn(async () => {- throw new DOMException("denied", "NotAllowedError");- }) }),- sharingPausedRef: ref(false), microphoneVolume: 1, setMicrophonePending: vi.fn(),- });- await current.context.changeMicrophone(true, "");- expect(current.setNoticeValue).toHaveBeenLastCalledWith(expect.objectContaining({ key: "host.microphone.denied", target: "operation" }));- expect(current.setPhase).not.toHaveBeenCalled();- expect(current.track.stop).not.toHaveBeenCalled();- expect(current.sourceSwitchRef.current).toBeNull();- });-- it.each(["applied", "failed", "stopped"])("commits Browser voice processing only for the current successful input: %s", async outcome => {- const current = fixture();- const capture = deferred<MediaStream | null>();- const setMicrophone = vi.fn(() => capture.promise);- Object.assign(current.context, {- hostAudioRef: ref({ setMicrophoneVolume: vi.fn(), setMicrophone }),- sharingPausedRef: ref(false), microphoneVolume: 1, setMicrophonePending: vi.fn(),- setMicrophoneDevices: vi.fn(),- });- const changing = current.context.changeMicrophone(true, "virtual-input", false);- expect(setMicrophone).toHaveBeenCalledWith(true, "virtual-input", false);- expect(current.context.setMicrophoneVoiceProcessing).not.toHaveBeenCalled();- if (outcome === "stopped") current.activeGenerationRef.current = null;- if (outcome === "failed") capture.reject(new Error("Input unavailable"));- else capture.resolve(null); // Input replacement keeps the existing mixed stream.- await changing;- if (outcome === "applied") expect(current.context.setMicrophoneVoiceProcessing).toHaveBeenCalledWith(false);- else expect(current.context.setMicrophoneVoiceProcessing).not.toHaveBeenCalled();- expect(current.setPhase).not.toHaveBeenCalled();- expect(current.track.stop).not.toHaveBeenCalled();- });it("keeps a rejected source change as operation feedback while the current share stays live", async () => {const current = fixture();diff --git a/tests/native-client.test.ts b/tests/native-client.test.tsindex 8884795d..bf44b103 100644--- a/tests/native-client.test.ts+++ b/tests/native-client.test.ts@@ -101,6 +101,11 @@ describe("native App private wire", () => {expect(nativeHealthSchema.parse({ ...health, nativeMedia: stronger }).nativeMedia).toMatchObject(stronger);expect(nativeHealthSchema.safeParse({ ...health, nativeMedia: { ...nativeMedia, maxVideoPixels: 0 } }).success).toBe(false);expect(nativeHealthSchema.safeParse({ ...health, nativeMedia: { ...nativeMedia, maxVideoMacroblocksPerSecond: -1 } }).success).toBe(false);+ expect(nativeHealthSchema.parse({ ...health, nativeMedia: { ...nativeMedia, maxRelayChildren: 20 } })+ .nativeMedia.maxRelayChildren).toBe(20);+ for (const maxRelayChildren of [0, 21, 1.5]) {+ expect(nativeHealthSchema.safeParse({ ...health, nativeMedia: { ...nativeMedia, maxRelayChildren } }).success).toBe(false);+ }});it.each(["opening", "hello", "close"])("retires App acquisition during %s without waiting for its timeout", async stage => {diff --git a/tests/native-viewer-peer.test.ts b/tests/native-viewer-peer.test.tsindex f0d8171a..3772b865 100644--- a/tests/native-viewer-peer.test.ts+++ b/tests/native-viewer-peer.test.ts@@ -16,13 +16,16 @@ afterEach(() => {vi.unstubAllGlobals();});-it.each(["commit", "expired", "rpc-expired"])("scopes optional connection preparation to its route: %s", async outcome => {+it.each(["commit", "expired", "rpc-expired"].flatMap(outcome =>+ [undefined, 20].map(maxRelayChildren => ({ outcome, maxRelayChildren })),+))("scopes optional connection preparation to its route: $outcome, backend capacity $maxRelayChildren", async ({ outcome, maxRelayChildren }) => {vi.useFakeTimers();vi.stubGlobal("window", globalThis);vi.stubGlobal("MediaStream", class { getTracks() { return []; } });vi.stubGlobal("RTCPeerConnection", class { close() {} });vi.spyOn(NativeMediaBridge.prototype, "start").mockResolvedValue({} as MediaStream);const client = {+ health: { nativeMedia: { maxRelayChildren } },preparePunch: vi.fn(async () => ({ address: "198.51.100.1", port: 40000, step: 1 })),runPunch: vi.fn(async () => true), closePunch: vi.fn(async () => undefined),receiveOffer: vi.fn(async () => ({ answer: { type: "answer", sdp: "answer" }, audio: false, codec: "vp8" })),@@ -34,13 +37,14 @@ it.each(["commit", "expired", "rpc-expired"])("scopes optional connection prepariceServers: [{ urls: ["stun:site.example:3478"] }],natPredictionStunUrls: ["stun:site.example:3479", "stun:site.example:3480"],}, { sendSignal: sent, sendRestartRequest: () => true, onStream: () => {}, onUpdate: () => {}, onRecoveryExhausted: exhausted },- { natPredictionEnabled: true, recoveryOwner: "route" }, async () => client, unavailable, "session", 2);+ { natPredictionEnabled: true, recoveryOwner: "route" }, async () => client, unavailable, "session", 20);// The page accepts a failure only while this peer owns that connection.exhausted.mockImplementation(() => peer.hasConnectionId("current"));const prepare: SignalPayload = { kind: "punch", connectionId: "current", punch: { phase: "prepare", secret: "42".repeat(32) } };try {await peer.acceptSignal("parent", prepare);await vi.advanceTimersByTimeAsync(0);+ expect(client.preparePunch).toHaveBeenCalledWith("session", "current", expect.anything(), expect.any(String), maxRelayChildren ?? 3);await peer.acceptSignal("parent", { kind: "punch", connectionId: "current", punch: {phase: "start", prediction: { address: "198.51.100.2", port: 50000, step: 1 },} });@@ -54,7 +58,7 @@ it.each(["commit", "expired", "rpc-expired"])("scopes optional connection preparexpect(unavailable).not.toHaveBeenCalled();if (outcome === "commit") {expect(exhausted).not.toHaveBeenCalled();- expect(client.receiveOffer).toHaveBeenCalledWith("session", "current", expect.anything(), expect.anything(), 2, true);+ expect(client.receiveOffer).toHaveBeenCalledWith("session", "current", expect.anything(), expect.anything(), maxRelayChildren ?? 3, true);await peer.acceptSignal("parent", prepare);expect(client.preparePunch).toHaveBeenCalledOnce();} else {diff --git a/tests/network-lab.test.ts b/tests/network-lab.test.tsindex 6732701a..eb8cb641 100644--- a/tests/network-lab.test.ts+++ b/tests/network-lab.test.ts@@ -46,13 +46,17 @@ describe("network laboratory evidence", () => {const sample = { controlOpen: true, playbackPeerId: 0,controls: [{ type: "receive-offer", connectionId: "current" }],events: [{ scope: "app", type: "edge-state", connectionId: "current", state: "connected" }],- stats: [{ type: "selected-pair", peerId: 0, remoteAddress: "127.0.0.1" }],+ stats: [{ type: "inbound-rtp", kind: "video", peerId: 0 },+ { type: "selected-pair", peerId: 0, remoteAddress: "127.0.0.1" },+ { type: "selected-pair", peerId: 1, remoteAddress: "198.51.100.2" },+ { type: "inbound-rtp", kind: "audio", peerId: 1 }],} as unknown as MediaSample;expect(() => checkAppPath(sample, "receive-offer", ["10.71.2.2"])).not.toThrow();expect(() => checkAppPath({ ...sample, events: [...sample.events, { ...sample.events[0]!, state: "failed" }] }, "receive-offer", ["10.71.2.2"])).toThrow();expect(() => checkAppPath({ ...sample, controls: [...sample.controls, { type: "close-receiver", connectionId: "current" }] }, "receive-offer", ["10.71.2.2"])).toThrow();expect(() => checkAppPath({ ...sample, playbackPeerId: 1 }, "receive-offer", ["10.71.2.2"])).toThrow();- expect(() => checkAppPath({ ...sample, stats: [{ ...sample.stats[0]!, remoteAddress: "198.51.100.11" }] }, "receive-offer", ["10.71.2.2"])).toThrow();+ expect(() => checkAppPath({ ...sample, stats: sample.stats.map(row => row.type === "selected-pair" && row.peerId === 0+ ? { ...row, remoteAddress: "198.51.100.11" } : row) }, "receive-offer", ["10.71.2.2"])).toThrow();});it("checks mapping observations rather than trusting a NAT configuration name", () => {diff --git a/tests/protocol.test.ts b/tests/protocol.test.tsindex b8fe6285..d669c5c3 100644--- a/tests/protocol.test.ts+++ b/tests/protocol.test.ts@@ -67,13 +67,13 @@ const qualitySettings = {describe("runtime capabilities", () => {it("defaults missing capabilities off and ignores unknown descriptors", () => {- expect(runtimeCapabilitiesSchema.parse({})).toEqual({ sfu: false, natPrediction: false, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false });+ expect(runtimeCapabilitiesSchema.parse({})).toEqual({ sfu: false, natPrediction: false, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false, roomVoice: false, relayVolunteer: false });expect(runtimeCapabilitiesSchema.parse({ sfu: true, extra: { enabled: true } }))- .toEqual({ sfu: true, natPrediction: false, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false });+ .toEqual({ sfu: true, natPrediction: false, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false, roomVoice: false, relayVolunteer: false });expect(runtimeCapabilitiesSchema.parse({ natPrediction: true, SFU: true }))- .toEqual({ sfu: false, natPrediction: true, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false });+ .toEqual({ sfu: false, natPrediction: true, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false, roomVoice: false, relayVolunteer: false });expect(runtimeCapabilitiesSchema.parse({ sfu: true, natPrediction: true }))- .toEqual({ sfu: true, natPrediction: true, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false });+ .toEqual({ sfu: true, natPrediction: true, roomInteractions: false, hostRoomSession: false, remoteInput: false, viewerRouteSelection: false, audioPresence: false, roomVoice: false, relayVolunteer: false });expect(runtimeCapabilitiesSchema.parse({ sfu: true, sfuOnly: true }).sfuOnly).toBe(true);expect(runtimeCapabilitiesSchema.parse({ roomReactionIds: ["heart", "future-effect"] }).roomReactionIds).toEqual(["heart", "future-effect"]);@@ -1564,12 +1564,7 @@ describe("server signaling protocol", () => {...peerAssisted,routeAssignment: {...peerAssisted.routeAssignment,- childPeerIds: [- "viewer_12345678",- "viewer_87654321",- "viewer_third_1234",- "viewer_overflow_1",- ],+ childPeerIds: Array.from({ length: MAX_VIEWERS_PER_ROOM_LIMIT + 1 }, (_, index) => `viewer_overflow_${index}`),},}).success,).toBe(false);@@ -1690,12 +1685,7 @@ describe("server signaling protocol", () => {expect(participantRouteAssignmentSchema.safeParse({...assignment,- childPeerIds: [- "child_12345678",- "child_87654321",- "child_third_1234",- "child_overflow_1",- ],+ childPeerIds: Array.from({ length: MAX_VIEWERS_PER_ROOM_LIMIT + 1 }, (_, index) => `child_${String(index).padStart(8, "0")}`),}).success,).toBe(false);expect(diff --git a/tests/publish-container.test.ts b/tests/publish-container.test.tsindex 762fcd6e..9368c955 100644--- a/tests/publish-container.test.ts+++ b/tests/publish-container.test.ts@@ -7,9 +7,13 @@ vi.mock("../scripts/release-artifacts.mjs", () => ({ readReleaseArtifacts: artifconst version = "v1.2.1", revision = "a".repeat(40), digest = "b".repeat(64);const repository = "TNTcraftHIM/Piik", image = `piik-candidate:${revision}`;const tag = `ghcr.io/tntcrafthim/piik:${version}`;-const servers = ["amd64", "arm64"].map(arch => ({+const linuxServers = ["amd64", "arm64"].map(arch => ({name: `piik-aaaaaaa-${arch}-runtime.tar.gz`, sha256: arch === "amd64" ? digest : "d".repeat(64), arch,+ goos: "linux",}));+const servers = [...linuxServers, {+ name: "piik-aaaaaaa-windows-amd64-runtime.zip", sha256: "e".repeat(64), arch: "amd64", goos: "windows",+}];type Scenario = { existing?: boolean; draft?: boolean; badArchive?: boolean;wrongSource?: boolean; wrongImage?: boolean; remoteMismatch?: boolean;registryError?: boolean; newerRelease?: boolean; largeCommit?: boolean;@@ -76,7 +80,7 @@ const indexes = () => command.mock.calls.filter(([program, args]) => program ===.map(([, args]) => args.slice(4));describe("container publication", () => {- it("publishes both verified Server images under one version and latest index", async () => {+ it("publishes only Linux Server images under one version and latest index", async () => {await publish();expect(artifacts).toHaveBeenCalledWith("artifacts", version, revision);expect(pushes()).toEqual([`${tag}-amd64`, `${tag}-arm64`]);diff --git a/tests/publish-release.test.ts b/tests/publish-release.test.tsindex 173f5984..eb278ebd 100644--- a/tests/publish-release.test.ts+++ b/tests/publish-release.test.ts@@ -14,9 +14,11 @@ vi.mock("node:timers/promises", () => ({ setTimeout: async () => undefined }));const directory = mkdtempSync(join(tmpdir(), "piik-publisher-"));const version = "v1.0.1", revision = "a".repeat(40);const hash = (value: string | Buffer) => createHash("sha256").update(value).digest("hex");-for (const target of ["server", "server-linux-arm64", "windows-amd64", "linux-amd64", "linux-arm64", "darwin-arm64", "darwin-amd64"]) {+for (const target of ["server", "server-linux-arm64", "server-windows-amd64", "windows-amd64", "linux-amd64", "linux-arm64", "darwin-arm64", "darwin-amd64"]) {const server = target.startsWith("server");- const artifact = `${target}.${server ? "tar.gz" : "zip"}`;+ // The Windows Server package ships a ZIP; the Linux Server packages keep tar.gz.+ const archive = target === "server-windows-amd64" ? "zip" : server ? "tar.gz" : "zip";+ const artifact = `${target}.${archive}`;writeFileSync(join(directory, artifact), target);writeFileSync(join(directory, `${target}.release.json`), JSON.stringify({schema: 2, version, revision, artifact, artifactSha256: hash(target),diff --git a/tests/release-automation.test.ts b/tests/release-automation.test.tsindex 214a56ee..7e34f6a7 100644--- a/tests/release-automation.test.ts+++ b/tests/release-automation.test.ts@@ -16,11 +16,20 @@ describe("release automation", () => {it("shares only an authored leading bilingual headline with the website", () => {const opening = "**Play together. Your turn!**\n\n**远程同乐,轮到你啦!**";expect(splitReleaseHeadline(`${opening}\n\n### 中文\n\n修复开播。`)).toEqual({- headline: { "zh-CN": "远程同乐,轮到你啦!", en: "Play together. Your turn!" },+ headline: { "zh-CN": { title: "远程同乐,轮到你啦!", description: "" }, en: { title: "Play together. Your turn!", description: "" } },notes: "### 中文\n\n修复开播。",});expect(splitReleaseHeadline(opening.replaceAll("\n\n", "\r\n\r\n\r\n")).headline)- .toEqual({ "zh-CN": "远程同乐,轮到你啦!", en: "Play together. Your turn!" });+ .toEqual({ "zh-CN": { title: "远程同乐,轮到你啦!", description: "" }, en: { title: "Play together. Your turn!", description: "" } });+ const explained = "**Play together. Your turn!**\n\nPiik now supports remote control and remote co-play.\n\n" ++ "**远程同乐,轮到你啦!**\n\nPiik 现已支持远程控制与远程同乐。";+ expect(splitReleaseHeadline(`${explained}\n\n### English\n\nSharing fixes.`)).toEqual({+ headline: {+ en: { title: "Play together. Your turn!", description: "Piik now supports remote control and remote co-play." },+ "zh-CN": { title: "远程同乐,轮到你啦!", description: "Piik 现已支持远程控制与远程同乐。" },+ },+ notes: "### English\n\nSharing fixes.",+ });for (const body of [undefined, "旧版本说明", "**只有一句**", "** **\n\n**English**","**Fixed** **disconnects**\n\n**Details**", `本次更新\n\n${opening}`, `### 中文\n\n${opening}`]) {expect(splitReleaseHeadline(body)).toEqual({ headline: null, notes: body ?? "" });@@ -103,7 +112,8 @@ describe("release automation", () => {}));expect(candidate).toMatchObject({ version: "v1.0.1", publish: false });commit("fix: repair playback\n\n## Release notes\n**Earlier theme**\n\n**旧主题**\n\n- Playback resumes after reconnecting.");- const opening = "**Play together. Your turn!**\n\n**远程同乐,轮到你啦!**";+ const opening = "**Play together. Your turn!**\n\nPiik now supports remote control and remote co-play.\n\n" ++ "**远程同乐,轮到你啦!**\n\nPiik 现已支持远程控制与远程同乐。";const next = commit(`feat: add a sharing option\n\n## Release notes\n${opening}\n\n- Choose a window to share.`);const notes = releaseNotes(root, "v1.1.0", next, "fixture/Piik");expect(notes.startsWith(opening)).toBe(true);@@ -234,9 +244,10 @@ describe("release automation", () => {const revision = "a".repeat(40);const run = () => spawnSync(process.execPath, [publisher, root, version, revision, "--dry-run"], { encoding: "utf8" });try {- for (const target of ["server", "server-linux-arm64", "windows-amd64", "linux-amd64", "linux-arm64", "darwin-arm64", "darwin-amd64"]) {+ for (const target of ["server", "server-linux-arm64", "server-windows-amd64", "windows-amd64", "linux-amd64", "linux-arm64", "darwin-arm64", "darwin-amd64"]) {const server = target.startsWith("server");- const artifact = `${target}.${server ? "tar.gz" : "zip"}`;+ const archive = target === "server-windows-amd64" ? "zip" : server ? "tar.gz" : "zip";+ const artifact = `${target}.${archive}`;writeFileSync(join(root, artifact), target);const descriptor = { schema: 2, version, revision, artifact, artifactSha256: sha(target),target, ...(server ? { manifest: `${target}.manifest.tsv`, manifestSha256: sha("manifest") } : {}) };@@ -246,8 +257,8 @@ describe("release automation", () => {}const complete = run();expect(complete.status, complete.stderr).toBe(0);- expect(JSON.parse(complete.stdout).targets).toHaveLength(7);- expect(JSON.parse(complete.stdout).files).toBe(7);+ expect(JSON.parse(complete.stdout).targets).toHaveLength(8);+ expect(JSON.parse(complete.stdout).files).toBe(8);const checksum = join(root, "windows-amd64.zip.sha256");const originalChecksum = readFileSync(checksum, "utf8");writeFileSync(checksum, "wrong checksum");diff --git a/tests/remote-input.test.ts b/tests/remote-input.test.tsindex 57fbd1fe..6d7b1214 100644--- a/tests/remote-input.test.ts+++ b/tests/remote-input.test.ts@@ -1,7 +1,17 @@import { expect, it, vi } from "vitest";-import { RemoteInputSession, picturePoint } from "../src/client/remote-control/input-session";+import { RemoteInputSession } from "../src/client/remote-control/input-session";+import { picturePoint, rotatePicturePoint, rotatePictureDelta, type VideoRotation } from "../src/client/media/video-geometry";import { InputRoute, type InputIdentity } from "../src/client/remote-control/input-route";-import { remoteInputStateSchema } from "../src/client/remote-control/protocol";+import { matchesRemoteShortcut, remoteInputStateSchema } from "../src/client/remote-control/protocol";++it("recognizes only the selected local release chord outside IME composition", () => {+ const chord = { code: "F9", ctrlKey: true, altKey: true, metaKey: false, shiftKey: false, isComposing: false };+ expect(matchesRemoteShortcut(chord, 9)).toBe(true);+ expect(matchesRemoteShortcut(chord, 10)).toBe(false);+ for (const changed of [{ ctrlKey: false }, { altKey: false }, { shiftKey: true }, { metaKey: true }, { isComposing: true }]) {+ expect(matchesRemoteShortcut({ ...chord, ...changed }, 9)).toBe(false);+ }+});class Channel extends EventTarget {readyState = "open";@@ -93,7 +103,7 @@ it("binds input to the current request and retires cancelled or replaced grants"it("maps only visible picture pixels when playback has letterboxing", () => {const video = { videoWidth: 1920, videoHeight: 1080,- style: { objectFit: "contain" },+ style: { objectFit: "contain" }, dataset: {},getBoundingClientRect: () => ({ left: 100, top: 50, width: 800, height: 600 }),} as HTMLVideoElement;expect(picturePoint(video, 500, 350)).toEqual({ x: 0.5, y: 0.5 });@@ -126,6 +136,25 @@ it("ends a pending request when its source becomes unavailable, even before thesession.dispose();});+it.each([+ [0, { x: .25, y: .75 }], [90, { x: .25, y: .25 }],+ [180, { x: .75, y: .25 }], [270, { x: .75, y: .75 }],+] as const)("maps rotated picture pixels and relative motion back to source axes (%s°)", (rotation, shown) => {+ const video = { videoWidth: 1920, videoHeight: 1080,+ style: { objectFit: "fill" }, dataset: { pictureRotation: String(rotation) },+ getBoundingClientRect: () => ({ left: 100, top: 50, width: 800, height: 600 }),+ } as unknown as HTMLVideoElement;+ expect(rotatePicturePoint({ x: .25, y: .75 }, rotation)).toEqual(shown);+ expect(picturePoint(video, 100 + shown.x * 800, 50 + shown.y * 600)).toEqual({ x: .25, y: .75 });+ expect(picturePoint(video, 99, 50)).toBeNull();+ const motion = rotatePictureDelta({ x: .1, y: -.2 }, rotation as VideoRotation);+ expect(rotatePictureDelta(motion, rotation, true)).toEqual({ x: .1, y: -.2 });+ video.style.objectFit = "contain";+ const sideways = rotation === 90 || rotation === 270;+ expect(picturePoint(video, sideways ? 101 : 500, sideways ? 350 : 51)).toBeNull();+ expect(picturePoint(video, 500, 350)).toEqual({ x: .5, y: .5 });+});+it("sends a control password only in the request and follows the App policy after cancellation", () => {const channel = new Channel();const session = new RemoteInputSession(channel as unknown as RTCDataChannel, () => {});diff --git a/tests/remote-touchpad.test.ts b/tests/remote-touchpad.test.tsindex 56aee4ae..1778f047 100644--- a/tests/remote-touchpad.test.ts+++ b/tests/remote-touchpad.test.ts@@ -1,6 +1,7 @@import { expect, it, vi } from "vitest";import { RemoteTouchpad } from "../src/client/remote-control/touchpad";import type { RemoteInputEvent } from "../src/client/remote-control/input-session";+import type { VideoRotation } from "../src/client/media/video-geometry";it("keeps taps, dragging, two-finger gestures and grant retirement distinct", () => {vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "performance"] });@@ -8,7 +9,7 @@ it("keeps taps, dragging, two-finger gestures and grant retirement distinct", ()const events: RemoteInputEvent[] = [], scroll: number[] = [];vi.stubGlobal("requestAnimationFrame", (callback: () => void) => setTimeout(callback, 16));vi.stubGlobal("cancelAnimationFrame", clearTimeout);- const touchpad = new RemoteTouchpad(() => ({ width: 200, height: 100 }),+ const touchpad = new RemoteTouchpad(() => ({ width: 200, height: 100, rotation: 0 }),event => events.push(event), delta => scroll.push(delta), () => {}, { scale: 1, transform: () => {}, visiblePosition: position => position });touchpad.down(1, 20, 20); touchpad.up(1);expect(events).toEqual([{ type: "move", x: .5, y: .5 },@@ -55,7 +56,7 @@ it("keeps pinch/pan local and never turns the remaining finger into a remote clitry {const input = vi.fn(), scroll = vi.fn(), transform = vi.fn();const viewport = { scale: 1, transform, visiblePosition: (position: { x: number; y: number }) => position };- const pad = new RemoteTouchpad(() => ({ width: 200, height: 100 }), input, scroll, () => {}, viewport);+ const pad = new RemoteTouchpad(() => ({ width: 200, height: 100, rotation: 0 }), input, scroll, () => {}, viewport);pad.down(1, 40, 50); pad.down(2, 160, 50);input.mockClear();pad.move(1, 10, 50); pad.move(2, 190, 50);@@ -86,3 +87,22 @@ it("keeps pinch/pan local and never turns the remaining finger into a remote cliexpect(transform).not.toHaveBeenCalled();} finally { vi.useRealTimers(); vi.unstubAllGlobals(); }});++it.each([+ [0, .75, .5], [90, .5, .25], [180, .25, .5], [270, .5, .75],+] as const)("keeps touch motion aligned with the rotated picture and releases a held drag (%s°)", (rotation, x, y) => {+ vi.useFakeTimers();+ try {+ const events: RemoteInputEvent[] = [];+ const pad = new RemoteTouchpad(() => ({ width: 200, height: 100, rotation: rotation as VideoRotation }),+ event => events.push(event), () => {}, () => {}, { scale: 1, transform: () => {}, visiblePosition: position => position });+ pad.down(1, 20, 20);+ vi.advanceTimersByTime(500);+ pad.move(1, 70, 20);+ expect(events.at(-1)).toEqual({ type: "move", x, y });+ pad.reset();+ expect(events.at(-1)).toEqual({ type: "button", button: 0, down: false });+ pad.up(1);+ expect(events.filter(event => event.type === "button")).toHaveLength(2);+ } finally { vi.useRealTimers(); }+});diff --git a/tests/room-preferences.test.ts b/tests/room-preferences.test.tsindex 0a31943d..3aec88c2 100644--- a/tests/room-preferences.test.ts+++ b/tests/room-preferences.test.ts@@ -15,10 +15,12 @@ function storage() {it("keeps independent room-tool choices across reads without storing private runtime fields", () => {const values = storage();- saveRoomPreferences({ pictureFit: "cover", routePreference: "p2p", keyboardPage: "text", combineKeys: true });- saveRoomPreferences({ interactionEffects: false, remoteControlMode: "password" });- expect(readRoomPreferences()).toMatchObject({ pictureFit: "cover", routePreference: "p2p", keyboardPage: "text",- combineKeys: true, interactionEffects: false, remoteControlMode: "password" });+ saveRoomPreferences({ pictureFit: "cover", pictureRotation: 270, routePreference: "p2p", keyboardPage: "text", combineKeys: true });+ saveRoomPreferences({ interactionEffects: false, remoteControlMode: "password", remoteReleaseKey: 9, remoteStopKey: 8,+ voiceListeningVolume: 1.5, voiceInput: { deviceId: "", volume: 2, voiceProcessing: true } });+ expect(readRoomPreferences()).toMatchObject({ pictureFit: "cover", pictureRotation: 270, routePreference: "p2p", keyboardPage: "text",+ combineKeys: true, interactionEffects: false, remoteControlMode: "password", remoteReleaseKey: 9, remoteStopKey: 8,+ voiceListeningVolume: 1.5, voiceInput: { deviceId: "", volume: 2, voiceProcessing: true } });// Storage accepts only the preference contract, even if a caller supplies a// room snapshot with credentials, text or actual held input by mistake.@@ -31,6 +33,8 @@ it("keeps independent room-tool choices across reads without storing private runfor (const field of ["password", "grant", "text", "modifiers", "controller"]) expect(saved).not.toHaveProperty(field);expect([...values.values()][0]).not.toContain("private");expect(readRoomPreferences().pictureFit).toBe("cover");+ values.set("piik:room-preferences:v1", JSON.stringify({ pictureFit: "cover", pictureRotation: 45 }));+ expect(readRoomPreferences()).toMatchObject({ pictureFit: "cover", pictureRotation: 0 });});it("rejects malformed saved data and invalid patches while retaining useful defaults", () => {diff --git a/tests/room-voice-client.test.ts b/tests/room-voice-client.test.tsnew file mode 100644index 00000000..fc4fb712--- /dev/null+++ b/tests/room-voice-client.test.ts@@ -0,0 +1,223 @@+import { afterEach, expect, it, vi } from "vitest";+import { RoomVoiceSession } from "../src/client/room-voice/session";+import { clientMessageSchema, type ClientMessage, type RoomVoiceState } from "../src/shared/protocol";++afterEach(() => vi.unstubAllGlobals());++function microphone() {+ const track = { readyState: "live", contentHint: "", onended: null as null | (() => void),+ stop: vi.fn(() => { track.readyState = "ended"; }) };+ const stream = { getTracks: () => [track], getAudioTracks: () => [track] } as unknown as MediaStream;+ return { track, stream };+}+function room(revision: number, joined = true, publication = false, enabled = true): RoomVoiceState {+ return { type: "room-voice-state", revision, enabled, hostPeerId: "host",+ members: [{ peerId: "self", connected: true, joined, upstream: { kind: "none" },+ ...(publication ? { publicationId: "publication" } : {}) }],+ publications: publication ? [{ id: "publication", peerId: "self" }] : [], connections: [], unavailable: [] };+}+function setup() {+ const resume = vi.fn(async () => {});+ class Context {+ currentTime = 0;+ createGain() { return { gain: { value: 1, setTargetAtTime: vi.fn() }, connect: vi.fn() }; }+ createAnalyser() { return { fftSize: 256, getFloatTimeDomainData: vi.fn() }; }+ createMediaStreamSource() { return { connect: vi.fn() }; }+ createMediaStreamDestination() { return { stream: microphone().stream }; }+ resume = resume;+ close = async () => {};+ }+ vi.stubGlobal("AudioContext", Context);+ const messages: ClientMessage[] = [];+ const session = new RoomVoiceSession(message => { messages.push(message); return true; }, { iceServers: [] });+ session.authenticated("self", "viewer"); session.receive(room(1));+ return { session, messages, resume };+}++it("clears a transport failure after the committed voice transports actually connect", () => {+ const { session } = setup();+ vi.spyOn(session.endpoint, "reconcile").mockResolvedValue();+ let connected = false;+ vi.spyOn(session.endpoint, "connected", "get").mockImplementation(() => connected);+ const pending = { ...room(2), connections: [{ connectionId: "repair_connection_123", parentPeerId: "host", childPeerId: "self",+ transport: "peer" as const, pending: true, revision: 2, send: [], receive: [] }] };+ session.receive({ type: "room-voice-error", code: "connection-unavailable" });+ session.receive(pending);+ expect(session.getSnapshot().error).toBe("transport");+ session.receive({ ...pending, revision: 3, connections: [{ ...pending.connections[0]!, pending: false }] });+ expect(session.getSnapshot().error).toBe("transport");+ connected = true;+ session.receive({ ...pending, revision: 4, connections: [{ ...pending.connections[0]!, pending: false }] });+ expect(session.getSnapshot().error).toBeNull();+ session.close();+});++it("captures only on explicit action and waits for the server publication acknowledgement", async () => {+ const mic = microphone(), getUserMedia = vi.fn(async () => mic.stream);+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });+ const { session, messages, resume } = setup();+ try {+ expect(getUserMedia).not.toHaveBeenCalled();+ await session.startMicrophone();+ expect(resume.mock.invocationCallOrder[0]).toBeLessThan(getUserMedia.mock.invocationCallOrder[0]!);+ expect(getUserMedia).toHaveBeenCalledWith({ audio: expect.objectContaining({ echoCancellation: true, channelCount: 1 }), video: false });+ expect(session.getSnapshot()).toMatchObject({ microphone: false, capturePending: true });+ expect(messages).toContainEqual({ type: "room-voice-command", command: { action: "publish" } });+ session.receive(room(2, true, true));+ expect(session.getSnapshot()).toMatchObject({ microphone: true, capturePending: false });+ expect(mic.track.stop).not.toHaveBeenCalled();+ // Source sharing has no call into this owner. An ordinary authority update+ // with the same publication must retain the actual microphone stream.+ session.receive(room(3, true, true));+ expect(session.microphone).toBe(true);+ mic.track.onended?.();+ expect(session.microphone).toBe(false);+ expect(messages.at(-1)).toEqual({ type: "room-voice-command", command: { action: "unpublish", publicationId: "publication" } });+ expect(messages.every(message => clientMessageSchema.safeParse(message).success)).toBe(true);+ } finally { session.close(); }+});++it("explains an unavailable microphone API without requesting a publication", async () => {+ vi.stubGlobal("navigator", {});+ const { session, messages } = setup();+ try {+ await session.startMicrophone();+ expect(session.getSnapshot()).toMatchObject({ error: "microphoneUnavailable", capturePending: false, microphone: false });+ expect(messages.some(message => message.type === "room-voice-command")).toBe(false);+ } finally { session.close(); }+});++it.each(["cancel", "leave", "close-room", "disconnect", "close"] as const)("stops a late microphone result after %s without reviving authority", async action => {+ let finish!: (stream: MediaStream) => void;+ const getUserMedia = vi.fn(() => new Promise<MediaStream>(resolve => { finish = resolve; }));+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });+ const { session, messages } = setup();+ const starting = session.startMicrophone();+ await vi.waitFor(() => expect(getUserMedia).toHaveBeenCalledOnce());+ if (action === "cancel") session.stopMicrophone();+ if (action === "leave") { session.receive(room(2, false)); session.receive(room(3, true)); }+ if (action === "close-room") { session.receive(room(2, false, false, false)); session.receive(room(3, true)); }+ if (action === "disconnect") session.disconnected();+ if (action === "close") session.close();+ const mic = microphone(); finish(mic.stream); await starting;+ expect(mic.track.stop).toHaveBeenCalled();+ expect(session.getSnapshot()).toMatchObject({ microphone: false, capturePending: false });+ expect(messages.some(message => message.type === "room-voice-command" && message.command.action === "publish")).toBe(false);+ session.close();+});++it("retires an acknowledged publication after cancellation and never attaches it to a newer capture", async () => {+ const mic = microphone(), getUserMedia = vi.fn(async () => mic.stream);+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });+ const { session, messages } = setup();+ await session.startMicrophone(); session.stopMicrophone();+ await session.startMicrophone();+ expect(getUserMedia).toHaveBeenCalledOnce();+ session.receive(room(2, true, true));+ expect(session.microphone).toBe(false);+ expect(mic.track.stop).toHaveBeenCalled();+ expect(messages.at(-1)).toEqual({ type: "room-voice-command", command: { action: "unpublish", publicationId: "publication" } });+ expect(session.getSnapshot().capturePending).toBe(false);+ session.close();+});++it("closes capture and clears pending publication when the Host closes room voice", async () => {+ const mic = microphone(), replacement = microphone();+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia: vi.fn()+ .mockResolvedValueOnce(mic.stream).mockResolvedValueOnce(replacement.stream) } });+ const { session } = setup();+ await session.startMicrophone();+ expect(session.getSnapshot().capturePending).toBe(true);+ session.receive(room(2, false, false, false));+ expect(mic.track.stop).toHaveBeenCalled();+ expect(session.getSnapshot()).toMatchObject({ microphone: false, capturePending: false });+ session.receive(room(3));+ await session.startMicrophone(); session.receive(room(4, true, true));+ expect(session.microphone).toBe(true);+ session.receive(room(5, false, false, false));+ expect(replacement.track.stop).toHaveBeenCalled();+ expect(session.getSnapshot()).toMatchObject({ microphone: false, capturePending: false });+ session.receive(room(6, true));+ expect(session.microphone).toBe(false);+ session.close();+});++it("pauses local listening independently of microphone and per-person mute", async () => {+ const mic = microphone(), getUserMedia = vi.fn(async () => mic.stream);+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });+ const { session, messages } = setup();+ try {+ await session.startMicrophone(); session.receive(room(2, true, true));+ session.setListeningVolume(2);+ session.muteVoice("friend");+ session.deafen(true);+ expect(mic.track.stop).not.toHaveBeenCalled();+ expect(session.getSnapshot()).toMatchObject({ deafened: true, microphone: true, capturePending: false, listeningVolume: 2 });+ expect(messages.some(message => message.type === "room-voice-command" && message.command.action === "unpublish")).toBe(false);+ session.deafen(false);+ expect(session.getSnapshot()).toMatchObject({ deafened: false, microphone: true, listeningVolume: 2, input: { volume: 1 } });+ expect(session.getSnapshot().muted.has("friend")).toBe(true);+ expect(getUserMedia).toHaveBeenCalledOnce();+ } finally { session.close(); }+});++it("keeps the current microphone on a failed input change and replaces only local input on success", async () => {+ const first = microphone(), replacement = microphone();+ const getUserMedia = vi.fn().mockResolvedValueOnce(first.stream)+ .mockRejectedValueOnce(new DOMException("Device busy", "NotReadableError")).mockResolvedValueOnce(replacement.stream);+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });+ const { session, messages } = setup();+ await session.startMicrophone(); session.receive(room(2, true, true));+ session.setVolume(.5);+ await session.configureInput({ deviceId: "other", voiceProcessing: false });+ expect(session.getSnapshot().input).toMatchObject({ deviceId: "", voiceProcessing: true, volume: .5 });+ expect(first.track.stop).not.toHaveBeenCalled();+ await session.configureInput({ deviceId: "other", voiceProcessing: false });+ expect(getUserMedia).toHaveBeenLastCalledWith({ audio: expect.objectContaining({ deviceId: { exact: "other" }, noiseSuppression: false }), video: false });+ expect(first.track.stop).toHaveBeenCalledOnce();+ expect(replacement.track.stop).not.toHaveBeenCalled();+ expect(session.getSnapshot()).toMatchObject({ microphone: true, capturePending: false, input: { deviceId: "other", voiceProcessing: false, volume: .5 } });+ expect(messages.filter(message => message.type === "room-voice-command")).toEqual([{ type: "room-voice-command", command: { action: "publish" } }]);+ session.close();+ expect(replacement.track.stop).toHaveBeenCalledOnce();+});++it("keeps person volume local across publication changes and retires it with the participant", () => {+ const { session, messages } = setup();+ const friend = { peerId: "friend", connected: true, joined: true, upstream: { kind: "none" as const } };+ session.receive({ ...room(2), members: [...room(2).members, friend] });+ session.setPeerVolume("friend", 2);+ session.setListeningVolume(.5);+ session.muteVoice("friend");+ session.receive({ ...room(3), members: [...room(3).members, { ...friend, publicationId: "friend-publication" }],+ publications: [{ peerId: "friend", id: "friend-publication" }] });+ expect(session.getSnapshot().peerVolumes.get("friend")).toBe(2);+ expect(session.getSnapshot().muted.has("friend")).toBe(true);+ expect(session.getSnapshot().listeningVolume).toBe(.5);+ expect(messages).toHaveLength(0);+ session.disconnected();+ session.authenticated("self", "viewer");+ session.receive({ ...room(3), members: [...room(3).members, friend] });+ expect(session.getSnapshot().peerVolumes.get("friend")).toBe(2);+ expect(session.getSnapshot().muted.has("friend")).toBe(true);+ session.receive(room(4));+ expect(session.getSnapshot().peerVolumes.size).toBe(0);+ expect(session.getSnapshot().muted.has("friend")).toBe(false);+ session.close();+});++it("preserves a valid microphone request and source when an unrelated room voice edge fails", async () => {+ let finish!: (stream: MediaStream) => void;+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia: () => new Promise<MediaStream>(resolve => { finish = resolve; }) } });+ const { session } = setup();+ const starting = session.startMicrophone();+ await vi.waitFor(() => expect(finish).toBeTypeOf("function"));+ session.receive({ type: "room-voice-error", code: "connection-unavailable" });+ const mic = microphone(); finish(mic.stream); await starting;+ session.receive(room(2, true, true));+ expect(session.microphone).toBe(true);+ session.receive({ type: "room-voice-error", code: "connection-unavailable" });+ expect(session.microphone).toBe(true);+ expect(mic.track.stop).not.toHaveBeenCalled();+ session.close();+});diff --git a/tests/route-tree.test.ts b/tests/route-tree.test.tsindex 5fbd6784..b6549ebb 100644--- a/tests/route-tree.test.ts+++ b/tests/route-tree.test.ts@@ -434,8 +434,8 @@ describe("RouteTree", () => {expect(html.match(/class="lr-route-hit"/g)).toHaveLength(1);expect(html).toContain('<button class="lr-route-hit" type="button"');- expect(html).toContain('aria-label="Bob · 显示连接详情"');- expect(html).not.toContain('aria-label="Alice · 显示连接详情"');+ expect(html).toContain('aria-label="Bob · 连接详情"');+ expect(html).not.toContain('aria-label="Alice · 连接详情"');});it("keeps truncated Host, unselectable and pending names in visible tooltip targets", () => {@@ -454,7 +454,7 @@ describe("RouteTree", () => {// The hidden topology list retains every full identity before client// layout measures clipping; generic static spans must not be named.expect(html).toContain(`${name}${suffix}`);- if (index === 2) expect(targets[index]).toContain(`aria-label="${name}${suffix} · 显示连接详情"`);+ if (index === 2) expect(targets[index]).toContain(`aria-label="${name}${suffix} · 连接详情"`);else expect(targets[index]).not.toContain("aria-label=");expect(targets[index]).toMatch(/class="lr-route-label lr-route-name[^>]*>[^<]*…<\/span>/);expect(targets[index]).toContain('popover="manual"');diff --git a/tests/signaling-admission.test.ts b/tests/signaling-admission.test.tsindex df7ade79..8d2f72f8 100644--- a/tests/signaling-admission.test.ts+++ b/tests/signaling-admission.test.ts@@ -38,6 +38,44 @@ function fixture(role: "host" | "viewer" = "host") {}describe("room authentication and site admission", () => {+ it("replays only this page's relay intent after the authenticated page's ordinary capacity report", async () => {+ const { signal, sockets, events } = fixture("viewer");+ const wire = JSON.parse(readFileSync(new URL("./fixtures/wire-samples.json", import.meta.url), "utf8"));+ const authenticated = JSON.parse(wire.serverMessages.find(+ (sample: { name: string }) => sample.name === "authenticated-viewer-minimal").json);+ events.onMessage.mockImplementation(message => {+ if (message.type === "authenticated") signal.send({ type: "relay-capacity", downstreamEdges: 3 });+ });+ sockets[0]!.receive(authenticated);+ expect(signal.relayVolunteerRequest).toBeNull();+ expect(sockets[0]!.send.mock.calls.map(([raw]) => JSON.parse(raw).type)).not.toContain("set-relay-volunteer");+ expect(signal.setRelayVolunteer(true, 20)).toBe(true);+ sockets[0]!.receive({ type: "relay-volunteer", enabled: true, capacity: 20 });+ for (const enabled of [true, false]) {+ if (!enabled) {+ signal.setRelayVolunteer(false, 20);+ // An earlier enabled acknowledgement must not restore consent while+ // the newer withdrawal is in flight or replay it after socket loss.+ sockets.at(-1)!.receive({ type: "relay-volunteer", enabled: true, capacity: 20 });+ expect(signal.relayVolunteerRequest?.enabled).toBe(false);+ sockets.at(-1)!.receive({ type: "relay-volunteer", enabled: false, capacity: 2 });+ }+ sockets.at(-1)!.dispatchEvent(Object.assign(new Event("close"), { code: 1006 }));+ await vi.advanceTimersByTimeAsync(800);+ const socket = sockets.at(-1)!;+ socket.dispatchEvent(new Event("open"));+ socket.receive(authenticated);+ const reports = socket.send.mock.calls.map(([raw]) => JSON.parse(raw)).filter(message =>+ message.type === "relay-capacity" || message.type === "set-relay-volunteer");+ expect(reports).toEqual([+ { type: "relay-capacity", downstreamEdges: 3 },+ { type: "set-relay-volunteer", enabled, capacity: 20 },+ ]);+ }+ signal.stop();+ expect(signal.relayVolunteerRequest).toBeNull();+ });+it("opts into audio presence after discovery and replays subscriptions and Host intent on reconnect", async () => {const wire = JSON.parse(readFileSync(new URL("./fixtures/wire-samples.json", import.meta.url), "utf8"));const auth = (role: string) => JSON.parse(wire.serverMessages.find(diff --git a/tests/viewer-audio.test.ts b/tests/viewer-audio.test.tsindex 8245e953..b88d0311 100644--- a/tests/viewer-audio.test.ts+++ b/tests/viewer-audio.test.ts@@ -152,6 +152,37 @@ describe("Viewer local audio", () => {audio.dispose();});+ it("shares a lent context while muting and retiring each voice sink independently", () => {+ const context = new PlaybackContext();+ const gains: PlaybackContext["gain"][] = [];+ vi.spyOn(context, "createGain").mockImplementation(() => {+ const gain = { gain: { value: 1 }, connect: vi.fn(), disconnect: vi.fn() };+ gains.push(gain); return gain;+ });+ const elements = [new PlaybackVideo(), new PlaybackVideo()];+ const outputs = elements.map(element => new ViewerAudio(element as unknown as HTMLAudioElement,+ vi.fn(), () => context as unknown as AudioContext, 4));+ outputs.forEach(output => { output.bind(new AudioStream([audioTrack()]) as unknown as MediaStream); output.setLevel(2); });+ context.start();+ expect(PlaybackContext.instances).toHaveLength(1);+ expect(gains.map(gain => gain.gain.value)).toEqual([2, 2]);+ expect(elements.every(element => element.muted)).toBe(true);+ outputs[0].setLevel(4);+ expect(gains.map(gain => gain.gain.value)).toEqual([4, 2]);+ outputs[0].setMuted(true);+ expect(gains.map(gain => gain.gain.value)).toEqual([0, 2]);+ outputs[0].dispose();+ expect(gains[0].disconnect).toHaveBeenCalledOnce();+ expect(context.close).not.toHaveBeenCalled();+ outputs[1].setLevel(0);+ expect(gains[1].gain.value).toBe(0);+ outputs[1].setLevel(1.5);+ expect(gains[1].gain.value).toBe(1.5);+ outputs[1].dispose();+ expect(context.close).not.toHaveBeenCalled();+ void context.close();+ });+it("uses current preferences after resume and ignores completions after disposal", async () => {const video = new PlaybackVideo();const onChange = vi.fn();