amiudmodz 6.2.7 → 6.3.0
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.
- package/lib/Socket/business.d.ts +6 -1
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/communities.d.ts +6 -1
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +17 -4
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +6 -1
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-send.d.ts +6 -1
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +85 -21
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +4 -5
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Utils/baileys-event-stream.js +0 -0
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js +6 -7
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/VoIP/audio-feeder.d.ts +42 -4
- package/lib/VoIP/audio-feeder.d.ts.map +1 -1
- package/lib/VoIP/audio-feeder.js +252 -128
- package/lib/VoIP/audio-feeder.js.map +1 -1
- package/lib/VoIP/index.d.ts +91 -8
- package/lib/VoIP/index.d.ts.map +1 -1
- package/lib/VoIP/index.js +834 -184
- package/lib/VoIP/index.js.map +1 -1
- package/lib/VoIP/relay-transport.d.ts +26 -1
- package/lib/VoIP/relay-transport.d.ts.map +1 -1
- package/lib/VoIP/relay-transport.js +257 -181
- package/lib/VoIP/relay-transport.js.map +1 -1
- package/lib/VoIP/signaling.d.ts +57 -3
- package/lib/VoIP/signaling.d.ts.map +1 -1
- package/lib/VoIP/signaling.js +791 -328
- package/lib/VoIP/signaling.js.map +1 -1
- package/lib/VoIP/types.d.ts +12 -11
- package/lib/VoIP/types.d.ts.map +1 -1
- package/lib/VoIP/types.js +4 -9
- package/lib/VoIP/types.js.map +1 -1
- package/lib/VoIP/video-feeder.d.ts +53 -0
- package/lib/VoIP/video-feeder.d.ts.map +1 -0
- package/lib/VoIP/video-feeder.js +269 -0
- package/lib/VoIP/video-feeder.js.map +1 -0
- package/lib/VoIP/wasm-engine.d.ts +10 -2
- package/lib/VoIP/wasm-engine.d.ts.map +1 -1
- package/lib/VoIP/wasm-engine.js +179 -71
- package/lib/VoIP/wasm-engine.js.map +1 -1
- package/lib/VoIP/worker-bootstrap.js +29 -51
- package/lib/VoIP/worker-bootstrap.js.map +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/decode.js +10 -0
- package/lib/WABinary/decode.js.map +1 -1
- package/lib/WABinary/encode.d.ts.map +1 -1
- package/lib/WABinary/encode.js +10 -0
- package/lib/WABinary/encode.js.map +1 -1
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +18 -17
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/assets/wasm/README.md +76 -0
- package/lib/assets/wasm/loader.js +0 -1
- package/lib/assets/wasm/loader.js.map +1 -1
- package/lib/assets/wasm/worker-modules.js +0 -1
- package/lib/assets/wasm/worker-modules.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +146 -142
package/lib/VoIP/wasm-engine.js
CHANGED
|
@@ -9,25 +9,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _NodeWorkerMessagePort_listeners, _NodeWorkerMessagePort_worker, _NodeWorkerMessagePort_handleMessage,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @author ShellTear
|
|
22
|
-
*/
|
|
23
|
-
import * as vm from "node:vm";
|
|
24
|
-
import * as fs from "node:fs";
|
|
25
|
-
import * as path from "node:path";
|
|
26
|
-
import { randomFillSync } from "node:crypto";
|
|
27
|
-
import { Worker } from "node:worker_threads";
|
|
28
|
-
import { fileURLToPath } from "node:url";
|
|
29
|
-
const WASM_FILE_PATH = fileURLToPath(import.meta.url);
|
|
30
|
-
const WASM_DIR_PATH = path.dirname(WASM_FILE_PATH);
|
|
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));
|
|
31
21
|
const CALL_WASM_AB_PROPS_JSON = process.env.CALL_WASM_AB_PROPS_JSON ?? "";
|
|
32
22
|
const PTHREAD_POOL_SIZE = 20;
|
|
33
23
|
const VOIP_READY_TIMEOUT_MS = 15000;
|
|
@@ -67,9 +57,15 @@ const filterWorkerStderr = (chunk) => {
|
|
|
67
57
|
process.stderr.write(chunk);
|
|
68
58
|
}
|
|
69
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
|
+
});
|
|
70
66
|
const resolveWorkerScriptPath = () => {
|
|
71
|
-
const compiled = path.join(
|
|
72
|
-
return fs.existsSync(compiled) ? compiled : path.join(
|
|
67
|
+
const compiled = path.join(currentDir, "worker-bootstrap.js");
|
|
68
|
+
return fs.existsSync(compiled) ? compiled : path.join(currentDir, "worker-bootstrap.mts");
|
|
73
69
|
};
|
|
74
70
|
class NodeWorkerMessagePort {
|
|
75
71
|
constructor(worker, name = "WAWebVoipWebWasmWorker") {
|
|
@@ -203,6 +199,7 @@ class NodeWorkerMessagePort {
|
|
|
203
199
|
_NodeWorkerMessagePort_listeners = new WeakMap(), _NodeWorkerMessagePort_worker = new WeakMap(), _NodeWorkerMessagePort_handleMessage = new WeakMap();
|
|
204
200
|
export class WasmEngine {
|
|
205
201
|
constructor(config = {}) {
|
|
202
|
+
_WasmEngine_jsWorkers.set(this, new Set());
|
|
206
203
|
_WasmEngine_config.set(this, void 0);
|
|
207
204
|
_WasmEngine_instance.set(this, null);
|
|
208
205
|
_WasmEngine_initialized.set(this, false);
|
|
@@ -228,34 +225,33 @@ export class WasmEngine {
|
|
|
228
225
|
this.initialize = async () => {
|
|
229
226
|
if (__classPrivateFieldGet(this, _WasmEngine_initialized, "f"))
|
|
230
227
|
throw new Error("WasmEngine already initialized");
|
|
231
|
-
const voipStorageDir = "
|
|
228
|
+
const voipStorageDir = __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir;
|
|
232
229
|
try {
|
|
233
230
|
if (!fs.existsSync(voipStorageDir))
|
|
234
231
|
fs.mkdirSync(voipStorageDir, { recursive: true });
|
|
235
232
|
}
|
|
236
233
|
catch { }
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const workerFile = path.join(__classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath, "assets", "wasm", "worker-modules.js");
|
|
240
|
-
const downloadAsset = async (filename, targetPath) => {
|
|
241
|
-
const cdnUrl = `https://raw.githubusercontent.com/LuxyTeam/baileys-caller-optimized/main/assets/wasm/${filename}`;
|
|
242
|
-
console.log(`[WASM ENGINE] WASM asset missing. Downloading ${filename}...`);
|
|
243
|
-
const res = await fetch(cdnUrl);
|
|
244
|
-
if (!res.ok)
|
|
245
|
-
throw new Error(`Failed to download ${filename} from ${cdnUrl}: HTTP ${res.status}`);
|
|
246
|
-
const buffer = Buffer.from(await res.arrayBuffer());
|
|
247
|
-
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
248
|
-
fs.writeFileSync(targetPath, buffer);
|
|
249
|
-
console.log(`[WASM ENGINE] Successfully downloaded ${filename} (${buffer.length} bytes) to ${targetPath}`);
|
|
250
|
-
};
|
|
251
|
-
if (!__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary && !fs.existsSync(__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath)) {
|
|
252
|
-
await downloadAsset("whatsapp.wasm", __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmPath);
|
|
253
|
-
}
|
|
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");
|
|
254
236
|
if (!fs.existsSync(loaderFile)) {
|
|
255
|
-
|
|
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
|
+
}
|
|
256
252
|
}
|
|
257
|
-
if (!fs.existsSync(
|
|
258
|
-
|
|
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/.`);
|
|
259
255
|
}
|
|
260
256
|
const wasmBuffer = __classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary
|
|
261
257
|
? Buffer.from(__classPrivateFieldGet(this, _WasmEngine_config, "f").wasmBinary)
|
|
@@ -263,9 +259,6 @@ export class WasmEngine {
|
|
|
263
259
|
const diskWorkerCode = fs.existsSync(workerFile) ? fs.readFileSync(workerFile, "utf8") : "";
|
|
264
260
|
__classPrivateFieldSet(this, _WasmEngine_workerModulesCode, __classPrivateFieldGet(this, _WasmEngine_config, "f").workerModulesCode ?? diskWorkerCode, "f");
|
|
265
261
|
const workerBundleHasLoader = typeof __classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f") === "string" && /WAWebVoipWebWasmLoader/.test(__classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f"));
|
|
266
|
-
// Skip the on-disk loader.js if the worker bundle already has a loader —
|
|
267
|
-
// the standalone loader.js is older and would clobber the freshly fetched
|
|
268
|
-
// bindings inside worker-modules.js.
|
|
269
262
|
__classPrivateFieldSet(this, _WasmEngine_loaderCode, __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderCode ??
|
|
270
263
|
(workerBundleHasLoader ? "" : fs.existsSync(loaderFile) ? fs.readFileSync(loaderFile, "utf8") : ""), "f");
|
|
271
264
|
if (!__classPrivateFieldGet(this, _WasmEngine_loaderCode, "f") && !__classPrivateFieldGet(this, _WasmEngine_workerModulesCode, "f")) {
|
|
@@ -304,7 +297,7 @@ export class WasmEngine {
|
|
|
304
297
|
if (typeof wasmLoader !== "function") {
|
|
305
298
|
throw new Error(`No compatible WASM loader found. Tried: ${loaderModuleNames.join(", ")}`);
|
|
306
299
|
}
|
|
307
|
-
if (!__classPrivateFieldGet(_a,
|
|
300
|
+
if (!__classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbacksRegistered))
|
|
308
301
|
__classPrivateFieldGet(this, _WasmEngine_registerGlobalCallbacks, "f").call(this);
|
|
309
302
|
await __classPrivateFieldGet(this, _WasmEngine_initPThreadPool, "f").call(this);
|
|
310
303
|
const workersLoadingPromise = __classPrivateFieldGet(this, _WasmEngine_loadWasmModuleToAllWorkers, "f").call(this);
|
|
@@ -422,6 +415,38 @@ export class WasmEngine {
|
|
|
422
415
|
tcToken?.delete?.();
|
|
423
416
|
}
|
|
424
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
|
+
};
|
|
425
450
|
this.endCall = (reason = 0, sendTerminate = true) => {
|
|
426
451
|
__classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
|
|
427
452
|
__classPrivateFieldGet(this, _WasmEngine_instance, "f").endCall(reason, sendTerminate);
|
|
@@ -506,6 +531,47 @@ export class WasmEngine {
|
|
|
506
531
|
__classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
|
|
507
532
|
__classPrivateFieldGet(this, _WasmEngine_instance, "f").updateIceRtt?.(rttMs, relayIp, relayPort);
|
|
508
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
|
+
};
|
|
509
575
|
this.sendAudioData = (data, ptr) => {
|
|
510
576
|
__classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
|
|
511
577
|
if (!data || data.length === 0 || !ptr)
|
|
@@ -513,7 +579,7 @@ export class WasmEngine {
|
|
|
513
579
|
if (typeof __classPrivateFieldGet(this, _WasmEngine_instance, "f").onAudioDataFromJs !== "function")
|
|
514
580
|
return;
|
|
515
581
|
try {
|
|
516
|
-
const heapF32 = __classPrivateFieldGet(this, _WasmEngine_instance, "f").GROWABLE_HEAP_F32?.()
|
|
582
|
+
const heapF32 = __classPrivateFieldGet(this, _WasmEngine_instance, "f").GROWABLE_HEAP_F32?.();
|
|
517
583
|
if (!heapF32)
|
|
518
584
|
return;
|
|
519
585
|
const index = Math.floor(ptr / 4);
|
|
@@ -532,7 +598,6 @@ export class WasmEngine {
|
|
|
532
598
|
__classPrivateFieldGet(this, _WasmEngine_ensureInitialized, "f").call(this);
|
|
533
599
|
__classPrivateFieldGet(this, _WasmEngine_instance, "f")._free(ptr);
|
|
534
600
|
};
|
|
535
|
-
// ─── private ──────────────────────────────────────────────────────────────
|
|
536
601
|
_WasmEngine_ensureInitialized.set(this, () => {
|
|
537
602
|
if (!__classPrivateFieldGet(this, _WasmEngine_initialized, "f") || !__classPrivateFieldGet(this, _WasmEngine_instance, "f")) {
|
|
538
603
|
throw new Error("WasmEngine not initialized. Call initialize() first.");
|
|
@@ -636,8 +701,6 @@ export class WasmEngine {
|
|
|
636
701
|
aigc_version: 0,
|
|
637
702
|
call_admin_version: 0,
|
|
638
703
|
vid_stream_pause_resume_jb_reset_threshold_ms: 0,
|
|
639
|
-
// Opus: max bandwidth WB (16 kHz). FB (48 kHz) needs native audio device
|
|
640
|
-
// hooks not available in this JS-only WASM context.
|
|
641
704
|
opus_max_bandwidth: 1103, // OPUS_BANDWIDTH_WIDEBAND
|
|
642
705
|
};
|
|
643
706
|
const boolProps = {
|
|
@@ -696,6 +759,7 @@ export class WasmEngine {
|
|
|
696
759
|
loaderCode: __classPrivateFieldGet(this, _WasmEngine_loaderCode, "f"),
|
|
697
760
|
loaderModuleName: __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderModuleName,
|
|
698
761
|
resourcesPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath,
|
|
762
|
+
storageDir: __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir,
|
|
699
763
|
enableLogs: __classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs,
|
|
700
764
|
},
|
|
701
765
|
});
|
|
@@ -711,7 +775,7 @@ export class WasmEngine {
|
|
|
711
775
|
__classPrivateFieldGet(this, _WasmEngine_allocateUnusedWorker, "f").call(this);
|
|
712
776
|
});
|
|
713
777
|
_WasmEngine_loadWasmModuleToWorker.set(this, (worker) => new Promise((resolve) => {
|
|
714
|
-
var
|
|
778
|
+
var _b, _c;
|
|
715
779
|
const loadedHandler = (msg) => {
|
|
716
780
|
if (msg && msg.cmd === "loaded") {
|
|
717
781
|
worker.removeMessageListener("cmd", loadedHandler);
|
|
@@ -723,7 +787,7 @@ export class WasmEngine {
|
|
|
723
787
|
}
|
|
724
788
|
};
|
|
725
789
|
worker.addMessageListener("cmd", loadedHandler);
|
|
726
|
-
worker.workerID = (__classPrivateFieldSet(this, _WasmEngine_nextWorkerID, (
|
|
790
|
+
worker.workerID = (__classPrivateFieldSet(this, _WasmEngine_nextWorkerID, (_c = __classPrivateFieldGet(this, _WasmEngine_nextWorkerID, "f"), _b = _c++, _c), "f"), _b);
|
|
727
791
|
worker.postMessage({
|
|
728
792
|
cmd: "load", type: "cmd",
|
|
729
793
|
wasmMemory: __classPrivateFieldGet(this, _WasmEngine_wasmMemory, "f"),
|
|
@@ -756,6 +820,11 @@ export class WasmEngine {
|
|
|
756
820
|
});
|
|
757
821
|
});
|
|
758
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?.());
|
|
759
828
|
_a.registerGlobalCallbackListener("startCaptureJS", () => callbacks.onAudioCaptureStart?.());
|
|
760
829
|
_a.registerGlobalCallbackListener("stopCaptureJS", () => callbacks.onAudioCaptureStop?.());
|
|
761
830
|
if (callbacks.onAudioPlaybackInit) {
|
|
@@ -818,7 +887,7 @@ export class WasmEngine {
|
|
|
818
887
|
return relayData.byteLength;
|
|
819
888
|
});
|
|
820
889
|
}
|
|
821
|
-
__classPrivateFieldSet(_a,
|
|
890
|
+
__classPrivateFieldSet(_a, _a, true, "f", _WasmEngine_globalCallbacksRegistered);
|
|
822
891
|
});
|
|
823
892
|
_WasmEngine_requireModule.set(this, (name) => {
|
|
824
893
|
const preDefinedModules = {
|
|
@@ -841,11 +910,14 @@ export class WasmEngine {
|
|
|
841
910
|
loaderCode: __classPrivateFieldGet(this, _WasmEngine_loaderCode, "f"),
|
|
842
911
|
loaderModuleName: __classPrivateFieldGet(this, _WasmEngine_config, "f").loaderModuleName,
|
|
843
912
|
resourcesPath: __classPrivateFieldGet(this, _WasmEngine_config, "f").resourcesPath,
|
|
913
|
+
storageDir: __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir,
|
|
844
914
|
enableLogs: __classPrivateFieldGet(this, _WasmEngine_config, "f").enableLogs,
|
|
845
915
|
},
|
|
846
916
|
});
|
|
847
917
|
worker.stdout?.on("data", () => { });
|
|
848
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));
|
|
849
921
|
return worker;
|
|
850
922
|
},
|
|
851
923
|
},
|
|
@@ -980,17 +1052,27 @@ export class WasmEngine {
|
|
|
980
1052
|
callbacks.onAudioPlaybackStop?.();
|
|
981
1053
|
return 0;
|
|
982
1054
|
},
|
|
983
|
-
startVideoCaptureJS: () => {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
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
|
+
},
|
|
987
1071
|
dataChannelStateCallback: () => 0,
|
|
988
1072
|
getBrowserAudioProcessingStatus: () => 7,
|
|
989
1073
|
getBweModelPath: () => null,
|
|
990
|
-
videoFrameConsumed: (
|
|
991
|
-
|
|
992
|
-
callbacks.onVideoFrameConsumed(data);
|
|
993
|
-
}
|
|
1074
|
+
videoFrameConsumed: () => {
|
|
1075
|
+
callbacks.onVideoFrameConsumed?.();
|
|
994
1076
|
return 0;
|
|
995
1077
|
},
|
|
996
1078
|
cryptoHkdfExtractWithSaltAndExpand: (data) => {
|
|
@@ -1007,7 +1089,7 @@ export class WasmEngine {
|
|
|
1007
1089
|
},
|
|
1008
1090
|
isParticipantKnownContact: () => true,
|
|
1009
1091
|
getPersistentDirectoryPath: () => {
|
|
1010
|
-
const dir = "
|
|
1092
|
+
const dir = __classPrivateFieldGet(this, _WasmEngine_config, "f").storageDir;
|
|
1011
1093
|
try {
|
|
1012
1094
|
if (!fs.existsSync(dir))
|
|
1013
1095
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -1208,14 +1290,40 @@ export class WasmEngine {
|
|
|
1208
1290
|
};
|
|
1209
1291
|
return atomicsWrapper;
|
|
1210
1292
|
});
|
|
1211
|
-
const
|
|
1212
|
-
? (path.isAbsolute(config.resourcesPath) ? config.resourcesPath : path.resolve(process.cwd(), config.resourcesPath))
|
|
1213
|
-
|
|
1214
|
-
|
|
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
|
|
1215
1310
|
? (path.isAbsolute(config.wasmPath) ? config.wasmPath : path.resolve(process.cwd(), config.wasmPath))
|
|
1216
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
|
+
}
|
|
1217
1322
|
__classPrivateFieldSet(this, _WasmEngine_config, {
|
|
1218
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"),
|
|
1219
1327
|
wasmPath,
|
|
1220
1328
|
resourcesPath: basePath,
|
|
1221
1329
|
enableLogs: config.enableLogs ?? true,
|
|
@@ -1229,20 +1337,20 @@ export class WasmEngine {
|
|
|
1229
1337
|
}, "f");
|
|
1230
1338
|
}
|
|
1231
1339
|
}
|
|
1232
|
-
|
|
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();
|
|
1233
1341
|
_WasmEngine_globalCallbackListeners = { value: new Map() };
|
|
1234
1342
|
_WasmEngine_globalCallbacksRegistered = { value: false };
|
|
1235
1343
|
WasmEngine.registerGlobalCallbackListener = (callbackName, handler) => {
|
|
1236
1344
|
const key = `callback:${callbackName}`;
|
|
1237
|
-
let set = __classPrivateFieldGet(_a,
|
|
1345
|
+
let set = __classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).get(key);
|
|
1238
1346
|
if (!set) {
|
|
1239
1347
|
set = new Set();
|
|
1240
|
-
__classPrivateFieldGet(_a,
|
|
1348
|
+
__classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).set(key, set);
|
|
1241
1349
|
}
|
|
1242
1350
|
set.add(handler);
|
|
1243
1351
|
};
|
|
1244
1352
|
WasmEngine.notifyGlobalCallbackListeners = (callbackName, data) => {
|
|
1245
|
-
const set = __classPrivateFieldGet(_a,
|
|
1353
|
+
const set = __classPrivateFieldGet(_a, _a, "f", _WasmEngine_globalCallbackListeners).get(`callback:${callbackName}`);
|
|
1246
1354
|
if (!set)
|
|
1247
1355
|
return;
|
|
1248
1356
|
for (const handler of set) {
|
|
@@ -1252,5 +1360,5 @@ WasmEngine.notifyGlobalCallbackListeners = (callbackName, data) => {
|
|
|
1252
1360
|
catch { }
|
|
1253
1361
|
}
|
|
1254
1362
|
};
|
|
1255
|
-
|
|
1363
|
+
export default WasmEngine;
|
|
1256
1364
|
//# sourceMappingURL=wasm-engine.js.map
|