diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2022-04-30 03:34:32 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2022-04-30 03:34:32 +0300 |
commit | 55e91e4a6f4e56d0e03da785549b3c107dd4409d (patch) | |
tree | 7cdae36c85d11ff4d4ae392bccbe9f73d8311e19 | |
parent | 10086691edef05783d0df053d2f3dfae782a1c2e (diff) |
Do not create data channels when they are not enabled
"enableDataChannels" prevented the messages to be sent when the data
channels were disabled, but it did not prevent the data channels from
being created.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r-- | src/utils/webrtc/simplewebrtc/peer.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/utils/webrtc/simplewebrtc/peer.js b/src/utils/webrtc/simplewebrtc/peer.js index 6b0a987a8..9689e02f9 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) } |