google-chromewebrtcmobile-chrome

webRTC is not reconnecting after internet dropout on Chrome mobile


I have a webRTC video which is working as expected between Chrome on PC and Chrome on mobile but if the internet connection is disrupted on the mobile it will not resume the webRTC video when it is back online, however it will resume correctly if it is the Chrome on PC that has the internet disrupted.

It is the same implementation used regardless of device or browser and chrome mobile seems to support webRTC the same as desktop (https://caniuse.com/?search=webrtc), why might it be failing on mobile chrome?

I have the below 'oniceconnectionstatechange' function:

 pc.oniceconnectionstatechange = event => {
     if (pc.iceConnectionState === 'failed') {
       pc.restartIce()
     }
  }

Solution

  • I think you are seeing the different behaviors because of your NAT Mappings. It could be something else, but with the details we have that is my first guess.

    When the connection is disrupted on desktop (and then returns) you are keeping your NAT Mapping. When the connection is disrupted on mobile maybe you are getting a new one. You could confirm the behavior yourself by sending UDP packets from your phone and printing out the src details on a world routable server.

    The proper way to reconnect a peer is to do an ICE Restart. That ensures that even if your network path changes you will reconnect.