Search code examples
javascriptgoogle-chromewebrtcpeerjs

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
}

Solution

  • 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();