From c93b5a63e3e995493fa233837f806cea61ce5a32 Mon Sep 17 00:00:00 2001 From: Justin Martinez Date: Thu, 9 Nov 2017 14:21:15 -0700 Subject: [PATCH 1/6] Changes to allow temsys objects to work --- rtcpeerconnection.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/rtcpeerconnection.js b/rtcpeerconnection.js index f18275a..8188024 100644 --- a/rtcpeerconnection.js +++ b/rtcpeerconnection.js @@ -109,16 +109,18 @@ function PeerConnection(config, constraints) { this.pc = new RTCPeerConnection(config, constraints); - if (typeof this.pc.getLocalStreams === 'function') { - this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); + if (typeof this.pc.getLocalStreams === 'function' || + (this.pc.getLocalStreams && this.pc.getLocalStreams.call)) { + this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); } else { this.getLocalStreams = function () { return []; }; } - if (typeof this.pc.getRemoteStreams === 'function') { - this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); + if (typeof this.pc.getRemoteStreams === 'function' || + (this.pc.getRemoteStreams && this.pc.getRemoteStreams.call)) { + this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); } else { this.getRemoteStreams = function () { return []; @@ -128,16 +130,19 @@ function PeerConnection(config, constraints) { this.addStream = this.pc.addStream.bind(this.pc); this.removeStream = function (stream) { - if (typeof self.pc.removeStream === 'function') { + if (typeof self.pc.removeStream === 'function' || + (self.pc.removeStream && self.pc.removeStream.call)) { self.pc.removeStream.apply(self.pc, arguments); - } else if (typeof self.pc.removeTrack === 'function') { + } else if (typeof self.pc.removeTrack === 'function' || + (self.pc.removeTrack && self.pc.removeTrack.call)) { stream.getTracks().forEach(function (track) { self.pc.removeTrack(track); }); } }; - if (typeof this.pc.removeTrack === 'function') { + if (typeof this.pc.removeTrack === 'function' || + (this.pc.removeTrack && this.pc.removeTrack.call)) { this.removeTrack = this.pc.removeTrack.bind(this.pc); } From c0f706d4e0e6cd1958bb259f92fda039adf04a63 Mon Sep 17 00:00:00 2001 From: Hans Meyer Date: Tue, 15 May 2018 11:24:25 -0600 Subject: [PATCH 2/6] refactor Temasys-sensitive function checks; include pc.getSenders and pc.getReceivers in Temasys-sensitive function check --- rtcpeerconnection.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rtcpeerconnection.js b/rtcpeerconnection.js index e59fe90..7d89e27 100644 --- a/rtcpeerconnection.js +++ b/rtcpeerconnection.js @@ -109,8 +109,7 @@ function PeerConnection(config, constraints) { this.pc = new RTCPeerConnection(config, constraints); - if (typeof this.pc.getLocalStreams === 'function' || - (this.pc.getLocalStreams && this.pc.getLocalStreams.call)) { + if (isFunction(this.pc.getLocalStreams)) { this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); } else { this.getLocalStreams = function () { @@ -118,7 +117,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getSenders === 'function') { + if (isFunction(this.pc.getSenders)) { this.getSenders = this.pc.getSenders.bind(this.pc); } else { this.getSenders = function () { @@ -126,8 +125,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getRemoteStreams === 'function' || - (this.pc.getRemoteStreams && this.pc.getRemoteStreams.call)) { + if (isFunction(this.pc.getRemoteStreams)) { this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); } else { this.getRemoteStreams = function () { @@ -135,7 +133,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getReceivers === 'function') { + if (isFunction(this.pc.getReceivers)) { this.getReceivers = this.pc.getReceivers.bind(this.pc); } else { this.getReceivers = function () { @@ -146,19 +144,16 @@ function PeerConnection(config, constraints) { this.addStream = this.pc.addStream.bind(this.pc); this.removeStream = function (stream) { - if (typeof self.pc.removeStream === 'function' || - (self.pc.removeStream && self.pc.removeStream.call)) { + if (isFunction(self.pc.removeStream)) { self.pc.removeStream.apply(self.pc, arguments); - } else if (typeof self.pc.removeTrack === 'function' || - (self.pc.removeTrack && self.pc.removeTrack.call)) { + } else if (isFunction(self.pc.removeTrack)) { stream.getTracks().forEach(function (track) { self.pc.removeTrack(track); }); } }; - if (typeof this.pc.removeTrack === 'function' || - (this.pc.removeTrack && this.pc.removeTrack.call)) { + if (isFunction(this.pc.removeTrack)) { this.removeTrack = this.pc.removeTrack.bind(this.pc); } @@ -206,6 +201,7 @@ function PeerConnection(config, constraints) { logger.log('PeerConnection event:', arguments); }); } + this.hadLocalStunCandidate = false; this.hadRemoteStunCandidate = false; this.hadLocalRelayCandidate = false; @@ -224,6 +220,11 @@ function PeerConnection(config, constraints) { this._localDataChannels = []; this._candidateBuffer = []; + + // includes consideration for ActiveX/NPAPI methods (for Temasys support) + function isFunction(val) { + return typeof val === 'function' || !!(val && val.call); + } } util.inherits(PeerConnection, WildEmitter); @@ -233,6 +234,7 @@ Object.defineProperty(PeerConnection.prototype, 'signalingState', { return this.pc.signalingState; } }); + Object.defineProperty(PeerConnection.prototype, 'iceConnectionState', { get: function () { return this.pc.iceConnectionState; @@ -277,7 +279,6 @@ PeerConnection.prototype._checkRemoteCandidate = function (candidate) { } }; - // Init and add ice candidate object with correct constructor PeerConnection.prototype.processIce = function (update, cb) { cb = cb || function () {}; @@ -454,7 +455,6 @@ PeerConnection.prototype.offer = function (constraints, cb) { ); }; - // Process an incoming offer so that ICE may proceed before deciding // to answer the request. PeerConnection.prototype.handleOffer = function (offer, cb) { From f18e49a286d349b55035e3de288bbc19839800a8 Mon Sep 17 00:00:00 2001 From: Hans Meyer Date: Tue, 15 May 2018 11:27:00 -0600 Subject: [PATCH 3/6] appease linter --- rtcpeerconnection.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rtcpeerconnection.js b/rtcpeerconnection.js index 7d89e27..07f112b 100644 --- a/rtcpeerconnection.js +++ b/rtcpeerconnection.js @@ -11,6 +11,11 @@ function PeerConnection(config, constraints) { config = config || {}; config.iceServers = config.iceServers || []; + // includes consideration for ActiveX/NPAPI methods (for Temasys support) + function isFunction(val) { + return typeof val === 'function' || !!(val && val.call); + } + // make sure this only gets enabled in Google Chrome // EXPERIMENTAL FLAG, might get removed without notice this.enableChromeNativeSimulcast = false; @@ -220,11 +225,6 @@ function PeerConnection(config, constraints) { this._localDataChannels = []; this._candidateBuffer = []; - - // includes consideration for ActiveX/NPAPI methods (for Temasys support) - function isFunction(val) { - return typeof val === 'function' || !!(val && val.call); - } } util.inherits(PeerConnection, WildEmitter); From 3600b4af12fbd41c9a32803cbf582bc2c3b3079e Mon Sep 17 00:00:00 2001 From: Hans Meyer Date: Tue, 15 May 2018 11:36:15 -0600 Subject: [PATCH 4/6] new build --- rtcpeerconnection.bundle.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/rtcpeerconnection.bundle.js b/rtcpeerconnection.bundle.js index 59c3be7..97ad91a 100644 --- a/rtcpeerconnection.bundle.js +++ b/rtcpeerconnection.bundle.js @@ -3631,6 +3631,11 @@ function PeerConnection(config, constraints) { config = config || {}; config.iceServers = config.iceServers || []; + // includes consideration for ActiveX/NPAPI methods (for Temasys support) + function isFunction(val) { + return typeof val === 'function' || !!(val && val.call); + } + // make sure this only gets enabled in Google Chrome // EXPERIMENTAL FLAG, might get removed without notice this.enableChromeNativeSimulcast = false; @@ -3726,7 +3731,7 @@ function PeerConnection(config, constraints) { this.pc = new RTCPeerConnection(config, constraints); - if (typeof this.pc.getLocalStreams === 'function') { + if (isFunction(this.pc.getLocalStreams)) { this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); } else { this.getLocalStreams = function () { @@ -3734,7 +3739,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getSenders === 'function') { + if (isFunction(this.pc.getSenders)) { this.getSenders = this.pc.getSenders.bind(this.pc); } else { this.getSenders = function () { @@ -3742,7 +3747,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getRemoteStreams === 'function') { + if (isFunction(this.pc.getRemoteStreams)) { this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); } else { this.getRemoteStreams = function () { @@ -3750,7 +3755,7 @@ function PeerConnection(config, constraints) { }; } - if (typeof this.pc.getReceivers === 'function') { + if (isFunction(this.pc.getReceivers)) { this.getReceivers = this.pc.getReceivers.bind(this.pc); } else { this.getReceivers = function () { @@ -3761,16 +3766,16 @@ function PeerConnection(config, constraints) { this.addStream = this.pc.addStream.bind(this.pc); this.removeStream = function (stream) { - if (typeof self.pc.removeStream === 'function') { + if (isFunction(self.pc.removeStream)) { self.pc.removeStream.apply(self.pc, arguments); - } else if (typeof self.pc.removeTrack === 'function') { + } else if (isFunction(self.pc.removeTrack)) { stream.getTracks().forEach(function (track) { self.pc.removeTrack(track); }); } }; - if (typeof this.pc.removeTrack === 'function') { + if (isFunction(this.pc.removeTrack)) { this.removeTrack = this.pc.removeTrack.bind(this.pc); } @@ -3818,6 +3823,7 @@ function PeerConnection(config, constraints) { logger.log('PeerConnection event:', arguments); }); } + this.hadLocalStunCandidate = false; this.hadRemoteStunCandidate = false; this.hadLocalRelayCandidate = false; @@ -3845,6 +3851,7 @@ Object.defineProperty(PeerConnection.prototype, 'signalingState', { return this.pc.signalingState; } }); + Object.defineProperty(PeerConnection.prototype, 'iceConnectionState', { get: function () { return this.pc.iceConnectionState; From 80c8d9cf639b701cc3a217000acff4f85984941c Mon Sep 17 00:00:00 2001 From: Hans Meyer Date: Tue, 15 May 2018 12:24:07 -0600 Subject: [PATCH 5/6] rename to avoid confusion with std isFunction() --- rtcpeerconnection.bundle.js | 16 ++++++++-------- rtcpeerconnection.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rtcpeerconnection.bundle.js b/rtcpeerconnection.bundle.js index 97ad91a..7d1f5b1 100644 --- a/rtcpeerconnection.bundle.js +++ b/rtcpeerconnection.bundle.js @@ -3632,7 +3632,7 @@ function PeerConnection(config, constraints) { config.iceServers = config.iceServers || []; // includes consideration for ActiveX/NPAPI methods (for Temasys support) - function isFunction(val) { + function isCallable(val) { return typeof val === 'function' || !!(val && val.call); } @@ -3731,7 +3731,7 @@ function PeerConnection(config, constraints) { this.pc = new RTCPeerConnection(config, constraints); - if (isFunction(this.pc.getLocalStreams)) { + if (isCallable(this.pc.getLocalStreams)) { this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); } else { this.getLocalStreams = function () { @@ -3739,7 +3739,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getSenders)) { + if (isCallable(this.pc.getSenders)) { this.getSenders = this.pc.getSenders.bind(this.pc); } else { this.getSenders = function () { @@ -3747,7 +3747,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getRemoteStreams)) { + if (isCallable(this.pc.getRemoteStreams)) { this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); } else { this.getRemoteStreams = function () { @@ -3755,7 +3755,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getReceivers)) { + if (isCallable(this.pc.getReceivers)) { this.getReceivers = this.pc.getReceivers.bind(this.pc); } else { this.getReceivers = function () { @@ -3766,16 +3766,16 @@ function PeerConnection(config, constraints) { this.addStream = this.pc.addStream.bind(this.pc); this.removeStream = function (stream) { - if (isFunction(self.pc.removeStream)) { + if (isCallable(self.pc.removeStream)) { self.pc.removeStream.apply(self.pc, arguments); - } else if (isFunction(self.pc.removeTrack)) { + } else if (isCallable(self.pc.removeTrack)) { stream.getTracks().forEach(function (track) { self.pc.removeTrack(track); }); } }; - if (isFunction(this.pc.removeTrack)) { + if (isCallable(this.pc.removeTrack)) { this.removeTrack = this.pc.removeTrack.bind(this.pc); } diff --git a/rtcpeerconnection.js b/rtcpeerconnection.js index 07f112b..8cd516d 100644 --- a/rtcpeerconnection.js +++ b/rtcpeerconnection.js @@ -12,7 +12,7 @@ function PeerConnection(config, constraints) { config.iceServers = config.iceServers || []; // includes consideration for ActiveX/NPAPI methods (for Temasys support) - function isFunction(val) { + function isCallable(val) { return typeof val === 'function' || !!(val && val.call); } @@ -114,7 +114,7 @@ function PeerConnection(config, constraints) { this.pc = new RTCPeerConnection(config, constraints); - if (isFunction(this.pc.getLocalStreams)) { + if (isCallable(this.pc.getLocalStreams)) { this.getLocalStreams = this.pc.getLocalStreams.bind(this.pc); } else { this.getLocalStreams = function () { @@ -122,7 +122,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getSenders)) { + if (isCallable(this.pc.getSenders)) { this.getSenders = this.pc.getSenders.bind(this.pc); } else { this.getSenders = function () { @@ -130,7 +130,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getRemoteStreams)) { + if (isCallable(this.pc.getRemoteStreams)) { this.getRemoteStreams = this.pc.getRemoteStreams.bind(this.pc); } else { this.getRemoteStreams = function () { @@ -138,7 +138,7 @@ function PeerConnection(config, constraints) { }; } - if (isFunction(this.pc.getReceivers)) { + if (isCallable(this.pc.getReceivers)) { this.getReceivers = this.pc.getReceivers.bind(this.pc); } else { this.getReceivers = function () { @@ -149,16 +149,16 @@ function PeerConnection(config, constraints) { this.addStream = this.pc.addStream.bind(this.pc); this.removeStream = function (stream) { - if (isFunction(self.pc.removeStream)) { + if (isCallable(self.pc.removeStream)) { self.pc.removeStream.apply(self.pc, arguments); - } else if (isFunction(self.pc.removeTrack)) { + } else if (isCallable(self.pc.removeTrack)) { stream.getTracks().forEach(function (track) { self.pc.removeTrack(track); }); } }; - if (isFunction(this.pc.removeTrack)) { + if (isCallable(this.pc.removeTrack)) { this.removeTrack = this.pc.removeTrack.bind(this.pc); } From b9d92cd542ee9d1ad5120604f9856e978f503916 Mon Sep 17 00:00:00 2001 From: Justin Martinez Date: Mon, 17 Jun 2019 13:26:08 -0600 Subject: [PATCH 6/6] added check for empty canidate property --- rtcpeerconnection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtcpeerconnection.js b/rtcpeerconnection.js index 8cd516d..4fe6d70 100644 --- a/rtcpeerconnection.js +++ b/rtcpeerconnection.js @@ -770,7 +770,7 @@ PeerConnection.prototype._answer = function (constraints, cb) { // Internal method for emitting ice candidates on our peer object PeerConnection.prototype._onIce = function (event) { var self = this; - if (event.candidate) { + if (event.candidate && event.candidate.candidate) { if (this.dontSignalCandidates) return; var ice = event.candidate;