Skip to content

Commit c01f301

Browse files
committed
fix(paused): prevent scanning frozen stream
Formally this was solved by setting `decodeResult` to `null` when the stream start playing again. This property has been removed. Now solved again by having a dedicated property `readyAfterPause`.
1 parent 4835330 commit c01f301

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/components/QrcodeReader.vue

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ export default {
3737
return {
3838
camera: null,
3939
destroyed: false,
40+
readyAfterPause: true,
4041
}
4142
},
4243
4344
computed: {
4445
4546
shouldScan () {
46-
return !this.paused && this.camera !== null && !this.destroyed
47+
return this.paused === false &&
48+
this.camera !== null &&
49+
this.destroyed === false &&
50+
this.readyAfterPause
4751
},
4852
4953
/**
@@ -74,36 +78,29 @@ export default {
7478
7579
watch: {
7680
/**
77-
* Automatically freezes the video stream when conditions for the scanning
78-
* process are not fullfilled anymore.
79-
*
8081
* Starts continuous scanning process as soon as conditions for that are
8182
* fullfilled. The process stops itself automatically when the conditions
8283
* are not fullfilled anymore.
8384
*/
8485
shouldScan (shouldScan) {
8586
if (shouldScan) {
86-
this.$refs.video.play()
8787
this.startScanning()
88-
} else {
89-
this.$refs.video.pause()
9088
}
9189
},
9290
93-
/**
94-
* Resets decodeResult when component is un-paused. This way one QR code
95-
* can be decoded twice in a row (see #8). Waits though until video is
96-
* actually not frozen anymore. Otherwise the last frame from before
97-
* pausing would be rescanned.
98-
*/
99-
paused (newValue) {
100-
if (newValue === false) {
101-
const resetDecodeResult = () => { this.decodeResult = null }
102-
const video = this.$refs.video
91+
paused (paused) {
92+
const video = this.$refs.video
93+
94+
if (paused) {
95+
video.pause()
96+
97+
this.readyAfterPause = false
98+
} else {
99+
video.play()
103100
104101
video.addEventListener(
105102
'timeupdate',
106-
resetDecodeResult,
103+
() => { this.readyAfterPause = true },
107104
{ once: true }
108105
)
109106
}

src/misc/Scanner.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ export function keepScanning (camera, options) {
3131

3232
const recur = (contentBefore, locationBefore) => {
3333
return () => {
34-
const imageData = camera.captureFrame()
35-
const { content, location } = scan(imageData)
34+
if (shouldContinue()) {
35+
const imageData = camera.captureFrame()
36+
const { content, location } = scan(imageData)
3637

37-
if (content !== null && content !== contentBefore) {
38-
decodeHandler(content)
39-
}
38+
if (content !== null && content !== contentBefore) {
39+
decodeHandler(content)
40+
}
4041

41-
if (location !== locationBefore) {
42-
locateHandler(location)
43-
}
42+
if (location !== locationBefore) {
43+
locateHandler(location)
44+
}
4445

45-
if (shouldContinue()) {
4646
window.setTimeout(() => {
4747
window.requestAnimationFrame(
4848
recur(content || contentBefore, location)

0 commit comments

Comments
 (0)