sinch-rtc
Version:
RTC JavaScript/Web SDK
47 lines • 3.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HighInboundPacketLossDetector = void 0;
const CallQualityWarningMediaStreamType_1 = require("../CallQualityWarningMediaStreamType");
const BufferedWarningDetector_1 = require("./BufferedWarningDetector");
const WebRTCStats_types_1 = require("../../reporting/WebRTCStats.types");
const WebRtcStatsDetector_1 = require("./WebRtcStatsDetector");
const WebRtcStatsUtils_1 = require("../../WebRtcStatsUtils");
const HighInboundPacketLossWarningEvent_1 = require("../events/HighInboundPacketLossWarningEvent");
class HighInboundPacketLossDetector extends BufferedWarningDetector_1.BufferedWarningDetector {
constructor(mediaStream, fanout) {
super(fanout, BufferedWarningDetector_1.BufferedWarningDetector.DEFAULT_BUFFER_SIZE, BufferedWarningDetector_1.BufferedWarningDetector.DEFAULT_SAMPLES_COUNT_FOR_WARNING, HighInboundPacketLossDetector.FRACTION_LOST_THRESHOLD);
this.mediaStream = mediaStream;
this.lastPacketsReceivedValue = 0;
this.lastPacketLostValue = 0;
}
onNewWebRtcStats(report) {
const mediaStreamType = this.mediaStream === CallQualityWarningMediaStreamType_1.CallQualityWarningMediaStreamType.Audio
? WebRTCStats_types_1.MediaType.Audio
: WebRTCStats_types_1.MediaType.Video;
const inboundRtpStats = (0, WebRtcStatsUtils_1.getStatsWithType)(report, WebRTCStats_types_1.RtcStatsTypes.InboundRtp, mediaStreamType);
const timestamp = inboundRtpStats === null || inboundRtpStats === void 0 ? void 0 : inboundRtpStats[WebRtcStatsDetector_1.WebRtcStatsDetector.TIMESTAMP_KEY];
const packetsLost = inboundRtpStats === null || inboundRtpStats === void 0 ? void 0 : inboundRtpStats[HighInboundPacketLossDetector.PACKET_LOSS_KEY];
const packetsReceived = inboundRtpStats === null || inboundRtpStats === void 0 ? void 0 : inboundRtpStats[HighInboundPacketLossDetector.PACKET_RECEIVED_KEY];
if (packetsLost === undefined ||
packetsReceived === undefined ||
timestamp === undefined) {
return;
}
const packetsReceivedDelta = packetsReceived - this.lastPacketsReceivedValue;
if (packetsReceivedDelta === 0) {
return;
}
const fractionLost = (packetsLost - this.lastPacketLostValue) / packetsReceivedDelta;
this.lastPacketLostValue = packetsLost;
this.lastPacketsReceivedValue = packetsReceived;
this.onNewMonitoredValue(fractionLost, timestamp);
}
warningEventWithType(type) {
return new HighInboundPacketLossWarningEvent_1.HighInboundPacketLossWarningEvent(type, this.mediaStream);
}
}
exports.HighInboundPacketLossDetector = HighInboundPacketLossDetector;
HighInboundPacketLossDetector.PACKET_LOSS_KEY = "packetsLost";
HighInboundPacketLossDetector.PACKET_RECEIVED_KEY = "packetsReceived";
HighInboundPacketLossDetector.FRACTION_LOST_THRESHOLD = 0.01;
//# sourceMappingURL=HighInboundPacketLossDetector.js.map