UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

40 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BufferedWarningDetector = void 0; const CallQualityWarningEventType_1 = require("../CallQualityWarningEventType"); const StatsBuffer_1 = require("../StatsBuffer"); const WebRtcStatsDetector_1 = require("./WebRtcStatsDetector"); /** * * BufferedWarningDetector tracks given WebRTC statistic parameter by keeping it's recent values inside a * [StatsBuffer] issuing warning when given amount of values in buffer exceeds provided threshold. * * Implementation should call `onNewMonitoredValue` whenever a new value of the monitored parameter is available. */ class BufferedWarningDetector extends WebRtcStatsDetector_1.WebRtcStatsDetector { constructor(fanout, bufferSize, samplesCountForWarning, threshold) { super(fanout); this.lastSampleTimestampMs = -1; this.buffer = new StatsBuffer_1.StatsBuffer(bufferSize, samplesCountForWarning, threshold); } onNewMonitoredValue(value, timestampMs) { if (value === undefined || timestampMs === undefined) { return; } if (timestampMs <= this.lastSampleTimestampMs) { return; } this.lastSampleTimestampMs = timestampMs; this.buffer.add(value); if (this.buffer.isAboveThreshold && !this.isInTriggeredState) { this.emitWarning(this.warningEventWithType(CallQualityWarningEventType_1.CallQualityWarningEventType.Trigger)); } else if (!this.buffer.isAboveThreshold && this.isInTriggeredState) { this.emitWarning(this.warningEventWithType(CallQualityWarningEventType_1.CallQualityWarningEventType.Recover)); } } } exports.BufferedWarningDetector = BufferedWarningDetector; BufferedWarningDetector.DEFAULT_BUFFER_SIZE = 4; BufferedWarningDetector.DEFAULT_SAMPLES_COUNT_FOR_WARNING = 3; //# sourceMappingURL=BufferedWarningDetector.js.map