Barcode scanner issue fixed (#721)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2025-03-12 12:58:50 +05:30 committed by GitHub
parent 7b942997ce
commit c3c66e0b71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 6 deletions

View File

@ -165,6 +165,10 @@ export default {
this.openCameraUpload() this.openCameraUpload()
}, },
beforeUnmount() {
this.cleanupCurrentStream()
},
methods: { methods: {
async cleanupCurrentStream() { async cleanupCurrentStream() {
if (this.quaggaInitialized) { if (this.quaggaInitialized) {
@ -183,6 +187,8 @@ export default {
const webcamElement = document.getElementById("webcam") const webcamElement = document.getElementById("webcam")
if (webcamElement && webcamElement.srcObject) { if (webcamElement && webcamElement.srcObject) {
const tracks = webcamElement.srcObject.getTracks()
tracks.forEach(track => track.stop())
webcamElement.srcObject = null webcamElement.srcObject = null
} }
}, },
@ -226,6 +232,7 @@ export default {
} }
const stream = await navigator.mediaDevices.getUserMedia(constraints) const stream = await navigator.mediaDevices.getUserMedia(constraints)
this.mediaStream = stream // Store the stream reference
webcamElement.srcObject = stream webcamElement.srcObject = stream
this.webcam = new Webcam( this.webcam = new Webcam(
@ -289,12 +296,8 @@ export default {
}, },
cancelCamera() { cancelCamera() {
this.isCapturing = false this.isCapturing = false
this.capturedImage = null this.capturedImage = null
if (this.quaggaInitialized) { this.cleanupCurrentStream() // Use the cleanup method
Quagga.stop()
this.quaggaInitialized = false
}
this.webcam.stop()
this.$emit("stopWebcam") this.$emit("stopWebcam")
}, },
processCapturedImage() { processCapturedImage() {