triniwiz / nativescript-webrtc

Apache License 2.0
42 stars 25 forks source link

Can't connect outside local network #20

Closed codingcronus closed 4 years ago

codingcronus commented 5 years ago

I cannot connect two devices while one of them is outside the local network (I disable wifi and set it to 4g).

I am using the new Standard API and adding my STUN and TURN servers by:

let iceServices: TNSRTCIceServer[] = [
      new TNSRTCIceServer(['turn:{myturnipaddress}:3478'], '{myusername}', '{mypassword}'),
      new TNSRTCIceServer(['stun.l.google.com:19302']),
      new TNSRTCIceServer(['stun1.l.google.com:19302']),
      new TNSRTCIceServer(['stun2.l.google.com:19302']),
      new TNSRTCIceServer(['stun3.l.google.com:19302']),
      new TNSRTCIceServer(['stun4.l.google.com:19302'])
  ];

const options: TNSRTCConfigurationOptions = {
      iceServers: iceServices
};

const config = new TNSRTCConfiguration(options);
let connection = new TNSRTCPeerConnection(config);

// From here I use the connection...

I have tested the TURN-server using the online testing tool and it seems that it works as expected.

The connection works perfectly while running on my local network.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Plugin version: ^2.0.0-alpha.18 (edit: Tested with both alpha.15 and .18)

triniwiz commented 5 years ago

Can you try using only the turn also is there any way to verify you are getting connected to the turn server

triniwiz commented 5 years ago

Also what are you using to set up the call?

codingcronus commented 5 years ago

I have tried to use only the TURN server and as a matter of fact I cannot see that it connects. When I use the Trickle ICE tool I can see the request, so the TURN server is responding, but I guess the request is never send from the WebRTC library. Let me see if the "old" API is working.

I am using Socket.IO for signalling.

Thanks for a brilliant library none the less!

codingcronus commented 5 years ago

Hi Triniwiz I have verified that the configuration really ignores the ICE servers. I edited the constructor of FancyRTCConfiguration.swift where I inserted my TURN server as the only entry. After I did that, my TURN server logs shows incoming requests and the video connection is started successfully.

Please have a look at my initial source code for reference.

Also, here is the modified constructor:

Screenshot 2019-05-28 at 23 30 13
Who-Code commented 5 years ago

Also currently facing this issue not only in ios but also on android, using web implementation works like a charm

Who-Code commented 5 years ago

@codingcronus can you give a more detailed information about your fixing process in the plug-in and how to use the modified plug-in ?

codingcronus commented 5 years ago

@rkeller1 sure, I have only done this for IOS, but I believe that the process is almost identical for Android.

Under platforms/ios/Pods/FancyWebRTC/Sources/FancyWebRTC you have all the native webrtc source code. If you do a search all for: "stun:stun.l.google.com:19302" you can find the various places (in my case FancyRTCConfiguration.swift and and FancyRTCPeerConnection.swift) where the plugin uses the default stun servers. Here I simply add my STUN/TURN servers as shown in the screenshot above.

This enables you to use your custom STUN/TURN servers and next step would be to fix the bug in the Nativescript-webrtc plugin so that it can be configured without modifying the native source code.

Who-Code commented 5 years ago

@codingcronus How To you rebuilded the Library, i applied the changes but it seems like nothing changed

codingcronus commented 5 years ago

@rkeller1 did you do a: "tns run ios --bundle" command after applying your changes? This should rebuild the iOS source as well.

Who-Code commented 5 years ago

@codingcronus yeah, tried your command and "tns debug ios --clean" nothing of both works :/ More Details: Using Plain Typescript for my project

codingcronus commented 5 years ago

@rkeller1 Okay, that is odd. Let me check as soon as I am back on my other computer (~8 hours).

Who-Code commented 5 years ago

@codingcronus thank you for your support

codingcronus commented 5 years ago

@rkeller1 you're welcome. PS. what I think initially worked for me was to clone the Nativescript-webrtc project, apply the modifications as previously discussed, build the plugin (see the package.json for command instructions), copy the .tgz package to my nativescript project and from there install the plugin locally (https://docs.nativescript.org/tooling/docs-cli/lib-management/plugin-install)

Who-Code commented 5 years ago

@codingcronus will try this tomorrow. Never did this before

Who-Code commented 5 years ago

@triniwiz do you know when you have time to take a look on the Bugfix ?

Who-Code commented 5 years ago

Any news regarding this issue ?