Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This : (opts || {}).RTCPeerConnection || RTCPeerConnection sometimes returns undefined on ios #54

Open
magestican opened this issue Apr 10, 2017 · 3 comments

Comments

@magestican
Copy link

On an environment with quickconnect together with cordova + libwebrtc on an ios device, this statement returns undefined sometimes and causes an error of which the application never recovers resulting in failure of call initialization.

The scenario where this happens is when opts does not have RTCPeerConnection property, however RTCPeerConnection exists as a global variable, therefore that indicates this in-line statement is wrong.

Maybe a clearer code would be

(opts && opts.RTCPeerConnection) ? opts.RTCPeerConnection : RTCPeerConnection

PS : I dont understand the {}.RTCPeerConnection from this logic, it will always return undefined.

@nathanoehlman
Copy link
Contributor

Hi Bryan,

I had a look through this, and I think this is the scenario you are attempting to fix:

  1. rtc-quickconnect is loaded, and at the time of load, the logic at https://github.com/rtc-io/rtc-tools/blob/master/index.js#L47 sets the value of RTCPeerConnection that is used later in the createConnection method at https://github.com/rtc-io/rtc-tools/blob/master/index.js#L76.
  2. Presumably, this is being loaded asynchronously to window.RTCPeerConnection being set by whatever Cordova iOS RTC plugin you are using, which occasionally results in RTCPeerConnection = undefined, depending on whether the plugin/quickconnect finishes loading first. If the plugin is loaded first, quickconnect detects it correctly, otherwise it is undefined.
  3. At some point later, quickconnect({}) is called to start the call.

If this is correct, rather than the solution in the patch, is it possible to use the mechanism for passing in a custom RTCPeerConnection object to createConnection, namely passing the RTCPeerConnection in the opts to quickconnect - presuming of course that the call to quickconnect is guaranteed to occur at the code that sets window.RTCPeerConnection?

For example:

quickconnect('...', { RTCPeerConnection: window.RTCPeerConnection})

Let me know if you think whether that is an appropriate solution, or if I have misunderstood in some way.

Cheers,
Nathan

@magestican
Copy link
Author

Hey @nathanoehlman , that is exactly the scenario which I was running into, and your solution looks to be doing the right thing, fixing this problem.

I have updated the PR with a comment on the line giving the error so that it would help other people in the future if they run into the same, it would probably be better to give out a console.warn statement however, let me know what you think.

Regards, Bryan

@chris3000
Copy link

Hello, I'm having the exact same issue with the rtc-quickconnect sample code, but I'm using Node.js. I don't have a "window", so I'm not sure how to fix the problem in a server-only environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants