Early video retransmissions could be rejected before an SFU publication admitted its primary stream. The shared RTP reader now restores the associated primary identity before admission. A repository audit also found ownership omissions in Viewer input retirement, queued route work, partially constructed connections and sender-evidence cleanup; each is corrected at its existing owner without changing routing or adaptation policy. The same phase fixes bounded Linux diagnostic encoding, picker/tooltip keyboard and touch behavior, and stale-language notices. Documentation now reflects current App, room and media lifecycles. Theme-role consolidation remains deferred. Validation: complete Web check (1,685 tests, type-check and build); Windows Go core tests/vet/cross-builds; Linux CI race/vulnerability checks and all seven package targets; native Linux diagnostic fixtures on both architectures; actual Chromium/Pion SFU decode, live settings, reload/recovery and resource-retirement gate; documentation and website builds. Confirmed defects were compared against their baseline and independently reviewed. No protocol, configuration or persistence migration is required. Physical device limits and unmatched field reports remain open. ## Release notes ### 中文 这是一次分享稳定性与交互细节维护更新,兼容现有 2.x 客户端和站点。 - 修复部分服务器中转开播失败:较早到达的视频重传包不再被误判,导致媒体发布提前结束。 - 修复停播后快速重新分享时,旧任务可能拖延新线路准备的问题。 - 撤销邀请或替换观众会话时,同步清理对应的远控输入身份,保留其他观众的正常使用。 - 改善连接失败、观众反复加入退出后的资源回收;避免 Linux 单路输出的错误信息意外中断整个分享。 - 修正选源、互动和线路提示的键盘/触屏操作;切换语言后,当前校验与错误提示会同步更新。 ### English This maintenance update improves sharing reliability and interaction details. It remains compatible with existing 2.x Apps and Sites. - Fix an SFU startup failure caused by video retransmissions arriving before the primary stream was admitted. - Prevent retired sharing tasks from delaying route preparation after a quick stop and restart. - Retire remote-input identities when invitations are revoked or Viewer sessions are replaced, while preserving other participants. - Release resources correctly after connection failures and repeated Viewer churn; prevent Linux output diagnostics from unexpectedly ending the whole share. - Improve keyboard and touch behavior in source selection, interactions and route help. Active validation and error messages now follow language changes.
8.0 KiB
ADR-0002: Durable Room Authority And Scoped Viewer Access
- Status: Accepted; implemented
- Date: 2026-09-10
Context
Piik serves one Host and at most 20 trusted Viewers. The application server owns a small room and authorization aggregate while WebRTC and LiveKit own live media sessions. Frequent application releases should not force the Host to create another room or redistribute invitations, but a database must not become a second owner for transient signaling, routes, media, or diagnostics.
The same product therefore needs two deployment choices over one room model:
- lightweight mode keeps no server-side room data after process exit;
- stable mode keeps only room authority in one local SQLite file so surviving pages can reauthenticate and rebuild fresh media after an application restart.
Decision
One Room Authority Model
Every room owns:
- one random free code from
1000through9999; - a SHA-256 Host-token digest and Viewer-grant digest;
- an opaque random Viewer authorization generation;
open | privatecode entry and optional salted scrypt password material.
Room authority has no time limit by default. Explicit replacement or deletion invalidates its credentials and releases the code; grant rotation or revocation retires the invitation independently. Public sites may opt into the empty-room retention policy to keep abandoned allocations from exhausting the 9,000-code space. Occupancy, including idle chat, protects a room; the existing signaling heartbeat owns expiry and normal retirement owns cleanup. There is no client lease or renewal. The allocation bound remains; a full store rejects creation when no empty room is reclaimable. Site-access cookies retain their separate 24-hour rolling idle lifetime.
Lightweight And Stable Storage
Hosted Server uses SQLite by default:
- absent or empty
ROOM_DATABASE_PATHresolvesrooms.sqlitein the working directory; service/container templates select a writable persistent directory; - an explicit absolute path selects that SQLite file;
ROOM_DATABASE_PATH=:memory:explicitly selects process-only rooms, whose authority ends at process exit. App Local uses this memory composition directly and does not inherit Hosted environment defaults.
Stable mode stores only roomId, Host-token digest, Viewer-grant digest,
authorization generation, code-entry policy and optional password verifier.
It never stores raw tokens, grants, or passwords.
The schema is one exact current version on an embedded SQLite driver, one connection, one writer, and transactional room mutations. An unknown schema, wrong application identity, corrupt row, inaccessible path, or second owner fails startup before signaling or SFU resource mutation. There is no automatic legacy reader or migration chain; published upgrades follow the public compatibility promise. A schema cutover must preserve existing authority through an explicit offline operation on a verified copy, with the previous database and application retained for rollback. Removing the lease column never deletes rooms or rotates credentials.
On restart, every saved room authority is restored. No Host, socket, share or media route is considered online until fresh sessions establish it again.
Participants, display names, client/peer/session IDs, share generation, pause, quality settings, codec decisions, route graph, pending operations, first-frame proof, SFU publications/subscriptions, RTCStats, diagnostics, and logs remain process-only. Every restart creates fresh session and route authority and media must reconnect and recommit on a newly decoded frame. SQLite does not make media recovery seamless or remove the browser gesture required after capture itself ends.
Host Ownership And Preferred Code
Each Host tab keeps its current room and raw Host token in session storage; same-origin local storage keeps the resume hint and independent creation profile. The Host-tab lifecycle owns cross-tab claims and resume behavior. The server keeps only the token digest. Clearing browser data or changing device loses ownership; IP, UA, hardware and browser fingerprints are never identity.
The browser also remembers one non-secret preferred room code with no local expiry or renewal timer. It is only a future allocation hint. The server remains the sole owner of room existence and code allocation: it reuses the hint only when free, otherwise allocates another random free code and the browser replaces its preference.
Explicit Room Replacement
The Host room-code control includes a refresh action immediately before Copy. With the exact Host token, one server operation allocates a guaranteed different free code and retires the old room through the normal delete lifecycle. Failure before commit leaves the old room unchanged. Success invalidates the old Host token, Viewer grant, password, authorization generation, sessions, routes and SFU resources, ends any active share, returns fresh room credentials, and updates the local preferred code. No old room or media state is migrated.
Viewer Access
Each room has one 128-bit, 22-character base64url Viewer grant independent of code entry. A valid grant authorizes only the Viewer role for that exact current room. The browser consumes it into room-scoped session storage and removes the URL fragment. Stable mode preserves only its digest so an existing invitation continues across application restart; rotation or revocation atomically updates the digest and authorization generation.
open admits site-authorized code entry without a room password. private
disables passwordless code entry; without a password it is invitation-only, and
with a password it additionally admits a matching code-and-password attempt.
Missing or deleted codes return ROOM_NOT_FOUND; expected existing-room denial
returns ROOM_ACCESS_DENIED.
Consequences
- Lightweight mode remains the smallest complete server and leaves no durable room authority after process exit.
- Stable mode preserves room code, Host ownership, invitations, revocation, password policy across application releases without persisting live topology or media state.
- Application restart in stable mode is a bounded reauthentication and media rebuild, not uninterrupted playback. LiveKit high availability remains a separate infrastructure decision.
- Production activation changes persistent state and therefore requires a verified writable directory, configuration backup, database backup/restore boundary and rollback procedure; it is not an ordinary app-only cutover.
Acceptance Gates
- Both modes pass the same creation, ownership, admission, password, rotate/revoke, replacement and 9,000-code-capacity behavior.
- Default inactivity cannot invalidate room authority. Opt-in retention only retires empty rooms, commits storage first and cleans up all transient effects. Stable restart preserves authority, restarts the empty interval and restores no participant or media authority.
- A surviving Host and Viewer can reauthenticate after restart, receive fresh sessions/routes, and recommit media; an old revoked grant stays revoked.
- Replacement never returns the old code, never partially retires the old room, and invalidates all old access before the new credentials are exposed.
- Raw credentials and private media/network identifiers never enter SQLite or logs. Corrupt, mismatched or multiply owned databases fail before service readiness.