Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

feat(app): add camera sharing and Host microphone controls

AAAa9b7507488b0
diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml
index 62d80831..9d0d1ea5 100644
--- a/.github/workflows/website.yml
+++ b/.github/workflows/website.yml
@@ -20,7 +20,10 @@ jobs:
deploy:
if: >-
github.ref == 'refs/heads/main' &&
- (github.event_name == 'workflow_dispatch' || github.event.workflow_run.event == 'push')
+ (github.event_name == 'workflow_dispatch' ||
+ (github.event.workflow_run.event == 'push' &&
+ github.event.workflow_run.head_branch == 'main' &&
+ github.event.workflow_run.conclusion == 'success'))
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
@@ -33,7 +36,7 @@ jobs:
steps:
- uses: actions/checkout@v6
with:
- ref: main
+ ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- uses: actions/setup-node@v6
with:
node-version-file: .node-version
@@ -49,5 +52,16 @@ jobs:
with:
path: build/site
retention-days: 1
+ - name: Keep older runs from replacing the current website
+ id: current
+ shell: bash
+ run: |
+ git fetch --no-tags origin main
+ if [ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ]; then
+ echo "deploy=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "Skipped an outdated website build. Run Website again for current main." >> "$GITHUB_STEP_SUMMARY"
+ fi
- uses: actions/deploy-pages@v4
+ if: steps.current.outputs.deploy == 'true'
id: deployment
diff --git a/README.md b/README.md
index 7e44b95b..58e85d99 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ watch in their browsers.
## Features
- **Watch without installing.** Friends join by invitation in a desktop or mobile browser.
-- **Share from Piik App or an existing Piik site.** Capture a screen, window or browser tab; available sources and audio depend on the platform.
+- **Share from Piik App or an existing Piik site.** Choose a screen, window, browser tab or camera; available sources and audio depend on the platform.
- **Direct connections first.** Media travels between participants where possible (P2P). A self-hosted server can provide automatic media forwarding (SFU) as a fallback.
- **Rooms you control.** Invitations, room codes and optional room passwords, for one host and up to 20 viewers.
- **Flexible viewing.** Light and dark themes, playback controls, picture-in-picture and a connection topology view.
@@ -55,7 +55,7 @@ you can also create a room in the online version.
| Start here | What you need to do |
| --- | --- |
-| [Use Piik online](https://demo.piik.tv) | Open it in a desktop browser to create a room and share. |
+| [Use Piik online](https://demo.piik.tv) | Share from a desktop browser, or choose Camera on a phone with browser camera support. |
| [Download Piik App](https://piik.tv/#download) | Extract and open the App, choose **Public invite**, then **Open Piik** to create a temporary room. |
| [Host your own site](./docs/operations/self-hosting.md) | Advanced: deploy Piik Server on a Linux x64 server with your own domain, then connect through Piik App or a browser. |
@@ -64,6 +64,9 @@ 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.
+
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.
The App offers a local room, a temporary public link, or a connection to your own
diff --git a/README.zh-CN.md b/README.zh-CN.md
index a14ebf3a..511d8397 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -30,7 +30,7 @@ Piik 是一个免费开源的屏幕共享工具,适合游戏围观、一起看
## 功能
- **观看无须安装。** 朋友通过邀请链接,用电脑或手机浏览器加入。
-- **用 Piik App 或已有 Piik 站点分享。** 支持屏幕、窗口和浏览器标签页;可选来源与音频能力取决于平台。
+- **用 Piik App 或已有 Piik 站点分享。** 支持屏幕、窗口、浏览器标签页和摄像头;可选来源与音频能力取决于平台。
- **优先直接连接。** 画面优先在设备之间传输(P2P),自建站点可启用媒体转发(SFU)自动兜底。
- **房间由你管理。** 支持邀请链接、房间号和可选的房间密码,一位房主、最多 20 位观众。
- **灵活的观看方式。** 支持深浅主题、播放控制、画中画和连接拓扑查看。
@@ -52,7 +52,7 @@ Piik 是一个免费开源的屏幕共享工具,适合游戏围观、一起看
| 从这里开始 | 需要做什么 |
| --- | --- |
-| [使用在线版](https://demo.piik.tv) | 在电脑浏览器打开,直接创建房间并分享。 |
+| [使用在线版](https://demo.piik.tv) | 用电脑浏览器分享画面;手机浏览器支持摄像头访问时,也可选择摄像头分享。 |
| [下载 Piik App](https://piik.tv/?lang=zh-CN#download) | 解压并启动 Piik App,选择**公网邀请**,点击**进入 Piik**,创建临时房间。 |
| [部署自己的站点](./docs/operations/self-hosting.zh-CN.md) | 进阶使用:在 Linux x64 服务器上部署 Piik Server、配置自己的域名,再用 Piik App 或浏览器连接。 |
@@ -61,6 +61,8 @@ Piik 是一个免费开源的屏幕共享工具,适合游戏围观、一起看
1. 点击**开始分享**,选择要分享的画面和声音。
2. 点击**复制邀请链接**,发给朋友。分享期间保持标签页打开。
+分享时还可以开启**麦克风**解说,在旁边的设置中选择设备、调整人声音量。
+
Piik 默认跟随系统语言,中文系统显示简体中文,其他语言显示英文。
顶部的 **中 / EN / ✦** 可切换中英文或体验纯视觉模式。
Piik App 提供本地房间、临时公网邀请和连接已有站点三种模式,分享期间需保持 App 运行。
diff --git a/docs/README.md b/docs/README.md
index 5cad289f..3ef26b14 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -98,6 +98,7 @@ and [website preview and publishing](./operations/website.md).
| Host and viewer behavior | [Presentation and lifecycle](./standards/presentation-lifecycle.md) |
| Why a design was chosen | [Architecture decisions](./adr/) |
| Measurements and platform limits | [Research](./research/) and [verification status](./verification-status.md) |
+| Camera and Host microphone candidate | [Capture scope and limits](./research/camera-and-microphone.md) |
## Shared conventions
diff --git a/docs/adr/0009-optional-nat-prediction.md b/docs/adr/0009-optional-nat-prediction.md
index 98d8c765..72500b76 100644
--- a/docs/adr/0009-optional-nat-prediction.md
+++ b/docs/adr/0009-optional-nat-prediction.md
@@ -19,10 +19,10 @@ connection acquisition reuses the route controller's existing opportunity ledger
## Decision
-1. `NAT_PREDICTION_ENABLED` defaults to `false`. A disabled deployment does not
- expose the Host control and the server rejects NAT prediction in the room
- policy. An enabled deployment exposes `NAT traversal`; the pre-share switch
- defaults on, remains Host-controllable, locks while sharing, and is not
+1. `NAT_PREDICTION_ENABLED` defaults to `false`. A disabled deployment shows the
+ Host control locked off and the server rejects NAT prediction in the room
+ policy. An enabled deployment exposes `Enhanced NAT traversal`; the pre-share
+ switch defaults on, remains Host-controllable, locks while sharing, and is not
persisted beyond that share generation.
2. An enabled Site derives ports 3479 and 3480 from its first ordinary STUN
authority on UDP 3478. Public-link App mode instead supplies one ordinary
diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md
index cf54b67c..776a68a9 100644
--- a/docs/guide/getting-started.md
+++ b/docs/guide/getting-started.md
@@ -41,15 +41,19 @@ With just a four-digit room code, open the same Piik site and choose
The host decides whether code entry is available; ask for an invitation link if
you cannot join by code.
+Hosts can turn off **Skip passwords** beside the link to copy the ordinary room
+address. Visitors follow the site's and room's access checks; invite-only rooms
+require the invitation credential. This switch does not revoke existing invites.
+
If an old link no longer works, ask the host for the current invitation.
App Local rooms and temporary public invitations end when that App run stops.
## Use Piik online
-1. Open [demo.piik.tv](https://demo.piik.tv) in a desktop browser that supports
- screen sharing.
-2. Select **Start sharing**, choose a screen, window or tab, and enable audio if
- needed and offered by the browser.
+1. Open [demo.piik.tv](https://demo.piik.tv) in your browser.
+2. Select **Start sharing**, then **Browser** for a screen, window or tab, or
+ **Camera** where your computer or phone browser supports it. Enable source
+ audio if the picker offers it.
3. Confirm the preview and select **Copy invite link**. Open that link on a
second device or send it to a friend.
4. Select **Stop sharing** when finished.
@@ -67,7 +71,7 @@ restrictive networks may load the page but block video.
The launcher opens in your system browser.
3. Choose **Public invite** for friends outside your local network, then select
**Open Piik**. Other modes are explained below.
-4. Choose **Start sharing**, then select **Browser**, **Apps / Windows**, or
+4. Choose **Start sharing**, then select **Browser**, **Camera**, **Apps / Windows**, or
**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.
@@ -91,8 +95,12 @@ See the [App guide](../../cmd/piik-app/README.md) for package and runtime detail
| **Public invite** | Friends are elsewhere and you want a temporary invitation. | Needs Internet access. The public address lasts for this App run. |
| **Connect to Site** | Your group already has a Piik site. | Enter its address; the App adds capture capabilities to the site's sharing page. |
+For Local room and Public invite, expand **Site passphrase** to set an optional
+access passphrase.
+
For **Connect to Site**, enter the full site address, such as
-`https://demo.piik.tv`, add its passphrase if required, then choose **Open Piik**.
+`https://demo.piik.tv`, then choose **Open Piik**. Enter the site's passphrase
+on the page that opens if asked.
After opening the site through the App once, the same browser remembers that
entry. Keep the App running with that site configured and you can visit the
address directly. **Start sharing** opens the selector; choose **Apps / Windows**
@@ -114,9 +122,10 @@ or [Piik App](#share-with-piik-app). Hosting a site yourself is an advanced opti
follow the [self-hosting guide](../operations/self-hosting.md) for server, HTTPS
and network setup.
-1. Open your group's Piik site on your computer. Enter its site passphrase if asked.
-2. Choose **Start sharing**. In the browser picker, select the screen, window or
- tab you want friends to see, and enable audio if offered.
+1. Open your group's Piik site. Enter its site passphrase if asked.
+2. Choose **Start sharing**, then **Browser** to select a screen, window or tab
+ in the browser picker, or **Camera** where your computer or phone browser supports it.
+ Enable source audio if the picker offers it.
3. Check the preview, then choose **Copy invite link** and send it to your friends.
4. Keep the sharing tab open. Use **Pause sharing**, **Switch source**, or
**Stop sharing** when you need them.
@@ -130,6 +139,21 @@ The site manages rooms and invitations; the App supplies native capture.
If its operator has enabled SFU forwarding, turn off **Privacy mode** before
sharing to allow that fallback. The project's online site uses P2P only.
+## Add your voice
+
+While sharing, select **Microphone** below the picture and
+allow microphone access. Select it again to mute. Open **Sharing settings** 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.
+
## When something gets in the way
For sound, capture, startup or playback issues, see [Troubleshooting](./troubleshooting.md).
diff --git a/docs/guide/getting-started.zh-CN.md b/docs/guide/getting-started.zh-CN.md
index da8654af..ef3ef23c 100644
--- a/docs/guide/getting-started.zh-CN.md
+++ b/docs/guide/getting-started.zh-CN.md
@@ -38,13 +38,17 @@ Piik 支持一位房主分享屏幕,最多 20 位受邀观众通过浏览器
你可能需要站点口令和房间密码。能否通过房间号加入由房主决定;
无法加入时,请朋友发邀请链接。
+房主可关闭链接旁的 **免密邀请**,复制普通房间地址。访客打开地址后按站点和房间设置
+验证口令或密码;仅限邀请的房间需保留凭证。这个开关不会撤销已发出的邀请。
+
旧链接失效了,就请房主重新发一份当前邀请。
App 的本地房间和临时公网邀请会随本次 App 退出而结束。
## 使用在线版
-1. 在支持屏幕共享的电脑浏览器中打开 [demo.piik.tv](https://demo.piik.tv)。
-2. 点击 **开始分享**,选择屏幕、窗口或标签页;如需声音且浏览器提供该选项,启用音频。
+1. 在浏览器中打开 [demo.piik.tv](https://demo.piik.tv)。
+2. 点击 **开始分享**,选择 **浏览器** 分享屏幕、窗口或标签页;也可在电脑或手机上选择
+ **摄像头**(需浏览器支持访问)。如需来源声音且选择器提供该选项,启用音频。
3. 确认预览后,点击 **复制邀请链接**,用另一台设备打开,或发送给朋友。
4. 分享结束后,点击 **停止分享**。
@@ -60,7 +64,7 @@ App 的本地房间和临时公网邀请会随本次 App 退出而结束。
启动页会在系统浏览器里打开。
3. 邀请不在同一局域网的朋友时,选择 **公网邀请**,再点击 **进入 Piik**。
其他模式的用途见下表。
-4. 点击 **开始分享**,按可用选项选择 **浏览器**、**程序 / 窗口** 或 **屏幕**,
+4. 点击 **开始分享**,按可用选项选择 **浏览器**、**摄像头**、**程序 / 窗口** 或 **屏幕**,
然后选定要分享的画面与声音。
5. 复制房间邀请发给朋友。分享期间保持 App 和分享标签页打开。
@@ -83,8 +87,10 @@ Linux 原生采集还需要[系统组件](../../native/capture/linux/README.md)
| **公网邀请** | 朋友在别处,想临时发个邀请。 | 需要互联网连接;公网地址只在本次 App 运行期间有效。 |
| **连接站点** | 你们已经有一个 Piik 站点。 | 输入站点地址,在原有分享页面使用 App 的采集能力。 |
-使用 **连接站点** 时,填写完整地址,例如 `https://demo.piik.tv`;如果站点有访问口令,
-也一并填写,然后点击 **进入 Piik**。通过 App 打开过一次后,同一浏览器会记住这个入口。
+本地房间和公网邀请可展开 **站点口令** 设置可选的访问口令。
+
+使用 **连接站点** 时,填写完整地址,例如 `https://demo.piik.tv`,然后点击 **进入 Piik**。
+如果站点要求访问口令,在打开的站点页面输入。通过 App 打开过一次后,同一浏览器会记住这个入口。
保持 App 运行并使用该站点配置,之后就能直接访问网址。点击 **开始分享**,
在选择器里选 **程序 / 窗口** 或 **屏幕**,即可使用 App 采集。
浏览器询问本地网络权限时,请允许访问。换浏览器、使用无痕窗口或清除站点数据后,
@@ -101,9 +107,9 @@ Linux 原生采集还需要[系统组件](../../native/capture/linux/README.md)
也可以使用项目提供的[在线版](#使用在线版)或 [Piik App](#用-piik-app-分享)。
自建站点属于进阶操作,服务器、HTTPS 和网络端口的配置步骤见[部署指南](../operations/self-hosting.zh-CN.md)。
-1. 在电脑上打开 Piik 站点。如果站点设置了口令,先输入口令。
-2. 点击 **开始分享**,在浏览器弹窗里选择屏幕、窗口或标签页;
- 如需声音且浏览器提供该选项,启用音频。
+1. 打开 Piik 站点。如果站点设置了口令,先输入口令。
+2. 点击 **开始分享**,选择 **浏览器** 后在系统弹窗里选择屏幕、窗口或标签页;
+ 浏览器支持时,电脑和手机也可选择 **摄像头**。如需来源声音且选择器提供该选项,启用音频。
3. 确认预览画面后,点击 **复制邀请链接** 发给朋友。
4. 保持分享标签页打开。需要时使用 **暂停分享**、**切换来源** 或 **停止分享**。
@@ -116,6 +122,17 @@ Linux 原生采集还需要[系统组件](../../native/capture/linux/README.md)
如果管理员已启用 SFU 转发,房主可在开始分享前关闭 **隐私模式**,允许使用这条兜底线路。
项目提供的在线版仅使用 P2P。
+## 加上自己的声音
+
+分享时,点击画面下方的 **麦克风**,并允许访问。
+再次点击即可静音。在画面下方的 **分享设置** 中可以选择麦克风和调节输入音量,默认 100%,最高可调至 200%。
+观众会同时听到来源声音和你的解说;房主本机预览保持静音。
+
+摄像头分享不会自动开启麦克风。App 的 **程序 / 窗口** 和 **屏幕** 采集也使用同一组控件,
+可以保留「默认设备」,也可以指定麦克风。在 **摄像头** 页签中允许访问后,点击对应的画面卡片开始分享。
+设备名称和可用预览取决于浏览器权限;正在分享摄像头时,其他摄像头只显示名称。
+建议佩戴耳机,避免扬声器声音被麦克风再次收进去。
+
## 遇到问题了
声音、采集、启动或播放遇到问题时,先看[问题排查](./troubleshooting.zh-CN.md)。
diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md
index 1ad62765..fc7cc0dc 100644
--- a/docs/guide/troubleshooting.md
+++ b/docs/guide/troubleshooting.md
@@ -9,7 +9,8 @@ collect a diagnostic report if the problem persists.
| What you see | Try this |
| --- | --- |
-| Picture but no sound | Unmute the video. The host should choose a source with shareable audio; if sound was disabled, stop and start sharing with it enabled. App window/screen capture keeps that setting when switching sources. |
+| Picture but no source sound | Unmute the video. The host should choose a source with shareable audio and enable sound in the source picker. |
+| 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. |
| 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** → **Browser picker** also offers browser capture. |
| 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. |
@@ -51,6 +52,20 @@ On supported Windows versions, the App source picker offers **Show capture borde
off by default. Windows permissions or another active capture can still require
the border. Windows 10 does not provide this control for its capture API.
+### Windows 11: the border is still visible
+
+1. Select **Apps / Windows** or **Screens** in Piik and leave **Show capture border**
+ off. A Browser-selected source uses the browser's own capture indicator.
+2. Stop other apps or tabs capturing the same window/display, then restart sharing.
+3. If Windows denied borderless capture, review **Screenshot borders** in Windows
+ privacy settings. Its settings page can also be opened with
+ `ms-settings:privacy-graphicscapturewithoutborder` from **Win+R**, when available.
+
+Windows requires consent and can retain the border when another capture requests
+it ([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.
+
### Optional Windows 10 workaround
[DWM Custom Projection Border](https://windhawk.net/mods/dwm-custom-projection-border)
diff --git a/docs/guide/troubleshooting.zh-CN.md b/docs/guide/troubleshooting.zh-CN.md
index f782a6f5..322ccfd9 100644
--- a/docs/guide/troubleshooting.zh-CN.md
+++ b/docs/guide/troubleshooting.zh-CN.md
@@ -9,7 +9,8 @@
| 你遇到的情况 | 可以先试什么 |
| --- | --- |
-| 有画面,没声音 | 先取消视频静音。房主应选择支持分享声音的来源;如果开始时关闭了声音,请停止后重新开始并打开声音。通过 App 采集窗口或屏幕时,切换来源会保留原来的声音设置。 |
+| 有画面,没来源声音 | 先取消视频静音。房主应选择支持分享声音的来源,并在选源器中打开声音。 |
+| 听不到房主说话 | 房主可在画面下方开启 **麦克风**,在 **分享设置 → 声音** 中检查输入设备和音量,并确认设备连接与麦克风权限。如控件不可用,请更新 App 并刷新页面。 |
| 没有屏幕选择弹窗 | 按系统提示允许浏览器或 App 录制屏幕。浏览器采集需要 HTTPS 或 `localhost`,请在电脑上尝试分享。 |
| App 的窗口或屏幕列表为空 | 先查看选源器中的提示,再按 [App 来源排查](#app-找不到窗口或屏幕) 操作;也可以选 **浏览器** → **浏览器选择器** 使用浏览器采集。 |
| 分享的窗口或屏幕周围出现黄框 | 这是 Windows 的采集提示。查看[采集边框说明](#windows-分享时出现黄框),了解 Windows 11 的开关和 Windows 10 的可选处理方法。 |
@@ -47,6 +48,19 @@ Windows 用黄色边框标出正在采集的窗口或屏幕。在支持的 Windo
App 选源器提供 **显示采集边框** 开关,默认关闭;系统权限或其他正在进行的采集
仍可能要求显示边框。Windows 10 的采集接口没有这个开关。
+### Windows 11 关闭开关后仍有黄框
+
+1. 从 Piik 的 **程序 / 窗口** 或 **屏幕** 列表选源,保持 **显示采集边框** 关闭。
+ 通过浏览器选源时,采集标识由浏览器管理。
+2. 停止其他软件或标签页对同一窗口、屏幕的采集,再重新开始分享。
+3. 如果之前拒绝了无边框采集权限,在 Windows 隐私设置中检查 **屏幕截图边框**。
+ 支持该设置页的系统也可以按 **Win+R**,输入 `ms-settings:privacy-graphicscapturewithoutborder` 打开。
+
+Windows 需要用户授权;其他采集要求显示边框时,边框仍会保留
+([微软接口说明](https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscapturesession.isborderrequired),英文)。
+仍未解决时,反馈中请附上 Windows 版本、选源方式和
+[App 诊断报告](../../cmd/piik-app/README.zh-CN.md#诊断)。
+
### Windows 10 可选处理方法
[DWM Custom Projection Border](https://windhawk.net/mods/dwm-custom-projection-border)
diff --git a/docs/operations/website.md b/docs/operations/website.md
index 4711e25c..0a734752 100644
--- a/docs/operations/website.md
+++ b/docs/operations/website.md
@@ -133,9 +133,10 @@ Verify the latest redirects and package checksums after releases.
3. Set the approved `piik.tv` custom domain in Pages settings and configure its
DNS using GitHub's [current domain instructions](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site).
Actions publishing does not need a `CNAME` file in the source tree.
-4. Accepted main pushes run CI first; its completion triggers **Website**, which
- checks out current main. Manual **Website** dispatch from `main` republishes
- the site when needed. Download links resolve through each provider, so
+4. Accepted main pushes run CI first; success triggers **Website**, which checks
+ out that CI run's exact commit. Manual dispatch uses its selected `main` commit.
+ Before publishing, both paths skip a build that is no longer current main;
+ dispatch again for the latest commit when needed. Download links resolve through each provider, so
publishing a package or retrying its mirror needs no link refresh.
Only `build/site/` is uploaded; website work does not package App/Server.
Verify HTTPS, both languages, relative assets and per-platform download links.
diff --git a/docs/project-memory.md b/docs/project-memory.md
index ec69dff7..a3e9549b 100644
--- a/docs/project-memory.md
+++ b/docs/project-memory.md
@@ -1,10 +1,11 @@
# Project Memory
-Last updated: 2026-09-11
+Last updated: 2026-09-21
Piik is private, low-latency screen sharing for one Host and up to 20
authenticated friends. The current product surface is Web Host, Web Viewer, and
-Browser relay; desktop and mobile Browsers are Viewer targets. It is not a
+Browser relay; desktop and mobile Browsers are Viewer targets, and camera-capable
+mobile Browsers can also host. It is not a
public broadcast service. Hosted and App run one shared Go core
([ADR-0012](./adr/0012-shared-go-backend-core.md)); Node and Vite build the
Browser UI and are not a runtime. Source includes a cross-platform App that
diff --git a/docs/research/camera-and-microphone.md b/docs/research/camera-and-microphone.md
new file mode 100644
index 00000000..221a6402
--- /dev/null
+++ b/docs/research/camera-and-microphone.md
@@ -0,0 +1,117 @@
+# Camera And Host Microphone
+
+Status: integrated into the ordinary Host UI and accepted for release.
+Remaining device coverage belongs to [TODO](../todo.md#awaiting-device-or-reporter-evidence).
+
+## Scope And Ownership
+
+The existing source picker offers Browser, Camera, Window and Screen in that
+order, defaulting to Window when an App is detected. Without an App, it shows
+only Browser and Camera, defaulting to Browser. Mobile browsers can choose Camera
+when screen capture is unavailable.
+There is one active picture; capture, replacement, pause and stop retain their
+existing Host session and route owners. Camera permission never includes an
+implicit microphone request. HTTPS or localhost is required for device capture.
+
+The Host microphone mixes commentary with Browser source audio into one outgoing
+audio track through Web Audio. The existing P2P, relay and SFU senders borrow
+that stream. Microphone mute preserves the mixed track and source replacement
+preserves microphone intent. Denial or unplugging leaves healthy video alone;
+retiring the share closes audio resources and discards late permission results.
+The Host preview stays muted. Viewers receive the combined sound with their
+existing volume control and never request microphone permission.
+
+App native screen/window capture mixes selected-device microphone PCM with source
+audio before the existing Opus encoder. Windows uses WASAPI, macOS uses
+AVAudioEngine and Linux uses PulseAudio/PipeWire through GStreamer. Platform
+converters supply 48 kHz stereo PCM; one 20 ms output clock consumes each input
+once, with a bounded queue and silence for missing samples. This bounds backlog;
+it does not replace platform resampling or establish long-term clock-drift and
+echo-cancellation performance.
+
+New App/page pairs opt into a stable mixed audio track from share startup, even
+with source sound disabled. Opening or muting the microphone and replacing the
+source preserve that track, encoder, preview and route owners. Source sound and
+microphone availability remain separate reported facts. Old Apps/pages retain
+the existing capture contract through capability negotiation; microphone capture
+starts only after an explicit action. Permission waiting is cancellable and does
+not hold the control reader. Device loss retires only that audio input.
+
+Windows native capture and the App-to-Viewer path have local acceptance evidence.
+macOS/Linux microphone compilation is checked by native-platform packaging.
+Real audio-level/echo checks, macOS/Linux device acceptance and actual phone
+capture remain physical evidence limits; synthetic tests do not establish
+those results. The owner authorized release with those limits retained. The
+Host preview remains muted on every path.
+
+This scope adds no room messages, ports, chat, Viewer microphone or emoji
+interactions. Microphone, pause, source replacement and stop share one action
+row below the picture, outside the playback controls and television status.
+Their order and meaning stay the same in Chinese, English and pure-visual modes.
+Source-sound details describe the raw capture input; microphone intent and
+Viewer playback volume are separate facts. Pausing the share silences the mixed
+output and temporarily disables microphone toggling without clearing its intent.
+Sharing settings open from the action dock. Picture presets/parameters and sound
+form separate groups, with microphone device/input gain under sound and a further
+disclosure for connection/codec options. The panel expands in page flow, pushing
+the couch down; video presets remain available before capture starts.
+The dock keeps only its frequent mute action; camera selection stays with source selection.
+The default follows the system; an explicit selection never silently falls back
+to another device. Browser capture and native capture keep separate device IDs
+for the page lifetime. Enumeration does not request permission. Browser labels
+may appear only after the first grant; refresh and device-change events update
+the list. A missing selected device stays visible as unavailable.
+Switching an active microphone prepares the new input before retiring the old
+one; failure leaves the old input running. The mixed output stays unchanged.
+Camera selection belongs in the existing Camera tab and uses the same named
+thumbnail cards as window/display selection. Entering the
+Camera tab may request camera permission for local previews; it never requests
+microphone access or starts a room. Preview inputs open serially and stop after
+one bounded thumbnail. Leaving the tab or cancelling the picker stops owned
+inputs and discards late permission results. Images last only for that picker.
+While already sharing a camera, preview borrows the current video frame and
+lists other devices without opening them, because some phones retire an active
+camera when another opens. Missing thumbnails do not disable a known device.
+The Host's existing source-replacement operation
+owns the old camera's automatic end event until the pending capture settles;
+failure with an already-ended old camera retires sharing normally. This does
+not suppress a user's screen-share Stop action. Some phones require releasing
+the old camera before opening another; seamless switching is not established.
+
+The input-volume control adjusts microphone input from
+0–200% through smoothed input gain. It does not change source audio or Viewer playback volume,
+reopen permission, or replace the outgoing track. Its value lasts for the Host
+page lifetime; new page loads use 100%. Mute remains a separate direct action.
+Volume settings use the existing settings disclosure without covering the picture
+or participants. The microphone-volume comic describes outgoing
+commentary, separately from the Viewer's local listening volume.
+
+## Local Review
+
+Use the ordinary development or embedded Server entry described in
+[the contributor guide](../../CONTRIBUTING.md).
+Start a share from the normal Host page, select a source, then join through its
+ordinary invitation in another browser tab. Use headphones for same-device
+microphone tests. Browser-emulated mobile layout and synthetic devices do not
+establish actual iOS/Android permission, orientation, background or audio behavior.
+
+## Primary Technical References
+
+- [Google Meet audio controls](https://support.google.com/meet/answer/10409699?hl=en)
+ keeps microphone settings next to the frequent mute action.
+- [OBS audio mixer](https://obsproject.com/kb/audio-mixer-guide) separates source
+ volume, mute and monitoring; Piik uses only the controls needed for commentary.
+
+- [Web Audio stream destination](https://www.w3.org/TR/webaudio-1.0/#MediaStreamAudioDestinationNode)
+ produces a single audio track from the audio graph.
+- [Media Capture and Streams](https://www.w3.org/TR/mediacapture-streams/)
+ owns microphone permissions, device lifetime and echo-cancellation constraints.
+- [Camera capture](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia)
+ and [screen capture](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)
+ have separate permissions, capabilities and secure-context requirements.
+- [WebRTC track replacement](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/replaceTrack)
+ describes reuse of negotiated media slots and when renegotiation is required.
+- [WASAPI shared capture](https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-initialize),
+ [AVAudioConverter resampling](https://developer.apple.com/documentation/technotes/tn3136-avaudioconverter-performing-sample-rate-conversions)
+ and [GStreamer audio mixing](https://gstreamer.freedesktop.org/documentation/audiomixer/audiomixer.html)
+ define the platform conversion and PCM mixing boundaries.
diff --git a/docs/research/cross-platform-client-runtime.md b/docs/research/cross-platform-client-runtime.md
index 606dfd26..eaf12161 100644
--- a/docs/research/cross-platform-client-runtime.md
+++ b/docs/research/cross-platform-client-runtime.md
@@ -158,6 +158,26 @@ totals as its portable core proof. Detailed Piik quality metrics enrich a
development run when its source module is served, but their absence on a static
deployment no longer erases valid native RTCStats.
+### Public Invitation Startup
+
+The pinned cloudflared Quick Tunnel defaults to explicit QUIC, which disables
+its HTTP/2 fallback. Piik requests `--protocol auto` and
+`--max-edge-addr-retries 0`: try QUIC once, then let cloudflared fall back within
+the existing 30-second startup budget. This affects HTTP/WebSocket control only;
+media routes, tunnel identity and ordered shutdown keep their existing owners.
+DNS failures, API rejection and networks blocking both transports can still fail.
+
+A 2026-09-21 Windows check used the packaged binary with an isolated UDP sink and
+TCP forwarder. The previous arguments timed out at 30 seconds without trying TCP.
+The candidate connected in about 11 seconds, served the public page and echoed a
+WebSocket message, then joined the child on close. A separate ordinary-network
+run registered in about five seconds but this host's public HTTPS/WSS requests
+ended with EOF; end-to-end access on that path remains unverified. These checks
+do not establish the cause of reports without matching diagnostics. Upstream
+[Quick Tunnel setup](https://github.com/cloudflare/cloudflared/blob/2026.8.3/cmd/cloudflared/tunnel/quick_tunnel.go)
+and [protocol fallback](https://github.com/cloudflare/cloudflared/blob/2026.8.3/supervisor/tunnel.go)
+own the dependency behavior; Piik adds no separate retry loop.
+
## Remaining Gates
- Run the exact clean-revision package on macOS; Linux amd64 is proved.
diff --git a/docs/research/native-client-lifecycle.md b/docs/research/native-client-lifecycle.md
index 86ffa4a0..d36ddb06 100644
--- a/docs/research/native-client-lifecycle.md
+++ b/docs/research/native-client-lifecycle.md
@@ -260,6 +260,24 @@ starts at build 20348, beyond consumer Windows 10 build 19045. The current
capture helper therefore retains the system border there. Browser capture
indicators remain Browser-owned.
+On Windows 11 build 26200, a 2026-09-21 controlled native-window check confirmed
+borderless permission was allowed and the default capture had no border. A
+second session explicitly requiring a border made it visible; gracefully ending
+that session cleared it while borderless capture continued. Force-killing the
+bordered capture instead left the outline behind in this fixture, even after
+the remaining capture ended.
+
+The stream owner previously connected parent cancellation directly to
+`exec.CommandContext`, killing the child before its existing bounded stop
+sequence could release the platform session. Parent cancellation now enters
+that same `Stream.Close` sequence; an unresponsive process still has the existing
+one-second kill deadline. Subprocess regression checks cover explicit stop,
+parent cancellation, concurrent stop and an unresponsive child. A real WGC
+capture cancelled through this Go owner exited normally and cleared the border.
+This establishes a retirement defect and its local repair, not the cause of
+every reported Windows 11 border: denied consent and other active captures
+remain distinct Windows-owned limits.
+
An unofficial WGC-preserving option exists:
[Windhawk's DWM Custom Projection Border](https://github.com/ramensoftware/windhawk-mods/blob/main/mods/dwm-custom-projection-border.wh.cpp)
documents disabling the border on Windows 10 21H2. Source inspection confirms
diff --git a/docs/standards/media-quality.md b/docs/standards/media-quality.md
index 0bbd9e3d..07135d75 100644
--- a/docs/standards/media-quality.md
+++ b/docs/standards/media-quality.md
@@ -12,12 +12,25 @@ production behavior and remaining acceptance.
## Capture And Controls
-- The Web Host may share a display, application window, or Browser tab and may
+- The Web Host may share a display, application window, Browser tab or camera and may
stop, synchronously pause/resume audio and video, or switch source.
- An App-launched Host explicitly chooses either that Browser capture path or
one native screen/window enumerated by the packaged platform capture boundary. The
latter uses one supported native codec path and never infers a target from
a title. An ordinary Web Host does not probe localhost.
+- Camera is a peer source choice in the same picker, including on phones. Only
+ the chosen source requests permission. Browser/camera Host microphone capture
+ is explicit and uses voice processing separately from screen audio; its 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.
+- An audio-only update with the same capture video preserves the Browser video
+ sender, encoding state and startup evidence on both direct and SFU paths.
+ A new video source owns a new startup baseline; audio changes do not.
- Windows native capture follows an explicitly stretched active display path
for an entire display or a window covering that display, when the captured
frame matches its desktop source dimensions. Other frames retain their own
diff --git a/docs/standards/presentation-lifecycle.md b/docs/standards/presentation-lifecycle.md
index 2dee6952..52c1e865 100644
--- a/docs/standards/presentation-lifecycle.md
+++ b/docs/standards/presentation-lifecycle.md
@@ -46,14 +46,16 @@ versions of the product UI.
A remembered App activation permits discovery when choosing a source or
receiving media; it does not make App a prerequisite for sharing. Idle Host
-pages hold no App control session. Ordinary Web entry opens the Browser picker
-directly. Activated origins offer the shared source selector, initially on its
-Browser tab unless App is already connected. Discovery never blocks Browser
-selection or changes the chosen tab. Native tabs and refresh remain reachable
-after absence or disconnection; pending attempts are shared, completed failures
+pages hold no App control session. The shared source selector orders Browser,
+Camera, Window and Screen, defaulting to Window after App detection. Without an
+App it shows only Browser and Camera, defaulting to Browser. Discovery never
+blocks Browser selection or overrides an explicitly chosen tab. Refresh remains
+reachable after failed App discovery; pending attempts are shared, completed failures
do not suppress later discovery. Cancelling the selector or ending a share
releases its unused control session; an obsolete operation cannot install or
-retire another operation's media. Optional native ingress uses an already
+retire another operation's media. Camera thumbnails own only temporary preview
+inputs; leaving their tab or picker retires them. An active shared camera is
+borrowed, never reopened or stopped by preview. Optional native ingress uses an already
available connection without another scan. If it is not ready at Browser
startup, that share keeps Browser senders.
diff --git a/docs/standards/rooms-access.md b/docs/standards/rooms-access.md
index 5960e785..16b8e276 100644
--- a/docs/standards/rooms-access.md
+++ b/docs/standards/rooms-access.md
@@ -8,7 +8,8 @@ the storage decision; implementation detail belongs in code and tests.
- A room has one Host and at most 20 authenticated Viewers.
- Room codes are random free four-digit values from `1000..9999`. A code locates
- a room; it is not a secret or permanent identity.
+ a room within its site authority; it is not globally unique, a secret or a
+ permanent identity. App public-link rooms belong to that App's local authority.
- Every room has a 256-bit Host token. The server stores only its digest; the
owning Browser keeps the raw token locally.
- Each Host tab retains its current room in session storage. The origin keeps
@@ -60,6 +61,12 @@ tabs or Browser sessions; tab duplication and opener initialization remain
Browser behavior. The grant has no independent TTL and ends with the room or
when the Host rotates or revokes it.
+The Host can omit the grant from the displayed/copied link. This page-local
+choice defaults to including it and does not change admission policy, revoke
+existing invitations or clear a recipient's valid authorization. The ordinary
+room address retains the server-provided site and room path; it follows site
+access and code-entry rules. An invite-only room has no ordinary-address entry.
+
Code-only admission is independent of invitations:
- `open` admits a site-authorized Viewer by room code;
diff --git a/docs/standards/routing-transport.md b/docs/standards/routing-transport.md
index 175ea944..c55a48d2 100644
--- a/docs/standards/routing-transport.md
+++ b/docs/standards/routing-transport.md
@@ -34,10 +34,11 @@ share generation:
- native-edge topology convergence is enabled by default. The Host may disable
it before sharing; when disabled, quality evidence stays diagnostic and
availability routing is unchanged;
-- NAT traversal requires an exact three-destination STUN survey: a Site may use
- self-hosted 3478/3479/3480, Public Link uses its bounded public survey, and
+- NAT traversal enhancement requires an exact three-destination STUN survey:
+ a Site may use self-hosted 3478/3479/3480, Public Link uses its bounded public survey, and
pure LAN supplies none. Its default-on Host switch augments Browser and Native
- P2P edges. Native uses one media socket for IPv4 and, where available, IPv6
+ P2P edges. This gate leaves ordinary ICE and Native gateway mapping enabled.
+ Native uses one media socket for IPv4 and, where available, IPv6
direct connections; its STUN survey and best-effort gateway mapping use IPv4.
Availability and background direct acquisition share a bounded budget of
three actual connection attempts per eligible parent/session opportunity.
@@ -105,8 +106,8 @@ begins only after that exact candidate commits as the active route.
Either preparing endpoint reports local rejection or connection-start failure
to that same operation immediately; it does not wait out a silent candidate's
deadline or start an independent recovery loop.
-When NAT traversal is enabled, another operation may use the remaining
-connection-attempt budget after rollback. The waiting display uses the actual
+When NAT traversal enhancement is enabled, another operation may use the
+remaining connection-attempt budget after rollback. The waiting display uses the actual
server-issued attempt ordinal; it never counts time as an attempted connection.
Committed Browser P2P recovery first restarts ICE on the same connection, then
rebuilds that connection if necessary, within the existing two-request budget.
diff --git a/docs/standards/visual-language.md b/docs/standards/visual-language.md
index b9228eba..29d7ba85 100644
--- a/docs/standards/visual-language.md
+++ b/docs/standards/visual-language.md
@@ -116,6 +116,37 @@ on hover or keyboard focus, then compress on press. Inputs and option tiles
share softer corners. Keep a distinct focus ring and a persistent selected
state; disabled controls must not pretend to activate. Reduced motion keeps
the colour, outline and selected position without decorative displacement.
+The shared button uses the same pressed value for `aria-pressed` and its selected
+treatment; 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
+than the controls inside them; nested diagnostic panels retain their softer fill.
+Keep room identity, invitation and admission controls ahead of expanded topology
+and connection details, so inspecting a route does not displace room actions.
+
+Sharing and local playback controls use the same quiet, compact button treatment.
+The Host's persistent dock stays below the picture; the Viewer's playback bar
+belongs to the video. Their similar appearance does not equate broadcast pause
+with local playback pause. Waiting overlays use the space above the actual
+playback bar, including when it wraps. Keep the primary status readable on
+narrow screens; optional waiting copy yields first. Microphone mute, sharing
+pause, source replacement and stop remain direct actions; stopping stays
+visually separated from frequent actions.
+One compact dock combines direct actions and the sharing-settings entry below
+the television, above the couch. Its disclosure groups quality presets and picture
+parameters with sound and microphone settings; presets remain available before
+sharing starts. Separate the less frequent connection/codec options in a nested
+disclosure. Expand in page flow, pushing later content down instead of covering
+the picture or participants. Use two content groups on wide screens and stack
+them on narrow screens; avoid another permanent row of settings cards. Keep
+shared presentation separate from the existing setting/resource owners.
+The microphone comic depicts Host commentary gain;
+the Viewer's listening-volume comic remains a different action.
+
+Visual source choices (windows, screens and cameras) share named thumbnail cards,
+including their focus, hover and refresh treatment. Microphone selection uses
+device names in a compact selector. Shared enumeration does not make these two
+selection tasks visually interchangeable.
## Cast And Objects
@@ -130,6 +161,7 @@ Participant characters should leave room for that distinctive presence.
| 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. |
| Server forwarding media | A server on the media path; opening a Site alone does not imply SFU |
These are **identity/object colours**, not status. A green pawn remains green
diff --git a/docs/status.md b/docs/status.md
index 26d7ef44..fb7bdb2f 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -1,6 +1,6 @@
# Current Status
-Last updated: 2026-09-17
+Last updated: 2026-09-21
This is the compact execution/deployment index. Product modules own behavior,
[verification status](./verification-status.md) owns unresolved physical limits,
@@ -24,6 +24,11 @@ and Git/PRs own completed history.
mascot, concrete media waits use their owning comic, and waiting captions are
secondary to literal status. Website reduced-motion preference and player
tooltip 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
+ [capture assessment](./research/camera-and-microphone.md) owns platform behavior
+ and the remaining physical evidence limits.
Website delivery includes a bilingual reader documentation center generated
from the repository's guides alongside the homepage, with search and detailed
diff --git a/docs/todo.md b/docs/todo.md
index 1a34e0a6..29db3549 100644
--- a/docs/todo.md
+++ b/docs/todo.md
@@ -1,24 +1,46 @@
# Current TODO Ledger
-Last reviewed: 2026-09-20
+Last reviewed: 2026-09-21
Only **Now** is executable. Product modules own behavior; Git/PRs own completed
history. A parked idea is not implementation authority.
## Now
-- [ ] **Review camera and Host microphone in the separate capture candidate.**
- Keep device selection in the existing source/settings surfaces. Finish control
- grouping, dark-theme feedback and microphone volume presentation; verify native
- mixing, device replacement and mobile camera behavior before acceptance.
- These features are excluded from the bug-fix release.
+- [ ] **Complete manual accessible-name review.** Verify the empty video's
+ screen-reader output: Chromium exposes an unavailable-media
+ description despite the literal shared-picture label and no media error. Also
+ review accessible naming on disabled tooltip wrappers and the UI catalogue's
+ paired-character example; automated checks leave those for manual review.
- [ ] **Refine the isolated room-interaction prototype.** Review chat, optional
danmaku and participant-targeted reactions for usability, placement and intended
cross-view synchronization. Preserve room authorization and media-route owners.
+ Accept its combined layout: sharing settings with the picture, wide-screen chat
+ beside participants, stacked chat on narrow screens and room actions before
+ diagnostics. Check its theater chat entry and participant menu on real devices;
+ keep chat available independently of sharing.
+ Retain current room creation: the first share creates a room, an existing room
+ can resume, and stopping media keeps the opted-in interaction session. Do not
+ add visit-triggered creation or a separate pre-share room-creation entry.
This experiment does not authorize integration or publication.
## Awaiting Device Or Reporter Evidence
+- [ ] **Camera and Host microphone device coverage.** The owner accepted the
+ sharing layout and authorized release with these physical limits recorded.
+ Verify real audio levels/echo, multiple-device replacement and native mixing on
+ target systems, plus phone camera permission, orientation and background use.
+ Keep the existing capture and route owners. The
+ [capture assessment](./research/camera-and-microphone.md) owns behavior and
+ separates bounded Windows/browser checks from untested device combinations.
+- [ ] **App public-invitation startup field acceptance.** Retest the frequent
+ creation-failure report and the earlier
+ [#396 timeout](https://github.com/TNTcraftHIM/Piik/issues/396#issuecomment-5691465700)
+ with the updated App. A controlled UDP-blocked/TCP-available reproduction confirms
+ a dependency configuration defect; the existing tunnel now uses cloudflared's
+ bounded protocol fallback. [Runtime evidence](./research/cross-platform-client-runtime.md#public-invitation-startup)
+ separates this fix from DNS, provider and remote access failures. The reporting
+ environments still need version and diagnostic evidence before assigning a cause.
- [ ] **Interruption during established viewing.** A Viewer reportedly returns
to P2P connecting after watching for a while. Native receiver renegotiation,
retired event delivery and SFU replacement have locally reproduced defects
@@ -27,9 +49,11 @@ history. A parked idea is not implementation authority.
report when present. The existing five-second Viewer membership grace during
signaling loss is unchanged. This is distinct from the first-frame report below.
- [ ] **Windows 11 capture border remains visible.** Identify the App/Browser
- capture path, Windows build and capture-border permission result. A local
- Windows 11 request succeeded; the reported failure remains unconfirmed. Check
- system consent and other active captures before changing the WGC path.
+ capture path, Windows build and capture-border permission result. Local checks
+ reproduced a border surviving forced process termination; parent cancellation
+ now uses bounded graceful retirement. [Capture evidence](./research/native-client-lifecycle.md#windows-capture-borders)
+ verifies the repair and concurrent-capture behavior on Windows 11. The
+ reporter's cause remains unconfirmed; check consent and other active captures.
- [ ] **Brief connection followed by repeated Viewer loss on v1.5.0.** One
Viewer reportedly drops just after connection details appear, while other
Viewers work; App public-link mode is suspected. Check signaling, first-frame
@@ -37,23 +61,18 @@ history. A parked idea is not implementation authority.
reproduction establishes one premature candidate replacement; the affected
environment and paired diagnostics are still unavailable, so the reporting
machine's cause remains unconfirmed.
-- [ ] **App source-discovery field acceptance.** Retest the missing-window report
- with the current App and page. Obtain OS/browser, version and paired Debug
- reports to distinguish discovery, capture capability and enumeration failures.
- Local permission and recovery checks do not establish the reporting machine's
- cause.
+- [ ] **App discovery and share-start field acceptance.** Retest the missing-window
+ report, an unreachable App despite its process running, and generic share-start
+ failure with the current App and page. OS/browser, version, selected source and
+ paired Debug reports are still unavailable. Distinguish site authorization,
+ browser permission, control capacity, enumeration and capture-start failures;
+ local permission and recovery checks do not establish the reporters' causes.
- [ ] **Windows 32-bit candidate acceptance.** Verify the isolated
`spike/windows-x86-capture` candidate's launch, capture/audio, memory pressure,
source replacement and update links on a 32-bit Windows device. WOW64
Host/media checks establish only that environment. Reconcile its scoped
SDK/toolchain and atomic-alignment changes with current main when accepted;
the experiment is not part of this maintenance release.
-- [ ] **Public invitation startup timeout.** The reporter in
- [#396](https://github.com/TNTcraftHIM/Piik/issues/396#issuecomment-5691465700)
- confirmed Local startup is fixed, but separately reported that the public
- invitation service did not connect within 30 seconds. Trace tunnel startup,
- network reachability and the existing timeout/error feedback using a current
- Debug report; the Local fix does not establish this separate failure's cause.
- [ ] **Windows launcher exit after opening the page.** A user reports that the
mode-selection page opens, then the App console reports
`Piik App could not open its launcher: exit status 0xc0000005`.
@@ -129,3 +148,10 @@ not establish better connection success or speed; this note adds no retry policy
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.
+10. **4K in advanced sharing settings.** Deferred until after the current capture
+ maintenance phase. Add 3840x2160 without changing the default or recommended
+ presets. Extend the existing capture, decode and relay bounds together; verify
+ H.264 level negotiation for 4K at 60 fps. Current strict quality messages reject
+ `2160p`, so preserve published Browser/App/Server compatibility through explicit
+ receiving-end support before exposing or sending the new setting. Include
+ source replacement, lower outputs and resource limits in acceptance.
diff --git a/internal/app/app.go b/internal/app/app.go
index 54a04028..b645a175 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -624,6 +624,7 @@ func discoverNativeMedia(ctx context.Context, configuredPath string) nativeRunti
ReceiverReuse: true,
Video: summary.Video,
CaptureBorderControl: summary.CaptureBorderControl,
+ Microphone: summary.Microphone,
ProcessAudio: summary.ProcessAudio,
SystemAudio: summary.SystemAudio,
HardwareH264: summary.HardwareH264,
diff --git a/internal/app/loopback/server.go b/internal/app/loopback/server.go
index b6959078..07498242 100644
--- a/internal/app/loopback/server.go
+++ b/internal/app/loopback/server.go
@@ -72,6 +72,7 @@ type NativeMediaCapabilities struct {
ReceiverReuse bool `json:"receiverReuse,omitempty"`
Video bool `json:"video"`
CaptureBorderControl bool `json:"captureBorderControl,omitempty"`
+ Microphone bool `json:"microphone,omitempty"`
ProcessAudio bool `json:"processAudio"`
SystemAudio bool `json:"systemAudio"`
HardwareH264 bool `json:"hardwareH264"`
diff --git a/internal/app/mediaedge/audio.go b/internal/app/mediaedge/audio.go
index ddfbfe8f..49e840cc 100644
--- a/internal/app/mediaedge/audio.go
+++ b/internal/app/mediaedge/audio.go
@@ -94,6 +94,10 @@ func (engine *Engine) NewRelayedAudioSource(capacity int) (*AudioSource, error)
}
func (source *AudioSource) WritePCM(pcm []byte, duration time.Duration) error {
+ return source.WritePCMWithDropped(pcm, duration, 0)
+}
+
+func (source *AudioSource) WritePCMWithDropped(pcm []byte, duration time.Duration, dropped uint16) error {
if source == nil || source.encoder == nil || duration <= 0 {
return errors.New("native PCM sample is invalid")
}
@@ -110,7 +114,7 @@ func (source *AudioSource) WritePCM(pcm []byte, duration time.Duration) error {
return err
}
source.bytes.Add(uint64(len(packet)))
- return source.samples.WriteSample(media.Sample{Data: packet, Duration: duration})
+ return source.samples.WriteSample(media.Sample{Data: packet, Duration: duration, PrevDroppedPackets: dropped})
}
func (source *AudioSource) WriteRTP(packet *rtp.Packet) error {
diff --git a/internal/app/nativecapture/microphones.go b/internal/app/nativecapture/microphones.go
new file mode 100644
index 00000000..40db4871
--- /dev/null
+++ b/internal/app/nativecapture/microphones.go
@@ -0,0 +1,44 @@
+package nativecapture
+
+import (
+ "context"
+ "errors"
+ "os/exec"
+ "strings"
+ "unicode/utf8"
+)
+
+// Device identities remain local to the authenticated App control connection.
+type Microphone struct {
+ ID string `json:"id"`
+ Label string `json:"label"`
+}
+
+func ValidDeviceID(id string) bool {
+ return len(id) <= 512 && utf8.ValidString(id) && !strings.ContainsRune(id, 0)
+}
+
+func ListMicrophones(parent context.Context, executable string) ([]Microphone, error) {
+ ctx, cancel := context.WithTimeout(parent, probeTimeout)
+ defer cancel()
+ stdout := &boundedBuffer{limit: maxProbeOutputBytes}
+ command := exec.CommandContext(ctx, executable, "--list-microphones")
+ command.Stdout = stdout
+ hideWindow(command)
+ if err := command.Run(); err != nil {
+ return nil, errors.New("native microphone list is unavailable")
+ }
+ var devices []Microphone
+ if err := decodeStrictJSON(stdout.Bytes(), &devices); err != nil || devices == nil || len(devices) > 64 {
+ return nil, errors.New("native microphone list is invalid")
+ }
+ seen := make(map[string]bool, len(devices))
+ for _, device := range devices {
+ if device.ID == "" || !ValidDeviceID(device.ID) || seen[device.ID] ||
+ device.Label == "" || len(device.Label) > 512 || !utf8.ValidString(device.Label) || strings.ContainsRune(device.Label, 0) {
+ return nil, errors.New("native microphone identity is invalid")
+ }
+ seen[device.ID] = true
+ }
+ return devices, nil
+}
diff --git a/internal/app/nativecapture/probe.go b/internal/app/nativecapture/probe.go
index d6bceb87..cc30fcba 100644
--- a/internal/app/nativecapture/probe.go
+++ b/internal/app/nativecapture/probe.go
@@ -47,6 +47,7 @@ type Capabilities struct {
PlatformBuild string `json:"platformBuild"`
VideoCapture bool `json:"videoCapture"`
CaptureBorderControl bool `json:"captureBorderControl,omitempty"`
+ Microphone bool `json:"microphone,omitempty"`
ProcessAudio bool `json:"processAudio"`
SystemAudio bool `json:"systemAudio"`
SoftwareVP8 bool `json:"softwareVP8"`
@@ -56,6 +57,7 @@ type Capabilities struct {
type Summary struct {
Video bool
CaptureBorderControl bool
+ Microphone bool
ProcessAudio bool
SystemAudio bool
HardwareH264 bool
@@ -66,6 +68,7 @@ func (capabilities Capabilities) Summary() Summary {
summary := Summary{
Video: capabilities.VideoCapture,
CaptureBorderControl: capabilities.VideoCapture && capabilities.CaptureBorderControl,
+ Microphone: capabilities.Microphone,
ProcessAudio: capabilities.ProcessAudio,
SystemAudio: capabilities.SystemAudio,
SoftwareVP8: capabilities.SoftwareVP8,
diff --git a/internal/app/nativecapture/stream.go b/internal/app/nativecapture/stream.go
index e8e56118..af49cee2 100644
--- a/internal/app/nativecapture/stream.go
+++ b/internal/app/nativecapture/stream.go
@@ -298,7 +298,22 @@ func StartSystemAudio(parent context.Context, executable string) (*Stream, error
})
}
+func StartMicrophone(parent context.Context, executable, deviceID string) (*Stream, error) {
+ if !ValidDeviceID(deviceID) {
+ return nil, errors.New("microphone device is invalid")
+ }
+ arguments := []string{"--capture-microphone"}
+ if deviceID != "" {
+ arguments = append(arguments, "--device", deviceID)
+ }
+ return startAudioStreamWithTimeout(parent, executable, arguments, time.Minute)
+}
+
func startAudioStream(parent context.Context, executable string, arguments []string) (*Stream, error) {
+ return startAudioStreamWithTimeout(parent, executable, arguments, probeTimeout)
+}
+
+func startAudioStreamWithTimeout(parent context.Context, executable string, arguments []string, timeout time.Duration) (*Stream, error) {
if parent == nil {
parent = context.Background()
}
@@ -315,7 +330,7 @@ func startAudioStream(parent context.Context, executable string, arguments []str
}
ready <- validateAudioReadyFrame(frame)
}()
- timer := time.NewTimer(probeTimeout)
+ timer := time.NewTimer(timeout)
defer timer.Stop()
select {
case readyErr := <-ready:
@@ -395,7 +410,12 @@ func startStreamWithEnvironment(
if executable == "" {
return nil, errors.New("native capture process is unavailable")
}
- ctx, cancel := context.WithCancel(parent)
+ if err := parent.Err(); err != nil {
+ return nil, err
+ }
+ // Parent cancellation requests the same bounded Q/Close sequence as an
+ // explicit stop. Killing first can leave platform capture state behind.
+ ctx, cancel := context.WithCancel(context.WithoutCancel(parent))
started := time.Now()
// A diagnostic-only process label correlates stderr while old/new captures overlap.
captureID := strconv.FormatInt(started.UnixNano(), 36)
@@ -444,8 +464,10 @@ func startStreamWithEnvironment(
logger: logger,
ctx: ctx,
}
+ stopParent := context.AfterFunc(parent, func() { _ = stream.Close() })
go func() {
waitErr := command.Wait()
+ stopParent()
_ = trace.Close()
logCaptureFailure(ctx, waitErr, command.ProcessState.ExitCode(), stderr.Bytes())
logger.DebugContext(ctx, "piik-client", "event", "capture-process-ended", "mode", mode,
diff --git a/internal/app/nativecapture/stream_test.go b/internal/app/nativecapture/stream_test.go
index abe5576f..a5f06614 100644
--- a/internal/app/nativecapture/stream_test.go
+++ b/internal/app/nativecapture/stream_test.go
@@ -7,10 +7,80 @@ import (
"errors"
"io"
"log/slog"
+ "os"
+ "path/filepath"
"strings"
"testing"
+ "time"
)
+func TestCaptureStopHelper(t *testing.T) {
+ mode := os.Getenv("PIIK_CAPTURE_STOP_FIXTURE")
+ if mode == "" {
+ return
+ }
+ if err := writeFrame(os.Stdout, Frame{Kind: FrameStatus, Data: []byte("ready")}); err != nil {
+ os.Exit(2)
+ }
+ if mode == "unresponsive" {
+ time.Sleep(10 * time.Second)
+ os.Exit(3)
+ }
+ frame, err := readFrame(os.Stdin)
+ if err != nil || frame.Kind != FrameControl || string(frame.Data) != "Q" {
+ os.Exit(4)
+ }
+ // A platform capture must get time to release its session before process exit.
+ time.Sleep(50 * time.Millisecond)
+ if err := os.WriteFile(os.Getenv("PIIK_CAPTURE_STOP_MARKER"), []byte("released"), 0600); err != nil {
+ os.Exit(5)
+ }
+ os.Exit(0)
+}
+
+func TestCaptureStopUsesOneBoundedRetirementPath(t *testing.T) {
+ executable, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, mode := range []string{"explicit", "parent", "both", "unresponsive"} {
+ t.Run(mode, func(t *testing.T) {
+ ctx, cancel := context.WithCancel(t.Context())
+ defer cancel()
+ marker := filepath.Join(t.TempDir(), "released")
+ stream, err := startStreamWithEnvironment(ctx, executable,
+ []string{"-test.run=^TestCaptureStopHelper$"},
+ []string{"PIIK_CAPTURE_STOP_FIXTURE=" + mode, "PIIK_CAPTURE_STOP_MARKER=" + marker})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer stream.Close()
+ if _, err := stream.Read(); err != nil {
+ t.Fatal(err)
+ }
+ if mode != "explicit" {
+ cancel()
+ }
+ if mode == "explicit" || mode == "both" {
+ go stream.Close()
+ }
+ select {
+ case <-stream.Done():
+ case <-time.After(captureStopTimeout + 3*time.Second):
+ t.Fatal("capture retirement exceeded its stop budget")
+ }
+ _, err = os.Stat(marker)
+ if mode == "unresponsive" {
+ if !os.IsNotExist(err) {
+ t.Fatalf("unresponsive capture unexpectedly released: %v", err)
+ }
+ } else if err != nil {
+ t.Fatalf("capture was killed before receiving its stop command: %v", err)
+ }
+ })
+ }
+}
+
func TestDiagnosticStderrOverflowDoesNotStopTheChildReader(t *testing.T) {
for _, discard := range []bool{false, true} {
buffer := &boundedBuffer{limit: 4, discardOverflow: discard}
diff --git a/internal/app/nativecontrol/session.go b/internal/app/nativecontrol/session.go
index 6a5b8c4a..3396b9c9 100644
--- a/internal/app/nativecontrol/session.go
+++ b/internal/app/nativecontrol/session.go
@@ -8,6 +8,7 @@ import (
"errors"
"io"
"log/slog"
+ "math"
"net/url"
"regexp"
"strconv"
@@ -43,7 +44,6 @@ type Session struct {
ctx context.Context
cancel context.CancelFunc
events chan any
- hostEvents chan nativehost.Event
viewerEvents chan nativeviewer.Event
mu sync.Mutex
@@ -72,7 +72,6 @@ func New(
ctx: ctx,
cancel: cancel,
events: make(chan any, 256),
- hostEvents: make(chan nativehost.Event, 256),
viewerEvents: make(chan nativeviewer.Event, 256),
}
go session.relayEvents()
@@ -118,6 +117,22 @@ func (session *Session) Handle(ctx context.Context, payload []byte) (result any,
responseEnvelope: response(envelope, "capture-options"),
Adapters: session.capabilities.Adapters,
}, nil
+ case "list-microphones":
+ var request requestEnvelope
+ if err := decodeStrict(payload, &request); err != nil {
+ return nil, protocolViolation("native microphone list request is invalid")
+ }
+ if !session.capabilities.Microphone {
+ return operationFailure(envelope, errors.New("native microphone is unavailable")), nil
+ }
+ devices, err := nativecapture.ListMicrophones(ctx, session.captureProcess)
+ if err != nil {
+ return operationFailure(envelope, err), nil
+ }
+ return struct {
+ responseEnvelope
+ Devices []nativecapture.Microphone `json:"devices"`
+ }{response(envelope, "microphone-list"), devices}, nil
case "list-sources":
var request listSourcesRequest
if err := decodeStrict(payload, &request); err != nil || request.Type != envelope.Type {
@@ -168,6 +183,34 @@ func (session *Session) Handle(ctx context.Context, payload []byte) (result any,
"share", diagnostics.ID(request.ShareID), "profile", nativeQualityProfile(request.Profile), "codec", request.Codec, "audio", request.Audio,
"sourceKind", request.Source.Kind, "adapterIndex", request.AdapterIndex, "encoderIndex", request.EncoderIndex)
return session.startShare(ctx, envelope, request)
+ case "set-microphone":
+ var request microphoneRequest
+ if err := decodeStrict(payload, &request); err != nil || !validIdentities(request.ShareID) ||
+ (request.Enabled == nil && request.Volume == nil && request.DeviceID == nil) ||
+ (request.DeviceID != nil && !nativecapture.ValidDeviceID(*request.DeviceID)) ||
+ (request.Volume != nil && (math.IsNaN(*request.Volume) || math.IsInf(*request.Volume, 0) || *request.Volume < 0 || *request.Volume > 2)) {
+ return nil, protocolViolation("native microphone request is invalid")
+ }
+ host := session.current(request.ShareID)
+ if host == nil {
+ return nil, errors.New("native share does not exist")
+ }
+ // Commit gain in command order; asynchronous device setup must not later
+ // overwrite a newer slider value received while permission was pending.
+ if request.Volume != nil {
+ if err := host.SetMicrophone(nil, request.Volume, nil); err != nil {
+ return nil, err
+ }
+ }
+ if request.Enabled == nil && request.DeviceID == nil {
+ return response(envelope, "microphone-set"), nil
+ }
+ result = session.runHostOperation(host, envelope, func() (any, error) {
+ err := host.SetMicrophone(request.Enabled, nil, request.DeviceID)
+ return response(envelope, "microphone-set"), err
+ }, complete)
+ asynchronous = result == nil
+ return result, nil
case "update-share":
var request updateShareRequest
if err := decodeStrict(payload, &request); err != nil ||
@@ -394,22 +437,33 @@ func (session *Session) Close() error {
}
func (session *Session) updateHost(host *nativehost.Session, request requestEnvelope, shareID string, profile nativehost.QualityProfile, complete func(any, error)) any {
+ return session.runHostOperation(host, request, func() (any, error) {
+ err := host.UpdateProfile(profile)
+ return session.shareUpdateResult(request, shareID, profile, err), err
+ }, complete)
+}
+
+// Quality and microphone setup share one bounded operation slot. Stop remains
+// synchronous and cancels the owning share before joining this completion.
+func (session *Session) runHostOperation(host *nativehost.Session, request requestEnvelope, operation func() (any, error), complete func(any, error)) any {
session.mu.Lock()
if session.closed || session.host != host || session.updateDone != nil {
session.mu.Unlock()
- return operationFailure(request, errors.New("native quality update is unavailable or already active"))
+ return operationFailure(request, errors.New("native share operation is unavailable or already active"))
}
done := make(chan struct{})
session.updateDone = done
session.mu.Unlock()
go func() {
- err := host.UpdateProfile(profile)
+ result, err := operation()
session.mu.Lock()
current := !session.closed && session.host == host
if !current && err == nil {
- err = errors.New("native share stopped during quality update")
+ err = errors.New("native share stopped during operation")
+ }
+ if err != nil {
+ result = operationFailure(request, err)
}
- result := session.shareUpdateResult(request, shareID, profile, err)
complete(result, err)
close(done)
if session.closed {
@@ -476,13 +530,24 @@ func (session *Session) startShare(
EncoderIndex: request.EncoderIndex,
Profile: profile.Video,
},
- Profile: profile,
- EdgeCapacity: request.EdgeCapacity,
+ MicrophoneMixing: request.MicrophoneMixing && session.capabilities.Microphone,
+ Profile: profile,
+ EdgeCapacity: request.EdgeCapacity,
AudioEnabled: request.Audio && session.capabilities.Summary().AudioFor(
request.Source.Kind,
),
PortMapping: session.portMapping,
- Events: session.hostEvents,
+ Events: func(ctx context.Context, event nativehost.Event) {
+ var value any = eventMessage(event)
+ if event.Current != nil {
+ value = loopback.ControlEvent{Value: value, Current: event.Current}
+ }
+ select {
+ case session.events <- value:
+ case <-ctx.Done():
+ case <-session.ctx.Done():
+ }
+ },
})
if err != nil {
return nil, err
@@ -503,6 +568,7 @@ func (session *Session) startShare(
responseEnvelope: response(envelope, "share-started"),
ShareID: request.ShareID,
Audio: host.HasAudio(),
+ SourceAudio: host.SourceAudio(),
Codec: codec,
}, nil
}
@@ -758,12 +824,6 @@ func (session *Session) watchHost(host *nativehost.Session) {
func (session *Session) relayEvents() {
for {
select {
- case event := <-session.hostEvents:
- var value any = eventMessage(event)
- if event.Current != nil {
- value = loopback.ControlEvent{Value: value, Current: event.Current}
- }
- session.emit(value)
case event := <-session.viewerEvents:
session.emit(loopback.ControlEvent{Value: viewerEventMessage(event), Current: event.Current})
case <-session.ctx.Done():
@@ -829,6 +889,8 @@ func eventMessage(event nativehost.Event) any {
PublicationGeneration: event.PublicationGeneration,
}
switch event.Type {
+ case "audio-state":
+ return audioStateEvent{eventEnvelope: base, SourceAudio: event.SourceAudio, Microphone: event.Microphone, Failed: event.Failed}
case "publication-quality":
return publicationQualityEvent{eventEnvelope: base, PublicationQualitySample: *event.PublicationQuality}
case "edge-candidate", "publication-candidate":
diff --git a/internal/app/nativecontrol/session_test.go b/internal/app/nativecontrol/session_test.go
index a1b08d5d..8194035e 100644
--- a/internal/app/nativecontrol/session_test.go
+++ b/internal/app/nativecontrol/session_test.go
@@ -111,6 +111,11 @@ func runQuietCaptureFixture(directory string) {
_, _ = os.Stdout.Write(payload)
}
status := func() { payload, _ := json.Marshal(state); write(nativecapture.FrameStatus, payload, 0) }
+ if len(os.Args) == 2 && os.Args[1] == "--capture-microphone" {
+ write(nativecapture.FrameStatus, []byte(`{"state":"active","audio":true}`), 0)
+ _, _ = io.Copy(io.Discard, os.Stdin)
+ return
+ }
status()
closed := make(chan struct{})
go func() { _, _ = io.Copy(io.Discard, os.Stdin); close(closed) }()
@@ -144,6 +149,65 @@ func runQuietCaptureFixture(directory string) {
<-closed
}
+func TestMicrophoneOptInPreservesLegacyAndOrdersStateBeforeCompletion(t *testing.T) {
+ for _, optIn := range []bool{false, true} {
+ t.Run(strconv.FormatBool(optIn), func(t *testing.T) {
+ t.Setenv("PIIK_QUIET_CAPTURE_FIXTURE", t.TempDir())
+ executable, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ session := New(executable, nativecapture.Capabilities{VideoCapture: true, SoftwareVP8: true, Microphone: true}, false)
+ defer session.Close()
+ request := startShareRequest{Version: 9, ID: "request_start", Type: "start-share", ShareID: "share_123456",
+ Source: nativecapture.CaptureTarget{Kind: "display", SourceID: "1", Title: "Fixture"},
+ MicrophoneMixing: optIn, EdgeCapacity: 1, Codec: "vp8",
+ Profile: qualitySettings{Resolution: "1080p", MaxFramerate: 30, MaxBitrate: 5_000_000, DegradationPreference: "balanced"}}
+ payload, _ := json.Marshal(request)
+ result, err := session.Handle(t.Context(), payload)
+ started, ok := result.(shareStartedResponse)
+ if err != nil || !ok {
+ t.Fatalf("start failed: %v %#v", err, result)
+ }
+ encoded, _ := json.Marshal(started)
+ if started.Audio != optIn || bytes.Contains(encoded, []byte(`"sourceAudio"`)) != optIn {
+ t.Fatalf("mixed output leaked across opt-in: %s", encoded)
+ }
+ result, err = session.Handle(t.Context(), []byte(`{"version":9,"id":"request_mic","type":"set-microphone","shareId":"share_123456","enabled":true,"volume":1}`))
+ if !optIn {
+ if _, failed := result.(requestFailedResponse); err != nil || !failed {
+ t.Fatalf("non-opted share admitted mic: %v %#v", err, result)
+ }
+ return
+ }
+ if err != nil || result != nil {
+ t.Fatalf("device setup was not asynchronous: %v %#v", err, result)
+ }
+ stateSeen := false
+ for {
+ select {
+ case event := <-session.Events():
+ switch value := event.(type) {
+ case audioStateEvent:
+ stateSeen = value.Microphone && !value.SourceAudio
+ case responseEnvelope:
+ if value.Type == "microphone-set" {
+ if !stateSeen {
+ t.Fatal("completion overtook microphone state")
+ }
+ return
+ }
+ case requestFailedResponse:
+ t.Fatalf("microphone failed: %#v", value)
+ }
+ case <-time.After(2 * time.Second):
+ t.Fatal("microphone did not complete")
+ }
+ }
+ })
+ }
+}
+
func TestCaptureBorderPreferenceFollowsSourceAndProfile(t *testing.T) {
for _, supported := range []bool{false, true} {
t.Run(strconv.FormatBool(supported), func(t *testing.T) {
diff --git a/internal/app/nativecontrol/wire.go b/internal/app/nativecontrol/wire.go
index 281bd431..a68404da 100644
--- a/internal/app/nativecontrol/wire.go
+++ b/internal/app/nativecontrol/wire.go
@@ -48,6 +48,7 @@ type startShareRequest struct {
ShareID string `json:"shareId"`
Source nativecapture.CaptureTarget `json:"source"`
Audio bool `json:"audio"`
+ MicrophoneMixing bool `json:"microphoneMixing,omitempty"`
ShowCaptureBorder bool `json:"showCaptureBorder,omitempty"`
AdapterIndex uint32 `json:"adapterIndex"`
EncoderIndex uint32 `json:"encoderIndex"`
@@ -56,6 +57,21 @@ type startShareRequest struct {
Codec string `json:"codec"`
}
+type microphoneRequest struct {
+ requestEnvelope
+ ShareID string `json:"shareId"`
+ Enabled *bool `json:"enabled,omitempty"`
+ Volume *float64 `json:"volume,omitempty"`
+ DeviceID *string `json:"deviceId,omitempty"`
+}
+
+type audioStateEvent struct {
+ eventEnvelope
+ SourceAudio bool `json:"sourceAudio"`
+ Microphone bool `json:"microphone"`
+ Failed bool `json:"failed"`
+}
+
type updateShareRequest struct {
Version int `json:"version"`
ID string `json:"id"`
@@ -195,9 +211,10 @@ type captureOptionsResponse struct {
type shareStartedResponse struct {
responseEnvelope
- ShareID string `json:"shareId"`
- Audio bool `json:"audio"`
- Codec string `json:"codec"`
+ ShareID string `json:"shareId"`
+ Audio bool `json:"audio"`
+ SourceAudio *bool `json:"sourceAudio,omitempty"`
+ Codec string `json:"codec"`
}
type shareUpdatedResponse struct {
diff --git a/internal/app/nativehost/audio_mix.go b/internal/app/nativehost/audio_mix.go
new file mode 100644
index 00000000..b4707c35
--- /dev/null
+++ b/internal/app/nativehost/audio_mix.go
@@ -0,0 +1,263 @@
+package nativehost
+
+import (
+ "context"
+ "encoding/binary"
+ "errors"
+ "log/slog"
+ "math"
+ "sync"
+ "time"
+
+ "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/diagnostics"
+)
+
+const audioPeriod = 20 * time.Millisecond
+
+// Each device is resampled by the platform to PCM48 stereo. This bounded FIFO
+// absorbs scheduling jitter; it never replays samples or builds a latency tail.
+// It does not claim to eliminate long-term drift between hardware clocks.
+type audioInput struct {
+ stream *nativecapture.Stream
+ frames [][]byte
+}
+
+func (input *audioInput) push(frame []byte) {
+ if len(input.frames) == 4 {
+ input.frames = input.frames[1:]
+ }
+ input.frames = append(input.frames, frame)
+}
+
+func (input *audioInput) pop() []byte {
+ if input == nil || len(input.frames) == 0 {
+ return nil
+ }
+ frame := input.frames[0]
+ input.frames[0] = nil
+ input.frames = input.frames[1:]
+ return frame
+}
+
+// One share owns one output/encoder. Replacing an input never replaces that
+// output. The session owns source capture; this owner owns microphone capture.
+type audioMix struct {
+ ctx context.Context
+ output *mediaedge.AudioSource
+ emit func(Event)
+ shareID string
+ mu sync.Mutex
+ // State delivery is ordered, but backpressure never holds the audio lock.
+ eventMu sync.Mutex
+ readers sync.WaitGroup
+ source, microphone *audioInput
+ paused bool
+ gain, appliedGain float64
+ microphoneDevice string
+}
+
+func (mix *audioMix) stateLocked(failed bool) Event {
+ return Event{Type: "audio-state", ShareID: mix.shareID,
+ SourceAudio: mix.source != nil, Microphone: mix.microphone != nil, Failed: failed}
+}
+
+func (mix *audioMix) setSource(stream *nativecapture.Stream) {
+ mix.eventMu.Lock()
+ defer mix.eventMu.Unlock()
+ mix.mu.Lock()
+ if mix.ctx.Err() != nil {
+ mix.mu.Unlock()
+ return
+ }
+ mix.source = nil
+ if stream != nil {
+ mix.source = &audioInput{stream: stream}
+ mix.readers.Add(1)
+ go mix.read(mix.source, false)
+ }
+ state := mix.stateLocked(false)
+ mix.mu.Unlock()
+ mix.emit(state)
+}
+
+func (mix *audioMix) read(input *audioInput, microphone bool) {
+ defer mix.readers.Done()
+ for {
+ frame, err := input.stream.Read()
+ mix.mu.Lock()
+ current := mix.source
+ if microphone {
+ current = mix.microphone
+ }
+ if current != input || mix.ctx.Err() != nil {
+ mix.mu.Unlock()
+ return
+ }
+ if err != nil || frame.Kind != nativecapture.FramePCM || len(frame.Data) != nativeaudio.FrameBytes || frame.Duration != audioPeriod {
+ mix.mu.Unlock()
+ mix.inputEnded(input, microphone)
+ slog.DebugContext(mix.ctx, "piik-client", "event", "audio-input-ended", "microphone", microphone, diagnostics.Error(err))
+ _ = input.stream.Close()
+ return
+ }
+ if !mix.paused {
+ input.push(frame.Data)
+ }
+ mix.mu.Unlock()
+ }
+}
+
+func (mix *audioMix) setPaused(paused bool) {
+ mix.mu.Lock()
+ defer mix.mu.Unlock()
+ mix.paused = paused
+ for _, input := range []*audioInput{mix.source, mix.microphone} {
+ if input != nil {
+ input.frames = nil
+ }
+ }
+ // Never carry a pre-pause ramp into the resumed share.
+ mix.appliedGain = 0
+}
+
+func (mix *audioMix) inputEnded(input *audioInput, microphone bool) {
+ mix.eventMu.Lock()
+ defer mix.eventMu.Unlock()
+ mix.mu.Lock()
+ current := mix.source
+ if microphone {
+ current = mix.microphone
+ }
+ if current != input || mix.ctx.Err() != nil {
+ mix.mu.Unlock()
+ return
+ }
+ if microphone {
+ mix.microphone = nil
+ } else {
+ mix.source = nil
+ }
+ state := mix.stateLocked(microphone)
+ mix.mu.Unlock()
+ mix.emit(state)
+}
+
+func (mix *audioMix) setMicrophone(executable string, enabled *bool, gain *float64, deviceID *string) error {
+ if deviceID != nil && !nativecapture.ValidDeviceID(*deviceID) {
+ return errors.New("microphone device is invalid")
+ }
+ if gain != nil && (math.IsNaN(*gain) || math.IsInf(*gain, 0) || *gain < 0 || *gain > 2) {
+ return errors.New("microphone volume is invalid")
+ }
+ mix.mu.Lock()
+ if gain != nil {
+ mix.gain = *gain
+ }
+ wanted := mix.microphone != nil
+ if enabled != nil {
+ wanted = *enabled
+ }
+ device := mix.microphoneDevice
+ if deviceID != nil {
+ device = *deviceID
+ }
+ unchanged := wanted == (mix.microphone != nil) && device == mix.microphoneDevice
+ mix.mu.Unlock()
+ if unchanged {
+ return nil
+ }
+ var stream *nativecapture.Stream
+ if wanted {
+ var err error
+ stream, err = nativecapture.StartMicrophone(mix.ctx, executable, device)
+ if err != nil {
+ return err
+ }
+ }
+ mix.eventMu.Lock()
+ defer mix.eventMu.Unlock()
+ mix.mu.Lock()
+ if mix.ctx.Err() != nil {
+ mix.mu.Unlock()
+ if stream != nil {
+ _ = stream.Close()
+ }
+ return mix.ctx.Err()
+ }
+ previous := mix.microphone
+ mix.microphoneDevice = device
+ mix.microphone = nil
+ if stream != nil {
+ mix.microphone = &audioInput{stream: stream}
+ mix.readers.Add(1)
+ go mix.read(mix.microphone, true)
+ }
+ state := mix.stateLocked(false)
+ mix.mu.Unlock()
+ if previous != nil {
+ _ = previous.stream.Close()
+ }
+ mix.emit(state)
+ return nil
+}
+
+func (mix *audioMix) run() {
+ ticker := time.NewTicker(audioPeriod)
+ defer ticker.Stop()
+ var output [nativeaudio.FrameBytes]byte
+ previous := time.Now()
+ for {
+ select {
+ case now := <-ticker.C:
+ // Pion advances RTP time across missed ticks; do not burst old speech.
+ dropped := uint16(min(max(int(now.Sub(previous)/audioPeriod)-1, 0), 65535))
+ previous = now
+ mix.mu.Lock()
+ source, microphone := mix.source.pop(), mix.microphone.pop()
+ gain := mix.gain
+ if microphone == nil {
+ gain = 0
+ }
+ mixPCM(output[:], source, microphone, mix.appliedGain, gain)
+ mix.appliedGain = gain
+ if mix.paused {
+ clear(output[:])
+ }
+ // A retired edge cannot end healthy sibling media.
+ _ = mix.output.WritePCMWithDropped(output[:], audioPeriod, dropped)
+ mix.mu.Unlock()
+ case <-mix.ctx.Done():
+ mix.mu.Lock()
+ microphone := mix.microphone
+ mix.microphone = nil
+ mix.mu.Unlock()
+ if microphone != nil {
+ _ = microphone.stream.Close()
+ }
+ mix.readers.Wait() // Session cancellation/retirement also closes source.
+ return
+ }
+ }
+}
+
+// Mix once in a wider type, then saturate. Never attenuate source sound just
+// because the microphone was enabled. Gain changes span a frame, not a sample.
+func mixPCM(output, source, microphone []byte, from, to float64) {
+ for sample := range nativeaudio.FrameSamples {
+ gain := from + (to-from)*float64(sample+1)/nativeaudio.FrameSamples
+ for channel := range nativeaudio.Channels {
+ offset := (sample*nativeaudio.Channels + channel) * 2
+ value := 0.0
+ if source != nil {
+ value = float64(int16(binary.LittleEndian.Uint16(source[offset:])))
+ }
+ if microphone != nil {
+ value += gain * float64(int16(binary.LittleEndian.Uint16(microphone[offset:])))
+ }
+ binary.LittleEndian.PutUint16(output[offset:], uint16(int16(max(-32768, min(32767, value)))))
+ }
+ }
+}
diff --git a/internal/app/nativehost/audio_mix_test.go b/internal/app/nativehost/audio_mix_test.go
new file mode 100644
index 00000000..0bac3243
--- /dev/null
+++ b/internal/app/nativehost/audio_mix_test.go
@@ -0,0 +1,242 @@
+package nativehost
+
+import (
+ "context"
+ "encoding/binary"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "github.com/TNTcraftHIM/Piik/internal/app/nativeaudio"
+ "github.com/TNTcraftHIM/Piik/internal/app/nativecapture"
+)
+
+func TestMixPCMRetainsSourceGainAndSaturatesStereo(t *testing.T) {
+ frame := func(value int16) []byte {
+ data := make([]byte, nativeaudio.FrameBytes)
+ for i := 0; i < len(data); i += 2 {
+ binary.LittleEndian.PutUint16(data[i:], uint16(value))
+ }
+ return data
+ }
+ output := frame(0)
+ mixPCM(output, frame(1000), nil, 0, 0)
+ if int16(binary.LittleEndian.Uint16(output)) != 1000 {
+ t.Fatal("source was attenuated")
+ }
+ mixPCM(output, frame(1000), frame(2000), 0, 2)
+ if binary.LittleEndian.Uint16(output[:2]) != binary.LittleEndian.Uint16(output[2:4]) ||
+ int16(binary.LittleEndian.Uint16(output[len(output)-2:])) != 5000 ||
+ int16(binary.LittleEndian.Uint16(output)) >= 1100 {
+ t.Fatal("stereo gain did not ramp")
+ }
+ for _, value := range []int16{-30000, 30000} {
+ mixPCM(output, frame(value), frame(value), 2, 2)
+ expected := int16(32767)
+ if value < 0 {
+ expected = -32768
+ }
+ if int16(binary.LittleEndian.Uint16(output)) != expected {
+ t.Fatal("sum wrapped instead of saturating")
+ }
+ }
+ mixPCM(output, nil, nil, 2, 0)
+ for _, value := range output {
+ if value != 0 {
+ t.Fatal("missing input replayed old audio")
+ }
+ }
+ input := &audioInput{}
+ for i := byte(0); i < 10; i++ {
+ input.push([]byte{i})
+ }
+ for i := byte(6); i < 10; i++ {
+ if got := input.pop(); len(got) != 1 || got[0] != i {
+ t.Fatal("FIFO retained stale frames")
+ }
+ }
+ if input.pop() != nil {
+ t.Fatal("FIFO replayed the last sample")
+ }
+}
+
+func startMixedFixture(t *testing.T) (*Session, nativecapture.VideoOptions, <-chan Event) {
+ t.Helper()
+ t.Setenv("PIIK_NATIVEHOST_PIPE_FIXTURE", "audio-recovery")
+ executable, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
+ t.Cleanup(cancel)
+ events := make(chan Event, 64)
+ options := nativecapture.VideoOptions{Codec: "vp8", Profile: audioRecoveryProfile(),
+ Target: nativecapture.CaptureTarget{Kind: "display", SourceID: "1", Title: "Mixed fixture"}}
+ session, err := Start(ctx, Options{ShareID: "mixed_fixture", CaptureProcess: executable, Video: options,
+ Profile: QualityProfile{Video: options.Profile, AudioBitrate: 64000}, MicrophoneMixing: true,
+ EdgeCapacity: 1, BindAddress: "127.0.0.1:0", Events: func(_ context.Context, event Event) {
+ select {
+ case events <- event:
+ case <-ctx.Done():
+ }
+ }})
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = session.Close() })
+ return session, options, events
+}
+
+func TestNativeMicrophonePreservesMediaOwnersAcrossInputChanges(t *testing.T) {
+ session, options, events := startMixedFixture(t)
+ check := func(err error) {
+ t.Helper()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ if !session.HasAudio() || session.SourceAudio() == nil || *session.SourceAudio() {
+ t.Fatal("silent mixed output was not reserved independently of source")
+ }
+ _, err := session.PrepareLocalEdge("mixed_edge")
+ check(err)
+ edge, source := session.edge("mixed_edge"), session.audioSource
+ enabled, gain := true, 1.0
+ check(session.SetMicrophone(&enabled, &gain, nil))
+ session.mixer.mu.Lock()
+ microphone := session.mixer.microphone
+ session.mixer.mu.Unlock()
+ if microphone == nil {
+ t.Fatal("microphone did not start")
+ }
+ device := "missing"
+ if session.SetMicrophone(nil, nil, &device) == nil {
+ t.Fatal("missing microphone accepted")
+ }
+ session.mixer.mu.Lock()
+ retained := session.mixer.microphone == microphone
+ session.mixer.mu.Unlock()
+ if !retained {
+ t.Fatal("failed device switch retired healthy microphone")
+ }
+ device = "headset"
+ check(session.SetMicrophone(nil, nil, &device))
+ session.mixer.mu.Lock()
+ replaced := session.mixer.microphone
+ session.mixer.mu.Unlock()
+ if replaced == nil || replaced == microphone || session.audioSource != source || session.edge("mixed_edge") != edge {
+ t.Fatal("device change failed to replace only the input")
+ }
+ microphone = replaced
+ options.Target.SourceID = "2"
+ check(session.ReplaceSource(t.Context(), options, true))
+ session.mixer.mu.Lock()
+ sameMicrophone := session.mixer.microphone == microphone
+ session.mixer.mu.Unlock()
+ if !sameMicrophone || session.audioSource != source || session.edge("mixed_edge") != edge || !*session.SourceAudio() {
+ t.Fatal("source replacement rebuilt microphone/output/edge")
+ }
+ session.SetPaused(true)
+ time.Sleep(60 * time.Millisecond)
+ session.mixer.mu.Lock()
+ queued := len(session.mixer.source.frames) + len(session.mixer.microphone.frames)
+ session.mixer.mu.Unlock()
+ if queued != 0 {
+ t.Fatal("paused speech accumulated")
+ }
+ session.SetPaused(false)
+ // EOF retires only the microphone; source and all negotiated media stay live.
+ check(microphone.stream.Close())
+ timer := time.NewTimer(time.Second)
+ defer timer.Stop()
+ for {
+ select {
+ case event := <-events:
+ if event.Type != "audio-state" || !event.Failed {
+ continue
+ }
+ if event.Microphone || !event.SourceAudio || !session.HasAudio() || session.edge("mixed_edge") != edge {
+ t.Fatal("input loss damaged healthy media")
+ }
+ enabled = false
+ check(session.SetMicrophone(&enabled, nil, nil))
+ return
+ case <-timer.C:
+ t.Fatal("microphone loss was not reported")
+ }
+ }
+}
+
+func TestStopCancelsPendingMicrophoneWithoutRevivingShare(t *testing.T) {
+ marker := filepath.Join(t.TempDir(), "microphone-started")
+ t.Setenv("PIIK_MICROPHONE_WAIT", marker)
+ session, _, _ := startMixedFixture(t)
+ result := make(chan error, 1)
+ go func() { enabled := true; result <- session.SetMicrophone(&enabled, nil, nil) }()
+ deadline := time.Now().Add(2 * time.Second)
+ for {
+ if _, err := os.Stat(marker); err == nil {
+ break
+ }
+ if time.Now().After(deadline) {
+ t.Fatal("microphone fixture did not start")
+ }
+ time.Sleep(time.Millisecond)
+ }
+ stopped := make(chan error, 1)
+ go func() { stopped <- session.Close() }()
+ select {
+ case err := <-stopped:
+ if err != nil {
+ t.Fatal(err)
+ }
+ case <-time.After(2 * time.Second):
+ t.Fatal("microphone permission blocked Stop")
+ }
+ if err := <-result; err == nil {
+ t.Fatal("late microphone became live after Stop")
+ }
+ session.mixer.mu.Lock()
+ defer session.mixer.mu.Unlock()
+ if session.mixer.microphone != nil {
+ t.Fatal("retired microphone retained")
+ }
+}
+
+func TestCancelledMixerCannotRegisterReplacementReader(t *testing.T) {
+ ctx, cancel := context.WithCancel(t.Context())
+ cancel()
+ mix := &audioMix{ctx: ctx}
+ mix.setSource(&nativecapture.Stream{})
+ if mix.source != nil {
+ t.Fatal("cancelled mixer installed a source")
+ }
+ mix.readers.Wait()
+}
+
+func TestAudioNotificationBackpressureDoesNotBlockPauseOrGain(t *testing.T) {
+ ctx, cancel := context.WithCancel(t.Context())
+ defer cancel()
+ entered, returned := make(chan struct{}), make(chan struct{})
+ input := &audioInput{}
+ mix := &audioMix{ctx: ctx, microphone: input, emit: func(Event) { close(entered); <-ctx.Done() }}
+ go func() { mix.inputEnded(input, true); close(returned) }()
+ <-entered
+ controlled := make(chan struct{})
+ go func() {
+ mix.setPaused(true)
+ gain := 1.5
+ if err := mix.setMicrophone("", nil, &gain, nil); err != nil {
+ t.Error(err)
+ }
+ close(controlled)
+ }()
+ select {
+ case <-controlled:
+ case <-time.After(time.Second):
+ t.Fatal("notifications blocked the control reader before Stop")
+ }
+ cancel()
+ <-returned
+}
diff --git a/internal/app/nativehost/audio_test.go b/internal/app/nativehost/audio_test.go
index 92198eef..5a82770f 100644
--- a/internal/app/nativehost/audio_test.go
+++ b/internal/app/nativehost/audio_test.go
@@ -42,7 +42,18 @@ func runAudioRecoveryCapture() {
os.Exit(1)
}
}
- audio := len(os.Args) > 1 && os.Args[1] == "--capture-audio"
+ microphone := len(os.Args) > 1 && os.Args[1] == "--capture-microphone"
+ if microphone {
+ if len(os.Args) == 4 && os.Args[2] == "--device" && os.Args[3] == "missing" {
+ os.Exit(2)
+ }
+ if marker := os.Getenv("PIIK_MICROPHONE_WAIT"); marker != "" {
+ _ = os.WriteFile(marker, nil, 0600)
+ <-stopped
+ return
+ }
+ }
+ audio := microphone || (len(os.Args) > 1 && os.Args[1] == "--capture-audio")
period := time.Second / 30
status := []byte(`{"state":"active","audio":true}`)
if audio {
@@ -92,7 +103,12 @@ func TestAudioEOFWaitsForExplicitSourceReplacement(t *testing.T) {
Target: nativecapture.CaptureTarget{Kind: "display", SourceID: "1", Title: "Audio fixture"}}
session, err := Start(ctx, Options{ShareID: "audio-recovery", CaptureProcess: executable,
Video: options, Profile: QualityProfile{Video: options.Profile, AudioBitrate: 64_000},
- AudioEnabled: true, EdgeCapacity: 1, BindAddress: "127.0.0.1:0", Events: events})
+ AudioEnabled: true, EdgeCapacity: 1, BindAddress: "127.0.0.1:0", Events: func(_ context.Context, event Event) {
+ select {
+ case events <- event:
+ case <-ctx.Done():
+ }
+ }})
check(err)
defer session.Close()
if !session.HasAudio() {
diff --git a/internal/app/nativehost/publication_test.go b/internal/app/nativehost/publication_test.go
index f6612da4..d94a03e7 100644
--- a/internal/app/nativehost/publication_test.go
+++ b/internal/app/nativehost/publication_test.go
@@ -1,6 +1,7 @@
package nativehost
import (
+ "context"
"testing"
"time"
@@ -25,7 +26,12 @@ func TestPublicationGenerationFencesNativeControl(t *testing.T) {
t.Fatal(err)
}
events := make(chan Event, 64)
- session := &Session{shareID: "share_12345678", engine: engine, source: source, ctx: t.Context(), events: events}
+ session := &Session{shareID: "share_12345678", engine: engine, source: source, ctx: t.Context(), events: func(ctx context.Context, event Event) {
+ select {
+ case events <- event:
+ case <-ctx.Done():
+ }
+ }}
_, media, err := session.PreparePublication("generation_12345678", "connection_12345678", nil)
if err != nil || media.Codec != "vp8" || len(media.Layers) != 1 {
t.Fatalf("publication did not reuse capture metadata: %+v %v", media, err)
diff --git a/internal/app/nativehost/session.go b/internal/app/nativehost/session.go
index 513debf9..dd49d707 100644
--- a/internal/app/nativehost/session.go
+++ b/internal/app/nativehost/session.go
@@ -43,6 +43,9 @@ type CaptureState struct {
type Event struct {
Current func() bool
+ SourceAudio bool
+ Microphone bool
+ Failed bool
Type string
ShareID string
ConnectionID string
@@ -57,15 +60,16 @@ type Event struct {
}
type Options struct {
- ShareID string
- CaptureProcess string
- Video nativecapture.VideoOptions
- Profile QualityProfile
- AudioEnabled bool
- EdgeCapacity int
- BindAddress string
- PortMapping bool
- Events chan<- Event
+ ShareID string
+ CaptureProcess string
+ Video nativecapture.VideoOptions
+ Profile QualityProfile
+ AudioEnabled bool
+ MicrophoneMixing bool
+ EdgeCapacity int
+ BindAddress string
+ PortMapping bool
+ Events func(context.Context, Event)
}
type Session struct {
@@ -79,7 +83,8 @@ type Session struct {
engine *mediaedge.Engine
source *mediaedge.Source
audioSource *mediaedge.AudioSource
- events chan<- Event
+ mixer *audioMix
+ events func(context.Context, Event)
ctx context.Context
cancel context.CancelFunc
@@ -151,19 +156,31 @@ func Start(parent context.Context, options Options) (*Session, error) {
edges: make(map[string]*mediaedge.Edge),
audioChanged: make(chan struct{}, 1),
}
- if audioStream != nil {
+ if audioStream != nil || options.MicrophoneMixing {
audioSource, audioErr := engine.NewAudioSource(
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))
- _ = audioStream.Close()
+ if audioStream != nil {
+ _ = audioStream.Close()
+ }
audioStream = nil
session.audioStream = nil
} else {
session.audioSource = audioSource
}
}
+ if options.MicrophoneMixing {
+ if session.audioSource == nil {
+ cancel()
+ _ = stream.Close()
+ _ = engine.Close()
+ 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
@@ -308,6 +325,9 @@ func (session *Session) SetPaused(paused bool) {
return
}
session.paused = paused
+ if session.mixer != nil {
+ session.mixer.setPaused(paused)
+ }
source := session.source
session.mu.Unlock()
if !paused {
@@ -391,7 +411,7 @@ func (session *Session) ReplaceSource(
options.OutputGroups = session.edgeCapacity
hasAudio := session.audioSource != nil && session.audioStream != nil
session.mu.Unlock()
- if audioEnabled != hasAudio {
+ if session.mixer == nil && audioEnabled != hasAudio {
return errors.New("native source audio availability cannot change while sharing")
}
options.Profile = profile.Video
@@ -401,7 +421,7 @@ func (session *Session) ReplaceSource(
return err
}
var replacementAudio *nativecapture.Stream
- if hasAudio {
+ if audioEnabled {
replacementAudio, err = startAudioCapture(
ctx,
session.captureProcess,
@@ -418,7 +438,7 @@ func (session *Session) ReplaceSource(
replacement,
state,
replacementAudio,
- hasAudio,
+ true,
)
}
@@ -500,6 +520,9 @@ func (session *Session) commitCapture(
session.profile = profile
session.mu.Unlock()
+ if replaceAudio && session.mixer != nil {
+ session.mixer.setSource(replacementAudio)
+ }
_ = replacement.RequestKeyFrame(-1)
_ = previous.Close()
if replaceAudio && previousAudio != nil {
@@ -513,9 +536,6 @@ func (session *Session) commitCapture(
if err := session.ctx.Err(); err != nil {
return err
}
- session.emit(Event{
- Type: "capture-state", ShareID: session.shareID, State: "active",
- })
return nil
}
@@ -532,6 +552,7 @@ func (session *Session) installCapture(next *nativecapture.Stream) error {
session.captureApplied = nil
}
session.mu.Unlock()
+ session.emit(Event{Type: "capture-state", ShareID: session.shareID, State: "active"})
return nil
}
@@ -607,7 +628,9 @@ func (session *Session) run() {
session.runQuality()
close(qualityDone)
}()
- if session.audioStream == nil {
+ if session.mixer != nil {
+ go func() { session.mixer.run(); close(audioDone) }()
+ } else if session.audioStream == nil {
close(audioDone)
} else {
go func() {
@@ -1016,6 +1039,7 @@ func (session *Session) runQuality() {
}
}
+// Public shares without the microphone opt-in retain their original audio shape.
func (session *Session) runAudio() {
current := session.currentAudioStream()
for current != nil {
@@ -1065,9 +1089,8 @@ func (session *Session) emit(event Event) {
if session.events == nil {
return
}
- select {
- case session.events <- event:
- case <-session.ctx.Done():
+ if session.ctx.Err() == nil {
+ session.events(session.ctx, event)
}
}
@@ -1114,3 +1137,25 @@ func validH264ProfileLevelID(value string) bool {
return false
}
}
+
+// Optional facts are emitted only to a page which opted into mixed audio.
+func (session *Session) SourceAudio() *bool {
+ if session.mixer == nil {
+ return nil
+ }
+ session.mixer.mu.Lock()
+ defer session.mixer.mu.Unlock()
+ available := session.mixer.source != nil
+ return &available
+}
+
+func (session *Session) SetMicrophone(enabled *bool, gain *float64, deviceID *string) error {
+ if enabled != nil || deviceID != nil {
+ session.updateMu.Lock()
+ defer session.updateMu.Unlock()
+ }
+ if session.mixer == nil || session.ctx.Err() != nil {
+ return errors.New("native microphone is unavailable")
+ }
+ return session.mixer.setMicrophone(session.captureProcess, enabled, gain, deviceID)
+}
diff --git a/internal/app/nativehost/session_test.go b/internal/app/nativehost/session_test.go
index 9918788e..107a03c4 100644
--- a/internal/app/nativehost/session_test.go
+++ b/internal/app/nativehost/session_test.go
@@ -66,7 +66,7 @@ func TestCaptureCommitWaitsForReaderMetadataOrTermination(t *testing.T) {
publication, err := engine.NewPublication(source, mediaedge.EdgeOptions{ConnectionID: "metadata-fixture"})
check(err)
session := &Session{ctx: ctx, cancel: cancel, engine: engine, source: source, stream: previous,
- edgeCapacity: 1, ready: make(chan error, 1), done: make(chan error, 1), events: make(chan Event, 16)}
+ edgeCapacity: 1, ready: make(chan error, 1), done: make(chan error, 1), events: func(context.Context, Event) {}}
options.Profile.Width, options.Profile.Height = 854, 480
replacement, err := nativecapture.StartVideo(ctx, executable, options)
check(err)
diff --git a/internal/app/publictunnel/process.go b/internal/app/publictunnel/process.go
index 94a7ed58..992f53dc 100644
--- a/internal/app/publictunnel/process.go
+++ b/internal/app/publictunnel/process.go
@@ -88,6 +88,10 @@ func Start(
"--no-autoupdate",
"--loglevel", "info",
"--output", "json",
+ // Quick Tunnels otherwise force QUIC. Let cloudflared try TCP after
+ // the first failed edge attempt, within our bounded startup window.
+ "--protocol", "auto",
+ "--max-edge-addr-retries", "0",
"--url", localOrigin,
)
hideWindow(child)
diff --git a/internal/app/publictunnel/process_test.go b/internal/app/publictunnel/process_test.go
index 9be2aff3..394ff3b9 100644
--- a/internal/app/publictunnel/process_test.go
+++ b/internal/app/publictunnel/process_test.go
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "slices"
"strings"
"sync"
"testing"
@@ -17,7 +18,18 @@ import (
func TestMain(tests *testing.M) {
if mode := os.Getenv("PIIK_TUNNEL_FIXTURE"); mode != "" {
- if mode == "ready" || mode == "fail-after-ready" {
+ if mode == "tcp-only" {
+ // Model the pinned Quick Tunnel's opt-in protocol fallback. Without
+ // both flags, an unavailable UDP edge consumes Piik's startup budget.
+ for name, want := range map[string]string{"--protocol": "auto", "--max-edge-addr-retries": "0"} {
+ index := slices.Index(os.Args, name)
+ if index < 0 || index+1 >= len(os.Args) || os.Args[index+1] != want {
+ fmt.Fprintln(os.Stderr, "UDP unavailable; TCP fallback not enabled within startup budget")
+ os.Exit(7)
+ }
+ }
+ }
+ if mode == "ready" || mode == "fail-after-ready" || mode == "tcp-only" {
fmt.Println(`{"message":"https://test-room.trycloudflare.com"}`)
fmt.Println(`{"message":"Registered tunnel connection"}`)
}
@@ -37,6 +49,23 @@ func TestMain(tests *testing.M) {
os.Exit(tests.Run())
}
+func TestStartupEnablesCloudflaredProtocolFallback(t *testing.T) {
+ executable, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("PIIK_TUNNEL_FIXTURE", "tcp-only")
+ ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second)
+ defer cancel()
+ process, err := Start(ctx, executable, "http://127.0.0.1:8787")
+ if err != nil {
+ t.Fatalf("tunnel with TCP available: %v", err)
+ }
+ if err := process.Close(); err != nil {
+ t.Fatal(err)
+ }
+}
+
type blockedTunnelLog struct {
slog.Handler
entered chan struct{}
diff --git a/native/capture/darwin/Info.plist b/native/capture/darwin/Info.plist
new file mode 100644
index 00000000..94901d2f
--- /dev/null
+++ b/native/capture/darwin/Info.plist
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0"><dict>
+ <key>CFBundleIdentifier</key><string>tv.piik.capture</string>
+ <key>CFBundleName</key><string>Piik</string>
+ <key>NSMicrophoneUsageDescription</key><string>Include your voice while sharing.</string>
+</dict></plist>
diff --git a/native/capture/darwin/build.sh b/native/capture/darwin/build.sh
index 6a83f87c..0f300e40 100644
--- a/native/capture/darwin/build.sh
+++ b/native/capture/darwin/build.sh
@@ -13,10 +13,13 @@ xcrun swiftc \
-parse-as-library \
-swift-version 5 \
-target arm64-apple-macos13.0 \
+ -framework AVFoundation \
-framework AudioToolbox \
+ -framework CoreAudio \
-framework CoreMedia \
-framework CoreVideo \
-framework ScreenCaptureKit \
-framework VideoToolbox \
+ -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker "$(dirname "$0")/Info.plist" \
"$(dirname "$0")/main.swift" \
-o "$output/piik-capture"
diff --git a/native/capture/darwin/main.swift b/native/capture/darwin/main.swift
index 9af0e5e5..9154c936 100644
--- a/native/capture/darwin/main.swift
+++ b/native/capture/darwin/main.swift
@@ -1,4 +1,6 @@
+import AVFoundation
import AudioToolbox
+import CoreAudio
import CoreMedia
import CoreVideo
import Darwin
@@ -76,6 +78,7 @@ private struct Probe: Codable {
let platformBuild: String
let videoCapture: Bool
let processAudio: Bool
+ let microphone = true
let systemAudio: Bool
let softwareVP8 = false
let adapters: [AdapterProbe]
@@ -284,6 +287,12 @@ private final class StopSignal {
semaphore.signal()
}
+ var isStopped: Bool {
+ lock.lock()
+ defer { lock.unlock() }
+ return stopped
+ }
+
func wait() throws {
semaphore.wait()
lock.lock()
@@ -1178,6 +1187,14 @@ private final class AudioCaptureOutput: NSObject, SCStreamOutput, SCStreamDelega
}
}
+ // Microphone conversion and ScreenCaptureKit audio use the same PCM framing.
+ func appendPCM(_ buffer: AVAudioPCMBuffer) throws {
+ guard !done.isStopped, let samples = buffer.int16ChannelData else { return }
+ pending.append(UnsafeRawPointer(samples[0]).assumingMemoryBound(to: UInt8.self),
+ count: Int(buffer.frameLength) * 4)
+ try flushFrames()
+ }
+
private func flushFrames() throws {
let frameBytes = 960 * 2 * MemoryLayout<Int16>.size
while pending.count >= frameBytes {
@@ -1697,6 +1714,141 @@ private func capture(_ arguments: [String]) async throws {
try await stream.stopCapture()
}
+// AVAudioEngine callbacks never wait on stdout. Four copied buffers bound the
+// worker; the persistent platform converter owns resampling between callbacks.
+private func audioDeviceString(_ device: AudioDeviceID, _ selector: AudioObjectPropertySelector) -> String? {
+ var address = AudioObjectPropertyAddress(mSelector: selector, mScope: kAudioObjectPropertyScopeGlobal, mElement: kAudioObjectPropertyElementMain)
+ var value: CFString?
+ var size = UInt32(MemoryLayout<CFString?>.size)
+ guard AudioObjectGetPropertyData(device, &address, 0, nil, &size, &value) == noErr else { return nil }
+ return value as String?
+}
+
+private func microphoneDevices() throws -> [(id: AudioDeviceID, uid: String, name: String)] {
+ var address = AudioObjectPropertyAddress(mSelector: kAudioHardwarePropertyDevices, mScope: kAudioObjectPropertyScopeGlobal, mElement: kAudioObjectPropertyElementMain)
+ var size: UInt32 = 0
+ guard AudioObjectGetPropertyDataSize(AudioObjectID(kAudioObjectSystemObject), &address, 0, nil, &size) == noErr,
+ size <= 4096 else { throw CaptureFailure(description: "microphone list is unavailable") }
+ var devices = [AudioDeviceID](repeating: 0, count: Int(size) / MemoryLayout<AudioDeviceID>.size)
+ if devices.isEmpty { return [] }
+ let status = devices.withUnsafeMutableBytes { buffer in
+ AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject), &address, 0, nil, &size, buffer.baseAddress!)
+ }
+ guard status == noErr else { throw CaptureFailure(description: "microphone list is unavailable") }
+ return devices.compactMap { device in
+ var input = AudioObjectPropertyAddress(mSelector: kAudioDevicePropertyStreams, mScope: kAudioDevicePropertyScopeInput, mElement: kAudioObjectPropertyElementMain)
+ var bytes: UInt32 = 0
+ guard AudioObjectGetPropertyDataSize(device, &input, 0, nil, &bytes) == noErr, bytes > 0,
+ let uid = audioDeviceString(device, kAudioDevicePropertyDeviceUID),
+ let name = audioDeviceString(device, kAudioObjectPropertyName) else { return nil }
+ return (id: device, uid: uid, name: name)
+ }
+}
+
+private func listMicrophones() throws {
+ let devices = try microphoneDevices().map { ["id": $0.uid, "label": $0.name] }
+ guard devices.count <= 64 else { throw CaptureFailure(description: "too many microphones") }
+ FileHandle.standardOutput.write(try JSONSerialization.data(withJSONObject: devices))
+}
+
+private func captureMicrophone(deviceUID: String = "") throws {
+ let done = StopSignal()
+ let control = DispatchQueue(label: "piik.microphone.control")
+ let worker = DispatchQueue(label: "piik.microphone.pcm")
+ let slots = DispatchSemaphore(value: 4)
+ let output = AudioCaptureOutput(writer: ProtocolWriter(), done: done)
+ var engine: AVAudioEngine?
+ var observer: NSObjectProtocol?
+ var tapped = false
+ readInput(done: done)
+ defer {
+ control.sync {
+ if let observer { NotificationCenter.default.removeObserver(observer) }
+ if tapped { engine?.inputNode.removeTap(onBus: 0) }
+ engine?.stop()
+ engine = nil
+ }
+ worker.sync {} // Queued work observes stopped; no tail audio is flushed.
+ }
+ let permitted: (Bool) -> Void = { allowed in
+ control.async {
+ guard !done.isStopped else { return }
+ guard allowed else {
+ done.signal(CaptureFailure(description: "microphone permission denied"))
+ return
+ }
+ do {
+ let capture = AVAudioEngine()
+ engine = capture
+ let input = capture.inputNode
+ if !deviceUID.isEmpty {
+ guard let selected = try microphoneDevices().first(where: { $0.uid == deviceUID }),
+ let unit = input.audioUnit else { throw CaptureFailure(description: "selected microphone is unavailable") }
+ var device = selected.id
+ guard AudioUnitSetProperty(unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0,
+ &device, UInt32(MemoryLayout<AudioDeviceID>.size)) == noErr else {
+ throw CaptureFailure(description: "selected microphone could not open")
+ }
+ }
+ let format = input.outputFormat(forBus: 0)
+ guard format.sampleRate > 0, format.channelCount > 0,
+ let target = AVAudioFormat(commonFormat: .pcmFormatInt16,
+ sampleRate: 48_000, channels: 2, interleaved: true),
+ let converter = AVAudioConverter(from: format, to: target) else {
+ throw CaptureFailure(description: "microphone format is unavailable")
+ }
+ converter.channelMap = [0, format.channelCount > 1 ? 1 : 0]
+ observer = NotificationCenter.default.addObserver(
+ forName: .AVAudioEngineConfigurationChange, object: capture, queue: nil
+ ) { _ in done.signal(CaptureFailure(description: "microphone device changed")) }
+ input.installTap(onBus: 0, bufferSize: 960, format: format) { buffer, _ in
+ guard !done.isStopped, buffer.frameLength > 0,
+ slots.wait(timeout: .now()) == .success else { return }
+ guard let copy = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: buffer.frameLength) else {
+ slots.signal()
+ return
+ }
+ copy.frameLength = buffer.frameLength
+ let source = UnsafeMutableAudioBufferListPointer(buffer.mutableAudioBufferList)
+ let destination = UnsafeMutableAudioBufferListPointer(copy.mutableAudioBufferList)
+ for index in 0..<source.count {
+ if let src = source[index].mData, let dst = destination[index].mData {
+ memcpy(dst, src, min(Int(source[index].mDataByteSize), Int(destination[index].mDataByteSize)))
+ }
+ }
+ worker.async {
+ defer { slots.signal() }
+ guard !done.isStopped else { return }
+ let capacity = AVAudioFrameCount(ceil(Double(copy.frameLength) * 48_000 / format.sampleRate)) + 64
+ guard let converted = AVAudioPCMBuffer(pcmFormat: target, frameCapacity: capacity) else { return }
+ var supplied = false
+ var error: NSError?
+ let status = converter.convert(to: converted, error: &error) { _, state in
+ if supplied { state.pointee = .noDataNow; return nil }
+ supplied = true
+ state.pointee = .haveData
+ return copy
+ }
+ if status == .error {
+ done.signal(error ?? CaptureFailure(description: "microphone conversion failed") as NSError)
+ return
+ }
+ do { try output.appendPCM(converted) } catch { done.signal(error) }
+ }
+ }
+ tapped = true
+ try capture.start()
+ } catch { done.signal(error) }
+ }
+ }
+ switch AVCaptureDevice.authorizationStatus(for: .audio) {
+ case .authorized: permitted(true)
+ case .notDetermined: AVCaptureDevice.requestAccess(for: .audio, completionHandler: permitted)
+ default: permitted(false)
+ }
+ try done.wait()
+}
+
private func captureAudio(_ arguments: [String]) async throws {
guard arguments.count == 5,
arguments[1] == "--capture-audio",
@@ -1763,6 +1915,12 @@ private struct PiikCapture {
try selfTest()
} else if arguments.count == 2, arguments[1] == "--list" {
try await listSources()
+ } else if arguments.count == 2, arguments[1] == "--list-microphones" {
+ try listMicrophones()
+ } else if arguments.count == 2, arguments[1] == "--capture-microphone" {
+ try captureMicrophone()
+ } else if arguments.count == 4, arguments[1] == "--capture-microphone", arguments[2] == "--device", !arguments[3].isEmpty, arguments[3].utf8.count <= 512 {
+ try captureMicrophone(deviceUID: arguments[3])
} else if arguments.count > 1, arguments[1] == "--capture-audio" {
try await captureAudio(arguments)
} else if arguments.count > 1, arguments[1] == "--encoded-video" {
diff --git a/native/capture/linux/main.c b/native/capture/linux/main.c
index 464b8f57..38143b68 100644
--- a/native/capture/linux/main.c
+++ b/native/capture/linux/main.c
@@ -316,10 +316,10 @@ static int write_probe(void) {
g_string_append_printf(
json,
"{\"protocol\":%d,\"platform\":\"linux\",\"platformBuild\":%s,"
- "\"videoCapture\":%s,\"softwareVP8\":false,\"processAudio\":false,\"systemAudio\":%s,"
+ "\"videoCapture\":%s,\"softwareVP8\":false,\"processAudio\":false,\"systemAudio\":%s,\"microphone\":%s,"
"\"adapters\":[",
kCaptureProtocol, build, video ? "true" : "false",
- audio ? "true" : "false");
+ audio ? "true" : "false", audio ? "true" : "false");
g_free(build);
if (encoders->len > 0) {
g_string_append(json,
@@ -1234,27 +1234,69 @@ cleanup:
return result;
}
+static int write_microphones(void) {
+ GstDeviceMonitor *monitor = gst_device_monitor_new();
+ gst_device_monitor_add_filter(monitor, "Audio/Source", NULL);
+ if (!gst_device_monitor_start(monitor)) { gst_object_unref(monitor); return 2; }
+ GList *devices = gst_device_monitor_get_devices(monitor);
+ GString *json = g_string_new("[");
+ guint count = 0;
+ for (GList *item = devices; item != NULL && count < 64; item = item->next) {
+ GstElement *source = gst_device_create_element(GST_DEVICE(item->data), NULL);
+ GstElementFactory *factory = source == NULL ? NULL : gst_element_get_factory(source);
+ if (factory != NULL && strcmp(gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory)), "pulsesrc") == 0) {
+ gchar *device = NULL;
+ g_object_get(source, "device", &device, NULL);
+ if (device != NULL && device[0] != '\0') {
+ gchar *name = gst_device_get_display_name(GST_DEVICE(item->data));
+ gchar *id_json = json_string(device), *name_json = json_string(name);
+ g_string_append_printf(json, "%s{\"id\":%s,\"label\":%s}", count++ == 0 ? "" : ",", id_json, name_json);
+ g_free(id_json); g_free(name_json); g_free(name);
+ }
+ g_free(device);
+ }
+ if (source != NULL) gst_object_unref(source);
+ }
+ g_string_append_c(json, ']');
+ fputs(json->str, stdout);
+ g_string_free(json, TRUE);
+ g_list_free_full(devices, gst_object_unref);
+ gst_device_monitor_stop(monitor);
+ gst_object_unref(monitor);
+ return ferror(stdout) ? 2 : 0;
+}
+
static int capture_audio(int count, char **values) {
- if (count != 5 || strcmp(values[1], "--capture-audio") != 0 ||
+ gboolean microphone = (count == 2 || (count == 4 && strcmp(values[2], "--device") == 0 &&
+ values[3][0] != '\0' && strlen(values[3]) <= 512)) && strcmp(values[1], "--capture-microphone") == 0;
+ if (!microphone && (count != 5 || strcmp(values[1], "--capture-audio") != 0 ||
(strcmp(values[2], "picker") != 0 &&
strcmp(values[2], "display") != 0) ||
strcmp(values[3], "0") != 0 ||
- strcmp(values[4], "0") != 0 || !audio_stack_available()) {
+ strcmp(values[4], "0") != 0)) {
return 2;
}
GError *error = NULL;
- GstElement *pipeline = gst_parse_launch(
- "pulsesrc device=@DEFAULT_MONITOR@ do-timestamp=true ! "
+ if (!audio_stack_available()) return 2;
+ gchar *description = g_strconcat(
+ microphone ? "pulsesrc name=microphone do-timestamp=true ! " : "pulsesrc device=@DEFAULT_MONITOR@ do-timestamp=true ! ",
"queue max-size-buffers=4 max-size-bytes=0 max-size-time=0 "
"leaky=downstream ! audioconvert ! audioresample ! "
"audio/x-raw,format=S16LE,rate=48000,channels=2,layout=interleaved ! "
- "appsink name=output emit-signals=true sync=false max-buffers=4 drop=true",
- &error);
+ "appsink name=output emit-signals=true sync=false max-buffers=4 drop=true", NULL);
+ GstElement *pipeline = gst_parse_launch(description, &error);
+ g_free(description);
if (pipeline == NULL || error != NULL) {
g_clear_error(&error);
if (pipeline != NULL) gst_object_unref(pipeline);
return 2;
}
+ if (microphone && count == 4) {
+ GstElement *input = gst_bin_get_by_name(GST_BIN(pipeline), "microphone");
+ if (input == NULL) { gst_object_unref(pipeline); return 2; }
+ g_object_set(input, "device", values[3], NULL);
+ gst_object_unref(input);
+ }
CaptureRun run = {
.loop = g_main_loop_new(NULL, FALSE),
.pipeline = pipeline,
@@ -1276,13 +1318,15 @@ static int capture_audio(int count, char **values) {
}
int main(int argc, char **argv) {
- gst_init(&argc, &argv);
+ // Piik owns this CLI. Opaque device IDs must never become GStreamer flags.
+ gst_init(NULL, NULL);
if (argc == 2 && strcmp(argv[1], "--probe") == 0) return write_probe();
if (argc == 2 && strcmp(argv[1], "--list") == 0) return write_sources();
+ if (argc == 2 && strcmp(argv[1], "--list-microphones") == 0) return write_microphones();
if (argc > 1 && (strcmp(argv[1], "--capture-video") == 0 || strcmp(argv[1], "--encoded-video") == 0)) {
return capture_video(argc, argv);
}
- if (argc > 1 && strcmp(argv[1], "--capture-audio") == 0) {
+ if (argc > 1 && (strcmp(argv[1], "--capture-audio") == 0 || strcmp(argv[1], "--capture-microphone") == 0)) {
return capture_audio(argc, argv);
}
fprintf(stderr, "Piik capture unavailable: unsupported command\n");
diff --git a/native/capture/windows/README.md b/native/capture/windows/README.md
index 59dc7e72..7bd87e62 100644
--- a/native/capture/windows/README.md
+++ b/native/capture/windows/README.md
@@ -46,7 +46,8 @@ npm run check:native
```
The checks include synthetic output-worker replacement and failure cases using
-WARP and a test codec. They do not capture a screen or validate a physical encoder.
+WARP and a test codec, plus preview cleanup when WGC rejects a hidden test window.
+They do not capture a user screen or validate a physical encoder.
The implementation follows Microsoft's MIT-licensed reference samples and
official API contracts without copying their WIL framework. The retained MF
diff --git a/native/capture/windows/capture_target.cpp b/native/capture/windows/capture_target.cpp
index 3b1de556..9f74c3c9 100644
--- a/native/capture/windows/capture_target.cpp
+++ b/native/capture/windows/capture_target.cpp
@@ -1,6 +1,8 @@
#define NOMINMAX
#include <windows.h>
#include <dwmapi.h>
+#include <mmdeviceapi.h>
+#include <functiondiscoverykeys_devpkey.h>
#include <shellapi.h>
#include <d3d11.h>
#include <dxgi1_2.h>
@@ -921,6 +923,41 @@ HRESULT CapturePreview(TargetKind kind, UINT64 source_id,
} // namespace
+int WriteMicrophoneList() {
+ if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) return 2;
+ const int result = []() {
+ ComPtr<IMMDeviceEnumerator> enumerator;
+ ComPtr<IMMDeviceCollection> devices;
+ if (FAILED(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, IID_PPV_ARGS(&enumerator))) ||
+ FAILED(enumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &devices))) return 2;
+ UINT count = 0;
+ if (FAILED(devices->GetCount(&count)) || count > 64) return 2;
+ std::cout << '[';
+ bool first = true;
+ for (UINT index = 0; index < count; ++index) {
+ ComPtr<IMMDevice> device;
+ ComPtr<IPropertyStore> properties;
+ if (FAILED(devices->Item(index, &device)) || FAILED(device->OpenPropertyStore(STGM_READ, &properties))) continue;
+ LPWSTR id = nullptr;
+ PROPVARIANT name;
+ PropVariantInit(&name);
+ if (SUCCEEDED(device->GetId(&id)) && SUCCEEDED(properties->GetValue(PKEY_Device_FriendlyName, &name)) &&
+ name.vt == VT_LPWSTR && name.pwszVal != nullptr) {
+ if (!first) std::cout << ',';
+ first = false;
+ std::cout << "{\"id\":" << JsonString(Utf8(id))
+ << ",\"label\":" << JsonString(Utf8(name.pwszVal)) << '}';
+ }
+ CoTaskMemFree(id);
+ PropVariantClear(&name);
+ }
+ std::cout << ']';
+ return std::cout.good() ? 0 : 2;
+ }();
+ CoUninitialize();
+ return result;
+}
+
int WriteSourceList() {
std::vector<SourceTarget> targets;
if (!EnumDisplayMonitors(nullptr, nullptr, CollectDisplay,
diff --git a/native/capture/windows/capture_target.h b/native/capture/windows/capture_target.h
index 94898b11..e1ccf2c8 100644
--- a/native/capture/windows/capture_target.h
+++ b/native/capture/windows/capture_target.h
@@ -9,6 +9,7 @@ namespace piik::capture {
enum class TargetKind { window, display };
int WriteSourceList();
+int WriteMicrophoneList();
HRESULT WriteSourcePreview(TargetKind kind, UINT64 source_id, DWORD pid,
UINT64 expected_creation_time);
HRESULT ValidateProcessTarget(DWORD pid, UINT64 expected_creation_time);
diff --git a/native/capture/windows/main.cpp b/native/capture/windows/main.cpp
index a37142c6..92eb4831 100644
--- a/native/capture/windows/main.cpp
+++ b/native/capture/windows/main.cpp
@@ -920,9 +920,10 @@ piik::capture::TargetKind ParseTargetKind(const wchar_t* value) {
}
struct ProductArguments final {
- enum class Mode { list, probe, preview, audio, video, encoded } mode = Mode::list;
+ enum class Mode { list, microphones, probe, preview, audio, microphone, video, encoded } mode = Mode::list;
piik::capture::TargetKind target_kind =
piik::capture::TargetKind::window;
+ std::wstring microphone_device;
DWORD pid = 0;
UINT64 creation_time = 0;
UINT64 source_id = 0;
@@ -1005,6 +1006,18 @@ ProductArguments ParseProductArguments(int count, wchar_t** values) {
ParseNonNegativeUint64(values[5], "argument-creation-time");
return arguments;
}
+ if (count == 2 && std::wstring(values[1]) == L"--list-microphones") {
+ arguments.mode = ProductArguments::Mode::microphones;
+ return arguments;
+ }
+ if ((count == 2 || (count == 4 && std::wstring(values[2]) == L"--device")) && std::wstring(values[1]) == L"--capture-microphone") {
+ if (count == 4) {
+ arguments.microphone_device = values[3];
+ if (arguments.microphone_device.empty() || arguments.microphone_device.size() > 512) Fail("argument-device", "microphone device is invalid");
+ }
+ arguments.mode = ProductArguments::Mode::microphone;
+ return arguments;
+ }
if (count == 5 && std::wstring(values[1]) == L"--capture-audio") {
arguments.mode = ProductArguments::Mode::audio;
arguments.target_kind = ParseTargetKind(values[2]);
@@ -1105,6 +1118,9 @@ HRESULT RunAudioCapture(const ProductArguments& arguments) {
piik::capture::kAudioChunkDuration100ns, data,
size);
};
+ if (arguments.mode == ProductArguments::Mode::microphone) {
+ return piik::capture::CaptureMicrophone(arguments.microphone_device, stop.get(), should_stop, ready, pcm);
+ }
if (arguments.target_kind == piik::capture::TargetKind::display) {
return piik::capture::CaptureSystemAudio(
stop.get(), should_stop, ready, pcm);
@@ -1159,7 +1175,7 @@ void WriteCapabilityProbe() {
<< ",\"videoCapture\":" << (window_capture ? "true" : "false")
<< ",\"captureBorderControl\":"
<< (window_capture && piik::capture::CaptureBorder::Supported() ? "true" : "false")
- << ",\"softwareVP8\":true"
+ << ",\"microphone\":true,\"softwareVP8\":true"
<< ",\"processAudio\":"
<< (process_audio ? "true" : "false")
<< ",\"systemAudio\":" << (system_audio ? "true" : "false")
@@ -2063,6 +2079,7 @@ int wmain(int argc, wchar_t** argv) {
int wmain(int argc, wchar_t** argv) {
try {
ProductArguments arguments = ParseProductArguments(argc, argv);
+ if (arguments.mode == ProductArguments::Mode::microphones) return piik::capture::WriteMicrophoneList();
if (arguments.mode == ProductArguments::Mode::list) {
return piik::capture::WriteSourceList();
}
@@ -2081,7 +2098,7 @@ int wmain(int argc, wchar_t** argv) {
"capture-preview");
return 0;
}
- if (arguments.mode == ProductArguments::Mode::audio) {
+ if (arguments.mode == ProductArguments::Mode::audio || arguments.mode == ProductArguments::Mode::microphone) {
Check(RunAudioCapture(arguments), "process-audio-capture");
return 0;
}
diff --git a/native/capture/windows/process_audio.cpp b/native/capture/windows/process_audio.cpp
index d6d6b400..ca847062 100644
--- a/native/capture/windows/process_audio.cpp
+++ b/native/capture/windows/process_audio.cpp
@@ -77,13 +77,22 @@ HRESULT ActivateProcessLoopback(DWORD pid, HANDLE completed,
return result;
}
-HRESULT ActivateSystemLoopback(ComPtr<IAudioClient>* client) {
+HRESULT ActivateEndpoint(ComPtr<IAudioClient>* client, bool microphone = false, const std::wstring& device_id = L"") {
ComPtr<IMMDeviceEnumerator> enumerator;
HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
CLSCTX_ALL, IID_PPV_ARGS(&enumerator));
ComPtr<IMMDevice> device;
if (SUCCEEDED(result)) {
- result = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device);
+ result = device_id.empty()
+ ? enumerator->GetDefaultAudioEndpoint(microphone ? eCapture : eRender, microphone ? eCommunications : eConsole, &device)
+ : enumerator->GetDevice(device_id.c_str(), &device);
+ if (SUCCEEDED(result) && microphone) {
+ ComPtr<IMMEndpoint> endpoint;
+ EDataFlow flow = eAll;
+ result = device.As(&endpoint);
+ if (SUCCEEDED(result)) result = endpoint->GetDataFlow(&flow);
+ if (SUCCEEDED(result) && flow != eCapture) result = E_INVALIDARG;
+ }
}
if (SUCCEEDED(result)) {
result = device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr,
@@ -92,7 +101,7 @@ HRESULT ActivateSystemLoopback(ComPtr<IAudioClient>* client) {
return result;
}
-HRESULT CaptureLoopbackAudio(ComPtr<IAudioClient> client, HANDLE process,
+HRESULT CaptureAudioFrames(ComPtr<IAudioClient> client, HANDLE process, bool loopback,
HANDLE stop_event, const StopProbe& stop_probe,
const ReadyWriter& ready_writer,
const PCMWriter& writer) {
@@ -115,7 +124,7 @@ HRESULT CaptureLoopbackAudio(ComPtr<IAudioClient> client, HANDLE process,
format.nAvgBytesPerSec = kAudioSampleRate * format.nBlockAlign;
if (SUCCEEDED(result)) {
result = client->Initialize(AUDCLNT_SHAREMODE_SHARED,
- AUDCLNT_STREAMFLAGS_LOOPBACK | AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
+ (loopback ? AUDCLNT_STREAMFLAGS_LOOPBACK : 0) | AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY,
0, 0, &format, nullptr);
}
@@ -221,7 +230,7 @@ bool ProcessAudioAvailable() {
bool SystemAudioAvailable() {
ComPtr<IAudioClient> client;
- return SUCCEEDED(ActivateSystemLoopback(&client)) && client != nullptr;
+ return SUCCEEDED(ActivateEndpoint(&client)) && client != nullptr;
}
HRESULT CaptureProcessAudio(DWORD pid, UINT64 expectedCreationTime,
@@ -246,7 +255,7 @@ HRESULT CaptureProcessAudio(DWORD pid, UINT64 expectedCreationTime,
result = ActivateProcessLoopback(pid, completed, &client);
}
if (SUCCEEDED(result)) {
- result = CaptureLoopbackAudio(client, process, stop_event, stop_probe,
+ result = CaptureAudioFrames(client, process, true, stop_event, stop_probe,
ready_writer, writer);
}
if (completed != nullptr) CloseHandle(completed);
@@ -262,9 +271,9 @@ HRESULT CaptureSystemAudio(HANDLE stop_event, const StopProbe& stop_probe,
HRESULT com_result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(com_result)) return com_result;
ComPtr<IAudioClient> client;
- HRESULT result = ActivateSystemLoopback(&client);
+ HRESULT result = ActivateEndpoint(&client);
if (SUCCEEDED(result)) {
- result = CaptureLoopbackAudio(client, nullptr, stop_event, stop_probe,
+ result = CaptureAudioFrames(client, nullptr, true, stop_event, stop_probe,
ready_writer, writer);
}
client.Reset();
@@ -272,4 +281,18 @@ HRESULT CaptureSystemAudio(HANDLE stop_event, const StopProbe& stop_probe,
return result;
}
+HRESULT CaptureMicrophone(const std::wstring& device_id, HANDLE stop_event, const StopProbe& stop_probe,
+ const ReadyWriter& ready_writer, const PCMWriter& writer) {
+ HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
+ if (FAILED(result)) return result;
+ ComPtr<IAudioClient> client;
+ result = ActivateEndpoint(&client, true, device_id);
+ if (SUCCEEDED(result)) {
+ result = CaptureAudioFrames(client, nullptr, false, stop_event, stop_probe, ready_writer, writer);
+ }
+ client.Reset();
+ CoUninitialize();
+ return result;
+}
+
} // namespace piik::capture
diff --git a/native/capture/windows/process_audio.h b/native/capture/windows/process_audio.h
index 692b9915..55e0215b 100644
--- a/native/capture/windows/process_audio.h
+++ b/native/capture/windows/process_audio.h
@@ -4,6 +4,7 @@
#include <cstdint>
#include <functional>
+#include <string>
namespace piik::capture {
@@ -22,6 +23,8 @@ using StopProbe = std::function<bool()>;
bool ProcessAudioAvailable();
bool SystemAudioAvailable();
+HRESULT CaptureMicrophone(const std::wstring& device_id, HANDLE stop_event, const StopProbe& stop_probe,
+ const ReadyWriter& ready_writer, const PCMWriter& writer);
HRESULT CaptureProcessAudio(DWORD pid, UINT64 expected_creation_time,
HANDLE stop_event, const StopProbe& stop_probe,
const ReadyWriter& ready_writer,
diff --git a/scripts/access-privacy-gate.ts b/scripts/access-privacy-gate.ts
index 001cc215..e2ffc1ec 100644
--- a/scripts/access-privacy-gate.ts
+++ b/scripts/access-privacy-gate.ts
@@ -329,7 +329,7 @@ async function main(): Promise<void> {
throw new Error("Room preparation did not enable the Viewer password");
}
report.roomPrepared = true;
- chrome = launchChrome(chromePath, debugPort, profile, [
+ chrome = await launchChrome(chromePath, debugPort, profile, [
"--headless=new", "--no-first-run", "--disable-extensions",
"--disable-logging",
], { cwd: root });
diff --git a/scripts/app-browser-fanout-gate.ts b/scripts/app-browser-fanout-gate.ts
index b38b986f..44d38eae 100644
--- a/scripts/app-browser-fanout-gate.ts
+++ b/scripts/app-browser-fanout-gate.ts
@@ -1,4 +1,5 @@
import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "node:child_process";
+import { once } from "node:events";
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
@@ -6,7 +7,7 @@ import {
CdpConnection, cleanupRun, createPage, evaluate, fetchJsonBefore, launchChrome, reservePort,
waitForSample, waitForVersion, type PageHandle,
} from "./browser-gate-harness";
-import { decodeAppEndpoint } from "./app-gate-endpoint";
+import { readAppEndpoint } from "./app-gate-endpoint";
const ROOT = resolve(import.meta.dirname, "..");
const BUILD_ROOT = join(ROOT, "build/go-check");
@@ -96,7 +97,8 @@ const probe = String.raw`(() => {
})()`;
function build(command: string, args: string[]): void {
- const result = spawnSync(command, args, { cwd: ROOT, encoding: "utf8", windowsHide: true });
+ const result = spawnSync(command, args, { cwd: ROOT, encoding: "utf8", windowsHide: true,
+ timeout: 120_000, killSignal: "SIGKILL" });
if (result.error) throw result.error;
if (result.status !== 0) {
throw new Error((result.stderr || result.stdout).trim() || command + " failed");
@@ -136,12 +138,18 @@ async function startRoomServer(
});
child.stdout.resume();
child.stderr.resume();
- await waitForSample(
- (deadline) => fetchJsonBefore<{ status: string }>(`http://127.0.0.1:${port}/healthz`, deadline),
- (value) => value.status === "ok",
- 20000,
- );
- return child;
+ try {
+ await once(child, "spawn");
+ await waitForSample(
+ (deadline) => fetchJsonBefore<{ status: string }>(`http://127.0.0.1:${port}/healthz`, deadline),
+ (value) => value.status === "ok",
+ 20000,
+ );
+ return child;
+ } catch (error) {
+ await cleanupRun({ server: child, chrome: null, native: null, cdp: null, profile: null, ports: [port] });
+ throw error;
+ }
}
async function main(): Promise<void> {
@@ -167,14 +175,11 @@ async function main(): Promise<void> {
"--site", origin, "--config", join(profile, "client.json"),
"--capture-process", join(BUILD_ROOT, "piik-capture.exe"),
], { windowsHide: true, stdio: "pipe", env: { ...process.env, PIIK_CLIENT_GATE_NO_BROWSER: "true" } });
+ await once(app, "spawn");
app.stderr.resume();
- let output = "";
- app.stdout.on("data", (chunk: Buffer) => {
- output += chunk.toString();
- if (!nativePort && output.includes("\n")) nativePort = decodeAppEndpoint(output.split("\n")[0]!).port;
- });
- await waitForSample(async () => nativePort, (value) => value > 0, 15000);
- chrome = launchChrome(chromePath, debugPort, profile, [
+ nativePort = (await readAppEndpoint(app)).port;
+ app.stdout.resume();
+ chrome = await launchChrome(chromePath, debugPort, profile, [
"--headless=new",
"--no-first-run", "--no-default-browser-check", "--no-proxy-server",
"--autoplay-policy=no-user-gesture-required", "--disable-background-timer-throttling",
@@ -215,12 +220,10 @@ async function main(): Promise<void> {
"--site", relayOrigin, "--config", join(profile,"relay-client.json"),
"--capture-process", join(BUILD_ROOT,"piik-capture.exe"),
], { windowsHide:true, stdio:"pipe", env:{...process.env,PIIK_CLIENT_GATE_NO_BROWSER:"true"} });
- relayApp.stderr.resume(); let relayOutput="";
- relayApp.stdout.on("data", (chunk:Buffer) => {
- relayOutput+=chunk.toString();
- if (!relayPort && relayOutput.includes("\n")) relayPort=decodeAppEndpoint(relayOutput.split("\n")[0]!).port;
- });
- await waitForSample(async()=>relayPort,(value)=>value>0,15000);
+ await once(relayApp, "spawn");
+ relayApp.stderr.resume();
+ relayPort = (await readAppEndpoint(relayApp)).port;
+ relayApp.stdout.resume();
const viewers: PageHandle[] = [];
for (let index=0; index<2; index++) {
stage = `viewer-${index+1}`;
diff --git a/scripts/app-icons.mjs b/scripts/app-icons.mjs
index fd46cb33..5c6af9e4 100644
--- a/scripts/app-icons.mjs
+++ b/scripts/app-icons.mjs
@@ -139,6 +139,7 @@ function writeMacAssets(packageRoot, version, revision, entries) {
"<key>CFBundlePackageType</key><string>APPL</string>",
`<key>CFBundleShortVersionString</key><string>${bundleVersion}</string>`,
"<key>NSScreenCaptureUsageDescription</key><string>Share a screen or application selected by you.</string>",
+ "<key>NSMicrophoneUsageDescription</key><string>Include your voice while sharing.</string>",
"<key>NSAudioCaptureUsageDescription</key><string>Share sound from the selected screen or application.</string>",
`<key>CFBundleVersion</key><string>${bundleVersion}</string>`,
`<key>PiikSourceRevision</key><string>${revision}</string>`,
diff --git a/scripts/app-link-gate.ts b/scripts/app-link-gate.ts
index 7ca830e4..815b16be 100644
--- a/scripts/app-link-gate.ts
+++ b/scripts/app-link-gate.ts
@@ -1,4 +1,5 @@
import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "node:child_process";
+import { once } from "node:events";
import { mkdir, mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
@@ -66,12 +67,16 @@ function run(
args: string[],
cwd = ROOT,
environment: NodeJS.ProcessEnv = process.env,
+ timeoutMs = 120_000,
): string {
const result = spawnSync(command, args, {
cwd,
env: environment,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
+ timeout: timeoutMs,
+ killSignal: "SIGKILL",
+ windowsHide: true,
});
if (result.error) throw result.error;
if (result.status !== 0) {
@@ -121,8 +126,9 @@ async function waitForRemotePage(
const result = spawnSync(ssh, [
...transport,
destination,
- "curl", "--fail", "--silent", url,
- ], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
+ "curl", "--fail", "--silent", "--connect-timeout", "5", "--max-time", "8", url,
+ ], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true,
+ timeout: Math.max(1, Math.min(10_000, deadline - Date.now())), killSignal: "SIGKILL" });
if (result.status === 0 && result.stdout.includes('<div id="root"></div>')) {
return result.stdout;
}
@@ -134,12 +140,14 @@ async function waitForRemotePage(
async function createInvitation(port: number, password: string): Promise<string> {
const origin = `http://localhost:${port}`;
const access = await fetch(`${origin}/api/site-access`, {
+ signal: AbortSignal.timeout(5_000),
method: "POST",
headers: { Authorization: `Bearer ${password}`, Origin: origin },
});
const cookie = access.headers.get("set-cookie")?.split(";", 1)[0];
if (!access.ok) throw new Error("Local access authentication failed");
const room = await fetch(`${origin}/api/rooms`, {
+ signal: AbortSignal.timeout(5_000),
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -156,15 +164,15 @@ async function createInvitation(port: number, password: string): Promise<string>
}
async function stopApp(child: ChildProcessWithoutNullStreams | null): Promise<boolean> {
- if (!child || child.exitCode !== null || child.signalCode !== null) return true;
- child.stdin.write("\n");
+ if (!child?.pid || child.exitCode !== null || child.signalCode !== null) return true;
+ const exited = once(child, "exit");
+ child.stdin.once("error", () => {}); // Exit may race the stop request (EPIPE).
try {
- await withDeadline(
- () => new Promise<void>((resolveExit) => child.once("exit", () => resolveExit())),
- Date.now() + 8_000,
- );
+ child.stdin.end("\n");
+ await withDeadline(() => exited, Date.now() + 8_000);
} catch {
- child.kill();
+ child.kill("SIGKILL");
+ await withDeadline(() => exited, Date.now() + 3_000).catch(() => undefined);
}
return child.exitCode !== null || child.signalCode !== null;
}
@@ -172,11 +180,13 @@ async function stopApp(child: ChildProcessWithoutNullStreams | null): Promise<bo
async function waitUntilLinkCloses(origin: string): Promise<boolean> {
const deadline = Date.now() + 15_000;
while (Date.now() < deadline) {
+ const signal = AbortSignal.timeout(Math.max(1, Math.min(5_000, deadline - Date.now())));
try {
- const response = await fetch(`${origin}/healthz`, { cache: "no-store" });
+ const response = await fetch(`${origin}/healthz`, { cache: "no-store", signal });
if (!response.ok) return true;
} catch {
- return true;
+ // A silent request is not proof that the invitation was retired.
+ if (!signal.aborted) return true;
}
await new Promise((resolveWait) => setTimeout(resolveWait, 250));
}
@@ -239,6 +249,7 @@ async function main(): Promise<void> {
stdio: "pipe",
windowsHide: true,
});
+ await once(app, "spawn");
const output = new LineCapture(app);
const accessLine = await output.wait(
(line) => line.startsWith("Local access password: ") || line === "Local access: open",
@@ -283,7 +294,7 @@ async function main(): Promise<void> {
...transport,
destination,
websocketProbe,
- ]);
+ ], ROOT, process.env, Math.max(1, Math.min(10_000, websocketDeadline - Date.now())));
result.remoteWebSocket = upgrade.includes("101 Switching Protocols");
if (!result.remoteWebSocket) {
await new Promise((resolveWait) => setTimeout(resolveWait, 250));
diff --git a/scripts/app-local-gate.ts b/scripts/app-local-gate.ts
index 24347099..ab616a35 100644
--- a/scripts/app-local-gate.ts
+++ b/scripts/app-local-gate.ts
@@ -124,7 +124,7 @@ async function main(): Promise<void> {
"piik-client": "1",
}).toString();
- browser = launchChrome(browserPath, debugPort, profile, [
+ browser = await launchChrome(browserPath, debugPort, profile, [
"--headless=new",
...(process.env.PIIK_CLIENT_GATE_NO_SANDBOX === "true"
? ["--no-sandbox"]
diff --git a/scripts/app-loopback-gate.ts b/scripts/app-loopback-gate.ts
index e0fd9f02..f7982ab1 100644
--- a/scripts/app-loopback-gate.ts
+++ b/scripts/app-loopback-gate.ts
@@ -199,7 +199,7 @@ async function main(): Promise<void> {
portServer.close((error) => error ? rejectPort(error) : resolvePort(address.port));
});
});
- browser = launchChrome(browserPath, debugPort, profile, [
+ browser = await launchChrome(browserPath, debugPort, profile, [
"--headless=new",
...(disposableNoSandbox ? ["--no-sandbox"] : []),
"--no-first-run",
diff --git a/scripts/app-media-gate.ts b/scripts/app-media-gate.ts
index 958ab026..27b1ad6d 100644
--- a/scripts/app-media-gate.ts
+++ b/scripts/app-media-gate.ts
@@ -743,7 +743,7 @@ async function main(): Promise<void> {
}
server = await startPageServer(pagePort);
- chrome = launchChrome(chromePath, debugPort, profile, [
+ chrome = await launchChrome(chromePath, debugPort, profile, [
"--no-first-run",
"--no-default-browser-check",
"--disable-extensions",
diff --git a/scripts/app-native-host-gate.ts b/scripts/app-native-host-gate.ts
index 0cf1a83e..ca281f86 100644
--- a/scripts/app-native-host-gate.ts
+++ b/scripts/app-native-host-gate.ts
@@ -126,12 +126,16 @@ function run(
args: string[],
cwd = ROOT,
environment: NodeJS.ProcessEnv = process.env,
+ timeoutMs = 120_000,
): string {
const result = spawnSync(command, args, {
cwd,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
env: environment,
+ timeout: timeoutMs,
+ killSignal: "SIGKILL",
+ windowsHide: true,
});
if (result.error) throw result.error;
if (result.status !== 0) {
@@ -163,6 +167,8 @@ async function stopChild(child: ChildProcessWithoutNullStreams | ChildProcess |
if (process.platform === "win32" && child.pid !== undefined) {
spawnSync("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], {
stdio: "ignore",
+ timeout: 5_000,
+ windowsHide: true,
});
try {
await waitForChild(child, 2_000);
@@ -299,8 +305,8 @@ async function runRemotePeerGate(
const remotePath = `/tmp/piik-peer-gate-${randomBytes(8).toString("hex")}`;
const transportOptions = remoteTransportOptions(options);
try {
- run(scp, [...transportOptions, binary, `${destination}:${remotePath}`]);
- run(ssh, [...transportOptions, destination, "chmod", "700", remotePath]);
+ run(scp, [...transportOptions, binary, `${destination}:${remotePath}`], ROOT, process.env, 30_000);
+ run(ssh, [...transportOptions, destination, "chmod", "700", remotePath], ROOT, process.env, 15_000);
const remote = spawn(
ssh,
[
@@ -367,7 +373,7 @@ async function runRemotePeerGate(
};
} finally {
try {
- run(ssh, [...transportOptions, destination, "rm", "-f", remotePath]);
+ run(ssh, [...transportOptions, destination, "rm", "-f", remotePath], ROOT, process.env, 10_000);
} catch {
// The temporary binary is harmless if an already-closed SSH session
// prevents cleanup; the gate never places it in the repository.
@@ -425,7 +431,7 @@ export async function startSourceBrowser(
child: ChildProcessWithoutNullStreams;
cdp: CdpConnection;
}> {
- const child = launchChrome(chromePath, debugPort, profile, [
+ const child = await launchChrome(chromePath, debugPort, profile, [
"--no-first-run", "--no-default-browser-check",
"--disable-extensions", "--disable-logging",
"--disable-background-timer-throttling",
@@ -435,12 +441,17 @@ export async function startSourceBrowser(
]);
child.stdout.resume();
child.stderr.resume();
- const version = await waitForVersion(debugPort, child);
- const cdp = await CdpConnection.connect(
- version.webSocketDebuggerUrl,
- Date.now() + 10_000,
- );
- return { child, cdp };
+ try {
+ const version = await waitForVersion(debugPort, child);
+ const cdp = await CdpConnection.connect(
+ version.webSocketDebuggerUrl,
+ Date.now() + 10_000,
+ );
+ return { child, cdp };
+ } catch (error) {
+ await cleanupRun({ chrome: child, cdp: null, native: null, server: null, profile: null, ports: [debugPort] });
+ throw error;
+ }
}
export async function closeSourceBrowser(
@@ -461,7 +472,7 @@ export async function closeSourceBrowser(
export async function waitForCaptureWindow(captureBinary: string): Promise<void> {
await waitForValue(
- async () => JSON.parse(run(captureBinary, ["--list"])) as Array<{
+ async () => JSON.parse(run(captureBinary, ["--list"], ROOT, process.env, 5_000)) as Array<{
title?: unknown;
}>,
(targets) => targets.some((target) =>
@@ -746,7 +757,7 @@ async function main(): Promise<void> {
15_000,
);
stage = "host-browser";
- chrome = launchChrome(chromePath, debugPort, profile, [
+ chrome = await launchChrome(chromePath, debugPort, profile, [
"--no-first-run", "--no-default-browser-check",
"--disable-extensions", "--disable-logging",
"--disable-background-timer-throttling",
@@ -801,6 +812,7 @@ async function main(): Promise<void> {
5_000,
);
stage = "pre-share-codec";
+ await clickHostControl(cdp, host, `document.querySelector('.lr-sharing-technical > summary')`);
await clickHostControl(cdp, host,
`([...document.querySelectorAll('button.lr-chip')].find((button) =>
button.textContent?.trim() === ${JSON.stringify(requestedCodec.toUpperCase())}))`,
@@ -956,6 +968,9 @@ async function main(): Promise<void> {
Date.now() + 5_000,
);
stage = "native-quality-presets";
+ await clickHostControl(cdp, host,
+ `document.querySelector('button[aria-controls="host-advanced-door"]')`,
+ );
for (const [index, width, height] of [[0, 1280, 720], [1, 1920, 1080]] as const) {
await clickHostControl(cdp, host, `document.querySelectorAll('button.lr-tile')[${index}]`);
await waitForValue(
@@ -974,12 +989,6 @@ async function main(): Promise<void> {
result.livePresetChanges += 1;
}
stage = "native-quality-controls";
- await evaluate<void>(
- cdp,
- host,
- `document.querySelector('button[aria-controls="host-advanced-door"]')?.click()`,
- Date.now() + 5_000,
- );
await waitForValue(
(deadline) => evaluate<boolean>(
cdp!,
@@ -1190,7 +1199,7 @@ async function main(): Promise<void> {
Date.now() + 5_000,
);
await waitForValue((deadline) => evaluate<boolean>(cdp!, host,
- `Boolean(document.querySelector('#host-advanced-door .lr-door-body[aria-busy="true"]'))`,
+ `Boolean(document.querySelector('#host-advanced-door .lr-sharing-panel[aria-busy="true"]'))`,
deadline,
), Boolean, 5_000);
} finally {
@@ -1219,7 +1228,7 @@ async function main(): Promise<void> {
})()`, deadline,
), Boolean, 20_000);
await waitForValue((deadline) => evaluate<boolean>(cdp!, host,
- `Boolean(document.querySelector('#host-advanced-door .lr-door-body[aria-busy="false"]'))`,
+ `Boolean(document.querySelector('#host-advanced-door .lr-sharing-panel[aria-busy="false"]'))`,
deadline,
), Boolean, 5_000);
}
@@ -1261,11 +1270,8 @@ async function main(): Promise<void> {
10_000,
);
const framesBeforeSourceChange = resumed.frames;
- await evaluate<void>(
- cdp,
- host,
- `document.querySelector('[role="dialog"] button[data-native-source]')?.click()`,
- Date.now() + 5_000,
+ await selectNativeSource(cdp, host, sourceKind,
+ sourceKind === "window" ? SOURCE_TITLE : undefined,
);
stage = "native-source-replaced";
result.nativeSourceChanged = await waitForValue(
diff --git a/scripts/browser-gate-harness.ts b/scripts/browser-gate-harness.ts
index 4b7ec3bb..72b8c0a3 100644
--- a/scripts/browser-gate-harness.ts
+++ b/scripts/browser-gate-harness.ts
@@ -1,4 +1,5 @@
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
+import { once } from "node:events";
import { lstat, readdir, rm } from "node:fs/promises";
import { createConnection, createServer } from "node:net";
import { tmpdir } from "node:os";
@@ -142,14 +143,14 @@ export class CdpConnection {
}
// launchChrome starts an isolated Chrome process with the shared CDP flags.
-export function launchChrome(
+export async function launchChrome(
executable: string,
debugPort: number,
profile: string,
flags: string[] = [],
options: { cwd?: string; env?: NodeJS.ProcessEnv } = {},
-): ChildProcessWithoutNullStreams {
- return spawn(executable, [
+): Promise<ChildProcessWithoutNullStreams> {
+ const child = spawn(executable, [
`--remote-debugging-port=${debugPort}`,
`--user-data-dir=${profile}`,
...flags,
@@ -160,6 +161,8 @@ export function launchChrome(
stdio: "pipe",
windowsHide: true,
});
+ await once(child, "spawn");
+ return child;
}
export function withDeadline<T>(
@@ -361,6 +364,7 @@ export async function cleanupRun(
? await stopProcessTree(resources.chrome)
: true;
if (resources.native && processRunning(resources.native)) {
+ resources.native.stdin.once("error", () => {}); // Exit may race the stop request (EPIPE).
try {
resources.native.stdin.write("\n");
} catch {}
@@ -396,7 +400,7 @@ export async function cleanupRun(
}
function processRunning(child: ChildProcessWithoutNullStreams): boolean {
- return child.exitCode === null && child.signalCode === null;
+ return child.pid !== undefined && child.exitCode === null && child.signalCode === null;
}
async function stopProcessTree(
diff --git a/scripts/browser-local-pool-probe.ts b/scripts/browser-local-pool-probe.ts
index a44070d8..0bf78741 100644
--- a/scripts/browser-local-pool-probe.ts
+++ b/scripts/browser-local-pool-probe.ts
@@ -66,7 +66,7 @@ const server = createServer((request, response) => {
await new Promise<void>(r => server.listen(0, '127.0.0.1', r));
const port = (server.address() as { port: number }).port, debugPort = await reservePort();
const profile = await mkdtemp(join(tmpdir(), 'piik-client-media-'));
-const chrome = launchChrome(process.env.CHROME_PATH || 'C:/Program Files/Google/Chrome/Application/chrome.exe', debugPort, profile,
+const chrome = await launchChrome(process.env.CHROME_PATH || 'C:/Program Files/Google/Chrome/Application/chrome.exe', debugPort, profile,
['--headless=new', '--no-first-run', '--autoplay-policy=no-user-gesture-required',
...(background ? [] : ['--disable-background-timer-throttling', '--disable-renderer-backgrounding']),
...(nativeSource ? ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] : [])]);
diff --git a/scripts/embedded-sfu-gate.ts b/scripts/embedded-sfu-gate.ts
index 4647b052..81a75e90 100644
--- a/scripts/embedded-sfu-gate.ts
+++ b/scripts/embedded-sfu-gate.ts
@@ -180,7 +180,7 @@ async function main(): Promise<void> {
})()`, Date.now() + 5_000);
if (audioState !== "running") throw new Error("Native source tone did not start");
}
- chrome = launchChrome(chromePath, debugPort, profile, [
+ chrome = await launchChrome(chromePath, debugPort, profile, [
"--headless=new", "--disable-gpu", "--no-first-run", "--no-default-browser-check",
"--disable-extensions", "--disable-background-networking", "--autoplay-policy=no-user-gesture-required",
"--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows",
diff --git a/src/client/components/living/CameraSources.tsx b/src/client/components/living/CameraSources.tsx
new file mode 100644
index 00000000..63591414
--- /dev/null
+++ b/src/client/components/living/CameraSources.tsx
@@ -0,0 +1,49 @@
+import { useEffect, useState } from "react";
+import { loadCameraPreviews, type CameraPreview } from "../../media/camera-previews";
+import { useCopy } from "../../ui/copy";
+import { Glyph } from "../../ui/icons";
+import { CaptureSourceCard } from "./CaptureSourceCard";
+import { HintComic } from "./hints";
+import { Pill } from "./primitives";
+
+export function useCameraSources(active: boolean, activeVideo?: HTMLVideoElement | null,
+ load = loadCameraPreviews) {
+ const [sources, setSources] = useState<CameraPreview[]>([]);
+ const [busy, setBusy] = useState(true);
+ const [error, setError] = useState<"host.camera.denied" | "host.camera.unavailable" | null>(null);
+ const [revision, refresh] = useState(0);
+ useEffect(() => {
+ if (!active) return;
+ const request = new AbortController();
+ setBusy(true); setError(null); setSources([]);
+ void load(request.signal, result => { if (!request.signal.aborted) setSources(result); }, activeVideo).catch(error => {
+ if (!request.signal.aborted) setError(error instanceof DOMException && error.name === "NotAllowedError"
+ ? "host.camera.denied" : "host.camera.unavailable");
+ }).finally(() => { if (!request.signal.aborted) setBusy(false); });
+ return () => request.abort();
+ }, [active, revision, activeVideo, load]);
+ return { sources, busy, error, refresh: () => refresh(value => value + 1) };
+}
+
+export function CameraSources({ sources, busy, error, selected, disabled, onSelect }:
+ Pick<ReturnType<typeof useCameraSources>, "sources" | "busy" | "error"> & {
+ selected: string; disabled: boolean; onSelect: (deviceId: string) => void;
+ }) {
+ const { t, vis } = useCopy();
+ return <>
+ <div className="lr-source-picker-list" aria-busy={busy}>
+ {sources.map((source, index) => <CaptureSourceCard key={source.id} cameraKey={source.id}
+ title={source.label || `${t("host.device.camera")} ${index + 1}`}
+ action={t("host.sourcePicker.camera", { title: source.label || `${t("host.device.camera")} ${index + 1}` })}
+ icon="camera" hint="hint-capture-camera" preview={source.preview}
+ selected={source.id === selected} disabled={disabled || busy} onSelect={() => onSelect(source.id)} />)}
+ </div>
+ {busy && <span className="lr-source-picker-status" role="status" aria-label={t("host.sourcePicker.loading")}>
+ <Glyph name="refresh" className="lr-spin" size={18} />{!vis && t("host.sourcePicker.loading")}
+ </span>}
+ {error ? <Pill icon="camera" label={t(error)} comic="source-failed" tone="bad" />
+ : !busy && !sources.length ? <span className="lr-source-picker-status" role="status" aria-label={t("host.sourcePicker.empty")}>
+ <HintComic kind="hint-no-sources" size={160} />{!vis && t("host.sourcePicker.empty")}
+ </span> : null}
+ </>;
+}
diff --git a/src/client/components/living/CaptureSourceCard.tsx b/src/client/components/living/CaptureSourceCard.tsx
new file mode 100644
index 00000000..1624a998
--- /dev/null
+++ b/src/client/components/living/CaptureSourceCard.tsx
@@ -0,0 +1,24 @@
+import type { Ref } from "react";
+import { Glyph, type GlyphName } from "../../ui/icons";
+import { Tooltip } from "./Tooltip";
+import type { HintKind } from "./hints";
+
+/** One visual source card; its caller owns discovery and preview resources. */
+export function CaptureSourceCard({ title, action, icon, hint, preview, disabled, selected,
+ nativeKey, cameraKey, buttonRef, onPreview, onSelect }: {
+ title: string; action: string; icon: GlyphName; hint: HintKind; preview: string | null;
+ disabled?: boolean; selected?: boolean; nativeKey?: string; cameraKey?: string;
+ buttonRef?: Ref<HTMLButtonElement>; onPreview?: () => void; onSelect: () => void;
+}) {
+ return <Tooltip kind={hint} text={title} className="lr-source-option-hint">
+ <button ref={buttonRef} type="button" className="lr-source-option"
+ data-native-source={nativeKey} data-camera-source={cameraKey}
+ aria-label={action} aria-current={selected || undefined} disabled={disabled}
+ onMouseEnter={onPreview} onFocus={onPreview} onClick={onSelect}>
+ <span className="lr-source-option-copy"><strong>{title}</strong></span>
+ <span className="lr-source-option-preview" aria-hidden="true">
+ {preview ? <img src={preview} alt="" /> : <Glyph name={icon} size={23} />}
+ </span>
+ </button>
+ </Tooltip>;
+}
diff --git a/src/client/components/living/CaptureSourcePicker.tsx b/src/client/components/living/CaptureSourcePicker.tsx
index ea133d75..be4e1c64 100644
--- a/src/client/components/living/CaptureSourcePicker.tsx
+++ b/src/client/components/living/CaptureSourcePicker.tsx
@@ -7,17 +7,21 @@ import { Glyph, type GlyphName } from "../../ui/icons";
import { Tooltip } from "./Tooltip";
import { HintComic } from "./hints";
import { Pill } from "./primitives";
-import { WaitingCaption } from "./WaitingStatus";
+import { CameraSources, useCameraSources } from "./CameraSources";
+import { CaptureSourceCard } from "./CaptureSourceCard";
+import type { loadCameraPreviews } from "../../media/camera-previews";
-const SOURCE_TABS = ["browser", "window", "display"] as const;
+const SOURCE_TABS = ["browser", "camera", "window", "display"] as const;
type SourceTab = (typeof SOURCE_TABS)[number];
const SOURCE_ICONS = {
browser: "globe",
window: "window",
display: "display",
+ camera: "camera",
} satisfies Record<SourceTab, GlyphName>;
export type NativeSourceList =
+ | { kind: "browser" }
| { kind: "loading" }
| { kind: "unavailable" }
| { kind: "incompatible" }
@@ -34,12 +38,17 @@ export type NativeSourceList =
export function CaptureSourcePicker({
nativeSources,
onBrowser,
+ onCamera,
onNative,
onPreview,
onRefresh,
onCancel,
browserAvailable = true,
+ cameraAvailable = !!onCamera,
initialTab = "window",
+ initialCamera = "",
+ activeCameraVideo,
+ loadCameras,
initialAudio = true,
initialShowCaptureBorder = false,
audioLocked = false,
@@ -47,6 +56,10 @@ export function CaptureSourcePicker({
}: {
nativeSources: NativeSourceList;
onBrowser: () => void;
+ onCamera?: (deviceId: string) => void;
+ initialCamera?: string;
+ activeCameraVideo?: HTMLVideoElement | null;
+ loadCameras?: typeof loadCameraPreviews;
onNative: (target: NativeCaptureTarget, audio: boolean, showCaptureBorder: boolean) => void;
onPreview: (
target: NativeCaptureTarget,
@@ -55,6 +68,7 @@ export function CaptureSourcePicker({
onRefresh: () => void;
onCancel: () => void;
browserAvailable?: boolean;
+ cameraAvailable?: boolean;
initialTab?: SourceTab;
initialAudio?: boolean;
initialShowCaptureBorder?: boolean;
@@ -64,14 +78,24 @@ export function CaptureSourcePicker({
const { vis, t } = useCopy();
const pickerId = useId();
const panelRef = useRef<HTMLDivElement>(null);
- const [tab, setTab] = useState<SourceTab>(initialTab);
+ const [tab, setTab] = useState<SourceTab | null>(null);
const [shareAudio, setShareAudio] = useState(initialAudio);
const [showCaptureBorder, setShowCaptureBorder] = useState(initialShowCaptureBorder);
- const activeTab = tab === "browser" && !browserAvailable ? "window" : tab;
- const supportsCaptureBorder = nativeSources.kind === "ready" && nativeSources.captureBorderControl === true;
+ const appDetected = nativeSources.kind === "ready" || nativeSources.kind === "failed" ||
+ nativeSources.kind === "unsupported" || nativeSources.kind === "incompatible";
+ const tabs = SOURCE_TABS.filter((value) => appDetected || value === "browser" || value === "camera");
+ const preferredTab = tab ?? initialTab;
+ const tabAvailable = (value: SourceTab) => value === "camera" ? cameraAvailable
+ : value === "browser" || nativeSources.kind === "browser" ? browserAvailable : true;
+ const activeTab = tabs.includes(preferredTab) && tabAvailable(preferredTab)
+ ? preferredTab : tabs.find(tabAvailable) ?? "browser";
+ const nativeTab = activeTab === "window" || activeTab === "display";
+ const browserCapture = activeTab === "browser";
+ const cameraSources = useCameraSources(activeTab === "camera", activeCameraVideo, loadCameras);
+ const supportsCaptureBorder = nativeTab && nativeSources.kind === "ready" && nativeSources.captureBorderControl === true;
const issueKey = nativeSources.kind === "incompatible" ? "native.incompatible"
- : activeTab !== "browser" && (nativeSources.kind === "unavailable" ||
- nativeSources.kind === "unsupported" || nativeSources.kind === "failed")
+ : nativeSources.kind === "unavailable" ? "host.sourcePicker.unavailable" : !nativeTab ? null
+ : (nativeSources.kind === "unsupported" || nativeSources.kind === "failed")
? `host.sourcePicker.${nativeSources.kind}` as const
: null;
@@ -87,7 +111,7 @@ export function CaptureSourcePicker({
}, [onCancel]);
const sources =
- nativeSources.kind === "ready"
+ nativeTab && nativeSources.kind === "ready"
? nativeSources.sources.filter(
(target) => target.kind === activeTab || target.kind === "picker",
)
@@ -98,7 +122,8 @@ export function CaptureSourcePicker({
? nativeSources.processAudio
: nativeSources.systemAudio);
const anyNativeAudio = sources.some(supportsAudio);
- const refreshLabel = t(nativeSources.kind === "loading" ? "host.sourcePicker.loading" : "host.sourcePicker.refresh");
+ const refreshing = activeTab === "camera" ? cameraSources.busy : nativeSources.kind === "loading";
+ const refreshLabel = t(refreshing ? "host.sourcePicker.loading" : "host.sourcePicker.refresh");
const audioAction = t(!anyNativeAudio ? "host.noAudio" : audioLocked
? "host.sourcePicker.audioLocked"
: shareAudio ? "host.sourcePicker.audioOff" : "host.sourcePicker.audioOn");
@@ -112,10 +137,10 @@ export function CaptureSourcePicker({
type="button"
className="lr-source-picker-refresh"
aria-label={refreshLabel}
- disabled={nativeSources.kind === "loading"}
- onClick={onRefresh}
+ disabled={refreshing}
+ onClick={activeTab === "camera" ? cameraSources.refresh : onRefresh}
>
- <Glyph name="refresh" size={18} className={nativeSources.kind === "loading" ? "lr-spin" : undefined} />
+ <Glyph name="refresh" size={18} className={refreshing ? "lr-spin" : undefined} />
</button>
);
const closeButton = (
@@ -158,12 +183,12 @@ export function CaptureSourcePicker({
<strong>{t("host.sourcePicker.title")}</strong>
</span>
)}
- <Tooltip kind="hint-refresh-sources" text={vis ? undefined : refreshLabel}
- tone={nativeSources.kind === "loading" ? "busy" : undefined}
- motion={nativeSources.kind === "loading" ? "progress" : undefined}
+ {activeTab === "camera" || nativeSources.kind !== "browser" ? <Tooltip kind="hint-refresh-sources" text={vis ? undefined : refreshLabel}
+ tone={refreshing ? "busy" : undefined}
+ motion={refreshing ? "progress" : undefined}
place="below" align="end">
{refreshButton}
- </Tooltip>
+ </Tooltip> : null}
<Tooltip kind="hint-close" text={vis ? undefined : t("common.cancel")} place="below" align="end">
{closeButton}
</Tooltip>
@@ -171,14 +196,14 @@ export function CaptureSourcePicker({
<div
className="lr-source-picker-tabs"
+ style={{ gridTemplateColumns: `repeat(${tabs.length}, minmax(0, 1fr))` }}
role="tablist"
aria-label={t("host.sourcePicker.title")}
onKeyDown={(event) => {
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key))
return;
- const available = SOURCE_TABS.filter(
- (value) => value !== "browser" || browserAvailable,
- );
+ const available = tabs.filter(tabAvailable);
+ if (!available.length) return;
const index = available.indexOf(activeTab);
const next =
event.key === "Home"
@@ -199,7 +224,7 @@ export function CaptureSourcePicker({
?.focus();
}}
>
- {SOURCE_TABS.map((value) => {
+ {tabs.map((value) => {
const button = (
<button
type="button"
@@ -210,7 +235,7 @@ export function CaptureSourcePicker({
aria-selected={activeTab === value}
aria-label={t(`host.sourcePicker.tab.${value}`)}
tabIndex={activeTab === value ? 0 : -1}
- disabled={value === "browser" && !browserAvailable}
+ disabled={!tabAvailable(value)}
onClick={() => setTab(value)}
>
<Glyph
@@ -242,32 +267,34 @@ export function CaptureSourcePicker({
id={`${pickerId}-panel`}
aria-labelledby={`${pickerId}-${activeTab}`}
>
+ {activeTab === "camera" ? <CameraSources {...cameraSources} selected={initialCamera}
+ disabled={selectionDisabled} onSelect={id => onCamera?.(id)} /> : <>
<div className="lr-source-picker-list">
- {activeTab === "browser" ? (
+ {browserCapture ? (
<button
type="button"
className="lr-source-option is-browser"
aria-label={t("host.sourcePicker.browser")}
- disabled={selectionDisabled}
+ disabled={selectionDisabled || !tabAvailable(activeTab)}
onClick={onBrowser}
>
<span className="lr-source-option-icon" aria-hidden="true">
- <Glyph name="globe" size={23} />
+ <Glyph name={SOURCE_ICONS[activeTab]} size={23} />
</span>
{vis ? (
<span className="visually-hidden">
- {t("host.sourcePicker.browser")}
+ {t(`host.sourcePicker.tab.${activeTab}`)}
</span>
) : (
<span className="lr-source-option-copy">
- <strong>{t("host.sourcePicker.browser")}</strong>
+ <strong>{t(`host.sourcePicker.tab.${activeTab}`)}</strong>
<small>{t("host.sourcePicker.browserHint")}</small>
</span>
)}
</button>
) : null}
- {activeTab !== "browser"
+ {nativeTab && !browserCapture
? sources.map((target) => (
<CaptureSourceOption
key={nativeCaptureTargetKey(target)}
@@ -284,8 +311,9 @@ export function CaptureSourcePicker({
))
: null}
</div>
+ </>}
- {activeTab !== "browser" &&
+ {nativeTab &&
nativeSources.kind === "ready" &&
(supportsCaptureBorder || sources.length > 0) ? (
<div className="lr-source-picker-options">
@@ -329,17 +357,7 @@ export function CaptureSourcePicker({
{issueKey ? (
<Pill icon="alert" label={t(issueKey)} comic="warning" />
- ) : activeTab === "browser" ? null : nativeSources.kind === "loading" ? (
- <span
- className="lr-source-picker-status"
- role="status"
- aria-label={t("host.sourcePicker.loading")}
- >
- <HintComic kind="hint-refresh-sources" size={240} tone="busy" motion="progress" />
- {vis ? null : <span>{t("host.sourcePicker.loading")}</span>}
- <WaitingCaption context="host.sourcePicker.loading" />
- </span>
- ) : sources.length === 0 ? (
+ ) : browserCapture || activeTab === "camera" ? null : sources.length === 0 ? (
<span
className="lr-source-picker-status"
role="status"
@@ -415,30 +433,9 @@ function CaptureSourceOption({
{ title },
);
- return (
- <Tooltip kind={target.kind === "picker" ? "hint-source-picker" : target.kind === "display" ? "hint-capture-display" : "hint-capture-window"} text={title} className="lr-source-option-hint">
- <button
- ref={buttonRef}
- type="button"
- className="lr-source-option"
- data-native-source={nativeCaptureTargetKey(target)}
- aria-label={action}
- disabled={disabled}
- onMouseEnter={requestPreview}
- onFocus={requestPreview}
- onClick={onSelect}
- >
- <span className="lr-source-option-copy">
- <strong>{title}</strong>
- </span>
- <span className="lr-source-option-preview" aria-hidden="true">
- {preview ? (
- <img src={preview} alt="" />
- ) : (
- <Glyph name={target.kind === "picker" ? "share" : target.kind} size={23} />
- )}
- </span>
- </button>
- </Tooltip>
- );
+ return <CaptureSourceCard title={title} action={action}
+ icon={target.kind === "picker" ? "share" : target.kind}
+ hint={target.kind === "picker" ? "hint-source-picker" : target.kind === "display" ? "hint-capture-display" : "hint-capture-window"}
+ preview={preview} nativeKey={nativeCaptureTargetKey(target)} buttonRef={buttonRef}
+ disabled={disabled} onPreview={requestPreview} onSelect={onSelect} />;
}
diff --git a/src/client/components/living/HostMicrophone.tsx b/src/client/components/living/HostMicrophone.tsx
new file mode 100644
index 00000000..0748efe4
--- /dev/null
+++ b/src/client/components/living/HostMicrophone.tsx
@@ -0,0 +1,49 @@
+import { useId } from "react";
+import { Btn } 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 }: {
+ enabled: boolean; disabled?: boolean; native?: boolean;
+ volume: number; onVolume: (volume: number) => void;
+ deviceId: string; onDevice: (id: string) => void; loadDevices: () => Promise<CaptureDevice[]>;
+}) {
+ 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}
+ aria-label={t("host.microphone.volume")} aria-valuetext={`${percent}%`}
+ onChange={event => onVolume(Number(event.target.value) / 100)} />
+ </Tooltip>
+ </div>;
+}
diff --git a/src/client/components/living/LauncherForm.tsx b/src/client/components/living/LauncherForm.tsx
index 53e94af5..d268587f 100644
--- a/src/client/components/living/LauncherForm.tsx
+++ b/src/client/components/living/LauncherForm.tsx
@@ -1,4 +1,4 @@
-import type { FormEvent, ReactNode } from "react";
+import { useId, type FormEvent, type ReactNode } from "react";
import { BrandMark } from "./BrandMark";
import { Tooltip } from "./Tooltip";
import { WelcomeLine } from "./WelcomeLine";
@@ -7,6 +7,7 @@ import type { HintKind } from "./hints";
import { Glyph, type GlyphName } from "../../ui/icons";
import { useCopy, type CopyKey } from "../../ui/copy";
export type AppMode = "local" | "link" | "site";
+export const SUGGESTED_SITE = "https://demo.piik.tv";
const MODES: Array<{
mode: AppMode;
@@ -65,6 +66,7 @@ export function LauncherForm({
children?: ReactNode;
}) {
const { vis, t } = useCopy();
+ const accessHintId = useId();
const accessField = (
<label className="lr-input lr-client-access">
<Glyph name="key" size={18} />
@@ -75,6 +77,7 @@ export function LauncherForm({
spellCheck={false}
placeholder={vis ? "" : t("client.launch.localAccess")}
aria-label={t("client.launch.localAccess")}
+ aria-describedby={accessHintId}
onChange={(event) => {
onLocalAccessPasswordChange(event.target.value);
}}
@@ -167,7 +170,7 @@ export function LauncherForm({
value={site}
spellCheck={false}
inputMode="url"
- placeholder="https://share.example"
+ placeholder={SUGGESTED_SITE}
aria-label={t("client.launch.siteAddress")}
onChange={(event) => {
onSiteChange(event.target.value);
@@ -177,12 +180,21 @@ export function LauncherForm({
) : null}
{mode !== "site" ? (
- <Tooltip
- kind="hint-password"
- text={vis ? undefined : t("client.launch.localAccessHint")}
- >
+ <details className="lr-client-access-options">
+ <summary>
+ <Glyph name="key" size={17} />
+ <span className={vis ? "visually-hidden" : undefined}>{t("client.launch.accessSettings")}</span>
+ {localAccessPassword && <span className="lr-client-access-set">
+ <Glyph name="check" size={14} />
+ <span className={vis ? "visually-hidden" : undefined}>{t("client.launch.accessSet")}</span>
+ </span>}
+ <Glyph name="chevron" size={15} />
+ </summary>
{accessField}
- </Tooltip>
+ <p id={accessHintId} className={vis ? "visually-hidden" : "lr-client-access-hint"}>
+ {t("client.launch.localAccessHint")}
+ </p>
+ </details>
) : null}
<Btn
diff --git a/src/client/components/living/MicrophoneDeviceSelect.tsx b/src/client/components/living/MicrophoneDeviceSelect.tsx
new file mode 100644
index 00000000..28760d9f
--- /dev/null
+++ b/src/client/components/living/MicrophoneDeviceSelect.tsx
@@ -0,0 +1,57 @@
+import { useEffect, useId, useState } from "react";
+import type { CaptureDevice } from "../../media/capture-devices";
+import { useCopy } from "../../ui/copy";
+import { Glyph } from "../../ui/icons";
+
+// Shared presentation only: capture and replacement stay with the Host owner.
+export function MicrophoneDeviceSelect({ value, load, onChange, disabled, revision, browser = true }: {
+ value: string; load: () => Promise<CaptureDevice[]>;
+ onChange: (id: string) => void; disabled?: boolean; revision?: unknown; browser?: boolean;
+}) {
+ const { t, vis } = useCopy();
+ const id = useId();
+ const [devices, setDevices] = useState<CaptureDevice[]>([]);
+ const [busy, setBusy] = useState(true);
+ const [failed, setFailed] = useState(false);
+ const [refresh, setRefresh] = useState(0);
+ useEffect(() => {
+ let current = true;
+ let request = 0;
+ const update = () => {
+ const token = ++request;
+ setBusy(true);
+ void load().then(result => {
+ if (!current || request !== token) return;
+ setDevices(result); setFailed(false);
+ }, () => {
+ if (current && request === token) setFailed(true);
+ }).finally(() => { if (current && request === token) setBusy(false); });
+ };
+ update();
+ if (browser) navigator.mediaDevices?.addEventListener("devicechange", update);
+ return () => {
+ current = false;
+ if (browser) navigator.mediaDevices?.removeEventListener("devicechange", update);
+ };
+ }, [load, refresh, revision, browser]);
+ const missing = value !== "" && !devices.some(device => device.id === value);
+ return <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")}
+ onChange={event => onChange(event.target.value)}>
+ <option value="">{t("host.device.default")}</option>
+ {missing && <option value={value} disabled>{t("host.device.missing")}</option>}
+ {devices.map((device, index) => <option key={device.id} value={device.id}>
+ {device.label || `${t("host.device.microphone")} ${index + 1}`}
+ </option>)}
+ </select>
+ <button type="button" className="lr-btn lr-device-refresh" disabled={busy || disabled}
+ aria-label={t("host.device.refresh")} onClick={() => setRefresh(value => value + 1)}>
+ <Glyph name="refresh" size={16} className={busy ? "lr-spin" : undefined} />
+ </button>
+ </div>
+ {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/PlaybackControls.tsx b/src/client/components/living/PlaybackControls.tsx
index ffe13eea..38cadaca 100644
--- a/src/client/components/living/PlaybackControls.tsx
+++ b/src/client/components/living/PlaybackControls.tsx
@@ -114,7 +114,7 @@ export function PlaybackControls({
const percent = Math.round(audio.level * 100);
return (
- <div ref={controlsRef} className={`lr-playback${hidden ? " is-hidden" : ""}`} data-can-play={canPlay} role="group" aria-label={t("playback.controls")}>
+ <div ref={controlsRef} className={`lr-playback lr-media-controls${hidden ? " is-hidden" : ""}`} data-can-play={canPlay} role="group" aria-label={t("playback.controls")}>
<span className="lr-playback-audio">
<Btn icon={paused ? "play" : "pause"}
draw="playback-state"
diff --git a/src/client/components/living/SharingSettings.tsx b/src/client/components/living/SharingSettings.tsx
new file mode 100644
index 00000000..68e4c595
--- /dev/null
+++ b/src/client/components/living/SharingSettings.tsx
@@ -0,0 +1,31 @@
+import type { ReactNode } from "react";
+import { useCopy } from "../../ui/copy";
+import { Glyph } from "../../ui/icons";
+import { Cap } from "./primitives";
+
+// Presentation only. Capture, preferences and pending operations stay with the Host.
+export function SharingSettings({ id, open, busy, presets, picture, audio, technical }: {
+ id: string; open: boolean; busy?: boolean;
+ presets: ReactNode; picture?: ReactNode; audio: ReactNode; technical?: ReactNode;
+}) {
+ const { t } = useCopy();
+ return <div id={id} className={`lr-sharing-settings lr-door-reveal${open ? " is-open" : ""}`}>
+ <div>{open ? <section className="lr-sharing-panel" aria-label={t("host.advanced")} aria-busy={busy}>
+ <div className="lr-sharing-columns">
+ <section className="lr-sharing-section" aria-label={t("host.settings.picture")}>
+ <h2 aria-label={t("host.settings.picture")}><Glyph name="tv" size={20} /><Cap k="host.settings.picture" /></h2>
+ {presets}
+ {picture}
+ </section>
+ <section className="lr-sharing-section" aria-label={t("host.settings.sound")}>
+ <h2 aria-label={t("host.settings.sound")}><Glyph name="speaker" size={20} /><Cap k="host.settings.sound" /></h2>
+ {audio}
+ </section>
+ </div>
+ {technical ? <details className="lr-sharing-technical">
+ <summary aria-label={t("host.settings.technical")}><Glyph name="sliders" size={17} /><Cap k="host.settings.technical" /></summary>
+ <div>{technical}</div>
+ </details> : null}
+ </section> : null}</div>
+ </div>;
+}
diff --git a/src/client/components/living/Tooltip.tsx b/src/client/components/living/Tooltip.tsx
index ee7aa046..912c10a2 100644
--- a/src/client/components/living/Tooltip.tsx
+++ b/src/client/components/living/Tooltip.tsx
@@ -166,7 +166,7 @@ export function Tooltip({
if (!vw) return; // no layout (SSR/test): keep the prop alignment
const rect = wrap.getBoundingClientRect();
// A wrapped control row remains one working area, including on narrow screens.
- const controlBar = wrap.closest<HTMLElement>(".lr-playback, .lr-source-picker-options");
+ const controlBar = wrap.closest<HTMLElement>(".lr-playback, .lr-source-picker-options, .lr-host-share-controls");
const playback = controlBar?.classList.contains("lr-playback");
const avoid = controlBar?.getBoundingClientRect() ?? rect;
const player = wrap.closest<HTMLElement>(".lr-tv-screen")?.getBoundingClientRect();
@@ -182,7 +182,7 @@ export function Tooltip({
(panelMounted ? tipRef.current?.offsetHeight : 0) || FALLBACK_PANEL_HEIGHT;
const fitsAbove = avoid.top - panelHeight - EDGE_MARGIN >= EDGE_MARGIN;
const fitsBelow = !vh || below + panelHeight + EDGE_MARGIN <= vh - EDGE_MARGIN;
- const preferredPlace = wrap.closest(".lr-tv-chin") ? "below" : place;
+ const preferredPlace = wrap.closest(".lr-tv-chin, .lr-host-share-controls") ? "below" : place;
let livePlace: Placement =
preferredPlace === "above"
? fitsAbove || !fitsBelow
diff --git a/src/client/components/living/hints/index.tsx b/src/client/components/living/hints/index.tsx
index bfc60e82..85474a51 100644
--- a/src/client/components/living/hints/index.tsx
+++ b/src/client/components/living/hints/index.tsx
@@ -23,6 +23,9 @@ export type { HintKind, HintScene };
export const HINT_KINDS: readonly HintKind[] = [
"hint-share-start",
"hint-share-stop",
+ "hint-microphone-on",
+ "hint-microphone-off",
+ "hint-microphone-volume",
"hint-pause",
"hint-resume",
"hint-switch-source",
@@ -79,6 +82,7 @@ export const HINT_KINDS: readonly HintKind[] = [
"hint-client-local",
"hint-client-site",
"hint-capture-browser",
+ "hint-capture-camera",
"hint-capture-window",
"hint-capture-display",
"hint-local-play",
diff --git a/src/client/components/living/hints/set1.tsx b/src/client/components/living/hints/set1.tsx
index 5007873d..94e48062 100644
--- a/src/client/components/living/hints/set1.tsx
+++ b/src/client/components/living/hints/set1.tsx
@@ -24,6 +24,7 @@ import {
rmBlock,
} from "../Comic";
import type { HintScene, Set1Kind } from "../../../ui/visual-kinds";
+import { Glyph } from "../../../ui/icons";
function SourceWindow({ x, y, alternate = false }: { x: number; y: number; alternate?: boolean }) {
return <>
@@ -279,7 +280,7 @@ ${rmBlock(
</>
);
-function CaptureHint({ theme, target }: Parameters<HintScene>[0] & { target: "browser" | "window" | "display" }) {
+function CaptureHint({ theme, target }: Parameters<HintScene>[0] & { target: "browser" | "window" | "display" | "camera" }) {
return <>
<style>{`
.vls-capture-choice{animation:vlsCaptureChoice var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}
@@ -297,6 +298,9 @@ ${rmBlock(["vls-capture-choice"], [[".vls-capture-choice", "opacity:1;transform:
</> : target === "window" ? <>
<g opacity={.35}><SourceWindow x={38} y={24} alternate /></g>
<SourceWindow x={60} y={41} />
+ </> : target === "camera" ? <>
+ <g transform="translate(30 31)"><Glyph name="camera" size={32} /></g>
+ <Pawn x={91} yb={73} s={13} eyes color={SKY} />
</> : <>
<rect x={29} y={21} width={100} height={54} rx={4} fill="var(--paper)" stroke="var(--ink)" strokeWidth={2} />
<path d="M79 75v9m-16 0h32" stroke="var(--ink)" strokeWidth={2.5} strokeLinecap="round" />
@@ -311,12 +315,43 @@ ${rmBlock(["vls-capture-choice"], [[".vls-capture-choice", "opacity:1;transform:
<path d="M225 34h4m-4 6h4m-4 6h4" stroke={SKY} strokeWidth={2.5} />
<rect x={237} y={34} width={37} height={23} rx={2} fill={TV_SCREEN} stroke={SKY} strokeWidth={1.5} />
<path d="M237 39h37 M243 53l7-10 5 6 4-4 7 8Z" stroke={SKY} strokeWidth={1} fill={SKY} />
- </g> : <path className="vls-capture-choice" d="M229 54l10-14 7 8 5-5 8 11Z" fill={SKY} />}
+ </g> : target === "camera" ? <g className="vls-capture-choice"><Pawn x={251} yb={63} s={10} eyes color={SKY} /></g>
+ : <path className="vls-capture-choice" d="M229 54l10-14 7 8 5-5 8 11Z" fill={SKY} />}
<Pawn x={190} yb={78} s={8} eyes host />
</>;
}
+function MicrophoneHint({ theme, mode }: Parameters<HintScene>[0] & { mode: "on" | "off" | "volume" }) {
+ return <>
+ <style>{`
+.vls-mic-voice{animation:vlsMicVoice var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}
+@keyframes vlsMicVoice{0%,10%{opacity:0;transform:translateX(-3px)}24%,48%{opacity:1;transform:none}68%,100%{opacity:0;transform:translateX(3px)}}
+.vls-mic-gain{animation:vlsMicGain var(--comic-duration,3.2s) ease-out var(--comic-repeat,1) both}
+@keyframes vlsMicGain{0%,12%{transform:translateX(0)}40%,100%{transform:translateX(28px)}}
+${rmBlock(["vls-mic-voice"], [[".vls-mic-voice", "opacity:1;transform:none"]])}
+${rmBlock(["vls-mic-gain"], [[".vls-mic-gain", "transform:translateX(28px)"]])}
+`}</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 === "volume" ? <>
+ <path d="M113 46q5 6 0 12" stroke={MINT} strokeWidth={2.5} strokeLinecap="round" fill="none" />
+ {index === 1 && <path className="vls-mic-voice" d="M120 40q10 12 0 24m7-29q15 17 0 34" stroke={MINT} strokeWidth={2.5} strokeLinecap="round" fill="none" />}
+ <path d="M89 82h40" stroke={FAINT} strokeWidth={3} strokeLinecap="round" />
+ <circle className={index === 1 ? "vls-mic-gain" : undefined} cx={94} cy={82} r={4} fill={SKY} />
+ </> : (index === 0 ? mode === "on" : mode === "off")
+ ? <path d="m77 67 31-33" stroke={WARN} strokeWidth={3} strokeLinecap="round" />
+ : <path className="vls-mic-voice" d="M113 44q7 8 0 16m7-21q12 13 0 26" stroke={MINT} strokeWidth={2.5} strokeLinecap="round" fill="none" />}
+ </g>)}
+ </>;
+}
+
export const SET1_SCENES: Record<Set1Kind, HintScene> = {
+ "hint-microphone-on": (props) => <MicrophoneHint {...props} mode="on" />,
+ "hint-microphone-off": (props) => <MicrophoneHint {...props} mode="off" />,
+ "hint-microphone-volume": (props) => <MicrophoneHint {...props} mode="volume" />,
"hint-share-start": SceneShareStart,
"hint-share-stop": SceneShareStop,
"hint-pause": ScenePause,
@@ -324,6 +359,7 @@ export const SET1_SCENES: Record<Set1Kind, HintScene> = {
"hint-switch-source": SceneSwitchSource,
"hint-reconnect": SceneReconnect,
"hint-capture-browser": (props) => <CaptureHint {...props} target="browser" />,
+ "hint-capture-camera": (props) => <CaptureHint {...props} target="camera" />,
"hint-capture-window": (props) => <CaptureHint {...props} target="window" />,
"hint-capture-display": (props) => <CaptureHint {...props} target="display" />,
};
diff --git a/src/client/components/living/playback-controls.css b/src/client/components/living/playback-controls.css
index dab5070c..360ec4be 100644
--- a/src/client/components/living/playback-controls.css
+++ b/src/client/components/living/playback-controls.css
@@ -14,6 +14,13 @@
transition: opacity 180ms ease, transform 220ms var(--spring);
}
.lr-playback.is-hidden { opacity: 0; transform: translateY(6px); pointer-events: none; }
+/* Let the bar's actual height (including wrapping) reserve overlay space. */
+.lr-tv-screen:has(> .lr-playback) { display: grid; width: 100%; grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); }
+/* Keep the primary status readable when narrow controls wrap to a second row. */
+.lr-tv-screen:has(> .lr-playback):has(> .lr-tv-overlay) { min-height: 168px; }
+.lr-tv-screen:has(> .lr-playback) > video { grid-area: 1 / 1 / -1 / -1; min-height: 0; }
+.lr-tv-screen > .lr-playback { position: relative; inset: auto; grid-area: 2 / 1; }
+.lr-tv-screen:has(> .lr-playback) > .lr-tv-overlay { grid-area: 1 / 1 / 2 / 2; }
.lr-tv-screen:has(> .lr-playback[data-can-play="true"]) > video { cursor: pointer; }
.lr-tv-screen:has(> .lr-playback.is-hidden) > video { cursor: none; }
/* The video's own focus outline is clipped by the screen; mark its container. */
@@ -21,13 +28,7 @@
.lr-playback .lr-btn {
display: grid; place-items: center; flex: none;
min-width: 0; width: 44px; height: 44px; padding: 0;
- border: 0; border-radius: 10px; box-shadow: none;
- background: transparent; color: inherit; cursor: pointer;
- transition: transform 260ms var(--spring), background-color 140ms ease;
}
-.lr-playback .lr-btn:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]) { transform: translateY(-2px); background: var(--wall-2); }
-.lr-playback .lr-btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(2px) scale(.95); transition-duration: 80ms; }
-.lr-playback .lr-btn[aria-pressed="true"] { background: var(--wall-2); }
.lr-playback-audio { display: flex; align-items: center; flex: 1; gap: 8px; min-width: min-content; }
.lr-playback-separator { flex: none; width: 1px; height: 20px; background: currentColor; opacity: .22; }
.lr-playback-volume { flex: 0 1 144px; min-width: 32px; }
@@ -38,6 +39,9 @@
.lr-tv-screen:fullscreen { width: 100%; height: 100%; border: 0; border-radius: 0; }
.lr-tv-screen:has(> .lr-playback) { container-type: inline-size; }
@container (max-width: 440px) {
+ .lr-tv-screen > .lr-tv-overlay.has-comic { gap: 4px; padding: 6px; }
+ .lr-tv-overlay > .lr-waiting-caption { min-height: 1.4em; }
+ .lr-tv-overlay > .lr-waiting-caption > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lr-playback { gap: 6px; padding: 4px 8px max(4px, env(safe-area-inset-bottom)); }
.lr-playback .lr-btn { width: clamp(32px, 11cqw, 44px); }
.lr-playback-audio { gap: 4px; }
diff --git a/src/client/components/living/primitives.tsx b/src/client/components/living/primitives.tsx
index bb28a65d..40f52895 100644
--- a/src/client/components/living/primitives.tsx
+++ b/src/client/components/living/primitives.tsx
@@ -45,6 +45,7 @@ export function Btn({
pressed,
expanded,
controls,
+ popoverTarget,
onClick,
type = "button",
hint,
@@ -62,6 +63,7 @@ export function Btn({
pressed?: boolean;
expanded?: boolean;
controls?: string;
+ popoverTarget?: string;
onClick?: () => void;
type?: "button" | "submit";
/** Shared hint comic; text modes add the localized caption. */
@@ -75,11 +77,12 @@ export function Btn({
const label = t(title);
const wrapped = Boolean(hint);
const softDisabled = Boolean(wrapped && disabled);
+ const activeTone = tone ?? (pressed ? "on" : undefined);
const button = (
<button
id={id}
type={type}
- className={`lr-btn${tone ? ` is-${tone}` : ""}`}
+ className={`lr-btn${activeTone ? ` is-${activeTone}` : ""}`}
aria-label={label}
disabled={disabled && !softDisabled}
aria-disabled={softDisabled || undefined}
@@ -87,6 +90,7 @@ export function Btn({
aria-pressed={pressed}
aria-expanded={expanded}
aria-controls={controls}
+ popoverTarget={popoverTarget}
style={softDisabled ? SOFT_DISABLED_STYLE : undefined}
onClick={
softDisabled
diff --git a/src/client/locales/en.ts b/src/client/locales/en.ts
index efb41b2e..1b7d94cd 100644
--- a/src/client/locales/en.ts
+++ b/src/client/locales/en.ts
@@ -40,7 +40,7 @@ export const en: Record<CopyKey, string> = {
"common.enable": "Enable {name}",
"common.disable": "Disable {name}",
"host.join.hide": "Hide room entry",
- "host.advanced.hide": "Hide advanced settings",
+ "host.advanced.hide": "Hide sharing settings",
"host.password.settingsHide": "Hide password settings",
"host.sourcePicker.audioOn": "Share sound",
"host.sourcePicker.audioOff": "Stop sharing sound",
@@ -63,7 +63,9 @@ export const en: Record<CopyKey, string> = {
"client.launch.lanHint": "Choose an address on the same network as your friends.",
"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.localAccessHint": "If set, visitors enter this passphrase before accessing your site.",
+ "client.launch.accessSettings": "Site passphrase",
+ "client.launch.accessSet": "Set",
+ "client.launch.localAccessHint": "If set, required to create rooms or join by code. Invite links grant access to their room.",
"client.launch.go": "Open Piik",
"client.launch.starting": "Preparing Piik",
"client.launch.error": "Piik could not start",
@@ -87,7 +89,7 @@ export const en: Record<CopyKey, string> = {
"gate.unavailableRoute": "Unavailable",
"join.title": "Join a room",
- "join.hint": "Enter the four-digit room code from your friend",
+ "join.hint": "Enter a room code for {site}",
"join.field": "Room code",
"join.submit": "Join",
"join.invalid": "Enter a four-digit room code between 1000 and 9999",
@@ -101,7 +103,31 @@ export const en: Record<CopyKey, string> = {
"host.start": "Start sharing",
"host.sourcePicker.title": "Choose what to share",
"host.sourcePicker.browser": "Browser picker",
- "host.sourcePicker.browserHint": "Screen, window, or Browser tab",
+ "host.sourcePicker.browserHint": "Choose a source in your browser's capture picker",
+ "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",
+ "host.device.default": "Default device",
+ "host.device.missing": "Selected device unavailable",
+ "host.device.refresh": "Refresh devices",
+ "host.device.listFailed": "Could not load devices. Try refreshing.",
+ "host.device.permission.microphone": "Turn on the microphone and allow access to see the available devices here.",
+ "host.microphone.volume": "Microphone volume",
+ "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",
"host.sourcePicker.tab.display": "Screens",
@@ -136,7 +162,7 @@ export const en: Record<CopyKey, string> = {
"host.switchSource": "Switch source",
"host.switching": "Choosing",
"host.stop": "Stop sharing",
- "host.noAudio": "This source has no shareable audio",
+ "host.noAudio": "Source sound is not being shared",
"host.localPreviewPaused": "Local preview paused; sharing continues",
"host.pauseNotice": "Audio and video sharing paused",
"host.stopNotice": "Sharing stopped",
@@ -163,7 +189,7 @@ export const en: Record<CopyKey, string> = {
"host.invite": "Invite link",
"host.invite.copy": "Copy invite link",
- "host.invite.copyFailed": "Could not copy the invite link; try again",
+ "host.invite.copyFailed": "Could not copy the link; try again",
"host.invite.rotate": "Rotate invite link; viewers using the old link will need to rejoin",
"host.invite.revoke": "Revoke invite link and disconnect viewers who joined with it",
"host.invite.rotateShort": "Rotate link",
@@ -171,6 +197,11 @@ export const en: Record<CopyKey, string> = {
"host.invite.updated": "Invite link rotated",
"host.invite.revoked": "Invite link revoked",
"host.invite.emptyOpen": "No invite link; the room code still works",
+ "host.invite.address": "Room address",
+ "host.invite.copyAddress": "Copy room address",
+ "host.invite.includeCredential": "Skip passwords",
+ "host.invite.credentialHint": "Anyone with this link can join the room",
+ "host.invite.credentialRequired": "This room is invite-only; turn on Skip passwords",
"host.invite.emptyPassword": "No invite link; room code plus password still works",
"host.invite.emptyPrivate": "No invite link; rotate one before inviting",
@@ -207,7 +238,11 @@ export const en: Record<CopyKey, string> = {
"host.quality.720p30": "720p · 30 fps",
"host.quality.1080p30": "1080p · 30 fps",
"host.quality.1080p60": "1080p · 60 fps",
- "host.advanced": "Advanced settings",
+ "host.advanced": "Sharing settings",
+ "host.settings.button": "Settings",
+ "host.settings.picture": "Picture",
+ "host.settings.sound": "Sound",
+ "host.settings.technical": "Connection & encoding",
"host.advanced.resolution": "Resolution ceiling",
"host.advanced.framerate": "Frame rate ceiling",
"host.advanced.bitrate": "Video bitrate ceiling",
@@ -230,11 +265,11 @@ export const en: Record<CopyKey, string> = {
"Share over peer-to-peer (P2P) connections only. Viewers cannot watch if those connections fail",
"host.advanced.route.peerOnlyRequired":
"This service supports peer-to-peer (P2P) media only, so Privacy mode is always on",
- "host.advanced.route.natPrediction": "NAT traversal",
+ "host.advanced.route.natPrediction": "Enhanced NAT traversal",
"host.advanced.route.natPredictionHint":
- "Use extra STUN observations to try more direct paths",
+ "Use extra probes and retries to help connect across some restricted networks. Available in browsers and the App",
"host.advanced.route.natPredictionUnavailable":
- "Extra NAT traversal is not enabled on this service; ordinary P2P remains available",
+ "This service has not enabled the enhancement. Standard P2P connections are still attempted",
"host.advanced.codec": "Video codec",
"host.advanced.codec.auto": "Auto",
"host.advanced.codec.autoHint": "Pick automatically",
@@ -336,7 +371,7 @@ export const en: Record<CopyKey, string> = {
"viewer.notice.mediaRecovering": "Media connection recovering",
"viewer.notice.hostOffline": "Host connection lost; picture may freeze",
"viewer.hint.denied": "Use the host's invite link, or try the room password.",
- "viewer.hint.notFound": "Check the room code, or ask the host for a new invite link.",
+ "viewer.hint.notFound": "Check that the room code belongs to {site}, or open the host’s invite link.",
"viewer.hint.invite": "Ask the host for a new invite link.",
"viewer.hint.generic": "Check your entry point and try again.",
@@ -357,8 +392,8 @@ export const en: Record<CopyKey, string> = {
"host.switchingSource": "Switching source",
"host.capture.fpsUnknown": "Unknown frame rate",
"host.capture.codecPending": "Codec pending",
- "host.capture.hasAudio": "With audio",
- "host.capture.noAudio": "No audio",
+ "host.capture.hasAudio": "Source audio included",
+ "host.capture.noAudio": "No source audio",
"host.stageAria": "Share or join a room",
"host.captureAria": "Actual capture parameters",
"host.quality.title": "{label} · {mbps} Mbps",
diff --git a/src/client/locales/zh.ts b/src/client/locales/zh.ts
index e6b8bbb6..de18fbed 100644
--- a/src/client/locales/zh.ts
+++ b/src/client/locales/zh.ts
@@ -40,7 +40,7 @@ export const zh = {
"common.enable": "开启{name}",
"common.disable": "关闭{name}",
"host.join.hide": "收起加入房间",
- "host.advanced.hide": "收起高级设置",
+ "host.advanced.hide": "收起分享设置",
"host.password.settingsHide": "收起密码设置",
"host.sourcePicker.audioOn": "分享声音",
"host.sourcePicker.audioOff": "停止分享声音",
@@ -63,7 +63,9 @@ export const zh = {
"client.launch.lanHint": "选择与朋友处于同一网络的地址。",
"client.launch.lanUnavailable": "没有可用的局域网地址,请连接网络后刷新页面",
"client.launch.localAccess": "站点口令(可选)",
- "client.launch.localAccessHint": "设置后,访问此站点需要先输入口令。",
+ "client.launch.accessSettings": "站点口令",
+ "client.launch.accessSet": "已设置",
+ "client.launch.localAccessHint": "设置后,开房或凭房间号加入需要口令。邀请链接可直接进入对应房间。",
"client.launch.go": "进入 Piik",
"client.launch.starting": "正在准备 Piik",
"client.launch.error": "Piik 启动失败",
@@ -87,7 +89,7 @@ export const zh = {
"gate.unavailableRoute": "无法访问",
"join.title": "加入房间",
- "join.hint": "输入房主发来的房间号",
+ "join.hint": "输入 {site} 的房间号",
"join.field": "房间号",
"join.submit": "加入",
"join.invalid": "请输入 1000 至 9999 的四位房间号",
@@ -101,7 +103,31 @@ export const zh = {
"host.start": "开始分享",
"host.sourcePicker.title": "选择分享来源",
"host.sourcePicker.browser": "浏览器选择器",
- "host.sourcePicker.browserHint": "屏幕、窗口或浏览器标签页",
+ "host.sourcePicker.browserHint": "在浏览器弹出的选择器中选择画面",
+ "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": "摄像头",
+ "host.device.default": "默认设备",
+ "host.device.missing": "所选设备暂不可用",
+ "host.device.refresh": "刷新设备",
+ "host.device.listFailed": "暂时无法获取设备,请刷新重试。",
+ "host.device.permission.microphone": "开启麦克风并允许访问后,可以在这里选择设备。",
+ "host.microphone.volume": "麦克风音量",
+ "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": "程序 / 窗口",
"host.sourcePicker.tab.display": "屏幕",
@@ -136,7 +162,7 @@ export const zh = {
"host.switchSource": "切换来源",
"host.switching": "正在选择",
"host.stop": "停止分享",
- "host.noAudio": "当前来源没有可共享音频",
+ "host.noAudio": "未分享来源声音",
"host.localPreviewPaused": "本地预览已暂停,分享仍在继续",
"host.pauseNotice": "音视频分享已暂停",
"host.stopNotice": "已停止分享",
@@ -163,7 +189,7 @@ export const zh = {
"host.invite": "邀请链接",
"host.invite.copy": "复制邀请链接",
- "host.invite.copyFailed": "无法复制邀请链接,请稍后重试",
+ "host.invite.copyFailed": "无法复制链接,请稍后重试",
"host.invite.rotate": "更新邀请链接;使用旧链接的观众需要重新加入",
"host.invite.revoke": "撤销邀请链接,并断开通过该链接加入的观众",
"host.invite.rotateShort": "更新链接",
@@ -171,6 +197,11 @@ export const zh = {
"host.invite.updated": "邀请链接已更新",
"host.invite.revoked": "邀请链接已撤销",
"host.invite.emptyOpen": "暂无邀请链接,仍可凭房间号加入",
+ "host.invite.address": "房间地址",
+ "host.invite.copyAddress": "复制房间地址",
+ "host.invite.includeCredential": "免密邀请",
+ "host.invite.credentialHint": "收到链接即可加入此房间",
+ "host.invite.credentialRequired": "当前仅限邀请,请开启免密邀请",
"host.invite.emptyPassword": "暂无邀请链接,仍可凭房间号和密码加入",
"host.invite.emptyPrivate": "暂无邀请链接,请先更新链接再邀请他人",
@@ -207,7 +238,11 @@ export const zh = {
"host.quality.720p30": "720p · 30 帧",
"host.quality.1080p30": "1080p · 30 帧",
"host.quality.1080p60": "1080p · 60 帧",
- "host.advanced": "高级设置",
+ "host.advanced": "分享设置",
+ "host.settings.button": "设置",
+ "host.settings.picture": "画面",
+ "host.settings.sound": "声音",
+ "host.settings.technical": "连接与编码",
"host.advanced.resolution": "分辨率上限",
"host.advanced.framerate": "帧率上限",
"host.advanced.bitrate": "视频码率上限",
@@ -230,11 +265,11 @@ export const zh = {
"仅通过设备间连接(P2P)传输画面。连接不通时,观众将无法观看",
"host.advanced.route.peerOnlyRequired":
"当前服务仅支持设备间连接(P2P),隐私模式无法关闭",
- "host.advanced.route.natPrediction": "NAT 穿透",
+ "host.advanced.route.natPrediction": "NAT 穿透增强",
"host.advanced.route.natPredictionHint":
- "借助额外 STUN 探测,尝试更多直连路径",
+ "借助额外探测和重试,帮助部分受限网络建立直连。浏览器和 App 均可使用",
"host.advanced.route.natPredictionUnavailable":
- "当前服务未启用额外 NAT 穿透,仍可使用普通 P2P 连接",
+ "当前服务未启用此增强,仍会尝试常规 P2P 连接",
"host.advanced.codec": "视频编码",
"host.advanced.codec.auto": "自动",
"host.advanced.codec.autoHint": "自动选择",
@@ -336,7 +371,7 @@ export const zh = {
"viewer.notice.mediaRecovering": "媒体连接正在恢复",
"viewer.notice.hostOffline": "房主连接已中断,画面可能停住",
"viewer.hint.denied": "请使用房主发来的邀请链接,或输入房间密码。",
- "viewer.hint.notFound": "请确认房间号,或让房主重新发送邀请链接。",
+ "viewer.hint.notFound": "请确认这是 {site} 的房间号,或打开房主的邀请链接。",
"viewer.hint.invite": "请让房主重新发送邀请链接。",
"viewer.hint.generic": "请检查入口后重试。",
@@ -357,8 +392,8 @@ export const zh = {
"host.switchingSource": "正在切换来源",
"host.capture.fpsUnknown": "帧率未知",
"host.capture.codecPending": "编码待定",
- "host.capture.hasAudio": "含音频",
- "host.capture.noAudio": "无音频",
+ "host.capture.hasAudio": "含来源音频",
+ "host.capture.noAudio": "无来源音频",
"host.stageAria": "分享或加入房间",
"host.captureAria": "实际捕获参数",
"host.quality.title": "{label} · {mbps} Mbps",
diff --git a/src/client/media/camera-previews.ts b/src/client/media/camera-previews.ts
new file mode 100644
index 00000000..fd2804cf
--- /dev/null
+++ b/src/client/media/camera-previews.ts
@@ -0,0 +1,100 @@
+import { browserCameras, type CaptureDevice } from "./capture-devices";
+
+export type CameraPreview = CaptureDevice & { preview: string | null };
+
+function frame(video: HTMLVideoElement): string | null {
+ if (video.readyState < 2 || !video.videoWidth || !video.videoHeight) return null;
+ const canvas = document.createElement("canvas");
+ const scale = Math.min(320 / video.videoWidth, 320 / video.videoHeight);
+ canvas.width = Math.max(1, Math.round(video.videoWidth * scale));
+ canvas.height = Math.max(1, Math.round(video.videoHeight * scale));
+ const context = canvas.getContext("2d");
+ if (!context) return null;
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
+ return canvas.toDataURL("image/jpeg", .75);
+}
+
+async function snapshot(stream: MediaStream, signal: AbortSignal): Promise<string | null> {
+ const video = document.createElement("video");
+ video.muted = true;
+ video.playsInline = true;
+ video.srcObject = stream;
+ try {
+ return await new Promise(resolve => {
+ const finish = () => {
+ clearTimeout(timer);
+ video.removeEventListener("loadeddata", finish);
+ signal.removeEventListener("abort", finish);
+ try { resolve(signal.aborted ? null : frame(video)); }
+ catch { resolve(null); }
+ };
+ const timer = setTimeout(finish, 2000);
+ video.addEventListener("loadeddata", finish);
+ signal.addEventListener("abort", finish, { once: true });
+ if (signal.aborted) finish();
+ else void video.play().catch(finish);
+ });
+ } finally {
+ video.pause();
+ video.srcObject = null;
+ }
+}
+
+/** Picker-only snapshots. Never open another camera while a camera is shared. */
+export async function loadCameraPreviews(signal: AbortSignal,
+ publish: (sources: CameraPreview[]) => void, activeVideo?: HTMLVideoElement | null): Promise<void> {
+ let owned: MediaStream | null = null;
+ const release = () => { owned?.getTracks().forEach(track => track.stop()); owned = null; };
+ const open = async (id: string) => {
+ signal.throwIfAborted();
+ owned = await navigator.mediaDevices.getUserMedia({ audio: false, video: {
+ ...(id ? { deviceId: { exact: id } } : { facingMode: { ideal: "environment" } }),
+ width: { ideal: 320 }, height: { ideal: 180 }, frameRate: { ideal: 15, max: 15 },
+ } });
+ // A permission promise can settle after the picker has closed.
+ if (signal.aborted) { release(); signal.throwIfAborted(); }
+ return owned;
+ };
+ signal.addEventListener("abort", release, { once: true });
+ try {
+ signal.throwIfAborted();
+ let devices = await browserCameras();
+ signal.throwIfAborted();
+ if (activeVideo) {
+ const stream = activeVideo.srcObject as MediaStream | null;
+ const id = stream?.getVideoTracks()[0]?.getSettings().deviceId;
+ publish(devices.map(device => ({ ...device, preview: device.id === id ? frame(activeVideo) : null })));
+ return;
+ }
+ // Permission exposes device identities. Keep that first frame before retiring
+ // the temporary input, then visit remaining cameras one at a time.
+ let first: MediaStream | null = null;
+ if (!devices.some(device => device.label)) {
+ first = await open("");
+ devices = await browserCameras();
+ signal.throwIfAborted();
+ const track = first.getVideoTracks()[0];
+ if (!devices.length && track) devices = [{ id: track.getSettings().deviceId ?? "", label: track.label }];
+ }
+ const sources: CameraPreview[] = devices.map(device => ({ ...device, preview: null }));
+ publish(sources.map(source => ({ ...source })));
+ const firstId = first?.getVideoTracks()[0]?.getSettings().deviceId ?? "";
+ if (first) {
+ const source = sources.find(source => source.id === firstId);
+ if (source) source.preview = await snapshot(first, signal);
+ release();
+ }
+ for (const source of sources) {
+ signal.throwIfAborted();
+ if (!first || source.id !== firstId) {
+ try { source.preview = await snapshot(await open(source.id), signal); }
+ catch (error) { if (signal.aborted) throw error; /* A busy camera remains selectable. */ }
+ finally { release(); }
+ }
+ if (!signal.aborted) publish(sources.map(source => ({ ...source })));
+ }
+ } finally {
+ release();
+ signal.removeEventListener("abort", release);
+ }
+}
diff --git a/src/client/media/capture-devices.ts b/src/client/media/capture-devices.ts
new file mode 100644
index 00000000..922ea4ca
--- /dev/null
+++ b/src/client/media/capture-devices.ts
@@ -0,0 +1,11 @@
+export type CaptureDevice = { id: string; label: string };
+
+// Enumeration never requests permission or opens a device. Device IDs remain
+// local; the capture owner applies an explicit choice when permission is given.
+export async function browserCaptureDevices(kind: "audioinput" | "videoinput"): Promise<CaptureDevice[]> {
+ const devices = await navigator.mediaDevices.enumerateDevices();
+ return devices.filter(device => device.kind === kind && device.deviceId && device.deviceId !== "default" && device.deviceId !== "communications")
+ .map(device => ({ id: device.deviceId, label: device.label }));
+}
+
+export const browserCameras = () => browserCaptureDevices("videoinput");
diff --git a/src/client/media/host-audio.ts b/src/client/media/host-audio.ts
new file mode 100644
index 00000000..9a6102cc
--- /dev/null
+++ b/src/client/media/host-audio.ts
@@ -0,0 +1,138 @@
+import type { BrowserCaptureSource } from "./quality";
+
+// The Host session owns capture and lifetime. This helper owns only the raw
+// audio inputs and mixer; transports borrow its single output track.
+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 closed = false;
+
+ constructor(source: MediaStream, private changed: (enabled: boolean) => void,
+ private kind: BrowserCaptureSource = "browser") {
+ this.source = source;
+ }
+
+ /** Capture facts come from the input, never the mixer destination track. */
+ get sourceStream(): MediaStream { return this.source; }
+ get sourceKind(): BrowserCaptureSource { return this.kind; }
+
+ attach(source: MediaStream, kind = this.kind): MediaStream {
+ const previous = this.source;
+ this.source = source;
+ this.kind = kind;
+ const output = this.compose();
+ 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);
+ }
+ }
+
+ toggleMicrophone(deviceId = this.microphoneDevice): Promise<MediaStream | null> {
+ return this.setMicrophone(!this.microphone?.enabled, deviceId);
+ }
+
+ async setMicrophone(enabled: boolean, deviceId: string): Promise<MediaStream | null> {
+ if (this.closed) return null;
+ if (!enabled || (this.microphone && deviceId === this.microphoneDevice)) {
+ if (this.microphone && deviceId !== this.microphoneDevice) {
+ this.microphone.stop();
+ this.microphone = null;
+ this.compose();
+ }
+ this.microphoneDevice = deviceId;
+ if (this.microphone) this.microphone.enabled = enabled;
+ this.changed(enabled);
+ 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: {
+ echoCancellation: true, noiseSuppression: true, autoGainControl: true,
+ ...(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;
+ microphone.onended = () => {
+ if (this.closed || this.microphone !== microphone) return;
+ this.microphone = null;
+ this.compose();
+ this.changed(false);
+ };
+ const output = this.compose();
+ previous?.stop();
+ stream = null;
+ this.changed(true);
+ // 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;
+ this.microphone?.stop();
+ this.microphone = null;
+ this.source.getAudioTracks().forEach((track) => track.stop());
+ this.closeMixer();
+ }
+}
diff --git a/src/client/media/quality.ts b/src/client/media/quality.ts
index d3711502..bdb860e3 100644
--- a/src/client/media/quality.ts
+++ b/src/client/media/quality.ts
@@ -185,9 +185,7 @@ function captureConstraints(profile: QualityProfile): MediaTrackConstraints {
};
}
-export async function captureDisplay(
- profile: QualityProfile,
-): Promise<MediaStream> {
+export async function captureDisplay(profile: QualityProfile): Promise<MediaStream> {
if (!navigator.mediaDevices?.getDisplayMedia) {
throw new Error("getDisplayMedia unavailable");
}
@@ -195,7 +193,9 @@ export async function captureDisplay(
const complete = debugOperation("capture", "display", { requested: profile });
let stream: MediaStream;
try {
- stream = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions(captureConstraints(profile)));
+ stream = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions({
+ ...captureConstraints(profile),
+ }));
} catch (error) {
complete("failed", {}, error);
throw error;
@@ -219,6 +219,25 @@ export async function captureDisplay(
return stream;
}
+export type BrowserCaptureSource = "browser" | "camera";
+
+export async function captureBrowserSource(profile: QualityProfile, source: BrowserCaptureSource, deviceId = ""): Promise<MediaStream> {
+ if (source !== "camera") return captureDisplay(profile);
+ const resolution = QUALITY_RESOLUTIONS[profile.resolution];
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: {
+ ...(deviceId ? { deviceId: { exact: deviceId } } : { facingMode: { ideal: "environment" } }),
+ width: { ideal: resolution.width }, height: { ideal: resolution.height },
+ frameRate: { ideal: profile.maxFramerate, max: profile.maxFramerate },
+ } });
+ const track = stream.getVideoTracks()[0];
+ if (!track || track.readyState === "ended") {
+ stream.getTracks().forEach((track) => track.stop());
+ throw new Error("Camera capture produced no live video track");
+ }
+ track.contentHint = "motion";
+ return stream;
+}
+
export async function applyCaptureProfile(
stream: MediaStream,
profile: QualityProfile,
diff --git a/src/client/native/client.ts b/src/client/native/client.ts
index 6db3c955..f9c50e6d 100644
--- a/src/client/native/client.ts
+++ b/src/client/native/client.ts
@@ -32,6 +32,7 @@ import {
shareSourceReplacedResponseSchema,
shareUpdatedResponseSchema,
sourceListResponseSchema,
+ microphoneListResponseSchema,
sourcePreviewResponseSchema,
type NativeAdapter,
type NativeClientEvent,
@@ -166,6 +167,7 @@ export class NativeClient {
private readonly listeners = new Set<(event: NativeClientEvent) => void>();
private readonly closeListeners = new Set<() => void>();
private closed = false;
+ private microphoneVolumeUpdate: { shareId: string; volume: number; done: Promise<void> } | null = null;
private constructor(
readonly health: NativeHealth,
@@ -277,13 +279,14 @@ export class NativeClient {
async startShare(
input: NativeShareInput,
- ): Promise<{ audio: boolean; codec: NativeVideoCodec }> {
+ ): Promise<{ audio: boolean; codec: NativeVideoCodec; sourceAudio?: boolean }> {
// Older Apps reject unknown command fields.
const { showCaptureBorder = false, ...shareInput } = input;
const response = await this.request(
"start-share",
{
...shareInput,
+ ...(this.health.nativeMedia.microphone ? { microphoneMixing: true } : {}),
...(this.health.nativeMedia.captureBorderControl ? { showCaptureBorder } : {}),
},
shareStartedResponseSchema,
@@ -292,7 +295,7 @@ export class NativeClient {
if (response.shareId !== input.shareId) {
throw new Error("Native share identity changed");
}
- return { audio: response.audio, codec: response.codec };
+ return { audio: response.audio, codec: response.codec, sourceAudio: response.sourceAudio };
}
async updateShare(shareId: string, profile: QualitySettings): Promise<void> {
@@ -582,7 +585,36 @@ export class NativeClient {
);
}
+ async microphones(): Promise<{ id: string; label: string }[]> {
+ if (!this.health.nativeMedia.microphone) throw new Error("Piik App microphone is unavailable");
+ return (await this.request("list-microphones", {}, microphoneListResponseSchema)).devices;
+ }
+
+ async setMicrophone(shareId: string, enabled: boolean, volume: number, deviceId = ""): Promise<void> {
+ if (!this.health.nativeMedia.microphone) throw new Error("Piik App microphone is unavailable");
+ await this.request("set-microphone", { shareId, enabled, volume, deviceId }, nativeAckResponseSchema, null);
+ }
+
+ // Dragging keeps at most one request in flight and one latest value. It cannot
+ // queue dozens of slider events ahead of Stop or reopen a lost microphone.
+ setMicrophoneVolume(shareId: string, volume: number): Promise<void> {
+ if (!this.health.nativeMedia.microphone) return Promise.reject(new Error("Piik App microphone is unavailable"));
+ const active = this.microphoneVolumeUpdate;
+ if (active?.shareId === shareId) { active.volume = volume; return active.done; }
+ const update = { shareId, volume, done: Promise.resolve() };
+ this.microphoneVolumeUpdate = update;
+ update.done = (async () => {
+ do {
+ const sent = update.volume;
+ await this.request("set-microphone", { shareId, volume: sent }, nativeAckResponseSchema);
+ if (sent === update.volume) break;
+ } while (this.microphoneVolumeUpdate === update && !this.closed);
+ })().finally(() => { if (this.microphoneVolumeUpdate === update) this.microphoneVolumeUpdate = null; });
+ return update.done;
+ }
+
async stopShare(shareId: string): Promise<void> {
+ if (this.microphoneVolumeUpdate?.shareId === shareId) this.microphoneVolumeUpdate = null;
await this.request("stop-share", { shareId }, nativeAckResponseSchema);
}
@@ -597,6 +629,7 @@ export class NativeClient {
close(): void {
if (this.closed) return;
this.closed = true;
+ this.microphoneVolumeUpdate = null;
this.rejectPending();
this.listeners.clear();
this.closeListeners.clear();
diff --git a/src/client/native/wire.ts b/src/client/native/wire.ts
index 229244d9..4326d5da 100644
--- a/src/client/native/wire.ts
+++ b/src/client/native/wire.ts
@@ -36,6 +36,7 @@ export const nativeHealthSchema = nativeDiscoveryIdentitySchema.extend({
video: z.boolean().default(false),
processAudio: z.boolean().default(false),
systemAudio: z.boolean().default(false),
+ microphone: z.boolean().default(false),
// API availability, not Windows approval or observed border visibility.
captureBorderControl: z.boolean().default(false),
hardwareH264: z.boolean().default(false),
@@ -140,6 +141,10 @@ export const sourceListResponseSchema = z
sources: z.array(nativeCaptureTargetSchema).max(1024),
})
.strict();
+export const microphoneListResponseSchema = z.object({
+ ...responseBase, type: z.literal("microphone-list"),
+ devices: z.array(z.object({ id: z.string().min(1).max(512), label: z.string().min(1).max(512) }).strict()).max(64),
+}).strict();
export const sourcePreviewResponseSchema = z
.object({
...responseBase,
@@ -155,6 +160,7 @@ export const shareStartedResponseSchema = z
type: z.literal("share-started"),
shareId: opaqueIdentifierSchema,
audio: z.boolean(),
+ sourceAudio: z.boolean().optional(),
codec: nativeVideoCodecSchema,
})
.strict();
@@ -227,6 +233,7 @@ export const nativeAckResponseSchema = z
"receive-stopped",
"share-stopped",
"share-paused",
+ "microphone-set",
"publication-answer-accepted",
"publication-candidate-accepted",
"publication-layers-accepted",
@@ -241,6 +248,7 @@ const eventBase = {
};
export const nativeEventSchema = z.discriminatedUnion("type", [
+ z.object({ ...eventBase, type: z.literal("audio-state"), sourceAudio: z.boolean(), microphone: z.boolean(), failed: z.boolean() }).strict(),
z
.object({
...eventBase,
diff --git a/src/client/pages/AppLauncherPage.tsx b/src/client/pages/AppLauncherPage.tsx
index 142498b6..0ae1cf6d 100644
--- a/src/client/pages/AppLauncherPage.tsx
+++ b/src/client/pages/AppLauncherPage.tsx
@@ -5,7 +5,7 @@ import { BrandMark } from "../components/living/BrandMark";
import { LoadingStatus } from "../components/living/WaitingStatus";
import { Tooltip } from "../components/living/Tooltip";
import { AppHeader } from "../components/living/Header";
-import { LauncherForm, type AppMode } from "../components/living/LauncherForm";
+import { LauncherForm, SUGGESTED_SITE, type AppMode } from "../components/living/LauncherForm";
import { Btn, Pill } from "../components/living/primitives";
import { Glyph } from "../ui/icons";
import { hasCopyPreference, useCopy, type CopyKey } from "../ui/copy";
@@ -57,7 +57,7 @@ export function AppLauncherPage() {
.then((state) => {
if (!current) return;
setMode(state.defaultMode);
- setSite(state.site);
+ setSite(state.site || SUGGESTED_SITE);
setLocalAccessPassword(state.localAccessPassword);
setAppDebug(state.debug);
setDebug(state.debug === true || browserDebugEnabled);
diff --git a/src/client/pages/ControlsPreview.tsx b/src/client/pages/ControlsPreview.tsx
index b9e74bdf..cb402638 100644
--- a/src/client/pages/ControlsPreview.tsx
+++ b/src/client/pages/ControlsPreview.tsx
@@ -4,10 +4,14 @@ import { RoomChip, RoomAdmissionBadge } from "../components/living/RoomChip";
import { CaptureSourcePicker, type NativeSourceList } from "../components/living/CaptureSourcePicker";
import { LedStrip } from "../components/living/Header";
import { StageTv } from "../components/living/Stage";
+import { HostMicrophone, HostMicrophoneSettings } from "../components/living/HostMicrophone";
import { PlaybackControls } from "../components/living/PlaybackControls";
+import { SharingSettings } from "../components/living/SharingSettings";
+import { LauncherForm, SUGGESTED_SITE, type AppMode } from "../components/living/LauncherForm";
import { QualityPresets } from "../components/living/QualityPresets";
import { RoomCodeInput } from "../components/living/RoomCodeInput";
import type { QualityProfileId } from "../media/quality";
+import type { loadCameraPreviews } from "../media/camera-previews";
import { Tooltip } from "../components/living/Tooltip";
import { StatusIndicator } from "../components/living/StatusIndicator";
import { deriveParticipantStatus } from "../ui/media-status";
@@ -23,14 +27,28 @@ const SOURCES = { kind: "ready", processAudio: true, systemAudio: true, captureB
{ kind: "display", sourceId: "103", title: "Display 1" },
] } satisfies NativeSourceList;
const previewSource = async () => POSTER;
+const previewCameras: typeof loadCameraPreviews = async (_signal, publish) => publish([
+ { id: "built-in", label: "Built-in 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="#dce9e5"/><rect x="216" y="16" width="82" height="102" rx="7" fill="#fbfcf3"/><path d="M257 16v102M216 66h82" stroke="#b2cbc2" stroke-width="4"/><path d="M106 147q0-62 54-62t54 62" fill="#449986"/><circle cx="160" cy="57" r="29" fill="#449986"/><path d="M151 55v4m18-4v4" stroke="#203c3a" stroke-width="5" stroke-linecap="round"/><path d="M0 151h320v29H0" fill="#d8b898"/><rect x="232" y="131" 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" }];
export function ControlsPreview() {
const { t, lang, vis } = useCopy();
const en = lang === "en";
const [sound, setSound] = useState(true);
+ const [microphone, setMicrophone] = useState(false);
+ const [microphoneVolume, setMicrophoneVolume] = useState(1);
+ const [microphoneDevice, setMicrophoneDevice] = useState("");
+ const [sharingSettings, setSharingSettings] = useState(false);
+ const [launchMode, setLaunchMode] = useState<AppMode>("link");
+ const [launchSite, setLaunchSite] = useState(SUGGESTED_SITE);
+ const [launchPassword, setLaunchPassword] = useState("");
const [preset, setPreset] = useState<QualityProfileId>("1080p30");
const [policy, setPolicy] = useState<"open" | "private">("open");
const [roomPassword, setRoomPassword] = useState(false);
+ const [includeCredential, setIncludeCredential] = useState(true);
+ const roomLink = `https://piik.example/r/9527${includeCredential ? "#v=preview" : ""}`;
const [paused, setPaused] = useState(false);
const [passwordVisible, setPasswordVisible] = useState(false);
const [name, setName] = useState("Piik friend");
@@ -66,10 +84,25 @@ export function ControlsPreview() {
<Btn icon="network" title="host.topology" hint="hint-topology" onClick={notify} />
<Btn icon="sliders" title="host.advanced" hint="hint-advanced" onClick={notify} />
</div>
+ <div className="lr-host-share-controls lr-media-controls" role="group" aria-label={t("host.shareControls")}>
+ <HostMicrophone enabled={microphone} paused={paused} volume={microphoneVolume}
+ onToggle={() => setMicrophone(value => !value)} />
+ <Btn icon={paused ? "play" : "pause"} title={paused ? "host.resume" : "host.pause"} cap={paused ? "host.resume" : "host.pause"}
+ hint={paused ? "hint-resume" : "hint-pause"} onClick={() => setPaused(!paused)} />
+ <Btn icon="switchSource" title="host.switchSource" cap="host.switchSource" hint="hint-switch-source" onClick={notify} />
+ <Btn icon="sliders" cap="host.settings.button" title={sharingSettings ? "host.advanced.hide" : "host.advanced"}
+ hint={sharingSettings ? "hint-collapse" : "hint-advanced"} tone={sharingSettings ? "on" : undefined}
+ expanded={sharingSettings} controls="preview-sharing-settings" onClick={() => setSharingSettings(value => !value)} />
+ <Btn id="host-stop-share" icon="stop" tone="danger" title="host.stop" cap="host.stop" hint="hint-share-stop" onClick={notify} />
+ </div>
+ <SharingSettings id="preview-sharing-settings" open={sharingSettings}
+ presets={<QualityPresets selected={preset} onSelect={setPreset} />}
+ audio={<HostMicrophoneSettings deviceId={microphoneDevice} onDevice={setMicrophoneDevice} loadDevices={previewMicrophones}
+ native enabled={microphone} disabled={paused} volume={microphoneVolume} onVolume={setMicrophoneVolume} />}
+ />
</section>
<section id="option-preview" className="cp-card">
<header><span className="cp-number">02</span><h2>{en ? "Pick, toggle, adjust" : "选一个,再拨一下。"}</h2></header>
- <QualityPresets selected={preset} onSelect={setPreset} />
<div className="cp-tools">
<SwitchItem checked={sound} onChange={setSound} label={t("host.sourcePicker.audioOn")} hint="hint-share-audio" />
<SwitchItem checked disabled locked onChange={() => undefined} label={t("host.advanced.route.peerOnly")}
@@ -91,6 +124,18 @@ export function ControlsPreview() {
<RoomAdmissionBadge policy="private" passwordEnabled />
<RoomAdmissionBadge policy="private" passwordEnabled={false} />
</div>
+ <div className="lr-invite-field">
+ <Tooltip kind="hint-invite-link" text={roomLink} className="lr-invite-hint">
+ <input className="lr-invite-url" readOnly dir="ltr" value={roomLink}
+ aria-label={t(includeCredential ? "host.invite" : "host.invite.address")} />
+ </Tooltip>
+ <span className="lr-row-group"><Glyph name="key" size={17} />
+ <SwitchItem checked={includeCredential} onChange={setIncludeCredential}
+ label={t("host.invite.includeCredential")} note={t("host.invite.credentialHint")} hint="hint-invite-link" />
+ </span>
+ </div>
+ {!includeCredential && policy === "private" && !roomPassword ? <Pill icon="lock" tone="warn"
+ comic="hint-policy-private" label={t("host.invite.credentialRequired")} /> : null}
</section>
<section id="input-preview" className="cp-card">
<header><span className="cp-number">03</span><h2>{en ? "Names, codes and small details" : "名字、房间号,还有小细节。"}</h2></header>
@@ -103,7 +148,7 @@ export function ControlsPreview() {
placeholder={t("join.password")} aria-label={t("join.password")} aria-invalid={invalid} aria-describedby={invalid ? "preview-input-error" : undefined} autoComplete="off" />
</label>
<Btn icon={passwordVisible ? "eyeOff" : "eye"} title={passwordVisible ? "host.password.hide" : "host.password.show"}
- hint={passwordVisible ? "hint-password-hide" : "hint-password-show"} onClick={() => setPasswordVisible(!passwordVisible)} />
+ pressed={passwordVisible} hint={passwordVisible ? "hint-password-hide" : "hint-password-show"} onClick={() => setPasswordVisible(!passwordVisible)} />
<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}
@@ -129,7 +174,7 @@ export function ControlsPreview() {
<PeoplePreview />
<section id="source-preview" className="cp-section">
<header className="cp-section-head"><span className="cp-number">06</span><div><h2>{en ? "Choose a picture" : "挑一块画面。"}</h2>
- <p>{en ? "The actual source selector, with sample windows. Selection only updates this preview." : "正式的画面选择器,放入了几个示例窗口;选择只影响这张预览。"}</p></div></header>
+ <p>{en ? "The actual source selector, with sample windows and cameras. Selection only updates this preview." : "正式的画面选择器,放入了示例窗口和摄像头;选择只影响这张预览。"}</p></div></header>
<div className="cp-tools">{(["ready", "loading", "unavailable", "incompatible", "unsupported", "failed", "empty"] as const).map((value, index) => <Chip key={value}
title={value} selected={sourceState === value} onClick={() => { setSourceState(value); setSourceOpen(true); }}>
{en ? ["Available", "Loading", "App unavailable", "Update needed", "Capture unavailable", "Read failed", "Empty list"][index] : ["正常", "读取中", "App 未连接", "需要更新", "无法采集", "读取失败", "空列表"][index]}</Chip>)}
@@ -142,6 +187,8 @@ export function ControlsPreview() {
: sourceState === "ready" ? { ...SOURCES, captureBorderControl: captureBorderAvailable } : { kind: sourceState }}
initialShowCaptureBorder={showCaptureBorder}
onBrowser={() => { setSourceOpen(false); notify(); }}
+ onCamera={() => { setSourceOpen(false); notify(); }}
+ loadCameras={previewCameras}
onNative={(_target, _audio, showBorder) => { setShowCaptureBorder(showBorder); setSourceOpen(false); notify(); }}
onPreview={previewSource} onRefresh={() => setSourceState("ready")} onCancel={() => setSourceOpen(false)} />
: <div className="cp-stage-action"><Btn icon="cast" tone="primary" title="host.start" cap="host.start" hint="hint-share-start" onClick={() => setSourceOpen(true)} /></div>}
@@ -156,5 +203,14 @@ export function ControlsPreview() {
</StageTv></div>
<p><a href="/__playback-preview">{en ? "Open the full playback preview" : "进入完整播放预览"} →</a></p>
</section>
+ <section id="launcher-preview" className="cp-section">
+ <header className="cp-section-head"><span className="cp-number">08</span><h2>{t("client.launch.title")}</h2></header>
+ <div className="lr-client-launch">
+ <LauncherForm mode={launchMode} onModeChange={setLaunchMode}
+ site={launchSite} onSiteChange={setLaunchSite}
+ localAccessPassword={launchPassword} onLocalAccessPasswordChange={setLaunchPassword}
+ onSubmit={event => event.preventDefault()} />
+ </div>
+ </section>
</>;
}
diff --git a/src/client/pages/HostPage.tsx b/src/client/pages/HostPage.tsx
index ae4140b8..7417ed3d 100644
--- a/src/client/pages/HostPage.tsx
+++ b/src/client/pages/HostPage.tsx
@@ -1,4 +1,5 @@
import {
+ useCallback,
useEffect,
useLayoutEffect,
useMemo,
@@ -21,9 +22,13 @@ 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 { Couch, type CouchEntry } from "../components/living/Couch";
+import { SharingSettings } from "../components/living/SharingSettings";
+import { HostMicrophone, HostMicrophoneSettings } from "../components/living/HostMicrophone";
+import { HostAudio } from "../media/host-audio";
import {
CaptureSourcePicker,
type NativeSourceList,
@@ -110,7 +115,8 @@ import {
import { labelParticipantSnapshot } from "../lib/viewer-presence";
import {
applyCaptureProfile,
- captureDisplay,
+ captureBrowserSource,
+ type BrowserCaptureSource,
matchingQualityProfileId,
QUALITY_PROFILES,
DEGRADATION_PREFERENCE_KEYS,
@@ -235,10 +241,10 @@ interface CaptureDetails {
* mode never see a baked-in string from capture time. */
resolution: string | null;
frameRate: number | null;
- hasAudio: boolean;
+ hasSourceAudio: boolean;
}
-function captureDetails(stream: MediaStream, native = false): CaptureDetails {
+function captureDetails(stream: MediaStream, native = false, sourceAudio?: boolean): CaptureDetails {
// A Native preview is a received track, not an observation of raw capture.
const settings = native ? undefined : stream.getVideoTracks()[0]?.getSettings();
return {
@@ -247,7 +253,7 @@ function captureDetails(stream: MediaStream, native = false): CaptureDetails {
? `${settings.width}x${settings.height}`
: null,
frameRate: settings?.frameRate ?? null,
- hasAudio: stream.getAudioTracks().length > 0,
+ hasSourceAudio: sourceAudio ?? stream.getAudioTracks().length > 0,
};
}
@@ -331,7 +337,7 @@ interface HostPageProps {
}
type ShareSourceSelection =
- | { kind: "browser" }
+ | { kind: "browser"; source?: BrowserCaptureSource; deviceId?: string }
| {
kind: "native";
client: NativeClient;
@@ -371,6 +377,16 @@ export function HostPage({
const [signalStatus, setSignalStatus] =
useState<SignalConnectionState>("offline");
const [stream, setStream] = useState<MediaStream | null>(null);
+ const hostAudioRef = useRef<HostAudio | null>(null);
+ const [microphoneEnabled, setMicrophoneEnabled] = useState(false);
+ const [microphoneVolume, setMicrophoneVolume] = useState(1);
+ const [microphonePending, setMicrophonePending] = useState(false);
+ const [microphoneDevices, setMicrophoneDevices] = useState({ browser: "", native: "" });
+ 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 [showCaptureBorder, setShowCaptureBorder] = useState(false);
const [nativeSources, setNativeSources] =
@@ -487,10 +503,13 @@ export function HostPage({
): void {
setNoticeKey(key, comic, tone, vars);
}
- const [copiedInviteUrl, setCopiedInviteUrl] = useState<string | null>(null);
- const copied = copiedInviteUrl !== null && copiedInviteUrl === room?.inviteUrl;
+ const [includeInviteCredential, setIncludeInviteCredential] = useState(true);
+ const roomLink = includeInviteCredential ? room?.inviteUrl : room?.canonicalUrl;
+ const roomLinkBlocked = !includeInviteCredential && room?.codeEntryPolicy === "private" && !viewerPasswordEnabled;
+ const [copiedRoomLink, setCopiedRoomLink] = useState<string | null>(null);
+ const copied = copiedRoomLink !== null && copiedRoomLink === roomLink;
const copiedResetTimerRef = useRef<number | null>(null);
- const copyInviteRequestRef = useRef<object | null>(null);
+ const copyRoomLinkRequestRef = useRef<object | null>(null);
const [switchingSource, setSwitchingSource] = useState(false);
const [changingQuality, setChangingQuality] = useState(false);
const [sharingPaused, setSharingPaused] = useState(false);
@@ -540,7 +559,7 @@ export function HostPage({
const activeRouteRevisionRef = useRef(0);
const generationRef = useRef(0);
const activeGenerationRef = useRef<number | null>(null);
- const sourceSwitchRef = useRef<object | null>(null);
+ const sourceSwitchRef = useRef<{ replacingVideo?: MediaStreamTrack } | null>(null);
const qualityChangeRef = useRef<object | null>(null);
const pendingQualityChangeRef = useRef<QualitySettings | null>(null);
const qualitySettingsRef = useRef<QualitySettings>(DEFAULT_QUALITY_SETTINGS);
@@ -563,6 +582,7 @@ export function HostPage({
const nativeEventCleanupRef = useRef<(() => void) | null>(null);
const nativeClientCloseCleanupRef = useRef<(() => void) | null>(null);
const nativeModeRef = useRef(false);
+ const nativeSourceAudioRef = useRef<boolean | undefined>(undefined);
const nativeSourceRequestRef = useRef<object | null>(null);
const nativePreviewTailRef = useRef<Promise<void>>(Promise.resolve());
const nativeSourcePathRef = useRef<NativeCapturePath | null>(null);
@@ -670,7 +690,7 @@ export function HostPage({
window.clearTimeout(copiedResetTimerRef.current);
copiedResetTimerRef.current = null;
}
- copyInviteRequestRef.current = null;
+ copyRoomLinkRequestRef.current = null;
viewerQualityEvidenceStore.clear();
cancelViewerQualityEvidenceRender();
activeRouteRevisionRef.current = 0;
@@ -684,6 +704,8 @@ export function HostPage({
nativeClientConnectRef.current = null;
nativeClientRef.current?.close();
nativeClientRef.current = null;
+ hostAudioRef.current?.dispose();
+ hostAudioRef.current = null;
streamRef.current?.getTracks().forEach((track) => track.stop());
retiringStreamRef.current?.getTracks().forEach((track) => track.stop());
streamRef.current = null;
@@ -847,6 +869,10 @@ export function HostPage({
hostPeerIdRef.current = null;
void hostSfuRouteRef.current?.disconnect();
hostSfuRouteRef.current = null;
+ hostAudioRef.current?.dispose();
+ hostAudioRef.current = null;
+ setMicrophoneEnabled(false);
+ setMicrophonePending(false);
streamRef.current?.getTracks().forEach((track) => track.stop());
retiringStreamRef.current?.getTracks().forEach((track) => track.stop());
streamRef.current = null;
@@ -882,7 +908,7 @@ export function HostPage({
clearHostRoom(keepResumeHint);
roomRef.current = null;
setRoom(null);
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
setViewerPasswordDraft(creationProfileRef.current.roomPassword ?? "");
setViewerPasswordVisible(false);
return true;
@@ -970,7 +996,7 @@ export function HostPage({
writePreferredRoom(replacement.roomId);
roomRef.current = replacement;
setRoom(replacement);
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
setViewerPasswordEnabled(profile.roomPassword !== null);
setViewerPasswordDraft(profile.roomPassword ?? "");
setViewerPasswordVisible(false);
@@ -1010,7 +1036,7 @@ export function HostPage({
writePreferredRoom(replacement.roomId);
roomRef.current = replacement;
setRoom(replacement);
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
setViewerPasswordEnabled(profile.roomPassword !== null);
setViewerPasswordDraft(profile.roomPassword ?? "");
setViewerPasswordVisible(false);
@@ -1106,12 +1132,14 @@ export function HostPage({
captured: MediaStream,
generation: number,
): void {
- captured.getVideoTracks()[0]?.addEventListener(
+ const track = captured.getVideoTracks()[0];
+ track?.addEventListener(
"ended",
() => {
if (
isCurrentGeneration(generation) &&
- streamRef.current === captured
+ streamRef.current?.getVideoTracks()[0] === track &&
+ sourceSwitchRef.current?.replacingVideo !== track
) {
endSharing({ key: "host.stopNotice" });
}
@@ -1128,11 +1156,31 @@ export function HostPage({
const { client, target, audio, showCaptureBorder, path } = selection;
let bridge: NativeMediaBridge | null = null;
let shareStarted = false;
+ let nativeEventCleanup: (() => void) | null = null;
try {
await nativeShareCleanupRef.current;
await nativePreviewTailRef.current;
if (!isCurrentShare(generation, shareGeneration)) return null;
if (nativeClientRef.current !== client) throw new Error("Piik App is unavailable");
+ nativeSourceAudioRef.current = undefined;
+ nativeEventCleanup = client.onEvent((event) => {
+ if (event.shareId !== shareGeneration || !isCurrentShare(generation, shareGeneration) || nativeClientRef.current !== client) return;
+ if (event.type === "audio-state") {
+ nativeSourceAudioRef.current = event.sourceAudio;
+ 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.type === "share-ended") {
+ endSharing(
+ { key: event.failed ? "host.shareEnded" : "host.stopNotice" },
+ true,
+ event.failed ? "source-failed" : "share-ended",
+ event.failed ? "bad" : "off",
+ );
+ }
+ });
+ nativeEventCleanupRef.current = nativeEventCleanup;
const started = await client.startShare({
shareId: shareGeneration,
source: target,
@@ -1150,6 +1198,7 @@ export function HostPage({
return null;
}
if (nativeClientRef.current !== client) throw new Error("Piik App is unavailable");
+ nativeSourceAudioRef.current ??= started.sourceAudio ?? started.audio;
videoCodecRef.current = manualVideoCodecPreference(started.codec);
bridge = new NativeMediaBridge(
shareGeneration,
@@ -1171,22 +1220,6 @@ export function HostPage({
nativeMediaBridgeRef.current = bridge;
nativeModeRef.current = true;
setNativeActive(true);
- const nativeEventCleanup = client.onEvent((event) => {
- if (
- event.type === "share-ended" &&
- event.shareId === shareGeneration &&
- isCurrentShare(generation, shareGeneration) &&
- nativeClientRef.current === client
- ) {
- endSharing(
- { key: event.failed ? "host.shareEnded" : "host.stopNotice" },
- true,
- event.failed ? "source-failed" : "share-ended",
- event.failed ? "bad" : "off",
- );
- }
- });
- nativeEventCleanupRef.current = nativeEventCleanup;
const stream = await bridge.start();
if (!isCurrentShare(generation, shareGeneration)) {
if (nativeMediaBridgeRef.current === bridge) disposeNativeShare();
@@ -1195,6 +1228,8 @@ export function HostPage({
}
return stream;
} catch (error) {
+ nativeEventCleanup?.();
+ if (nativeEventCleanupRef.current === nativeEventCleanup) nativeEventCleanupRef.current = null;
if (
nativeClientRef.current === client &&
nativeShareGenerationRef.current === shareGeneration
@@ -1295,6 +1330,10 @@ export function HostPage({
const request = {};
nativeSourceRequestRef.current = request;
nativeSourcePathRef.current = null;
+ if (!launchedByClient || (phase === "live" && !nativeModeRef.current)) {
+ setNativeSources({ kind: "browser" });
+ return;
+ }
setNativeSources({ kind: "loading" });
let client: NativeClient | null;
@@ -1402,15 +1441,12 @@ export function HostPage({
function requestSharing(): void {
setJoiningRoom(false);
- if (!launchedByClient) {
- void startSharing({ kind: "browser" });
- return;
- }
void openCaptureSourcePicker();
}
- function startBrowserShareFromPicker(): void {
- void startSharing({ kind: "browser" });
+ function startBrowserShareFromPicker(source: BrowserCaptureSource, deviceId = ""): void {
+ if (phase === "live") void switchSource(source, deviceId);
+ else void startSharing({ kind: "browser", source, deviceId });
}
async function loadNativeSourcePreview(
@@ -1467,6 +1503,7 @@ export function HostPage({
nativeEventCleanupRef.current = null;
nativeShareGenerationRef.current = null;
nativeModeRef.current = false;
+ nativeSourceAudioRef.current = undefined;
setNativeActive(false);
if (!client || !shareGeneration) {
releaseUnusedNativeClient();
@@ -1614,9 +1651,9 @@ export function HostPage({
debugEvent("quality", "committed", { generation, applied: appliedProfile });
outcome = "applied";
if (nativeUpdate) {
- setDetails(captureDetails(activeStream, true));
+ setDetails(captureDetails(activeStream, true, nativeSourceAudioRef.current));
} else if (captureChanged) {
- setDetails(captureDetails(activeStream));
+ setDetails(captureDetails(hostAudioRef.current?.sourceStream ?? activeStream));
}
signalRef.current?.setHostQualitySettings(appliedProfile);
const ingress = nativeMediaIngressRef.current;
@@ -1787,6 +1824,9 @@ export function HostPage({
return;
}
sharingPausedRef.current = false;
+ // Before the mixer existed, source audio itself was the paused output.
+ // Restore it only on an accepted resume, never during permission handoff.
+ if (hostAudioRef.current) setMediaPaused(hostAudioRef.current.sourceStream, false);
setSharingPaused(false);
setNoticeValue(null);
return;
@@ -2395,7 +2435,7 @@ export function HostPage({
shareGenerationRef.current = shareGeneration;
closeCaptureSourcePicker();
setNoticeValue(null);
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
setPhase("starting");
let captured: MediaStream | null = null;
@@ -2410,7 +2450,7 @@ export function HostPage({
nativeStarted = true;
} else {
// This must remain the first awaited operation in the button gesture.
- captured = await captureDisplay(qualitySettingsRef.current);
+ captured = await captureBrowserSource(qualitySettingsRef.current, selection.source ?? "browser", selection.deviceId);
}
} catch (error) {
if (!isCurrentShare(generation, shareGeneration)) {
@@ -2419,7 +2459,7 @@ export function HostPage({
}
activeGenerationRef.current = null;
shareGenerationRef.current = null;
- setNoticeError(error, "capture", "television");
+ setCaptureError(error, selection.kind === "browser" ? selection.source : undefined, "capture");
setPhase(isCapturePermissionFailure(error, "capture") ? "idle" : "error");
return;
}
@@ -2430,12 +2470,16 @@ export function HostPage({
return;
}
if (captured) {
+ if (selection.kind === "browser") {
+ hostAudioRef.current = new HostAudio(captured, setMicrophoneEnabled, selection.source ?? "browser");
+ if (selection.source === "camera") setCameraDevice(selection.deviceId ?? "");
+ }
streamRef.current = captured;
setStream(captured);
watchCaptureEnd(captured, generation);
if (selection.kind === "native") {
setDetails(
- captureDetails(captured, true),
+ captureDetails(captured, true, nativeSourceAudioRef.current),
);
} else {
setDetails(captureDetails(captured));
@@ -2718,7 +2762,7 @@ export function HostPage({
const activeStream = streamRef.current;
if (activeStream) {
setDetails(
- captureDetails(activeStream, true),
+ captureDetails(activeStream, true, nativeSourceAudioRef.current),
);
}
const sfuUpdated = await hostSfuRouteRef.current?.updateProfile(qualitySettingsRef.current) ?? true;
@@ -2745,7 +2789,7 @@ export function HostPage({
}
}
- async function switchSource(): Promise<void> {
+ async function switchSource(source?: BrowserCaptureSource, deviceId = ""): Promise<void> {
const generation = activeGenerationRef.current;
if (
phase !== "live" ||
@@ -2756,26 +2800,35 @@ export function HostPage({
) {
return;
}
- if (nativeModeRef.current) {
+ if (!source) {
await openCaptureSourcePicker();
return;
}
+ if (nativeModeRef.current) return;
- const token = {};
+ // Some browsers retire the old camera while opening the new one. That
+ // transition belongs to this replacement, not the share-ended observer.
+ const token = { replacingVideo: source === "camera" && hostAudioRef.current?.sourceKind === "camera"
+ ? streamRef.current?.getVideoTracks()[0] : undefined };
sourceSwitchRef.current = token;
+ closeCaptureSourcePicker();
setSwitchingSource(true);
setNoticeValue(null);
let captured: MediaStream;
try {
// Like initial capture, changing source must begin in this button gesture.
- captured = await captureDisplay(qualitySettingsRef.current);
+ captured = await captureBrowserSource(qualitySettingsRef.current, source, deviceId);
} catch (error) {
if (
isCurrentGeneration(generation) &&
sourceSwitchRef.current === token
) {
- setNoticeError(error, "source");
+ if (token.replacingVideo?.readyState === "ended") {
+ endSharing({ key: "host.shareEnded" }, true, "source-failed", "bad");
+ } else {
+ setCaptureError(error, source, "source");
+ }
}
finishSourceSwitch(token);
return;
@@ -2789,24 +2842,90 @@ export function HostPage({
return;
}
+ try {
+ if (source === "camera") setCameraDevice(deviceId);
+ captured = hostAudioRef.current?.attach(captured, source) ?? captured;
+ await replaceBrowserStream(captured, generation, token);
+ } catch (error) {
+ if (isCurrentGeneration(generation)) setNoticeError(error, "source");
+ } finally {
+ finishSourceSwitch(token);
+ }
+ }
+
+ function setCaptureError(error: unknown, source: BrowserCaptureSource | undefined, action: "source" | "capture") {
+ const target = action === "source" ? "operation" : "television";
+ if (source !== "camera") {
+ setNoticeError(error, action, target);
+ return;
+ }
+ setNoticeValue({ kind: "key", key: error instanceof DOMException && error.name === "NotAllowedError"
+ ? "host.camera.denied" : "host.camera.unavailable", target, comic: "source-failed", tone: "warn" });
+ }
+
+ async function changeMicrophone(enabled: boolean, deviceId: string): 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);
+ if (!isCurrentGeneration(generation) || hostAudioRef.current !== audio) return;
+ setMicrophoneDevices(previous => ({ ...previous, browser: deviceId }));
+ 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;
if (!previousStream) {
captured.getTracks().forEach((track) => track.stop());
setNoticeKey("host.shareEnded", "share-ended", "off");
- finishSourceSwitch(token);
return;
}
retiringStreamRef.current = previousStream;
- invalidateSenderQualityEvidence();
- if (routePolicyRef.current.topologyOptimization) {
+ 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.
+ const retirePrevious = () => previousStream.getVideoTracks().forEach((track) => {
+ if (!captured.getTracks().includes(track)) track.stop();
+ });
+ if (videoChanged) invalidateSenderQualityEvidence();
+ if (videoChanged && routePolicyRef.current.topologyOptimization) {
signalRef.current?.send({ type: "reset-sender-quality" });
}
setMediaPaused(captured, sharingPausedRef.current);
streamRef.current = captured;
setStream(captured);
- setDetails(captureDetails(captured));
- watchCaptureEnd(captured, generation);
+ setDetails(captureDetails(hostAudioRef.current?.sourceStream ?? captured));
+ if (videoChanged) watchCaptureEnd(captured, generation);
try {
const ingress = nativeMediaIngressRef.current;
@@ -2884,7 +3003,7 @@ export function HostPage({
activeSfuRoute && hostSfuRouteRef.current === activeSfuRoute
? syncHostSfuQualityWarning(activeSfuRoute, generation)
: null;
- previousStream.getTracks().forEach((track) => track.stop());
+ retirePrevious();
if (retiringStreamRef.current === previousStream) {
retiringStreamRef.current = null;
}
@@ -2912,7 +3031,7 @@ export function HostPage({
);
if (
- isCurrentGeneration(generation) &&
+ videoChanged && isCurrentGeneration(generation) &&
sourceSwitchRef.current === token
) {
const sourceNotice =
@@ -2932,28 +3051,28 @@ export function HostPage({
);
}
} finally {
- previousStream.getTracks().forEach((track) => track.stop());
+ retirePrevious();
if (retiringStreamRef.current === previousStream) {
retiringStreamRef.current = null;
}
- finishSourceSwitch(token);
}
}
- async function copyInvite(): Promise<void> {
+ async function copyRoomLink(): Promise<void> {
const activeRoom = roomRef.current;
- const inviteUrl = activeRoom?.inviteUrl;
- if (!inviteUrl) {
+ const link = includeInviteCredential ? activeRoom?.inviteUrl : activeRoom?.canonicalUrl;
+ if (!activeRoom || !link || roomLinkBlocked || roomMutating) {
return;
}
const request = {};
- copyInviteRequestRef.current = request;
- const current = () => copyInviteRequestRef.current === request &&
- isCurrentRoomAuthority(activeRoom) && roomRef.current?.inviteUrl === inviteUrl;
+ copyRoomLinkRequestRef.current = request;
+ const current = () => copyRoomLinkRequestRef.current === request &&
+ isCurrentRoomAuthority(activeRoom) &&
+ (includeInviteCredential ? roomRef.current?.inviteUrl : roomRef.current?.canonicalUrl) === link;
try {
- await navigator.clipboard.writeText(inviteUrl);
+ await navigator.clipboard.writeText(link);
if (!current()) return;
- setCopiedInviteUrl(inviteUrl);
+ setCopiedRoomLink(link);
setNoticeValue((current) => current?.kind === "key" && current.key === "host.invite.copyFailed" ? null : current);
// One owner for the confirmation window: a second copy restarts it
// instead of inheriting the first click's expiry.
@@ -2962,11 +3081,11 @@ export function HostPage({
}
copiedResetTimerRef.current = window.setTimeout(() => {
copiedResetTimerRef.current = null;
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
}, 1_500);
} catch {
if (!current()) return;
- setCopiedInviteUrl(null);
+ setCopiedRoomLink(null);
setNoticeErrorKey("host.invite.copyFailed", "copy-failed");
}
}
@@ -3318,20 +3437,23 @@ export function HostPage({
{nativeSources ? (
<CaptureSourcePicker
nativeSources={nativeSources}
- initialTab={nativeClientRef.current ? "window" : "browser"}
- onBrowser={startBrowserShareFromPicker}
+ onBrowser={() => startBrowserShareFromPicker("browser")}
+ onCamera={deviceId => startBrowserShareFromPicker("camera", deviceId)}
+ initialCamera={cameraDevice}
+ activeCameraVideo={hostAudioRef.current?.sourceKind === "camera" ? videoRef.current : null}
onNative={startNativeShareFromPicker}
onPreview={loadNativeSourcePreview}
onRefresh={openCaptureSourcePicker}
onCancel={closeCaptureSourcePicker}
- browserAvailable={!nativeActive}
+ browserAvailable={!nativeActive && !!navigator.mediaDevices?.getDisplayMedia}
+ cameraAvailable={!nativeActive && !!navigator.mediaDevices?.getUserMedia}
selectionDisabled={roomMutating || switchingSource || changingQuality}
initialAudio={
nativeActive
- ? (streamRef.current?.getAudioTracks().length ?? 0) > 0
+ ? nativeSourceAudioRef.current ?? false
: true
}
- audioLocked={nativeActive}
+ audioLocked={nativeActive && !nativeClientRef.current?.health.nativeMedia.microphone}
initialShowCaptureBorder={showCaptureBorder}
/>
) : !stream &&
@@ -3381,6 +3503,7 @@ export function HostPage({
style={{ gap: 12 }}
onSubmit={joinRoomFromStage}
>
+ {!vis && <span className="lr-cap lr-join-site">{t("join.hint", { site: window.location.host })}</span>}
<RoomCodeInput value={joinRoomCode} rejectedAttempt={joinRejectedAttempt} autoFocus
onChange={value => { setJoinRoomCode(value); setJoinRejectedAttempt(0); }} />
<RoomCodeError attempt={joinRejectedAttempt} theme="stage" />
@@ -3426,9 +3549,67 @@ export function HostPage({
/>
) : null}
</StageTv>
+ <div className="lr-host-share-controls lr-media-controls" role="group" aria-label={t("host.shareControls")}>
+ {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"])} />
+ <Btn
+ icon={sharingPaused ? "play" : "pause"}
+ cap={sharingPaused ? "host.resume" : "host.pause"}
+ title={sharingPaused ? "host.resume" : "host.pause"}
+ hint={sharingPaused ? "hint-resume" : "hint-pause"}
+ draw="host-share-toggle"
+ disabled={switchingSource || changingQuality || microphonePending}
+ onClick={toggleSharingPause}
+ />
+ <Btn
+ id="host-switch-source"
+ icon="switchSource"
+ cap={switchingSource ? "host.switching" : "host.switchSource"}
+ title="host.switchSource"
+ hint="hint-switch-source"
+ disabled={switchingSource || changingQuality || microphonePending}
+ onClick={() => void switchSource()}
+ />
+ </> : null}
+ <Btn
+ icon="sliders"
+ busy={changingQuality}
+ cap="host.settings.button"
+ title={showAdvanced ? "host.advanced.hide" : "host.advanced"}
+ hint={showAdvanced ? "hint-collapse" : "hint-advanced"}
+ tone={showAdvanced ? "on" : undefined}
+ expanded={showAdvanced}
+ controls="host-advanced-door"
+ onClick={() => setShowAdvanced((current) => !current)}
+ />
+ {phase === "live" ? (
+ <Btn
+ id="host-stop-share"
+ icon="stop"
+ tone="danger"
+ cap="host.stop"
+ title="host.stop"
+ hint="hint-share-stop"
+ onClick={() => endSharing({ key: "host.stopNotice" })}
+ />
+ ) : phase === "starting" ? (
+ <Btn
+ id="host-cancel-share"
+ icon="x"
+ tone="danger"
+ cap="host.cancelStart"
+ title="host.cancelStart"
+ hint="hint-close"
+ onClick={() => endSharing({ key: "host.startCancelled" })}
+ />
+ ) : null}
+ </div>
<div className="lr-stage-notices" role="status" aria-live="polite">
- {!details?.hasAudio && stream ? (
- <Pill icon="speakerOff" label={t("host.noAudio")} comic="no-audio" />
+ {!details?.hasSourceAudio && stream ? (
+ <Pill icon="speakerOff" label={t("host.noAudio")} comic="no-audio" tone="off" />
) : null}
{hostSfuWarningText ? (
<Pill icon="alert" label={hostSfuWarningText} comic="warning" />
@@ -3439,6 +3620,308 @@ export function HostPage({
motion={noticeValue.comic === "signal-recovering" || noticeValue.comic === "recovering" || noticeValue.comic === "connecting-sfu" ? "progress" : "still"} />
) : null}
</div>
+ <SharingSettings id="host-advanced-door" open={showAdvanced} busy={changingQuality}
+ presets={
+ <QualityPresets selected={selectedQualityProfileId} busy={changingQuality}
+ disabled={phase === "starting" || switchingSource}
+ onSelect={id => void changeQuality({ ...QUALITY_PROFILES[id],
+ screenAudioQuality: resolveScreenAudioQuality(advancedQualityRef.current.screenAudioQuality),
+ })} />
+ }
+ picture={<>
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="expand" size={19} />
+ <Cap k="host.advanced.resolution" />
+ </span>
+ <div
+ className="lr-row-group"
+ role="group"
+ aria-label={t("host.advanced.resolution")}
+ >
+ {(
+ Object.keys(QUALITY_RESOLUTIONS) as QualityResolution[]
+ ).map((resolution) => (
+ <Chip
+ key={resolution}
+ selected={advancedQuality.resolution === resolution}
+ disabled={phase === "starting" || switchingSource}
+ title={QUALITY_RESOLUTIONS[resolution].label}
+ hint="hint-quality"
+ onClick={() =>
+ changeAdvancedQuality({ resolution })
+ }
+ >
+ {QUALITY_RESOLUTIONS[resolution].label}
+ </Chip>
+ ))}
+ </div>
+ </div>
+ <div className="lr-sharing-limits">
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="frames" size={19} />
+ <Cap k="host.advanced.framerate" />
+ </span>
+ <Tooltip kind="hint-metric-fps" text={vis ? undefined : t("host.advanced.framerate")} className="lr-slider-hint">
+ <span className="lr-slider">
+ <input
+ type="range"
+ min={15}
+ max={60}
+ step={5}
+ value={advancedQuality.maxFramerate}
+ disabled={phase === "starting" || switchingSource}
+ aria-label={t("host.advanced.framerate")}
+ onChange={(event) =>
+ changeAdvancedQuality({
+ maxFramerate: Number(event.target.value),
+ })
+ }
+ />
+ <output>{advancedQuality.maxFramerate} fps</output>
+ </span>
+ </Tooltip>
+ </div>
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="gauge" size={19} />
+ <Cap k="host.advanced.bitrate" />
+ </span>
+ <Tooltip kind="hint-metric-bitrate" text={vis ? undefined : t("host.advanced.bitrate")} className="lr-slider-hint">
+ <span className="lr-slider">
+ <input
+ type="range"
+ min={2000000}
+ max={12000000}
+ step={500000}
+ value={advancedQuality.maxBitrate}
+ disabled={phase === "starting" || switchingSource}
+ aria-label={t("host.advanced.bitrate")}
+ onChange={(event) =>
+ changeAdvancedQuality({
+ maxBitrate: Number(event.target.value),
+ })
+ }
+ />
+ <output>
+ {(advancedQuality.maxBitrate / 1_000_000).toFixed(1)}{" "}
+ Mbps
+ </output>
+ </span>
+ </Tooltip>
+ </div>
+ </div>
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="mountain" size={19} />
+ <Cap k="host.advanced.preference" />
+ </span>
+ <div
+ className="lr-row-group"
+ role="group"
+ aria-label={t("host.advanced.preference")}
+ >
+ {(
+ Object.keys(
+ PREFERENCE_PRESENTATION,
+ ) as DegradationPreference[]
+ ).map((preference) => (
+ <Chip
+ key={preference}
+ name="degradationPreference"
+ value={preference}
+ selected={
+ advancedQuality.degradationPreference === preference
+ }
+ disabled={phase === "starting" || switchingSource}
+ title={`${t(DEGRADATION_PREFERENCE_KEYS[preference])} · ${t(PREFERENCE_PRESENTATION[preference].hint)}`}
+ hint={preference === "maintain-resolution" ? "hint-prefer-resolution" : preference === "maintain-framerate" ? "hint-prefer-framerate" : "hint-degrade-pref"}
+ onClick={() =>
+ changeAdvancedQuality({
+ degradationPreference: preference,
+ })
+ }
+ >
+ <Glyph
+ name={PREFERENCE_PRESENTATION[preference].icon}
+ size={18}
+ />
+ <Cap k={DEGRADATION_PREFERENCE_KEYS[preference]} />
+ </Chip>
+ ))}
+ </div>
+ </div>
+ </>}
+ audio={<>
+ {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)}
+ />
+ ) : null}
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="speaker" size={19} />
+ <Cap k="host.advanced.audio" />
+ </span>
+ <div
+ className="lr-row-group"
+ role="group"
+ aria-label={t("host.advanced.audio")}
+ >
+ {(
+ Object.keys(
+ AUDIO_QUALITY_CAPTIONS,
+ ) as ScreenAudioQuality[]
+ ).map((audioQuality) => (
+ <Chip
+ key={audioQuality}
+ selected={
+ resolveScreenAudioQuality(
+ advancedQuality.screenAudioQuality,
+ ) === audioQuality
+ }
+ disabled={phase === "starting" || switchingSource}
+ title={t("host.audio.title", {
+ label: t(AUDIO_QUALITY_CAPTIONS[audioQuality]),
+ kbps: String(
+ SCREEN_AUDIO_BITRATES[audioQuality] / 1_000,
+ ),
+ })}
+ hint="hint-audio-quality"
+ onClick={() => changeScreenAudioQuality(audioQuality)}
+ >
+ <Cap k={AUDIO_QUALITY_CAPTIONS[audioQuality]} />
+ <small className="lr-audio-rate">
+ {SCREEN_AUDIO_BITRATES[audioQuality] / 1_000}
+ </small>
+ </Chip>
+ ))}
+ </div>
+ </div>
+ </>}
+ technical={<>
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="branch" size={19} />
+ <Cap k="host.advanced.route" />
+ </span>
+ <div className="lr-row-group">
+ <SwitchItem
+ checked={routePolicy.topologyOptimization}
+ disabled={phase === "starting" || phase === "live"}
+ onChange={(checked) =>
+ changeRoutePolicy({ topologyOptimization: checked })
+ }
+ label={t("host.advanced.route.topo")}
+ note={t("host.advanced.route.topoHint")}
+ hint="hint-topology"
+ />
+ <SwitchItem
+ checked={routePolicy.natPrediction}
+ disabled={
+ !natPredictionAvailable || phase === "starting" || phase === "live"
+ }
+ locked={!natPredictionAvailable}
+ onChange={(checked) =>
+ changeRoutePolicy({ natPrediction: checked })
+ }
+ label={t("host.advanced.route.natPrediction")}
+ note={t(
+ natPredictionAvailable
+ ? "host.advanced.route.natPredictionHint"
+ : "host.advanced.route.natPredictionUnavailable",
+ )}
+ hint={
+ natPredictionAvailable ? "hint-nat-prediction" : "hint-nat-unavailable"
+ }
+ />
+ <SwitchItem
+ checked={routePolicy.peerOnly}
+ disabled={
+ !sfuAvailable || phase === "starting" || phase === "live"
+ }
+ locked={!sfuAvailable}
+ onChange={(checked) =>
+ changeRoutePolicy({ peerOnly: checked })
+ }
+ label={t("host.advanced.route.peerOnly")}
+ note={t(
+ sfuAvailable
+ ? "host.advanced.route.peerOnlyHint"
+ : "host.advanced.route.peerOnlyRequired",
+ )}
+ hint={sfuAvailable ? "hint-route-p2p" : "hint-route-p2p-required"}
+ />
+ </div>
+ </div>
+ <div className="lr-door-group">
+ <span
+ className="lr-door-glyph"
+ >
+ <Glyph name="puzzle" size={19} />
+ <Cap k="host.advanced.codec" />
+ </span>
+ <div
+ className="lr-row-group"
+ role="group"
+ aria-label={t("host.advanced.codec")}
+ >
+ {(["vp8", "auto", "h264"] as const).map((mode) => (
+ <Chip
+ key={mode}
+ selected={displayedVideoCodecMode === mode}
+ disabled={phase === "starting" || phase === "live"}
+ title={
+ mode === "auto"
+ ? resolvedVideoCodec
+ ? `${t("host.advanced.codec.auto")} · ${resolvedVideoCodec.toUpperCase()}`
+ : `${t("host.advanced.codec.auto")} · ${t("host.advanced.codec.autoHint")}`
+ : `${mode.toUpperCase()} · ${t(
+ mode === "vp8"
+ ? "host.advanced.codec.vp8Hint"
+ : "host.advanced.codec.h264Hint",
+ )}`
+ }
+ hint="hint-codec"
+ onClick={() => changeVideoCodecMode(mode)}
+ >
+ {mode.toUpperCase()}
+ </Chip>
+ ))}
+ </div>
+ </div>
+ </>}
+ />
<Couch
view="host"
host={{
@@ -3566,11 +4049,7 @@ export function HostPage({
<div className="lr-row-group lr-group-actions lr-host-diagnostics-slot">
<Btn
icon="gauge"
- cap={
- showConnectionDetails
- ? "host.details.hide"
- : "host.details"
- }
+ cap="host.details"
title={
showConnectionDetails
? "host.details.hide"
@@ -3600,140 +4079,23 @@ export function HostPage({
onClick={() => setShowTopology((current) => !current)}
/>
</div>
- {phase === "live" || phase === "starting" ? (
- <div className="lr-row-group lr-group-actions lr-host-share-slot">
- {phase === "live" ? (
- <>
- <Btn
- icon={sharingPaused ? "play" : "pause"}
- cap={sharingPaused ? "host.resume" : "host.pause"}
- title={sharingPaused ? "host.resume" : "host.pause"}
- hint={sharingPaused ? "hint-resume" : "hint-pause"}
- draw="host-share-toggle"
- disabled={switchingSource || changingQuality}
- onClick={toggleSharingPause}
- />
- <Btn
- id="host-switch-source"
- icon="switchSource"
- cap={switchingSource ? "host.switching" : "host.switchSource"}
- title="host.switchSource"
- hint="hint-switch-source"
- disabled={switchingSource || changingQuality}
- onClick={() => void switchSource()}
- />
- <Btn
- icon="stop"
- tone="danger"
- cap="host.stop"
- title="host.stop"
- hint="hint-share-stop"
- onClick={() => endSharing({ key: "host.stopNotice" })}
- />
- </>
- ) : (
- <Btn
- id="host-cancel-share"
- icon="x"
- tone="danger"
- cap="host.cancelStart"
- title="host.cancelStart"
- hint="hint-close"
- onClick={() => endSharing({ key: "host.startCancelled" })}
- />
- )}
- </div>
- ) : null}
+
</div>
</Row>
- {showConnectionDetails && details && (stream || nativeActive) ? (
- <Row sub>
- <div id="host-details-panel" style={{ display: "contents" }}>
- <span
- className="lr-meter-tag"
- >
- <Glyph name="share" size={17} />
- {vis ? null : (
- <span className="lr-cap">{t("stats.capture")}</span>
- )}
- </span>
- <div
- className="lr-meter"
- role="group"
- aria-label={t("host.captureAria")}
- >
- <MetricCell label="stats.resolution" value={details.resolution ?? t("stats.unknown")} />
- <MetricCell label="stats.fps" value={details.frameRate ? `${details.frameRate.toFixed(0)} fps` : vis ? "—" : t("host.capture.fpsUnknown")} />
- <MetricCell label="stats.codec" value={resolvedVideoCodec?.toUpperCase() ?? (vis ? "—" : t("host.capture.codecPending"))} />
- <Tooltip toggleOnClick kind={details.hasAudio ? "hint-source-audio" : "no-audio"}
- text={vis ? undefined : t(details.hasAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}
- tone={details.hasAudio ? "off" : "warn"}>
- <button type="button" className="lr-meter-cell"
- style={{ border: 0, color: "inherit", font: "inherit", textAlign: "start" }}
- aria-label={t(details.hasAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}>
- <Glyph name={details.hasAudio ? "speaker" : "speakerOff"} size={16} />
- {!vis && <b>{t(details.hasAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}</b>}
- </button>
- </Tooltip>
- </div>
- </div>
- </Row>
- ) : null}
- {showConnectionDetails && viewerOverviewEntries.length > 0 ? (
- <ViewerOverview
- entries={viewerOverviewEntries}
- selectedKey={selectedPawn}
- onSelect={(peerId) =>
- setSelectedPawn((current) =>
- current === peerId ? null : peerId,
- )
- }
- />
- ) : null}
- {selectedViewer && selectedDetail ? (
- <PawnDetail
- pawnKey={selectedViewer.peerId}
- name={selectedViewer.label}
- route={selectedDetail.route}
- metrics={selectedDetail.metrics}
- direction={selectedDetail.direction}
- tag={selectedDetail.tag}
- error={selectedDetail.error}
- expanded={metricsExpanded}
- onToggleMetrics={setMetricsExpanded}
- onClose={() => setSelectedPawn(null)}
- />
- ) : null}
- {showTopology ? (
- <Row sub>
- <RouteTree
- hostPeerId={hostPeerId}
- hostIdentity={hostIdentity}
- hostLabel={labeledHostPresence?.label ?? displayName}
- viewers={viewers}
- selectedPeerId={selectedPawn}
- onSelectPeer={(peerId) =>
- setSelectedPawn((current) =>
- current === peerId ? null : peerId,
- )
- }
- />
- </Row>
- ) : null}
-
{room ? (
<Row label={t("host.policy")}>
<RowGroup actions>
<Btn
icon={copied ? "check" : "link"}
cap="common.copy"
- title={copied ? "common.copied" : "host.invite.copy"}
- hint="hint-copy-invite"
- hintTone={copied ? "live" : undefined}
+ title={copied ? "common.copied" : roomLinkBlocked ? "host.invite.credentialRequired"
+ : includeInviteCredential ? "host.invite.copy" : "host.invite.copyAddress"}
+ hint={roomLinkBlocked ? "hint-policy-private" : "hint-copy-invite"}
+ hintTone={copied ? "live" : roomLinkBlocked ? "warn" : undefined}
hintMotion={copied ? "still" : undefined}
- disabled={!room.inviteUrl || roomMutating}
- onClick={() => void copyInvite()}
+ disabled={!roomLink || roomMutating || roomLinkBlocked}
+ onClick={() => void copyRoomLink()}
/>
<Btn
icon="refresh"
@@ -3753,20 +4115,35 @@ export function HostPage({
onClick={() => void changeViewerGrant("revoke")}
/>
</RowGroup>
- {room.inviteUrl ? (
- <Tooltip kind="hint-invite-link" text={room.inviteUrl} className="lr-invite-hint">
- <input
- className="lr-invite-url"
- type="text"
- dir="ltr"
- value={room.inviteUrl}
- readOnly
- spellCheck={false}
- aria-label={t("host.invite")}
- onFocus={(event) => event.currentTarget.select()}
- />
- </Tooltip>
- ) : null}
+ <div className="lr-invite-field">
+ {roomLink ? (
+ <Tooltip kind="hint-invite-link" text={roomLink} className="lr-invite-hint">
+ <input
+ className="lr-invite-url"
+ type="text"
+ dir="ltr"
+ value={roomLink}
+ readOnly
+ spellCheck={false}
+ aria-label={t(includeInviteCredential ? "host.invite" : "host.invite.address")}
+ onFocus={(event) => event.currentTarget.select()}
+ />
+ </Tooltip>
+ ) : null}
+ <span className="lr-row-group">
+ <Glyph name="key" size={17} />
+ <SwitchItem checked={includeInviteCredential} disabled={roomMutating}
+ label={t("host.invite.includeCredential")} hint="hint-invite-link"
+ note={t("host.invite.credentialHint")}
+ onChange={checked => {
+ copyRoomLinkRequestRef.current = null;
+ setCopiedRoomLink(null);
+ setIncludeInviteCredential(checked);
+ }} />
+ </span>
+ </div>
+ {roomLinkBlocked ? <Pill icon="lock" tone="warn" comic="hint-policy-private"
+ label={t("host.invite.credentialRequired")} /> : null}
<span className="lr-divider" aria-hidden="true" />
<RowGroup>
<span
@@ -3929,310 +4306,80 @@ export function HostPage({
</Row>
) : null}
- <Row label={t("host.quality")}>
- <RowGroup>
- <QualityPresets selected={selectedQualityProfileId} busy={changingQuality}
- disabled={phase === "starting" || switchingSource}
- onSelect={id => void changeQuality({ ...QUALITY_PROFILES[id],
- screenAudioQuality: resolveScreenAudioQuality(advancedQualityRef.current.screenAudioQuality),
- })} />
- </RowGroup>
- <span className="lr-spacer" />
- {/* Keep the tooltip trigger compact when mobile rows stretch. */}
- <span style={{ display: "flex", justifyContent: "flex-end" }}>
- <Btn
- icon="sliders"
- busy={changingQuality}
- cap="host.advanced"
- title={showAdvanced ? "host.advanced.hide" : "host.advanced"}
- hint={showAdvanced ? "hint-collapse" : "hint-advanced"}
- tone={showAdvanced ? "on" : undefined}
- expanded={showAdvanced}
- controls="host-advanced-door"
- onClick={() => setShowAdvanced((current) => !current)}
- />
- </span>
- </Row>
- <div
- id="host-advanced-door"
- className={`lr-door-reveal${showAdvanced ? " is-open" : ""}`}
- >
- <div>
- {showAdvanced ? (
+ {showConnectionDetails && details && (stream || nativeActive) ? (
+ <Row sub>
+ <div id="host-details-panel" style={{ display: "contents" }}>
+ <span
+ className="lr-meter-tag"
+ >
+ <Glyph name="share" size={17} />
+ {vis ? null : (
+ <span className="lr-cap">{t("stats.capture")}</span>
+ )}
+ </span>
<div
- className="lr-door-body"
+ className="lr-meter"
role="group"
- aria-label={t("host.advanced")}
- aria-busy={changingQuality}
+ aria-label={t("host.captureAria")}
>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="expand" size={19} />
- <Cap k="host.advanced.resolution" />
- </span>
- <div
- className="lr-row-group"
- role="group"
- aria-label={t("host.advanced.resolution")}
- >
- {(
- Object.keys(QUALITY_RESOLUTIONS) as QualityResolution[]
- ).map((resolution) => (
- <Chip
- key={resolution}
- selected={advancedQuality.resolution === resolution}
- disabled={phase === "starting" || switchingSource}
- title={QUALITY_RESOLUTIONS[resolution].label}
- hint="hint-quality"
- onClick={() =>
- changeAdvancedQuality({ resolution })
- }
- >
- {QUALITY_RESOLUTIONS[resolution].label}
- </Chip>
- ))}
- </div>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="frames" size={19} />
- <Cap k="host.advanced.framerate" />
- </span>
- <Tooltip kind="hint-metric-fps" text={vis ? undefined : t("host.advanced.framerate")} className="lr-slider-hint">
- <span className="lr-slider">
- <input
- type="range"
- min={15}
- max={60}
- step={5}
- value={advancedQuality.maxFramerate}
- disabled={phase === "starting" || switchingSource}
- aria-label={t("host.advanced.framerate")}
- onChange={(event) =>
- changeAdvancedQuality({
- maxFramerate: Number(event.target.value),
- })
- }
- />
- <output>{advancedQuality.maxFramerate} fps</output>
- </span>
- </Tooltip>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="gauge" size={19} />
- <Cap k="host.advanced.bitrate" />
- </span>
- <Tooltip kind="hint-metric-bitrate" text={vis ? undefined : t("host.advanced.bitrate")} className="lr-slider-hint">
- <span className="lr-slider">
- <input
- type="range"
- min={2000000}
- max={12000000}
- step={500000}
- value={advancedQuality.maxBitrate}
- disabled={phase === "starting" || switchingSource}
- aria-label={t("host.advanced.bitrate")}
- onChange={(event) =>
- changeAdvancedQuality({
- maxBitrate: Number(event.target.value),
- })
- }
- />
- <output>
- {(advancedQuality.maxBitrate / 1_000_000).toFixed(1)}{" "}
- Mbps
- </output>
- </span>
- </Tooltip>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="mountain" size={19} />
- <Cap k="host.advanced.preference" />
- </span>
- <div
- className="lr-row-group"
- role="group"
- aria-label={t("host.advanced.preference")}
- >
- {(
- Object.keys(
- PREFERENCE_PRESENTATION,
- ) as DegradationPreference[]
- ).map((preference) => (
- <Chip
- key={preference}
- name="degradationPreference"
- value={preference}
- selected={
- advancedQuality.degradationPreference === preference
- }
- disabled={phase === "starting" || switchingSource}
- title={`${t(DEGRADATION_PREFERENCE_KEYS[preference])} · ${t(PREFERENCE_PRESENTATION[preference].hint)}`}
- hint={preference === "maintain-resolution" ? "hint-prefer-resolution" : preference === "maintain-framerate" ? "hint-prefer-framerate" : "hint-degrade-pref"}
- onClick={() =>
- changeAdvancedQuality({
- degradationPreference: preference,
- })
- }
- >
- <Glyph
- name={PREFERENCE_PRESENTATION[preference].icon}
- size={18}
- />
- <Cap k={DEGRADATION_PREFERENCE_KEYS[preference]} />
- </Chip>
- ))}
- </div>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="speaker" size={19} />
- <Cap k="host.advanced.audio" />
- </span>
- <div
- className="lr-row-group"
- role="group"
- aria-label={t("host.advanced.audio")}
- >
- {(
- Object.keys(
- AUDIO_QUALITY_CAPTIONS,
- ) as ScreenAudioQuality[]
- ).map((audioQuality) => (
- <Chip
- key={audioQuality}
- selected={
- resolveScreenAudioQuality(
- advancedQuality.screenAudioQuality,
- ) === audioQuality
- }
- disabled={phase === "starting" || switchingSource}
- title={t("host.audio.title", {
- label: t(AUDIO_QUALITY_CAPTIONS[audioQuality]),
- kbps: String(
- SCREEN_AUDIO_BITRATES[audioQuality] / 1_000,
- ),
- })}
- hint="hint-audio-quality"
- onClick={() => changeScreenAudioQuality(audioQuality)}
- >
- <Cap k={AUDIO_QUALITY_CAPTIONS[audioQuality]} />
- <small className="lr-audio-rate">
- {SCREEN_AUDIO_BITRATES[audioQuality] / 1_000}
- </small>
- </Chip>
- ))}
- </div>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="branch" size={19} />
- <Cap k="host.advanced.route" />
- </span>
- <div className="lr-row-group">
- <SwitchItem
- checked={routePolicy.topologyOptimization}
- disabled={phase === "starting" || phase === "live"}
- onChange={(checked) =>
- changeRoutePolicy({ topologyOptimization: checked })
- }
- label={t("host.advanced.route.topo")}
- note={t("host.advanced.route.topoHint")}
- hint="hint-topology"
- />
- <SwitchItem
- checked={routePolicy.natPrediction}
- disabled={
- !natPredictionAvailable || phase === "starting" || phase === "live"
- }
- locked={!natPredictionAvailable}
- onChange={(checked) =>
- changeRoutePolicy({ natPrediction: checked })
- }
- label={t("host.advanced.route.natPrediction")}
- note={t(
- natPredictionAvailable
- ? "host.advanced.route.natPredictionHint"
- : "host.advanced.route.natPredictionUnavailable",
- )}
- hint={
- natPredictionAvailable ? "hint-nat-prediction" : "hint-nat-unavailable"
- }
- />
- <SwitchItem
- checked={routePolicy.peerOnly}
- disabled={
- !sfuAvailable || phase === "starting" || phase === "live"
- }
- locked={!sfuAvailable}
- onChange={(checked) =>
- changeRoutePolicy({ peerOnly: checked })
- }
- label={t("host.advanced.route.peerOnly")}
- note={t(
- sfuAvailable
- ? "host.advanced.route.peerOnlyHint"
- : "host.advanced.route.peerOnlyRequired",
- )}
- hint={sfuAvailable ? "hint-route-p2p" : "hint-route-p2p-required"}
- />
- </div>
- </div>
- <div className="lr-door-group">
- <span
- className="lr-door-glyph"
- >
- <Glyph name="puzzle" size={19} />
- <Cap k="host.advanced.codec" />
- </span>
- <div
- className="lr-row-group"
- role="group"
- aria-label={t("host.advanced.codec")}
- >
- {(["vp8", "auto", "h264"] as const).map((mode) => (
- <Chip
- key={mode}
- selected={displayedVideoCodecMode === mode}
- disabled={phase === "starting" || phase === "live"}
- title={
- mode === "auto"
- ? resolvedVideoCodec
- ? `${t("host.advanced.codec.auto")} · ${resolvedVideoCodec.toUpperCase()}`
- : `${t("host.advanced.codec.auto")} · ${t("host.advanced.codec.autoHint")}`
- : `${mode.toUpperCase()} · ${t(
- mode === "vp8"
- ? "host.advanced.codec.vp8Hint"
- : "host.advanced.codec.h264Hint",
- )}`
- }
- hint="hint-codec"
- onClick={() => changeVideoCodecMode(mode)}
- >
- {mode.toUpperCase()}
- </Chip>
- ))}
- </div>
- </div>
+ <MetricCell label="stats.resolution" value={details.resolution ?? t("stats.unknown")} />
+ <MetricCell label="stats.fps" value={details.frameRate ? `${details.frameRate.toFixed(0)} fps` : vis ? "—" : t("host.capture.fpsUnknown")} />
+ <MetricCell label="stats.codec" value={resolvedVideoCodec?.toUpperCase() ?? (vis ? "—" : t("host.capture.codecPending"))} />
+ <Tooltip toggleOnClick kind={details.hasSourceAudio ? "hint-source-audio" : "no-audio"}
+ text={vis ? undefined : t(details.hasSourceAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}
+ tone="off">
+ <button type="button" className="lr-meter-cell"
+ style={{ border: 0, color: "inherit", font: "inherit", textAlign: "start" }}
+ aria-label={t(details.hasSourceAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}>
+ <Glyph name={details.hasSourceAudio ? "speaker" : "speakerOff"} size={16} />
+ {!vis && <b>{t(details.hasSourceAudio ? "host.capture.hasAudio" : "host.capture.noAudio")}</b>}
+ </button>
+ </Tooltip>
</div>
- ) : null}
- </div>
- </div>
-
+ </div>
+ </Row>
+ ) : null}
+ {showConnectionDetails && viewerOverviewEntries.length > 0 ? (
+ <ViewerOverview
+ entries={viewerOverviewEntries}
+ selectedKey={selectedPawn}
+ onSelect={(peerId) =>
+ setSelectedPawn((current) =>
+ current === peerId ? null : peerId,
+ )
+ }
+ />
+ ) : null}
+ {selectedViewer && selectedDetail ? (
+ <PawnDetail
+ pawnKey={selectedViewer.peerId}
+ name={selectedViewer.label}
+ route={selectedDetail.route}
+ metrics={selectedDetail.metrics}
+ direction={selectedDetail.direction}
+ tag={selectedDetail.tag}
+ error={selectedDetail.error}
+ expanded={metricsExpanded}
+ onToggleMetrics={setMetricsExpanded}
+ onClose={() => setSelectedPawn(null)}
+ />
+ ) : null}
+ {showTopology ? (
+ <Row sub>
+ <RouteTree
+ hostPeerId={hostPeerId}
+ hostIdentity={hostIdentity}
+ hostLabel={labeledHostPresence?.label ?? displayName}
+ viewers={viewers}
+ selectedPeerId={selectedPawn}
+ onSelectPeer={(peerId) =>
+ setSelectedPawn((current) =>
+ current === peerId ? null : peerId,
+ )
+ }
+ />
+ </Row>
+ ) : null}
</div>
</main>
</div>
diff --git a/src/client/pages/JoinPage.tsx b/src/client/pages/JoinPage.tsx
index 16a829d5..7bec2946 100644
--- a/src/client/pages/JoinPage.tsx
+++ b/src/client/pages/JoinPage.tsx
@@ -50,7 +50,7 @@ export function JoinPage() {
{vis ? null : (
<div className="lr-access-text">
<h1>{t("join.title")}</h1>
- <p>{t("join.hint")}</p>
+ <p className="lr-join-site">{t("join.hint", { site: window.location.host })}</p>
</div>
)}
<RoomCodeInput value={roomId} rejectedAttempt={rejectedAttempt} autoFocus
diff --git a/src/client/pages/TooltipPreviewPage.tsx b/src/client/pages/TooltipPreviewPage.tsx
index 80b6b86d..8ad563d3 100644
--- a/src/client/pages/TooltipPreviewPage.tsx
+++ b/src/client/pages/TooltipPreviewPage.tsx
@@ -74,6 +74,7 @@ export function TooltipPreviewPage() {
<a href="#input-preview">{en ? "Inputs" : "输入与房间号"}</a><a href="#feedback-preview">{en ? "Feedback" : "反馈"}</a>
<a href="#people-preview">{en ? "People & connections" : "人物、沙发与连接图"}</a><a href="#source-preview">{en ? "Source picker" : "画面选择"}</a>
<a href="#playback-preview">{en ? "Playback" : "播放栏"}</a><a href="#comic-preview">{en ? "Tooltips & comics" : "提示与漫画"}</a>
+ <a href="#launcher-preview">{en ? "App launcher" : "模式选择"}</a>
<a href="#hint-admission-code">{en ? "Room entry" : "房间准入"}</a>
<a href="#metrics-preview">{en ? "Metrics" : "连接数据"}</a>
<a href="#welcome-preview">{en ? "Opening lines" : "开场白"}</a>
diff --git a/src/client/pages/ViewerPage.tsx b/src/client/pages/ViewerPage.tsx
index 55637de7..408f5a22 100644
--- a/src/client/pages/ViewerPage.tsx
+++ b/src/client/pages/ViewerPage.tsx
@@ -2119,12 +2119,12 @@ export function ViewerPage({
<div className="lr-join-panel">
<Comic kind={deniedComic} theme="paper" tone={viewerStatus.activity.tone} />
<span className="visually-hidden" role="alert">
- {t(deniedMessageKey)} · {t(deniedHintKey)}
+ {t(deniedMessageKey)} · {t(deniedHintKey, { site: window.location.host })}
</span>
{vis ? null : (
<div className="lr-access-text">
<h1>{t(deniedMessageKey)}</h1>
- <p>{t(deniedHintKey)}</p>
+ <p className="lr-join-site">{t(deniedHintKey, { site: window.location.host })}</p>
</div>
)}
{codeOnlyDenied && (
diff --git a/src/client/sfu/publisher.ts b/src/client/sfu/publisher.ts
index b31e1e6f..ba8fc8a5 100644
--- a/src/client/sfu/publisher.ts
+++ b/src/client/sfu/publisher.ts
@@ -54,6 +54,7 @@ export type SfuPublisherFailureStage =
export class SfuPublisher {
private peer: SfuPeer | null = null;
private video: MediaStreamTrack | null = null;
+ private sourceVideo: MediaStreamTrack | null = null;
private audio: MediaStreamTrack | null = null;
private videoSender: RTCRtpSender | null = null;
private audioSender: RTCRtpSender | null = null;
@@ -144,13 +145,15 @@ export class SfuPublisher {
let video: MediaStreamTrack | null = null;
try {
this.failureStage = "source";
- video = this.ownTrack(cloneSenderVideoTrack(requiredVideo(stream)));
+ const sourceVideo = requiredVideo(stream);
+ video = this.ownTrack(cloneSenderVideoTrack(sourceVideo));
await applyVideoCaptureProfile(video, profile);
if (this.peer !== peer) {
this.releaseTrack(video);
return false;
}
this.video = video;
+ this.sourceVideo = sourceVideo;
this.audio = this.ownTrack(stream.getAudioTracks()[0]?.clone() ?? null);
this.setPaused(this.paused);
const dimensions = video.getSettings();
@@ -223,35 +226,41 @@ export class SfuPublisher {
const audioSender = this.audioSender;
if (!peer || !profile || !previousVideo || !videoSender || !audioSender)
return false;
- const nextVideo = this.ownTrack(
- cloneSenderVideoTrack(requiredVideo(stream)),
- );
+ const sourceVideo = requiredVideo(stream);
+ const videoChanged = sourceVideo !== this.sourceVideo;
+ const nextVideo = videoChanged
+ ? this.ownTrack(cloneSenderVideoTrack(sourceVideo)) : previousVideo;
const nextAudio = this.ownTrack(
stream.getAudioTracks()[0]?.clone() ?? null,
);
let retained = false;
- this.resetStats();
+ const previousStartup = this.startupPending;
+ const previousBaseline = this.startupFramesBaseline;
+ if (videoChanged) this.resetStats();
try {
- await applyVideoCaptureProfile(nextVideo, profile);
+ if (videoChanged) await applyVideoCaptureProfile(nextVideo, profile);
if (this.peer !== peer) return false;
nextVideo.enabled = !this.paused;
if (nextAudio) {
nextAudio.enabled = !this.paused;
nextAudio.contentHint = "music";
}
- await videoSender.replaceTrack(nextVideo);
+ if (videoChanged) await videoSender.replaceTrack(nextVideo);
await audioSender.replaceTrack(nextAudio);
if (this.peer !== peer) return false;
this.video = nextVideo;
this.audio = nextAudio;
- this.startupPending = needsStartupVideoProfile(profile);
- this.startupFramesBaseline = null;
- await this.configure(profile);
+ if (videoChanged) {
+ this.startupPending = needsStartupVideoProfile(profile);
+ this.startupFramesBaseline = null;
+ }
+ await this.configure(profile, videoChanged);
if (this.peer !== peer) return false;
if (!peer.send({ kind: "media", media: this.media(profile) }))
throw new Error("SFU signaling is unavailable");
retained = true;
- this.releaseTrack(previousVideo);
+ this.sourceVideo = sourceVideo;
+ if (videoChanged) this.releaseTrack(previousVideo);
this.releaseTrack(previousAudio);
this.setPaused(this.paused);
return true;
@@ -260,10 +269,14 @@ export class SfuPublisher {
if (this.peer !== peer) return false;
this.video = previousVideo;
this.audio = previousAudio;
+ if (videoChanged) {
+ this.startupPending = previousStartup;
+ this.startupFramesBaseline = previousBaseline;
+ }
try {
- await videoSender.replaceTrack(previousVideo);
+ if (videoChanged) await videoSender.replaceTrack(previousVideo);
await audioSender.replaceTrack(previousAudio);
- await this.configure(profile);
+ await this.configure(profile, videoChanged);
this.videoWarning = { key: "host.fail.sfuSwitch" };
return false;
} catch {
@@ -272,7 +285,7 @@ export class SfuPublisher {
}
} finally {
if (!retained) {
- this.releaseTrack(nextVideo);
+ if (videoChanged) this.releaseTrack(nextVideo);
this.releaseTrack(nextAudio);
}
}
@@ -345,6 +358,7 @@ export class SfuPublisher {
peer?.close();
for (const track of this.ownedTracks) this.releaseTrack(track);
this.video = null;
+ this.sourceVideo = null;
this.audio = null;
this.videoSender = null;
this.audioSender = null;
diff --git a/src/client/styles.css b/src/client/styles.css
index 2468a045..814a0134 100644
--- a/src/client/styles.css
+++ b/src/client/styles.css
@@ -42,6 +42,7 @@
--radius: 16px;
--control-radius: 18px;
--control-edge: color-mix(in srgb, var(--ink) 62%, var(--paper));
+ --control-hover: var(--wall-2);
--control-shadow: 0 3px 0 color-mix(in srgb, var(--ink) 13%, transparent);
--spring: cubic-bezier(.3, 1.45, .45, 1);
--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC",
@@ -55,6 +56,7 @@ html[data-theme="dark"] {
--wall-2: #0e1620;
--ink: #dde8f3;
--paper: #22303e;
+ --control-hover: #2b3d4f;
--frame: #0a111a;
--action: #4a84f2;
--action-deep: #3a70d8;
@@ -483,15 +485,17 @@ body.lr-theater-open .lr-top { visibility: hidden; }
}
.lr-source-picker-refresh { margin-left: auto; }
.lr-source-picker-head > .lr-comic-tip-wrap:has(> .lr-source-picker-refresh) { margin-left: auto; }
-.lr-source-picker-refresh:hover,
-.lr-source-picker-close:hover { background: rgba(255, 255, 255, .1); }
-.lr-source-picker-refresh:active,
-.lr-source-picker-close:active { transform: scale(.92); }
+.lr-source-picker-refresh:is(:hover, :focus-visible):not(:disabled),
+.lr-source-picker-close:is(:hover, :focus-visible):not(:disabled) { background: rgba(255, 255, 255, .1); }
+.lr-source-picker-refresh:active:not(:disabled),
+.lr-source-picker-close:active:not(:disabled) { transform: scale(.92); }
.lr-source-picker-tabs {
display: grid;
- grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 4px;
- border-bottom: 1px solid rgba(223, 232, 242, .35);
+ padding: 4px;
+ border: 1px solid rgba(223, 232, 242, .24);
+ border-radius: 16px;
+ background: rgba(0, 0, 0, .12);
}
.lr-source-picker-tabs > span { min-width: 0; }
.lr-source-picker-tabs button {
@@ -503,7 +507,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }
gap: 7px;
padding: 8px 4px;
border: 0;
- border-bottom: 3px solid transparent;
+ border-radius: 12px;
background: transparent;
color: #9aa8bb;
font-size: 12px;
@@ -511,10 +515,13 @@ body.lr-theater-open .lr-top { visibility: hidden; }
transition: color 120ms ease, background 120ms ease;
}
.lr-source-picker-tabs button svg { flex: 0 0 auto; }
-.lr-source-picker-tabs button:hover { background: rgba(255, 255, 255, .06); }
+@media (max-width: 520px) {
+ .lr-source-picker-tabs button { flex-direction: column; gap: 3px; padding-inline: 0; font-size: 11px; }
+}
+.lr-source-picker-tabs button:is(:hover, :focus-visible):not(:disabled):not([aria-selected="true"]) { background: rgba(255, 255, 255, .1); }
.lr-source-picker-tabs button[aria-selected="true"] {
- border-bottom-color: #9de8bf;
- color: #9de8bf;
+ background: #dfe8f2;
+ color: #22303e;
}
.lr-source-picker-body {
display: flex;
@@ -550,13 +557,13 @@ body.lr-theater-open .lr-top { visibility: hidden; }
text-align: left;
transition: transform 150ms var(--spring), border-color 120ms ease, background 120ms ease;
}
-.lr-source-option:hover,
-.lr-source-option:focus-visible {
+.lr-source-option:is(:hover, :focus-visible):not(:disabled) {
border-color: var(--action);
background: rgba(47, 111, 237, .2);
transform: translateY(-2px);
}
-.lr-source-option:active { transform: scale(.98); }
+.lr-source-option:active:not(:disabled) { transform: scale(.98); }
+.lr-source-option[aria-current="true"] { border-color: #dfe8f2; background: rgba(223, 232, 242, .18); }
.lr-source-option:not(.is-browser) {
display: grid;
align-items: stretch;
@@ -587,8 +594,7 @@ body.lr-theater-open .lr-top { visibility: hidden; }
}
.lr-source-option-preview {
width: 100%;
- aspect-ratio: 16 / 9;
- height: auto;
+ height: 144px;
overflow: hidden;
border-radius: 8px;
background: rgba(255, 255, 255, .1);
@@ -791,8 +797,8 @@ body.lr-theater-open .lr-top { visibility: hidden; }
align-items: center;
gap: 12px;
padding: 15px 18px;
- border: 2.5px solid var(--ink);
- border-radius: var(--radius);
+ border: 1px solid var(--control-edge);
+ border-radius: 24px;
background: var(--paper);
}
.lr-row.is-sub { background: var(--wall-2); border-color: transparent; }
@@ -807,10 +813,8 @@ body.lr-theater-open .lr-top { visibility: hidden; }
gap: 8px;
}
.lr-host-identity-slot,
-.lr-host-diagnostics-slot,
-.lr-host-share-slot { flex: 0 0 auto; }
-.lr-host-diagnostics-slot,
-.lr-host-share-slot {
+.lr-host-diagnostics-slot { flex: 0 0 auto; }
+.lr-host-diagnostics-slot {
padding-inline-start: 10px;
border-inline-start: 2.5px solid var(--wall-2);
}
@@ -879,6 +883,10 @@ html[data-theme="dark"] .lr-viewer-host-slot svg { color: #9bb0c5; }
.lr-source-option-hint > .lr-source-option { width: 100%; height: 100%; }
.lr-invite-hint { width: 100%; min-width: 0; max-width: 340px; flex: 1 1 240px; }
.lr-invite-hint > .lr-invite-url { width: 100%; }
+.lr-invite-field { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; flex: 1 1 360px; min-width: 0; }
+.lr-invite-field > .lr-invite-hint { flex: 1 1 180px; max-width: none; }
+.lr-invite-field .lr-invite-url { max-width: none; }
+.lr-invite-field > .lr-row-group { flex: none; width: auto; }
.lr-spacer { flex: 1; }
.lr-divider { width: 2.5px; align-self: stretch; border-radius: 2px; background: var(--wall-2); }
.lr-row.is-sub .lr-divider { background: #c3d4cb; }
@@ -955,7 +963,7 @@ html[data-theme="dark"] .lr-invite-url { background: #1a2634; border-color: #334
transition: transform 260ms var(--spring), background-color 140ms ease, border-color 140ms ease;
}
.lr-btn:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]) { transform: translateY(-2px); }
-.lr-btn:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]):not(.is-primary):not(.is-on):not(.is-danger) { background: var(--wall-2); border-color: var(--ink); }
+.lr-btn:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]):not(.is-primary):not(.is-on):not(.is-danger) { background: var(--control-hover); border-color: var(--ink); }
.lr-btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(2px) scale(.95); box-shadow: none; transition-duration: 80ms; }
.lr-btn.is-primary { border-color: var(--action-deep); background: var(--action-deep); color: #fff; }
.lr-btn.is-primary:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]) { background: color-mix(in srgb, var(--action-deep) 88%, #000); }
@@ -965,6 +973,14 @@ html[data-theme="dark"] .lr-invite-url { background: #1a2634; border-color: #334
.lr-btn .lr-cap { margin-left: 2px; font-size: 12.5px; font-weight: 600; }
.lr-cap { font-size: 12.5px; font-weight: 600; color: inherit; white-space: nowrap; }
+/* Sharing and local playback have distinct owners, but one control grammar. */
+:where(.lr-media-controls) .lr-btn {
+ min-width: 44px; height: 44px; padding: 0 12px;
+ border: 0; border-radius: 12px; box-shadow: none;
+ background: transparent; color: inherit;
+}
+.lr-media-controls .lr-btn.is-danger { color: var(--danger); }
+
/* Diagnostics stay quiet until explicitly enabled; keep the shared input feedback. */
.lr-header-diagnostic { display: inline-flex; }
.lr-header-diagnostic .lr-btn { min-width: 40px; width: 40px; height: 40px; padding: 0; box-shadow: none; }
@@ -992,6 +1008,7 @@ html[data-theme="dark"] .lr-invite-url { background: #1a2634; border-color: #334
.lr-chip .lr-cap { font-family: var(--font); letter-spacing: 0; }
.lr-chip small { margin-left: 5px; font-size: 10.5px; opacity: .6; }
.lr-chip .lr-audio-rate {
+ opacity: .85;
min-width: 3ch;
margin-left: 0;
text-align: center;
@@ -1131,6 +1148,7 @@ html[data-theme="dark"] .lr-invite-url { background: #1a2634; border-color: #334
.lr-welcome-cipher i { width: 3px; height: 3px; background: #d7982b; transform: rotate(45deg); }
.lr-tv-overlay > .lr-welcome { position: absolute; top: clamp(20px, 3vw, 32px); left: 18px; right: 18px; width: auto; font-size: clamp(13px, 1.5vw, 16px); }
.lr-tv-overlay:has(> .lr-join-panel) > .lr-welcome { display: none; }
+.lr-tv-overlay:has(> .lr-join-panel) { position: relative; grid-template-columns: minmax(0, 1fr); }
.lr-welcome-catalog { margin-block: 0 24px; }
.lr-welcome-catalog summary { cursor: pointer; width: fit-content; padding-block: 12px; font-weight: 650; }
.lr-welcome-catalog ol { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 12px 32px; padding-inline-start: 28px; }
@@ -1519,14 +1537,21 @@ html[data-theme="dark"] .lr-door-glyph { color: #7d92a8; }
.lr-client-lan-option strong { font-size: 13px; overflow-wrap: anywhere; }
.lr-client-lan-option small { font: 12px var(--mono); }
.lr-client-lan-option:has(:focus-visible) { outline: 3px solid var(--action); outline-offset: 1px; }
-/* Only the wrapped access field spans the panel width; a wrapped pill or
- button keeps its own size so the grid can center it. */
-.lr-client-launch-panel > .lr-comic-tip-wrap:has(> .lr-client-access) {
- width: min(460px, 100%);
-}
-.lr-client-launch-panel > .lr-comic-tip-wrap > .lr-client-access {
- width: 100%;
-}
+.lr-client-access-options { width: min(460px, 100%); min-width: 0; }
+.lr-client-access-options > summary {
+ display: flex; align-items: center; justify-content: center; gap: 8px;
+ width: fit-content; max-width: 100%; min-height: 40px; margin: 0 auto; padding: 8px 12px;
+ border-radius: 12px; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
+ list-style: none; transition: background-color 140ms ease, color 140ms ease;
+}
+.lr-client-access-options > summary::-webkit-details-marker { display: none; }
+.lr-client-access-options > summary:is(:hover, :focus-visible) { background: var(--control-hover); color: var(--ink); }
+.lr-client-access-options > summary:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
+.lr-client-access-options > summary > svg:last-child { transition: transform 160ms ease; }
+.lr-client-access-options[open] > summary > svg:last-child { transform: rotate(180deg); }
+.lr-client-access-set { display: inline-flex; align-items: center; gap: 4px; color: var(--ink); }
+.lr-client-access-options .lr-client-access { width: 100%; margin-top: 8px; }
+.lr-client-access-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.lr-join {
flex: 1;
@@ -1536,12 +1561,14 @@ html[data-theme="dark"] .lr-door-glyph { color: #7d92a8; }
}
.lr-join-panel {
display: grid;
+ grid-template-columns: minmax(0, 1fr);
width: 100%;
min-width: 0;
max-width: 100%;
justify-items: center;
gap: 20px;
}
+.lr-join-site { max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: center; }
.lr-join-door { color: var(--ink); }
.lr-dials-wrap.is-shake { animation: lr-shake .4s ease; }
@keyframes lr-shake {
@@ -1550,7 +1577,7 @@ html[data-theme="dark"] .lr-door-glyph { color: #7d92a8; }
50% { transform: translateX(6px); }
75% { transform: translateX(-4px); }
}
-.lr-dials-wrap { position: relative; }
+.lr-dials-wrap { position: relative; max-width: 100%; }
.lr-dials-wrap:focus-within { outline: 3px solid var(--action); outline-offset: 2px; border-radius: 14px; }
.lr-dials { display: flex; gap: 12px; }
.lr-dial {
@@ -1648,7 +1675,6 @@ html[data-theme="dark"] .lr-join-go:disabled { background: #1a2634; color: #4860
/* ---------- dark theme refinements ---------- */
-html[data-theme="dark"] .lr-btn:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]):not(.is-primary):not(.is-on):not(.is-danger) { background: #2b3d4f; }
html[data-theme="dark"] .lr-btn.is-on { background: var(--ink); color: #22303e; }
html[data-theme="dark"] .lr-btn.is-danger:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]) { background: #3d2626; }
html[data-theme="dark"] .lr-chip:is(:hover, :focus-visible):not(:disabled):not([aria-disabled="true"]):not(.is-selected),
@@ -1700,8 +1726,7 @@ html[data-theme="dark"] .lr-switch::after { background: var(--ink); }
margin-left: 0;
}
.lr-host-identity-slot,
- .lr-host-diagnostics-slot,
- .lr-host-share-slot { width: 100%; }
+ .lr-host-diagnostics-slot { width: 100%; }
.lr-viewer-personal-controls {
width: 100%;
margin-left: 0;
@@ -1718,7 +1743,6 @@ html[data-theme="dark"] .lr-switch::after { background: var(--ink); }
.lr-input.lr-name-editor { width: min(136px, 40vw); }
.lr-group-actions { display: flex; width: 100%; gap: 8px; min-width: 0; }
.lr-host-diagnostics-slot,
- .lr-host-share-slot,
.lr-viewer-actions-slot {
padding-inline-start: 0;
border-inline-start: 0;
@@ -1735,6 +1759,7 @@ html[data-theme="dark"] .lr-switch::after { background: var(--ink); }
.lr-viewer-self-slot .lr-name-tag { flex: 0 1 auto; }
.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; }
.lr-dial { width: 54px; height: 66px; font-size: 28px; }
.lr-tv-screen.has-entry { aspect-ratio: auto; min-height: 292px; }
@@ -1760,6 +1785,78 @@ html[data-theme="dark"] .lr-switch::after { background: var(--ink); }
margin: 10px auto 0;
}
.lr-stage-notices:empty { display: none; }
+.lr-sharing-settings { width: min(820px, 100%); margin: 0 auto; }
+.lr-sharing-panel {
+ margin-top: 14px; padding: 22px; background: var(--paper);
+ border: 1px solid var(--control-edge); border-radius: 24px; box-shadow: var(--control-shadow);
+ animation: lr-sharing-enter 180ms ease-out;
+}
+.lr-sharing-columns { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 28px; }
+.lr-sharing-section { display: grid; align-content: start; gap: 18px; min-width: 0; }
+.lr-sharing-section + .lr-sharing-section { padding-inline-start: 24px; border-inline-start: 1px solid var(--wall-2); }
+.lr-sharing-section h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
+.lr-sharing-section .lr-door-group { gap: 8px; }
+.lr-sharing-panel .lr-sharing-section .lr-door-glyph { color: var(--muted); }
+.lr-sharing-section .lr-door-glyph .lr-cap { white-space: normal; }
+.lr-sharing-limits { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
+.lr-sharing-panel .lr-slider { width: 100%; }
+.lr-sharing-panel .lr-slider output { min-width: 5ch; }
+.lr-sharing-section .lr-tiles { gap: 8px; }
+.lr-sharing-section .lr-tiles > .lr-comic-tip-wrap { flex: 1; min-width: 0; }
+.lr-sharing-section .lr-tile { width: 100%; min-width: 0; padding: 8px 5px; gap: 2px; border-radius: 14px; }
+.lr-sharing-section .lr-tile > svg { height: 28px; }
+.lr-sharing-section .lr-slider input { width: 100%; min-width: 0; }
+.lr-sharing-section .lr-row-group { gap: 7px; }
+.lr-sharing-section .lr-chip { min-height: 38px; padding: 7px 11px; }
+.lr-sharing-technical { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--wall-2); }
+.lr-sharing-technical > summary { width: fit-content; padding: 7px 3px; color: var(--muted); cursor: pointer; font-size: 12px; }
+.lr-sharing-technical > summary > svg { vertical-align: middle; margin-inline-end: 6px; }
+.lr-sharing-technical > div { display: grid; gap: 18px; padding-top: 16px; }
+@keyframes lr-sharing-enter { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
+@media (prefers-reduced-motion: reduce) { .lr-sharing-panel { animation: none; } }
+@media (max-width: 680px) {
+ .lr-sharing-panel { padding: 16px; border-radius: 20px; }
+ .lr-sharing-columns { grid-template-columns: 1fr; gap: 22px; }
+ .lr-sharing-limits { grid-template-columns: 1fr; }
+ .lr-sharing-section + .lr-sharing-section { padding: 20px 0 0; border-inline-start: 0; border-top: 1px solid var(--wall-2); }
+}
+.lr-host-share-controls {
+ display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px;
+ width: fit-content; max-width: 100%; margin: 12px auto 0; padding: 6px;
+ background: var(--paper); color: var(--ink); border: 1px solid var(--control-edge);
+ border-radius: 20px; box-shadow: 0 3px 0 color-mix(in srgb, var(--ink) 8%, transparent);
+}
+.lr-host-share-controls > .lr-comic-tip-wrap:has(#host-stop-share) { margin-inline-start: 4px; padding-inline-start: 8px; border-inline-start: 1px solid var(--control-edge); }
+.lr-microphone-settings { min-width: 0; max-width: 440px; gap: 6px; }
+.lr-microphone-settings .lr-capture-device { padding: 0; }
+.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-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-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;
+ border: 1px solid var(--control-edge); border-radius: 12px;
+ background: var(--wall); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer;
+ transition: background-color 140ms ease, border-color 140ms ease;
+}
+.lr-capture-device select:is(:hover, :focus-visible):not(:disabled) { background: var(--control-hover); border-color: var(--ink); }
+.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 { color: var(--muted); font-size: 11px; line-height: 1.5; }
+.lr-source-picker-body > .lr-capture-device { margin-bottom: 10px; }
+.lr-source-picker .lr-capture-device :is(label, small) { color: #9aa8bb; }
+@media (max-width: 580px) {
+ .lr-host-share-controls { gap: 2px; }
+ .lr-host-share-controls .lr-btn { width: 44px; padding: 0; }
+ .lr-host-share-controls .lr-cap { display: none; }
+ .lr-host-share-controls .lr-btn[aria-controls] { width: auto; min-width: 44px; height: auto; min-height: 44px; grid-auto-flow: row; gap: 2px; padding: 4px 8px; }
+ .lr-host-share-controls .lr-btn[aria-controls] .lr-cap { display: inline; max-width: 9ch; white-space: normal; font-size: 11px; line-height: 1.3; text-align: center; }
+}
.lr-room.is-theater .lr-stage-notices {
position: absolute;
z-index: 3;
@@ -1999,7 +2096,7 @@ svg[data-comic-motion="still"] .lr-person-eyes > ellipse {
transition-duration: 0.01ms !important;
}
.lr-tv-static { animation: none; opacity: .35; }
- .lr-btn, .lr-chip, .lr-tile, .lr-client-mode, .lr-toggle button, .lr-lang > button, .lr-language-menu button { transform: none !important; }
+ .lr-btn, .lr-chip, .lr-tile, .lr-client-mode, .lr-toggle button, .lr-lang > button, .lr-language-menu button, .lr-source-option, .lr-source-picker-refresh, .lr-source-picker-close { transform: none !important; }
.lr-route-edge.is-pending { animation: none; }
}
diff --git a/src/client/ui/icons.tsx b/src/client/ui/icons.tsx
index 2d2372a3..225eedd3 100644
--- a/src/client/ui/icons.tsx
+++ b/src/client/ui/icons.tsx
@@ -10,6 +10,9 @@ import { useEffect, useRef, type ReactNode } from "react";
import { bindSvgReplayOnPointerEnter } from "./animation";
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"/></>) },
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"/></>) },
diff --git a/src/client/ui/visual-kinds.ts b/src/client/ui/visual-kinds.ts
index 65638769..50bac2df 100644
--- a/src/client/ui/visual-kinds.ts
+++ b/src/client/ui/visual-kinds.ts
@@ -51,6 +51,10 @@ export type Set1Kind =
| "hint-switch-source"
| "hint-reconnect"
| "hint-capture-browser"
+ | "hint-capture-camera"
+ | "hint-microphone-on"
+ | "hint-microphone-off"
+ | "hint-microphone-volume"
| "hint-capture-window"
| "hint-capture-display";
diff --git a/src/client/webrtc/host-peer.ts b/src/client/webrtc/host-peer.ts
index d7d61850..bd7f674c 100644
--- a/src/client/webrtc/host-peer.ts
+++ b/src/client/webrtc/host-peer.ts
@@ -233,7 +233,8 @@ export class HostPeer {
return false;
}
- const nextVideoTrack = cloneSenderVideoTrack(nextSourceVideoTrack);
+ const videoChanged = this.stream.getVideoTracks()[0] !== nextSourceVideoTrack;
+ const nextVideoTrack = videoChanged ? cloneSenderVideoTrack(nextSourceVideoTrack) : previousVideoTrack;
let retainedNextVideoTrack = false;
const nextAudioTrack = nextStream.getAudioTracks()[0] ?? null;
const nextAudioDirection = nextAudioTrack ? "sendonly" : "inactive";
@@ -244,19 +245,21 @@ export class HostPeer {
this.replacementAudioTrack = nextAudioTrack;
this.applyPausedState(nextVideoTrack, nextAudioTrack);
const previousAudioTrack = audioSender.track;
- this.statsSamplingBlocked = true;
- this.statsAccumulator = createStatsAccumulator();
+ if (videoChanged) {
+ this.statsSamplingBlocked = true;
+ this.statsAccumulator = createStatsAccumulator();
+ }
try {
try {
- await videoSender.replaceTrack(nextVideoTrack);
+ if (videoChanged) await videoSender.replaceTrack(nextVideoTrack);
await audioSender.replaceTrack(nextAudioTrack);
if (audioDirectionChanged) {
audioTransceiver.direction = nextAudioDirection;
}
} catch (error) {
const [videoRollback] = await Promise.allSettled([
- videoSender.replaceTrack(previousVideoTrack),
+ videoChanged ? videoSender.replaceTrack(previousVideoTrack) : Promise.resolve(),
audioSender.replaceTrack(previousAudioTrack),
]);
if (audioDirectionChanged) {
@@ -276,34 +279,36 @@ export class HostPeer {
this.senderVideoTrack = nextVideoTrack;
this.stream = nextStream;
retainedNextVideoTrack = true;
- this.pooledVideo?.dispose();
- this.pooledVideo = null;
- this.attachVideoPool(nextSourceVideoTrack);
- if (previousVideoTrack !== this.encodedOutput?.track) previousVideoTrack.stop();
- this.startupVideoProfilePending = needsStartupVideoProfile(
- this.desiredProfile,
- );
- this.startupFramesBaseline = null;
- this.snapshot = { ...this.snapshot, metrics: { ...EMPTY_METRICS } };
+ if (videoChanged) {
+ this.pooledVideo?.dispose();
+ this.pooledVideo = null;
+ this.attachVideoPool(nextSourceVideoTrack);
+ if (previousVideoTrack !== this.encodedOutput?.track) previousVideoTrack.stop();
+ this.startupVideoProfilePending = needsStartupVideoProfile(this.desiredProfile);
+ this.startupFramesBaseline = null;
+ this.snapshot = { ...this.snapshot, metrics: { ...EMPTY_METRICS } };
+ }
await this.configureSender(videoSender, audioSender, {
profile: startupVideoProfile(this.desiredProfile),
profileRevision: this.profileRevision,
- video: this.connection.connectionState === "connected",
+ video: videoChanged && this.connection.connectionState === "connected",
audio: true,
});
this.snapshot = { ...this.snapshot, error: null };
this.emit();
return !audioDirectionChanged || (await this.createOffer(false));
} finally {
- if (!retainedNextVideoTrack) {
+ if (videoChanged && !retainedNextVideoTrack) {
nextVideoTrack.stop();
}
if (this.replacementVideoTrack === nextVideoTrack) {
this.replacementVideoTrack = null;
this.replacementAudioTrack = null;
}
- this.statsAccumulator = createStatsAccumulator();
- this.statsSamplingBlocked = false;
+ if (videoChanged) {
+ this.statsAccumulator = createStatsAccumulator();
+ this.statsSamplingBlocked = false;
+ }
}
});
}
diff --git a/tests/browser-gate-harness.test.ts b/tests/browser-gate-harness.test.ts
new file mode 100644
index 00000000..f9919cd4
--- /dev/null
+++ b/tests/browser-gate-harness.test.ts
@@ -0,0 +1,8 @@
+import { expect, it } from "vitest";
+import { join } from "node:path";
+import { launchChrome } from "../scripts/browser-gate-harness";
+
+it("reports a missing browser executable through awaited startup", async () => {
+ await expect(launchChrome(join(import.meta.dirname, "missing-browser.exe"), 9222,
+ join(import.meta.dirname, "unused-profile"))).rejects.toMatchObject({ code: "ENOENT" });
+});
diff --git a/tests/camera-previews.test.ts b/tests/camera-previews.test.ts
new file mode 100644
index 00000000..b2019ab4
--- /dev/null
+++ b/tests/camera-previews.test.ts
@@ -0,0 +1,125 @@
+import { afterEach, expect, test, vi } from "vitest";
+import { loadCameraPreviews, type CameraPreview } from "../src/client/media/camera-previews";
+
+function setup({ permission = true, frames = true } = {}) {
+ const tracks: { id: string; readyState: string; stop: ReturnType<typeof vi.fn> }[] = [];
+ const videos: Video[] = [];
+ const devices = ["front", "rear"].map(id => ({ kind: "videoinput", deviceId: id, label: `${id} camera` }));
+ const enumerateDevices = vi.fn(async () => permission ? devices : []);
+ const stream = (id: string) => {
+ const track = { id, kind: "video", label: `${id} camera`, readyState: "live",
+ getSettings: () => ({ deviceId: id }), stop: vi.fn(() => { track.readyState = "ended"; }) };
+ tracks.push(track);
+ return { getTracks: () => [track], getVideoTracks: () => [track] } as unknown as MediaStream;
+ };
+ const getUserMedia = vi.fn(async (options: MediaStreamConstraints) => {
+ expect(options.audio).toBe(false);
+ expect(tracks.filter(track => track.readyState === "live")).toHaveLength(0);
+ permission = true;
+ const id = (options.video as MediaTrackConstraints).deviceId as ConstrainDOMStringParameters | undefined;
+ return stream(id?.exact as string ?? "rear");
+ });
+ class Video extends EventTarget {
+ muted = false;
+ playsInline = false;
+ srcObject: MediaStream | null = null;
+ readyState = 0;
+ videoWidth = 1920;
+ videoHeight = 1080;
+ pause = vi.fn();
+ play = vi.fn(async () => {
+ if (frames) { this.readyState = 2; this.dispatchEvent(new Event("loadeddata")); }
+ });
+ }
+ const createElement = vi.fn((tag: string) => {
+ if (tag === "video") { const video = new Video(); videos.push(video); return video; }
+ return { width: 0, height: 0, getContext: () => ({ drawImage: vi.fn() }), toDataURL: () => "data:image/jpeg;preview" };
+ });
+ vi.stubGlobal("navigator", { mediaDevices: { getUserMedia, enumerateDevices } });
+ vi.stubGlobal("document", { createElement });
+ const publish = vi.fn<(sources: CameraPreview[]) => void>();
+ return { tracks, videos, devices, stream, getUserMedia, enumerateDevices, createElement, publish };
+}
+
+afterEach(() => { vi.unstubAllGlobals(); vi.useRealTimers(); });
+
+test("camera thumbnails use serial video-only inputs and release every input", async () => {
+ const { tracks, videos, publish, getUserMedia } = setup();
+ await loadCameraPreviews(new AbortController().signal, publish);
+ expect(getUserMedia).toHaveBeenCalledTimes(2);
+ expect(tracks.every(track => track.stop.mock.calls.length === 1)).toBe(true);
+ expect(videos.every(video => video.muted && video.playsInline && video.srcObject === null)).toBe(true);
+ expect(publish.mock.lastCall?.[0].every(source => !!source.preview)).toBe(true);
+ // Earlier renders are immutable while later thumbnails arrive.
+ expect(publish.mock.calls[0]![0].every(source => source.preview === null)).toBe(true);
+});
+
+test("permission bootstrap retains its first frame without reopening that camera", async () => {
+ const { tracks, publish, getUserMedia } = setup({ permission: false });
+ await loadCameraPreviews(new AbortController().signal, publish);
+ expect(getUserMedia).toHaveBeenCalledTimes(2);
+ expect(tracks.map(track => track.id)).toEqual(["rear", "front"]);
+ expect(publish.mock.lastCall?.[0].map(source => source.id)).toEqual(["front", "rear"]);
+ expect(tracks.every(track => track.readyState === "ended")).toBe(true);
+});
+
+test("late permission results after cancellation are stopped and never published", async () => {
+ const { getUserMedia, stream, tracks, publish } = setup({ permission: false });
+ let grant!: (value: MediaStream) => void;
+ getUserMedia.mockImplementationOnce(() => new Promise(resolve => { grant = resolve; }));
+ const request = new AbortController();
+ const pending = loadCameraPreviews(request.signal, publish);
+ const cancelled = expect(pending).rejects.toMatchObject({ name: "AbortError" });
+ await vi.waitFor(() => expect(grant).toBeDefined());
+ request.abort();
+ grant(stream("late"));
+ await cancelled;
+ expect(tracks[0]!.stop).toHaveBeenCalledOnce();
+ expect(publish).not.toHaveBeenCalled();
+});
+
+test("cancelling a frame wait immediately releases it and never opens the next camera", async () => {
+ const { tracks, videos, publish, getUserMedia } = setup({ frames: false });
+ const request = new AbortController();
+ const pending = loadCameraPreviews(request.signal, publish);
+ const cancelled = expect(pending).rejects.toMatchObject({ name: "AbortError" });
+ await vi.waitFor(() => expect(videos).toHaveLength(1));
+ const published = publish.mock.calls.length;
+ request.abort();
+ expect(tracks[0]!.stop).toHaveBeenCalledOnce();
+ await cancelled;
+ expect(getUserMedia).toHaveBeenCalledOnce();
+ expect(publish).toHaveBeenCalledTimes(published);
+ expect(videos[0]!.srcObject).toBeNull();
+});
+
+test("an active camera is borrowed without opening or stopping any camera", async () => {
+ const { stream, getUserMedia, publish, tracks } = setup();
+ const active = { srcObject: stream("front"), readyState: 2, videoWidth: 1280, videoHeight: 720 } as HTMLVideoElement;
+ await loadCameraPreviews(new AbortController().signal, publish, active);
+ expect(getUserMedia).not.toHaveBeenCalled();
+ expect(tracks[0]!.stop).not.toHaveBeenCalled();
+ expect(publish.mock.lastCall?.[0].map(source => !!source.preview)).toEqual([true, false]);
+});
+
+test("a busy camera keeps its identity and does not suppress other choices", async () => {
+ const { publish, tracks, getUserMedia } = setup();
+ getUserMedia.mockRejectedValueOnce(new DOMException("Busy", "NotReadableError"));
+ await loadCameraPreviews(new AbortController().signal, publish);
+ expect(publish.mock.lastCall?.[0].map(source => [source.id, !!source.preview])).toEqual([["front", false], ["rear", true]]);
+ expect(tracks[0]!.stop).toHaveBeenCalledOnce();
+});
+
+test("missing frames are bounded and an already cancelled picker requests nothing", async () => {
+ vi.useFakeTimers();
+ const { videos, tracks, getUserMedia, publish } = setup({ frames: false });
+ const pending = loadCameraPreviews(new AbortController().signal, publish);
+ await vi.runAllTimersAsync();
+ await pending;
+ expect(tracks.every(track => track.readyState === "ended")).toBe(true);
+ expect(videos.every(video => video.srcObject === null)).toBe(true);
+ getUserMedia.mockClear();
+ const request = new AbortController(); request.abort();
+ await expect(loadCameraPreviews(request.signal, publish)).rejects.toMatchObject({ name: "AbortError" });
+ expect(getUserMedia).not.toHaveBeenCalled();
+});
diff --git a/tests/copy.test.ts b/tests/copy.test.ts
index 41d81170..3e4002ce 100644
--- a/tests/copy.test.ts
+++ b/tests/copy.test.ts
@@ -73,9 +73,9 @@ describe("copy catalog", () => {
expect(t("en", "join.title")).toBe("Join a room");
expect(t("zh", "host.advanced.route.peerOnly")).toBe("隐私模式");
expect(t("en", "host.advanced.route.peerOnly")).toBe("Privacy mode");
- expect(t("zh", "host.advanced.route.natPrediction")).toBe("NAT 穿透");
+ expect(t("zh", "host.advanced.route.natPrediction")).toBe("NAT 穿透增强");
expect(t("en", "host.advanced.route.natPrediction")).toBe(
- "NAT traversal",
+ "Enhanced NAT traversal",
);
expect(isCopyKey("viewer.reconnect")).toBe(true);
expect(isCopyKey("Reconnect media")).toBe(false);
diff --git a/tests/host-audio.test.ts b/tests/host-audio.test.ts
new file mode 100644
index 00000000..954e3df5
--- /dev/null
+++ b/tests/host-audio.test.ts
@@ -0,0 +1,191 @@
+import { afterEach, expect, test, vi } from "vitest";
+import { HostAudio } from "../src/client/media/host-audio";
+import { captureBrowserSource, QUALITY_PROFILES } from "../src/client/media/quality";
+
+class Track {
+ enabled = true;
+ readyState = "live";
+ onended: (() => void) | null = null;
+ constructor(readonly kind: string) {}
+ stop = vi.fn(() => { this.readyState = "ended"; });
+}
+class Stream {
+ constructor(private tracks: Track[]) {}
+ getTracks() { return this.tracks; }
+ getAudioTracks() { return this.tracks.filter((track) => track.kind === "audio"); }
+ getVideoTracks() { return this.tracks.filter((track) => track.kind === "video"); }
+}
+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 };
+}
+afterEach(() => vi.unstubAllGlobals());
+
+test("camera is a bounded video source and never implicitly requests a microphone", async () => {
+ const { getUserMedia } = setup();
+ const video = new Track("video");
+ const source = media(video);
+ getUserMedia.mockResolvedValue(source);
+ expect(await captureBrowserSource(QUALITY_PROFILES["1080p30"], "camera")).toBe(source);
+ expect(getUserMedia).toHaveBeenCalledWith({ audio: false, video: {
+ facingMode: { ideal: "environment" }, width: { ideal: 1920 }, height: { ideal: 1080 },
+ frameRate: { ideal: 30, max: 30 },
+ } });
+});
+
+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")));
+ await captureBrowserSource(QUALITY_PROFILES["1080p30"], "camera", "front-camera");
+ expect(getUserMedia).toHaveBeenCalledWith({ audio: false, video: expect.objectContaining({ deviceId: { exact: "front-camera" } }) });
+ expect(getUserMedia.mock.calls[0][0].video).not.toHaveProperty("facingMode");
+});
diff --git a/tests/host-peer-tracks.test.ts b/tests/host-peer-tracks.test.ts
index 5295fd52..bf6fb98a 100644
--- a/tests/host-peer-tracks.test.ts
+++ b/tests/host-peer-tracks.test.ts
@@ -862,6 +862,30 @@ describe("HostPeer source replacement", () => {
expect(nextSenderVideo?.stop).toHaveBeenCalledOnce();
});
+ it.each([false, true])("keeps the video sender and quality when only audio changes (failure=%s)", async (fail) => {
+ const video = createTrack("video", "same-video");
+ const peer = createPeer(createStream(video, null));
+ await peer.start();
+ await acceptPeerAnswer(peer);
+ const connection = FakePeerConnection.latest!;
+ const videoSender = connection.senders[0]!;
+ const audioSender = connection.senders[1]!;
+ const clone = videoSender.track!;
+ const parametersBefore = videoSender.setParameters.mock.calls.length;
+ const offersBefore = connection.createOfferCallCount;
+ audioSender.failNextReplace = fail;
+ const audio = createTrack("audio", "mixed-audio");
+ expect(await peer.replaceStream(createStream(video, audio))).toBe(!fail);
+ expect(videoSender.replaceTrack).not.toHaveBeenCalled();
+ expect(videoSender.setParameters).toHaveBeenCalledTimes(parametersBefore);
+ expect(videoSender.track).toBe(clone);
+ expect(clone.stop).not.toHaveBeenCalled();
+ expect(video.clone).toHaveBeenCalledOnce();
+ expect(audioSender.track).toBe(fail ? null : audio);
+ expect(connection.createOfferCallCount).toBe(offersBefore + (fail ? 0 : 1));
+ peer.dispose();
+ });
+
it("keeps capture controls on the sender-owned video clone", async () => {
const sourceVideo = createConfiguredVideoTrack(
"capture-video",
diff --git a/tests/host-quality-ownership.test.ts b/tests/host-quality-ownership.test.ts
index aa030bc6..af0ccb81 100644
--- a/tests/host-quality-ownership.test.ts
+++ b/tests/host-quality-ownership.test.ts
@@ -18,12 +18,12 @@ const source = ts.createSourceFile("HostPage.tsx", readFileSync(
new URL("../src/client/pages/HostPage.tsx", import.meta.url), "utf8",
), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const owners = new Set(["changeQuality", "commitQuality", "handleSignalMessage",
- "switchNativeSource", "finishSourceSwitch", "recoverBrowserFanout", "disposeNativeShare",
+ "switchSource", "watchCaptureEnd", "switchNativeSource", "finishSourceSwitch", "replaceBrowserStream", "recoverBrowserFanout", "disposeNativeShare",
"acquireNativeClient", "requestSharing", "startNativeShare", "startBrowserNativeIngress",
"ownNativeClient", "discardNativeClient", "releaseUnusedNativeClient", "closeCaptureSourcePicker",
"openCaptureSourcePicker", "startBrowserShareFromPicker", "startNativeShareFromPicker",
- "startSharing", "beginRoomMutation", "finishRoomMutation",
- "startPeer", "reconcileHostChildren", "setNotice", "setNoticeKey", "setNoticeError", "setNoticeErrorKey", "endSharing", "copyInvite", "isCurrentRoomAuthority"]);
+ "startSharing", "beginRoomMutation", "finishRoomMutation", "setCaptureError", "changeMicrophone", "toggleSharingPause",
+ "startPeer", "reconcileHostChildren", "setNotice", "setNoticeKey", "setNoticeError", "setNoticeErrorKey", "endSharing", "copyRoomLink", "isCurrentRoomAuthority"]);
const functions: string[] = [];
function collect(node: ts.Node): void {
if (ts.isFunctionDeclaration(node) && node.name && owners.has(node.name.text)) {
@@ -59,13 +59,14 @@ function fixture(launchedByClient = true) {
isConnected: vi.fn(() => true) };
const client = { updateShare: vi.fn(async () => undefined), replaceShareSource: vi.fn(async () => undefined),
startShare: vi.fn(async (): Promise<{ audio: boolean; codec: "h264" }> => ({ audio: false, codec: "h264" })),
+ onEvent: vi.fn((_listener: (event: unknown) => void) => () => undefined),
close: vi.fn(), onClose: vi.fn(() => () => undefined),
health: { nativeMedia: { video: true, hardwareH264: true, softwareVP8: true } },
captureOptions: vi.fn(async () => []), sources: vi.fn(async () => []),
stopReceive: vi.fn(async () => undefined), stopShare: vi.fn(async () => undefined) };
const route = { updateProfile: vi.fn(async () => true), resyncAuthoritative: vi.fn(async (): Promise<void> => undefined) };
const state = {
- debugError, debugEvent, debugOperation, NativeCompatibilityError, isCapturePermissionFailure,
+ debugError, debugEvent, debugOperation, NativeCompatibilityError, isCapturePermissionFailure, DOMException,
launchedByClient, NativeClient: { connect: vi.fn(async (): Promise<typeof client | null> => null) },
nativeClientConnectRef: ref<Promise<typeof client | null> | null>(null),
ownNativeClient: vi.fn(), setJoiningRoom: vi.fn(), startSharing: vi.fn(), openCaptureSourcePicker: vi.fn(),
@@ -77,14 +78,16 @@ function fixture(launchedByClient = true) {
setNativeSources: vi.fn(), setShowCaptureBorder: vi.fn(), defaultNativeCapturePath: () => ({ adapterIndex: 0, encoderIndex: 0 }),
roomMutationRef: ref<object | null>(null), setRoomMutation: vi.fn(),
generationRef: ref(0), shareGenerationRef: ref<string | null>("share"), createOpaqueId: () => "share",
- setCopiedInviteUrl: vi.fn(), setPhase: vi.fn(), roomInitializationRef: ref(Promise.resolve()), roomRef: ref(null),
+ setCopiedRoomLink: vi.fn(), setPhase: vi.fn(), roomInitializationRef: ref(Promise.resolve()), roomRef: ref(null),
createRoom: vi.fn(async () => { throw new Error("must not create an empty room"); }),
readPreferredRoomId: () => null, disposeResources: vi.fn(), ApiError: class extends Error {},
NativeMediaBridge: vi.fn(), manualVideoCodecPreference: vi.fn(),
phase: "live", qualitySettingsRef: ref<QualitySettings>(original), advancedQualityRef: ref<QualitySettings>(original),
qualityChangeRef: ref<object | null>(null), pendingQualityChangeRef: 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), setMicrophoneEnabled: vi.fn(),
nativeModeRef: ref(false), nativeClientRef: ref<typeof client | null>(client), nativeShareGenerationRef: ref<string | null>("share"),
+ hostAudioRef: ref<{ sourceStream: MediaStream } | null>(null),
nativeMediaIngressRef: ref<ReturnType<typeof ingress> | null>(null), nativeMediaBridgeRef: ref(null),
nativeEventCleanupRef: ref(null), nativeShareCleanupRef: ref(Promise.resolve()),
peersRef: ref(new Map([["viewer", peer]])), hostProvisionalChildRef: ref(null), hostSfuRouteRef: ref(route),
@@ -140,13 +143,62 @@ function fixture(launchedByClient = true) {
};
}
-describe("Host invite copy feedback", () => {
- function copyFixture() {
+describe("Camera replacement ownership", () => {
+ it("keeps a screen Stop authoritative while a camera picker is pending", async () => {
+ const current = fixture();
+ let ended!: () => void;
+ const track = { readyState: "live", addEventListener: (_event: string, callback: () => void) => { ended = callback; } };
+ const previous = { getVideoTracks: () => [track] };
+ const pending = deferred<unknown>();
+ const endSharing = vi.fn(() => { current.context.sourceSwitchRef.current = null; });
+ Object.assign(current.context, {
+ streamRef: ref(previous), captureBrowserSource: () => pending.promise,
+ closeCaptureSourcePicker: vi.fn(), hostAudioRef: ref({ sourceKind: "browser" }), endSharing,
+ });
+ current.context.watchCaptureEnd(previous, 1);
+ const switching = current.context.switchSource("camera", "second");
+ track.readyState = "ended";
+ ended();
+ expect(endSharing).toHaveBeenCalledOnce();
+ const stop = vi.fn();
+ pending.resolve({ getTracks: () => [{ stop }] });
+ await switching;
+ expect(stop).toHaveBeenCalledOnce();
+ });
+ it.each(["success", "failed-live", "failed-ended"])("owns old camera retirement while switching: %s", async outcome => {
+ const current = fixture();
+ let ended!: () => void;
+ const track = { readyState: "live", addEventListener: (_event: string, callback: () => void) => { ended = callback; } };
+ const previous = { getVideoTracks: () => [track] };
+ const replacement = { getTracks: () => [], getVideoTracks: () => [{ readyState: "live" }] };
+ const pending = deferred<unknown>();
+ const endSharing = vi.fn(), replaceBrowserStream = vi.fn(async () => {}), setCaptureError = vi.fn();
+ Object.assign(current.context, {
+ streamRef: ref(previous), captureBrowserSource: () => pending.promise, closeCaptureSourcePicker: vi.fn(),
+ hostAudioRef: ref({ sourceKind: "camera", attach: (stream: unknown) => stream }),
+ endSharing, replaceBrowserStream, setCaptureError, setCameraDevice: vi.fn(),
+ });
+ current.context.watchCaptureEnd(previous, 1);
+ const switching = current.context.switchSource("camera", "second");
+ if (outcome !== "failed-live") { track.readyState = "ended"; ended(); }
+ expect(endSharing).not.toHaveBeenCalled();
+ if (outcome === "success") pending.resolve(replacement);
+ else pending.reject(new Error("camera unavailable"));
+ await switching;
+ expect(replaceBrowserStream).toHaveBeenCalledTimes(outcome === "success" ? 1 : 0);
+ expect(endSharing).toHaveBeenCalledTimes(outcome === "failed-ended" ? 1 : 0);
+ expect(setCaptureError).toHaveBeenCalledTimes(outcome === "failed-live" ? 1 : 0);
+ });
+});
+
+describe("Host room-link copy feedback", () => {
+ function copyFixture(includeInviteCredential = true) {
const current = fixture();
let copiedUrl: string | null = null;
let notice: unknown = null;
- current.setCopiedInviteUrl.mockImplementation((next: string | null) => { copiedUrl = next; });
- const room = { roomId: "1234", hostToken: "host-token", inviteUrl: "https://example.test/r/1234#v=example" };
+ current.setCopiedRoomLink.mockImplementation((next: string | null) => { copiedUrl = next; });
+ const room = { roomId: "1234", hostToken: "host-token", inviteUrl: "https://example.test/r/1234#v=example",
+ canonicalUrl: "https://example.test/r/1234" };
Object.assign(current.roomRef, { current: room });
current.setNoticeValue.mockImplementation((next: unknown) => {
notice = typeof next === "function" ? next(notice) : next;
@@ -156,14 +208,31 @@ describe("Host invite copy feedback", () => {
navigator: { clipboard: { writeText } },
copiedResetTimerRef: ref<number | null>(null),
- copyInviteRequestRef: ref<object | null>(null),
+ copyRoomLinkRequestRef: ref<object | null>(null),
+ includeInviteCredential, roomLinkBlocked: false, roomMutating: false,
window: { setTimeout: vi.fn(() => 1), clearTimeout: vi.fn() },
});
- return { ...current, writeText, copied: () => copiedUrl !== null && copiedUrl === current.context.roomRef.current?.inviteUrl,
+ return { ...current, writeText, copied: () => copiedUrl !== null && copiedUrl === (current.context.includeInviteCredential
+ ? current.context.roomRef.current?.inviteUrl : current.context.roomRef.current?.canonicalUrl),
replaceInvite: (inviteUrl: string | null) => { current.context.roomRef.current = { ...room, inviteUrl }; }, notice: () => notice,
- copy: current.context.copyInvite as () => Promise<void> };
+ copy: current.context.copyRoomLink as () => Promise<void> };
}
+ it("copies the canonical room URL when password-free invitation is off", async () => {
+ const current = copyFixture(false);
+ await current.copy();
+ expect(current.writeText).toHaveBeenCalledWith("https://example.test/r/1234");
+ expect(current.copied()).toBe(true);
+ });
+
+ it("does not copy a plain link that cannot admit a Viewer", async () => {
+ const current = copyFixture(false);
+ current.context.roomLinkBlocked = true;
+ await current.copy();
+ expect(current.writeText).not.toHaveBeenCalled();
+ expect(current.copied()).toBe(false);
+ });
+
it("clears an earlier success when the next copy fails", async () => {
const current = copyFixture();
await current.copy();
@@ -232,6 +301,35 @@ describe("Host invite copy feedback", () => {
});
describe("Host quality ownership", () => {
+ it.each([true, false])("resumes the former raw audio input only after an accepted mixed-output resume: %s", (accepted) => {
+ const current = fixture(false);
+ const source = {} as MediaStream;
+ current.hostAudioRef.current = { sourceStream: source };
+ current.peersRef.current.clear();
+ current.context.hostSfuRouteRef.current = null;
+ const setMediaPaused = vi.fn(() => true);
+ Object.assign(current.context, {
+ sharingPausedRef: ref(true), setSharingPaused: vi.fn(), setMediaPaused,
+ signalRef: ref({ setSharingPaused: () => accepted, confirmSharingPaused: vi.fn() }),
+ setNoticeErrorKey: vi.fn(),
+ });
+ current.context.toggleSharingPause();
+ expect(setMediaPaused).toHaveBeenCalledWith(current.streamRef.current, false);
+ if (accepted) expect(setMediaPaused).toHaveBeenCalledWith(source, false);
+ else {
+ expect(setMediaPaused).not.toHaveBeenCalledWith(source, false);
+ expect(setMediaPaused).toHaveBeenLastCalledWith(current.streamRef.current, true);
+ }
+ });
+ it("refreshes source details from the capture input after microphone mixing", async () => {
+ const current = fixture(false);
+ const source = {} as MediaStream;
+ current.hostAudioRef.current = { sourceStream: source };
+ const captureDetails = vi.fn(() => ({}));
+ current.context.captureDetails = captureDetails;
+ await current.change(lower);
+ expect(captureDetails).toHaveBeenCalledWith(source);
+ });
it.each([false, true])("remembers the border preference and passes it to native capture: replacing %s", async (replacing) => {
const current = fixture();
current.context.phase = replacing ? "live" : "idle";
@@ -262,7 +360,7 @@ describe("Host quality ownership", () => {
current.nativeShareGenerationRef.current = null;
const denied = new DOMException("cancelled", "NotAllowedError");
const capture = vi.fn(async () => { throw denied; });
- current.context.captureDisplay = capture;
+ current.context.captureBrowserSource = capture;
current.client.startShare.mockRejectedValue(denied);
await current.openPicker();
current.context.nativeSources = current.setNativeSources.mock.calls.at(-1)![0];
@@ -315,7 +413,7 @@ describe("Host quality ownership", () => {
Object.assign(current.context, {
phase: "idle", setNoticeValue, setNoticeError: current.writeNoticeError,
readableError: hostActionErrorNotice,
- captureDisplay: vi.fn(async () => { throw denied; }),
+ captureBrowserSource: vi.fn(async () => { throw denied; }),
});
current.activeGenerationRef.current = null;
current.nativeShareGenerationRef.current = null;
@@ -330,6 +428,64 @@ describe("Host quality ownership", () => {
expect(current.roomMutationRef.current).toBeNull();
});
+ it.each(["camera", "browser"])("keeps a rejected %s source change out of healthy media status", (source) => {
+ const current = fixture();
+ current.context.setCaptureError(new DOMException("denied", "NotAllowedError"), source, "source");
+ expect(current.setNoticeValue).toHaveBeenLastCalledWith(expect.objectContaining({ target: "operation", tone: "warn" }));
+ expect(current.setPhase).not.toHaveBeenCalled();
+ expect(current.track.stop).not.toHaveBeenCalled();
+ });
+
+ 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("keeps a rejected source change as operation feedback while the current share stays live", async () => {
const current = fixture();
const denied = new DOMException("private capture detail", "NotAllowedError");
@@ -394,12 +550,14 @@ describe("Host quality ownership", () => {
expect(createPeer).toHaveBeenCalledOnce();
});
- it("keeps Browser capture immediate and App selection reachable after absent discovery", async () => {
+ it("opens the same source picker for Browser and App without probing localhost on the Browser path", async () => {
const browser = fixture(false);
browser.nativeClientRef.current = null;
browser.requestShare();
- expect(browser.startSharing).toHaveBeenCalledWith({ kind: "browser" });
- expect(browser.openCaptureSourcePicker).not.toHaveBeenCalled();
+ expect(browser.startSharing).not.toHaveBeenCalled();
+ expect(browser.openCaptureSourcePicker).toHaveBeenCalledOnce();
+ await browser.openPicker();
+ expect(browser.setNativeSources).toHaveBeenLastCalledWith({ kind: "browser" });
expect(browser.NativeClient.connect).not.toHaveBeenCalled();
const current = fixture();
@@ -425,6 +583,7 @@ describe("Host quality ownership", () => {
it("shows App incompatibility in the picker and clears it on a successful refresh", async () => {
const current = fixture();
+ current.context.phase = "idle";
current.nativeClientRef.current = null;
current.nativeShareGenerationRef.current = null;
current.NativeClient.connect.mockRejectedValueOnce(new NativeCompatibilityError(8));
@@ -442,28 +601,33 @@ describe("Host quality ownership", () => {
it("distinguishes absent App, missing capture capability, incompatible codec and an empty source list", async () => {
const absent = fixture();
+ absent.context.phase = "idle";
absent.nativeClientRef.current = null;
await absent.openPicker();
expect(absent.setNativeSources).toHaveBeenLastCalledWith({ kind: "unavailable" });
const unsupported = fixture();
+ unsupported.context.phase = "idle";
unsupported.client.health.nativeMedia.video = false;
await unsupported.openPicker();
expect(unsupported.setNativeSources).toHaveBeenLastCalledWith({ kind: "unsupported" });
expect(unsupported.client.sources).not.toHaveBeenCalled();
const codec = fixture();
+ codec.context.phase = "idle";
codec.context.defaultNativeCapturePath = () => null;
await codec.openPicker();
expect(codec.setNativeSources).toHaveBeenLastCalledWith({ kind: "unsupported" });
const empty = fixture();
+ empty.context.phase = "idle";
await empty.openPicker();
expect(empty.setNativeSources).toHaveBeenLastCalledWith(expect.objectContaining({ kind: "ready", sources: [] }));
});
it("reports listing failure separately and reconnects on refresh", async () => {
const current = fixture();
+ current.context.phase = "idle";
current.nativeShareGenerationRef.current = null;
current.client.sources.mockRejectedValueOnce(new Error("capture helper exited"));
await current.openPicker();
@@ -479,6 +643,7 @@ describe("Host quality ownership", () => {
it("keeps a live Native share when source enumeration fails", async () => {
const current = fixture();
+ current.nativeModeRef.current = true;
current.client.sources.mockRejectedValueOnce(new Error("list failed"));
await current.openPicker();
expect(current.setNativeSources).toHaveBeenLastCalledWith({ kind: "failed" });
@@ -489,6 +654,7 @@ describe("Host quality ownership", () => {
it("ignores a cancelled discovery mismatch after another picker owns a compatible App", async () => {
const current = fixture();
+ current.context.phase = "idle";
current.nativeClientRef.current = null;
current.nativeShareGenerationRef.current = null;
const discovery = deferred<void>();
@@ -533,6 +699,7 @@ describe("Host quality ownership", () => {
it("retires discovery after picker cancellation and allows a later attempt", async () => {
const current = fixture();
+ current.context.phase = "idle";
current.nativeClientRef.current = null;
current.nativeShareGenerationRef.current = null;
const discovery = deferred<typeof current.client>();
@@ -554,7 +721,7 @@ describe("Host quality ownership", () => {
expect(replacement.close).toHaveBeenCalledOnce();
});
- it("retires a cancelled start ACK before publishing codec or bridge state", async () => {
+ it("retires a cancelled start ACK before publishing audio, codec or bridge state", async () => {
const current = fixture();
current.nativeShareGenerationRef.current = null;
const started = deferred<{ audio: boolean; codec: "h264" }>();
@@ -565,6 +732,7 @@ describe("Host quality ownership", () => {
started.resolve({ audio: false, codec: "h264" });
await expect(starting).resolves.toBeNull();
expect(current.client.stopShare).toHaveBeenCalledWith("share");
+ expect(current.nativeSourceAudioRef.current).toBeUndefined();
expect(current.manualVideoCodecPreference).not.toHaveBeenCalled();
expect(current.NativeMediaBridge).not.toHaveBeenCalled();
expect(current.setNativeActive).not.toHaveBeenCalled();
@@ -572,6 +740,7 @@ describe("Host quality ownership", () => {
it("ignores a stale listing failure after a newer picker owns the App", async () => {
const current = fixture();
+ current.context.phase = "idle";
current.nativeShareGenerationRef.current = null;
const listing = deferred<never>();
current.client.sources.mockReturnValueOnce(listing.promise.then(() => { throw new Error("old listing failed"); }));
diff --git a/tests/native-capture-selection.test.ts b/tests/native-capture-selection.test.ts
index d9083eb2..c8782a02 100644
--- a/tests/native-capture-selection.test.ts
+++ b/tests/native-capture-selection.test.ts
@@ -71,24 +71,32 @@ describe("native capture source selection", () => {
onPreview: async () => null, onRefresh: () => {}, onCancel: () => {},
};
const nativeTab = renderToStaticMarkup(createElement(CaptureSourcePicker, props));
+ if (kind === "unavailable") {
+ expect(nativeTab).not.toContain('data-source-tab="window"');
+ expect(nativeTab).not.toContain('data-source-tab="display"');
+ expect(nativeTab).toMatch(/data-source-tab="browser"[^>]*aria-selected="true"/);
+ }
expect(nativeTab.replaceAll("&#x27;", "'")).toContain(t(lang, `host.sourcePicker.${kind}`));
expect(nativeTab).not.toContain(t(lang, "host.sourcePicker.empty"));
expect(nativeTab).not.toMatch(/class="lr-source-picker-refresh"[^>]*disabled=""/);
const browserTab = renderToStaticMarkup(createElement(CaptureSourcePicker, { ...props, initialTab: "browser" }));
expect(browserTab).toContain(`aria-label="${t(lang, "host.sourcePicker.browser")}"`);
- expect(browserTab).not.toContain(t(lang, `host.sourcePicker.${kind}`));
+ const browserCopy = browserTab.replaceAll("&#x27;", "'");
+ if (kind === "unavailable") expect(browserCopy).toContain(t(lang, "host.sourcePicker.unavailable"));
+ else expect(browserCopy).not.toContain(t(lang, `host.sourcePicker.${kind}`));
expect(browserTab).not.toMatch(/class="lr-source-option is-browser"[^>]*disabled=""/);
}
});
- it.each(["browser", "window"] as const)("only adds waiting copy to the pending %s source list", initialTab => {
+ it.each(["browser", "window"] as const)("keeps Browser and Camera reachable during discovery with initial %s preference", initialTab => {
setCopy({ lang: "en", vis: false });
const html = renderToStaticMarkup(createElement(CaptureSourcePicker, {
nativeSources: { kind: "loading" }, initialTab,
onBrowser: () => {}, onNative: () => {}, onPreview: async () => null,
onRefresh: () => {}, onCancel: () => {},
}));
- expect(html.includes('class="lr-waiting-caption"')).toBe(initialTab === "window");
+ expect(html).toMatch(/data-source-tab="browser"[^>]*aria-selected="true"/);
+ expect(html).not.toContain('data-source-tab="window"');
expect(html).not.toContain("lr-brand-loader");
expect(html).not.toMatch(/class="lr-source-picker-close"[^>]*disabled=""/);
});
@@ -113,7 +121,33 @@ describe("native capture source selection", () => {
expect(html).toMatch(/data-source-tab="browser"[^>]*disabled=""/);
expect(html).toMatch(/data-native-source="window:1:10:123456"[^>]*disabled=""/);
expect(html).not.toContain('data-native-source="display:2"');
- expect(html.match(/role="tab"/g)).toHaveLength(3);
+ expect(html.match(/role="tab"/g)).toHaveLength(4);
+ expect([...html.matchAll(/data-source-tab="([^"]+)"/g)].map((match) => match[1]))
+ .toEqual(["browser", "camera", "window", "display"]);
+ expect(html).toMatch(/data-source-tab="window"[^>]*aria-selected="true"/);
+ });
+
+ it("offers only Browser and Camera without an App, defaulting to Browser", () => {
+ setCopy({ lang: "en", vis: false });
+ const html = renderToStaticMarkup(createElement(CaptureSourcePicker, {
+ nativeSources: { kind: "browser" }, onBrowser: () => {}, onCamera: () => {},
+ onNative: () => {}, onPreview: async () => null, onRefresh: () => {}, onCancel: () => {},
+ }));
+ expect([...html.matchAll(/data-source-tab="([^"]+)"/g)].map((match) => match[1]))
+ .toEqual(["browser", "camera"]);
+ expect(html).toMatch(/data-source-tab="browser"[^>]*aria-selected="true"/);
+ expect(html).not.toMatch(/data-source-tab="camera"[^>]*disabled=""/);
+ expect(html).not.toContain(t("en", "host.sourcePicker.unavailable"));
+ });
+
+ it("selects a focusable Camera tab when Browser sharing is unavailable", () => {
+ const html = renderToStaticMarkup(createElement(CaptureSourcePicker, {
+ nativeSources: { kind: "browser" }, browserAvailable: false,
+ onBrowser: () => {}, onCamera: () => {}, onNative: () => {},
+ onPreview: async () => null, onRefresh: () => {}, onCancel: () => {},
+ }));
+ expect(html).toMatch(/data-source-tab="camera"[^>]*aria-selected="true"[^>]*tabindex="0"/);
+ expect(html).toMatch(/data-source-tab="browser"[^>]*tabindex="-1"[^>]*disabled=""/);
});
it("retains the platform-owned combined source picker", () => {
diff --git a/tests/native-client.test.ts b/tests/native-client.test.ts
index 4eb3448c..ed81a8e7 100644
--- a/tests/native-client.test.ts
+++ b/tests/native-client.test.ts
@@ -356,11 +356,11 @@ describe("native App private wire", () => {
})).toEqual({
...health, nativeMedia: {
receiverReuse: false,
- video: true, processAudio: false, systemAudio: false, captureBorderControl: false, hardwareH264: false, softwareVP8: false,
+ video: true, processAudio: false, systemAudio: false, microphone: false, captureBorderControl: false, hardwareH264: false, softwareVP8: false,
},
});
expect(nativeHealthSchema.parse({ ...health, nativeMedia: undefined }).nativeMedia)
- .toEqual({ receiverReuse: false, video: false, processAudio: false, systemAudio: false, captureBorderControl: false, hardwareH264: false, softwareVP8: false });
+ .toEqual({ receiverReuse: false, video: false, processAudio: false, systemAudio: false, microphone: false, captureBorderControl: false, hardwareH264: false, softwareVP8: false });
for (const invalid of [
{ protocol: 0 }, { protocol: 9.5 }, { protocol: Number.MAX_SAFE_INTEGER + 1 },
{ service: "other" }, { port: NATIVE_CLIENT_PORT_END + 1 }, { instanceToken: "short" },
@@ -424,6 +424,70 @@ describe("native App private wire", () => {
} finally { client!.close(); }
});
+ it.each([false, true])("gates microphone mixing and coalesces volume without delaying Stop (%s)", async (supported) => {
+ const requests: Record<string, unknown>[] = [];
+ let socket!: Socket;
+ class Socket extends EventTarget {
+ static readonly OPEN = 1;
+ static readonly CLOSING = 2;
+ readyState = Socket.OPEN;
+ protocol = `piik-client-v9.${health.instanceToken}`;
+ constructor() { super(); socket = this; queueMicrotask(() => this.dispatchEvent(new Event("open"))); }
+ close() { this.readyState = Socket.CLOSING; }
+ ack(request: Record<string, unknown>, type: string, fields = {}) {
+ this.dispatchEvent(new MessageEvent("message", { data: JSON.stringify({ version: 9, id: request.id, type, ...fields }) }));
+ }
+ send(payload: string) {
+ const request = JSON.parse(payload) as Record<string, unknown>;
+ requests.push(request);
+ if (request.type === "set-microphone") return;
+ if (request.type === "list-microphones") {
+ queueMicrotask(() => this.ack(request, "microphone-list", { devices: [{ id: "headset", label: "USB Headset" }] }));
+ return;
+ }
+ queueMicrotask(() => this.ack(request,
+ request.type === "hello" ? "ready" : request.type === "start-share" ? "share-started" : "share-stopped",
+ request.type === "start-share" ? { shareId: request.shareId, audio: supported, codec: "vp8", ...(supported ? { sourceAudio: false } : {}) } : {}));
+ }
+ }
+ vi.stubGlobal("WebSocket", Socket);
+ vi.stubGlobal("window", { setTimeout, clearTimeout });
+ vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({
+ ...health, nativeMedia: { ...health.nativeMedia, ...(supported ? { microphone: true } : {}) },
+ }))));
+ const client = (await NativeClient.connect())!;
+ try {
+ const started = await client.startShare({ shareId: "share_123456", audio: false,
+ source: { kind: "display", sourceId: "1", title: "Screen" }, adapterIndex: 0, encoderIndex: 0,
+ edgeCapacity: 1, profile: DEFAULT_QUALITY_SETTINGS, codec: "vp8" });
+ expect(requests.at(-1)?.microphoneMixing).toBe(supported ? true : undefined);
+ expect(started.audio).toBe(supported);
+ if (!supported) {
+ await expect(client.setMicrophone("share_123456", true, 1)).rejects.toThrow();
+ await expect(client.microphones()).rejects.toThrow();
+ expect(requests.some(request => request.type === "set-microphone")).toBe(false);
+ return;
+ }
+ expect(await client.microphones()).toEqual([{ id: "headset", label: "USB Headset" }]);
+ const choosing = client.setMicrophone("share_123456", true, 1, "headset");
+ expect(requests.at(-1)).toMatchObject({ type: "set-microphone", deviceId: "headset", enabled: true });
+ socket.ack(requests.at(-1)!, "microphone-set");
+ await choosing;
+ requests.length = 0;
+ const pending = client.setMicrophoneVolume("share_123456", 0.1);
+ for (let value = 2; value <= 20; value++) expect(client.setMicrophoneVolume("share_123456", value / 10)).toBe(pending);
+ expect(requests.filter(request => request.type === "set-microphone")).toHaveLength(1);
+ socket.ack(requests.at(-1)!, "microphone-set");
+ await vi.waitFor(() => expect(requests.at(-1)?.volume).toBe(2));
+ const last = requests.at(-1)!;
+ expect(last).not.toHaveProperty("enabled");
+ await client.stopShare("share_123456");
+ socket.ack(last, "microphone-set");
+ await pending;
+ expect(requests.at(-1)?.type).toBe("stop-share");
+ } finally { client.close(); }
+ });
+
it.each([false, true])("requests receiver reuse only from a capable App (%s)", async (supported) => {
const requests: Record<string, unknown>[] = [];
class Socket extends EventTarget {
diff --git a/tests/release-automation.test.ts b/tests/release-automation.test.ts
index 077c5ab3..ee367b1b 100644
--- a/tests/release-automation.test.ts
+++ b/tests/release-automation.test.ts
@@ -61,7 +61,7 @@ describe("release automation", () => {
expect(() => releaseNotes(root, "v1.1.1", invalid, "fixture/Piik")).toThrow("one nonempty");
}
} finally { rmSync(root, { recursive: true, force: true }); }
- });
+ }, 15_000); // Real Git subprocesses share the runner with the rest of the suite.
it("plans from immutable tags and all unreleased main changes without editing version files", () => {
const root = mkdtempSync(join(tmpdir(), "piik-release-plan-"));
diff --git a/tests/sfu-client.test.ts b/tests/sfu-client.test.ts
index 5fa51793..9311826b 100644
--- a/tests/sfu-client.test.ts
+++ b/tests/sfu-client.test.ts
@@ -322,6 +322,56 @@ describe("embedded SFU browser transport", () => {
expect(pc.createOffer).toHaveBeenCalledOnce();
});
+ it.each([false, true])("keeps established SFU video through audio-only addition and removal (initial audio=%s)", async (audio) => {
+ const { publisher: host, pc, video, send } = await publisher(audio);
+ const sender = pc.transceivers[0]!.sender;
+ const ownedVideo = video.clones[0]!;
+ feedVideoStats(pc, ownedVideo.id, 6);
+ await vi.advanceTimersByTimeAsync(2_000);
+ expect(sender.parameters.degradationPreference).toBe("balanced");
+ const parameters = sender.setParameters.mock.calls.length;
+ const constraints = ownedVideo.applyConstraints.mock.calls.length;
+ const voice = new FakeTrack("audio");
+ for (const tracks of [[voice], []]) {
+ expect(await host.replaceStream(stream(video, ...tracks))).toBe(true);
+ expect(sender.track).toBe(ownedVideo);
+ expect(sender.replaceTrack).not.toHaveBeenCalled();
+ expect(sender.setParameters).toHaveBeenCalledTimes(parameters);
+ expect(ownedVideo.applyConstraints).toHaveBeenCalledTimes(constraints);
+ expect(ownedVideo.stop).not.toHaveBeenCalled();
+ expect(sender.parameters.degradationPreference).toBe("balanced");
+ expect(send).toHaveBeenLastCalledWith(expect.objectContaining({ kind: "media", media: expect.objectContaining({ audio: tracks.length > 0 }) }));
+ }
+ expect(video.clones).toHaveLength(1);
+ expect(pc.createOffer).toHaveBeenCalledOnce();
+ expect(voice.clones[0]!.stop).toHaveBeenCalledOnce();
+ await host.disconnect();
+ expect(ownedVideo.stop).toHaveBeenCalledOnce();
+ expect(video.stop).not.toHaveBeenCalled();
+ });
+
+ it("rolls back a rejected audio-only update without mutating the video", async () => {
+ const { publisher: host, pc, video, sound, send } = await publisher();
+ const videoSender = pc.transceivers[0]!.sender;
+ const audioSender = pc.transceivers[1]!.sender;
+ const ownedVideo = video.clones[0]!;
+ const previousAudio = sound.clones[0]!;
+ feedVideoStats(pc, ownedVideo.id, 6);
+ await vi.advanceTimersByTimeAsync(2_000);
+ const parameters = videoSender.setParameters.mock.calls.length;
+ const voice = new FakeTrack("audio");
+ send.mockReturnValueOnce(false);
+ expect(await host.replaceStream(stream(video, voice))).toBe(false);
+ expect(videoSender.track).toBe(ownedVideo);
+ expect(videoSender.replaceTrack).not.toHaveBeenCalled();
+ expect(videoSender.setParameters).toHaveBeenCalledTimes(parameters);
+ expect(ownedVideo.stop).not.toHaveBeenCalled();
+ expect(audioSender.track).toBe(previousAudio);
+ expect(previousAudio.stop).not.toHaveBeenCalled();
+ expect(voice.clones[0]!.stop).toHaveBeenCalledOnce();
+ expect(videoSender.parameters.degradationPreference).toBe("balanced");
+ });
+
it("reuses the audio transceiver when source audio appears and retires clones only", async () => {
const { publisher: host, pc, video, send } = await publisher(false);
const nextVideo = new FakeTrack("video");
@@ -412,16 +462,22 @@ describe("embedded SFU browser transport", () => {
});
it("rolls back a failed source replacement and releases its unused clone", async () => {
- const { publisher: host, pc, video } = await publisher();
- pc.transceivers[0]!.sender.replaceTrack.mockRejectedValueOnce(
- new Error("replace rejected"),
- );
+ const { publisher: host, pc, video, send } = await publisher();
+ const videoSender = pc.transceivers[0]!.sender;
+ feedVideoStats(pc, video.clones[0]!.id, 6);
+ await vi.advanceTimersByTimeAsync(2_000);
+ send.mockReturnValueOnce(false);
const replacement = new FakeTrack("video");
expect(await host.replaceStream(stream(replacement))).toBe(false);
expect(pc.transceivers[0]!.sender.track).toBe(video.clones[0]);
expect(video.clones[0]!.stop).not.toHaveBeenCalled();
expect(replacement.clones[0]!.stop).toHaveBeenCalledOnce();
+ expect(videoSender.parameters.degradationPreference).toBe("balanced");
expect(pc.close).not.toHaveBeenCalled();
+ const replacements = videoSender.replaceTrack.mock.calls.length;
+ expect(await host.replaceStream(stream(video, new FakeTrack("audio")))).toBe(true);
+ expect(videoSender.replaceTrack).toHaveBeenCalledTimes(replacements);
+ expect(video.clones).toHaveLength(1);
});
it("preserves media during a signaling outage and updates only the route fence", async () => {