diff --git a/src/utils/signaling.js b/src/utils/signaling.js index 56c98faafa..31e8ecb56c 100644 --- a/src/utils/signaling.js +++ b/src/utils/signaling.js @@ -338,8 +338,14 @@ Signaling.Base.prototype.leaveCall = function(token, keepToken, all = false) { } }.bind(this)) .catch(function() { + this._trigger('leaveCall', [token, keepToken]) reject(new Error()) - }) + // We left the current call. + if (!keepToken && token === this.currentCallToken) { + this.currentCallToken = null + this.currentCallFlags = null + } + }.bind(this)) }) } diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js index 2b6ae2dbad..c84e83ce55 100644 --- a/src/utils/webrtc/webrtc.js +++ b/src/utils/webrtc/webrtc.js @@ -52,7 +52,7 @@ let ownScreenPeer = null let selfInCall = PARTICIPANT.CALL_FLAG.DISCONNECTED // Special variable to know when the local user explicitly joined and left the // call; this is needed to know when the user was kicked out from the call by a -// moderator. +// moderator and discard signaling events if received when not in the call. let localUserInCall = false const delayedConnectionToPeer = [] let callParticipantCollection = null @@ -531,12 +531,20 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local localCallParticipantModel = _localCallParticipantModel signaling.on('usersLeft', function(users) { + if (!localUserInCall) { + return + } + users.forEach(function(user) { delete usersInCallMapping[user] }) usersChanged(signaling, [], users) }) signaling.on('usersChanged', function(users) { + if (!localUserInCall) { + return + } + users.forEach(function(user) { const sessionId = user.sessionId || user.sessionid usersInCallMapping[sessionId] = user @@ -544,11 +552,19 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local usersInCallChanged(signaling, usersInCallMapping) }) signaling.on('allUsersChangedInCallToDisconnected', function() { + if (!localUserInCall) { + return + } + // "End meeting for all" was used, we don't have a user list but everyone disconnects from the call usersInCallMapping = {} usersInCallChanged(signaling, usersInCallMapping) }) signaling.on('participantFlagsChanged', function(event) { + if (!localUserInCall) { + return + } + /** * event { * roomid: "1609407087", @@ -567,6 +583,10 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local } }) signaling.on('usersInRoom', function(users) { + if (!localUserInCall) { + return + } + usersInCallMapping = {} users.forEach(function(user) { const sessionId = user.sessionId || user.sessionid @@ -604,17 +624,33 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local // stopped, as the current own session is not passed along with the // sessions of the other participants as "disconnected" to // "usersChanged" when a call is left. - // The peer, on the other hand, is automatically ended by "leaveCall" - // below. + // The peer, on the other hand, is ended by the calls below. if (ownPeer && delayedConnectionToPeer[ownPeer.id]) { clearInterval(delayedConnectionToPeer[ownPeer.id]) delete delayedConnectionToPeer[ownPeer.id] } + // Besides stopping the media "leaveCall" would end the peers, but it + // does not stop the timers for pending connections, removes models or + // clears the call data, so this needs to be explicitly done here + // instead. + selfInCall = PARTICIPANT.CALL_FLAG.DISCONNECTED + + usersChanged(signaling, [], previousUsersInRoom) + usersInCallMapping = {} + webrtc.leaveCall() }) signaling.on('message', function(message) { + if (!localUserInCall) { + console.debug('Message received when not in the call, ignore', message.type, message) + + message.type = 'message-to-ignore' + + return + } + if (message.type === 'answer' && message.roomType === 'video' && delayedConnectionToPeer[message.from]) { clearInterval(delayedConnectionToPeer[message.from]) delete delayedConnectionToPeer[message.from] @@ -644,12 +680,6 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local delete delayedConnectionToPeer[message.from] } - if (!selfInCall) { - console.debug('Offer received when not in the call, ignore') - - message.type = 'offer-to-ignore' - } - // MCU screen offers do not include the "broadcaster" property, // which is expected by SimpleWebRTC in screen offers from a remote // peer, so it needs to be explicitly added. @@ -926,7 +956,6 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local usersChanged(signaling, [], previousUsersInRoom) usersInCallMapping = {} - previousUsersInRoom = [] // Reconnects with a new session id will trigger "usersChanged" // with the users in the room and that will re-establish the @@ -1710,7 +1739,6 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local usersChanged(signaling, [], previousUsersInRoom) usersInCallMapping = {} - previousUsersInRoom = [] }) return webrtc