UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.28 kB
export class AudioDesyncDetector{trackMonitor;name="audio-desync-detector";constructor(e){this.trackMonitor=e}lastDesyncDuration;_startedDesyncAt;_prevCorrectedSamples=0;get config(){return this.peerConnection.parent.config.audioDesyncDetector}get peerConnection(){return this.trackMonitor.getPeerConnection()}update(){const e=this.trackMonitor.getInboundRtp();if(!e||"audio"!==e.kind)return;if(this.config.disabled)return;const t=(e.insertedSamplesForDeceleration??0)+(e.removedSamplesForAcceleration??0)-this._prevCorrectedSamples;if(t<1||(e.receivingAudioSamples??0)<1)return;const n=t/(t+(e.receivingAudioSamples??0)),r=e.desync;e.desync?e.desync=this.config.fractionalCorrectionAlertOffThreshold<n:e.desync=this.config.fractionalCorrectionAlertOnThreshold<n,e.desync?r||(this._startedDesyncAt=Date.now(),this.peerConnection.parent.emit("audio-desync-track",{clientMonitor:this.peerConnection.parent,trackMonitor:this.trackMonitor}),this.config.createIssue&&this.peerConnection.parent.addIssue({type:"audio-desync",payload:{peerConnectionId:this.peerConnection.peerConnectionId,trackId:this.trackMonitor.track.id,dCorrectedSamples:t,fractionalCorrection:n}})):r&&(this._startedDesyncAt&&(this.lastDesyncDuration=Date.now()-this._startedDesyncAt),this._startedDesyncAt=void 0)}}