Newer
Older

Richard T. Carback III
committed
import type { XXDKUtils } from './types';
import { logFileWorkerPath } from './paths';
const xxdkWasm: URL = require('../assets/wasm/xxdk.wasm');
type Logger = {
StopLogging: () => void,
GetFile: () => Promise<string>,
Threshold: () => number,
MaxSize: () => number,
Size: () => Promise<number>,
Worker: () => Worker,
};
declare global {
interface Window extends XXDKUtils {
onWasmInitialized: () => void;
Crash: () => void;
GetLogger: () => Logger;
logger?: Logger;
getCrashedLogFile: () => Promise<string>;
Go: any;
}
}
export const InitXXDK = () => new Promise<XXDKUtils>(async (xxdkUtils) => {

Richard T. Carback III
committed
const isReady = new Promise<void>((resolve) => {
window!.onWasmInitialized = resolve;
});
const xxdkWasmPath = new URL(window!.xxdkBasePath.toString() + xxdkWasm.toString());
console.log("Fetching xxdkWASM: " + xxdkWasmPath);
console.log("Fetching xxdkWASM base: " + window!.xxdkBasePath);
console.log("Fetching xxdkWASM path: " + xxdkWasm);

Richard T. Carback III
committed
const logWorker = await logFileWorkerPath();
console.log("Got logworkerURL: " + logWorker);

Richard T. Carback III
committed
let go = new window!.Go();
go.argv = [
'--logLevel=1',
'--fileLogLevel=1',

Richard T. Carback III
committed
'--workerScriptURL=' + logWorker,

Richard T. Carback III
committed
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
]
let stream = await WebAssembly?.instantiateStreaming(
fetch(xxdkWasmPath), go.importObject);
go.run(stream.instance);
await isReady;
const {
Base64ToUint8Array,
ConstructIdentity,
DecodePrivateURL,
DecodePublicURL,
GenerateChannelIdentity,
GetChannelInfo,
GetChannelJSON,
GetClientVersion,
GetDefaultCMixParams,
GetOrInitPassword,
GetPublicChannelIdentityFromPrivate,
GetShareUrlType,
GetVersion,
GetWasmSemanticVersion,
ImportPrivateIdentity,
IsNicknameValid,
LoadChannelsManagerWithIndexedDb,
LoadCmix,
LoadNotifications,
LoadNotificationsDummy,
LoadSynchronizedCmix,
NewChannelsManagerWithIndexedDb,
NewCmix,
NewDMClientWithIndexedDb,
NewDatabaseCipher,
NewDummyTrafficManager,
NewSynchronizedCmix,
Purge,
ValidForever,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = (window as any) || {};
const { GetLogger } = window;
if(GetLogger) {
const logger = GetLogger()
// Get the actual Worker object from the log file object
const w = logger.Worker()
window.getCrashedLogFile = () => {
return new Promise((resolve) => {
w.addEventListener('message', ev => {
resolve(atob(JSON.parse(ev.data).data))
})
w.postMessage(JSON.stringify({ tag: 'GetFileExt' }))
});
};
window.logger = logger
}
xxdkUtils({
NewCmix,
NewSynchronizedCmix,
LoadCmix,
LoadNotifications,
LoadNotificationsDummy,
LoadSynchronizedCmix,
GetChannelInfo,
GenerateChannelIdentity,
GetDefaultCMixParams,
NewChannelsManagerWithIndexedDb,
Base64ToUint8Array,
LoadChannelsManagerWithIndexedDb,
GetPublicChannelIdentityFromPrivate,
IsNicknameValid,
GetShareUrlType,
GetVersion,
GetClientVersion,
GetOrInitPassword,
GetWasmSemanticVersion,
ImportPrivateIdentity,
ConstructIdentity,
DecodePrivateURL,
DecodePublicURL,
GetChannelJSON,
NewDMClientWithIndexedDb,
NewDatabaseCipher,
NewDummyTrafficManager,
Purge,
ValidForever
});
});