amiudmodz 6.2.6 → 6.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/lib/Defaults/index.d.ts.map +1 -1
  2. package/lib/Signal/libsignal.d.ts.map +1 -1
  3. package/lib/Signal/libsignal.js.map +1 -1
  4. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  5. package/lib/Signal/lid-mapping.js.map +1 -1
  6. package/lib/Socket/Client/types.d.ts.map +1 -1
  7. package/lib/Socket/Client/websocket.js.map +1 -1
  8. package/lib/Socket/business.d.ts +9 -27
  9. package/lib/Socket/business.d.ts.map +1 -1
  10. package/lib/Socket/business.js.map +1 -1
  11. package/lib/Socket/chats.d.ts +16 -13
  12. package/lib/Socket/chats.d.ts.map +1 -1
  13. package/lib/Socket/chats.js +1 -10
  14. package/lib/Socket/chats.js.map +1 -1
  15. package/lib/Socket/communities.d.ts +53 -71
  16. package/lib/Socket/communities.d.ts.map +1 -1
  17. package/lib/Socket/communities.js.map +1 -1
  18. package/lib/Socket/groups.d.ts +29 -25
  19. package/lib/Socket/groups.d.ts.map +1 -1
  20. package/lib/Socket/groups.js.map +1 -1
  21. package/lib/Socket/index.d.ts.map +1 -1
  22. package/lib/Socket/index.js +29 -14
  23. package/lib/Socket/index.js.map +1 -1
  24. package/lib/Socket/messages-recv.d.ts +45 -63
  25. package/lib/Socket/messages-recv.d.ts.map +1 -1
  26. package/lib/Socket/messages-recv.js.map +1 -1
  27. package/lib/Socket/messages-send.d.ts +47 -65
  28. package/lib/Socket/messages-send.d.ts.map +1 -1
  29. package/lib/Socket/messages-send.js +85 -280
  30. package/lib/Socket/messages-send.js.map +1 -1
  31. package/lib/Socket/mex.d.ts.map +1 -1
  32. package/lib/Socket/mex.js.map +1 -1
  33. package/lib/Socket/newsletter.d.ts +5 -1
  34. package/lib/Socket/newsletter.d.ts.map +1 -1
  35. package/lib/Socket/newsletter.js.map +1 -1
  36. package/lib/Socket/socket.d.ts +8 -8
  37. package/lib/Socket/socket.d.ts.map +1 -1
  38. package/lib/Socket/socket.js +1 -1
  39. package/lib/Socket/socket.js.map +1 -1
  40. package/lib/Types/Bussines.d.ts +1 -1
  41. package/lib/Types/Bussines.d.ts.map +1 -1
  42. package/lib/Types/Message.d.ts +1 -13
  43. package/lib/Types/Message.d.ts.map +1 -1
  44. package/lib/Types/Message.js.map +1 -1
  45. package/lib/Types/USync.d.ts.map +1 -1
  46. package/lib/Types/USync.js.map +1 -1
  47. package/lib/Types/index.d.ts.map +1 -1
  48. package/lib/Types/index.js.map +1 -1
  49. package/lib/Utils/MessageBuilder.d.ts +0 -1
  50. package/lib/Utils/MessageBuilder.d.ts.map +1 -1
  51. package/lib/Utils/MessageBuilder.js +0 -11
  52. package/lib/Utils/MessageBuilder.js.map +1 -1
  53. package/lib/Utils/auth-utils.d.ts.map +1 -1
  54. package/lib/Utils/auth-utils.js.map +1 -1
  55. package/lib/Utils/baileys-event-stream.js +0 -0
  56. package/lib/Utils/browser-utils.d.ts.map +1 -1
  57. package/lib/Utils/business.d.ts.map +1 -1
  58. package/lib/Utils/business.js.map +1 -1
  59. package/lib/Utils/chat-utils.d.ts.map +1 -1
  60. package/lib/Utils/chat-utils.js.map +1 -1
  61. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -1
  62. package/lib/Utils/crypto.d.ts.map +1 -1
  63. package/lib/Utils/crypto.js.map +1 -1
  64. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  65. package/lib/Utils/decode-wa-message.js.map +1 -1
  66. package/lib/Utils/event-buffer.d.ts.map +1 -1
  67. package/lib/Utils/event-buffer.js.map +1 -1
  68. package/lib/Utils/generics.d.ts.map +1 -1
  69. package/lib/Utils/generics.js.map +1 -1
  70. package/lib/Utils/history.d.ts.map +1 -1
  71. package/lib/Utils/history.js.map +1 -1
  72. package/lib/Utils/identity-change-handler.d.ts.map +1 -1
  73. package/lib/Utils/identity-change-handler.js.map +1 -1
  74. package/lib/Utils/index.d.ts +0 -1
  75. package/lib/Utils/index.d.ts.map +1 -1
  76. package/lib/Utils/index.js +0 -1
  77. package/lib/Utils/index.js.map +1 -1
  78. package/lib/Utils/link-preview.d.ts.map +1 -1
  79. package/lib/Utils/messages-media.d.ts.map +1 -1
  80. package/lib/Utils/messages-media.js.map +1 -1
  81. package/lib/Utils/messages.d.ts +1 -1
  82. package/lib/Utils/messages.d.ts.map +1 -1
  83. package/lib/Utils/messages.js +0 -97
  84. package/lib/Utils/messages.js.map +1 -1
  85. package/lib/Utils/noise-handler.d.ts.map +1 -1
  86. package/lib/Utils/noise-handler.js.map +1 -1
  87. package/lib/Utils/offline-node-processor.d.ts.map +1 -1
  88. package/lib/Utils/pre-key-manager.d.ts.map +1 -1
  89. package/lib/Utils/process-message.d.ts.map +1 -1
  90. package/lib/Utils/process-message.js.map +1 -1
  91. package/lib/Utils/reporting-utils.d.ts.map +1 -1
  92. package/lib/Utils/rich-message-utils.js.map +1 -1
  93. package/lib/Utils/shortcake-crypto.d.ts.map +1 -1
  94. package/lib/Utils/shortcake.d.ts.map +1 -1
  95. package/lib/Utils/shortcake.js.map +1 -1
  96. package/lib/Utils/signal.d.ts.map +1 -1
  97. package/lib/Utils/signal.js.map +1 -1
  98. package/lib/Utils/stanza-ack.d.ts.map +1 -1
  99. package/lib/Utils/sync-action-utils.d.ts.map +1 -1
  100. package/lib/Utils/sync-action-utils.js.map +1 -1
  101. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  102. package/lib/Utils/tc-token-utils.js.map +1 -1
  103. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
  104. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -1
  105. package/lib/Utils/use-single-file-auth-state.js.map +1 -1
  106. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -1
  107. package/lib/Utils/validate-connection.d.ts.map +1 -1
  108. package/lib/Utils/validate-connection.js.map +1 -1
  109. package/lib/VoIP/audio-feeder.d.ts +54 -0
  110. package/lib/VoIP/audio-feeder.d.ts.map +1 -0
  111. package/lib/VoIP/audio-feeder.js +269 -0
  112. package/lib/VoIP/audio-feeder.js.map +1 -0
  113. package/lib/VoIP/index.d.ts +108 -0
  114. package/lib/VoIP/index.d.ts.map +1 -0
  115. package/lib/VoIP/index.js +920 -0
  116. package/lib/VoIP/index.js.map +1 -0
  117. package/lib/VoIP/relay-transport.d.ts +42 -0
  118. package/lib/VoIP/relay-transport.d.ts.map +1 -0
  119. package/lib/VoIP/relay-transport.js +652 -0
  120. package/lib/VoIP/relay-transport.js.map +1 -0
  121. package/lib/VoIP/signaling.d.ts +71 -0
  122. package/lib/VoIP/signaling.d.ts.map +1 -0
  123. package/lib/VoIP/signaling.js +1046 -0
  124. package/lib/VoIP/signaling.js.map +1 -0
  125. package/lib/VoIP/types.d.ts +13 -0
  126. package/lib/VoIP/types.d.ts.map +1 -0
  127. package/lib/VoIP/types.js +13 -0
  128. package/lib/VoIP/types.js.map +1 -0
  129. package/lib/VoIP/video-feeder.d.ts +53 -0
  130. package/lib/VoIP/video-feeder.d.ts.map +1 -0
  131. package/lib/VoIP/video-feeder.js +269 -0
  132. package/lib/VoIP/video-feeder.js.map +1 -0
  133. package/lib/VoIP/wasm-engine.d.ts +36 -0
  134. package/lib/VoIP/wasm-engine.d.ts.map +1 -0
  135. package/lib/VoIP/wasm-engine.js +1364 -0
  136. package/lib/VoIP/wasm-engine.js.map +1 -0
  137. package/lib/VoIP/worker-bootstrap.d.ts +2 -0
  138. package/lib/VoIP/worker-bootstrap.d.ts.map +1 -0
  139. package/lib/VoIP/worker-bootstrap.js +1023 -0
  140. package/lib/VoIP/worker-bootstrap.js.map +1 -0
  141. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  142. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  143. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -1
  144. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -1
  145. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -1
  146. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -1
  147. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -1
  148. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -1
  149. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -1
  150. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -1
  151. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -1
  152. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -1
  153. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -1
  154. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  155. package/lib/WAUSync/USyncQuery.js.map +1 -1
  156. package/lib/assets/wasm/README.md +76 -0
  157. package/lib/assets/wasm/loader.d.ts +2 -0
  158. package/lib/assets/wasm/loader.d.ts.map +1 -0
  159. package/lib/assets/wasm/loader.js +1866 -0
  160. package/lib/assets/wasm/loader.js.map +1 -0
  161. package/lib/assets/wasm/whatsapp.wasm +0 -0
  162. package/lib/assets/wasm/worker-modules.d.ts +2 -0
  163. package/lib/assets/wasm/worker-modules.d.ts.map +1 -0
  164. package/lib/assets/wasm/worker-modules.js +11038 -0
  165. package/lib/assets/wasm/worker-modules.js.map +1 -0
  166. package/lib/index.d.ts.map +1 -1
  167. package/lib/index.js.map +1 -1
  168. package/package.json +146 -142
