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/www/proxy.ts b/aos/network/www/proxy.ts
index 02573b3..3da817c 100644
--- a/aos/network/www/proxy.ts
+++ b/aos/network/www/proxy.ts
@@ -232,6 +232,10 @@
this.webSocketConnection.send(array.buffer.slice(array.byteOffset));
}
+ onIceCandidateError(e: RTCPeerConnectionIceErrorEvent): void {
+ console.warn(e);
+ }
+
// Called for new SDPs. Make sure to set it locally and remotely.
onOfferCreated(description: RTCSessionDescriptionInit): void {
this.rtcPeerConnection.setLocalDescription(description);
@@ -251,16 +255,17 @@
// We now have a websocket, so start setting up the peer connection. We only
// want a DataChannel, so create it and then create an offer to send.
onWebSocketOpen(): void {
- this.rtcPeerConnection = new RTCPeerConnection({});
+ this.rtcPeerConnection = new RTCPeerConnection(
+ {'iceServers': [{'urls': ['stun:stun.l.google.com:19302']}]});
this.rtcPeerConnection.addEventListener(
'datachannel', (e) => this.onDataChannel(e));
this.dataChannel = this.rtcPeerConnection.createDataChannel('signalling');
this.handlers.add(
new Handler((data) => this.onConfigMessage(data), this.dataChannel));
- // TODO(james): Is this used? Can we delete it?
- // window.dc = this.dataChannel;
this.rtcPeerConnection.addEventListener(
'icecandidate', (e) => this.onIceCandidate(e));
+ this.rtcPeerConnection.addEventListener(
+ 'icecandidateerror', (e) => this.onIceCandidateError(e));
this.rtcPeerConnection.createOffer().then(
(offer) => this.onOfferCreated(offer));
}