Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely turn off camera on mediastream javascript

im trying to create a video conference web app..

the problem is im trying to disable my camera on the middle conference, its work but my laptop camera indicator still on (the light is on) but on my web, video show blank screen, is that normal or i miss something?

here what i try

videoAction() {
  navigator.mediaDevices.getUserMedia({
    video: true,
    audio: true
  }).then(stream => {
     this.myStream = stream
  })

  this.myStream.getVideoTracks()[0].enabled = !(this.myStream.getVideoTracks()[0].enabled)
  this.mediaStatus.video = this.myStream.getVideoTracks()[0].enabled
}
like image 800
Jazuly Avatar asked Sep 14 '25 22:09

Jazuly


2 Answers

There is also a stop() method which should do the trick in Chrome and Safari. Firefox should already mark the camera as unused by setting the enabled property.

this.myStream.getVideoTracks()[0].stop();
like image 71
chrisguttandin Avatar answered Sep 17 '25 14:09

chrisguttandin


We need to assign window.localStream = stream; inside navigator.mediaDevices.getUserMedia method

For Stop Webcam and LED light off.

localStream.getVideoTracks()[0].stop();
video.src = '';

like image 36
Reshmakhan Avatar answered Sep 17 '25 14:09

Reshmakhan