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. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

docs: define later distribution packages (#201)

AAA5cc254703392
diff --git a/docs/project-memory.md b/docs/project-memory.md
index aa3227be..a0f98548 100644
--- a/docs/project-memory.md
+++ b/docs/project-memory.md
@@ -14,7 +14,7 @@ Last updated: 2026-08-22
- Ordinary peer ICE is STUN-only. Credentials, room secrets, candidate details, and diagnostic data remain private and narrowly scoped.
- Screen audio offers live-switchable 64/128/256 kbps sender ceilings and defaults to 128. The existing last-wins quality wire owns desired state; each endpoint serially applies and reads back current Host/relay/SFU audio senders, exposes local failures, and gives future senders the latest desired value. Opus remains fixed, and without an applied-ack wire the Host does not claim room-wide atomic convergence. These are configuration ceilings, not fidelity claims.
- Video codec selection remains `automatic | H.264 | VP8`. The accepted first switching boundary is a generation-fenced renegotiation/republish transaction while sharing is explicitly paused; unpaused hot switching is later reuse of that transaction, not an independent mechanism.
-- A source-checkout LAN one-command launcher is accepted as a Web development/deployment convenience. It reuses the current Node/config/access/storage contract and does not claim to be a packaged client, TLS provisioner, NAT traversal tool, or public deployment service.
+- Two distribution artifacts are accepted only after the current feature, NAT, and real-network ledger is complete. A public-server one-click deployment package installs the current application plus STUN/SFU/TURN and proxy components on a user-owned server. A Windows/macOS/Linux local package runs the Host, application server, and local state on the broadcaster's machine without source, Node, or any external Screener/network service; it keeps workable direct P2P but reports the reachability loss imposed by public ingress, TLS, gateway, NAT, or firewall limits rather than promising universal connectivity.
- Current UI, presence, route labels, and diagnostics describe observed state only; they do not create route authority.
- Viewer startup feedback remains on the stage until current-generation frame presentation is proven, distinguishes peer, fallback, media, autoplay, recovery, and failure phases, and keeps `Play` specific to autoplay rejection. The strict-NAT guessed-candidate idea remains an isolated emulator gate; only a pass may authorize one manually approved, kill-switched canary in an operator-owned test room with explicit consent from both endpoints and exact room/edge/generation/budget bounds.
@@ -31,7 +31,7 @@ Last updated: 2026-08-22
## Current Priority
1. Keep this truth set and [the TODO ledger](./todo.md) concise and internally consistent.
-2. Rebuild and release the accepted route runtime first. Then release live audio and paused video-codec switching, follow with evidence-led H.264 diagnosis and the strict-NAT emulator gate, then connection feedback, the LAN launcher, and the remaining accepted roadmap. Parallel branches may finish earlier but do not change this merge/deployment order.
+2. Rebuild and release the accepted route runtime first. Then release live audio and paused video-codec switching, follow with evidence-led H.264 diagnosis, the strict-NAT emulator gate, connection feedback, and the remaining functional roadmap. Distribution packaging starts only after those TODOs are complete. Parallel branches may finish earlier but do not change this merge/deployment order.
## Working Rules
diff --git a/docs/status.md b/docs/status.md
index 60f77ae6..871e7a2d 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -19,20 +19,19 @@ This is the current execution index. Git history owns completed timelines; [veri
- Automatic P2P-first routing, one active upstream, an acyclic graph, exact identity/generation authority, media-proven make-before-break, and bounded failure remain accepted.
- The holistic assisted-route model is accepted: one controller performs allocation, child reparenting, and relay abdication/drain. One Host publication serves SFU subscriptions; TURN is an exact edge transport, not a topology node. Wave A supplies endpoint accounting and the wire boundary without pretending that later controller convergence, media-binding generations, or independent SFU/TURN admission already exist.
- Parent selection is deterministic rather than random or score-based: hard eligibility filters, then shallowest result, remaining sender capacity, stable join order, and peer identity; one provisional edge uses standard ICE and media proof at a time. Viewer connection feedback and the strict-NAT emulator gate are accepted follow-up work, not deployed behavior.
-- Live 64/128/256 audio-ceiling mutation, a source-checkout LAN one-command launcher, and paused-share video codec switching are accepted but not yet implemented on canonical `main`. H.264 startup blur/low-FPS reports remain an evidence-led diagnosis, not a presumed codec defect.
+- Live 64/128/256 audio-ceiling mutation and paused-share video codec switching are accepted but not yet implemented on canonical `main`. H.264 startup blur/low-FPS reports remain an evidence-led diagnosis, not a presumed codec defect. Public-server and fully local distribution packages are later work after the functional, NAT, and real-network ledger is complete.
## Current Milestone
1. Rebuild and release route waves A-D from exact canonical `main`, including cap/accounting, bounded server admission, deterministic local parent selection, quality ownership, and one controller.
2. Release live audio-ceiling mutation and paused-share codec switching on the resulting generation/transition boundary.
3. Reproduce the H.264 startup report before any codec-specific repair, and build the strict-NAT emulator gate before any manually approved canary in an operator-owned test room.
-4. Add first-frame-driven Viewer connection stages, then integrate the scoped LAN launcher and remaining accepted tools.
-5. Validate and deploy each coherent slice in this order with its focused browser/network/resource and rollback gates.
+4. Add first-frame-driven Viewer connection stages and finish the remaining accepted functional and real-network work.
+5. Validate and deploy each coherent slice in this order with its focused browser/network/resource and rollback gates; distribution packaging remains outside this milestone.
## Active Boundaries
- `fix/configurable-relay-cap` is an old, incomplete draft and must not be merged as-is.
-- `feat/local-oneclick-bundle` is a stale-base donor only. Transplant its launcher logic and tests selectively; never import its old requirements, memory, status, access variable, or generated local state.
- Open PR #192 and the Native stack are evidence/research, not pending product releases.
- Deployed surfaces and retained candidates that still need product decisions are indexed only in [the TODO ledger](./todo.md); do not extend or roll them back automatically.
- Real SFU/TURN recovery, heterogeneous networks, mobile lifecycle, audio/A-V device behavior, and endurance/resource measurements remain external acceptance evidence, not blockers for unrelated reversible work.
diff --git a/docs/todo.md b/docs/todo.md
index f67a1b30..4d1cafbf 100644
--- a/docs/todo.md
+++ b/docs/todo.md
@@ -13,8 +13,7 @@ Only items in **Now** are executable after their stated decision gate. A branch
5. **Diagnose the production H.264/blur report.** Reproduce exact release `769de201f7cc` against current `main` on the same Host/browser/driver/game and one wired direct Viewer, changing one variable at a time. Implement a codec-specific repair only if codec/encoder evidence identifies it; otherwise fix the proven capture, sender, BWE, or lifecycle cause.
6. **Gate the strict-NAT guessed-candidate experiment.** Build only the isolated endpoint-dependent NAT emulator and browser harness first. Standard ICE must fail in the owned fixture, the capped candidate set must pass the documented repeatability, deadline, privacy, and cleanup gates in stable Chrome and Firefox, and fallback must remain unchanged. Only then may one manually approved, operator-owned test room run a default-off, kill-switched canary with explicit consent from both endpoints and exact room/edge/generation/budget bounds; failure closes the candidate. Do not ship guessed candidates to ordinary rooms or infer NAT type from IP, UA, carrier, or two STUN observations.
7. **Make Viewer connection progress explicit.** Derive one stable stage from existing access, route, peer/SFU, media, autoplay, and bounded-failure state. Keep the overlay until a composited current-generation frame, show `Play` only for actual autoplay rejection, preserve a still-valid old frame during recovery, and expose retry only through the bounded controller. Measure the existing token-free SFU prewarm and route stages before adding another connection mechanism.
-8. **Rebuild the LAN one-command launcher.** From fresh canonical `main`, transplant only the useful launcher/tests/wrappers from `feat/local-oneclick-bundle`, replace its stale access variable with `SITE_ACCESS_PASSWORD`, keep local SQLite state out of Git, and verify startup, health, localhost Host, and LAN Viewer output on PowerShell and POSIX boundaries. This is a source-checkout launcher, not an installer or public deployment system.
-9. **Validate and release in priority order.** Review, merge, and deploy each coherent slice from canonical `main`: route first, then audio/codec mutation, then H.264/NAT evidence and any proven repair, then connection feedback and remaining tools. Run the focused state machine and browser/network matrix relevant to that slice, plus independent review, build/full gates, bounded production preflight, postflight, and rollback verification. A parallel branch may finish early but does not jump this rollout order.
+8. **Validate and release in priority order.** Review, merge, and deploy each coherent slice from canonical `main`: route first, then audio/codec mutation, then H.264/NAT evidence and any proven repair, then connection feedback and remaining tools. Run the focused state machine and browser/network matrix relevant to that slice, plus independent review, build/full gates, bounded production preflight, postflight, and rollback verification. A parallel branch may finish early but does not jump this rollout order.
The existing route implementation is an input to these tasks. Preserve its verified generation, authorization, make-before-break, and media-proof invariants while migrating capacity and fallback accounting. The accepted model is the destination; each wave must remain safe and truthful on its own rather than installing a name-only controller or an unreserved overlap.
@@ -24,9 +23,11 @@ These items are real product work, ordered after the current release boundary; t
1. **Native shared encode, Windows first.** Prove one hardware encoder output can serve two independent Viewer transports and the Host-SFU publication while each connection retains its own RTP/RTCP, pacing, encryption, feedback, and upload accounting. Productize only after actual access-unit identity, Viewer2/FIFO, heterogeneous feedback, game-resource, browser/hardware, A/V, packaging, and licensing gates pass. Web Host/relay remains standard per-`RTCPeerConnection` encoding because no portable shared-encoder contract exists.
2. **Mobile Viewer lifecycle.** Run Android Chrome and iOS Safari device matrices for autoplay gesture, foreground/background audio, foreground video recovery, lock/page reclamation, rotation, and Wi-Fi/cellular migration. Preserve the same media element and current reconnect path; do not promise background video composition or unsupported lock-screen behavior.
-3. **Distributable sender.** Turn a proven Windows native path into a signed, installable, updateable sender before expanding capture/audio backends to macOS and Linux. A source checkout or evaluation ZIP is not a self-contained cross-platform client.
+3. **Native Host capture backend.** Productize a proven Windows native capture path before expanding capture/audio backends to macOS and Linux. Its capture, hardware encode, audio, identity and lifecycle evidence becomes an input to later packages; a source checkout or evaluation ZIP is not a distributable product.
4. **Real network acceptance.** Measure standard ICE/STUN, IPv4/IPv6, independent STUN destinations, selected TURN, SFU ingress, and bounded failure across representative NATs and mobile networks. Browser port prediction remains experiment-only until its emulator and allowlisted-canary gates pass; raw-IP ranking and a room-wide quality score remain out of scope. Parent choice uses exact edge evidence and the accepted route controller.
5. **Platform output only when real.** Revisit AirPlay/Cast only when a target browser and physical receiver prove the live `MediaStream` contract. System mirroring remains external; no placeholder button, custom receiver, or server transcode is scheduled.
+6. **Public-server one-click deployment package.** After every current functional and real-network item is settled, package the exact application, STUN/SFU/TURN, reverse proxy, storage, secrets, health checks, backup and rollback flow for a user-owned public server. Require real domain/TLS/firewall/capacity inputs and never ship credentials or call a partial deployment ready.
+7. **Fully local one-click Host-server package.** Last, package Windows/macOS/Linux Host capture, the exact application server and local state without requiring source, Node or any external Screener/STUN/SFU/TURN/tunnel/relay service. Preserve usable direct P2P and use the completed NAT/network evidence to maximize reachability, while reporting public-origin, gateway, NAT and firewall limits truthfully; loopback/LAN success is not universal Internet success.
## Product Decisions Needed
diff --git "a/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md" "b/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"
index 282b5685..a7e7f150 100644
--- "a/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"
+++ "b/docs/\346\226\271\346\241\210\350\256\276\350\256\241.md"
@@ -36,7 +36,9 @@
不选 Go 的原因是 Node 不承载正常情况下的媒体流量,换语言不会减少分享者上行或 TURN 中继成本。不选 C++ 的原因是浏览器能力尚未被实测证明不足;只有捕获、应用音频或硬件编码出现明确瓶颈时才增加原生 helper。
-本地一键启动只包装当前 Node/Vite 源码应用,不创建第二套服务器。`npm run local` 和 PowerShell/POSIX wrappers 检查 Node 24 与依赖、选择可用端口、使用专用本地状态目录、生成或复用符合当前合同的 `SITE_ACCESS_PASSWORD`,启动后轮询现有 health endpoint,并打印 localhost Host URL 与 LAN Viewer URL。它明确报告 HTTP LAN、缺少公网 TLS、防火墙/端口映射和未配置 STUN/SFU/TURN 的边界;不自动修改系统网络设置,不把源码启动器称为安装包或互联网部署器。测试通过注入端口、网络接口和子进程边界验证配置与输出,不依赖真实公网。
+最终分发有两个独立产物。公网服务器一键部署包面向用户自有服务器,编排同一版本的 Web/信令应用、持久状态、STUN/SFU/TURN 和反向代理,不建立第二套应用;域名、TLS、secret、端口、容量、备份、健康检查和回滚继续 fail closed。它不提供托管基础设施,也不把占位配置写成可用服务。
+
+本地自包含一键包在分享者电脑上同时承载 Host、当前 Web/信令应用服务器与本地状态,Viewer 仍使用普通浏览器。它不调用任何外部 Screener、STUN、SFU、TURN、隧道或 relay 服务,并复用唯一协议、房间、鉴权和路由实现;公网覆盖取决于本机入口、可信 origin、网关映射和 NAT 条件,direct P2P 可用时保留,受限时明确失败。具体 runtime、进程边界、签名、更新、证书、网关与 NAT 方案等当前功能和真实网络 TODO 完成后再由证据确定,不得先用某个打包器或自动映射技巧反向定义产品。
## 系统结构
@@ -358,8 +360,9 @@ Token-free SFU standby prewarm 保持可选且不创建 participant、publicatio
4. 完成连接恢复和 stats 面板;随后以 STUN-only snapshot 替换旧全房 TURN credential/refresh wire。
5. 从 canonical `main` 按 ADR-0005 依次落 route waves A-D:先统一 endpoint cap/accounting 与 wire,再建立 SFU/TURN resource admission,最后把 deterministic allocation、child reparent 和 parent drain 收到一个 controller;每个 wave 独立可回滚。
6. 路由边界合入后依次落 live screen-audio ceiling 和 paused video-codec transaction;随后做 H.264 根因诊断与 strict-NAT emulator gate,门禁通过才允许 allowlisted canary。
-7. 加入 first-frame-driven Viewer connection stages,再整合 source-checkout LAN launcher。Site access、room-scoped Viewer grant 与 SQLite v3 的已部署合同保持不变。
-8. Windows Native fixed-`HIGH` 保持可选且不改变 Web 默认;shared encode、移动 lifecycle、可分发 sender 和平台输出按 TODO roadmap 后续推进。
+7. 加入 first-frame-driven Viewer connection stages。Site access、room-scoped Viewer grant、路由与 SQLite v3 合同保持唯一。
+8. Windows Native fixed-`HIGH` 保持可选且不改变 Web 默认;shared encode、移动 lifecycle 和平台输出按 TODO roadmap 后续推进。
+9. 当前功能、NAT 与真实网络 TODO 完成后,再分别设计和交付公网服务器一键部署包与完全不依赖外部服务的本地 Host-server 包。
生产仍运行 `screener-v5`;当前 source 的 Wave A capacity slice 使用 `screener-v6`。不兼容 wire/schema 迁移须原子切换并保留迁移前备份。
diff --git "a/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md" "b/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"
index 7b828c0e..e22c4439 100644
--- "a/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"
+++ "b/docs/\351\234\200\346\261\202\347\220\206\350\247\243.md"
@@ -38,7 +38,8 @@ SFU/TURN 的 publication、subscription、transport、server-resource accounting
- 最小持久化:`ROOM_DATABASE_PATH` 可选且必须与 `SITE_ACCESS_PASSWORD` 同时配置。两者都存在时,SQLite 只持久保存从 `1` 开始自增的房间 ID、Host token 摘要、nullable Viewer grant 摘要,以及 nullable 48-byte Viewer-password material(16-byte salt + 32-byte scrypt verifier);数据库 `CHECK` 约束非空 BLOB 长度,不新增用户、成员或 session 表。明文房间密码只短暂存在于当前页面和鉴权/派生调用内存,不进入 URL、cookie、浏览器持久存储、日志或 SQLite。持久房间停止后仍显示等待状态;私密邀请按期限或 Host rotate 更新。旧 schema 行在原子迁移时必须 fail-closed 为没有可用明文 grant 的锁定私密状态,Host rotate 后才能生成新邀请。
### P1 - 重要功能
-- 本地一键启动:提供基于当前源码 checkout 的跨平台单命令 LAN 启动器,而不是安装包、云部署器或公网穿透工具。它复用唯一 Node 应用、当前 `SITE_ACCESS_PASSWORD`/SQLite/config 合同,自动选择可用端口并打印 localhost Host URL、LAN Viewer URL 和健康结果;Host 使用 secure-context 可接受的 localhost 或部署者提供的 HTTPS,LAN Viewer 可在已声明的本地 HTTP 边界访问。启动器不得伪造 TLS、防火墙、路由器端口映射、STUN、SFU 或 TURN 已配置,也不得复活已删除的环境变量;Node 24 与依赖安装仍是明确前置条件。
+- 公网服务器一键部署包:在用户自有的公网服务器上一键部署当前 Web/信令应用、持久状态和所需 STUN/SFU/TURN/反向代理组件,复用唯一配置、secret、路由、健康检查和回滚合同。它不是托管服务,不能内置真实凭据或跳过域名、TLS、防火墙、端口、容量和备份预检。
+- 本地自包含一键包:提供 Windows、macOS 和 Linux 可分发的桌面包,在分享者电脑上同时运行 Host、当前 Web/信令应用服务器和本地状态,朋友继续通过普通浏览器邀请观看。安装后启动不要求源码 checkout、Node 或任何外部 Screener、STUN、SFU、TURN、隧道或 relay 服务;它尽力使用本机可达入口和 direct P2P,但必须明确报告公网入口、可信 HTTPS/WSS、网关映射或 NAT 路径缺失,不能承诺任意 CGNAT/严格防火墙必通。两种分发包都排在当前功能、路由、NAT 和真实网络 TODO 完成之后。
- 私密房间双入口:private room 接受现有 `/r/{code}#v={grant}` 合法邀请直接进入,或“站点访问 + 房间号 + 该房间观看密码”。没有 grant 的 `/join` 或 `/r/{code}` 先显示明确标为“站点访问”的整站验证,通过后才显示明确标为“加入房间”的当前房间密码输入;有效 site-access cookie 直接跳过第一步,但两类密码不得复用、代填或互相替代。Host 可设置、轮换或移除房间观看密码。密码接受 1 至 64 个可见 ASCII 字符;异步 scrypt 全局最多执行 2 个、等待 16 个派生。站点口令和房间密码都不得进入 URL/query/storage/log/SQLite;不存在、错误密码、队满和正确密码后的满房都返回通用结果。
- 统一自动路由:旗舰部署开启 `PEER_ASSISTED_MEDIA` 后,所有正常房间使用同一个服务端 route controller,并各自保存 assignment、session、route revision、assignment generation、connection identity、media-binding generation 和容量状态。controller 只执行 allocate/distribute、child reparent 和 relay abdicate/drain;合格父节点可形成候选图,但 committed media graph 必须无环、每名 Viewer 同时至多一个 active upstream,且每个 active Viewer 必须沿 peer edges 到达 Host 或沿当前 authoritative Host publication 到达 source。加入、容量释放、节点离开、当前边失败或已接受的 path-health evidence 只开启一次有界重选;其余健康分支保持 sticky,不做常驻多源、周期评分或全房重平衡。候选先按当前身份、source reachability、无环、深度、sender slot、relay eligibility、failed-edge/cooldown 和 server admission 做硬过滤,再按最小结果深度、最多剩余稳态 sender slots、稳定加入顺序和 peer identity 确定性排序;一次只准备一个候选,以浏览器 ICE 和当前代媒体证明决定是否采用,失败才尝试下一个。初次加入或 hard failure 接受达到媒体可用门槛的首个候选;soft-quality reparent 还必须由 quality owner 证明候选达到恢复门槛并优于仍健康的旧 edge,否则回滚后试下一个。raw IP、地理位置、UA、自报 NAT 类型、未与 current-generation media 相关的单边 RTT 或跨 edge 加权分数均不得进入排序。迁移保留旧边,只有 exact current candidate 取得 live track、正 RTP 和 decoded-frame progress 后才原子 commit;失败、超时、代次变化或授权撤销销毁候选并保留或恢复旧权威。普通 peer 始终 STUN-only。SFU/TURN overlap 和资源准入由同一 typed ledger 与事务约束。该能力不增加用户拓扑选择、百分比发布或第二套路由器。
@@ -172,7 +173,8 @@ SFU/TURN 的 publication、subscription、transport、server-resource accounting
### 仓库可移植性
- Given 在新的 Windows、macOS 或 Linux 工作副本中克隆仓库,When 打开项目,Then 需求、调研、项目记忆、`AGENTS.md` 与 `.codex/` 均存在且处于 Git 跟踪状态,不依赖原开发机器的绝对路径或密钥。
-- Given 已完成 `npm ci` 的 Node 24 source checkout,When 在 Windows PowerShell、macOS 或 Linux 执行本地启动命令,Then launcher 选择可用监听端口、在 Git 忽略的受限状态目录生成或复用当前 `SITE_ACCESS_PASSWORD` 与 SQLite、等待现有 health endpoint 成功,再打印精确匹配该端口的 localhost Host URL、LAN Viewer fragment-invite origin 和 site password;health/spawn 失败必须终止 child 且不显示 ready。Given 没有 HTTPS、STUN/SFU/TURN、防火墙或公网配置,Then 输出明确只承诺 trusted-LAN HTTP Viewer 与 localhost Host,不修改系统网络、不声称跨网可用。重启复用本地 password/rooms,多网卡或显式 public URL 必须与实际 listener port 一致。
+- Given 用户在自有公网服务器运行一键部署包,When 域名、TLS、端口、secret、容量、存储和回滚预检通过,Then 同一版本的应用、STUN/SFU/TURN 与反向代理可重复启动并输出精确健康结果;任一必需条件失败时不得显示 ready、写入占位凭据或留下半配置服务。
+- Given 用户安装本地自包含一键包,When 在 Windows、macOS 或 Linux 启动分享,Then 包内 Host、当前应用服务器和受限本地状态使用同一协议与配置合同启动,用户无需源码、Node 或任何外部服务,Viewer 邀请仍由普通浏览器打开。Given 公网 HTTPS/WSS、信令入口、媒体 UDP、网关映射或 NAT 路径任一不可用,Then 预检必须如实显示受限或不可达,不得把 loopback/LAN 成功写成公网成功;可工作的 direct P2P 保留,失败进入明确终态。
## 待确认事项