-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipn-init.js
More file actions
34 lines (27 loc) · 868 Bytes
/
ipn-init.js
File metadata and controls
34 lines (27 loc) · 868 Bytes
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
import { sessionStateStorage } from "./lib/js-state-store"
export async function initIPN({ wsCallback }) {
if (typeof window.Go === 'undefined') {
console.log('Waiting for Go...');
return null;
}
try {
const go = new window.Go();
const result = await WebAssembly.instantiateStreaming(
fetch("main.wasm"),
go.importObject
);
go.run(result.instance).then(() => {
console.error("Unexpected shutdown");
});
const ipn = window.newIPN({
stateStorage: sessionStateStorage,
authKey: import.meta.env.VITE_NODE_AUTH_KEY,
hostname: 'wasm-tsconnect-testNode',
wsCallback: wsCallback
});
return ipn;
} catch (err) {
console.error('WASM 加载错误:', err);
return null;
}
}