Skip to content Skip to sidebar Skip to footer

Detect Offline Peer In Webrtc Connection

We are developing a video stream from a mobile device to a computer using WebRTC. The mobile device might lose its connection completely and the computer should be able to detect t

Solution 1:

As a workaround in Firefox, you could use getStats to detect if packets stop coming in:

varfindStat = (m, type) => [...m.values()].find(s => s.type == type && !s.isRemote);

var hasConnected = newPromise(resolve => pc.oniceconnectionstatechange =
  e => pc.iceConnectionState == "connected" && resolve());

var hasDropped = hasConnected.then(() =>newPromise(resolve => {
  var lastPackets = countdown = 0, timeout = 3; // secondsvar iv = setInterval(() => pc.getStats().then(stats => {
    var packets = findStat(stats, "inbound-rtp").packetsReceived;
    countdown = (packets - lastPackets)? timeout : countdown - 1;
    if (!countdown) resolve(clearInterval(iv)); 
    lastPackets = packets;
  }), 1000);
}));

Here's a demo: https://jsfiddle.net/4rzhe7n8/

Solution 2:

Post a Comment for "Detect Offline Peer In Webrtc Connection"