@observertc/client-monitor-js
Version:
ObserveRTC Client Integration Javascript Library
1 lines • 1.78 kB
JavaScript
import{positiveDelta as t}from"../utils/common";export class MediaSourceMonitor{_peerConnection;_visited=!0;timestamp;id;kind;audioLevel;trackIdentifier;totalAudioEnergy;totalSamplesDuration;echoReturnLoss;echoReturnLossEnhancement;width;height;frames;framesPerSecond;deltaFrames;deltaTotalAudioEnergy;deltaSamplesDuration;sourceFps;rmsAudioLevel;attachments;appData;constructor(t,e){this._peerConnection=t,this.id=e.id,this.timestamp=e.timestamp,this.kind=e.kind,Object.assign(this,e)}get visited(){const t=this._visited;return this._visited=!1,t}getPeerConnection(){return this._peerConnection}getTrack(){return this._peerConnection.mappedOutboundTracks.get(this.trackIdentifier??"")}getOutboundRtps(){return this._peerConnection.outboundRtps.filter((t=>t.mediaSourceId===this.id))}accept(e){this._visited=!0;const i=e.timestamp-this.timestamp;if(i<=0)return;const s=i/1e3;this.deltaFrames=t(e.frames,this.frames),this.deltaTotalAudioEnergy=t(e.totalAudioEnergy,this.totalAudioEnergy),this.deltaSamplesDuration=t(e.totalSamplesDuration,this.totalSamplesDuration),this.sourceFps=void 0!==this.deltaFrames?this.deltaFrames/s:void 0,this.rmsAudioLevel=void 0!==this.deltaTotalAudioEnergy&&void 0!==this.deltaSamplesDuration&&this.deltaSamplesDuration>0?Math.sqrt(this.deltaTotalAudioEnergy/this.deltaSamplesDuration):void 0,Object.assign(this,e)}createSample(){return{id:this.id,timestamp:this.timestamp,kind:this.kind,audioLevel:this.audioLevel,trackIdentifier:this.trackIdentifier,totalAudioEnergy:this.totalAudioEnergy,totalSamplesDuration:this.totalSamplesDuration,echoReturnLoss:this.echoReturnLoss,echoReturnLossEnhancement:this.echoReturnLossEnhancement,width:this.width,height:this.height,frames:this.frames,framesPerSecond:this.framesPerSecond,attachments:this.attachments}}}