Cordova-plugin-iosrtc: TypeError when using iosrtc together with webrtc-adapter 5.0.6

Created on 2 Nov 2017  路  15Comments  路  Source: cordova-rtc/cordova-plugin-iosrtc

Hi there,

thanks for maintaining this plugin. My team and I are using it in our webrtc cordova application together with the webrtc-adapter package and have been happy with this so far. We are using the latest cordova-plugin-iosrtc 4.0.2.

Unfortunately we have now tried to upgrade the webrtc-adapter package from version 4.0.1 to version 5.0.6 (latest) and hit an issue while initializing an rtc peer connection:

TypeError - undefined is not an object (evaluating 'nativeAddEventListener.apply')

It looks like there is some type mismatch between the two packages, therefore we cannot upgrade to the latest webrtc-adapter version.

Could this please be fixed?

Thank you,

Nicole Giorgi

bug third party library support webrtc-adapter

All 15 comments

me too

It seems that adapter.js does ugly stuff here. It takes the addEventListener method from the PeerConnection prototype.

However, the PeerConnection exported by cordova-plugin-iosrtc does not directly implement such a method in its prototype but, instead, uses the yaeti module to add such a method directly in the class instance (so not in the class prototype and hence the error above).

So, in order to fix it, the yaeti module should be modified somehow to add methods to the prototype of a class, and hence the usage in cordova-plugin-webrtc should also be changed.

I hope this may help somebody to provide a PR for yaeti of cordova-plugin-webrtc. Unfortunately I don't have time to work on it right now.

@ibc @nickygiorgi @k13elle This is most likely a hack and there are better ways to do this and needs to be thoroughly tested:

// Strictly private internal function to be used only in iosrtc code
function extend(From, ImplFunc) {
  function F() {
    var args = Array.prototype.slice.call(arguments, 0);
    From.apply(this, args); // Apply From's instance members
    ImplFunc.apply(this, args); // Apply ImplFunc's instance members
  }
  F.prototype = Object.create(From.prototype);
  F.prototype.constructor = F;
  return F;
}



// in RTCPeerConnection.js
var RTCPeerConnection = extend(EventTarget, function(pcConfig, pcConstraints) {
  // EventTarget.call(this); // No need for this call anymore!
  this.localDescription = null;
  // ......
});

module.exports = RTCPeerConnection;

RTCPeerConnection.prototype.createOffer = function () {
 // ...
}

// Now the addEventListener and removeEventListener functions are available on 
// RTCPeerConnection's prototype

A quick example http://jsbin.com/zezuho/1/edit?js,console

In this specific case of webrtc-adapter, The function will have to change a bit:

// Strictly private internal function to be used only in iosrtc code
function extend(From, ImplFunc) {
  function F() {
    var args = Array.prototype.slice.call(arguments, 0);
    From.apply(this, args); // Apply From's instance members
    ImplFunc.apply(this, args); // Apply ImplFunc's instance members
  }
  // F.prototype = Object.create(From.prototype);
  F.prototype = Object.assign({}, From.prototype);
  F.prototype.constructor = F;
  return F;
}

I have just now hit this same roadblock, so chiming in.

@naikus Did you or anyone test this solution? It's quite a big change for the plugin code, since it appears in every constructor.

@nickygiorgi Did you find an upgrade path? Did you have a serious issue with webrtc-adapter 4.0.1 that required an update? It seems I'm walking a similar path so any tips would be appreciated. Thanks!

@reedspool I did not pursue this further. We were working on a POC and meanwhile iOS 11 came with support for WebRTC so we used a web-only solution for iOS safari that worked for us.
But even with this approach, it seems the MediaStream (plugin) js class will need a different workaround because its created in a different way not via the new operator. Also the adapter uses (I guess) MediaStream (Web) constructor to create one. (I don't remember now exactly though). But its a considerable effort not just this EventEmitter but there are other changes as well.
Thanks,
-n

@reedspool No, unfortunately we are still on 4.0.1 and not planning to update for the near future. We found the issue while trying to update most of the packages and plugins we use in our application but if there is no official fix for this we don't really have time to spend bringing in custom modifications and testing whether they work in all cases.

We don't have any particular issue with 4.0.1, but we try to keep our dependencies up to date as much as possible, so I thought I'd point out this issue with updating this plugin. However, if no official fix will be released, we will just keep 4.0.1 until we can drop the plugin all together - we support users with versions prior to iOS 11 so cannot drop as yet.

Sorry I could not help much with this.

@naikus @nickygiorgi Thank you for your responses. The info is very helpful, even if it's not a golden ticket. I am hoping to support IE8+ so this solution is looking important and daunting.

Nicky, do you use MediaStream with Adapter 4.0.1, or perhaps you are just using RTC for DataChannel? I attempted to downgrade to 4.0.1 but immediately got another incompatibility issue with MediaStream.

We get the same error with the latest adapter.js
@naikus which file shoud be updated with your code?

@4i-helpynet I wrote this function in iosrtc.js, but this does not seem to work with MediaStream.js class since it does not use a "new" operator. You'll have to test this thoroughly

update to last [email protected] it works great.

@hthetiot - You state that [email protected] works great. Are you implying it fixes the problem that @nickygiorgi originally reported?

TypeError - undefined is not an object (evaluating 'nativeAddEventListener.apply')

I am using iosrtc 5.0.0 and I am getting the same error with [email protected].

I considered trying [email protected] but it has a dependency on Swift 3 which is no longer supported in the latest version of XCode.

Please see issue #380 and pull request #381 for fixes :)

@homerlex my bad, It does work with the adapter 7+ when you do not use addEventListener and use object.evenName = callback instead.

Thanks to @Skorpeo this will be fix on next release 5.0.2 once his PR review changes processed.

Thank you @homerlex for your comment.

Should be fixed by #373 with getReceivers|getSenders SHIM and addTrack|removeTrack SHAM

Was this page helpful?
0 / 5 - 0 ratings