I am developing the signaling system between two peers and have noticed that the RTCPeerConnection.onicecandidate event is not firing. I checked the iceGatheringState and it always returns as "new" meaning the peer connection has not began searching for ice candidates.
How do I initiate the gathering of ice candidate objects from the local machine to be sent out to a peer?
and
If I do not want to trickle candidates, how will I be able to send them over sdp once gathered?
This is my current code, I am able to successfully attain sdp data and capture them to be sent so ice and checking if the two clients are connected are the only issues.
var peerConn = new webkitRTCPeerConnection(
{'iceServers':[{'url':'stun:stun.1.google.com:19302'}]}
);
var remoteConn = new webkitRTCPeerConnection(
{'iceServers':[{'url':'stun:stun.1.google.com:19302'}]}
);
alert(peerConn.iceGatheringState);
///Event Handlers//
//will be called when each event occurs
//onicecandidate
//returns local ice candidates (when gathered) to be sent to peer
//peerConn.onicecandidate = onicecandidate;
peerConn.onicecandidate = function(iceEvent){ //not firing
if(iceEvent.candidate === null){
alert(peerConn.iceConnectionState);
alert(iceEvent.candidate);
//send to peer or put in with sdp data
}
}
After setLocalDescription(), the caller asks STUN servers to generate the ice candidates. The caller uses the signaling server to transmit the offer to the intended receiver of the call. The recipient receives the offer and calls RTCPeerConnection.
ice gathering is the generation of the local candidates you will send to the remote peer either in the offer sdp (full ICE) or separately (trickle ICE). ice gathering state is the state of the connection with the remote peer based on your trying of the remote candidates received through your chosen signaling method.
WebRTC uses a mechanism called ICE to to gather different types of candidates, and then it will start negotiating to see which of these candidates stick and allow me to reach out to you in that call.
ICE trickling is the process of continuing to send candidates after the initial offer or answer has already been sent to the other peer.
ICE gathering starts once you call setLocalDescription with the SDP you generated with createOffer or createAnswer.
If you don't want to use trickle ice, wait for the null candidate and then send the content of peerConn.localDescription.sdp -- which should include the candidates then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With