Sureshkumar Menon
Sureshkumar Menon

Reputation: 1165

Generating ICE Candidates

I am working WebRTC API's to make a video call between two PC's running on chrome browser. My observation is ICE Candidates are generated only if i connected to internet else no ice candidates are generated. Why is it like that?

connection block

var pc_config = {"iceServers":[]};

      pc = new webkitRTCPeerConnection(pc_config);
       pc.onicecandidate=function (evt) {

       if(evt.candidate){
         console.log("Sending candidate to other peer"+evt);
        jWebSocketClient.broadcastText("",evt);
        }
      };  

Thanks, Sureshkumar Menon

Upvotes: 6

Views: 6164

Answers (3)

Naziru
Naziru

Reputation: 21

Yes you have to connect to internet before your pcs share SDP. This is because ICE Server is not on your local computers but on the internet. The ICE server is connected in the WEB RTC in this line:

if (browser === 'firefox') { PeerConnConfig = { iceServers: [{ url: "stun:23.21.150.121" // FF doesn't support resolving DNS in iceServers yet } ] }; mediaConstraints = { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true, MozDontOfferDataChannel: true // Tell FF not to put datachannel info in SDP or chrome will crash } }; // FF doesn't expose this yet MediaStream.prototype.getVideoTracks = function () { return []; }; MediaStream.prototype.getAudioTracks = function () { return []; }; } else { PeerConnConfig = { iceServers: [{ url: "stun:stun.l.google.com:19302" } ] }; mediaConstraints = { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true }, optional: [{ DtlsSrtpKeyAgreement: true } ] }; // API compat for older versions of chrome if (!MediaStream.prototype.getVideoTracks) { MediaStream.prototype.getVideoTracks = function () { return this.videoTracks; }; MediaStream.prototype.getAudioTracks = function () { return this.audioTracks; }; } if (!PeerConnection.prototype.getLocalStreams) { PeerConnection.prototype.getLocalStreams = function () { return this.localStreams; }; PeerConnection.prototype.getRemoteStreams = function () { return this.remoteStreams; }; } }

I cut above code from WEBRTC_SHIM. consider especially line that defines the ICE server as: url: "stun:stun.l.google.com:19302".

Upvotes: -2

ZaX
ZaX

Reputation: 313

As far as I understand, there is four types of ICE candidate :

  1. Host candidate : from your local interface.
  2. Server reflexive candidate : provided by the STUN server, a translation of your local address into public network.
  3. Relayed candidate : provided by a TURN server, data will be relayed by the server
  4. Peer reflexive candidate : a rare case (?) where candidate is discovered during the connectivity checks. I'll skip this part as it is quite rare and I'm not sure to understand the big picture of it.

If you don't provide any STUN / TURN addresses to your program or if they are unreachable, the only candidate which can be retrieved is the host one. Note that your local address (127.0.0.1) is not taken as a potential candidate. Hope it helps.

However, I'm not totally sure to understand your use case.. Are both computers on the same local network ? If your interface is up, you should get at least the host candidate. I only worked with the C++ API, but I don't see why it would have a different behavior with the Javascript's.

Upvotes: 11

Masiar
Masiar

Reputation: 21352

If I'm not mistaken, ICE Candidates are created by contacting a STUN server, thus you need internet connection. This is done to translate a private address into a public one to enable your clients to connect (and be connected) to other clients.

Upvotes: 1

Related Questions