when is onicecandidate event handler invoked and what is the necessity of this?

1,884 views
Skip to first unread message

Arafat Al Mahmud

unread,
Oct 10, 2014, 10:18:11 PM10/10/14
to discuss...@googlegroups.com
In the SDP offers and answers, the ice candidates are mentioned. What I have understood so far is the ice candidates are parsed from the SDPs and used for ICE processing. We exchange the SDPs to the remote peers and thus they can get the informations about other peer's ice candidates. But I have seen many examples where from the onicecandidate event handler the received ice candidate event is sent to the remote peer using signalling mechanism. My question is, If the SDP already contains the required info, then why should we transmit ice candidate event data to the other peer ? Exactly in which order this event handler is invoked ?

Faraz Khan

unread,
Oct 15, 2014, 1:59:29 PM10/15/14
to discuss...@googlegroups.com
Arafat,
Its to handle trickle-ice. With webrtc native c++ (which is what we use) you have to use the OnIceCandidate and send the candidate across (I dont get any ice is the offer/answer sdps) as they are generated (one by one). I prefer it this way since its MUCH faster to establish a connection (rather than wait for all candidates to gather first).

I thought this is how chrome/firefox worked too - but I might be mistaken so someone else can probably help you there!

Anirban Dutta Ankan

unread,
Mar 24, 2016, 9:47:39 AM3/24/16
to discuss-webrtc
Hi Faraz,

Can you mention how to send the candidates to native c++ ? My localPeerConnection.onICEcandidate bind the icecandidates to local description, sends a offer to native c++ application and get an answer back. As there is no icecandidate in answer sdp, browser can't add a remotestream.

How to talk for ice candidates with a native c++ application ?

Thanks.

Ivaylo Tsankov

unread,
Mar 24, 2016, 3:29:15 PM3/24/16
to discuss-webrtc
The things are simple. When you create an offer and set it to local peer connection ice gathering mechanism is activated and onicecandidate event occurs when candidate is gathered. The last candidate is a NULL in both JS and C++ APIs. This means that all local candidates are gathered. When this happens you have get local SDP from peerconnection object. This object will consists of SDP plus all the candidates which are gathered during the candidate gathering process. You can use this logic to skip sending candidates and when last NULL candidate is gathered to request SDP from peer connection and send it over signalling mechanism. This will slow down the process but it will ease handling async code and race conditions.

Taylor Brandstetter

unread,
Mar 24, 2016, 3:58:17 PM3/24/16
to discuss...@googlegroups.com
I think the question may be asking how to add ICE candidates without waiting for them to all be gathered.

To do that using the native C++ API, you would listen to the OnIceCandidate callback, which indicates that a new candidate has been gathered. Then you can serialize it; a ToString method is provided which creates an SDP string, but you also need to signal the "mid" and/or "sdp_mline_index", to match a candidate to a media description. When the candidate is received by the peer, you can deserialize it by calling CreateIceCandidate, and then pass the resulting object into the PeerConnection via "AddIceCandidate".

On Thu, Mar 24, 2016 at 12:29 PM, Ivaylo Tsankov <ivaylot...@gmail.com> wrote:
The things are simple. When you create an offer and set it to local peer connection ice gathering mechanism is activated and onicecandidate event occurs when candidate is gathered. The last candidate is a NULL in both JS and C++ APIs. This means that all local candidates are gathered. When this happens you have get local SDP from peerconnection object. This object will consists of SDP plus all the candidates which are gathered during the candidate gathering process. You can use this logic to skip sending candidates and when last NULL candidate is gathered to request SDP from peer connection and send it over signalling mechanism. This will slow down the process but it will ease handling async code and race conditions.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/c54af560-3c19-4a72-8170-e6b7a41f7137%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages