46

I'm looking at the webrtc.html and peerconnection_server demo, and it is working fine between two Chrome browsers. My question is, what exactly is the first param of webkitPeerConnection ?

pc = new webkitPeerConnection("STUN stun.l.google.com:19302", onSignalingMessage);

Is it a third party STUN server given by Google for demo purpose ? If, in my JavaScript code, I replace "stun.l.google.com:19302" by "toto", I'm still able to make video calls. But as I'm on the same subnet, this can be explainable...

Siva
  • 1,938
  • 1
  • 17
  • 36
Vicky
  • 1,412
  • 4
  • 18
  • 30
  • 2
    https://groups.google.com/forum/#!topic/discuss-webrtc/b-5alYpbxXw why your question is the same ? – Utopik Nov 19 '13 at 09:38
  • STUN from Google not always works well. You can use servers from list I posted here. http://stackoverflow.com/a/20134888/243232 – Vlad Tsepelev Nov 22 '13 at 00:50
  • 1
    possible duplicate of [WEBRTC STUN stun.l.google.com:19302](http://stackoverflow.com/questions/20068944/webrtc-stun-stun-l-google-com19302) – Vaibhav Mule May 08 '15 at 16:19

3 Answers3

74
  • STUN servers are used by both clients to determine their IP address as visible by the global Internet.If both the peers are behind the same NAT , STUN settings are not needed since they are anyways reachable form each other . STUN effectively comes into play when the peers are on different networks.

  • As we know that webRTC is peer to peer and the ice candidates are mandatory in webrtc. ICE functionality can be in any of the two ways , STUN and TURN .

  • There are many stun servers provided by google and other sites which one could use . You can also setup your own STUn server according to rfc5766.

Hope that gives a zest of what and how of stun .

Altanai
  • 1,323
  • 1
  • 19
  • 33
6

A stun server is needed for two clients to communicate using webrtc if they are behind NAT. You will need that stun server to make sure people behind NAT can use the webrtc functionality on your web page.

Munim
  • 6,310
  • 2
  • 35
  • 44
  • STUN servers are only a very small part of NAT traversal. – Brad Dec 13 '16 at 01:13
  • 2
    i downloaded one video chat example but it contains url: ('stun:stun1.l.google.com:19302') and (url: 'turn:numb.viagenie.ca', credential: 'muazkh', username: 'webrtc@live.com') when i removed turn and also it working,may i know i need to use these both or onlyone.. is it open source??Is there any issues will occur for using these STUN and TURN\ – heart hacker Nov 15 '17 at 09:55
  • 2
    You don't need either of STUN or TURN servers for testing purpose. It will simply work locally. However, peers (end users) behind NAT may not be able to connect without having STUN servers. Having STUN will cover up to 86% of your use case. – dubucha Jul 11 '19 at 22:22
  • 3
    Think of STUN as direct flight and TURN as connecting flight station :) – dubucha Jul 11 '19 at 22:22
1

A STUN server basically tells you what your public IP is. (In a nutshell)

Explanation: When collecting ICE Candidates (or the ways to connect to a peer), the WebRTC code collects all possible ways of connecting to a peer. Connecting via the WAN is one of those ways (or candidates). So in order to know what public IP address is assigned to a device by its router (applicable for Full Cone NAT), STUN servers tell you just that.

I recommend reffering to this video for a lucidly beautiful explanation.

Broteen Das
  • 386
  • 4
  • 12