Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix not sending signaling messages to participants without a Peer object
"webrtc.sendToAll" only sends the signaling message to participants for
which there is a Peer object. Due to this now it also emits an event
that is handled by the WebRTC wrapper to send the message too to the
rest of participants in the call that do not have a Peer object.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and nickvergessen committed Jun 7, 2021
commit 0e0808366be2df8ce9fdf8c0b5f9fbb3bab92000
2 changes: 2 additions & 0 deletions src/utils/webrtc/simplewebrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ WebRTC.prototype.sendToAll = function(message, payload) {
this.peers.forEach(function(peer) {
peer.send(message, payload)
})

this.emit('sendToAll', message, payload)
}

// sends message to all using a datachannel
Expand Down
53 changes: 33 additions & 20 deletions src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,38 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
}
})

webrtc.on('sendToAll', function(messageType, payload) {
const sessionIdsForParticipantsWithPeers = {}
webrtc.webrtc.peers.forEach(peer => {
sessionIdsForParticipantsWithPeers[peer.id] = peer
})

// "webrtc.sendToAll" only sends the signaling message to participants
// for which there is a Peer object. Therefore the message needs to be
// explicitly sent here too to participants without audio and video.
for (const sessionId in usersInCallMapping) {
if (sessionIdsForParticipantsWithPeers[sessionId]) {
continue
} else if (!usersInCallMapping[sessionId].inCall) {
continue
} else if (sessionId === signaling.getSessionId()) {
continue
}

// "roomType" is not really relevant without a peer, but it is
// nevertheless expected in the message. As the signaling messages
// currently sent to all participants are related to video peers
// "video" is used as the room type.
const message = {
to: sessionId,
roomType: 'video',
type: messageType,
payload: payload,
}
signaling.emit('message', message)
}
})

webrtc.on('speaking', function() {
sendDataChannelToAll('status', 'speaking')
})
Expand Down Expand Up @@ -1093,26 +1125,7 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local

sendDataChannelToAll('status', 'nickChanged', payload)

// "webrtc.sendToAll" can not be used, as it only sends the signaling
// message to participants for which there is a Peer object, so the
// message may not be sent to participants without audio and video.
for (const sessionId in usersInCallMapping) {
if (!usersInCallMapping[sessionId].inCall) {
continue
} else if (sessionId === signaling.getSessionId()) {
continue
}

const message = {
to: sessionId,
roomType: 'video',
type: 'nickChanged',
payload: {
name: name,
},
}
signaling.emit('message', message)
}
webrtc.sendToAll('nickChanged', { name: name })
})

// Local screen added.
Expand Down