'REACT - How Can I subscribe stream video data during webRTC with socket.io?

Now I try to develop the video chat web app with REACT.

And I try to catch when peer screen turns off the video.

here is my code,

function paintPeerFace(peerStream, id, remoteNickname) {
console.log("peerStream : ", peerStream, id, remoteNickname);

if (checker) {
  addVideoStream(video2Ref.current, peerStream);
  console.log("video on/off?", peerStream.getVideoTracks()[0].enabled);
  setUser1(peerStream.getVideoTracks()[0].enabled);
  user1Stream.current = peerStream;
  checker = false;
} else {
  addVideoStream(video3Ref.current, peerStream);
  
}

}

in here,

peerStream.getVideoTracks()[0].enabled

I try to check the video stream data whether true(video on) or false(video off).

and when it is 'false',

I want to make my view changed.

So, Can I subscribe the stream data with REACT?



Solution 1:[1]

You can use MediaStreamTrack's "mute", "unmute" or "ended" events to check if it's active.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Liubomyr