Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utils/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

Expand Down
50 changes: 39 additions & 11 deletions src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -531,24 +531,40 @@ 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
})
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",
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1710,7 +1739,6 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local

usersChanged(signaling, [], previousUsersInRoom)
usersInCallMapping = {}
previousUsersInRoom = []
})

return webrtc
Expand Down