Skip to content

Commit 58e4bec

Browse files
committed
Try updating available cameras when none are detected
1 parent f1d0336 commit 58e4bec

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/components/Utilities/QRCamera.vue

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,33 @@ onUnmounted(() => {
2323
2424
// get list of camera devices of device and side
2525
// safari problems: always ask
26-
onBeforeMount(() => {
26+
onBeforeMount(() => { updateAvailableCamera() })
27+
28+
function updateAvailableCamera() {
2729
if (navigator.mediaDevices.getUserMedia) {
2830
navigator.mediaDevices
2931
.enumerateDevices()
3032
.then((devices) => {
3133
let environmentCameras = []
3234
devices.forEach((device) => {
3335
if (device.kind === 'videoinput') {
34-
let obj = {}
36+
let obj = {}
3537
const id = device.deviceId
36-
obj.id = id
37-
if (device.label && device.label.length > 0) {
38-
if (device.label.toLowerCase().indexOf('back') >= 0) {
39-
obj.facing = 'environment'
40-
console.log('found back camera')
41-
environmentCameras.push(obj)
42-
}
43-
}
38+
obj.id = id
39+
if (device.label && device.label.length > 0) {
40+
if (device.label.toLowerCase().indexOf('back') >= 0) {
41+
obj.facing = 'environment'
42+
console.log('found back camera')
43+
environmentCameras.push(obj)
44+
}
45+
}
4446
cameraStore.cameraDevices.push(obj)
4547
}
4648
})
47-
console.log('found cameras:')
48-
console.log(cameraStore.cameraDevices)
49-
console.log('found bac cameras:')
50-
console.log(environmentCameras)
49+
console.log('found cameras:')
50+
console.log(cameraStore.cameraDevices)
51+
console.log('found bac cameras:')
52+
console.log(environmentCameras)
5153
5254
// select last of environment cameras
5355
if (environmentCameras.length > 0) {
@@ -62,7 +64,7 @@ onBeforeMount(() => {
6264
console.log(err.name + ': ' + err.message)
6365
})
6466
}
65-
})
67+
}
6668
6769
async function detectedQR([result]) {
6870
if (result) {
@@ -77,6 +79,10 @@ async function detectedQR([result]) {
7779
7880
function switchCamera() {
7981
destroyed.value = true
82+
if (cameraStore.cameraDevices.length < 0) {
83+
console.log("No cameras found in cameraStore, re-enumerationg them")
84+
updateAvailableCamera()
85+
}
8086
cameraStore.toggleCameraSide()
8187
nextTick(() => {
8288
destroyed.value = false

0 commit comments

Comments
 (0)