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";}
}