UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.93 kB
import{Detectors as t}from"../detectors/Detectors";import{DryOutboundTrackDetector as e}from"../detectors/DryOutboundTrackDetector";export class OutboundTrackMonitor{track;_mediaSource;direction="outbound";detectors;mappedOutboundRtps=new Map;calculatedScore={weight:0,value:void 0};get score(){return this.calculatedScore.value}get scoreReasons(){return this.calculatedScore.reasons}attachments;appData;constructor(o,r,a){this.track=o,this._mediaSource=r,this.attachments=a,this.detectors=new t(new e(this)),"audio"===this.kind?this.calculatedScore.weight=1:"video"===this.kind&&(this.calculatedScore.weight=2)}getPeerConnection(){return this._mediaSource.getPeerConnection()}get kind(){return this.track.kind}bitrate;jitter;fractionLost;sendingPacketRate;remoteReceivedPacketRate;update(){this.bitrate=0,this.jitter=0,this.fractionLost=0,this.sendingPacketRate=0,this.remoteReceivedPacketRate=0;for(const t of this.mappedOutboundRtps.values())this.bitrate+=t.bitrate??0,this.jitter+=t.getRemoteInboundRtp()?.jitter??0,this.fractionLost+=t.getRemoteInboundRtp()?.fractionLost??0,this.sendingPacketRate+=t.packetRate??0,this.remoteReceivedPacketRate+=t.getRemoteInboundRtp()?.packetRate??0;this.detectors.update()}getOutboundRtps(){return Array.from(this.mappedOutboundRtps.values())}getHighestLayer(){const t=Array.from(this.mappedOutboundRtps.values());if(0===t.length)return;if(1===t.length)return t[0];let e,o=0;for(const t of this.mappedOutboundRtps.values())t.bitrate&&t.bitrate>o&&(e=t,o=t.bitrate);return e}createSample(){let t;return"audio"===this.kind?t=this.getPeerConnection()?.parent.scoreCalculator?.encodeOutboundAudioScoreReasons?.(this.calculatedScore.reasons):"video"===this.kind&&(t=this.getPeerConnection()?.parent.scoreCalculator?.encodeOutboundVideoScoreReasons?.(this.calculatedScore.reasons)),{id:this.track.id,kind:this.kind,timestamp:Date.now(),attachments:this.attachments,score:this.score,scoreReasons:t}}}