Skip to content

Commit 4b09a32

Browse files
committed
Polyfill BarcodeDetector API for improved performance of Html5QRcodeScanner
1 parent 9e85b70 commit 4b09a32

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

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: 1 addition & 0 deletions
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",

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,16 @@
19321932
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"
19331933
integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==
19341934

1935+
1936+
version "0.1.11"
1937+
resolved "https://registry.yarnpkg.com/@types/dom-webcodecs/-/dom-webcodecs-0.1.11.tgz#2e36e5cc71789551f107e2fe15d956845fa19567"
1938+
integrity sha512-yPEZ3z7EohrmOxbk/QTAa0yonMFkNkjnVXqbGb7D4rMr+F1dGQ8ZUFxXkyLLJuiICPejZ0AZE9Rrk9wUCczx4A==
1939+
1940+
"@types/emscripten@^1.39.13":
1941+
version "1.39.13"
1942+
resolved "https://registry.yarnpkg.com/@types/emscripten/-/emscripten-1.39.13.tgz#afeb1648648dc096efe57983e20387627306e2aa"
1943+
integrity sha512-cFq+fO/isvhvmuP/+Sl4K4jtU6E23DoivtbO4r50e3odaxAiVdbfSYRDdJ4gCdxx+3aRjhphS5ZMwIH4hFy/Cw==
1944+
19351945
"@types/eslint-scope@^3.7.7":
19361946
version "3.7.7"
19371947
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5"
@@ -2401,6 +2411,14 @@ balanced-match@^1.0.0:
24012411
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
24022412
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
24032413

2414+
barcode-detector@^2.3.1:
2415+
version "2.3.1"
2416+
resolved "https://registry.yarnpkg.com/barcode-detector/-/barcode-detector-2.3.1.tgz#91d0d4e3b913d87f94bae5d024b6b9b5cedc420c"
2417+
integrity sha512-D9KEtrquS1tmBZduxBZl8qublIKnRrFqD8TAHDYcLCyrHQBo+vitIxmjMJ61LvXjXyAMalOlO7q0Oh/9Rl2PbQ==
2418+
dependencies:
2419+
"@types/dom-webcodecs" "0.1.11"
2420+
zxing-wasm "1.3.4"
2421+
24042422
24052423
version "1.3.1"
24062424
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
@@ -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)