sinch-rtc
Version:
RTC JavaScript/Web SDK
51 lines • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstantAudioLevelDetector = void 0;
const WebRtcStatsUtils_1 = require("../../../WebRtcStatsUtils");
const CallQualityWarningEventType_1 = require("../../CallQualityWarningEventType");
const StatsBuffer_1 = require("../../StatsBuffer");
const WebRtcStatsDetector_1 = require("../WebRtcStatsDetector");
class ConstantAudioLevelDetector extends WebRtcStatsDetector_1.WebRtcStatsDetector {
constructor(statsIntervalMs, handler, fanout) {
super(fanout);
this.handler = handler;
this.lastStatTimestamp = -1;
this.statsBuffer = new StatsBuffer_1.StatsBuffer((0, WebRtcStatsUtils_1.calculateBufferSize)(ConstantAudioLevelDetector.AUDIO_STATS_COVERED_TIME_SPAN_MS, statsIntervalMs));
}
onNewWebRtcStats(report) {
const audioStats = this.handler.getAudioLevelStats(report);
const audioLevelValue = audioStats === null || audioStats === void 0 ? void 0 : audioStats[ConstantAudioLevelDetector.AUDIO_LEVEL_KEY];
const statsTimestamp = audioStats === null || audioStats === void 0 ? void 0 : audioStats[WebRtcStatsDetector_1.WebRtcStatsDetector.TIMESTAMP_KEY];
if (audioLevelValue === undefined ||
statsTimestamp === undefined ||
statsTimestamp <= this.lastStatTimestamp) {
return;
}
this.lastStatTimestamp = statsTimestamp;
this.handleNewAudioLevelValue(audioLevelValue);
}
handleNewAudioLevelValue(audioLevelValue) {
this.statsBuffer.add(audioLevelValue);
if (!this.statsBuffer.isFull) {
return;
}
if (this.statsBuffer.standardDeviation <
ConstantAudioLevelDetector.AUDIO_LEVEL_MIN_SD_THRESHOLD) {
if (!this.isInTriggeredState) {
this.emitWarning(this.handler.createWarningEvent(CallQualityWarningEventType_1.CallQualityWarningEventType.Trigger));
}
}
else if (this.isInTriggeredState) {
this.emitWarning(this.handler.createWarningEvent(CallQualityWarningEventType_1.CallQualityWarningEventType.Recover));
}
}
}
exports.ConstantAudioLevelDetector = ConstantAudioLevelDetector;
ConstantAudioLevelDetector.AUDIO_LEVEL_KEY = "audioLevel";
ConstantAudioLevelDetector.AUDIO_STATS_COVERED_TIME_SPAN_MS = 20000;
/** Audio level value is between 0..1 (linear), where 1.0 represents 0 dBov, 0 represents silence,
* and 0.5 represents approximately 6 dBSPL change in the sound pressure level from 0 dBov.
* This means we can use absolute value (0.5% of 1) as the threshold, since we know the expected range.
*/
ConstantAudioLevelDetector.AUDIO_LEVEL_MIN_SD_THRESHOLD = 0.005;
//# sourceMappingURL=ConstantAudioLevelDetector.js.map