## Problem and outcome / 问题与结果 This maintenance phase fixes failures around native capture startup, room reconnection and media handoffs. Capture mutations stay cancellable, relayed-content failures remain request-scoped, and failed media connections return to the existing route controller. Windows Auto codec selection measures delivered cadence instead of timer-sensitive per-frame work estimates. The phase preserves P2P-first routing, one committed graph and one route operation. It adds no signaling replay mechanism, changes no wire/schema version, and includes no interaction prototype or 4K feature work. ## Release notes ### 中文 Piik v1.6.8 是一次稳定性修复,重点改善 Windows 原生采集、断线恢复和分享过程中的控制响应。 #### 修复与改善 - **更准确地选择编码器。** Windows 的自动模式按实际出帧表现评估 H.264,并正确区分启动预热和持续性能不足,减少计时误差导致的不必要 VP8 回退。硬件编码事件改为异步等待。 - **改善断线与线路切换。** 房间信令短暂断开后保留观众成员身份 20 秒;修复线路切换、SFU 订阅恢复及声音重协商卡住的问题。失效连接及时交回现有路由控制器处理,原生 SFU 发送端不再把短暂断连直接判为终止。 - **保持 App 控制响应。** 开始分享和更换来源时仍可取消操作;合法消息突发不再直接关闭控制连接。中继信令的单条内容错误不会连带结束整场原生分享。 - **修正设备列表与配置保存。** 来源或麦克风数量达到上限时保留可用列表;配置替换失败时保留原有设置。 - **改善紧凑布局和辅助功能。** 调整手机横屏下的画面与播控布局、画质预设标签和长邀请链接显示,修正部分提示与辅助功能语义。 - **加强站点访问保护。** 站点登录 Cookie 使用独立随机签名密钥,应用自身阻止被其他页面嵌套。发布说明也会在合并前检查。 #### 升级说明 通信协议和持久化格式保持不变。设置了站点密码时,App 或 Server 重启后需要重新输入站点密码;持久化房间和邀请授权不受这项 Cookie 调整影响。Piik 操作页面不再支持嵌入 iframe。 ### English Piik v1.6.8 is a stability update focused on Windows native capture, connection recovery and responsive sharing controls. #### Fixes and improvements - **More accurate codec selection.** Windows Auto mode evaluates H.264 using delivered frames and distinguishes startup warmup from sustained performance limits, reducing unnecessary VP8 fallback caused by timing noise. Hardware encoder events now use asynchronous waiting. - **Improved reconnection and route handoffs.** Viewer membership survives brief signaling outages for 20 seconds. Fixes cover route activation, SFU subscription recovery and stalled audio renegotiation. Failed connections return to the existing route controller, and the native SFU publisher no longer treats a transient disconnect as immediate termination. - **Responsive App controls.** Starting a share and replacing its source remain cancellable. Valid message bursts no longer close the control connection, and an invalid relayed payload cannot terminate the entire native sharing session. - **Device lists and saved settings.** Source and microphone enumeration retain a usable list at their limits. Failed configuration replacement preserves the previous settings. - **Compact layouts and accessibility.** Improved picture and playback-control layout on landscape phones, quality preset labels and long invitation links, with corrected tooltip and accessibility semantics. - **Stronger site-access protection.** Login cookies use an independent random signing key, and the application prevents embedding by other pages. Release notes are also checked before merge. #### Upgrade notes Wire protocols and persistent formats are unchanged. If a site password is configured, restarting the App or Server requires entering it again; this cookie change does not revoke persisted rooms or invitation grants. Piik operation pages can no longer be embedded in an iframe. ## Verification / 验证 - `npm run check`: passed, 76 test files / 1,171 tests, TypeScript and production Web build. - `npm run check:go-core`: passed; full Go/native checks also passed during integration of the capture changes. macOS cgo builds remain native-runner checks. - Windows native Host gates: Auto, H.264 and VP8 passed during the phase; final control changes rechecked with Auto, including live/paused quality, source replacement, failure retirement and subsequent sharing. - Embedded SFU browser VP8 recovery: passed with production Host/Viewer route owners. - Embedded SFU native H.264, two rooms: passed, including recovered decoded video/audio, independent room retirement and resource cleanup. - Documentation, repository hygiene and diff checks: passed. Final follow-up changes only align operations documentation with the PR note check. - Go race checks could not run locally because no cgo/GCC toolchain is available; the existing Linux CI race job remains required. AMD/Intel hardware, broader device combinations, public-NAT field reports and long endurance are not established by these local checks. ## Impact / 影响 Compatible patch release after v1.6.7. The cookie and frame-protection effects are disclosed in the public upgrade notes. No automatic retry budget, room-code admission policy, room lifetime or media topology is replaced. Reports without matched diagnostics and unmeasured native performance costs remain in the TODO ledger.
317 lines
10 KiB
Go
317 lines
10 KiB
Go
package route
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/TNTcraftHIM/Piik/internal/server/protocol"
|
|
)
|
|
|
|
// A confirmed departure ends media authority even while acquisition is paused
|
|
// or descendants still need the old graph anchor to find a replacement.
|
|
func (c *Controller) retireDepartedEdges(nowMs int64) []*Resource {
|
|
released := []*Resource{}
|
|
changed := false
|
|
for peerID, edge := range c.upstreamByViewer.All() {
|
|
current, _ := c.participants.Get(peerID)
|
|
if current == nil || !current.departureConfirmed || !edge.PhysicalActive {
|
|
continue
|
|
}
|
|
if !changed {
|
|
// Active and prepared assignments share one revision sequence. Retire
|
|
// the candidate before publishing a newer active graph; its late ACK
|
|
// must not commit an older revision or restore the departed route.
|
|
released = append(released, c.abortOperation(&nowMs, RejectionAborted)...)
|
|
}
|
|
changed = true
|
|
if edge.Kind == UpstreamSfu {
|
|
c.retireSfuEdge(peerID, edge, &released, c.retainsAnchor(peerID))
|
|
} else {
|
|
edge.PhysicalActive = false
|
|
edge.Usable = false
|
|
}
|
|
}
|
|
if changed {
|
|
if !c.hasSfuSubscribers() && c.hostPublication != nil {
|
|
c.clearSfuQuality()
|
|
if c.hostPublication.PhysicalActive {
|
|
released = append(released, c.hostPublication.Resource)
|
|
}
|
|
c.hostPublication = nil
|
|
}
|
|
c.pruneRetiringSfuAnchors()
|
|
c.revision = c.allocateRevision()
|
|
c.touchFacts()
|
|
}
|
|
return released
|
|
}
|
|
|
|
// pruneDepartedLeaves removes departed viewers without
|
|
// children to a fixpoint, in participants order, and drops an
|
|
// orphaned publication.
|
|
func (c *Controller) pruneDepartedLeaves(released *[]*Resource) []string {
|
|
removed := []string{}
|
|
changed := true
|
|
for changed {
|
|
changed = false
|
|
// Live iteration: deleting the visited entry is JS-safe (ordered.Map.All).
|
|
for _, current := range c.participants.All() {
|
|
if current.role != protocol.RoleViewer || !current.departureConfirmed || len(c.childrenOf(current.peerID)) > 0 {
|
|
continue
|
|
}
|
|
edge, _ := c.upstreamByViewer.Get(current.peerID)
|
|
if edge != nil && edge.Kind == UpstreamSfu {
|
|
c.retireSfuEdge(current.peerID, edge, released, false)
|
|
} else {
|
|
c.upstreamByViewer.Delete(current.peerID)
|
|
}
|
|
c.clearQualityForParticipant(current.peerID)
|
|
c.participants.Delete(current.peerID)
|
|
delete(c.routeTimings, current.peerID)
|
|
c.directContinuations.Delete(current.peerID)
|
|
c.clearSfuBootstrapForDemand(current.peerID)
|
|
removed = append(removed, current.peerID)
|
|
changed = true
|
|
}
|
|
}
|
|
if len(removed) > 0 {
|
|
if !c.hasSfuSubscribers() && c.hostPublication != nil {
|
|
c.clearSfuQuality()
|
|
if c.hostPublication.PhysicalActive {
|
|
*released = append(*released, c.hostPublication.Resource)
|
|
}
|
|
c.hostPublication = nil
|
|
}
|
|
c.revision = c.allocateRevision()
|
|
c.touchFacts()
|
|
c.pruneRetiringSfuAnchors()
|
|
}
|
|
return removed
|
|
}
|
|
|
|
func (c *Controller) retireInvalidOperationEdge(childPeerID string, released *[]*Resource) bool {
|
|
edge, _ := c.upstreamByViewer.Get(childPeerID)
|
|
if edge == nil || !c.edgeRequiresMove(childPeerID, edge) {
|
|
return false
|
|
}
|
|
if edge.Kind == UpstreamSfu {
|
|
c.retireSfuEdge(childPeerID, edge, released, c.retainsAnchor(childPeerID))
|
|
c.pruneRetiringSfuAnchors()
|
|
} else {
|
|
edge.PhysicalActive = false
|
|
edge.Usable = false
|
|
}
|
|
if edge.Kind == UpstreamSfu && !c.hasSfuSubscribers() && c.hostPublication != nil {
|
|
publication := c.hostPublication
|
|
if publication.PhysicalActive {
|
|
*released = append(*released, publication.Resource)
|
|
}
|
|
publication.PhysicalActive = false
|
|
publication.Usable = false
|
|
c.hostPublication = nil
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (c *Controller) edgeRequiresMove(childPeerID string, edge *CommittedEdge) bool {
|
|
if !edge.Usable || !edge.PhysicalActive {
|
|
return true
|
|
}
|
|
if edge.Kind == UpstreamSfu {
|
|
return c.hostPublication == nil || !c.hostPublication.Usable ||
|
|
!c.hostPublication.PhysicalActive ||
|
|
c.hostPublication.Generation != edge.PublicationGeneration
|
|
}
|
|
if parent, ok := c.participants.Get(edge.ParentPeerID); ok && parent.departureConfirmed {
|
|
return true
|
|
}
|
|
for _, overflowing := range c.overflowPeerChildren(edge.ParentPeerID) {
|
|
if overflowing == childPeerID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// rebindCommittedSession preserves the reconnecting peer's edges and
|
|
// publication, updating them to its new session ID.
|
|
func (c *Controller) rebindCommittedSession(peerID, sessionID string) {
|
|
if ownEdge, ok := c.upstreamByViewer.Get(peerID); ok {
|
|
ownEdge.ChildSessionID = sessionID
|
|
}
|
|
for _, edge := range c.upstreamByViewer.Values() {
|
|
if edge.Kind != UpstreamPeer || edge.ParentPeerID != peerID {
|
|
continue
|
|
}
|
|
edge.ParentSessionID = sessionID
|
|
}
|
|
if peerID == c.hostPeerID && c.hostPublication != nil {
|
|
c.hostPublication.HostSessionID = sessionID
|
|
}
|
|
}
|
|
|
|
func (c *Controller) removePublicationGeneration(generation string) []*Resource {
|
|
released := []*Resource{}
|
|
for viewerPeerID, edge := range c.upstreamByViewer.All() {
|
|
if edge.Kind != UpstreamSfu || edge.PublicationGeneration != generation {
|
|
continue
|
|
}
|
|
c.retireSfuEdge(viewerPeerID, edge, &released, c.retainsAnchor(viewerPeerID))
|
|
}
|
|
if c.hostPublication != nil && c.hostPublication.Generation == generation {
|
|
if c.hostPublication.PhysicalActive {
|
|
released = append(released, c.hostPublication.Resource)
|
|
}
|
|
c.hostPublication = nil
|
|
}
|
|
c.pruneRetiringSfuAnchors()
|
|
return released
|
|
}
|
|
|
|
// retainsAnchor is the TS default argument of retireSfuEdge
|
|
// (`this.childrenOf(viewerPeerId).length > 0`), evaluated at call time.
|
|
func (c *Controller) retainsAnchor(viewerPeerID string) bool {
|
|
return len(c.childrenOf(viewerPeerID)) > 0
|
|
}
|
|
|
|
// retireSfuEdge releases the subscription only while it is
|
|
// still physically active, then keeps the edge as an anchor for attached
|
|
// peer descendants or deletes it.
|
|
func (c *Controller) retireSfuEdge(viewerPeerID string, edge *CommittedEdge, released *[]*Resource, retainAnchor bool) {
|
|
if edge.PhysicalActive {
|
|
*released = append(*released, edge.Resource)
|
|
}
|
|
c.clearQualityForParticipant(viewerPeerID)
|
|
if retainAnchor {
|
|
edge.Usable = false
|
|
edge.PhysicalActive = false
|
|
c.retiringPublicationGenerations.Set(edge.PublicationGeneration, struct{}{})
|
|
} else {
|
|
c.upstreamByViewer.Delete(viewerPeerID)
|
|
}
|
|
}
|
|
|
|
// hasRetiringAnchor reports whether an inactive SFU edge still references
|
|
// the generation (the `some` at 4816 and 4880).
|
|
func (c *Controller) hasRetiringAnchor(generation string) bool {
|
|
for _, edge := range c.upstreamByViewer.Values() {
|
|
if edge.Kind == UpstreamSfu && !edge.PhysicalActive && edge.PublicationGeneration == generation {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (c *Controller) pruneRetiringSfuAnchors() {
|
|
removed := true
|
|
for removed {
|
|
removed = false
|
|
for viewerPeerID, edge := range c.upstreamByViewer.All() {
|
|
if edge.Kind == UpstreamSfu &&
|
|
!edge.PhysicalActive &&
|
|
c.retiringPublicationGenerations.Has(edge.PublicationGeneration) &&
|
|
len(c.childrenOf(viewerPeerID)) == 0 {
|
|
c.upstreamByViewer.Delete(viewerPeerID)
|
|
removed = true
|
|
}
|
|
}
|
|
}
|
|
for generation := range c.retiringPublicationGenerations.All() {
|
|
if !c.hasRetiringAnchor(generation) {
|
|
c.retiringPublicationGenerations.Delete(generation)
|
|
}
|
|
}
|
|
}
|
|
|
|
// assertGraph panics on programming errors. Edge insertion order and
|
|
// participant order determine which violation is reported first.
|
|
func (c *Controller) assertGraph() {
|
|
host, _ := c.participants.Get(c.hostPeerID)
|
|
if host == nil || host.role != protocol.RoleHost {
|
|
panic(errors.New("Route Host is missing"))
|
|
}
|
|
for child, edge := range c.upstreamByViewer.All() {
|
|
c.assertViewer(child)
|
|
if edge.Kind == UpstreamPeer && !c.participants.Has(edge.ParentPeerID) {
|
|
panic(errors.New("Route parent is missing"))
|
|
}
|
|
if edge.Kind == UpstreamSfu && edge.PhysicalActive &&
|
|
(c.hostPublication == nil || c.hostPublication.Generation != edge.PublicationGeneration) {
|
|
panic(errors.New("SFU publication is stale"))
|
|
}
|
|
if edge.Kind == UpstreamSfu && !edge.PhysicalActive &&
|
|
!c.retiringPublicationGenerations.Has(edge.PublicationGeneration) {
|
|
panic(errors.New("Retiring SFU publication is unknown"))
|
|
}
|
|
seen := make(map[string]struct{})
|
|
current := child
|
|
for current != c.hostPeerID {
|
|
if _, visited := seen[current]; visited {
|
|
panic(errors.New("Peer route contains a cycle"))
|
|
}
|
|
seen[current] = struct{}{}
|
|
currentEdge, ok := c.upstreamByViewer.Get(current)
|
|
if !ok {
|
|
panic(errors.New("Route is not source-reachable"))
|
|
}
|
|
if currentEdge.Kind == UpstreamSfu {
|
|
var unknown bool
|
|
if currentEdge.PhysicalActive {
|
|
unknown = c.hostPublication == nil || c.hostPublication.Generation != currentEdge.PublicationGeneration
|
|
} else {
|
|
unknown = !c.retiringPublicationGenerations.Has(currentEdge.PublicationGeneration)
|
|
}
|
|
if unknown {
|
|
panic(errors.New("Route terminates at an unknown SFU publication"))
|
|
}
|
|
break
|
|
}
|
|
current = currentEdge.ParentPeerID
|
|
}
|
|
}
|
|
for _, current := range c.participants.Values() {
|
|
if !protocol.EndpointMediaCopyCountFits(c.usedSlots(current.peerID), c.endpointMediaCopyCapacity, protocol.EndpointMediaCopySteady) {
|
|
panic(errors.New("Committed route exceeds endpoint capacity"))
|
|
}
|
|
}
|
|
for generation := range c.retiringPublicationGenerations.All() {
|
|
if !c.hasRetiringAnchor(generation) {
|
|
panic(errors.New("Retiring SFU publication has no anchor"))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (c *Controller) assertViewer(peerID string) {
|
|
if current, ok := c.participants.Get(peerID); !ok || current.role != protocol.RoleViewer {
|
|
panic(errors.New("Route child must be a Viewer"))
|
|
}
|
|
}
|
|
|
|
func (c *Controller) hasSfuSubscribers() bool {
|
|
return c.sfuSubscriberCount() > 0
|
|
}
|
|
|
|
func (c *Controller) sfuSubscriberCount() int {
|
|
count := 0
|
|
for _, edge := range c.upstreamByViewer.Values() {
|
|
if edge.Kind == UpstreamSfu && edge.PhysicalActive {
|
|
count++
|
|
}
|
|
}
|
|
return count
|
|
}
|
|
|
|
// committedResources returns SFU subscriptions in map order, then the
|
|
// publication.
|
|
func (c *Controller) committedResources() []*Resource {
|
|
resources := []*Resource{}
|
|
for _, edge := range c.upstreamByViewer.Values() {
|
|
if edge.Kind == UpstreamSfu && edge.PhysicalActive {
|
|
resources = append(resources, edge.Resource)
|
|
}
|
|
}
|
|
if c.hostPublication != nil && c.hostPublication.PhysicalActive {
|
|
resources = append(resources, c.hostPublication.Resource)
|
|
}
|
|
return resources
|
|
}
|