Files
Piik/docs/operations/self-hosting.zh-CN.md
T
AAA 383f3656c7 fix(media): stabilize sharing startup and recovery
## Problem and outcome / 问题与结果

Sharing could fail when an optional output or encoder comparison failed, while retired Browser work could block media cleanup. Browser pooling also spent its startup protection before publication and classified its synthetic transport clock as realtime video, delaying recovery after a bandwidth drop. These repairs stay within the existing capture, producer, edge and connection owners.

Self-hosting samples now follow the configured public Origin and permit the site's requested camera/microphone capture. Piik's own Origin rejection has a specific bilingual explanation, distinct from arbitrary proxy 403 responses.

## Release notes

### 中文

这是一次分享稳定性维护更新,重点修复开播、换源与画质恢复,并改善自部署站点的配置和错误说明。

- Windows 自动选择编码器时,如果已验证 H.264 可用,后续软件编码对比失败或超时会保留可用的 H.264,避免因此无法开播。
- 较低画质输出或单条音频发送连接失败时,保留仍然健康的分享和其他连接。
- 修复停止分享、换源和媒体连接退役时,旧异步任务阻塞清理与恢复的问题。
- 改善浏览器共享编码的首播画质与网络波动后的恢复,避免因短时码率变化反复重建编码器。
- 自部署配置示例默认跟随站点网址;创建房间因网址未获允许而返回 403 时,页面会指出需要检查的配置。nginx 示例也修正了对本站摄像头、麦克风的权限限制。

