sourcey / libsourcey

C++14 evented IO libraries for high performance networking and media based applications
https://sourcey.com/libsourcey
GNU Lesser General Public License v2.1
1.32k stars 350 forks source link

How to use webrtcstreamer from AWS? #163

Closed michaelfig closed 7 years ago

michaelfig commented 7 years ago

Hi,

I'm running webrtcstreamerd on an AWS instance, with a TURN server on a separate instance.

I'd like for webrtcstreamerd to report its external IP address for the ICE candidates, but currently it is sending its internal, non-routable address to the client browser. Even though I have TURN enabled, I'm not seeing the public external IP in the "relay" ICE candidate.

Any advice would be appreciated, Michael.

auscaster commented 7 years ago

Have you setup your STUN servers? This is necessary to resolve the public IP from outside the network.

michaelfig commented 7 years ago

I've set up a coturn STUN/TURN server in AWS, and it works with non-AWS peers (tested by using that server with appr.tc). I'll describe my topology for webrtcstreamerd here (IPs have been changed to protect the innocent):

                                                            AWS Server 1
                                                     -----> 35.23.45.2    172.31.24.42  webrtcstreamerd
Non-AWS Client    Restrictive firewall               /
192.168.1.49 --> 192.168.1.1   24.71.89.99 ---->Internet (Public)
                                                    \          AWS Server 2
                                                     -----> 34.18.39.160  172.16.3.35  coturn

This diagram omits my Symple and HTTP services (on AWS Server 3) as they work just fine. An AWS server has a private address, but can be configured to be accessible on a public static IP (34.x and 35.x in the diagram) via direct NAT. In fact, coturn has specific configuration options for using the public IP in all its messages instead of the 172.x local interface IP.

When I try the webrtcstreamer example, configured for STUN and TURN from 34.18.39.160, my client correctly offers candidates including its srflx address (24.71.89.99) and relay addresses (34.18.39.160).

The problem I have is that webrtcstreamerd does not itself appear to use STUN, so it offers 172.31.24.42 instead of 35.23.45.2. What can I do to either rewrite the candidates to offer the public address, or use STUN in webrtcstreamerd?

Thanks, Michael.

auscaster commented 7 years ago

You should be able to add the STUN servers to webrtcstreamerd via the WebRTC internal API.

Check this code for how to do it: https://chromium.googlesource.com/external/webrtc/+/master/webrtc/examples/peerconnection/client/conductor.cc#117

Just create the webrtc::PeerConnectionInterface::RTCConfiguration config, and the STUN servers and pass to CreatePeerConnection

michaelfig commented 7 years ago

Thanks! Worked like a charm!