infobip-rtc
Version:
Infobip RTC JavaScript SDK - Infobip WebRTC API Implementation
47 lines • 2.01 kB
JavaScript
import { NetworkQuality } from "../../../call/event/NetworkQuality";
import { CodecWeights } from "./CodecWeights";
export class NetworkQualityStatistics {
constructor(mos = 0) {
this.mos = mos;
this.networkQuality = this.getNetworkQuality();
}
static forRTCStats(rtt, jitter, packetsReceived, packetsLost, codec) {
let mos = NetworkQualityStatistics.calculateMos(rtt, jitter, packetsReceived, packetsLost, codec);
return new NetworkQualityStatistics(mos);
}
static forMos(mos) {
return new NetworkQualityStatistics(mos);
}
static calculateMos(rtt, jitter, packetsReceived, packetsLost, codec) {
let codecDelay = 10.0;
let effectiveLatency = rtt + 2 * jitter + codecDelay;
let packetsSum = packetsLost + packetsReceived;
let percentagePacketsLost = packetsSum === 0 ? 0 : packetsLost * 100 / packetsSum;
let codecWeightFactor = CodecWeights.get(codec);
let transmissionRatingFactor = effectiveLatency < 160 ? 93.2 - (effectiveLatency / 40) : 93.2 - ((effectiveLatency - 120) / 10);
transmissionRatingFactor = transmissionRatingFactor - 2.5 * percentagePacketsLost * codecWeightFactor;
if (transmissionRatingFactor < 0) {
return 1.0;
}
let mos = 1 + 0.035 * transmissionRatingFactor + 0.000007 * transmissionRatingFactor * (transmissionRatingFactor - 60) * (100 - transmissionRatingFactor);
return Math.round((mos + Number.EPSILON) * 100) / 100;
}
getNetworkQuality() {
if (this.mos > 4.34) {
return NetworkQuality.EXCELLENT;
}
else if (this.mos > 4.03) {
return NetworkQuality.GOOD;
}
else if (this.mos > 3.6) {
return NetworkQuality.FAIR;
}
else if (this.mos > 3.1) {
return NetworkQuality.POOR;
}
else {
return NetworkQuality.BAD;
}
}
}
//# sourceMappingURL=NetworkQualityStatistics.js.map