@@ -0,0 +1,1364 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _NodeWorkerMessagePort_listeners, _NodeWorkerMessagePort_worker, _NodeWorkerMessagePort_handleMessage, _a, _WasmEngine_jsWorkers, _WasmEngine_globalCallbackListeners, _WasmEngine_globalCallbacksRegistered, _WasmEngine_config, _WasmEngine_instance, _WasmEngine_initialized, _WasmEngine_moduleRegistry, _WasmEngine_vmContext, _WasmEngine_unusedWorkers, _WasmEngine_runningWorkers, _WasmEngine_pthreads, _WasmEngine_nextWorkerID, _WasmEngine_wasmModule, _WasmEngine_wasmMemory, _WasmEngine_removeRunDependencyCallback, _WasmEngine_workersLoadedCount, _WasmEngine_audioPlaybackLoopInterval, _WasmEngine_audioPlaybackBuffer, _WasmEngine_isPlaybackActive, _WasmEngine_voipStackInitialized, _WasmEngine_voipStackInitPromise, _WasmEngine_voipReadyResolver, _WasmEngine_voipReadyPromise, _WasmEngine_workerModulesCode, _WasmEngine_loaderCode, _WasmEngine_ensureInitialized, _WasmEngine_makeStringList, _WasmEngine_createUint8List, _WasmEngine_startAudioPlaybackLoop, _WasmEngine_stopAudioPlaybackLoop, _WasmEngine_applyDefaultAbProps, _WasmEngine_allocateUnusedWorker, _WasmEngine_initPThreadPool, _WasmEngine_loadWasmModuleToWorker, _WasmEngine_loadWasmModuleToAllWorkers, _WasmEngine_registerGlobalCallbacks, _WasmEngine_requireModule, _WasmEngine_createVMContext, _WasmEngine_createAtomicsWrapper;
13
+ import * as vm from 'node:vm';
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import { tmpdir } from 'node:os';
17
+ import { Worker } from 'node:worker_threads';
18
+ import { randomFillSync } from 'node:crypto';
19
+ import { fileURLToPath } from 'node:url';
20
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
21
+ const CALL_WASM_AB_PROPS_JSON = process.env.CALL_WASM_AB_PROPS_JSON ?? "";
22
+ const PTHREAD_POOL_SIZE = 20;
23
+ const VOIP_READY_TIMEOUT_MS = 15000;
24
+ const parseJsonObjectEnv = (raw) => {
25
+ if (!raw)
26
+ return {};
27
+ try {
28
+ const parsed = JSON.parse(raw);
29
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
30
+ return parsed;
31
+ }
32
+ catch { }
33
+ return {};
34
+ };
35
+ const toByteArray = (input) => {
36
+ if (!input)
37
+ return new Uint8Array(0);
38
+ if (input instanceof Uint8Array)
39
+ return input;
40
+ if (typeof input === "string")
41
+ return new TextEncoder().encode(input);
42
+ if (ArrayBuffer.isView(input))
43
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
44
+ if (input instanceof ArrayBuffer)
45
+ return new Uint8Array(input);
46
+ if (typeof input === "object" && typeof input.length === "number") {
47
+ const arr = new Uint8Array(input.length);
48
+ for (let i = 0; i < input.length; i += 1)
49
+ arr[i] = input[i] ?? 0;
50
+ return arr;
51
+ }
52
+ return new Uint8Array(0);
53
+ };
54
+ const filterWorkerStderr = (chunk) => {
55
+ const line = chunk.toString().trim();
56
+ if (line && !line.startsWith("voip:") && !line.startsWith("still waiting")) {
57
+ process.stderr.write(chunk);
58
+ }
59
+ };
60
+ const normalizeVideoCaptureConfig = (data) => ({
61
+ width: Math.trunc(Number(data?.width ?? data?.frame_width ?? data?.frameWidth ?? 0)) || 640,
62
+ height: Math.trunc(Number(data?.height ?? data?.frame_height ?? data?.frameHeight ?? 0)) || 480,
63
+ fps: Math.trunc(Number(data?.fps ?? data?.frame_rate ?? data?.frameRate ?? data?.max_framerate ?? 0)) || 24,
64
+ raw: data
65
+ });
66
+ const resolveWorkerScriptPath = () => {
67
+ const compiled = path.join(currentDir, "worker-bootstrap.js");
68
+ return fs.existsSync(compiled) ? compiled : path.join(currentDir, "worker-bootstrap.mts");
69
+ };
70
+ class NodeWorkerMessagePort {
71
+ constructor(worker, name = "WAWebVoipWebWasmWorker") {
72
+ _NodeWorkerMessagePort_listeners.set(this, new Map());
73
+ _NodeWorkerMessagePort_worker.set(this, void 0);
74
+ this.workerID = 0;
75
+ this.pthread_ptr = 0;
76
+ this.postMessage = (msg, transferList) => {
77
+ const out = msg && typeof msg === "object" && msg.cmd && !msg.type ? { ...msg, type: "cmd" } : msg;
78
+ __classPrivateFieldGet(this, _NodeWorkerMessagePort_worker, "f").postMessage(out, transferList);
79
+ };
80
+ this.addMessageListener = (type, handler) => {
81
+ let set = __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").get(type);
82
+ if (!set) {
83
+ set = new Set();
84
+ __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").set(type, set);
85
+ }
86
+ set.add(handler);
87
+ return handler;
88
+ };
89
+ this.removeMessageListener = (type, handler) => __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").get(type)?.delete(handler) ?? false;
90
+ this.removeAllMessageListeners = (type) => {
91
+ if (type)
92
+ __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").get(type)?.clear();
93
+ else
94
+ __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").clear();
95
+ };
96
+ this.terminate = () => { __classPrivateFieldGet(this, _NodeWorkerMessagePort_worker, "f").terminate(); };
97
+ this.close = () => { };
98
+ this.isWrappingVirtualMessagePort = () => false;
99
+ this.getWorker = () => __classPrivateFieldGet(this, _NodeWorkerMessagePort_worker, "f");
100
+ _NodeWorkerMessagePort_handleMessage.set(this, (data) => {
101
+ if (!data || typeof data !== "object")
102
+ return;
103
+ if (data.type === "callback" || data.type === "waWasmWorkerCompatibleCallback") {
104
+ let callbackName;
105
+ let callbackArgs;
106
+ if (data.__name) {
107
+ callbackName = data.__name;
108
+ callbackArgs = {};
109
+ for (const key in data) {
110
+ if (key !== "type" && key !== "__name" && key !== "prototype" && key !== "args" && !key.startsWith("__")) {
111
+ callbackArgs[key] = data[key];
112
+ }
113
+ }
114
+ }
115
+ else if (data.name) {
116
+ callbackName = data.name;
117
+ callbackArgs = data.args ?? {};
118
+ }
119
+ else if (data.payload?.name) {
120
+ callbackName = data.payload.name;
121
+ callbackArgs = data.payload.args ?? {};
122
+ }
123
+ else {
124
+ return;
125
+ }
126
+ if (callbackName === "onSignalingXmpp" &&
127
+ (!callbackArgs || Object.keys(callbackArgs).length === 0)) {
128
+ callbackArgs = {
129
+ peerJid: data.peerJid, callId: data.callId, xmlPayload: data.xmlPayload,
130
+ };
131
+ }
132
+ let listenerData = callbackArgs;
133
+ if (!callbackArgs || Object.keys(callbackArgs).length === 0 ||
134
+ (Object.keys(callbackArgs).length === 1 && callbackArgs.prototype)) {
135
+ listenerData = {};
136
+ for (const key in data) {
137
+ if (key !== "type" && key !== "__name" && key !== "prototype" && key !== "args" && !key.startsWith("__")) {
138
+ listenerData[key] = data[key];
139
+ }
140
+ }
141
+ }
142
+ else if (callbackName === "sendDataToRelay") {
143
+ listenerData = { ...callbackArgs };
144
+ if (data.data !== undefined)
145
+ listenerData.data = data.data;
146
+ if (data.len !== undefined)
147
+ listenerData.len = data.len;
148
+ if (data.ip !== undefined)
149
+ listenerData.ip = data.ip;
150
+ if (data.port !== undefined)
151
+ listenerData.port = data.port;
152
+ }
153
+ else if (callbackName === "onCallEvent") {
154
+ listenerData = { ...callbackArgs };
155
+ if (data.eventType !== undefined)
156
+ listenerData.eventType = data.eventType;
157
+ if (data.userData !== undefined)
158
+ listenerData.userData = data.userData;
159
+ if (data.eventDataJson !== undefined)
160
+ listenerData.eventDataJson = data.eventDataJson;
161
+ }
162
+ WasmEngine.notifyGlobalCallbackListeners(callbackName, listenerData);
163
+ return;
164
+ }
165
+ const dispatch = (key) => {
166
+ if (!key)
167
+ return;
168
+ for (const handler of __classPrivateFieldGet(this, _NodeWorkerMessagePort_listeners, "f").get(key) ?? []) {
169
+ try {
170
+ handler(data);
171
+ }
172
+ catch { }
173
+ }
174
+ };
175
+ dispatch(data.type);
176
+ if (data.cmd !== data.type)
177
+ dispatch(data.cmd);
178
+ });
179
+ __classPrivateFieldSet(this, _NodeWorkerMessagePort_worker, worker, "f");
180
+ this.name = name;
181
+ this.fullyConnected = new Promise((resolve) => {
182
+ const loadedHandler = (msg) => {
183
+ if (msg && msg.cmd === "loaded") {
184
+ this.workerID = msg.workerID ?? 0;
185
+ resolve(this);
186
+ }
187
+ };
188
+ this.addMessageListener("cmd", loadedHandler);
189
+ });
190
+ if (typeof worker.on === "function") {
191
+ worker.on("message", (data) => __classPrivateFieldGet(this, _NodeWorkerMessagePort_handleMessage, "f").call(this, data));
192
+ worker.on("error", () => { });
193
+ }
194
+ else if (typeof worker.addEventListener === "function") {
195
+ worker.addEventListener("message", (ev) => __classPrivateFieldGet(this, _NodeWorkerMessagePort_handleMessage, "f").call(this, ev?.data ?? ev));
196
+ }
197
+ }
198
+ }
199
+ _NodeWorkerMessagePort_listeners = new WeakMap(), _NodeWorkerMessagePort_worker = new WeakMap(), _NodeWorkerMessagePort_handleMessage = new WeakMap();
200
+ export class WasmEngine {
201
+ constructor(config = {}) {
202
+ _WasmEngine_jsWorkers.set(this, new Set());
203
+ _WasmEngine_config.set(this, void 0);
204
+ _WasmEngine_instance.set(this, null);
205
+ _WasmEngine_initialized.set(this, false);
206
+ _WasmEngine_moduleRegistry.set(this, new Map());
207
+ _WasmEngine_vmContext.set(this, null);
208
+ _WasmEngine_unusedWorkers.set(this, []);
209
+ _WasmEngine_runningWorkers.set(this, []);
210
+ _WasmEngine_pthreads.set(this, {});
211
+ _WasmEngine_nextWorkerID.set(this, 1);
212
+ _WasmEngine_wasmModule.set(this, null);
213
+ _WasmEngine_wasmMemory.set(this, null);
214
+ _WasmEngine_removeRunDependencyCallback.set(this, null);
215
+ _WasmEngine_workersLoadedCount.set(this, 0);
216
+ _WasmEngine_audioPlaybackLoopInterval.set(this, null);
217
+ _WasmEngine_audioPlaybackBuffer.set(this, null);
218
+ _WasmEngine_isPlaybackActive.set(this, false);
219
+ _WasmEngine_voipStackInitialized.set(this, false);
220
+ _WasmEngine_voipStackInitPromise.set(this, null);
221
+ _WasmEngine_voipReadyResolver.set(this, null);
222
+ _WasmEngine_voipReadyPromise.set(this, null);
223
+ _WasmEngine_workerModulesCode.set(this, "");
224
+ _WasmEngine_loaderCode.set(this, "");
225
+ this.initialize = async () => {
226
+ if (__classPrivateFieldGet(this, _WasmEngine_initialized, "f"))
227
+ throw new Error("WasmEngine already initialized");
228
+ const voipStorageDir = __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir;
229
+ try {
230
+ if (!fs.existsSync(voipStorageDir))
231
+ fs.mkdirSync(voipStorageDir, { recursive: true });
232
+ }
233
+ catch { }
234
+ let loaderFile = path.join(__classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath, "assets", "wasm", "loader.js");
235
+ let workerFile = path.join(__classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath, "assets", "wasm", "worker-modules.js");
236
+ if (!fs.existsSync(loaderFile)) {
237
+ const fallbackBases = [
238
+ path.resolve(currentDir, ".."),
239
+ path.resolve(currentDir, "../../src"),
240
+ path.resolve(currentDir, "../../lib"),
241
+ path.resolve(process.cwd(), "src"),
242
+ path.resolve(process.cwd(), "lib"),
243
+ ];
244
+ for (const base of fallbackBases) {
245
+ const altLoader = path.join(base, "assets", "wasm", "loader.js");
246
+ if (fs.existsSync(altLoader)) {
247
+ loaderFile = altLoader;
248
+ workerFile = path.join(base, "assets", "wasm", "worker-modules.js");
249
+ break;
250
+ }
251
+ }
252
+ }
253
+ if (!__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary && !fs.existsSync(__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath)) {
254
+ throw new Error(`WhatsApp VoIP WASM not found at ${__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath}. Point wasmPath at it, hand the bytes over as wasmBinary, or put whatsapp.wasm, loader.js and worker-modules.js under <resourcesPath>/assets/wasm/.`);
255
+ }
256
+ const wasmBuffer = __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary
257
+ ? Buffer.from(__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary)
258
+ : fs.readFileSync(__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath);
259
+ const diskWorkerCode = fs.existsSync(workerFile) ? fs.readFileSync(workerFile, "utf8") : "";
260
+ __classPrivateFieldSet(this, _WasmEngine_workerModulesCode, __classPrivateFieldGet(this, _WasmEngine_config, "f").workerModulesCode ?? diskWorkerCode, "f");
261
+ const workerBundleHasLoader = typeof __classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f") === "string" && /WAWebVoipWebWasmLoader/.test(__classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f"));
262
+ __classPrivateFieldSet(this, _WasmEngine_loaderCode, __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderCode ??
263
+ (workerBundleHasLoader ? "" : fs.existsSync(loaderFile) ? fs.readFileSync(loaderFile, "utf8") : ""), "f");
264
+ if (!__classPrivateFieldGet(this, _WasmEngine_loaderCode, "f") && !__classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f")) {
265
+ throw new Error("No loader/worker code available to initialize VoIP");
266
+ }
267
+ const memory = new WebAssembly.Memory({ initial: 256, maximum: 32768, shared: true });
268
+ __classPrivateFieldSet(this, _WasmEngine_wasmMemory, memory, "f");
269
+ __classPrivateFieldSet(this, _WasmEngine_wasmModule, await WebAssembly.compile(wasmBuffer), "f");
270
+ __classPrivateFieldSet(this, _WasmEngine_vmContext, __classPrivateFieldGet(this, _WasmEngine_createVMContext, "f").call(this, memory), "f");
271
+ const runModuleCode = (code) => {
272
+ if (code)
273
+ vm.runInContext(code, __classPrivateFieldGet(this, _WasmEngine_vmContext, "f"));
274
+ };
275
+ runModuleCode(__classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f"));
276
+ runModuleCode(__classPrivateFieldGet(this, _WasmEngine_loaderCode, "f"));
277
+ __classPrivateFieldGet(this, _WasmEngine_vmContext, "f").WAWebVoipWebWasmWorkerResource = __classPrivateFieldGet(this, _WasmEngine_requireModule, "f").call(this, "WAWebVoipWebWasmWorkerResource");
278
+ const loaderModuleNames = [
279
+ __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderModuleName,
280
+ "WAWebVoipWebWasmLoader",
281
+ "WAWebVoipWebWasmLoader.worker",
282
+ "WAWebVoipWebWasmLoader_ProdLab_internal.worker",
283
+ "WAWebVoipWebWasmLoader_ProdLabvideo_internal.worker",
284
+ ].filter((v, i, a) => !!v && a.indexOf(v) === i);
285
+ let wasmLoader = null;
286
+ for (const moduleName of loaderModuleNames) {
287
+ const candidate = __classPrivateFieldGet(this, _WasmEngine_requireModule, "f").call(this, moduleName);
288
+ if (typeof candidate === "function") {
289
+ wasmLoader = candidate;
290
+ break;
291
+ }
292
+ if (typeof candidate?.default === "function") {
293
+ wasmLoader = candidate.default;
294
+ break;
295
+ }
296
+ }
297
+ if (typeof wasmLoader !== "function") {
298
+ throw new Error(`No compatible WASM loader found. Tried: ${loaderModuleNames.join(", ")}`);
299
+ }
300
+ if (!__classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbacksRegistered))
301
+ __classPrivateFieldGet(this, _WasmEngine_registerGlobalCallbacks, "f").call(this);
302
+ await __classPrivateFieldGet(this, _WasmEngine_initPThreadPool, "f").call(this);
303
+ const workersLoadingPromise = __classPrivateFieldGet(this, _WasmEngine_loadWasmModuleToAllWorkers, "f").call(this);
304
+ const readyPromise = wasmLoader({
305
+ wasmBinary: wasmBuffer,
306
+ wasmMemory: memory,
307
+ locateFile: () => __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath,
308
+ onRuntimeInitialized: () => { },
309
+ });
310
+ const [instance] = await Promise.all([readyPromise, workersLoadingPromise]);
311
+ __classPrivateFieldSet(this, _WasmEngine_instance, instance, "f");
312
+ __classPrivateFieldSet(this, _WasmEngine_initialized, true, "f");
313
+ };
314
+ this.isInitialized = () => __classPrivateFieldGet(this, _WasmEngine_initialized, "f");
315
+ this.destroy = () => {
316
+ __classPrivateFieldGet(this, _WasmEngine_stopAudioPlaybackLoop, "f").call(this);
317
+ if (__classPrivateFieldGet(this, _WasmEngine_instance, "f") && typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").endCall === "function") {
318
+ try {
319
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").endCall(0, false);
320
+ }
321
+ catch { }
322
+ }
323
+ for (const worker of [...__classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f"), ...__classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f")]) {
324
+ try {
325
+ worker.terminate();
326
+ }
327
+ catch { }
328
+ }
329
+ __classPrivateFieldSet(this, _WasmEngine_runningWorkers, [], "f");
330
+ __classPrivateFieldSet(this, _WasmEngine_unusedWorkers, [], "f");
331
+ __classPrivateFieldSet(this, _WasmEngine_instance, null, "f");
332
+ __classPrivateFieldSet(this, _WasmEngine_vmContext, null, "f");
333
+ __classPrivateFieldGet(this, _WasmEngine_moduleRegistry, "f").clear();
334
+ __classPrivateFieldSet(this, _WasmEngine_wasmModule, null, "f");
335
+ __classPrivateFieldSet(this, _WasmEngine_wasmMemory, null, "f");
336
+ __classPrivateFieldSet(this, _WasmEngine_initialized, false, "f");
337
+ };
338
+ this.initVoipStack = (selfJid, meUserJid, selfLid) => {
339
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
340
+ if (__classPrivateFieldGet(this, _WasmEngine_voipStackInitialized, "f") || __classPrivateFieldGet(this, _WasmEngine_voipStackInitPromise, "f"))
341
+ return;
342
+ __classPrivateFieldSet(this, _WasmEngine_voipStackInitPromise, new Promise((resolveInit) => {
343
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyPromise, new Promise((readyResolve) => {
344
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyResolver, () => {
345
+ __classPrivateFieldSet(this, _WasmEngine_voipStackInitialized, true, "f");
346
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyResolver, null, "f");
347
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyPromise, null, "f");
348
+ readyResolve();
349
+ }, "f");
350
+ }), "f");
351
+ try {
352
+ __classPrivateFieldGet(this, _WasmEngine_applyDefaultAbProps, "f").call(this);
353
+ try {
354
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").initVoipStack(selfJid, meUserJid, selfLid);
355
+ }
356
+ catch (modernErr) {
357
+ if (modernErr?.name === "BindingError" &&
358
+ (String(modernErr?.message ?? "").includes("expected 8 args") ||
359
+ String(modernErr?.message ?? "").includes("takes 8"))) {
360
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").initVoipStack(selfJid, meUserJid, selfLid, true, 5, 0, 8, 16);
361
+ }
362
+ else {
363
+ throw modernErr;
364
+ }
365
+ }
366
+ Promise.race([
367
+ __classPrivateFieldGet(this, _WasmEngine_voipReadyPromise, "f"),
368
+ new Promise((r) => setTimeout(() => {
369
+ __classPrivateFieldSet(this, _WasmEngine_voipStackInitialized, true, "f");
370
+ r();
371
+ }, VOIP_READY_TIMEOUT_MS)),
372
+ ]).finally(() => {
373
+ __classPrivateFieldSet(this, _WasmEngine_voipStackInitPromise, null, "f");
374
+ resolveInit();
375
+ });
376
+ }
377
+ catch {
378
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyResolver, null, "f");
379
+ __classPrivateFieldSet(this, _WasmEngine_voipReadyPromise, null, "f");
380
+ __classPrivateFieldSet(this, _WasmEngine_voipStackInitPromise, null, "f");
381
+ resolveInit();
382
+ }
383
+ }), "f");
384
+ };
385
+ this.waitForVoipStackReady = async () => {
386
+ if (__classPrivateFieldGet(this, _WasmEngine_voipStackInitialized, "f"))
387
+ return;
388
+ if (__classPrivateFieldGet(this, _WasmEngine_voipStackInitPromise, "f")) {
389
+ await __classPrivateFieldGet(this, _WasmEngine_voipStackInitPromise, "f");
390
+ }
391
+ else {
392
+ await new Promise((r) => setTimeout(r, 100));
393
+ }
394
+ };
395
+ this.isVoipStackReady = () => __classPrivateFieldGet(this, _WasmEngine_voipStackInitialized, "f");
396
+ this.startCall = (options) => {
397
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
398
+ const peers = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.peerList ?? [options.peerJid]);
399
+ const tcToken = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, options.extraData);
400
+ const isLidCall = options.isLidCall ?? options.peerJid.includes("@lid");
401
+ const isFromDialer = options.isFromDialer ?? false;
402
+ const peerJid = String(options.peerJid);
403
+ try {
404
+ try {
405
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").startVoipCall(peerJid, peers, options.callId, options.isVideo, options.peerPn, isLidCall, isFromDialer, tcToken);
406
+ }
407
+ catch (error) {
408
+ if (error?.name !== "BindingError")
409
+ throw error;
410
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").startVoipCall(peerJid, peers, options.callId, options.isVideo, options.peerPn, isFromDialer, tcToken);
411
+ }
412
+ }
413
+ finally {
414
+ peers?.delete?.();
415
+ tcToken?.delete?.();
416
+ }
417
+ };
418
+ this.startGroupCall = (options) => {
419
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
420
+ const pnUserJids = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.pnUserJids ?? []);
421
+ const lidUserJids = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.lidUserJids ?? []);
422
+ const deviceJidsCsv = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.deviceJidsCsv ?? []);
423
+ try {
424
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").startVoipGroupCall(pnUserJids, lidUserJids, deviceJidsCsv, options.callId, options.isVideo ?? false, options.groupJid, options.isLightWeight ?? false, options.scheduleId ?? "", options.chatName ?? "", options.chatIcon ?? "", options.callFromUI ?? 0, options.lobbyEntryType ?? 0, options.username ?? "");
425
+ }
426
+ finally {
427
+ pnUserJids?.delete?.();
428
+ lidUserJids?.delete?.();
429
+ deviceJidsCsv?.delete?.();
430
+ }
431
+ };
432
+ this.joinOngoingCall = (options) => {
433
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
434
+ const pnUserJids = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.pnUserJids ?? []);
435
+ const lidUserJids = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.lidUserJids ?? []);
436
+ const deviceJidsCsv = __classPrivateFieldGet(this, _WasmEngine_makeStringList, "f").call(this, options.deviceJidsCsv ?? []);
437
+ try {
438
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").joinVoipOngoingCall(options.callId, options.callCreatorJid, options.initialPeerJid ?? options.callCreatorJid, pnUserJids, lidUserJids, deviceJidsCsv, options.isVideo ?? false, options.groupJid ?? "", options.initialGroupTransactionId ?? 0, options.callCreatorIsNotContact ?? false, options.callLinkCode ?? "", options.isLightweight ?? false, options.scheduledId ?? "", options.joinAndAccept ?? true, options.chatName ?? "", options.lobbyEntryType ?? 0, options.isDeviceSwitch ?? false);
439
+ }
440
+ finally {
441
+ pnUserJids?.delete?.();
442
+ lidUserJids?.delete?.();
443
+ deviceJidsCsv?.delete?.();
444
+ }
445
+ };
446
+ this.acceptCall = (isMicEnabled = true, isCameraEnabled = false) => {
447
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
448
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").acceptCall(isMicEnabled, isCameraEnabled);
449
+ };
450
+ this.endCall = (reason = 0, sendTerminate = true) => {
451
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
452
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").endCall(reason, sendTerminate);
453
+ };
454
+ this.setMute = (muted) => {
455
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
456
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").setCallMute(muted);
457
+ };
458
+ this.updateNetworkMedium = (networkMedium, networkMtu = 0) => {
459
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
460
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").updateNetworkMedium?.(networkMedium, networkMtu);
461
+ };
462
+ this.handleSignalingOffer = (msg) => {
463
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
464
+ const tcTokenList = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, msg.tcToken);
465
+ try {
466
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleIncomingSignalingOffer(msg.payload, String(msg.peerPlatform ?? 0), String(msg.peerAppVersion ?? "0"), String(msg.epochId ?? "0"), String(msg.timestamp ?? "0"), msg.isOffline ?? false, msg.isOfferNotContact ?? false, String(msg.peerJid), tcTokenList);
467
+ }
468
+ finally {
469
+ tcTokenList?.delete?.();
470
+ }
471
+ };
472
+ this.handleSignalingMessage = (msg) => {
473
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
474
+ const tcTokenList = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, msg.tcToken);
475
+ try {
476
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleIncomingSignalingMessage(msg.payload, String(msg.peerPlatform ?? "0"), String(msg.peerAppVersion ?? "0"), String(msg.epochId ?? "0"), String(msg.timestamp ?? "0"), msg.isOffline ?? false, String(msg.peerJid), tcTokenList);
477
+ }
478
+ finally {
479
+ tcTokenList?.delete?.();
480
+ }
481
+ };
482
+ this.handleSignalingAck = (msg) => {
483
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
484
+ const options = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, msg.extraData);
485
+ try {
486
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleIncomingSignalingAck(msg.payload, String(msg.ackError ?? "0"), String(msg.msgType ?? ""), msg.peerJid ?? "", options);
487
+ }
488
+ finally {
489
+ options?.delete?.();
490
+ }
491
+ };
492
+ this.handleSignalingReceipt = (msg) => {
493
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
494
+ const tcTokenList = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, msg.tcToken);
495
+ try {
496
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleIncomingSignalingReceipt?.(msg.payload, msg.peerJid, tcTokenList);
497
+ }
498
+ finally {
499
+ tcTokenList?.delete?.();
500
+ }
501
+ };
502
+ this.handleOnTransportMessage = (data, ip, port) => {
503
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
504
+ if (typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleOnMessageFromHeap === "function") {
505
+ const ptr = this.malloc(data.byteLength);
506
+ if (!ptr)
507
+ return;
508
+ try {
509
+ const heapU8 = __classPrivateFieldGet(this, _WasmEngine_instance, "f").GROWABLE_HEAP_U8?.() ?? __classPrivateFieldGet(this, _WasmEngine_instance, "f").HEAPU8;
510
+ if (!heapU8)
511
+ return;
512
+ heapU8.set(data, ptr);
513
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleOnMessageFromHeap(ptr, data.byteLength, ip, port);
514
+ }
515
+ finally {
516
+ this.free(ptr);
517
+ }
518
+ return;
519
+ }
520
+ if (typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleOnMessage !== "function")
521
+ return;
522
+ const dataList = __classPrivateFieldGet(this, _WasmEngine_createUint8List, "f").call(this, data);
523
+ try {
524
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").handleOnMessage(dataList, ip, port);
525
+ }
526
+ finally {
527
+ dataList?.delete?.();
528
+ }
529
+ };
530
+ this.updateIceRtt = (rttMs, relayIp, relayPort) => {
531
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
532
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").updateIceRtt?.(rttMs, relayIp, relayPort);
533
+ };
534
+ this.startScreenShare = () => {
535
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
536
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").startScreenShare?.();
537
+ };
538
+ this.stopScreenShare = () => {
539
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
540
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f").stopScreenShare?.();
541
+ };
542
+ this.sendVideoFrame = (frame, width, height, fps, format = 0, orientation = 0, useDesktopCapture = false) => {
543
+ if (!__classPrivateFieldGet(this, _WasmEngine_jsWorkers, "f").size || !frame?.byteLength || !width || !height) {
544
+ return false;
545
+ }
546
+ const timestamp = Date.now();
547
+ for (const worker of __classPrivateFieldGet(this, _WasmEngine_jsWorkers, "f")) {
548
+ const copy = frame.buffer.slice(frame.byteOffset, frame.byteOffset + frame.byteLength);
549
+ try {
550
+ worker.postMessage({
551
+ type: "jsWorkerCmd",
552
+ jsWorkerCmd: "pushRawVideoFrame",
553
+ useDesktopCapture,
554
+ frameBuffer: copy,
555
+ width,
556
+ height,
557
+ fps,
558
+ format,
559
+ orientation,
560
+ timestamp
561
+ }, [copy]);
562
+ }
563
+ catch { }
564
+ }
565
+ return true;
566
+ };
567
+ this.releaseVideoFrameBuffer = () => {
568
+ for (const worker of __classPrivateFieldGet(this, _WasmEngine_jsWorkers, "f")) {
569
+ try {
570
+ worker.postMessage({ type: "jsWorkerCmd", jsWorkerCmd: "releaseRawVideoFrameBuffer" });
571
+ }
572
+ catch { }
573
+ }
574
+ };
575
+ this.sendAudioData = (data, ptr) => {
576
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
577
+ if (!data || data.length === 0 || !ptr)
578
+ return;
579
+ if (typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").onAudioDataFromJs !== "function")
580
+ return;
581
+ try {
582
+ const heapF32 = __classPrivateFieldGet(this, _WasmEngine_instance, "f").GROWABLE_HEAP_F32?.();
583
+ if (!heapF32)
584
+ return;
585
+ const index = Math.floor(ptr / 4);
586
+ if (index < 0 || index + data.length > heapF32.length)
587
+ return;
588
+ heapF32.set(data, index);
589
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").onAudioDataFromJs(ptr, data.length);
590
+ }
591
+ catch { }
592
+ };
593
+ this.malloc = (size) => {
594
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
595
+ return __classPrivateFieldGet(this, _WasmEngine_instance, "f")._malloc(size);
596
+ };
597
+ this.free = (ptr) => {
598
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
599
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f")._free(ptr);
600
+ };
601
+ _WasmEngine_ensureInitialized.set(this, () => {
602
+ if (!__classPrivateFieldGet(this, _WasmEngine_initialized, "f") || !__classPrivateFieldGet(this, _WasmEngine_instance, "f")) {
603
+ throw new Error("WasmEngine not initialized. Call initialize() first.");
604
+ }
605
+ });
606
+ _WasmEngine_makeStringList.set(this, (arr) => {
607
+ const list = new (__classPrivateFieldGet(this, _WasmEngine_instance, "f").StringList)();
608
+ for (const v of arr)
609
+ list.push_back(v);
610
+ return list;
611
+ });
612
+ _WasmEngine_createUint8List.set(this, (data) => {
613
+ if (!__classPrivateFieldGet(this, _WasmEngine_instance, "f")?.Uint8List)
614
+ return null;
615
+ const list = new (__classPrivateFieldGet(this, _WasmEngine_instance, "f").Uint8List)();
616
+ if (data)
617
+ data.forEach((byte) => list.push_back(byte));
618
+ return list;
619
+ });
620
+ _WasmEngine_startAudioPlaybackLoop.set(this, () => {
621
+ if (__classPrivateFieldGet(this, _WasmEngine_audioPlaybackLoopInterval, "f"))
622
+ return;
623
+ __classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
624
+ __classPrivateFieldSet(this, _WasmEngine_isPlaybackActive, true, "f");
625
+ if (typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").requestAudioDataFromWasmVoip !== "function")
626
+ return;
627
+ const framesPerChunk = 320;
628
+ const bufferSize = framesPerChunk * 4;
629
+ try {
630
+ const _malloc = __classPrivateFieldGet(this, _WasmEngine_instance, "f")._malloc ?? __classPrivateFieldGet(this, _WasmEngine_instance, "f").malloc;
631
+ if (!_malloc)
632
+ return;
633
+ __classPrivateFieldSet(this, _WasmEngine_audioPlaybackBuffer, _malloc(bufferSize), "f");
634
+ }
635
+ catch {
636
+ return;
637
+ }
638
+ if (!__classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f") || __classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f") <= 0)
639
+ return;
640
+ __classPrivateFieldSet(this, _WasmEngine_audioPlaybackLoopInterval, setInterval(() => {
641
+ if (!__classPrivateFieldGet(this, _WasmEngine_isPlaybackActive, "f") || !__classPrivateFieldGet(this, _WasmEngine_instance, "f") || !__classPrivateFieldGet(this, _WasmEngine_initialized, "f")) {
642
+ __classPrivateFieldGet(this, _WasmEngine_stopAudioPlaybackLoop, "f").call(this);
643
+ return;
644
+ }
645
+ try {
646
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f").requestAudioDataFromWasmVoip(__classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f"), bufferSize);
647
+ const heapF32 = __classPrivateFieldGet(this, _WasmEngine_instance, "f").GROWABLE_HEAP_F32?.();
648
+ if (!heapF32)
649
+ return;
650
+ const index = Math.floor(__classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f") / 4);
651
+ const numFloats = Math.floor(bufferSize / 4);
652
+ if (index < 0 || index + numFloats > heapF32.length)
653
+ return;
654
+ const audioData = new Float32Array(heapF32.buffer, heapF32.byteOffset + index * 4, numFloats);
655
+ const hasNonZero = audioData.some((s) => Math.abs(s) > 0.0001);
656
+ if (hasNonZero)
657
+ __classPrivateFieldGet(this, _WasmEngine_config, "f").callbacks?.onAudioPlaybackData?.(audioData);
658
+ }
659
+ catch { }
660
+ }, 16), "f");
661
+ });
662
+ _WasmEngine_stopAudioPlaybackLoop.set(this, () => {
663
+ __classPrivateFieldSet(this, _WasmEngine_isPlaybackActive, false, "f");
664
+ if (__classPrivateFieldGet(this, _WasmEngine_audioPlaybackLoopInterval, "f")) {
665
+ clearInterval(__classPrivateFieldGet(this, _WasmEngine_audioPlaybackLoopInterval, "f"));
666
+ __classPrivateFieldSet(this, _WasmEngine_audioPlaybackLoopInterval, null, "f");
667
+ }
668
+ if (__classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f") && __classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f") > 0) {
669
+ try {
670
+ __classPrivateFieldGet(this, _WasmEngine_instance, "f")?._free?.(__classPrivateFieldGet(this, _WasmEngine_audioPlaybackBuffer, "f"));
671
+ }
672
+ catch { }
673
+ __classPrivateFieldSet(this, _WasmEngine_audioPlaybackBuffer, null, "f");
674
+ }
675
+ });
676
+ _WasmEngine_applyDefaultAbProps.set(this, () => {
677
+ if (!__classPrivateFieldGet(this, _WasmEngine_instance, "f"))
678
+ return;
679
+ const setInt = typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropInt === "function"
680
+ ? (k, v) => { __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropInt(k, v); }
681
+ : null;
682
+ const setBool = typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropBool === "function"
683
+ ? (k, v) => { __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropBool(k, v); }
684
+ : null;
685
+ const setString = typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropString === "function"
686
+ ? (k, v) => { __classPrivateFieldGet(this, _WasmEngine_instance, "f").setABPropString(k, v); }
687
+ : null;
688
+ if (!setInt && !setBool && !setString)
689
+ return;
690
+ const opts = __classPrivateFieldGet(this, _WasmEngine_config, "f").options ?? {};
691
+ const intProps = {
692
+ heartbeat_interval_s: opts.heartbeatInterval ?? 30,
693
+ lobby_timeout_min: opts.lobbyTimeout ?? 1,
694
+ max_num_participants_for_ss: opts.maxParticipantsScreenShare ?? 32,
695
+ max_group_size_for_long_ringtone: opts.maxGroupSizeLongRingtone ?? 32,
696
+ app_exit_reason_version: 1,
697
+ log_level: opts.logLevel ?? 3,
698
+ calling_rust_migration_bitmap: 0,
699
+ calling_rust_migration_incoming_stanza_bitmap: 0,
700
+ default_endpoint_thread_poll_timeout: 0,
701
+ aigc_version: 0,
702
+ call_admin_version: 0,
703
+ vid_stream_pause_resume_jb_reset_threshold_ms: 0,
704
+ opus_max_bandwidth: 1103, // OPUS_BANDWIDTH_WIDEBAND
705
+ };
706
+ const boolProps = {
707
+ enable_av_downgrade: false,
708
+ enable_new_user_action_stanza_for_raise_hand_sender: false,
709
+ enable_webcodec_video_encode: false,
710
+ enable_init_bwe_for_group_call: false,
711
+ enable_ring_for_gc_on_offer_expire: false,
712
+ allow_reporting_call_replayer_id: false,
713
+ enable_offer_v2_upgrade: false,
714
+ enable_silent_offer: false,
715
+ voice_ai_conversation_starter_latency_tracking: false,
716
+ enable_waiting_room_logging: false,
717
+ attach_transport_rtx: false,
718
+ ignore_joinable_terminate_on_expired_offer: false,
719
+ enable_passthrough_video_decoder: false,
720
+ };
721
+ for (const [key, value] of Object.entries(intProps)) {
722
+ if (setInt && Number.isFinite(value))
723
+ try {
724
+ setInt(key, value);
725
+ }
726
+ catch { }
727
+ }
728
+ for (const [key, value] of Object.entries(boolProps)) {
729
+ if (setBool)
730
+ try {
731
+ setBool(key, value);
732
+ }
733
+ catch { }
734
+ }
735
+ const overrideProps = parseJsonObjectEnv(CALL_WASM_AB_PROPS_JSON);
736
+ for (const [key, value] of Object.entries(overrideProps)) {
737
+ try {
738
+ if (typeof value === "boolean" && setBool)
739
+ setBool(key, value);
740
+ else if (typeof value === "number" && setInt)
741
+ setInt(key, value);
742
+ else if (typeof value === "string" && setString)
743
+ setString(key, value);
744
+ }
745
+ catch { }
746
+ }
747
+ });
748
+ _WasmEngine_allocateUnusedWorker.set(this, () => {
749
+ const workerScriptPath = resolveWorkerScriptPath();
750
+ if (!fs.existsSync(workerScriptPath))
751
+ return;
752
+ try {
753
+ const worker = new Worker(workerScriptPath, {
754
+ stdout: true, stderr: true,
755
+ workerData: {
756
+ wasmPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath,
757
+ wasmBinary: __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary,
758
+ workerModulesCode: __classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f"),
759
+ loaderCode: __classPrivateFieldGet(this, _WasmEngine_loaderCode, "f"),
760
+ loaderModuleName: __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderModuleName,
761
+ resourcesPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath,
762
+ storageDir: __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir,
763
+ enableLogs: __classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs,
764
+ },
765
+ });
766
+ const port = new NodeWorkerMessagePort(worker, "WAWebVoipWebWasmWorker");
767
+ worker.stdout?.on("data", () => { }); // suppress noisy worker stdout
768
+ worker.stderr?.on("data", filterWorkerStderr);
769
+ __classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").push(port);
770
+ }
771
+ catch { }
772
+ });
773
+ _WasmEngine_initPThreadPool.set(this, async () => {
774
+ for (let i = 0; i < PTHREAD_POOL_SIZE; i += 1)
775
+ __classPrivateFieldGet(this, _WasmEngine_allocateUnusedWorker, "f").call(this);
776
+ });
777
+ _WasmEngine_loadWasmModuleToWorker.set(this, (worker) => new Promise((resolve) => {
778
+ var _b, _c;
779
+ const loadedHandler = (msg) => {
780
+ if (msg && msg.cmd === "loaded") {
781
+ worker.removeMessageListener("cmd", loadedHandler);
782
+ __classPrivateFieldSet(this, _WasmEngine_workersLoadedCount, __classPrivateFieldGet(this, _WasmEngine_workersLoadedCount, "f") + 1, "f");
783
+ if (__classPrivateFieldGet(this, _WasmEngine_workersLoadedCount, "f") >= PTHREAD_POOL_SIZE && __classPrivateFieldGet(this, _WasmEngine_removeRunDependencyCallback, "f")) {
784
+ __classPrivateFieldGet(this, _WasmEngine_removeRunDependencyCallback, "f").call(this, "loading-workers");
785
+ }
786
+ resolve();
787
+ }
788
+ };
789
+ worker.addMessageListener("cmd", loadedHandler);
790
+ worker.workerID = (__classPrivateFieldSet(this, _WasmEngine_nextWorkerID, (_c = __classPrivateFieldGet(this, _WasmEngine_nextWorkerID, "f"), _b = _c++, _c), "f"), _b);
791
+ worker.postMessage({
792
+ cmd: "load", type: "cmd",
793
+ wasmMemory: __classPrivateFieldGet(this, _WasmEngine_wasmMemory, "f"),
794
+ wasmModule: __classPrivateFieldGet(this, _WasmEngine_wasmModule, "f"),
795
+ workerID: worker.workerID,
796
+ handlers: [],
797
+ });
798
+ }));
799
+ _WasmEngine_loadWasmModuleToAllWorkers.set(this, async () => {
800
+ __classPrivateFieldSet(this, _WasmEngine_workersLoadedCount, 0, "f");
801
+ await Promise.all(__classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").map((w) => __classPrivateFieldGet(this, _WasmEngine_loadWasmModuleToWorker, "f").call(this, w)));
802
+ });
803
+ _WasmEngine_registerGlobalCallbacks.set(this, () => {
804
+ const callbacks = __classPrivateFieldGet(this, _WasmEngine_config, "f").callbacks ?? {};
805
+ _a.registerGlobalCallbackListener("loggingCallback", (data) => {
806
+ if (!__classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs)
807
+ return;
808
+ const level = data?.level;
809
+ const msg = data?.message ?? "";
810
+ const mapped = level === 1 ? "error" : level === 2 ? "warn" : level === 3 ? "log" : "debug";
811
+ callbacks.onLog?.(mapped, msg);
812
+ });
813
+ if (callbacks.onAudioCaptureInit) {
814
+ _a.registerGlobalCallbackListener("initCaptureDriverJS", (data) => {
815
+ callbacks.onAudioCaptureInit({
816
+ sampleRate: data?.sample_rate ?? data?.sampleRate,
817
+ channels: data?.channels,
818
+ bitsPerSample: data?.bits_per_sample ?? data?.bitsPerSample,
819
+ framesPerChunk: data?.frames_per_chunk ?? data?.framesPerChunk,
820
+ });
821
+ });
822
+ }
823
+ _a.registerGlobalCallbackListener("startVideoCaptureJS", (data) => callbacks.onVideoCaptureStart?.(normalizeVideoCaptureConfig(data)));
824
+ _a.registerGlobalCallbackListener("stopVideoCaptureJS", () => callbacks.onVideoCaptureStop?.());
825
+ _a.registerGlobalCallbackListener("videoFrameConsumed", () => callbacks.onVideoFrameConsumed?.());
826
+ _a.registerGlobalCallbackListener("startDesktopCaptureJS", (data) => callbacks.onDesktopCaptureStart?.(normalizeVideoCaptureConfig(data)));
827
+ _a.registerGlobalCallbackListener("stopDesktopCaptureJS", () => callbacks.onDesktopCaptureStop?.());
828
+ _a.registerGlobalCallbackListener("startCaptureJS", () => callbacks.onAudioCaptureStart?.());
829
+ _a.registerGlobalCallbackListener("stopCaptureJS", () => callbacks.onAudioCaptureStop?.());
830
+ if (callbacks.onAudioPlaybackInit) {
831
+ _a.registerGlobalCallbackListener("initPlaybackDriverJS", (data) => {
832
+ callbacks.onAudioPlaybackInit({
833
+ sampleRate: data?.sample_rate ?? data?.sampleRate,
834
+ channels: data?.channels,
835
+ bitsPerSample: data?.bits_per_sample ?? data?.bitsPerSample,
836
+ framesPerChunk: data?.frames_per_chunk ?? data?.framesPerChunk,
837
+ });
838
+ });
839
+ }
840
+ _a.registerGlobalCallbackListener("startPlaybackJS", () => {
841
+ callbacks.onAudioPlaybackStart?.();
842
+ __classPrivateFieldGet(this, _WasmEngine_startAudioPlaybackLoop, "f").call(this);
843
+ });
844
+ _a.registerGlobalCallbackListener("stopPlaybackJS", () => {
845
+ __classPrivateFieldGet(this, _WasmEngine_stopAudioPlaybackLoop, "f").call(this);
846
+ callbacks.onAudioPlaybackStop?.();
847
+ });
848
+ if (callbacks.onSignalingXmpp) {
849
+ _a.registerGlobalCallbackListener("onSignalingXmpp", (data) => {
850
+ const peerJid = data.peerJid ?? data.args?.peerJid;
851
+ const callId = data.callId ?? data.args?.callId;
852
+ let xmlPayload = data.xmlPayload ?? data.args?.xmlPayload;
853
+ if (Array.isArray(xmlPayload))
854
+ xmlPayload = new Uint8Array(xmlPayload);
855
+ else if (xmlPayload && typeof xmlPayload === "object" &&
856
+ !(xmlPayload instanceof Uint8Array) && !Buffer.isBuffer(xmlPayload)) {
857
+ xmlPayload = new Uint8Array(xmlPayload);
858
+ }
859
+ callbacks.onSignalingXmpp(peerJid, callId, xmlPayload);
860
+ });
861
+ }
862
+ if (callbacks.onCallEvent) {
863
+ _a.registerGlobalCallbackListener("onCallEvent", (data) => {
864
+ callbacks.onCallEvent(data.eventType, data.eventDataJson);
865
+ });
866
+ }
867
+ if (callbacks.sendDataToRelay) {
868
+ _a.registerGlobalCallbackListener("sendDataToRelay", (data) => {
869
+ let relayData = data.data ?? data.args?.data;
870
+ const ip = data.ip ?? data.args?.ip;
871
+ const portNum = data.port ?? data.args?.port;
872
+ if (relayData instanceof Uint8Array) { /* ok */ }
873
+ else if (Array.isArray(relayData))
874
+ relayData = new Uint8Array(relayData);
875
+ else if (Buffer.isBuffer(relayData))
876
+ relayData = new Uint8Array(relayData);
877
+ else if (relayData && typeof relayData === "object" && relayData.buffer) {
878
+ relayData = new Uint8Array(relayData.buffer, relayData.byteOffset ?? 0, relayData.byteLength ?? relayData.length);
879
+ }
880
+ else if (relayData instanceof ArrayBuffer)
881
+ relayData = new Uint8Array(relayData);
882
+ else
883
+ return 0;
884
+ if (!ip || !portNum)
885
+ return 0;
886
+ callbacks.sendDataToRelay(relayData, ip, portNum);
887
+ return relayData.byteLength;
888
+ });
889
+ }
890
+ __classPrivateFieldSet(_a, _a, true, "f", _WasmEngine_globalCallbacksRegistered);
891
+ });
892
+ _WasmEngine_requireModule.set(this, (name) => {
893
+ const preDefinedModules = {
894
+ Promise,
895
+ WAWebVoipWebWasmWorkerResource: {
896
+ resourcePath: resolveWorkerScriptPath(),
897
+ name: "WAWebVoipWebWasmWorker",
898
+ },
899
+ WorkerBundleResource: {
900
+ createDedicatedWebWorker: (resource) => {
901
+ const scriptPath = resource?.resourcePath && fs.existsSync(resource.resourcePath)
902
+ ? resource.resourcePath
903
+ : resolveWorkerScriptPath();
904
+ const worker = new Worker(scriptPath, {
905
+ stdout: true, stderr: true,
906
+ workerData: {
907
+ wasmPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath,
908
+ wasmBinary: __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary,
909
+ workerModulesCode: __classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f"),
910
+ loaderCode: __classPrivateFieldGet(this, _WasmEngine_loaderCode, "f"),
911
+ loaderModuleName: __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderModuleName,
912
+ resourcesPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath,
913
+ storageDir: __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir,
914
+ enableLogs: __classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs,
915
+ },
916
+ });
917
+ worker.stdout?.on("data", () => { });
918
+ worker.stderr?.on("data", filterWorkerStderr);
919
+ __classPrivateFieldGet(this, _WasmEngine_jsWorkers, "f").add(worker);
920
+ worker.on("exit", () => __classPrivateFieldGet(this, _WasmEngine_jsWorkers, "f").delete(worker));
921
+ return worker;
922
+ },
923
+ },
924
+ WorkerClient: { init: () => { } },
925
+ WorkerMessagePort: {
926
+ WorkerMessagePort: NodeWorkerMessagePort,
927
+ CastWorkerMessagePort: (w) => w,
928
+ WorkerSyncedMessagePort: NodeWorkerMessagePort,
929
+ },
930
+ bx: Object.assign((id) => String(id), { getURL: () => "" }),
931
+ HasteSupportData: { handle: () => { } },
932
+ ServiceWorkerDynamicModules: { handle: () => { } },
933
+ WhatsAppWebServiceWorker: { default: true },
934
+ WAWebLogger: { initializeWAWebLogger: () => { } },
935
+ WAWebSw: { initHandlers: () => { } },
936
+ WAWebWamRuntimeProvider: { setWamRuntime: () => { } },
937
+ WAWebWamWorkerInterface: { commit: () => { }, set: () => { } },
938
+ ServerJSDefine: { handleDefine: () => { } },
939
+ ix: { add: () => { } },
940
+ MetaConfigMap: { add: () => { } },
941
+ QPLHasteSupportDataStorage: { default: { add: () => { }, get: () => null } },
942
+ getFalcoLogPolicy_DO_NOT_USE: { add: () => { } },
943
+ gkx: { add: () => { } },
944
+ justknobx: { add: () => { } },
945
+ qex: { add: () => { } },
946
+ };
947
+ if (preDefinedModules[name])
948
+ return preDefinedModules[name];
949
+ const mod = __classPrivateFieldGet(this, _WasmEngine_moduleRegistry, "f").get(name);
950
+ if (!mod)
951
+ return {};
952
+ if (mod.exports !== undefined)
953
+ return mod.exports;
954
+ const requireFn = __classPrivateFieldGet(this, _WasmEngine_requireModule, "f");
955
+ const normalizeModuleResult = (value) => {
956
+ if (value && typeof value === "object" && "exports" in value && Object.keys(value).length === 1) {
957
+ return value.exports;
958
+ }
959
+ return value;
960
+ };
961
+ const importDefaultFn = (dep) => {
962
+ const v = requireFn(dep);
963
+ return v && v.__esModule ? v.default : v;
964
+ };
965
+ const importAllFn = (dep) => {
966
+ const v = requireFn(dep);
967
+ if (v == null)
968
+ return { default: v };
969
+ if (v.__esModule)
970
+ return v;
971
+ if (typeof v !== "object" && typeof v !== "function")
972
+ return { default: v };
973
+ const ns = {};
974
+ for (const key of Object.keys(v))
975
+ ns[key] = v[key];
976
+ ns.default = v;
977
+ return ns;
978
+ };
979
+ const tryMetro = () => {
980
+ const module = { exports: {} };
981
+ mod.factory(__classPrivateFieldGet(this, _WasmEngine_vmContext, "f") ?? globalThis, requireFn, importDefaultFn, importAllFn, null, module, module.exports);
982
+ return normalizeModuleResult(module.exports);
983
+ };
984
+ const tryLegacy = () => {
985
+ const exports = {};
986
+ const module = { exports };
987
+ const resolvedDeps = mod.deps.map((dep) => requireFn(dep));
988
+ mod.factory(__classPrivateFieldGet(this, _WasmEngine_vmContext, "f") ?? globalThis, requireFn, requireFn, requireFn, module, exports, ...resolvedDeps);
989
+ return normalizeModuleResult(module.exports);
990
+ };
991
+ let result = {};
992
+ let metroError = null;
993
+ try {
994
+ result = tryMetro();
995
+ }
996
+ catch (e) {
997
+ metroError = e;
998
+ }
999
+ if (metroError != null || (result && typeof result === "object" && Object.keys(result).length === 0)) {
1000
+ try {
1001
+ const legacyResult = tryLegacy();
1002
+ if (typeof legacyResult === "function" || (legacyResult && Object.keys(legacyResult).length > 0)) {
1003
+ result = legacyResult;
1004
+ }
1005
+ }
1006
+ catch { }
1007
+ }
1008
+ mod.exports = result;
1009
+ return result;
1010
+ });
1011
+ _WasmEngine_createVMContext.set(this, (memory) => {
1012
+ const callbacks = __classPrivateFieldGet(this, _WasmEngine_config, "f").callbacks ?? {};
1013
+ const wasmCallbacks = {
1014
+ onVoipReady: () => {
1015
+ __classPrivateFieldGet(this, _WasmEngine_voipReadyResolver, "f")?.call(this);
1016
+ callbacks.onVoipReady?.();
1017
+ },
1018
+ onSignalingXmpp: (data) => callbacks.onSignalingXmpp?.(data?.peerJid, data?.callId, data?.xmlPayload),
1019
+ onCallEvent: (data) => callbacks.onCallEvent?.(data?.eventType, data?.eventDataJson),
1020
+ sendDataToRelay: (data) => callbacks.sendDataToRelay?.(data?.data, data?.ip, data?.port),
1021
+ loggingCallback: (data) => {
1022
+ if (!__classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs)
1023
+ return;
1024
+ const level = data?.level;
1025
+ const msg = data?.message ?? "";
1026
+ const mapped = level === 1 ? "error" : level === 2 ? "warn" : level === 3 ? "log" : "debug";
1027
+ callbacks.onLog?.(mapped, msg);
1028
+ },
1029
+ initCaptureDriverJS: (data) => {
1030
+ callbacks.onAudioCaptureInit?.({
1031
+ sampleRate: data?.sample_rate, channels: data?.channels,
1032
+ bitsPerSample: data?.bits_per_sample, framesPerChunk: data?.frames_per_chunk,
1033
+ });
1034
+ return 0;
1035
+ },
1036
+ startCaptureJS: () => { callbacks.onAudioCaptureStart?.(); return 0; },
1037
+ stopCaptureJS: () => { callbacks.onAudioCaptureStop?.(); return 0; },
1038
+ initPlaybackDriverJS: (data) => {
1039
+ callbacks.onAudioPlaybackInit?.({
1040
+ sampleRate: data?.sample_rate, channels: data?.channels,
1041
+ bitsPerSample: data?.bits_per_sample, framesPerChunk: data?.frames_per_chunk,
1042
+ });
1043
+ return 0;
1044
+ },
1045
+ startPlaybackJS: () => {
1046
+ callbacks.onAudioPlaybackStart?.();
1047
+ __classPrivateFieldGet(this, _WasmEngine_startAudioPlaybackLoop, "f").call(this);
1048
+ return 0;
1049
+ },
1050
+ stopPlaybackJS: () => {
1051
+ __classPrivateFieldGet(this, _WasmEngine_stopAudioPlaybackLoop, "f").call(this);
1052
+ callbacks.onAudioPlaybackStop?.();
1053
+ return 0;
1054
+ },
1055
+ startVideoCaptureJS: (data) => {
1056
+ callbacks.onVideoCaptureStart?.(normalizeVideoCaptureConfig(data));
1057
+ return 0;
1058
+ },
1059
+ stopVideoCaptureJS: () => {
1060
+ callbacks.onVideoCaptureStop?.();
1061
+ return 0;
1062
+ },
1063
+ startDesktopCaptureJS: (data) => {
1064
+ callbacks.onDesktopCaptureStart?.(normalizeVideoCaptureConfig(data));
1065
+ return 0;
1066
+ },
1067
+ stopDesktopCaptureJS: () => {
1068
+ callbacks.onDesktopCaptureStop?.();
1069
+ return 0;
1070
+ },
1071
+ dataChannelStateCallback: () => 0,
1072
+ getBrowserAudioProcessingStatus: () => 7,
1073
+ getBweModelPath: () => null,
1074
+ videoFrameConsumed: () => {
1075
+ callbacks.onVideoFrameConsumed?.();
1076
+ return 0;
1077
+ },
1078
+ cryptoHkdfExtractWithSaltAndExpand: (data) => {
1079
+ const key = toByteArray(data?.key_);
1080
+ const salt = data?.salt_ ? toByteArray(data.salt_) : new Uint8Array(0);
1081
+ const info = toByteArray(data?.info_);
1082
+ const length = data?.length ?? 32;
1083
+ return callbacks.cryptoHkdf?.(key, salt, info, length) ?? new Uint8Array(length);
1084
+ },
1085
+ hmacSha256KeyGenerator: (data) => {
1086
+ const hmacData = new Uint8Array(data?.data_ ?? []);
1087
+ const hmacKey = new Uint8Array(data?.key_ ?? []);
1088
+ return callbacks.hmacSha256?.(hmacData, hmacKey) ?? new Uint8Array(32);
1089
+ },
1090
+ isParticipantKnownContact: () => true,
1091
+ getPersistentDirectoryPath: () => {
1092
+ const dir = __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir;
1093
+ try {
1094
+ if (!fs.existsSync(dir))
1095
+ fs.mkdirSync(dir, { recursive: true });
1096
+ }
1097
+ catch { }
1098
+ return dir;
1099
+ },
1100
+ };
1101
+ const __d = (name, deps, factory) => {
1102
+ __classPrivateFieldGet(this, _WasmEngine_moduleRegistry, "f").set(name, { deps, factory, exports: undefined });
1103
+ };
1104
+ const babelHelpers = {
1105
+ extends: Object.assign,
1106
+ inheritsLoose: (sub, sup) => {
1107
+ sub.prototype = Object.create(sup.prototype);
1108
+ sub.prototype.constructor = sub;
1109
+ sub.__proto__ = sup;
1110
+ },
1111
+ objectWithoutPropertiesLoose: (source, excluded) => {
1112
+ if (source == null)
1113
+ return {};
1114
+ const target = {};
1115
+ for (const key of Object.keys(source)) {
1116
+ if (excluded.indexOf(key) >= 0)
1117
+ continue;
1118
+ target[key] = source[key];
1119
+ }
1120
+ return target;
1121
+ },
1122
+ taggedTemplateLiteralLoose: (strings, raw) => {
1123
+ if (!raw)
1124
+ raw = strings.slice(0);
1125
+ strings.raw = raw;
1126
+ return strings;
1127
+ },
1128
+ wrapNativeSuper: (Class) => Class,
1129
+ };
1130
+ const addRunDependency = (dep) => {
1131
+ if (dep === "loading-workers" && __classPrivateFieldGet(this, _WasmEngine_workersLoadedCount, "f") >= PTHREAD_POOL_SIZE) {
1132
+ setImmediate(() => __classPrivateFieldGet(this, _WasmEngine_removeRunDependencyCallback, "f")?.call(this, dep));
1133
+ }
1134
+ };
1135
+ const removeRunDependency = (_dep) => { };
1136
+ __classPrivateFieldSet(this, _WasmEngine_removeRunDependencyCallback, removeRunDependency, "f");
1137
+ const webCrypto = {
1138
+ getRandomValues: (arr) => {
1139
+ if (!arr || !ArrayBuffer.isView(arr)) {
1140
+ throw new TypeError("crypto.getRandomValues expects a TypedArray");
1141
+ }
1142
+ const bytes = Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
1143
+ randomFillSync(bytes);
1144
+ return arr;
1145
+ },
1146
+ };
1147
+ const selfObj = {
1148
+ __swData: { dynamic_data: { hsdp: {}, dynamic_modules: [] } },
1149
+ WhatsAppVoipWasmCallbacks: wasmCallbacks,
1150
+ WhatsAppVoipWasmWorkerCompatibleCallbacks: wasmCallbacks,
1151
+ crypto: webCrypto,
1152
+ };
1153
+ selfObj.self = selfObj;
1154
+ selfObj.window = selfObj;
1155
+ selfObj.globalThis = selfObj;
1156
+ if (typeof global !== "undefined") {
1157
+ global.WhatsAppVoipWasmCallbacks = wasmCallbacks;
1158
+ global.WhatsAppVoipWasmWorkerCompatibleCallbacks = wasmCallbacks;
1159
+ }
1160
+ const context = vm.createContext({
1161
+ self: selfObj, globalThis: selfObj, global: selfObj, window: selfObj,
1162
+ console, setTimeout, setInterval, clearTimeout, clearInterval,
1163
+ queueMicrotask, performance, babelHelpers, __d,
1164
+ require: __classPrivateFieldGet(this, _WasmEngine_requireModule, "f"),
1165
+ addRunDependency, removeRunDependency,
1166
+ WebAssembly, SharedArrayBuffer,
1167
+ Atomics: __classPrivateFieldGet(this, _WasmEngine_createAtomicsWrapper, "f").call(this, memory),
1168
+ Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array,
1169
+ Float32Array, Float64Array, BigInt64Array, BigUint64Array,
1170
+ ArrayBuffer, DataView, Error, TypeError, RangeError, Promise,
1171
+ Map, Set, WeakMap, WeakSet, Symbol, Object, Array, String, Number,
1172
+ Boolean, Math, Date, JSON, RegExp, Function, Proxy, Reflect,
1173
+ crypto: webCrypto,
1174
+ WhatsAppVoipWasmCallbacks: wasmCallbacks,
1175
+ WhatsAppVoipWasmWorkerCompatibleCallbacks: wasmCallbacks,
1176
+ navigator: {
1177
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
1178
+ hardwareConcurrency: 4,
1179
+ },
1180
+ process: undefined,
1181
+ document: { currentScript: null },
1182
+ location: { href: "file:///wasm" },
1183
+ Worker: class {
1184
+ constructor() { }
1185
+ postMessage() { }
1186
+ terminate() { }
1187
+ addEventListener() { }
1188
+ },
1189
+ fetch: async () => { throw new Error("fetch not supported"); },
1190
+ XMLHttpRequest: class {
1191
+ open() { }
1192
+ send() { }
1193
+ setRequestHeader() { }
1194
+ },
1195
+ Blob: class {
1196
+ constructor() { }
1197
+ },
1198
+ URL: { createObjectURL: () => "blob:fake", revokeObjectURL: () => { } },
1199
+ Image: class {
1200
+ constructor() {
1201
+ this.src = "";
1202
+ this.onload = null;
1203
+ this.onerror = null;
1204
+ }
1205
+ },
1206
+ Audio: class {
1207
+ constructor() {
1208
+ this.src = "";
1209
+ }
1210
+ addEventListener() { }
1211
+ },
1212
+ __NODE_PTHREAD: {
1213
+ getUnusedWorker: () => {
1214
+ if (__classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").length === 0)
1215
+ return null;
1216
+ const worker = __classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").pop();
1217
+ __classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f").push(worker);
1218
+ return worker;
1219
+ },
1220
+ returnWorkerToPool: (worker) => {
1221
+ const idx = __classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f").indexOf(worker);
1222
+ if (idx >= 0) {
1223
+ __classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f").splice(idx, 1);
1224
+ __classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").push(worker);
1225
+ }
1226
+ },
1227
+ spawnThread: (params) => {
1228
+ const worker = __classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").pop();
1229
+ if (!worker)
1230
+ return 6;
1231
+ __classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f").push(worker);
1232
+ __classPrivateFieldGet(this, _WasmEngine_pthreads, "f")[params.pthread_ptr] = worker;
1233
+ worker.pthread_ptr = params.pthread_ptr;
1234
+ const pthreadTable = __classPrivateFieldGet(this, _WasmEngine_instance, "f")?.PThread?.pthreads;
1235
+ if (pthreadTable)
1236
+ pthreadTable[params.pthread_ptr] = worker;
1237
+ worker.postMessage({
1238
+ cmd: "run",
1239
+ start_routine: params.startRoutine,
1240
+ arg: params.arg,
1241
+ pthread_ptr: params.pthread_ptr,
1242
+ });
1243
+ return 0;
1244
+ },
1245
+ unusedWorkersCount: () => __classPrivateFieldGet(this, _WasmEngine_unusedWorkers, "f").length,
1246
+ runningWorkersCount: () => __classPrivateFieldGet(this, _WasmEngine_runningWorkers, "f").length,
1247
+ },
1248
+ __IS_NODE_PTHREAD_ENV: true,
1249
+ });
1250
+ context.self = context;
1251
+ context.globalThis = context;
1252
+ context.global = context;
1253
+ context.window = context;
1254
+ return context;
1255
+ });
1256
+ _WasmEngine_createAtomicsWrapper.set(this, (_memory) => {
1257
+ const atomicsWrapper = {
1258
+ add: Atomics.add.bind(Atomics),
1259
+ and: Atomics.and.bind(Atomics),
1260
+ compareExchange: Atomics.compareExchange.bind(Atomics),
1261
+ exchange: Atomics.exchange.bind(Atomics),
1262
+ isLockFree: Atomics.isLockFree.bind(Atomics),
1263
+ load: Atomics.load.bind(Atomics),
1264
+ or: Atomics.or.bind(Atomics),
1265
+ store: Atomics.store.bind(Atomics),
1266
+ sub: Atomics.sub.bind(Atomics),
1267
+ xor: Atomics.xor.bind(Atomics),
1268
+ notify: (typedArray, index, count) => {
1269
+ try {
1270
+ return Atomics.notify(typedArray, index, count);
1271
+ }
1272
+ catch (e) {
1273
+ if (e?.message?.includes("futex_wake") || e?.message?.includes("main_browser_thread"))
1274
+ return 0;
1275
+ throw e;
1276
+ }
1277
+ },
1278
+ waitAsync: Atomics.waitAsync
1279
+ ? Atomics.waitAsync.bind(Atomics)
1280
+ : () => ({ async: true, value: Promise.resolve("ok") }),
1281
+ wait: (typedArray, index, value, timeout) => {
1282
+ const currentValue = Atomics.load(typedArray, index);
1283
+ if (currentValue !== value)
1284
+ return "not-equal";
1285
+ if (timeout !== undefined && timeout <= 0)
1286
+ return "timed-out";
1287
+ return "timed-out";
1288
+ },
1289
+ [Symbol.toStringTag]: "Atomics",
1290
+ };
1291
+ return atomicsWrapper;
1292
+ });
1293
+ const candidateBases = [
1294
+ config.resourcesPath ? (path.isAbsolute(config.resourcesPath) ? config.resourcesPath : path.resolve(process.cwd(), config.resourcesPath)) : null,
1295
+ path.resolve(currentDir, ".."),
1296
+ path.resolve(currentDir, "../../src"),
1297
+ path.resolve(currentDir, "../../lib"),
1298
+ path.resolve(process.cwd(), "src"),
1299
+ path.resolve(process.cwd(), "lib"),
1300
+ process.cwd()
1301
+ ].filter(Boolean);
1302
+ let basePath = path.resolve(currentDir, "..");
1303
+ for (const candidate of candidateBases) {
1304
+ if (fs.existsSync(path.join(candidate, "assets", "wasm", "whatsapp.wasm"))) {
1305
+ basePath = candidate;
1306
+ break;
1307
+ }
1308
+ }
1309
+ let wasmPath = config.wasmPath
1310
+ ? (path.isAbsolute(config.wasmPath) ? config.wasmPath : path.resolve(process.cwd(), config.wasmPath))
1311
+ : path.join(basePath, "assets", "wasm", "whatsapp.wasm");
1312
+ if (!fs.existsSync(wasmPath)) {
1313
+ for (const candidate of candidateBases) {
1314
+ const alt = path.join(candidate, "assets", "wasm", "whatsapp.wasm");
1315
+ if (fs.existsSync(alt)) {
1316
+ wasmPath = alt;
1317
+ basePath = candidate;
1318
+ break;
1319
+ }
1320
+ }
1321
+ }
1322
+ __classPrivateFieldSet(this, _WasmEngine_config, {
1323
+ ...config,
1324
+ storageDir: config.storageDir
1325
+ ? (path.isAbsolute(config.storageDir) ? config.storageDir : path.resolve(process.cwd(), config.storageDir))
1326
+ : path.join(tmpdir(), "elaina-voip"),
1327
+ wasmPath,
1328
+ resourcesPath: basePath,
1329
+ enableLogs: config.enableLogs ?? true,
1330
+ options: {
1331
+ heartbeatInterval: 30,
1332
+ lobbyTimeout: 1,
1333
+ maxParticipantsScreenShare: 32,
1334
+ maxGroupSizeLongRingtone: 32,
1335
+ ...config.options,
1336
+ },
1337
+ }, "f");
1338
+ }
1339
+ }
1340
+ _a = WasmEngine, _WasmEngine_jsWorkers = new WeakMap(), _WasmEngine_config = new WeakMap(), _WasmEngine_instance = new WeakMap(), _WasmEngine_initialized = new WeakMap(), _WasmEngine_moduleRegistry = new WeakMap(), _WasmEngine_vmContext = new WeakMap(), _WasmEngine_unusedWorkers = new WeakMap(), _WasmEngine_runningWorkers = new WeakMap(), _WasmEngine_pthreads = new WeakMap(), _WasmEngine_nextWorkerID = new WeakMap(), _WasmEngine_wasmModule = new WeakMap(), _WasmEngine_wasmMemory = new WeakMap(), _WasmEngine_removeRunDependencyCallback = new WeakMap(), _WasmEngine_workersLoadedCount = new WeakMap(), _WasmEngine_audioPlaybackLoopInterval = new WeakMap(), _WasmEngine_audioPlaybackBuffer = new WeakMap(), _WasmEngine_isPlaybackActive = new WeakMap(), _WasmEngine_voipStackInitialized = new WeakMap(), _WasmEngine_voipStackInitPromise = new WeakMap(), _WasmEngine_voipReadyResolver = new WeakMap(), _WasmEngine_voipReadyPromise = new WeakMap(), _WasmEngine_workerModulesCode = new WeakMap(), _WasmEngine_loaderCode = new WeakMap(), _WasmEngine_ensureInitialized = new WeakMap(), _WasmEngine_makeStringList = new WeakMap(), _WasmEngine_createUint8List = new WeakMap(), _WasmEngine_startAudioPlaybackLoop = new WeakMap(), _WasmEngine_stopAudioPlaybackLoop = new WeakMap(), _WasmEngine_applyDefaultAbProps = new WeakMap(), _WasmEngine_allocateUnusedWorker = new WeakMap(), _WasmEngine_initPThreadPool = new WeakMap(), _WasmEngine_loadWasmModuleToWorker = new WeakMap(), _WasmEngine_loadWasmModuleToAllWorkers = new WeakMap(), _WasmEngine_registerGlobalCallbacks = new WeakMap(), _WasmEngine_requireModule = new WeakMap(), _WasmEngine_createVMContext = new WeakMap(), _WasmEngine_createAtomicsWrapper = new WeakMap();
1341
+ _WasmEngine_globalCallbackListeners = { value: new Map() };
1342
+ _WasmEngine_globalCallbacksRegistered = { value: false };
1343
+ WasmEngine.registerGlobalCallbackListener = (callbackName, handler) => {
1344
+ const key = `callback:${callbackName}`;
1345
+ let set = __classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).get(key);
1346
+ if (!set) {
1347
+ set = new Set();
1348
+ __classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).set(key, set);
1349
+ }
1350
+ set.add(handler);
1351
+ };
1352
+ WasmEngine.notifyGlobalCallbackListeners = (callbackName, data) => {
1353
+ const set = __classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).get(`callback:${callbackName}`);
1354
+ if (!set)
1355
+ return;
1356
+ for (const handler of set) {
1357
+ try {
1358
+ handler(data);
1359
+ }
1360
+ catch { }
1361
+ }
1362
+ };
1363
+ export default WasmEngine;
1364
+ //# sourceMappingURL=wasm-engine.js.map