1
0
forked from test/crm

fix: switch camera not working

This commit is contained in:
Shariq Ansari 2024-10-21 20:59:01 +05:30
parent c79cb3d52f
commit 96afa1fa50

View File

@ -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()
}