UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

66 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MissingMediaStreamWarningDetector = void 0; const rtc_1 = require("../../../rtc"); const CallQualityWarningEventType_1 = require("../CallQualityWarningEventType"); const MissingMediaStreamWarningEvent_1 = require("../events/MissingMediaStreamWarningEvent"); const BaseDetector_1 = require("./BaseDetector"); /** * Detector keeping track of the ICE connection state during the time the call is established. * * Note that whenever we observe an ICE state change that indicates lack of connectivity, we need to wait a certain amount of time * before doing the ICE state check itself. This is because the ICE state change might be related to remote peer * hanging up and not to connectivity loss. In this case, within the delay, the detector will be deactivated and * no warning will be emitted. */ class MissingMediaStreamWarningDetector extends BaseDetector_1.BaseDetector { constructor(fanout) { super(fanout); this.iceState = rtc_1.IceConnectionState.New; } get isActive() { return super.isActive; } set isActive(isActive) { super.isActive = isActive; if (!isActive && this.timeoutId) { clearTimeout(this.timeoutId); } else if (isActive) { this.scheduleStateCheck(); } } onIceConnectionStateChanged(state) { this.iceState = state; if (this.isActive) { this.scheduleStateCheck(); } } scheduleStateCheck() { if (this.timeoutId) { clearTimeout(this.timeoutId); } const checkDelay = this.iceState == rtc_1.IceConnectionState.Connected ? 0 : MissingMediaStreamWarningDetector.WARNING_EMISSION_DELAY_MS; if (checkDelay === 0) { this.performStateCheck(); } else { this.timeoutId = setTimeout(this.performStateCheck.bind(this), checkDelay); } } performStateCheck() { if (this.iceState !== rtc_1.IceConnectionState.Connected && !this.isInTriggeredState) { this.emitWarning(new MissingMediaStreamWarningEvent_1.MissingMediaStreamWarningEvent(CallQualityWarningEventType_1.CallQualityWarningEventType.Trigger)); } else if (this.iceState === rtc_1.IceConnectionState.Connected && this.isInTriggeredState) { this.emitWarning(new MissingMediaStreamWarningEvent_1.MissingMediaStreamWarningEvent(CallQualityWarningEventType_1.CallQualityWarningEventType.Recover)); } } } exports.MissingMediaStreamWarningDetector = MissingMediaStreamWarningDetector; MissingMediaStreamWarningDetector.WARNING_EMISSION_DELAY_MS = 2000; //# sourceMappingURL=MissingMediaStreamWarningDetector.js.map