Improve camera request flow and layout

This commit is contained in:
Claudio Ortolina
2025-02-14 11:44:10 +00:00
parent 7be29f1bf0
commit d13f3ce831
3 changed files with 33 additions and 12 deletions
+7 -5
View File
@@ -27,7 +27,7 @@ export default {
.getUserMedia(constraints)
.then((mediaStream) => {
console.debug("Camera access allowed")
this.pushEventTo(this.cameraPreview, "camera_allowed", {});
this.pushEventTo(this.el, "camera_allowed", {});
this.cameraPreview.srcObject = mediaStream;
this.cameraPreview.onloadedmetadata = () => {
this.cameraPreview.play();
@@ -37,7 +37,7 @@ export default {
barcodes.forEach(barcode => {
if (!detectedBarcodes.has(barcode.rawValue)) {
this.pushEventTo(this.cameraPreview, "barcode_scanned", { number: barcode.rawValue });
this.pushEventTo(this.el, "barcode_scanned", { number: barcode.rawValue });
detectedBarcodes.add(barcode.rawValue);
};
});
@@ -46,13 +46,15 @@ export default {
})
.catch((err) => {
console.error(`${err.name}: ${err.message}`);
this.pushEventTo(this.cameraPreview, "camera_denied", {});
this.pushEventTo(this.el, "camera_denied", {});
});
})
},
destroyed() {
this.cameraPreview.srcObject.getTracks().forEach(track => track.stop());
window.clearInterval(this.scanInterval);
if (this.cameraPreview.srcObject) {
this.cameraPreview.srcObject.getTracks().forEach(track => track.stop());
window.clearInterval(this.scanInterval);
}
}
}