diff --git a/src/call/Call.js b/src/call/Call.js index 5c86d9a3a9cee1aebe84d4e14f8652b0b8824855..0a3ceb9068653c821b79fa1152cdf6d86570cfb0 100644 --- a/src/call/Call.js +++ b/src/call/Call.js @@ -58,7 +58,7 @@ class Call { }; //webrtc - // map connectionId - data (pc, pendingOffer, pendingOfferPriority, offerSequence, pendingRenegotiation, sequence, kaTimer) + // map connectionId - data (pc, pendingOffer, pendingOfferPriority, offerSequence, pendingRenegotiation, sequence) this._pcData = {} // screen sharing @@ -75,6 +75,10 @@ class Call { this._callMidParticipantMapping = {}; this._callParticipantsData = {}; + this._kaTimer = null; + this._kaInterval = 0; + // KA sequence + this._sequence = 0; this._reconnectTimer = null; // for debugging purposes - for conf calls @@ -711,11 +715,11 @@ class Call { this.handleConfAudioPacket(response.data); } else if (response.status === ERROR_NETWORK || response.status === ERROR_NETWORK_FATAL) { console.warn("[SDK] EventSource failed (CallSignaling):", response.data); - Object.values(this._pcData).forEach(data => { - clearTimeout(data.kaTimer); - pcData.kaTimer = 0; - pcData.kaInterval = 0; - }); + if (this._kaTimer) { + clearTimeout(this._kaTimer); + this._kaTimer = 0; + this._kaInterval = 0; + } if (!this._reconnectTimer) { this._state = CallState.CALL_STATE_CONNECTING; this.turnConnectionTimer(true); @@ -1272,8 +1276,6 @@ class Call { offerSequence: 0, pendingRenegotiation: null, sequence: 0, - kaInterval: 0, - kaTimer: 0 }; } return this._pcData[connectionId]; @@ -1474,9 +1476,6 @@ class Call { this._connectionId = null; Object.values(this._pcData).forEach(pcData => { this._closePeerConnection(pcData.pc) - clearTimeout(pcData.kaTimer); - pcData.kaTimer = 0; - pcData.kaInterval = 0; }); if (this._callParticipantsData) { @@ -1495,12 +1494,6 @@ class Call { } this._remoteScreenSharer = null; - } else { - Object.values(this._pcData).forEach(data => { - clearTimeout(data.kaTimer); - pcData.kaTimer = 0; - pcData.kaInterval = 0; - }); } this._pcData = {}; @@ -1513,6 +1506,12 @@ class Call { this._micMuted = false; this._video = false; this._speakerMuted = false; + if (this._kaTimer) { + clearTimeout(this._kaTimer); + this._kaTimer = 0; + this._kaInterval = 0; + } + this._sequence = 0; this.turnConnectionTimer(false); @@ -1820,34 +1819,30 @@ class Call { return; } - const kaInterval = seconds; - this._initPcData(connectionId).kaInterval = kaInterval; - const kaTimer = this._initPcData(connectionId).kaTimer; - if (kaTimer) { - console.log("[SDK] [KA] KA timer already running:", kaInterval); + this._kaInterval = seconds; + if (this._kaTimer) { + console.log("[SDK] [KA] KA timer already running:", this._kaInterval); return; } const fn = () => { - console.log("[SDK] Send KA:", seconds, connectionId); - if (!this._pcData[connectionId] || !this._pcData[connectionId].kaInterval) { + console.log("[SDK] [KA] Send KA:", this._kaInterval); + if (!this._kaInterval) { console.log("[SDK] [KA] Send KA: STOPPED"); - return; + return } - const newKaInterval = this._pcData[connectionId].kaInterval; const ka = new CallSignaling.KeepAlive(); const keepAliveMessage = new CallSignaling.HandshakeMessage(); keepAliveMessage.setKeepAlive(ka); const keepAlivePacket = new CallSignaling.HandshakePacket(); keepAlivePacket.addMessage(keepAliveMessage); - keepAlivePacket.setConnectionId(connectionId); - keepAlivePacket.setSequence(++this._pcData[connectionId].sequence); + keepAlivePacket.setSequence(++this._sequence); this._callingTransport.sendMediaControlPacket(keepAlivePacket, this._id, this._participantId); - this._initPcData(connectionId).kaTimer = setTimeout(fn, newKaInterval * 1000); - } - this._initPcData(connectionId).kaTimer = setTimeout(fn, kaInterval * 1000); + this._kaTimer = setTimeout(fn, this._kaInterval * 1000); + }; + this._kaTimer = setTimeout(fn, this._kaInterval * 1000); } _handleTerminate(reason) {