已有自部署站点若遇到 403,请检查 `PUBLIC_BASE_URL` 与 `ALLOWED_ORIGINS`。使用旧 nginx 示例的站点需更新 `Permissions-Policy`;步骤见[自部署教程](https://piik.tv/docs/zh/self-hosting)。本次更新不改变房间、信令或 App 控制协议。

### English

This maintenance update improves sharing startup, source changes and video-quality recovery, with clearer configuration and error guidance for self-hosted sites.

- Windows automatic codec selection retains a verified H.264 encoder if the subsequent software comparison fails or times out, instead of failing to start sharing.
- A failed lower-quality output or individual audio sender no longer interrupts healthy sharing and other connections.
- Fixes retired asynchronous work blocking cleanup and recovery when stopping sharing, changing sources or retiring media connections.
- Improves initial quality and recovery after network fluctuations in Browser pooled encoding, while avoiding unnecessary encoder recreation after short bitrate changes.
- The self-hosting sample follows the configured site address by default. Piik's Origin-related room-creation 403 now identifies the settings to check. The nginx sample also permits camera and microphone requests from the site itself.

If an existing self-hosted site returns 403, check `PUBLIC_BASE_URL` and `ALLOWED_ORIGINS`. Sites using the old nginx sample must update `Permissions-Policy`; see the [self-hosting guide](https://piik.tv/docs/self-hosting). Room, signaling and App control protocols are unchanged.

## Verification / 验证

- `npm run check`: 75 files / 1,106 tests, TypeScript and production Web build passed.
- `npm run check:go`: Go formatting, tests, vet, supported core builds, Windows native compile and regressions passed. Darwin cgo packaging remains owned by its macOS CI runner.
- Repository hygiene, documentation checks and website/documentation build passed.
- Isolated VP8/H.264 Browser checks: constrained-child isolation and recovery, short congestion pulse, live and quiet settings, pause/resume, source replacement and ordinary fallback passed. Controlled bandwidth can still cause temporary low resolution, stalls and A/V jitter.
- Windows native Auto/H.264/VP8 startup, window resize/fullscreen/minimize/restore, Browser-to-App fanout and embedded-SFU checks passed in the bounded local fixtures.
- Old-code negative controls reproduce the repaired failure paths. A real Chromium policy check rejects camera/microphone with the previous nginx header and captures both fake devices with the corrected same-origin policy; geolocation remains denied.
- Independent read-only review covered root ownership, cancellation and the producer/carrier adaptation boundary.

## Impact / 影响

Compatible patch release, planned as v1.6.4. No wire, storage, routing-authority or interaction-model change. Matching Server restart interrupts current process-owned media; package cutover retains the existing bounded rollback procedure. Unknown field reports still require device/network evidence and are not claimed resolved by local fixtures. Raw diagnostics and experiment artifacts remain ignored; accepted constraints and concise evidence live in their existing documentation owners.
2026-09-25 14:42:59 +08:00

5.3 KiB
Raw Blame History

部署 Piik Server

English · 简体中文 · 文档导航

Piik Server 将网页、房间管理和可选的媒体转发打包在一个服务端程序中。 解压后即可运行,房间数据保存在 SQLite 中。

先在本机试用

以下服务端操作在 Linux x64 环境中执行。

从 GitHub Releases 或 Gitee 镜像下载 piik-<revision>-runtime.tar.gz,即 Linux x64 服务端程序包。 解压后,在该目录运行:

./piik-server

打开 http://localhost:8787 即可试用。需要让朋友通过互联网访问时, 继续完成下方配置。如果只想在自己的电脑上临时开房间,可直接使用 Piik App。

使用 Docker Compose

在已安装 Docker Compose v2 的 Linux x64 服务器上,将两个部署文件下载到空目录中:

curl -fsSLo compose.yaml https://raw.githubusercontent.com/TNTcraftHIM/Piik/main/deploy/container/compose.yaml
curl -fsSLo .env https://raw.githubusercontent.com/TNTcraftHIM/Piik/main/deploy/container/.env.example

将 .env 中的 share.example.com 换成自己的域名,然后启动:

docker compose run --rm piik --check-config
docker compose up -d

ghcr.io/tntcrafthim/piik:latest 镜像包含网页、信令、STUN 和可选 SFU。 接着完成下方的 HTTPS 配置和端口放行。 默认使用 P2P;如需 SFU 兜底,按 .env 中的说明启用即可。 请保留 piik-data 数据卷,房间数据和可选诊断文件都保存在其中。 更新与备份见容器维护说明。

对外提供服务

准备一台 Linux x64 服务器,以及一个指向服务器公网 IP 的域名。 下文以 share.example.com 为例,请替换成自己的域名。

1. 配置并启动 Piik

在程序旁新建 .env 文件:

PIIK_ENV=production
LISTEN_HOST=127.0.0.1
PUBLIC_BASE_URL=https://share.example.com
STUN_URLS=stun:share.example.com:3478
MAX_VIEWERS_PER_ROOM=20
SITE_ACCESS_PASSWORD=

使用普通用户,在该目录执行:

./piik-server --check-config
./piik-server

程序会自动读取 .env,并将房间数据保存在工作目录的 rooms.sqlite 中。 SITE_ACCESS_PASSWORD 留空时,进入站点无须口令; 如需设置口令,填写你想使用的口令即可。房间邀请与加入权限仍由房主管理。

PUBLIC_BASE_URL 应与浏览器访问的网址一致,包括 HTTPS 和非默认端口。 只使用这个地址时,ALLOWED_ORIGINS 不设置或留空即可;已有的非空值会覆盖此默认值, 旧地址未更新可能导致创建房间返回 403。

MAX_VIEWERS_PER_ROOM 可设置每房观众上限,不含房主,支持 1..20,修改后重启生效。 人数越多,对网络和转发资源的需求也可能增加。默认值及 App 房间的区别见 人数限制。

2. 配置 HTTPS

如果已有 HTTPS 反向代理,将请求转发到 127.0.0.1:8787,并启用 WebSocket 支持。 如果还没有,可以安装 Caddy,在 Caddyfile 中加入:

share.example.com {
    reverse_proxy 127.0.0.1:8787
}

重新加载 Caddy。域名解析正确且 TCP 80/443 可访问时,它会自动申请和续期证书。 具体操作见 Caddy 的 HTTPS 代理说明。

nginx 可参考配置示例。如果沿用了旧示例,请将 Permissions-Policy 改为 camera=(self), microphone=(self), geolocation=(),然后重新加载 nginx。 摄像头和麦克风的空白允许列表会阻止浏览器采集,即使用户已授权;self 允许本站请求访问。

3. 放行端口并检查

在服务器防火墙和云平台安全组中放行 TCP 80/443(HTTPS)和 UDP 3478(STUN)。 TCP 8787 仅供本机反向代理访问。STUN 域名需要直接解析到服务器,不能只经过 CDN 的 HTTP 代理。

打开 https://share.example.com/healthz,应返回 {"status":"ok"}。 随后打开站点,分享一个画面,并用另一台设备加入验证。 上述基础配置使用 P2P 传输,参与者之间需要可用的 UDP 通路。

可选:启用媒体兜底

在 .env 中添加 SFU_UDP_PORT=7882,放行 UDP 7882,再重启 Piik,即可启用自动 SFU 兜底。 如果服务器处于 NAT 后方,还需将 SFU_PUBLIC_IP 设置为外部可达的公网 IPv4 地址。 这项功能由同一个服务端程序提供。 房主需要在开始分享前关闭 隐私模式,才会允许使用这条线路。 直连和 SFU 媒体都需要可用的 UDP 通路。

长期运行与更新

需要开机启动时,参阅 systemd 与容器配置。 更新时保留 .env 和 rooms.sqlite:停止服务、备份房间数据、替换新版程序,再启动并检查健康状态和房间访问。 涉及数据格式变化的版本,请先阅读发布说明。

全部配置与端口 · 维护者发版工具