0

I have created the following javascript code, but I need to figure out a way to turn off the device's camera other than with a page refresh, which is not the best method. I'm new to javascript, but I'm not quite sure what to do from here. How would I turn off the device's camera in the if (arg == "hide") section?

  var turninModal = document.getElementById("turninModal");
  function turnin(arg) {
      if (arg == "show") {
        turninModal.style.display = "block";
        let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
        scanner.addListener('scan', function (content) {
          var audio = new Audio('beep-02.mp3');
          audio.play();
          if(validURL(content) == true) {window.open(content, '_self');}
        });
        Instascan.Camera.getCameras().then(function (cameras) {
          if (cameras.length > 0) {scanner.start(cameras[0]);}
          else {console.error('No cameras found.');}
        }).catch(function (e) {console.error(e);});
      }
      if (arg == "hide") {location.reload();}
  }
  window.onclick = function(event) {
    if (event.target == turninModal) {turninModal.style.display = "none";}
  }
Johnathan
  • 47
  • 5
  • Refer this answer. this is for usermedia. but same can be applied here i guess. https://stackoverflow.com/questions/28140147/turn-off-webcam-camera-after-using-getusermedia – Supun Dharmarathne Jul 26 '21 at 03:40
  • Try this method from official docs to stop camera - https://github.com/schmich/instascan#scannerstop – Azeem Aslam Jul 26 '21 at 06:11

0 Answers0