Search code examples
firefoxwebrtcrtspstun

How can I use webrtc offline


I'm developing a Vuejs app that among other things displays several RTSP streams in the browser. For converting the streams and displaying them I'm using RTSPtoWebRTC with WebRtcPlayer. I decided to use WebRTC because of the low latency (this is a robotics project). This method is working fine and I can view all the streams with a max latency of 50ms. But as soon as I disconnect from the internet I get an error:

Uncaught DOMException: Can't create RTCPeerConnections when the network is down

I cant count that this robot will have an internet connection at all time, this isnt the intent.

I tried several solutions like removing any mention of external iceServers from the player and the server.

      iceServers: [{
        urls: ["stun:stun.l.google.com:19302"]
      }]

Tried running my own STUN/TURN server with coturn and supplying the ip address as an ICE server but to no success - still same no internet error.

I'm running the app on Firefox if this matters and I found this post from a while back: firefox bug report about this issue

I tried the suggestion there of trying to set media.peerconnection.ice.loopback in about:config to true but still doesn't work.

Help is much appreciated!

Edit:

So, after spending too many hours trying to solve this I found that in Chrome this works offline just fine. So I’ll just stick to that


Solution

  • The error gets thrown here in Firefox code: https://searchfox.org/mozilla-central/source/dom/media/PeerConnection.jsm#473

    The workaround with the loopback interface no longer works if I read that code correct. The if condition in the code just asks the networking code if there is any network connectivity.

    So you either

    • try Phillips suggestion of making one network interface believe it still has connectivity. Maybe a fake interface with a hard coded IP address, but no default route would be enough.
    • Or you convince the Mozilla developers that there are reasonable use cases for using PeerConnections in offline scenarios to drop that check in Firefox - although I would be concerned that it might run into another error further down in the code. Or you could try to submit a patch yourself.