From 96afa1fa50998d855ed1cdb79ad94288cf3eb955 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 21 Oct 2024 20:59:01 +0530 Subject: [PATCH] fix: switch camera not working --- .../components/FilesUploader/FilesUploaderArea.vue | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/FilesUploader/FilesUploaderArea.vue b/frontend/src/components/FilesUploader/FilesUploaderArea.vue index 97db094c0..30b8a0eb1 100644 --- a/frontend/src/components/FilesUploader/FilesUploaderArea.vue +++ b/frontend/src/components/FilesUploader/FilesUploaderArea.vue @@ -201,21 +201,29 @@ function onFileInput(event) { const video = ref(null) const facingMode = ref('environment') +const stream = ref(null) async function startCamera() { showCamera.value = true - let stream = await navigator.mediaDevices.getUserMedia({ + stream.value = await navigator.mediaDevices.getUserMedia({ video: { facingMode: facingMode.value, }, audio: false, }) - video.value.srcObject = stream + video.value.srcObject = stream.value +} + +function stopStream() { + stream.value.getTracks().forEach((track) => track.stop()) + showCamera.value = false + cameraImage.value = null } function switchCamera() { facingMode.value = facingMode.value === 'environment' ? 'user' : 'environment' + stopStream() startCamera() }