UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 2.15 kB
import{Detectors as t}from"../detectors/Detectors";import{SynthesizedSamplesDetector as e}from"../detectors/SynthesizedSamplesDetector";import{positiveDelta as s}from"../utils/common";export class MediaPlayoutMonitor{_peerConnection;_visited=!0;detectors=new t;timestamp;id;kind;synthesizedSamplesDuration;synthesizedSamplesEvents;totalSamplesDuration;totalPlayoutDelay;totalSamplesCount;deltaSynthesizedSamplesDuration=0;deltaSamplesDuration=0;deltaSynthesizedSamplesEvents;deltaTotalPlayoutDelay;deltaSamplesCount;playoutDelayPerSampleInMs;synthesizedSamplesRatio;attachments;appData;constructor(t,s){this._peerConnection=t,this.id=s.id,this.timestamp=s.timestamp,this.kind=s.kind,Object.assign(this,s),null!==this._peerConnection.parent.config.syntheticSamplesDetector&&this.detectors.add(new e(this))}get visited(){const t=this._visited;return this._visited=!1,t}getPeerConnection(){return this._peerConnection}accept(t){this._visited=!0;t.timestamp-this.timestamp<=0||(this.deltaSynthesizedSamplesDuration=s(t.synthesizedSamplesDuration,this.synthesizedSamplesDuration)??0,this.deltaSamplesDuration=s(t.totalSamplesDuration,this.totalSamplesDuration)??0,this.deltaSynthesizedSamplesEvents=s(t.synthesizedSamplesEvents,this.synthesizedSamplesEvents),this.deltaTotalPlayoutDelay=s(t.totalPlayoutDelay,this.totalPlayoutDelay),this.deltaSamplesCount=s(t.totalSamplesCount,this.totalSamplesCount),void 0!==this.deltaTotalPlayoutDelay&&void 0!==this.deltaSamplesCount&&this.deltaSamplesCount>0?this.playoutDelayPerSampleInMs=1e3*this.deltaTotalPlayoutDelay/this.deltaSamplesCount:this.playoutDelayPerSampleInMs=void 0,this.synthesizedSamplesRatio=this.deltaSamplesDuration>0?Math.min(1,this.deltaSynthesizedSamplesDuration/this.deltaSamplesDuration):0,Object.assign(this,t),this.detectors.update())}createSample(){return{id:this.id,timestamp:this.timestamp,kind:this.kind,synthesizedSamplesDuration:this.synthesizedSamplesDuration,synthesizedSamplesEvents:this.synthesizedSamplesEvents,totalSamplesDuration:this.totalSamplesDuration,totalPlayoutDelay:this.totalPlayoutDelay,totalSamplesCount:this.totalSamplesCount,attachments:this.attachments}}}