21
21
22
22
import * as bindings from "./pkg/matrix_sdk_crypto_wasm_bg.js" ;
23
23
24
- const moduleUrl = new URL ( "./pkg/matrix_sdk_crypto_wasm_bg.wasm" , import . meta. url ) ;
24
+ const defaultURL = new URL ( "./pkg/matrix_sdk_crypto_wasm_bg.wasm" , import . meta. url ) ;
25
25
26
26
// Although we could simply instantiate the WASM at import time with a top-level `await`,
27
27
// we avoid that, to make it easier for callers to delay loading the WASM (and instead
@@ -52,10 +52,11 @@ let modPromise = null;
52
52
/**
53
53
* Loads and instantiates the WASM module asynchronously
54
54
*
55
+ * @param {URL } url - The URL to fetch the WebAssembly module from
55
56
* @returns {Promise<void> }
56
57
*/
57
- async function loadModuleAsync ( ) {
58
- const { instance } = await WebAssembly . instantiateStreaming ( fetch ( moduleUrl ) , {
58
+ async function loadModuleAsync ( url ) {
59
+ const { instance } = await WebAssembly . instantiateStreaming ( fetch ( url ) , {
59
60
// @ts -expect-error: The bindings don't exactly match the 'ExportValue' type
60
61
"./matrix_sdk_crypto_wasm_bg.js" : bindings ,
61
62
} ) ;
@@ -70,10 +71,11 @@ async function loadModuleAsync() {
70
71
*
71
72
* Returns a promise which will resolve once the other methods are ready.
72
73
*
74
+ * @param {URL } [url] - The URL to fetch the WebAssembly module from. If not provided, a default URL will be used.
73
75
* @returns {Promise<void> }
74
76
*/
75
- export async function initAsync ( ) {
76
- if ( ! modPromise ) modPromise = loadModuleAsync ( ) ;
77
+ export async function initAsync ( url = defaultURL ) {
78
+ if ( ! modPromise ) modPromise = loadModuleAsync ( url ) ;
77
79
await modPromise ;
78
80
}
79
81
0 commit comments