UNPKG

4.64 kBPlain TextView Raw
1import "objectFitPolyfill";
2import "webrtc-adapter/out/adapter_no_edge_no_global";
3
4import { BrowserCompatibility } from "./lib/browserCompatibility";
5import { BrowserHelper } from "./lib/browserHelper";
6import { CustomError } from "./lib/customError";
7import { UnsupportedBrowserError } from "./lib/unsupportedBrowserError";
8
9import "./styles/styles.scss";
10
11/**
12 * @hidden
13 */
14declare 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
34export * from "./lib/barcode";
35export * from "./lib/barcodeEncodingRange";
36export * from "./lib/barcodePicker";
37export * from "./lib/browserCompatibility";
38export * from "./lib/browserHelper";
39export * from "./lib/camera";
40export * from "./lib/cameraAccess";
41export * from "./lib/cameraSettings";
42export * from "./lib/customError";
43export * from "./lib/imageSettings";
44export * from "./lib/point";
45export * from "./lib/quadrilateral";
46export * from "./lib/parser";
47export * from "./lib/parserField";
48export * from "./lib/parserResult";
49export * from "./lib/scanResult";
50export * from "./lib/scanner";
51export * from "./lib/scanSettings";
52export * from "./lib/searchArea";
53export * from "./lib/symbologySettings";
54
55export * from "./lib/workers/engineWorker";
56
57/**
58 * @hidden
59 */
60export let deviceId: string = BrowserHelper.getDeviceId();
61/**
62 * @hidden
63 */
64export let userLicenseKey: string | undefined;
65/**
66 * @hidden
67 */
68export 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 =&nbsp;"/"</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 */
93export 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?:\/\//.test(engineLocation)) {
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