解决问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BarcodeDetector as BarcodeDetectorPonyfill, prepareZXingModule } from "barcode-detector/dist/cjs/index.js";
|
||||
import { BarcodeDetector as BarcodeDetectorPonyfill, prepareZXingModule } from "barcode-detector/dist/cjs/ponyfill.js";
|
||||
import { createUUID } from "../../utils/uuid";
|
||||
import { getConfig } from "../config";
|
||||
import scanBeepAudio from "../../../res/scan_beep.ogg";
|
||||
@@ -11,7 +11,10 @@ const scanWeb = {
|
||||
}
|
||||
|
||||
const DEFAULT_SCAN_BEEP_AUDIO = scanBeepAudio;
|
||||
const ZXING_READER_WASM_URL = "./lib/reader.wasm";
|
||||
const ZXING_READER_WASM_PATH = "lib/reader.wasm";
|
||||
const currentScriptSrc = typeof document !== "undefined"
|
||||
&& document.currentScript
|
||||
&& document.currentScript.src;
|
||||
|
||||
let barcodeDetectorPreparePromise = null;
|
||||
let scanBeepAudioEl = null;
|
||||
@@ -128,23 +131,30 @@ function getBarcodeDetectorClass() {
|
||||
return BarcodeDetectorPonyfill;
|
||||
}
|
||||
|
||||
function getZXingReaderWasmUrl() {
|
||||
if (currentScriptSrc) {
|
||||
return new URL(ZXING_READER_WASM_PATH, currentScriptSrc).href;
|
||||
}
|
||||
return "./" + ZXING_READER_WASM_PATH;
|
||||
}
|
||||
|
||||
function prepareBarcodeDetector() {
|
||||
const BarcodeDetectorClass = getBarcodeDetectorClass();
|
||||
if (typeof BarcodeDetector !== 'undefined' || !prepareZXingModule) {
|
||||
return Promise.resolve(BarcodeDetectorClass);
|
||||
}
|
||||
if (!barcodeDetectorPreparePromise) {
|
||||
prepareZXingModule({
|
||||
barcodeDetectorPreparePromise = prepareZXingModule({
|
||||
fireImmediately: true,
|
||||
overrides: {
|
||||
locateFile: path => {
|
||||
if (path && path.indexOf(".wasm") !== -1) {
|
||||
return ZXING_READER_WASM_URL;
|
||||
return getZXingReaderWasmUrl();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
});
|
||||
barcodeDetectorPreparePromise = Promise.resolve(BarcodeDetectorClass);
|
||||
}).then(() => BarcodeDetectorClass);
|
||||
}
|
||||
return barcodeDetectorPreparePromise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user