fix camera upload for mobile (#686)
Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
parent
55b0f57741
commit
83ef18f453
|
|
@ -1,12 +1,18 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="relative border">
|
<div class="relative border">
|
||||||
<video
|
<video
|
||||||
id="webcam"
|
id="webcam"
|
||||||
autoplay
|
autoplay
|
||||||
playsinline
|
playsinline
|
||||||
:class="[{ hidden: !isCapturing }, theme.fileInput.minHeight, theme.fileInput.borderRadius]"
|
muted
|
||||||
width="1280"
|
:class="[
|
||||||
height="720"
|
{ hidden: !isCapturing },
|
||||||
|
theme.fileInput.minHeight,
|
||||||
|
theme.fileInput.borderRadius,
|
||||||
|
'w-full h-full object-cover'
|
||||||
|
]"
|
||||||
|
webkit-playsinline
|
||||||
/>
|
/>
|
||||||
<canvas
|
<canvas
|
||||||
id="canvas"
|
id="canvas"
|
||||||
|
|
@ -146,25 +152,58 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
openCameraUpload() {
|
async openCameraUpload() {
|
||||||
this.isCapturing = true
|
this.isCapturing = true
|
||||||
this.capturedImage = null
|
this.capturedImage = null
|
||||||
this.webcam
|
|
||||||
.start()
|
try {
|
||||||
.then(() => {
|
// Get video element
|
||||||
|
const webcamElement = document.getElementById("webcam")
|
||||||
|
const canvasElement = document.getElementById("canvas")
|
||||||
|
|
||||||
|
// iOS specific constraints
|
||||||
|
const constraints = {
|
||||||
|
audio: false,
|
||||||
|
video: {
|
||||||
|
facingMode: this.isBarcodeMode ? 'environment' : 'user',
|
||||||
|
width: { ideal: 1280 },
|
||||||
|
height: { ideal: 720 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try getting the stream directly first
|
||||||
|
const stream = await navigator.mediaDevices.getUserMedia(constraints)
|
||||||
|
|
||||||
|
// Attach stream to video element
|
||||||
|
webcamElement.srcObject = stream
|
||||||
|
|
||||||
|
// Create webcam instance with the stream
|
||||||
|
this.webcam = new Webcam(
|
||||||
|
webcamElement,
|
||||||
|
this.isBarcodeMode ? 'environment' : 'user',
|
||||||
|
canvasElement
|
||||||
|
)
|
||||||
|
|
||||||
|
// Wait for video to be ready
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
webcamElement.onloadedmetadata = () => {
|
||||||
|
webcamElement.play()
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
this.cameraPermissionStatus = "allowed"
|
this.cameraPermissionStatus = "allowed"
|
||||||
if (this.isBarcodeMode) {
|
if (this.isBarcodeMode) {
|
||||||
this.initQuagga()
|
this.initQuagga()
|
||||||
}
|
}
|
||||||
})
|
} catch (err) {
|
||||||
.catch((err) => {
|
console.error('Camera error:', err)
|
||||||
console.error(err)
|
if (err.name === 'NotAllowedError' || err.toString().includes('Permission denied')) {
|
||||||
if (err.toString() === "NotAllowedError: Permission denied") {
|
|
||||||
this.cameraPermissionStatus = "blocked"
|
this.cameraPermissionStatus = "blocked"
|
||||||
return
|
} else {
|
||||||
}
|
|
||||||
this.cameraPermissionStatus = "unknown"
|
this.cameraPermissionStatus = "unknown"
|
||||||
})
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
initQuagga() {
|
initQuagga() {
|
||||||
if (!this.quaggaInitialized) {
|
if (!this.quaggaInitialized) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue