fix: switchCamera
All checks were successful
Build & Deploy on Dev / build (push) Successful in 2m51s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 2m51s
This commit is contained in:
parent
d4ae2f56a0
commit
e1962d79bb
1 changed files with 20 additions and 2 deletions
|
|
@ -392,8 +392,26 @@ async function switchCamera() {
|
|||
return
|
||||
}
|
||||
|
||||
const targetType: 'front' | 'back' = currentCameraType.value === 'front' ? 'back' : 'front'
|
||||
await changeCamera(targetType)
|
||||
const frontCameras = availableCameras.value.filter((device: any) =>
|
||||
identifyCameraType(device.label || '') === 'front'
|
||||
)
|
||||
const backCameras = availableCameras.value.filter((device: any) =>
|
||||
identifyCameraType(device.label || '') === 'back'
|
||||
)
|
||||
|
||||
let targetDevice
|
||||
if (currentCameraType.value === 'front' && backCameras.length > 0) {
|
||||
targetDevice = backCameras[0]
|
||||
} else if (frontCameras.length > 0) {
|
||||
targetDevice = frontCameras[0]
|
||||
} else {
|
||||
const nextIndex = (currentCameraIndex.value + 1) % availableCameras.value.length
|
||||
targetDevice = availableCameras.value[nextIndex]
|
||||
}
|
||||
|
||||
await camera.value?.changeCamera(targetDevice.deviceId)
|
||||
currentCameraIndex.value = availableCameras.value.indexOf(targetDevice)
|
||||
currentCameraType.value = identifyCameraType(targetDevice.label || '')
|
||||
}
|
||||
|
||||
/** function ถ่ายรูป*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue