Files
piik/docs/operations/self-hosting.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

Deploy Piik Server

English · 简体中文 · Documentation

Piik Server packages the web interface, room management and optional media forwarding in one server binary. Extract and run it; room data is stored in SQLite.

Try it locally

These server instructions use a Linux x64 machine.

Download piik-<revision>-runtime.tar.gz, the Linux x64 Server archive, from GitHub Releases or the Gitee mirror. Extract it and run the following in its directory:

./piik-server

Open http://localhost:8787. This is a local trial; use the configuration below to let friends connect over the internet. To start a temporary room on your computer, use the Piik App guide.

Docker Compose

On a Linux x64 server with Docker Compose v2, download the two deployment files into an empty directory:

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

Replace share.example.com in .env with your domain, then start Piik:

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

The ghcr.io/tntcrafthim/piik:latest image includes the Web UI, signaling, STUN and optional SFU. Complete HTTPS and firewall configuration below. The default is P2P; the sample .env also shows how to enable SFU fallback. Keep the piik-data volume, which stores room data and optional diagnostics. See container maintenance for updates and backups.

Put it online

You need a Linux x64 server and a domain pointing to its public IP. The example uses share.example.com; replace it with your domain.

1. Configure and start Piik

Create a .env file next to the binary:

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=

Run these commands from that directory as a regular user:

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

The server reads .env automatically and stores rooms in rooms.sqlite in the working directory. A blank SITE_ACCESS_PASSWORD allows entry without a site passphrase; enter a passphrase to require one. Room invitations and access settings still apply.

PUBLIC_BASE_URL must match the address opened in the browser, including HTTPS and any non-default port. Leave ALLOWED_ORIGINS unset or empty for this single address. An existing non-empty value overrides that default; a stale value can cause 403 when creating a room.

MAX_VIEWERS_PER_ROOM sets the room's Viewer limit, excluding the Host. Choose 1..20 and restart to apply it. More Viewers can require more network and relay resources. See room capacity for defaults and the difference from App rooms.

2. Enable HTTPS

Use your existing HTTPS reverse proxy to forward to 127.0.0.1:8787 with WebSocket support. If you do not have one, install Caddy and add this to its Caddyfile:

share.example.com {
    reverse_proxy 127.0.0.1:8787
}

Reload Caddy. It obtains and renews the certificate automatically when DNS points to the server and TCP 80/443 are reachable. See Caddy's HTTPS proxy guide.

For nginx, see the configuration example. If you copied an older example, change its Permissions-Policy to camera=(self), microphone=(self), geolocation=() and reload nginx. Empty camera/microphone allowlists prevent Browser capture even when the user grants permission; self allows this site to request access.

3. Open the ports and verify

Allow TCP 80/443 for HTTPS and UDP 3478 for STUN in the server firewall and cloud security group. Keep TCP 8787 private. The STUN hostname must resolve directly to the server; a CDN HTTP proxy does not forward its UDP traffic.

Open https://share.example.com/healthz; it should return {"status":"ok"}. Then open the site, share a screen and join from another device. This initial configuration uses P2P media, so participants need a usable UDP path.

Optional: media fallback

Add SFU_UDP_PORT=7882 to .env, allow UDP 7882, and restart Piik to enable automatic SFU fallback. When the server is behind NAT, also set SFU_PUBLIC_IP to its reachable public IPv4 address. The same binary provides the fallback. The Host must turn off Privacy mode before sharing to allow this route. Both direct and SFU media need a usable UDP connection.

Keep it running and update

For automatic startup, use the systemd or container guide. Keep .env and rooms.sqlite across updates. Back up room data while the server is stopped, replace the executable with the new release, then restart and check health and room access. Read release notes before an upgrade that changes data formats.

All settings and ports · Maintainer release tooling