AdapterJS icon indicating copy to clipboard operation
AdapterJS copied to clipboard

Add bind() polyfill to plugin functions

Open jeffstephens opened this issue 8 years ago • 13 comments

The Temasys plugin returns Javascript functions that reflect a much older version of Javascript and do not support the bind() functionality which causes failures in our code and some plugins like rtcpeerconnection. This recursively polyfills all functions on the plugin object so they support this relatively recent Javascript functionality.

jeffstephens avatar Sep 29 '17 20:09 jeffstephens

Will need to test, but in theory, it sounds great to me :)

johache avatar Oct 02 '17 03:10 johache

Sweet! I do believe I'm seeing infinite recursion in IE11 due to the different event listener code (attachEvent)... I'll fix that up.

Also, would it be better if I squashed these commits into one?

jeffstephens avatar Oct 02 '17 20:10 jeffstephens

You don't need to squash the commits.

I will be waiting for an update on the infinite recursion :)

johache avatar Oct 03 '17 04:10 johache

Ok, that should do it! Let me know if you'd like me to make any changes.

jeffstephens avatar Oct 03 '17 18:10 jeffstephens

Hi, I'm afraid this is not working as intended.

Safari

Take for example this sample : https://plugin.temasys.com.sg/demo/src/content/peerconnection/pc1/ You can modify it to use your AJS.

Try the following code :

var rs = pc2.getRemoteStreams;
rs.bind(pc1)(); // returns pc2.getRemoteStreams(), instead of pc1.getRemoteStreams()

This is probably due to the nature of NPAPI/ActiveX plugin. When you call pc.createOffer, it's not calling the createOffer function on the pc1 instance. It's calling the createOffer function of this specific instance of PC. pc2.createOffer is a difference instance of the function. I know it's a bit weird, but I'm pretty sure that's what's happening.

IE

IE is flat out not working for me. I tried to bind pc.createOffer and I am getting an immediate error when I try to call a function after binding it.

johache avatar Oct 04 '17 06:10 johache

Whoops - thanks for the info, that is helpful. The plugin objects are a bit strange. I'll work on getting this fixed!

jeffstephens avatar Oct 04 '17 17:10 jeffstephens

Feel free to work on it as much as you want, but very honestly, I don't think that there is a clean way of fixing this.

johache avatar Oct 05 '17 03:10 johache

Thanks for the help! I think you are probably right and I'm going to start looking at a different approach than modifying AdapterJS.

jeffstephens avatar Oct 05 '17 18:10 jeffstephens

Hi @johache - my colleague @dwilson6 figured out a way to make this work with the plugin objects. I'm now able to call bind() on the functions as in Chrome/Firefox. Would you mind taking another look?

jeffstephens avatar Oct 11 '17 22:10 jeffstephens

Sure, no prob. I'll either get to it today/tomorrow, or it will have a to wait for a couple of weeks.

johache avatar Oct 12 '17 03:10 johache

Hey @johache, do you have time to look at this? Thanks for your attention!

jeffstephens avatar Nov 09 '17 21:11 jeffstephens

I'm sorry, but it still doesn't seem to work.

var rs = pc2.getRemoteStreams;
rs.bind(pc2)(); // same error for rs.bind(pc2)();

Gives me this error TypeError: rs.bind(pc2) is not a function. (In 'rs.bind(pc2)()', 'rs.bind(pc2)' is an instance of Array)

and trying to preset actually calls the function :

var co = pc1.createOffer.bind(onCreateOfferSuccess, onCreateSessionDescriptionError,
      offerOptions);

johache avatar Nov 14 '17 04:11 johache

In my case, when I merge this pull request in adapter, using the latest simplewebrtc I get the error "Calling method on NPObject" on "return fToBind.apply(this instanceof fNOP". Note that SimpleWebRTC uses bind() so that is why it's so important to me to get this pull request to work.

This is when I do a Safari - Chrome video call. This error only appears on Safari's side.

ee11131 avatar Nov 15 '17 13:11 ee11131