Reputation: 443
Don't know if this example is correct
The process, call new RTCPeerConnection()
then createOffer()
then setLocalDescription()
Then I wait for onicecandidate
take what it gives and first send the offer
and second the icecandidates
through the signal server
to the other peer
Then the other peer takes the received offer
into setRemoteDescription(offer)
then the received icecandidates
into addIceCandidate(icecandidates)
then calls createAnswer()
this gives an answer
to put in setLocalDescription(answer)
this triggers onicecandidate
take these icecandidates
with the answer
=offer
and send them back to the other peer
The other peer takes the answer
into setRemoteDescription(answer)
then the received icecandidates
into addIceCandidate(icecandidates)
I think in this example the connection will work when testing inside local network but what if it doesn't because its not a local network, at what step in this example will the API call the STUN server and what other functions do I need to call if it does call the STUN server?
Upvotes: 3
Views: 1213
Reputation: 21
I've found that one way to generate BIND requests to be sent to the STUN server right away is to set the iceCandidatePoolSize option in the configuration to be > 0.
config = {iceServers: [{urls:stun:stunserver.stunprotocol.org}], iceCandidatePoolSize: 1};
peerConnection = new RTCPeerConnection(config); // pretty much starts to resolve the DNS name and sends BIND requests right away.
Hope this helps.
Also: this link is chock-full of great suggestions to troubleshoot webrtc connections.
Upvotes: 2
Reputation: 42430
You need to specify a STUN server in the peer connection's configuration. E.g.:
pc = new RTCPeerConnection({iceServers: [{urls: "stun:stun.1.google.com:19302"}]});
There are no other methods to call, provided it works on a LAN already. You should see additional calls to onicecandidate
from this, compared to before. That's it.
Note that a couple of the things you describe happen in parallel, but in short, what triggers the browser to connect to the STUN server is setLocalDescription
. It causes the browser's built-in ICE agent to kick off its candidate gathering process for this connection, and STUN is part of that.
Upvotes: 0