Format js files

This commit is contained in:
Claudio Ortolina
2025-03-06 15:49:54 +00:00
parent 4e609465c3
commit 13add71066
2 changed files with 36 additions and 29 deletions
+17 -14
View File
@@ -7,7 +7,7 @@ const barcodeReaderSetup = async function () {
// make sure the formats are supported
formats: supportedFormats,
});
}
};
export default {
async mounted() {
@@ -17,16 +17,18 @@ export default {
const constraints = {
audio: false,
video: {
width: 800, height: 600, facingMode: {
ideal: "environment"
}
width: 800,
height: 600,
facingMode: {
ideal: "environment",
},
},
};
this.el.addEventListener("camera_request", () => {
navigator.mediaDevices
.getUserMedia(constraints)
.then((mediaStream) => {
console.debug("Camera access allowed")
console.debug("Camera access allowed");
this.pushEventTo(this.el, "camera_allowed", {});
this.cameraPreview.srcObject = mediaStream;
this.cameraPreview.onloadedmetadata = () => {
@@ -35,26 +37,27 @@ export default {
const barcodes = await barcodeDetector.detect(this.cameraPreview);
if (barcodes.length <= 0) return;
barcodes.forEach(barcode => {
barcodes.forEach((barcode) => {
if (!detectedBarcodes.has(barcode.rawValue)) {
this.pushEventTo(this.el, "barcode_scanned", { number: barcode.rawValue });
this.pushEventTo(this.el, "barcode_scanned", {
number: barcode.rawValue,
});
detectedBarcodes.add(barcode.rawValue);
};
}
});
}, 500)
}, 500);
};
})
.catch((err) => {
console.error(`${err.name}: ${err.message}`);
this.pushEventTo(this.el, "camera_denied", {});
});
})
});
},
destroyed() {
if (this.cameraPreview.srcObject) {
this.cameraPreview.srcObject.getTracks().forEach(track => track.stop());
this.cameraPreview.srcObject.getTracks().forEach((track) => track.stop());
window.clearInterval(this.scanInterval);
}
}
}
},
};