let cameraStream = null;navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } }) .then(function (stream) { const cameraPreview = document.getElementById('cameraPreview'); cameraPreview.srcObject = stream; cameraStream = stream; }) .catch(function (error) { console.error('Error accessing the camera:', error); });const stopCameraButton = document.getElementById('stopCameraButton');stopCameraButton.addEventListener('click', function () { if (cameraStream) { const tracks = cameraStream.getTracks(); tracks.forEach(track => track.stop()); cameraStream = null; const cameraPreview = document.getElementById('cameraPreview'); cameraPreview.srcObject = null; }});