How to detect a frozen video stream in WebRTC



Unfortunately, from time to time when making a one-on-one video call using react-native-webrtc one of the two video streams freezes or becomes black. Is there a way to detect when that happens programmatically? Thx in advance!

Answer

It looks like each video track has a listener that fires as soon as the stream freezes.

In react native it’s the onmute listener:

stream.getVideoTracks().forEach(videoTrack => {
    videoTrack.onmute = () => {
        console.log("Frozen video stream detected!");
    };
});

Note that in React Native detecting frozen streams with this method only seems to work for remote tracks!

To detect if a stream is currently frozen I use ‚Äčthe muted property on the video track:

console.log(videoTrack.muted); // true when frozen

Another way I’ve found but haven’t explored further is the getStats() method on the RTCPeerConnection. It returns a promise with a huge amount of data that can be used to detect frozen video streams and a lot more I suppose.



Source: stackoverflow