|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: API Reference Index - CoreModule Class in JavaScript |
| 4 | +description: This page introduces the API for the CoreModule Class. |
| 5 | +keywords: Core, CoreModule, api reference, javascript, js |
| 6 | +needAutoGenerateSidebar: true |
| 7 | +needGenerateH3Content: true |
| 8 | +noTitleIndex: true |
| 9 | +--- |
| 10 | +<!--v3.0.20--Updated on 11/23/2023--> |
| 11 | + |
| 12 | +# CoreModule Class |
| 13 | + |
| 14 | +The CoreModule class defines common functionality in the Core module. |
| 15 | + |
| 16 | +| Name | Description | |
| 17 | +| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------- | |
| 18 | +| `static` [detectEnvironment()](#detectenvironment) | Detects and returns information about the current runtime environment. | |
| 19 | +| `static` [engineResourcePaths](#engineresourcepaths) | Configures the paths where the .wasm files and other necessary resources for modules are located. | |
| 20 | +| `static` [getVersion()](#getversion) | Returns the version of the Core module. | |
| 21 | +| `static` [isModuleLoaded()](#ismoduleloaded) | Returns whether the WebAssembly (.wasm) file for the specified module is successfully loaded. | |
| 22 | +| `static` [loadWasm()](#loadwasm) | Initiates the loading process for the .wasm file(s) corresponding to the specified module(s). | |
| 23 | + |
| 24 | +<!-- |
| 25 | +| `static` [onLog](#onlog) | Event triggered whenever a log message is ready to be dispatched. | |
| 26 | +| `static` [disableLogging()](#disablelogging) | Disables logging. | |
| 27 | +| `static` [enableLogging()](#enablelogging) | Enables logging to print internal logs to the browser console for debugging. | --> |
| 28 | + |
| 29 | +## detectEnvironment |
| 30 | + |
| 31 | +Detects and returns information about the current runtime environment. |
| 32 | + |
| 33 | +```typescript |
| 34 | +detectEnvironment(): Promise<any> |
| 35 | +``` |
| 36 | + |
| 37 | +**Return Value** |
| 38 | + |
| 39 | +A promise that resolves with the detected environment information (e.g., browser type and version, operating system, camera support, etc.). |
| 40 | + |
| 41 | +**Code snippet** |
| 42 | + |
| 43 | +```javascript |
| 44 | +await Dynamsoft.Core.CoreModule.detectEnvironment(); |
| 45 | +// Example return value: |
| 46 | +// {"wasm":true,"worker":true,"getUserMedia":true,"camera":true,"browser":"Edge","version":119,"OS":"Windows"} |
| 47 | +``` |
| 48 | + |
| 49 | +## engineResourcePaths |
| 50 | + |
| 51 | +Configures the paths where the .wasm files and other necessary resources for modules are located. It allows you to either return or set the paths that the system uses to find these resources. |
| 52 | + |
| 53 | +For resources loaded from popular CDNs like jsDelivr or UNPKG, the paths are automatically identified based on the JavaScript files referenced for these modules. Manual specification of these paths is necessary only in the following scenarios: |
| 54 | + |
| 55 | +1. When integrating the SDK within web frameworks such as Angular, React, or Vue. |
| 56 | +2. If you opt for a CDN different from the default choices. |
| 57 | +3. When you are serving the files on your own. |
| 58 | + |
| 59 | +<!-- |
| 60 | +> Specifying only the "rootDirectory" configures all paths to align with this directory automatically. However, if you provide both "rootDirectory" and specific paths for individual modules, the specific module paths will override the root directory setting. |
| 61 | + /** NOT WORKING AS EXPECTED YET |
| 62 | + * Specifies the root directory in which all the modules are located |
| 63 | + */ |
| 64 | + "rootDirectory"?: string; |
| 65 | + /** WILL BE RENAMED TO dlrData LATER |
| 66 | + * Specifies the resource path for the dynamsoft-capture-vision-dnn module. |
| 67 | + */ |
| 68 | + "dcm"?: string; |
| 69 | + /** NOT AVAILABLE NOW |
| 70 | + * Specifies the resource path for the dynamsoft-capture-vision-dnn module. |
| 71 | + */ |
| 72 | + "dnn"?: string; |
| 73 | +--> |
| 74 | +```typescript |
| 75 | +static engineResourcePaths: { |
| 76 | + /** |
| 77 | + * Specifies the resource path for the dynamsoft-capture-vision-std module. |
| 78 | + */ |
| 79 | + "std"?: string; |
| 80 | + /** |
| 81 | + * Specifies the resource path for the dynamsoft-image-processing module. |
| 82 | + */ |
| 83 | + "dip"?: string; |
| 84 | + /** |
| 85 | + * Specifies the resource path for the dynamsoft-core module. |
| 86 | + */ |
| 87 | + "core"?: string; |
| 88 | + /** |
| 89 | + * Specifies the resource path for the dynamsoft-license module. |
| 90 | + */ |
| 91 | + "license"?: string; |
| 92 | + /** |
| 93 | + * Specifies the resource path for the dynamsoft-capture-vision-router module. |
| 94 | + */ |
| 95 | + "cvr"?: string; |
| 96 | + /** |
| 97 | + * Specifies the resource path for the dynamsoft-utility module. |
| 98 | + */ |
| 99 | + "utility"?: string; |
| 100 | + /** |
| 101 | + * Specifies the resource path for the dynamsoft-barcode-reader module. |
| 102 | + */ |
| 103 | + "dbr"?: string; |
| 104 | + /** |
| 105 | + * Specifies the resource path for the dynamsoft-label-recognizer module. |
| 106 | + */ |
| 107 | + "dlr"?: string; |
| 108 | + /** |
| 109 | + * Specifies the resource path for the dynamsoft-document-normalizer module. |
| 110 | + */ |
| 111 | + "ddn"?: string; |
| 112 | + /** |
| 113 | + * Specifies the resource path for the dynamsoft-code-parser module. |
| 114 | + */ |
| 115 | + "dcp"?: string; |
| 116 | + /** |
| 117 | + * Specifies the resource path for the dynamsoft-camera-enhancer module. |
| 118 | + */ |
| 119 | + "dce"?: string; |
| 120 | +}; |
| 121 | +``` |
| 122 | + |
| 123 | +**Code snippet** |
| 124 | + |
| 125 | +```javascript |
| 126 | +// To specify the paths for multiple modules: |
| 127 | +Dynamsoft.Core.CoreModule.engineResourcePaths = { |
| 128 | + "std": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 129 | + "dip": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 130 | + "core": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 131 | + "license": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 132 | + "cvr": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 133 | + "utility": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 134 | + "dbr": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/" |
| 135 | + "dlr": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/", |
| 136 | + "ddn": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/" |
| 137 | + "dcp": "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/" |
| 138 | +}; |
| 139 | +// To specify the path for only one module: |
| 140 | +Dynamsoft. Core. CoreModule. engineResourcePaths. dbr = "https://[SPECIFY-THE-ROOT-DIRECTORY]/[email protected]/dist/"; |
| 141 | +``` |
| 142 | + |
| 143 | +## getVersion |
| 144 | + |
| 145 | +Returns the version of the Core module. |
| 146 | + |
| 147 | +```typescript |
| 148 | +static getVersion(): string; |
| 149 | +``` |
| 150 | + |
| 151 | +**Return Value** |
| 152 | + |
| 153 | +A string type representing the version. |
| 154 | + |
| 155 | +**Code snippet** |
| 156 | + |
| 157 | +```javascript |
| 158 | +const version = Dynamsoft.Core.CoreModule.getVersion(); |
| 159 | +console.log(version); |
| 160 | +``` |
| 161 | + |
| 162 | +## isModuleLoaded |
| 163 | + |
| 164 | +Returns whether the WebAssembly (.wasm) file for the specified module is successfully loaded. |
| 165 | + |
| 166 | +```typescript |
| 167 | +static isModuleLoaded(moduleName: string): boolean; |
| 168 | +``` |
| 169 | + |
| 170 | +**Parameters** |
| 171 | + |
| 172 | +`moduleName`: specifies a module. |
| 173 | + |
| 174 | +**Return Value** |
| 175 | + |
| 176 | +Boolean indicating whether the .wasm file for the specified module is loaded. |
| 177 | + |
| 178 | +**Code snippet** |
| 179 | + |
| 180 | +```javascript |
| 181 | +if(Dynamsoft.Core.CoreModule.isModuleLoaded("cvr")){ |
| 182 | + console.log("cvr module is loaded!"). |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +## loadWasm |
| 187 | + |
| 188 | +Initiates the loading process for the .wasm file(s) corresponding to the specified module(s). If a module relies on other modules, the other modules will be loaded as well. |
| 189 | + |
| 190 | +```typescript |
| 191 | +static loadWasm(moduleNames: Array<string> | string): Promise<void>; |
| 192 | +``` |
| 193 | + |
| 194 | +**Parameters** |
| 195 | + |
| 196 | +`moduleNames`: specifies one or multiple modules. Supported module names are "cvr", "core", "license", "std", "dip", "dbr", "dlr", "ddn". |
| 197 | + |
| 198 | +**Return Value** |
| 199 | + |
| 200 | +A promise that resolves when the resources have been successfully released. It does not provide any value upon resolution. |
| 201 | + |
| 202 | +**Code snippet** |
| 203 | + |
| 204 | +```javascript |
| 205 | +await Dynamsoft.Core.CoreModule.loadWasm("cvr"); |
| 206 | +``` |
| 207 | + |
| 208 | +<!-- |
| 209 | +## onLog |
| 210 | +
|
| 211 | +Event triggered whenever a log message is ready to be dispatched. |
| 212 | +
|
| 213 | +```typescript |
| 214 | +static onLog: (message:string) =>void; |
| 215 | +``` |
| 216 | +
|
| 217 | +**Parameters** |
| 218 | +
|
| 219 | +`message`: the log message ready to be dispatched. |
| 220 | +
|
| 221 | +**Code snippet** |
| 222 | +
|
| 223 | +```javascript |
| 224 | +Dynamsoft.Core.CoreModule.onLog = console.log; |
| 225 | +``` |
| 226 | +
|
| 227 | +## disableLogging |
| 228 | +
|
| 229 | +Disables logging. |
| 230 | +
|
| 231 | +```typescript |
| 232 | +static disableLogging(): void; |
| 233 | +``` |
| 234 | +
|
| 235 | +## enableLogging |
| 236 | +
|
| 237 | +Enables logging to print internal logs to the browser console for debugging. |
| 238 | +
|
| 239 | +```typescript |
| 240 | +static enableLogging(): void; |
| 241 | +``` --> |
0 commit comments