1 | import "objectFitPolyfill";
|
2 | import "webrtc-adapter/out/adapter_no_edge_no_global";
|
3 |
|
4 | import { BrowserCompatibility } from "./lib/browserCompatibility";
|
5 | import { BrowserHelper } from "./lib/browserHelper";
|
6 | import { CustomError } from "./lib/customError";
|
7 | import { UnsupportedBrowserError } from "./lib/unsupportedBrowserError";
|
8 |
|
9 | import "./styles/styles.scss";
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | declare global {
|
15 | interface Window {
|
16 | MediaStreamTrack?: {
|
17 | getSources?(callback: (devices: MediaDeviceInfo[]) => void): void;
|
18 | };
|
19 | Worker: Function;
|
20 | WebAssembly: object;
|
21 | OffscreenCanvas: Function;
|
22 | WebGLRenderingContext: Function;
|
23 | objectFitPolyfill(elements?: HTMLElement | HTMLElement[]): void;
|
24 | }
|
25 |
|
26 | interface Navigator {
|
27 | mozVibrate?: Navigator["vibrate"];
|
28 | msVibrate?: Navigator["vibrate"];
|
29 | webkitVibrate?: Navigator["vibrate"];
|
30 | enumerateDevices?(): Promise<MediaDeviceInfo[]>;
|
31 | }
|
32 | }
|
33 |
|
34 | export * from "./lib/barcode";
|
35 | export * from "./lib/barcodeEncodingRange";
|
36 | export * from "./lib/barcodePicker";
|
37 | export * from "./lib/browserCompatibility";
|
38 | export * from "./lib/browserHelper";
|
39 | export * from "./lib/camera";
|
40 | export * from "./lib/cameraAccess";
|
41 | export * from "./lib/cameraSettings";
|
42 | export * from "./lib/customError";
|
43 | export * from "./lib/imageSettings";
|
44 | export * from "./lib/point";
|
45 | export * from "./lib/quadrilateral";
|
46 | export * from "./lib/parser";
|
47 | export * from "./lib/parserField";
|
48 | export * from "./lib/parserResult";
|
49 | export * from "./lib/scanResult";
|
50 | export * from "./lib/scanner";
|
51 | export * from "./lib/scanSettings";
|
52 | export * from "./lib/searchArea";
|
53 | export * from "./lib/symbologySettings";
|
54 |
|
55 | export * from "./lib/workers/engineWorker";
|
56 |
|
57 | /**
|
58 | * @hidden
|
59 | */
|
60 | export let deviceId: string = BrowserHelper.getDeviceId();
|
61 | /**
|
62 | * @hidden
|
63 | */
|
64 | export let userLicenseKey: string | undefined;
|
65 | /**
|
66 | * @hidden
|
67 | */
|
68 | export let scanditEngineLocation: string;
|
69 |
|
70 | /**
|
71 | * Initialize and configure the Scandit Barcode Scanner SDK library. This function must be called as first thing
|
72 | * before using any other function of the library.
|
73 | *
|
74 | * Depending on parameters and device features, any of the following errors could be the rejected result of the returned
|
75 | * promise:
|
76 | * - `NoLicenseKeyError`
|
77 | * - `UnsupportedBrowserError`
|
78 | *
|
79 | * Camera access requests and external Scandit Engine library loads are done lazily only when needed by a
|
80 | * [[BarcodePicker]] (or [[Scanner]]) object. To make the loading process faster when scanning is actually needed, it is
|
81 | * recommended depending on the use case to create in advance a (hidden and paused) [[BarcodePicker]] or [[Scanner]]
|
82 | * object, to later simply show and unpause it when needed. You can also eagerly ask only for camera access permissions
|
83 | * by calling the [[CameraAccess.getCameras]] function.
|
84 | *
|
85 | * @param licenseKey The Scandit license key to be used by the library.
|
86 | * @param engineLocation <div class="tsd-signature-symbol">Default = "/"</div>
|
87 | * The location of the folder containing the external scandit-engine-sdk.min.js and
|
88 | * scandit-engine-sdk.wasm files (external Scandit Engine library).
|
89 | * By default they are retrieved from the root of the web application.
|
90 | * Can be a full URL to folder or an absolute folder path.
|
91 | * @returns A promise resolving when the library has been configured.
|
92 | */
|
93 | export function configure(
|
94 | licenseKey: string,
|
95 | {
|
96 | engineLocation = "/"
|
97 | }: {
|
98 | engineLocation?: string;
|
99 | } = {}
|
100 | ): Promise<void> {
|
101 | const browserCompatibility: BrowserCompatibility = BrowserHelper.checkBrowserCompatibility();
|
102 | if (!browserCompatibility.fullSupport && !browserCompatibility.scannerSupport) {
|
103 | return Promise.reject(new UnsupportedBrowserError(browserCompatibility));
|
104 | }
|
105 |
|
106 | if (licenseKey == null || licenseKey.trim().length < 64) {
|
107 | return Promise.reject(new CustomError({ name: "NoLicenseKeyError", message: "No license key provided" }));
|
108 | }
|
109 | userLicenseKey = licenseKey;
|
110 |
|
111 | engineLocation += engineLocation.slice(-1) === "/" ? "" : "/";
|
112 | if (/^https?:\/\
|
113 | scanditEngineLocation = `${engineLocation}`;
|
114 | } else {
|
115 | engineLocation = engineLocation
|
116 | .split("/")
|
117 | .filter(s => {
|
118 | return s.length > 0;
|
119 | })
|
120 | .join("/");
|
121 | if (engineLocation === "") {
|
122 | engineLocation = "/";
|
123 | } else {
|
124 | engineLocation = `/${engineLocation}/`;
|
125 | }
|
126 | if (location.protocol === "file:" || location.origin === "null") {
|
127 | scanditEngineLocation = `${location.href
|
128 | .split("/")
|
129 | .slice(0, -1)
|
130 | .join("/")}${engineLocation}`;
|
131 | } else {
|
132 | scanditEngineLocation = `${location.origin}${engineLocation}`;
|
133 | }
|
134 | }
|
135 |
|
136 | return Promise.resolve();
|
137 | }
|
138 |
|
\ | No newline at end of file |