webrtcHacks/adapter

WebRTC adapter non longer shim RTCPeerConnection.prototype.ontrack on cordova-plugin-iosRTC

hthetiot opened this issue · 6 comments

Please read first!

Please use discuss-webrtc for general technical discussions and questions.

  • I have provided steps to reproduce (e.g. a link to a jsfiddle)
  • I have provided browser name, version and adapter.js version
  • This issue only happens when adapter.js is used

Note: If the checkboxes above are not checked (which you do after the issue is posted), the issue will be closed.

Versions affected

Browser name including version iOS WKWebView using cordova-plugin-iosrtc 6.0.11

adapter.js 7.6+

Description

Prior to webrtc-adapter 7.6+ (tested from 6.4.8 to 7.5.1) using webrtc-adapter with cordova-plugin-iosrtc resulted in proper SHIM of RTCPeerConnection.prototype.ontrack event.
Since webrtc-adapter 7.6.0 the RTCPeerConnection.prototype.ontrack events Setter is non logger defined and the track events is non longer trigger.

Cordova-plugin-iosrtc repository: https://github.com/cordova-rtc/cordova-plugin-iosrtc
Related Cordova-plugin-iosrtc issues: cordova-rtc/cordova-plugin-iosrtc#516 (comment) cordova-rtc/cordova-plugin-iosrtc#505 (comment)

iOSRTC is a cordova plugin that implement WebRTC with MediaStream and getUserMedia support for WKWebView in swift and expose a SHIM of the WebRTC API, we otfen get regression due WebRTC-Adapter changes and in the past had to release new version when webrtc-adapter broken the compatibility with iosRTC (e.g https://github.com/cordova-rtc/cordova-plugin-iosrtc/blob/master/js/RTCPeerConnection.js#L48).

iOSRTC is also addressing the missing RTCPeerConnection.prototype.ontrack by implementing the RTCPeerConnection track event in the incoming release 6.0.12 (See PR cordova-rtc/cordova-plugin-iosrtc#508), the issue is developers tend to use webrtc-adapter@latest and got their application suddenly stop working with prior version 6.0.11 once they update their application or refer directly to https://webrtc.github.io/adapter/adapter-latest.js.

Steps to reproduce

Using MacOS with Xcode 11.4 (11E146) and an iOS device to run the sample with Camera support (Emulator does not support camera).

  1. npm i cordova
  2. git clone git@github.com:cordova-rtc/cordova-plugin-iosrtc-sample.git
  3. cd cordova-plugin-iosrtc-sample
  4. cordova platform add ios
  5. cordova build ios --device
  6. cordova run ios --device

Example with WebRTC adapter 7.5.1 (cordova-plugin-iosrtc-sample use latest by default)

Screen Shot 2020-05-24 at 6 00 11 PM

Example with WebRTC adapter 7.6.0

Screen Shot 2020-05-24 at 6 00 54 PM

To change webrtc-adapter version used by sample:

Sample use features detection to use track or addstream event in the latest version:

Expected results

RTCPeerConnection track event trigger and can be added to a MediaStream if the implementation is not available and allow third party library that depend RTCPeerConnection track event to keep working with prior iosRTC releases.

Actual results

RTCPeerConnection track event is not triggered and RTCPeerConnection.prototype.ontrack SHIM and getter is not available.

Thank you for considering iosRTC feedback and support.

fippo commented

looks like a side-effect from #1031 - what is navigator.userAgent?

Shit, that would be my own feedback on #1030 that caused this, the user agent can be totally Custom on Cordova, would be possible to go the feature detection path instead to apply some of the shim.

fippo commented

i suspect applying the chrome shim is easier - does the cordova UA allow determining the webrtc.org version used?

No it's does not, again Cordova developper can modify user agent at will. It would be more future proof to perform feature detection. For example:

var hasTrackEvent = Object.getOwnPropertyDescriptors(RTCPeerConnection.prototype).ontrack;

fippo commented

that is what the shims do whenever possible. The problem is that feature detection alone is not sufficient, in particular when shimming ontop of another shim.
Revert #1031 which was only a problem in devtools anyway?

I ended-up implementing ontrack anyway in iOSRTC, so we don't need the shim if people upgrade.

I don't think reverting #1031 is a good thing, many developper use devtools with mobile view. It will solve a lot of flase positive.

May be it's possible to improve feature detection, somewhere. Or detect WebRTC version depending exposed API on JavaScript. I may take a look.

We can close this issue for now.