@observertc/observer-js
Version:
Server Side NodeJS Library for processing ObserveRTC Samples
93 lines (92 loc) • 2.78 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObservedInboundTrack = void 0;
const Detectors_1 = require("./detectors/Detectors");
class ObservedInboundTrack {
timestamp;
id;
kind;
_peerConnection;
_inboundRtp;
_mediaPlayout;
detectors;
calculatedScore = {
weight: 1,
value: undefined,
};
appData;
report;
_visited = false;
addedAt;
removedAt;
muted;
attachments;
constructor(timestamp, id, kind, _peerConnection, _inboundRtp, _mediaPlayout) {
this.timestamp = timestamp;
this.id = id;
this.kind = kind;
this._peerConnection = _peerConnection;
this._inboundRtp = _inboundRtp;
this._mediaPlayout = _mediaPlayout;
this.detectors = new Detectors_1.Detectors();
this.report = {
trackId: this.id,
kind: this.kind,
fractionLostDistribution: {
gtOrEq050: 0,
lt001: 0,
lt005: 0,
lt010: 0,
lt020: 0,
lt050: 0,
count: 0,
sum: 0,
},
};
}
get score() {
return this.calculatedScore.value;
}
get visited() {
const visited = this._visited;
this._visited = false;
return visited;
}
getPeerConnection() {
return this._peerConnection;
}
getInboundRtp() {
return this._inboundRtp;
}
getMediaPlayout() {
return this._mediaPlayout;
}
getRemoteOutboundTrack() {
return this._peerConnection.client.call.remoteTrackResolver?.resolveRemoteOutboundTrack(this);
}
update(stats) {
this._visited = true;
this.timestamp = stats.timestamp;
this.calculatedScore.value = stats.score;
this.attachments = stats.attachments;
const fl = this._inboundRtp?.fractionLost;
if (fl !== undefined) {
if (fl < 0.01)
this.report.fractionLostDistribution.lt001 += 1;
else if (fl < 0.05)
this.report.fractionLostDistribution.lt005 += 1;
else if (fl < 0.1)
this.report.fractionLostDistribution.lt010 += 1;
else if (fl < 0.2)
this.report.fractionLostDistribution.lt020 += 1;
else if (fl < 0.5)
this.report.fractionLostDistribution.lt050 += 1;
else
this.report.fractionLostDistribution.gtOrEq050 += 1;
this.report.fractionLostDistribution.count += 1;
this.report.fractionLostDistribution.sum += fl;
}
this.detectors.update();
}
}
exports.ObservedInboundTrack = ObservedInboundTrack;