Configurate WebRTC to work across NATs
Using a public STUN server, allow the WebRTC connection to traverse
NATs.
This appears to work properly even when you do not have an Internet
connection. I also set up the options to make so that if there isn't
*any* non-loopback interface, things still work correctly.
Change-Id: Icb28f890bafa684c88be09afc45edc2039761362
diff --git a/aos/network/web_proxy.cc b/aos/network/web_proxy.cc
index 5902d30..317034c 100644
--- a/aos/network/web_proxy.cc
+++ b/aos/network/web_proxy.cc
@@ -308,6 +308,11 @@
webrtc::PeerConnectionInterface::RTCConfiguration config;
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
config.enable_dtls_srtp = true;
+ {
+ webrtc::PeerConnectionInterface::IceServer ice_server;
+ ice_server.urls.push_back("stun:stun.l.google.com:19302");
+ config.servers.push_back(ice_server);
+ }
std::unique_ptr<rtc::Thread> signaling_thread = rtc::Thread::Create();
signaling_thread->SetName("signaling_thread", nullptr);
@@ -319,6 +324,14 @@
factory_deps.signaling_thread = signaling_thread.release();
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory =
CreateModularPeerConnectionFactory(std::move(factory_deps));
+ {
+ // Don't ignore *any* networks--by default, the loopback interface is
+ // ignored, which makes it impossible to use WebRTC on devices with no
+ // network.
+ webrtc::PeerConnectionFactoryInterface::Options options;
+ options.network_ignore_mask = 0;
+ factory->SetOptions(options);
+ }
peer_connection_ =
factory->CreatePeerConnection(config, nullptr, nullptr, this);