ICE 重启 SIP.js

ICE restart with SIP.js

使用 SIP.js 时,ICE 重启的正确步骤是什么? (v0.20.0)

这就是我正在尝试的:

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);
            });
    }

}

好像执行没有错误,但也没有结果。 FireFox 调试工具“about:webrtc”显示“ICE 重启:0”,所以我猜它甚至没有开始重启。

ps:失败状态是通过重新启动 RTP 引擎(Kamailio 设置)引起的。在 RTP 引擎重新启动后,仍然有大约 20 秒的音频,并且仅当 ICE 状态更改为“失败”音频 stops.

找到解决我问题的方法:

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;
                        });
                });
        }
    }
};