Saran Kumar
Saran Kumar

Reputation: 79

Turn off/stop browser camera in my sample react video call application

I am developing a video chat web application using react.js and kurento utils SDK for the media server. The problem is that the camera/light is still ON even after the video call is ended.The camera stops only for the first time and the problem occurs only from the second call.

  let stream = videoElem.srcObject;
  let tracks = stream.getTracks();

  tracks.forEach(function(track) {
    track.stop();
  });

  videoElem.srcObject = null;
}

I tried every possible ways to solve this issue and the above code is what i used for stopping camera.Is this a problem with react.js?

Upvotes: 3

Views: 5479

Answers (2)

Marcos López
Marcos López

Reputation: 5

You must have more than one stream instances. What you can do is to have a single instance of stream, you can store it on redux or context and call it when you need it accordingly.

Upvotes: 0

vivekvw
vivekvw

Reputation: 113

Can you try stopping individual video and audio track as webrtc APIs e.g.

mediaStream.getAudioTracks()[0].stop();
mediaStream.getVideoTracks()[0].stop();

Upvotes: 3

Related Questions