Skip to content

Commit ddc1c28

Browse files
committed
Merge branch 'detector-api-polyfill'
2 parents 9e85b70 + 22fba37 commit ddc1c28

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

assets/controllers/pages/barcode_scan_controller.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import {Controller} from "@hotwired/stimulus";
2121
//import * as ZXing from "@zxing/library";
2222

23-
import {Html5QrcodeScanner, Html5Qrcode} from "html5-qrcode";
23+
import {Html5QrcodeScanner, Html5Qrcode} from "@part-db/html5-qrcode";
2424

2525
/* stimulusFetch: 'lazy' */
2626
export default class extends Controller {
@@ -50,7 +50,7 @@ export default class extends Controller {
5050
});
5151

5252
this._scanner = new Html5QrcodeScanner(this.element.id, {
53-
fps: 2,
53+
fps: 10,
5454
qrbox: qrboxFunction,
5555
experimentalFeatures: {
5656
//This option improves reading quality on android chrome
@@ -61,6 +61,11 @@ export default class extends Controller {
6161
this._scanner.render(this.onScanSuccess.bind(this));
6262
}
6363

64+
disconnect() {
65+
this._scanner.pause();
66+
this._scanner.clear();
67+
}
68+
6469
onScanSuccess(decodedText, decodedResult) {
6570
//Put our decoded Text into the input box
6671
document.getElementById('scan_dialog_input').value = decodedText;

assets/js/app.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,21 @@ import "./register_events";
4444
import "./tristate_checkboxes";
4545

4646
//Define jquery globally
47-
window.$ = window.jQuery = require("jquery")
47+
window.$ = window.jQuery = require("jquery");
48+
49+
//Use the local WASM file for the ZXing library
50+
import {
51+
setZXingModuleOverrides,
52+
} from "barcode-detector/pure";
53+
import wasmFile from "../../node_modules/zxing-wasm/dist/reader/zxing_reader.wasm";
54+
55+
setZXingModuleOverrides({
56+
locateFile: (path, prefix) => {
57+
if (path.endsWith(".wasm")) {
58+
return wasmFile;
59+
}
60+
return prefix + path;
61+
},
62+
});
63+
//Enable polyfill for the barcode detector. The WASM triggering is done when the barcode detector is used
64+
import "barcode-detector/side-effects";

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@zxcvbn-ts/language-en": "^3.0.1",
7373
"@zxcvbn-ts/language-fr": "^3.0.1",
7474
"@zxcvbn-ts/language-ja": "^3.0.1",
75+
"barcode-detector": "^2.3.1",
7576
"bootbox": "^6.0.0",
7677
"bootswatch": "^5.1.3",
7778
"bs-custom-file-input": "^1.3.4",
@@ -87,7 +88,7 @@
8788
"dompurify": "^3.0.3",
8889
"emoji.json": "^15.0.0",
8990
"exports-loader": "^5.0.0",
90-
"html5-qrcode": "^2.2.1",
91+
"@part-db/html5-qrcode": "^3.0.0",
9192
"json-formatter-js": "^2.3.4",
9293
"jszip": "^3.2.0",
9394
"katex": "^0.16.0",

webpack.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Encore
5959
.addEntry('app', './assets/js/app.js')
6060
.addEntry('webauthn_tfa', './assets/js/webauthn_tfa.js')
6161

62+
//Configure to just output the zxing wasm file, without parsing it
63+
.addRule({
64+
test: /zxing_reader\.wasm$/,
65+
type: "asset/resource"
66+
})
67+
6268
//.addEntry('page1', './assets/js/page1.js')
6369
//.addEntry('page2', './assets/js/page2.js')
6470

@@ -189,6 +195,10 @@ if (Encore.isDev()) {
189195

190196
module.exports = Encore.getWebpackConfig();
191197

198+
//Enable webassembly support
199+
module.exports.experiments = module.exports.experiments || {};
200+
module.exports.experiments.asyncWebAssembly = true;
201+
192202
//Enable webpack auto public path (this only works in combination with WebpackAutoPathSubscriber!!)
193203
//We do it here to supress a warning caused by webpack Encore
194204
module.exports.output.publicPath = 'auto';

yarn.lock

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,11 @@
18741874
resolved "https://registry.yarnpkg.com/@orchidjs/unicode-variants/-/unicode-variants-1.1.2.tgz#1fd71791a67fdd1591ebe0dcaadd3964537a824e"
18751875
integrity sha512-5DobW1CHgnBROOEpFlEXytED5OosEWESFvg/VYmH0143oXcijYTprRYJTs+55HzGM4IqxiLFSuqEzu9mPNwVsA==
18761876

1877+
"@part-db/html5-qrcode@^3.0.0":
1878+
version "3.0.1"
1879+
resolved "https://registry.yarnpkg.com/@part-db/html5-qrcode/-/html5-qrcode-3.0.1.tgz#3eafb7b4cb24eab8a4b815800756814f1d10c8bb"
1880+
integrity sha512-NAbXfrW7pEyK3+ZkL14+pHHq3vjBPn7WWvd82OG0BHbiZ5P3XHJnx33WBUaoUAt2pRRAFYVwQNw8OyNUSE8aeg==
1881+
18771882
"@polka/url@^1.0.0-next.24":
18781883
version "1.0.0-next.28"
18791884
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.28.tgz#d45e01c4a56f143ee69c54dd6b12eade9e270a73"
@@ -1932,6 +1937,16 @@
19321937
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"
19331938
integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==
19341939

1940+
1941+
version "0.1.11"
1942+
resolved "https://registry.yarnpkg.com/@types/dom-webcodecs/-/dom-webcodecs-0.1.11.tgz#2e36e5cc71789551f107e2fe15d956845fa19567"
1943+
integrity sha512-yPEZ3z7EohrmOxbk/QTAa0yonMFkNkjnVXqbGb7D4rMr+F1dGQ8ZUFxXkyLLJuiICPejZ0AZE9Rrk9wUCczx4A==
1944+
1945+
"@types/emscripten@^1.39.13":
1946+
version "1.39.13"
1947+
resolved "https://registry.yarnpkg.com/@types/emscripten/-/emscripten-1.39.13.tgz#afeb1648648dc096efe57983e20387627306e2aa"
1948+
integrity sha512-cFq+fO/isvhvmuP/+Sl4K4jtU6E23DoivtbO4r50e3odaxAiVdbfSYRDdJ4gCdxx+3aRjhphS5ZMwIH4hFy/Cw==
1949+
19351950
"@types/eslint-scope@^3.7.7":
19361951
version "3.7.7"
19371952
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5"
@@ -2401,6 +2416,14 @@ balanced-match@^1.0.0:
24012416
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
24022417
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
24032418

2419+
barcode-detector@^2.3.1:
2420+
version "2.3.1"
2421+
resolved "https://registry.yarnpkg.com/barcode-detector/-/barcode-detector-2.3.1.tgz#91d0d4e3b913d87f94bae5d024b6b9b5cedc420c"
2422+
integrity sha512-D9KEtrquS1tmBZduxBZl8qublIKnRrFqD8TAHDYcLCyrHQBo+vitIxmjMJ61LvXjXyAMalOlO7q0Oh/9Rl2PbQ==
2423+
dependencies:
2424+
"@types/dom-webcodecs" "0.1.11"
2425+
zxing-wasm "1.3.4"
2426+
24042427
24052428
version "1.3.1"
24062429
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
@@ -4019,11 +4042,6 @@ html-escaper@^2.0.2:
40194042
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453"
40204043
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==
40214044

4022-
html5-qrcode@^2.2.1:
4023-
version "2.3.8"
4024-
resolved "https://registry.yarnpkg.com/html5-qrcode/-/html5-qrcode-2.3.8.tgz#0b0cdf7a9926cfd4be530e13a51db47592adfa0d"
4025-
integrity sha512-jsr4vafJhwoLVEDW3n1KvPnCCXWaQfRng0/EEYk1vNcQGcG/htAdhJX0be8YyqMoSz7+hZvOZSTAepsabiuhiQ==
4026-
40274045
htmlparser2@^6.1.0:
40284046
version "6.1.0"
40294047
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-6.1.0.tgz#c4d762b6c3371a05dbe65e94ae43a9f845fb8fb7"
@@ -6959,3 +6977,10 @@ yocto-queue@^1.0.0:
69596977
version "1.1.1"
69606978
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.1.1.tgz#fef65ce3ac9f8a32ceac5a634f74e17e5b232110"
69616979
integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==
6980+
6981+
6982+
version "1.3.4"
6983+
resolved "https://registry.yarnpkg.com/zxing-wasm/-/zxing-wasm-1.3.4.tgz#4bc45b78dc3594278bb0c24233bfb035ca9efab1"
6984+
integrity sha512-9l0QymyATF19FmI92QHe7Dayb+BUN7P7zFAt5iDgTnUf0dFWokz6GVA/W9EepjW5q8s3e89fIE/7uxpX27yqEQ==
6985+
dependencies:
6986+
"@types/emscripten" "^1.39.13"

0 commit comments

Comments
 (0)