UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.49 kB
export class DryInboundTrackDetector{trackMonitor;static ISSUE_TYPE="dry-inbound-track";name="dry-inbound-track-detector";disabled=!1;issueKey;constructor(t){this.trackMonitor=t,this.issueKey=`${DryInboundTrackDetector.ISSUE_TYPE}-track-${t.track.id}`}_evented=!1;_startedDryAt;get peerConnection(){return this.trackMonitor.getPeerConnection()}get config(){return this.peerConnection.parent.config.dryInboundTrackDetector}_activatedAt;update(){if(this.disabled)return;if(this.trackMonitor.remoteOutboundTrackPaused)return void(this._activatedAt=void 0);if(0!==this.trackMonitor.getInboundRtp()?.deltaBytesReceived)return this._activatedAt=void 0,void(this._evented&&(this._resolve("dry inbound track recovered"),this._evented=!1));this._activatedAt||(this._activatedAt=Date.now());const t=Date.now()-this._activatedAt,e=this.peerConnection.parent;t<this.config.thresholdInMs||this._evented||(e.emit("dry-inbound-track",{trackMonitor:this.trackMonitor,clientMonitor:e}),this._raise({trackId:this.trackMonitor.track.id,duration:t}),this._evented=!0)}_raise(t){this._startedDryAt=this._startedDryAt??Date.now(),this.peerConnection.parent.raiseIssue(this.issueKey,{type:DryInboundTrackDetector.ISSUE_TYPE,payload:t})}_resolve(t){const e=this.peerConnection.parent,r=e.activeIssues.get(this.issueKey);let i;r&&(i={...r.payload,durationInMs:this._startedDryAt?Date.now()-this._startedDryAt:void 0}),e.resolveIssue(this.issueKey,{comment:t,payload:i,resolvedAt:Date.now()}),this._startedDryAt=void 0}}