diff --git a/src/utils/webrtc/models/CallParticipantModel.js b/src/utils/webrtc/models/CallParticipantModel.js index 748ae31f278..cda32ed7532 100644 --- a/src/utils/webrtc/models/CallParticipantModel.js +++ b/src/utils/webrtc/models/CallParticipantModel.js @@ -249,7 +249,8 @@ CallParticipantModel.prototype = { }, _handleRaisedHand: function(data) { - if (!this.get('peer') || this.get('peer').id !== data.id) { + // The hand could be raised even if there is no Peer object. + if (this.get('peerId') !== data.id) { return } diff --git a/src/utils/webrtc/simplewebrtc/peer.js b/src/utils/webrtc/simplewebrtc/peer.js index 47ad9ecf359..3fdfd186424 100644 --- a/src/utils/webrtc/simplewebrtc/peer.js +++ b/src/utils/webrtc/simplewebrtc/peer.js @@ -250,8 +250,6 @@ Peer.prototype.handleMessage = function(message) { } else if (message.type === 'unshareScreen') { this.parent.emit('unshareScreen', { id: message.from }) this.end() - } else if (message.type === 'raiseHand') { - this.parent.emit('raisedHand', { id: message.from, raised: message.payload }) } } diff --git a/src/utils/webrtc/simplewebrtc/simplewebrtc.js b/src/utils/webrtc/simplewebrtc/simplewebrtc.js index 46507a7e143..b70baa8b2f8 100644 --- a/src/utils/webrtc/simplewebrtc/simplewebrtc.js +++ b/src/utils/webrtc/simplewebrtc/simplewebrtc.js @@ -123,6 +123,10 @@ function SimpleWebRTC(opts) { // "nickChanged" can be received from a participant without a Peer // object if that participant is not sending audio nor video. self.emit('nick', { id: message.from, name: message.payload.name }) + } else if (message.type === 'raiseHand') { + // "raisedHand" can be received from a participant without a Peer + // object if that participant is not sending audio nor video. + self.emit('raisedHand', { id: message.from, raised: message.payload }) } else if (peers.length) { peers.forEach(function(peer) { if (message.sid && !self.connection.hasFeature('mcu')) { diff --git a/src/utils/webrtc/simplewebrtc/webrtc.js b/src/utils/webrtc/simplewebrtc/webrtc.js index fc44ab2d199..cc1562e038a 100644 --- a/src/utils/webrtc/simplewebrtc/webrtc.js +++ b/src/utils/webrtc/simplewebrtc/webrtc.js @@ -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 diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js index de134143c21..b339b71712e 100644 --- a/src/utils/webrtc/webrtc.js +++ b/src/utils/webrtc/webrtc.js @@ -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') }) @@ -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.