WebRTC: Difference between revisions

No edit summary
Line 15: Line 15:
===RTCPeerConnection===
===RTCPeerConnection===


The purpose of RTCPeerConnection is to negotiate a connection using the signalling channel (the Websocket forwarded through your nat).


When you make an RTCPeerConnection, you should pass in a list of iceServers:
<syntaxhighlight lang="javascript">
const configuration = {iceServers: [{urls: 'stun.l.google.com:19302'}]};
const pc = new RTCPeerConnection(configuration);
</syntaxhighlight>
There are two types of iceServers:
* STUN servers are used to find the public IP and port of the client.
** You can find a list of STUN servers [https://gist.github.com/mondain/b0ec1cf5f60ae726202e here].
* TURN servers are a fallback used to proxy data through the NAT.
For each STUN server, you need to send it to the other peer via your signalling channel:
<syntaxhighlight lang="javascript">
const configuration = {iceServers: [{urls: 'stuns:stun.example.org'}]};
</syntaxhighlight>
The other client will add these as follows:
<syntaxhighlight lang="javascript">
remoteConnection.addIceCandidate(e.candidate)
</syntaxhighlight>
{{ hidden | RTCPeerConnection Example |
Below is from [https://www.html5rocks.com/en/tutorials/webrtc/basics/ HTML5Rocks].
Below is from [https://www.html5rocks.com/en/tutorials/webrtc/basics/ HTML5Rocks].
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Line 84: Line 110:
};
};
</syntaxhighlight>
</syntaxhighlight>
}}


===RTCDataChannel===
===RTCDataChannel===