sk10
sk10

Reputation: 73

Both WebRTC peers initiate ICE restart simultaneously

I am fairly new to webRTC. The problem pertains to ICE restart. Let's say there are 2 peers connected using webRTC and one of them loses connection. Now, the peer connection will first go into "disconnected" state. And shortly after, if there is still no connection, goes into "failed" state.

Now, I understand once this failed state is reached, I have to perform an ICE restart. The problem is that even though one peer loses connection, both peers will report "failed" state and try to perform ICE restart, which I believe should be problematic. Here is a snippet of the code:

if (peer.localConnection.iceConnectionState == "failed") {
            // create an offer
                peer.localConnection.createOffer({
                    iceRestart : true
                }).then(function(offer) {
                    peer.localConnection.setLocalDescription(offer);
                    // forward the offer to the signaling server
                    var msg = createMsg("OFFER", myId, peerId, offer);
                    sendToSignallingServer(msg);
                }, function(error) {
                    //error
                });
        }

I understand that upon finding that there are now two offers, one of the peers should perform a "rollback" using RTCSessionDescription("rollback"). But I am confused whether this will work or not since both the peers might try to perform rollback.

How I can I make sure that only one peer performs a rollback?

Upvotes: 1

Views: 1770

Answers (1)

Philipp Hancke
Philipp Hancke

Reputation: 17305

One way to avoid the situation (as rollback is not widely implemented yet) is to only do the ice restart when your side of the connection sent the initial offer.

Upvotes: 3

Related Questions