-
Notifications
You must be signed in to change notification settings - Fork 1
/
WasmLoadSettings.ts
97 lines (84 loc) · 3.28 KB
/
WasmLoadSettings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
import { SDKError } from "./SDKError";
import { defaultWasmModuleName } from "../defaultWasmModule";
import { WasmType } from "./WasmType";
import * as ErrorTypes from "./ErrorTypes";
/**
* Function that will be called during loading of the SDK.
* @param loadPercentage Number between 0 and 100 indicating the loading progress.
*/
export type LoadProgressCallback = ( loadPercentage: number ) => void;
export type OptionalLoadProgressCallback = LoadProgressCallback | null;
export { WasmType };
/**
* Settings object for function loadWasmModule.
*/
export class WasmSDKLoadSettings
{
/**
* License key for unlocking the WebAssembly module. Bound to the domain name from which the application is served.
*/
licenseKey: string;
/**
* Write a hello message to the browser console when license check is successfully performed.
*
* Hello message will contain the name and version of the SDK, which are required information for all support
* tickets.
*
* The default value is true.
*/
allowHelloMessage = true;
/**
* Absolute location of WASM and related JS/data files. Useful when resource files should be loaded over CDN, or
* when web frameworks/libraries are used which store resources in specific locations, e.g. inside "assets" folder.
*
* Important: if the engine is hosted on another origin, CORS must be enabled between two hosts. That is, server
* where engine is hosted must have 'Access-Control-Allow-Origin' header for the location of the web app.
*
* Important: SDK and WASM resources must be from the same version of a package.
*
* Default value is empty string, i.e. "". In case of empty string, value of "window.location.origin" property is
* going to be used.
*/
engineLocation = "";
/**
* Type of the WASM that will be loaded. By default, if not set, the SDK will automatically determine the best WASM
* to load.
*/
wasmType: WasmType | null = null;
/**
* Defines the number of workers that will be used for multi-threaded processing of the images. If not set, the
* number of worker used will match the number of detected CPU cores on a device.
*
* If the browser does not support multi-threaded processing or it was deliberately disabled using the `wasmType`
* property, then this property will be ignored.
*/
numberOfWorkers: number | null = null;
/**
* Optional callback function that will report the SDK loading progress.
*
* This can be useful for displaying progress bar to users with slow connections.
*
* The default value is null.
*/
loadProgressCallback: OptionalLoadProgressCallback = null;
/**
* Name of the file containing the WebAssembly module.
*
* Change this only if you have renamed the original WASM and its support JS file for your purposes.
*/
wasmModuleName: string = defaultWasmModuleName;
/**
* @param licenseKey License key for unlocking the WebAssembly module.
*/
constructor( licenseKey: string )
{
if ( !licenseKey )
{
throw new SDKError( ErrorTypes.sdkErrors.licenseKeyMissing );
}
this.licenseKey = licenseKey;
}
}