Barcode scanner issue fixed (#721)
Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
parent
7b942997ce
commit
c3c66e0b71
|
|
@ -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(
|
||||||
|
|
@ -290,11 +297,7 @@ 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() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue