diff --git a/src/utils/webrtc/simplewebrtc/peer.js b/src/utils/webrtc/simplewebrtc/peer.js index 6b0a987a8f4..9689e02f901 100644 --- a/src/utils/webrtc/simplewebrtc/peer.js +++ b/src/utils/webrtc/simplewebrtc/peer.js @@ -561,6 +561,9 @@ Peer.prototype.sendDirectly = function(channel, messageType, payload) { } this.logger.log('sending via datachannel', channel, messageType, message) const dc = this.getDataChannel(channel) + if (!dc) { + return false + } if (dc.readyState !== 'open') { if (!Object.prototype.hasOwnProperty.call(this.pendingDCMessages, channel)) { this.pendingDCMessages[channel] = [] @@ -598,6 +601,9 @@ Peer.prototype.getDataChannel = function(name, opts) { if (!webrtcSupport.supportDataChannel) { return this.emit('error', new Error('createDataChannel not supported')) } + if (!this.enableDataChannels) { + return null + } let channel = this.channels[name] opts || (opts = {}) if (channel) { @@ -635,9 +641,7 @@ Peer.prototype.start = function() { // a) create a datachannel a priori // b) do a renegotiation later to add the SCTP m-line // Let's do (a) first... - if (this.enableDataChannels) { - this.getDataChannel('simplewebrtc') - } + this.getDataChannel('simplewebrtc') this.offer(this.receiveMedia) } diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js index c5b97f7abbc..49d26814721 100644 --- a/src/utils/webrtc/webrtc.js +++ b/src/utils/webrtc/webrtc.js @@ -693,8 +693,11 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local const sendDataChannelToAll = function(channel, message, payload) { // If running with MCU, the message must be sent through the // publishing peer and will be distributed by the MCU to subscribers. - if (ownPeer && signaling.hasFeature && signaling.hasFeature('mcu')) { - ownPeer.sendDirectly(channel, message, payload) + if (signaling.hasFeature && signaling.hasFeature('mcu')) { + if (ownPeer) { + ownPeer.sendDirectly(channel, message, payload) + } + return } webrtc.sendDirectlyToAll(channel, message, payload) @@ -1169,6 +1172,15 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local } else { callParticipantModel.setScreenPeer(peer) } + + // The SIP bridge publisher does not have data channels, so they + // need to be explicitly disabled in the subscriber. Otherwise it + // would try to open them, which would cause an endless loop of + // renegotiations, as after a negotiation the data channels will + // still not be opened, which will trigger a negotiation again. + if (callParticipantModel.get('internal')) { + peer.enableDataChannels = false + } } if (peer.type === 'video') { @@ -1182,10 +1194,10 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local setHandlerForNegotiationNeeded(peer) - // Make sure required data channels exist for all peers. This - // is required for peers that get created by SimpleWebRTC from - // received "Offer" messages. Otherwise the "channelMessage" - // will not be called. + // Make sure required data channels exist for all peers (that have + // not disabled them). This is required for peers that get created + // by SimpleWebRTC from received "Offer" messages. Otherwise the + // "channelMessage" will not be called. peer.getDataChannel('status') } })