Disable ICE Trickling

ICE trickling is a process where candidate-pairs are shared as soon as gathered by the ICEAgent.

Its true that, there is NO JavaScript API "currently" available in RTCWeb drafts to disable ICE-trickling process however, there is a trick that can be used to merge all candidate pairs in the session-description, and then you merely need to share that "single" SDP only.

The trick is simple: Wait until "end-of-candidate" signal is fired.

Usually "onicecandidate" event returns "NULL" entry for "event.candidate" object.

In "old-good" days, we were watching for "oniceconnectionstatechange" event, and checking for "peer.iceGatheringState === 'complete'" to return the SDP.

BTW, you can still listen for both "end-of-candidate" NULL value, as well as "peer.iceGatheringState === 'complete'".

peer.oniceconnectionstatechange = function(event) {
    if (peer.iceGatheringState === 'complete') {
        send_sdp_to_remote_peer();
    }
};

peer.onicecandidate = function(event) {
    if (event.candidate === null) {
        return send_sdp_to_remote_peer();
    }
};

var isSdpSent = false;

function send_sdp_to_remote_peer() {
    if (isSdpSent) return;
    isSdpSent = true;
  
    var sdp = peer.localDescription;
    socket.emit('remote-sdp', sdp);
}


No comments:

Post a Comment