From b1f3f6d3f421cb9fdb0be42e2f3c63c70aa96cdd Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Mon, 25 Sep 2017 15:38:33 -0600 Subject: [PATCH 1/7] Add bind() polyfill to plugin functions --- source/adapter.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/adapter.js b/source/adapter.js index 3936189..d047ba9 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -382,6 +382,23 @@ AdapterJS.addEvent = function(elem, evnt, func) { } }; +AdapterJS.recursivePolyfillBind(obj) { + if (!obj) { + return; + } + + var pluginProperties = Object.keys(obj); + for (var i = 0; i < pluginProperties.length; i++) { + var currentProperty = obj[pluginProperties[i]]; + + if (typeof currentProperty === 'function') { + currentProperty.bind = Function.prototype.bind; + } else if(typeof currentProperty === 'object') { + recursivePolyfillBind(currentProperty); + } + } +} + AdapterJS.renderNotificationBar = function (message, buttonText, buttonCallback) { // only inject once the page is ready if (document.readyState !== 'interactive' && document.readyState !== 'complete') { @@ -1133,7 +1150,11 @@ if (['webkit', 'moz', 'ms', 'AppleWebKit'].indexOf(AdapterJS.webrtcDetectedType) if (iceServers) { servers.iceServers = iceServers; } - return AdapterJS.WebRTCPlugin.plugin.PeerConnection(servers); + + // polyfill plugin functions with bind() + var peerConnection = AdapterJS.WebRTCPlugin.plugin.PeerConnection(servers); + AdapterJS.recursivePolyfillBind(peerConnection); + return peerConnection; } else { var mandatory = (constraints && constraints.mandatory) ? constraints.mandatory : null; From fc7e02f88e6c10777ba55a9f217d255a16afca1c Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Mon, 25 Sep 2017 15:40:38 -0600 Subject: [PATCH 2/7] Fix recursive function reference --- source/adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapter.js b/source/adapter.js index d047ba9..5c999bb 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -394,7 +394,7 @@ AdapterJS.recursivePolyfillBind(obj) { if (typeof currentProperty === 'function') { currentProperty.bind = Function.prototype.bind; } else if(typeof currentProperty === 'object') { - recursivePolyfillBind(currentProperty); + AdapterJS.recursivePolyfillBind(currentProperty); } } } From 368c6a21333a479ef927f21d1f9c0d4e394a6821 Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Mon, 25 Sep 2017 15:44:55 -0600 Subject: [PATCH 3/7] Only polyfill if bind() does not exist --- source/adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapter.js b/source/adapter.js index 5c999bb..f7b9b4b 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -391,7 +391,7 @@ AdapterJS.recursivePolyfillBind(obj) { for (var i = 0; i < pluginProperties.length; i++) { var currentProperty = obj[pluginProperties[i]]; - if (typeof currentProperty === 'function') { + if (typeof currentProperty === 'function' && !currentProperty.bind) { currentProperty.bind = Function.prototype.bind; } else if(typeof currentProperty === 'object') { AdapterJS.recursivePolyfillBind(currentProperty); From 225aec11bc43f63ab4975bdd10ffeb6a6555a934 Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Fri, 29 Sep 2017 16:04:10 -0600 Subject: [PATCH 4/7] Fix function syntax --- source/adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapter.js b/source/adapter.js index f7b9b4b..3475258 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -382,7 +382,7 @@ AdapterJS.addEvent = function(elem, evnt, func) { } }; -AdapterJS.recursivePolyfillBind(obj) { +AdapterJS.recursivePolyfillBind = function(obj) { if (!obj) { return; } From 1e4080694ec76735d9e3a3a414ffd8a9f7a64a5b Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Tue, 3 Oct 2017 11:59:48 -0600 Subject: [PATCH 5/7] Style fix --- source/adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapter.js b/source/adapter.js index 3475258..92c4afd 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -393,7 +393,7 @@ AdapterJS.recursivePolyfillBind = function(obj) { if (typeof currentProperty === 'function' && !currentProperty.bind) { currentProperty.bind = Function.prototype.bind; - } else if(typeof currentProperty === 'object') { + } else if (typeof currentProperty === 'object') { AdapterJS.recursivePolyfillBind(currentProperty); } } From 5b5e514131eae0057139913f1823a5bf83fd2c9a Mon Sep 17 00:00:00 2001 From: Jeff Stephens Date: Tue, 3 Oct 2017 12:00:12 -0600 Subject: [PATCH 6/7] Add blacklist for objects IE creates infinitely --- source/adapter.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/adapter.js b/source/adapter.js index 92c4afd..d4cbd59 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -387,6 +387,12 @@ AdapterJS.recursivePolyfillBind = function(obj) { return; } + // these objects cause infinite recursion in IE; ignore them + var recursionBlacklist = ['attachEvent()', 'detachEvent()', 'getLastException()']; + if (obj.value && recursionBlacklist.indexOf(obj.value.trim()) > -1) { + return; + } + var pluginProperties = Object.keys(obj); for (var i = 0; i < pluginProperties.length; i++) { var currentProperty = obj[pluginProperties[i]]; From 163173cc32f2c3759abe26ca468629dee92647c7 Mon Sep 17 00:00:00 2001 From: Devin Wilson Date: Wed, 11 Oct 2017 16:15:06 -0600 Subject: [PATCH 7/7] Make bind polyfill that works for temasys plugin JS objects --- source/adapter.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/source/adapter.js b/source/adapter.js index d4cbd59..5886a51 100644 --- a/source/adapter.js +++ b/source/adapter.js @@ -397,14 +397,44 @@ AdapterJS.recursivePolyfillBind = function(obj) { for (var i = 0; i < pluginProperties.length; i++) { var currentProperty = obj[pluginProperties[i]]; - if (typeof currentProperty === 'function' && !currentProperty.bind) { - currentProperty.bind = Function.prototype.bind; + if ((typeof currentProperty === 'function' || (currentProperty && currentProperty.call)) && !currentProperty.bind) { + // with the NPAPI/ActiveX JS functions you have to bind the bindPolyfill function to the NPAPI function and + // then call the bound function with the obj because the function must be called on its parent object + currentProperty.bind = bindPolyfill.bind(currentProperty)(obj); } else if (typeof currentProperty === 'object') { AdapterJS.recursivePolyfillBind(currentProperty); } } } +// adapted from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill +function bindPolyfill(oThis) { + // NPAPI/ActiveX JS functions are objects with a call property + if (typeof this !== 'function' && !(this && this.call)) { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; + } + fBound.prototype = new fNOP(); + + return fBound; +}; + AdapterJS.renderNotificationBar = function (message, buttonText, buttonCallback) { // only inject once the page is ready if (document.readyState !== 'interactive' && document.readyState !== 'complete') {