Skip to content

Commit c8600da

Browse files
committed
Merge branch 'master' into alpha
2 parents 754a042 + ea50a14 commit c8600da

File tree

9 files changed

+230
-58
lines changed

9 files changed

+230
-58
lines changed

docs/api/QrcodeStream.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ This component fundamentally depends on the [Stream API](https://caniuse.com/#fe
99
| No | Yes | Yes | Yes¹ | Yes² |
1010

1111
1. Chrome requires [HTTPS or localhost](https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins) (see _Troubleshooting_ for help)
12-
2. Safari also requires HTTPS **even** on localhost (see [#48](../../issues/48)). It also won't work in:
13-
- _Chrome for iOS_, _Firefox for iOS_, ... (see [#29](../../issues/29))
12+
2. Safari also requires HTTPS **even** on localhost (see [#48](https://github.com/gruhn/vue-qrcode-reader/issues/48)). It also won't work in:
13+
- _Chrome for iOS_, _Firefox for iOS_, ... (see [#29](https://github.com/gruhn/vue-qrcode-reader/issues/29))
1414
- WkWebView component of native iOS apps
15-
- web apps added to home screen (PWA mode) **prior to iOS 13.4** (see [#76](../../issues/76))
15+
- web apps added to home screen (PWA mode) **prior to iOS 13.4** (see [#76](https://github.com/gruhn/vue-qrcode-reader/issues/76))
1616

1717

1818
## Events

package-lock.json

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint": "^6.7.2",
4444
"eslint-plugin-prettier": "^3.1.3",
4545
"eslint-plugin-vue": "^6.2.2",
46+
"husky": "^4.2.5",
4647
"lint-staged": "^9.5.0",
4748
"prettier": "^1.19.1",
4849
"semantic-release": "^17.1.1",

src/components/QrcodeStream.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
<template lang="html">
2-
<div class="wrapper">
2+
<div class="qrcode-stream-wrapper">
33
<!--
4-
Note that the order of DOM elements matters.
5-
It defines the stacking order.
6-
The first element is at the very bottom, the last element is on top.
7-
This eliminates the need for `z-index`.
4+
Note, the following DOM elements are not styled with z-index.
5+
If z-index is not defined, elements are stacked in the order they appear in the DOM.
6+
The first element is at the very bottom and subsequent elements are added on top.
87
-->
98
<video
109
ref="video"
1110
v-show="shouldScan"
12-
class="camera"
11+
class="qrcode-stream-camera"
1312
autoplay
1413
muted
1514
playsinline
1615
></video>
1716

18-
<canvas ref="pauseFrame" v-show="!shouldScan" class="pause-frame"></canvas>
17+
<canvas ref="pauseFrame" v-show="!shouldScan" class="qrcode-stream-camera"></canvas>
1918

20-
<canvas ref="trackingLayer" class="tracking-layer"></canvas>
19+
<canvas ref="trackingLayer" class="qrcode-stream-overlay"></canvas>
2120

22-
<div class="overlay">
21+
<div class="qrcode-stream-overlay">
2322
<slot></slot>
2423
</div>
2524
</div>
@@ -30,7 +29,7 @@ import { keepScanning } from "../misc/scanner.js";
3029
import { thinSquare } from "../misc/track-func.js";
3130
import Camera from "../misc/camera.js";
3231
import CommonAPI from "../mixins/CommonAPI.vue";
33-
import Worker from "../worker/jsqr.js";
32+
import spawnWorker from "../worker/jsqr.js";
3433
3534
export default {
3635
name: "qrcode-stream",
@@ -59,7 +58,7 @@ export default {
5958
6059
worker: {
6160
type: Function,
62-
default: Worker
61+
default: spawnWorker
6362
}
6463
},
6564
@@ -285,27 +284,28 @@ export default {
285284
</script>
286285

287286
<style lang="css" scoped>
288-
.wrapper {
289-
position: relative;
290-
z-index: 0;
287+
.qrcode-stream-wrapper {
291288
width: 100%;
292289
height: 100%;
290+
291+
position: relative;
292+
z-index: 0;
293293
}
294294
295-
.overlay,
296-
.tracking-layer {
297-
position: absolute;
295+
.qrcode-stream-overlay {
298296
width: 100%;
299297
height: 100%;
298+
299+
position: absolute;
300300
top: 0;
301301
left: 0;
302302
}
303303
304-
.camera,
305-
.pause-frame {
306-
display: block;
307-
object-fit: cover;
304+
.qrcode-stream-camera {
308305
width: 100%;
309306
height: 100%;
307+
308+
display: block;
309+
object-fit: cover;
310310
}
311311
</style>

src/misc/camera.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { StreamApiNotSupportedError, InsecureContextError } from "./errors.js";
22
import { imageDataFromVideo } from "./image-data.js";
33
import { eventOn, timeout } from "callforth";
4-
import shimGetUserMedia from "./shimGetUserMedia"
4+
import shimGetUserMedia from "./shimGetUserMedia";
55

66
class Camera {
77
constructor(videoEl, stream) {
@@ -81,14 +81,14 @@ export default async function(videoEl, { camera, torch }) {
8181

8282
// This is a browser API only shim. It patches the global window object which
8383
// is not available during SSR. So we lazily apply this shim at runtime.
84-
await shimGetUserMedia()
84+
await shimGetUserMedia();
8585

8686
const constraints = {
8787
audio: false,
8888
video: {
8989
width: { min: 360, ideal: 640, max: 1920 },
9090
height: { min: 240, ideal: 480, max: 1080 },
91-
...(await narrowDownFacingMode(camera)),
91+
...(await narrowDownFacingMode(camera))
9292
}
9393
};
9494

src/misc/scanner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { eventOn } from "callforth";
22

3-
export async function scan(Worker, imageData) {
4-
const worker = new Worker();
3+
export const scan = async (spawnWorker, imageData) => {
4+
const worker = spawnWorker();
55

66
worker.postMessage(imageData, [imageData.data.buffer]);
77

@@ -16,14 +16,14 @@ export async function scan(Worker, imageData) {
1616
* Continuously extracts frames from camera stream and tries to read
1717
* potentially pictured QR codes.
1818
*/
19-
export function keepScanning(Worker, camera, options) {
19+
export const keepScanning = (spawnWorker, camera, options) => {
2020
const { detectHandler, locateHandler, minDelay } = options;
2121

2222
let contentBefore = null;
2323
let locationBefore = null;
2424
let lastScanned = performance.now();
2525

26-
const worker = new Worker();
26+
const worker = spawnWorker();
2727

2828
// If worker can't process frames fast enough, memory will quickly full up.
2929
// Make sure to process only one frame at a time.

0 commit comments

Comments
 (0)