6

I am trying to implement a toggle video feature using webRTC. Refer to the following code:

<video id="remote" autoPlay></video>
<button onclick="toggleVideo()">Toggle video</button>
let localVideo = document.querySelector('#local');

const toggleVideo = () => {
    localVideo.srcObject.getVideoTracks()[0].enabled = !localVideo.srcObject.getVideoTracks()[0].enabled
}

This turns off video as well as webcam indicator in firefox but not in chrome. Chrome only turns off the video.

According to MDN docs,

If the MediaStreamTrack represents the video input from a camera, disabling the track by setting enabled to false also updates device activity indicators to show that the camera is not currently recording or streaming. For example, the green "in use" light next to the camera in iMac and MacBook computers turns off while the track is muted in this way.

MDN docs Is there any other workaround?

RisingGeek
  • 83
  • 1
  • 9
  • Does this answer your question? [Why when both audio and video MediaStreamTracks enabled parameter set to false, "on-air" indicator keeps being turned on?](https://stackoverflow.com/questions/33304281/why-when-both-audio-and-video-mediastreamtracks-enabled-parameter-set-to-false) – Theolodis Nov 20 '20 at 13:03
  • No, I have seen many applications which have this feature. The mentioned question doesn't solve the issue. – RisingGeek Nov 21 '20 at 14:48
  • 1
    So the light does not stop blinking for you on chrome, if you stop the track? `localVideo.srcObject.getVideoTracks()[0].stop()` – Theolodis Nov 24 '20 at 15:30
  • Yes, you are correct. – RisingGeek Nov 25 '20 at 12:53

0 Answers0