1

WebRTC API allows you to turn on the flashlight feature on your phone from Chrome. However you can not turn it off. I have seen this problem on my Xiaomi phone and on Samsung devices.

function toggleFlash() {
  let that = this;
  const mediaStreamTrack = this.$refs.video.srcObject.getVideoTracks()[0];
  const imageCapture = new window.ImageCapture(mediaStreamTrack);
  imageCapture.getPhotoCapabilities().then(() => {
    if (that.tourch === false) {
      that.tourch = true;
      mediaStreamTrack.applyConstraints({
        advanced: [{ torch: true }]
      });
    } else if (that.tourch === true) {
      that.tourch = false;
      mediaStreamTrack.applyConstraints({
        advanced: [{ torch: false }]
      });
    }
  });
}
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • torch is written without an 'u'. that may be your problem – andii1997 Jun 27 '18 at 06:02
  • Find below reference. also without 'u' working and torch getting on. https://stackoverflow.com/questions/37848494/is-it-possible-to-control-the-camera-light-on-a-phone-via-a-website – Bhargav Chauhan Jun 27 '18 at 06:47
  • [here](https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints) it says it stays on, as long as the track is active. Try using `mediaStreamTrack.stop()` instead of the `mediaStreamTrack.applyConstraints(...)` – andii1997 Jun 27 '18 at 06:50
  • using `mediaStreamTrack.stop()` it could be stop camera as well. not possible to apply `mediaStreamTrack.stop()` – Bhargav Chauhan Jun 27 '18 at 07:22
  • oh, i thought you just wanted to use the torch. – andii1997 Jun 27 '18 at 07:24
  • No I was used camera and torch both. but in some devices like MI(all devices), `Motorola Droid turbo 2` torch off not working. – Bhargav Chauhan Jun 27 '18 at 07:33

0 Answers0