Search code examples
webrtcsipjs

ICE restart with SIP.js


What is the proper procedure to do ICE restart when using SIP.js? (v0.20.0)

This is what I'm trying:

oniceconnectionstatechange: (event) => {

    const newState = sdh.peerConnection.iceConnectionState;
    
    if (newState == 'failed') {
    
        sdh.peerConnection.restartIce();

        sdh.peerConnection.createOffer({'iceRestart': true})
            .then(function(offer) {
                return sdh.peerConnection.setLocalDescription(offer);
            });
    }

}

It seems to execute without an error, but also no result. FireFox debug-tool "about:webrtc" shows "ICE restarts: 0", so I guess it didn't even begin restart.

ps: failed state is induced by restarting RTP Engine (Kamailio setup). After RTP Engine restarts there is still audio for about 20 seconds and only when ICE state changes to "failed" audio stops.


Solution

  • Found solution that fixed my problem:

    sdh.peerConnectionDelegate = {
        oniceconnectionstatechange: (event) => {
            const newState = sdh.peerConnection.iceConnectionState;
    
            if (newState === 'disconnected') {
                sdh.peerConnection.restartIce();
    
                sdh.peerConnection.createOffer({'iceRestart': true})
                    .then((offer) => {
                        sdh.peerConnection.setLocalDescription(offer);
                        session.sessionDescriptionHandlerModifiersReInvite = [offer];
    
                        session.invite()
                            .then(() => {
                                session.logger.debug('iceRestart: RE-invite completed');
                            })
                            .catch((error) => {
                                if (error instanceof RequestPendingError) {
                                    session.logger.error('iceRestart: RE-invite is already in progress');
                                }
                                throw error;
                            });
                    });
            }
        }
    };