UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 7.19 kB
export class InboundRtpMonitor{_peerConnection;_visited=!0;addedAt=Date.now();timestamp;id;ssrc;kind;trackIdentifier;transportId;codecId;packetsReceived;packetsLost;jitter;mid;remoteId;framesDecoded;keyFramesDecoded;framesRendered;framesDropped;frameWidth;frameHeight;framesPerSecond;qpSum;totalDecodeTime;totalInterFrameDelay;totalSquaredInterFrameDelay;pauseCount;totalPausesDuration;freezeCount;totalFreezesDuration;lastPacketReceivedTimestamp;headerBytesReceived;packetsDiscarded;fecBytesReceived;fecPacketsReceived;fecPacketsDiscarded;bytesReceived;nackCount;firCount;pliCount;totalProcessingDelay;estimatedPlayoutTimestamp;jitterBufferDelay;jitterBufferTargetDelay;jitterBufferEmittedCount;jitterBufferMinimumDelay;totalSamplesReceived;concealedSamples;silentConcealedSamples;concealmentEvents;insertedSamplesForDeceleration;removedSamplesForAcceleration;audioLevel;totalAudioEnergy;totalSamplesDuration;framesReceived;decoderImplementation;playoutId;powerEfficientDecoder;framesAssembledFromMultiplePackets;totalAssemblyTime;retransmittedPacketsReceived;retransmittedBytesReceived;rtxSsrc;fecSsrc;totalCorruptionProbability;totalSquaredCorruptionProbability;corruptionMeasurements;bitrate;isFreezed;desync;avgFramesPerSec;fpsVolatility;lastNFramesPerSec=[];receivingAudioSamples;fractionLost;bitPerPixel;packetRate;ewmaFps;deltaPacketsLost;deltaPacketsReceived;deltaBytesReceived;deltaJitterBufferDelay;deltaCorruptionProbability;deltaFramesDecoded;deltaFramesReceived;deltaFramesRendered;deltaTime;attachments;appData;constructor(e,t){this._peerConnection=e,this.id=t.id,this.timestamp=t.timestamp,this.ssrc=t.ssrc,this.kind=t.kind,this.trackIdentifier=t.trackIdentifier,Object.assign(this,t)}get visited(){const e=this._visited;return this._visited=!1,e}getPeerConnection(){return this._peerConnection}accept(e){this._visited=!0;const t=e.timestamp-this.timestamp;if(t<=0)return void Object.assign(this,e);const i=t/1e3;if(this.totalSamplesReceived&&e.totalSamplesReceived&&(this.receivingAudioSamples=e.totalSamplesReceived-this.totalSamplesReceived),this.bytesReceived&&e.bytesReceived&&(this.deltaBytesReceived=e.bytesReceived-this.bytesReceived,this.bitrate=Math.max(0,8*this.deltaBytesReceived/i)),void 0!==this.packetsLost&&void 0!==e.packetsLost&&(this.deltaPacketsLost=e.packetsLost-this.packetsLost),void 0!==this.packetsReceived&&void 0!==e.packetsReceived&&(this.deltaPacketsReceived=e.packetsReceived-this.packetsReceived,this.packetRate=this.deltaPacketsReceived/i),void 0!==this.totalCorruptionProbability&&void 0!==e.totalCorruptionProbability&&void 0!==this.corruptionMeasurements&&void 0!==e.corruptionMeasurements){const t=e.totalCorruptionProbability-this.totalCorruptionProbability,i=Math.max(1,e.corruptionMeasurements-this.corruptionMeasurements);this.deltaCorruptionProbability=Math.max(0,t/i)}if(void 0!==this.jitterBufferDelay&&void 0!==e.jitterBufferDelay&&(this.deltaJitterBufferDelay=e.jitterBufferDelay-this.jitterBufferDelay),void 0!==this.framesDecoded&&void 0!==e.framesDecoded&&(this.deltaFramesDecoded=e.framesDecoded-this.framesDecoded),void 0!==this.framesReceived&&void 0!==e.framesReceived&&(this.deltaFramesReceived=e.framesReceived-this.framesReceived),void 0!==this.framesRendered&&void 0!==e.framesRendered&&(this.deltaFramesRendered=e.framesRendered-this.framesRendered),this.deltaTime=t,Object.assign(this,e),this.framesPerSecond){this.lastNFramesPerSec.push(this.framesPerSecond),this.lastNFramesPerSec.length>10&&this.lastNFramesPerSec.shift();const e=this.lastNFramesPerSec.reduce(((e,t)=>e+t),0)/this.lastNFramesPerSec.length,t=this.lastNFramesPerSec.reduce(((t,i)=>t+Math.abs(i-e)),0)/this.lastNFramesPerSec.length;this.avgFramesPerSec=e,this.fpsVolatility=t/e,this.bitrate&&this.frameWidth&&this.frameHeight&&(this.bitPerPixel=this.bitrate/(this.frameWidth*this.frameHeight))}void 0!==this.packetsReceived&&void 0!==this.packetsLost&&(this.fractionLost=0<this.packetsReceived&&0<this.packetsLost?this.packetsLost/(this.packetsLost+this.packetsReceived):0),void 0!==this.framesDecoded&&(this.ewmaFps=this.ewmaFps?.9*this.ewmaFps+.1*this.framesDecoded:this.framesDecoded)}getRemoteOutboundRtp(){return this._peerConnection.mappedRemoteOutboundRtpMonitors.get(this.ssrc)}getIceTransport(){return this._peerConnection.mappedIceTransportMonitors.get(this.transportId??"")}getCodec(){return this._peerConnection.mappedCodecMonitors.get(this.codecId??"")}getMediaPlayout(){return this._peerConnection.mappedMediaPlayoutMonitors.get(this.playoutId??"")}getTrack(){return this._peerConnection.mappedInboundTracks.get(this.trackIdentifier)}createSample(){return{timestamp:this.timestamp,id:this.id,ssrc:this.ssrc,kind:this.kind,trackIdentifier:this.trackIdentifier,transportId:this.transportId,codecId:this.codecId,packetsReceived:this.packetsReceived,packetsLost:this.packetsLost,jitter:this.jitter,mid:this.mid,remoteId:this.remoteId,framesDecoded:this.framesDecoded,keyFramesDecoded:this.keyFramesDecoded,framesRendered:this.framesRendered,framesDropped:this.framesDropped,frameWidth:this.frameWidth,frameHeight:this.frameHeight,framesPerSecond:this.framesPerSecond,qpSum:this.qpSum,totalDecodeTime:this.totalDecodeTime,totalInterFrameDelay:this.totalInterFrameDelay,totalSquaredInterFrameDelay:this.totalSquaredInterFrameDelay,pauseCount:this.pauseCount,totalPausesDuration:this.totalPausesDuration,freezeCount:this.freezeCount,totalFreezesDuration:this.totalFreezesDuration,lastPacketReceivedTimestamp:this.lastPacketReceivedTimestamp,headerBytesReceived:this.headerBytesReceived,packetsDiscarded:this.packetsDiscarded,fecBytesReceived:this.fecBytesReceived,fecPacketsReceived:this.fecPacketsReceived,fecPacketsDiscarded:this.fecPacketsDiscarded,bytesReceived:this.bytesReceived,nackCount:this.nackCount,firCount:this.firCount,pliCount:this.pliCount,totalProcessingDelay:this.totalProcessingDelay,estimatedPlayoutTimestamp:this.estimatedPlayoutTimestamp,jitterBufferDelay:this.jitterBufferDelay,jitterBufferTargetDelay:this.jitterBufferTargetDelay,jitterBufferEmittedCount:this.jitterBufferEmittedCount,jitterBufferMinimumDelay:this.jitterBufferMinimumDelay,totalSamplesReceived:this.totalSamplesReceived,concealedSamples:this.concealedSamples,silentConcealedSamples:this.silentConcealedSamples,concealmentEvents:this.concealmentEvents,insertedSamplesForDeceleration:this.insertedSamplesForDeceleration,removedSamplesForAcceleration:this.removedSamplesForAcceleration,audioLevel:this.audioLevel,totalAudioEnergy:this.totalAudioEnergy,totalSamplesDuration:this.totalSamplesDuration,framesReceived:this.framesReceived,decoderImplementation:this.decoderImplementation,playoutId:this.playoutId,powerEfficientDecoder:this.powerEfficientDecoder,framesAssembledFromMultiplePackets:this.framesAssembledFromMultiplePackets,totalAssemblyTime:this.totalAssemblyTime,retransmittedPacketsReceived:this.retransmittedPacketsReceived,retransmittedBytesReceived:this.retransmittedBytesReceived,rtxSsrc:this.rtxSsrc,fecSsrc:this.fecSsrc,totalCorruptionProbability:this.totalCorruptionProbability,totalSquaredCorruptionProbability:this.totalSquaredCorruptionProbability,corruptionMeasurements:this.corruptionMeasurements,attachments:this.attachments}}}