/** Media progress and capture freshness are independent of DOM painting and inventory SSE. */ export class PreviewLiveness { private lastFrame:number|null=null; private sourceSeen=Number.NEGATIVE_INFINITY; private staleSince:number|null=null; private connectedAt:number|null=null; private budgetPauseUntil=0; private budgetResumeAt:number|null=null; constructor(private negotiatedAt:number){} negotiated(now:number){this.negotiatedAt=now;} connected(now:number){this.connectedAt??=now;} frame(now:number){this.connected(now);this.lastFrame=now;} allocation(paused:boolean,now:number){ if(paused)this.budgetPauseUntil=now+3000; else if(this.budgetPauseUntil){this.budgetPauseUntil=0;this.budgetResumeAt=now;} } source(fresh:boolean,now:number){ this.sourceSeen=now; this.staleSince=fresh?null:this.staleSince??now; } state(now:number):'connecting'|'live'|'waiting'|'delayed'|'source-stalled'|'peer-stalled'{ // SDP is only signaling. ICE/DTLS can still be establishing the private route. if(this.connectedAt===null)return now-this.negotiatedAt>30000?'peer-stalled':'connecting'; if(this.staleSince!==null&&now-this.sourceSeen<3000){ return now-this.staleSince>=12000?'source-stalled':'delayed'; } // A fresh allocation pause is not a dead peer and never claims live imagery. // Missing hints still expire normally; actual source-stall evidence wins above. if(now(this.lastFrame===null?8000:30000))return 'peer-stalled'; if(this.lastFrame===null)return 'waiting'; return elapsed>2000?'delayed':'live'; } }