How to start collecting ICE peer candidates

I am developing a signaling system between two peers and notice that the RTCPeerConnection.onicecandidate event does not fire. I checked iceGatheringState and it always returns as “new”, which means that the peer did not start looking for ice candidates.

How to initiate the collection of candidate objects on ice from the local machine, which will be sent to the peer?

and

If I do not want to leak candidates, how can I send them via sdp after they are assembled?

This is my current code, I can successfully get the sdp data and commit it for sending, so ice and checking if the two clients are connected are the only problems.

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
    }
}
+4
1

ICE , setLocalDescription SDP, createOffer createAnswer.

, , peerConn.localDescription.sdp - .

+7

Source: https://habr.com/ru/post/1648826/


All Articles