@vanzxy/baileys 1.6.2 → 1.6.4

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.

Potentially problematic release.


This version of @vanzxy/baileys might be problematic. Click here for more details.

Files changed (51) hide show
  1. package/NOTICE.md +50 -0
  2. package/lib/Utils/A2UI.js +217 -0
  3. package/lib/Utils/MessageBuilder.js +332 -46
  4. package/lib/Utils/MessageBuilder_d.ts +45 -0
  5. package/lib/Utils/PersistentStore.js +592 -0
  6. package/lib/Utils/PersistentStore_d.ts +60 -0
  7. package/lib/Utils/anti-delete.d.ts +68 -0
  8. package/lib/Utils/anti-delete.js +185 -0
  9. package/lib/Utils/auto-reply.d.ts +47 -0
  10. package/lib/Utils/auto-reply.js +155 -0
  11. package/lib/Utils/button-helper-utils.js +314 -0
  12. package/lib/Utils/button-sender.js +817 -0
  13. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  14. package/lib/Utils/chat-history-helpers.js +71 -0
  15. package/lib/Utils/index.d.ts +11 -0
  16. package/lib/Utils/index.js +16 -0
  17. package/lib/Utils/media-messages.d.ts +18 -0
  18. package/lib/Utils/media-messages.js +71 -0
  19. package/lib/Utils/media-set.d.ts +13 -0
  20. package/lib/Utils/media-set.js +165 -0
  21. package/lib/Utils/message-kind.js +139 -0
  22. package/lib/Utils/message-search.d.ts +44 -0
  23. package/lib/Utils/message-search.js +174 -0
  24. package/lib/Utils/scheduling.d.ts +42 -0
  25. package/lib/Utils/scheduling.js +140 -0
  26. package/lib/Utils/status.d.ts +50 -0
  27. package/lib/Utils/status.js +108 -0
  28. package/lib/Utils/stickerpack.d.ts +51 -0
  29. package/lib/Utils/stickerpack.js +276 -0
  30. package/lib/Utils/templates.d.ts +76 -0
  31. package/lib/Utils/templates.js +151 -0
  32. package/lib/Utils/use-sqlite-auth-state.js +28 -1
  33. package/lib/Utils/vcard.d.ts +58 -0
  34. package/lib/Utils/vcard.js +94 -0
  35. package/lib/VoIP/audio-feeder.d.ts +15 -0
  36. package/lib/VoIP/audio-feeder.js +132 -0
  37. package/lib/VoIP/index.js +277 -0
  38. package/lib/VoIP/relay-transport.d.ts +43 -0
  39. package/lib/VoIP/relay-transport.js +559 -0
  40. package/lib/VoIP/signaling.js +624 -0
  41. package/lib/VoIP/types.d.ts +69 -0
  42. package/lib/VoIP/types.js +17 -0
  43. package/lib/VoIP/wasm-engine.d.ts +103 -0
  44. package/lib/VoIP/wasm-engine.js +1214 -0
  45. package/lib/VoIP/worker-bootstrap.js +1042 -0
  46. package/lib/WABinary/generic-utils.js +8 -0
  47. package/lib/assets/wasm/loader.js +5 -0
  48. package/lib/assets/wasm/whatsapp.wasm +0 -0
  49. package/lib/assets/wasm/worker-modules.js +273 -0
  50. package/lib/index.js +4 -0
  51. package/package.json +22 -1
@@ -0,0 +1,1042 @@
1
+ /**
2
+ * Worker-thread bootstrap for the WhatsApp WASM VoIP engine.
3
+ *
4
+ * Mirrors the browser Web-Worker environment (self/postMessage/babelHelpers/
5
+ * MessagePort) the WASM loader expects, then runs that loader inside a Node
6
+ * `worker_threads` Worker. Function-keyword shims are intentional — the
7
+ * loader inspects `.prototype` and `instanceof` on these.
8
+ *
9
+ * @author ShellTear
10
+ */
11
+ "use strict";
12
+ import { parentPort, workerData } from "worker_threads";
13
+ import * as path from "path";
14
+ import * as fs from "fs";
15
+ import * as crypto from "crypto";
16
+ import * as vm from "vm";
17
+ import { fileURLToPath } from "url";
18
+ import { createRequire } from "module";
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = path.dirname(__filename);
21
+ const _require = createRequire(import.meta.url);
22
+ const typedWorkerData = workerData;
23
+ if (typeof process === "undefined") {
24
+ global.process = {
25
+ cwd: () => __dirname || ".",
26
+ env: {},
27
+ platform: "linux",
28
+ version: "v18.0.0",
29
+ versions: {},
30
+ nextTick: (fn, ...args) => setImmediate(fn, ...args),
31
+ exit: (code) => {
32
+ throw new Error(`Process exit: ${code}`);
33
+ },
34
+ on: () => { },
35
+ off: () => { },
36
+ once: () => { },
37
+ emit: () => { },
38
+ };
39
+ }
40
+ else if (!process.cwd) {
41
+ process.cwd = () => __dirname || ".";
42
+ }
43
+ global.babelHelpers = {
44
+ extends: function (target) {
45
+ for (var i = 1; i < arguments.length; i++) {
46
+ var source = arguments[i];
47
+ if (source != null) {
48
+ for (var key in source) {
49
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
50
+ target[key] = source[key];
51
+ }
52
+ }
53
+ }
54
+ }
55
+ return target;
56
+ },
57
+ inheritsLoose: function (subClass, superClass) {
58
+ subClass.prototype = Object.create(superClass.prototype);
59
+ subClass.prototype.constructor = subClass;
60
+ subClass.__proto__ = superClass;
61
+ },
62
+ taggedTemplateLiteralLoose: function (strings, raw) {
63
+ if (!raw)
64
+ raw = strings.slice(0);
65
+ strings.raw = raw;
66
+ return strings;
67
+ },
68
+ asyncToGenerator: function (fn) {
69
+ return function () {
70
+ var self = this;
71
+ var args = arguments;
72
+ return new Promise(function (resolve, reject) {
73
+ var gen = fn.apply(self, args);
74
+ function step(key, arg) {
75
+ try {
76
+ var info = gen[key](arg);
77
+ var value = info.value;
78
+ }
79
+ catch (error) {
80
+ reject(error);
81
+ return;
82
+ }
83
+ if (info.done) {
84
+ resolve(value);
85
+ }
86
+ else {
87
+ Promise.resolve(value).then(function (val) { step("next", val); }, function (err) { step("throw", err); });
88
+ }
89
+ }
90
+ step("next");
91
+ });
92
+ };
93
+ },
94
+ createClass: function (Constructor, protoProps, staticProps) {
95
+ if (protoProps) {
96
+ for (var i = 0; i < protoProps.length; i++) {
97
+ var descriptor = protoProps[i];
98
+ descriptor.enumerable = descriptor.enumerable || false;
99
+ descriptor.configurable = true;
100
+ if ("value" in descriptor)
101
+ descriptor.writable = true;
102
+ Object.defineProperty(Constructor.prototype, descriptor.key, descriptor);
103
+ }
104
+ }
105
+ if (staticProps) {
106
+ for (var j = 0; j < staticProps.length; j++) {
107
+ var staticDescriptor = staticProps[j];
108
+ staticDescriptor.enumerable = staticDescriptor.enumerable || false;
109
+ staticDescriptor.configurable = true;
110
+ if ("value" in staticDescriptor)
111
+ staticDescriptor.writable = true;
112
+ Object.defineProperty(Constructor, staticDescriptor.key, staticDescriptor);
113
+ }
114
+ }
115
+ return Constructor;
116
+ },
117
+ classCallCheck: function (instance, Constructor) {
118
+ if (!(instance instanceof Constructor)) {
119
+ throw new TypeError("Cannot call a class as a function");
120
+ }
121
+ },
122
+ defineProperty: function (obj, key, value) {
123
+ if (key in obj) {
124
+ Object.defineProperty(obj, key, {
125
+ value: value,
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ });
130
+ }
131
+ else {
132
+ obj[key] = value;
133
+ }
134
+ return obj;
135
+ },
136
+ objectSpread: function (target) {
137
+ for (var i = 1; i < arguments.length; i++) {
138
+ var source = arguments[i] != null ? arguments[i] : {};
139
+ var ownKeys = Object.keys(source);
140
+ if (typeof Object.getOwnPropertySymbols === "function") {
141
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
142
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
143
+ }));
144
+ }
145
+ ownKeys.forEach(function (key) {
146
+ target[key] = source[key];
147
+ });
148
+ }
149
+ return target;
150
+ },
151
+ objectSpread2: function (target) {
152
+ for (var i = 1; i < arguments.length; i++) {
153
+ var source = arguments[i] != null ? arguments[i] : {};
154
+ if (i % 2) {
155
+ Object.keys(source).forEach(function (key) {
156
+ target[key] = source[key];
157
+ });
158
+ }
159
+ else if (Object.getOwnPropertyDescriptors) {
160
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
161
+ }
162
+ else {
163
+ Object.keys(source).forEach(function (key) {
164
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
165
+ });
166
+ }
167
+ }
168
+ return target;
169
+ },
170
+ wrapNativeSuper: function (Class) {
171
+ var _cache = typeof Map === "function" ? new Map() : undefined;
172
+ function Wrapper() {
173
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
174
+ }
175
+ function _construct(Parent, args, Class) {
176
+ if (typeof Reflect !== "undefined" && Reflect.construct) {
177
+ return Reflect.construct(Parent, args, Class);
178
+ }
179
+ var a = [null];
180
+ a.push.apply(a, args);
181
+ var instance = new (Function.bind.apply(Parent, a))();
182
+ if (Class)
183
+ Object.setPrototypeOf(instance, Class.prototype);
184
+ return instance;
185
+ }
186
+ function _getPrototypeOf(o) {
187
+ return Object.getPrototypeOf || function (o) { return o.__proto__; };
188
+ }
189
+ if (typeof Class !== "function")
190
+ return Class;
191
+ if (_cache) {
192
+ if (_cache.has(Class))
193
+ return _cache.get(Class);
194
+ _cache.set(Class, Wrapper);
195
+ }
196
+ Wrapper.prototype = Object.create(Class.prototype, {
197
+ constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true },
198
+ });
199
+ return Object.setPrototypeOf(Wrapper, Class);
200
+ },
201
+ isNativeFunction: function (fn) {
202
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
203
+ },
204
+ getPrototypeOf: function (o) {
205
+ return Object.getPrototypeOf ? Object.getPrototypeOf(o) : o.__proto__;
206
+ },
207
+ setPrototypeOf: function (o, p) {
208
+ return Object.setPrototypeOf ? Object.setPrototypeOf(o, p) : ((o.__proto__ = p), o);
209
+ },
210
+ assertThisInitialized: function (self) {
211
+ if (self === void 0) {
212
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
213
+ }
214
+ return self;
215
+ },
216
+ possibleConstructorReturn: function (self, call) {
217
+ if (call && (typeof call === "object" || typeof call === "function"))
218
+ return call;
219
+ return global.babelHelpers.assertThisInitialized(self);
220
+ },
221
+ inherits: function (subClass, superClass) {
222
+ if (typeof superClass !== "function" && superClass !== null) {
223
+ throw new TypeError("Super expression must either be null or a function");
224
+ }
225
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
226
+ constructor: { value: subClass, writable: true, configurable: true },
227
+ });
228
+ if (superClass)
229
+ Object.setPrototypeOf(subClass, superClass);
230
+ },
231
+ construct: function (Parent, args, Class) {
232
+ if (typeof Reflect !== "undefined" && Reflect.construct) {
233
+ return Reflect.construct(Parent, args, Class);
234
+ }
235
+ var a = [null];
236
+ a.push.apply(a, args);
237
+ var Constructor = Function.bind.apply(Parent, a);
238
+ var instance = new Constructor();
239
+ if (Class)
240
+ Object.setPrototypeOf(instance, Class.prototype);
241
+ return instance;
242
+ },
243
+ isNativeReflectConstruct: function () {
244
+ if (typeof Reflect === "undefined" || !Reflect.construct)
245
+ return false;
246
+ try {
247
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () { }));
248
+ return true;
249
+ }
250
+ catch (e) {
251
+ return false;
252
+ }
253
+ },
254
+ };
255
+ if (typeof global.require === "undefined") {
256
+ global.require = _require;
257
+ }
258
+ const _originalProcess = global.process;
259
+ const _originalRequire = global.require;
260
+ const hideNodeEnv = () => {
261
+ try {
262
+ delete global.process;
263
+ }
264
+ catch (e) {
265
+ global.process = undefined;
266
+ }
267
+ try {
268
+ delete global.require;
269
+ }
270
+ catch (e) {
271
+ global.require = undefined;
272
+ }
273
+ };
274
+ const restoreNodeEnv = () => {
275
+ global.process = _originalProcess;
276
+ global.require = _originalRequire;
277
+ };
278
+ const __modules = {};
279
+ const __moduleFactories = {};
280
+ global.__d = function (name, deps, factory, flags) {
281
+ if (typeof deps === "function") {
282
+ factory = deps;
283
+ deps = [];
284
+ }
285
+ __moduleFactories[name] = { factory, deps, flags };
286
+ };
287
+ const importDefaultModule = (name) => {
288
+ const value = global.__r(name);
289
+ return value && value.__esModule ? value.default : value;
290
+ };
291
+ const importAllModule = (name) => {
292
+ const value = global.__r(name);
293
+ if (value == null) {
294
+ return { default: value };
295
+ }
296
+ if (value.__esModule) {
297
+ return value;
298
+ }
299
+ if (typeof value !== "object" && typeof value !== "function") {
300
+ return { default: value };
301
+ }
302
+ const namespace = {};
303
+ for (const key of Object.keys(value)) {
304
+ namespace[key] = value[key];
305
+ }
306
+ namespace.default = value;
307
+ return namespace;
308
+ };
309
+ global.__r = function (name) {
310
+ if (__modules[name])
311
+ return __modules[name].exports;
312
+ const moduleFactory = __moduleFactories[name];
313
+ if (!moduleFactory)
314
+ throw new Error(`Module "${name}" not found`);
315
+ const module = { exports: {} };
316
+ __modules[name] = module;
317
+ try {
318
+ moduleFactory.factory(global, global.__r, importDefaultModule, importAllModule, null, module, module.exports);
319
+ }
320
+ catch (e) {
321
+ delete __modules[name];
322
+ throw e;
323
+ }
324
+ return module.exports;
325
+ };
326
+ __modules["Promise"] = { exports: Promise };
327
+ const bxFunc = function (id) { return id; };
328
+ bxFunc.getURL = function (_id, _opts) { return ""; };
329
+ __modules["bx"] = { exports: bxFunc };
330
+ __modules["WorkerBundleResource"] = {
331
+ exports: { createDedicatedWebWorker: function () { return null; } },
332
+ };
333
+ __modules["WorkerClient"] = { exports: { init: function () { } } };
334
+ __modules["WorkerMessagePort"] = {
335
+ exports: { WorkerSyncedMessagePort: function () { } },
336
+ };
337
+ __modules["WAWebVoipWebWasmWorkerResource"] = { exports: {} };
338
+ if (typeof self === "undefined")
339
+ global.self = global;
340
+ global.self = global;
341
+ if (typeof global.window === "undefined")
342
+ global.window = global;
343
+ global.importScripts = function (...urls) {
344
+ for (const url of urls) {
345
+ try {
346
+ const code = fs.readFileSync(url, "utf8");
347
+ eval(code);
348
+ }
349
+ catch (e) { }
350
+ }
351
+ };
352
+ if (typeof global.location === "undefined") {
353
+ global.location = {
354
+ href: __filename,
355
+ origin: "file://",
356
+ protocol: "file:",
357
+ host: "",
358
+ hostname: "",
359
+ port: "",
360
+ pathname: __filename,
361
+ search: "",
362
+ hash: "",
363
+ };
364
+ }
365
+ global.postMessage = function (data, transfer) {
366
+ if (parentPort)
367
+ parentPort.postMessage(data, transfer);
368
+ };
369
+ const messageListeners = [];
370
+ global.addEventListener = function (type, handler) {
371
+ if (type === "message") {
372
+ messageListeners.push(handler);
373
+ if (parentPort)
374
+ parentPort.on("message", (data) => {
375
+ handler({ data });
376
+ });
377
+ }
378
+ };
379
+ class SimpleHook {
380
+ listeners = [];
381
+ add = (fn) => { this.listeners.push(fn); return fn; };
382
+ remove = (fn) => { const idx = this.listeners.indexOf(fn); if (idx >= 0) {
383
+ this.listeners.splice(idx, 1);
384
+ return true;
385
+ } return false; };
386
+ clear = () => { this.listeners = []; };
387
+ call = (data) => { for (const fn of this.listeners) {
388
+ try {
389
+ fn(data);
390
+ }
391
+ catch { }
392
+ } };
393
+ }
394
+ class WorkerSyncedMessagePort {
395
+ $1 = {};
396
+ onUnhandledMessage = new SimpleHook();
397
+ onMessage = new SimpleHook();
398
+ onPostMessage = new SimpleHook();
399
+ onError = new SimpleHook();
400
+ $2;
401
+ name;
402
+ constructor(port, name) {
403
+ this.$2 = port;
404
+ this.name = name;
405
+ if (parentPort) {
406
+ parentPort.on("message", (data) => {
407
+ this.onMessageHandler(data);
408
+ });
409
+ }
410
+ }
411
+ onMessageHandler(data) {
412
+ try {
413
+ this.onMessage.call(data);
414
+ let handled = false;
415
+ const dispatch = (key) => {
416
+ if (!key)
417
+ return;
418
+ const hook = this.$1[key];
419
+ if (hook) {
420
+ handled = true;
421
+ hook.call(data);
422
+ }
423
+ };
424
+ dispatch(data.type);
425
+ if (data.cmd !== data.type)
426
+ dispatch(data.cmd);
427
+ if (!handled)
428
+ this.onUnhandledMessage.call(data);
429
+ }
430
+ catch (e) {
431
+ this.onError.call(e);
432
+ }
433
+ }
434
+ postMessage(data, transfer) {
435
+ this.onPostMessage.call(data);
436
+ if (parentPort) {
437
+ if (transfer)
438
+ parentPort.postMessage(data, transfer);
439
+ else
440
+ parentPort.postMessage(data);
441
+ }
442
+ }
443
+ addMessageListener(type, fn) {
444
+ let hook = this.$1[type];
445
+ if (!hook) {
446
+ hook = new SimpleHook();
447
+ this.$1[type] = hook;
448
+ }
449
+ return hook.add(fn);
450
+ }
451
+ removeMessageListener(type, fn) {
452
+ const hook = this.$1[type];
453
+ return !!hook && hook.remove(fn);
454
+ }
455
+ removeAllMessageListeners(type) {
456
+ const hook = this.$1[type];
457
+ if (hook)
458
+ hook.clear();
459
+ }
460
+ }
461
+ let WABinary = {
462
+ Binary: {
463
+ build: function (data) {
464
+ return {
465
+ readByteArrayView: function () {
466
+ if (data instanceof Uint8Array)
467
+ return data;
468
+ if (typeof data === "string")
469
+ return new TextEncoder().encode(data);
470
+ if (Array.isArray(data))
471
+ return new Uint8Array(data);
472
+ if (Buffer.isBuffer(data))
473
+ return new Uint8Array(data);
474
+ if (data instanceof ArrayBuffer)
475
+ return new Uint8Array(data);
476
+ if (ArrayBuffer.isView(data)) {
477
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
478
+ }
479
+ if (typeof data === "object" && data !== null && typeof data.length === "number") {
480
+ const arr = new Uint8Array(data.length);
481
+ for (let i = 0; i < data.length; i++)
482
+ arr[i] = data[i] || 0;
483
+ return arr;
484
+ }
485
+ return new Uint8Array(0);
486
+ },
487
+ };
488
+ },
489
+ },
490
+ };
491
+ let WACryptoHkdfSync = {
492
+ hkdf: function (key, salt, info, length) {
493
+ const prk = crypto
494
+ .createHmac("sha256", salt || Buffer.alloc(32))
495
+ .update(key)
496
+ .digest();
497
+ const n = Math.ceil(length / 32);
498
+ const okm = Buffer.alloc(n * 32);
499
+ let prev = Buffer.alloc(0);
500
+ for (let i = 0; i < n; i++) {
501
+ prev = crypto
502
+ .createHmac("sha256", prk)
503
+ .update(Buffer.concat([prev, info || Buffer.alloc(0), Buffer.from([i + 1])]))
504
+ .digest();
505
+ prev.copy(okm, i * 32);
506
+ }
507
+ return new Uint8Array(okm.slice(0, length));
508
+ },
509
+ };
510
+ class Sha256HMacBuilder {
511
+ hmac;
512
+ constructor(key) {
513
+ this.hmac = crypto.createHmac("sha256", key);
514
+ }
515
+ update(data) {
516
+ this.hmac.update(data);
517
+ return this;
518
+ }
519
+ finish() {
520
+ return new Uint8Array(this.hmac.digest());
521
+ }
522
+ }
523
+ const WACryptoSha256HmacBuilder = { Sha256HMacBuilder };
524
+ const WAWebVoipPersistentFS = {
525
+ getVoipPersistentDirectoryPath: function () {
526
+ return "/tmp/voip";
527
+ },
528
+ initPersistentFS: async function (_module) {
529
+ return Promise.resolve();
530
+ },
531
+ };
532
+ let WAWebVoipJsWorkerMessageHandler = {
533
+ handleJsWorkerMessage: function () { },
534
+ };
535
+ const getPreferredLoaderModuleNames = () => {
536
+ return [
537
+ typedWorkerData?.loaderModuleName,
538
+ "WAWebVoipWebWasmLoader",
539
+ "WAWebVoipWebWasmLoader.worker",
540
+ "WAWebVoipWebWasmLoader_ProdLab_internal.worker",
541
+ "WAWebVoipWebWasmLoader_ProdLabvideo_internal.worker",
542
+ ].filter((value, index, array) => !!value && array.indexOf(value) === index);
543
+ };
544
+ const resolveLoaderModule = () => {
545
+ for (const moduleName of getPreferredLoaderModuleNames()) {
546
+ try {
547
+ const loaderModule = global.__r(moduleName);
548
+ const resolved = loaderModule?.default ?? loaderModule;
549
+ if (typeof resolved === "function") {
550
+ return resolved;
551
+ }
552
+ }
553
+ catch (e) { }
554
+ }
555
+ return null;
556
+ };
557
+ const nullthrows = (value) => {
558
+ if (value == null)
559
+ throw new Error("Got unexpected null or undefined");
560
+ return value;
561
+ };
562
+ const asyncToGeneratorRuntime = {
563
+ asyncToGenerator: function (fn) {
564
+ return function (...args) {
565
+ const gen = fn.apply(this, args);
566
+ return new Promise((resolve, reject) => {
567
+ function step(key, arg) {
568
+ try {
569
+ const info = gen[key](arg);
570
+ const value = info.value;
571
+ if (info.done)
572
+ resolve(value);
573
+ else
574
+ Promise.resolve(value).then((val) => step("next", val), (err) => step("throw", err));
575
+ }
576
+ catch (e) {
577
+ reject(e);
578
+ }
579
+ }
580
+ step("next", undefined);
581
+ });
582
+ };
583
+ },
584
+ };
585
+ const e = new WorkerSyncedMessagePort(global.self, "VoipWebWasmWorker");
586
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks = {
587
+ onSignalingXmpp: function (n) {
588
+ e.postMessage({
589
+ type: "waWasmWorkerCompatibleCallback",
590
+ __name: "onSignalingXmpp",
591
+ peerJid: n.peerJid,
592
+ callId: n.callId,
593
+ xmlPayload: n.xmlPayload,
594
+ });
595
+ },
596
+ onCallEvent: function (n) {
597
+ e.postMessage({
598
+ type: "waWasmWorkerCompatibleCallback",
599
+ __name: "onCallEvent",
600
+ eventType: n.eventType,
601
+ userData: n.userData,
602
+ eventDataJson: n.eventDataJson,
603
+ });
604
+ },
605
+ sendDataToRelay: function (n) {
606
+ const t = n.data;
607
+ const r = n.len;
608
+ const o = n.ip;
609
+ const a = n.port;
610
+ e.postMessage({
611
+ type: "waWasmWorkerCompatibleCallback",
612
+ __name: "sendDataToRelay",
613
+ data: t,
614
+ len: r,
615
+ ip: o,
616
+ port: a,
617
+ });
618
+ return r || (t ? t.length || t.byteLength || 0 : 0);
619
+ },
620
+ loggingCallback: function (n) {
621
+ try {
622
+ e.postMessage(Object.assign({ type: "waWasmWorkerCompatibleCallback", __name: "loggingCallback" }, n));
623
+ }
624
+ catch (err) { }
625
+ },
626
+ initCaptureDriverJS: function (n) {
627
+ e.postMessage(Object.assign({ type: "waWasmWorkerCompatibleCallback", __name: "initCaptureDriverJS" }, n));
628
+ return 0;
629
+ },
630
+ startCaptureJS: function () {
631
+ e.postMessage({
632
+ type: "waWasmWorkerCompatibleCallback",
633
+ __name: "startCaptureJS",
634
+ });
635
+ return 0;
636
+ },
637
+ stopCaptureJS: function () {
638
+ e.postMessage({
639
+ type: "waWasmWorkerCompatibleCallback",
640
+ __name: "stopCaptureJS",
641
+ });
642
+ return 0;
643
+ },
644
+ initPlaybackDriverJS: function (n) {
645
+ e.postMessage(Object.assign({ type: "waWasmWorkerCompatibleCallback", __name: "initPlaybackDriverJS" }, n));
646
+ return 0;
647
+ },
648
+ startPlaybackJS: function () {
649
+ e.postMessage({
650
+ type: "waWasmWorkerCompatibleCallback",
651
+ __name: "startPlaybackJS",
652
+ });
653
+ return 0;
654
+ },
655
+ stopPlaybackJS: function () {
656
+ e.postMessage({
657
+ type: "waWasmWorkerCompatibleCallback",
658
+ __name: "stopPlaybackJS",
659
+ });
660
+ return 0;
661
+ },
662
+ startVideoCaptureJS: function (n) {
663
+ e.postMessage(Object.assign({ type: "waWasmWorkerCompatibleCallback", __name: "startVideoCaptureJS" }, n));
664
+ return 0;
665
+ },
666
+ stopVideoCaptureJS: function () {
667
+ e.postMessage({
668
+ type: "waWasmWorkerCompatibleCallback",
669
+ __name: "stopVideoCaptureJS",
670
+ });
671
+ return 0;
672
+ },
673
+ onVideoFrameWasmToJs: function (n) {
674
+ e.postMessage({
675
+ type: "waWasmWorkerCompatibleCallback",
676
+ __name: "onVideoFrameWasmToJs",
677
+ userJid: n.userJid,
678
+ frameBuffer: n.frameBuffer,
679
+ width: n.width,
680
+ height: n.height,
681
+ orientation: n.orientation,
682
+ format: n.format,
683
+ timestamp: n.timestamp,
684
+ isKeyFrame: n.isKeyFrame,
685
+ }, [n.frameBuffer]);
686
+ },
687
+ startDesktopCaptureJS: function (n) {
688
+ e.postMessage(Object.assign({ type: "waWasmWorkerCompatibleCallback", __name: "startDesktopCaptureJS" }, n));
689
+ return 0;
690
+ },
691
+ stopDesktopCaptureJS: function () {
692
+ e.postMessage({
693
+ type: "waWasmWorkerCompatibleCallback",
694
+ __name: "stopDesktopCaptureJS",
695
+ });
696
+ return 0;
697
+ },
698
+ cryptoHkdfExtractWithSaltAndExpand: function (t) {
699
+ const i = new Uint8Array(t.key_);
700
+ const l = t.salt_ ? new Uint8Array(t.salt_) : undefined;
701
+ const s = WABinary.Binary.build(t.info_).readByteArrayView();
702
+ return WACryptoHkdfSync.hkdf(i, l, s, t.length);
703
+ },
704
+ hmacSha256KeyGenerator: function (t) {
705
+ const r = new Uint8Array(t.data_);
706
+ const a = new Uint8Array(t.key_);
707
+ return new Sha256HMacBuilder(a).update(r).finish();
708
+ },
709
+ isParticipantKnownContact: function (_t) {
710
+ return false;
711
+ },
712
+ getPersistentDirectoryPath: function () {
713
+ return WAWebVoipPersistentFS.getVoipPersistentDirectoryPath();
714
+ },
715
+ getBrowserAudioProcessingStatus: function () {
716
+ return 7;
717
+ },
718
+ getBweModelPath: function () {
719
+ return null;
720
+ },
721
+ videoFrameConsumed: function () { },
722
+ dataChannelStateCallback: function () { },
723
+ };
724
+ let wasmLoader = null;
725
+ if (typedWorkerData && (typedWorkerData.loaderCode || typedWorkerData.workerModulesCode)) {
726
+ try {
727
+ const modulePrelude = "var __d = global.__d, __r = global.__r;\n";
728
+ const savedCallbacks = global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
729
+ if (typedWorkerData.workerModulesCode) {
730
+ const workerScript = new vm.Script(modulePrelude + typedWorkerData.workerModulesCode, {
731
+ filename: "workerModulesCode-SEM22icu2S7.js",
732
+ });
733
+ workerScript.runInThisContext();
734
+ }
735
+ if (typedWorkerData.loaderCode) {
736
+ const loaderScript = new vm.Script(modulePrelude + typedWorkerData.loaderCode, {
737
+ filename: "loaderCode-1eFv_3F3hOU.js",
738
+ });
739
+ loaderScript.runInThisContext();
740
+ }
741
+ if (!global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks?.loggingCallback) {
742
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks = savedCallbacks;
743
+ if (global.self !== global.self) {
744
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks = savedCallbacks;
745
+ }
746
+ }
747
+ if (global.self !== global.self) {
748
+ if (global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks) {
749
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks =
750
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
751
+ }
752
+ else if (global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks) {
753
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks =
754
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
755
+ }
756
+ global.self = global.self;
757
+ }
758
+ wasmLoader = resolveLoaderModule();
759
+ try {
760
+ const jsWorkerModule = global.__r("WAWebVoipJsWorkerMessageHandler");
761
+ if (jsWorkerModule) {
762
+ WAWebVoipJsWorkerMessageHandler = jsWorkerModule.default ?? jsWorkerModule;
763
+ }
764
+ }
765
+ catch (e) { }
766
+ }
767
+ catch (e) { }
768
+ }
769
+ if (!wasmLoader) {
770
+ const resourcesPath = typedWorkerData?.resourcesPath || path.join(__dirname, "wasm-resources");
771
+ const rsrcPath = path.join(resourcesPath, "loader.js");
772
+ if (fs.existsSync(rsrcPath)) {
773
+ try {
774
+ const loaderCode = fs.readFileSync(rsrcPath, "utf8");
775
+ const savedCallbacks = global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
776
+ const script = new vm.Script(loaderCode, { filename: rsrcPath });
777
+ script.runInThisContext();
778
+ if (!global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks?.loggingCallback) {
779
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks = savedCallbacks;
780
+ }
781
+ wasmLoader = resolveLoaderModule();
782
+ }
783
+ catch (e) { }
784
+ }
785
+ }
786
+ let s = {};
787
+ let u = false;
788
+ let _ = null;
789
+ let jsWorkerRawVideoFramePtr = 0;
790
+ let jsWorkerRawVideoFrameSize = 0;
791
+ const c = (condition, msg) => {
792
+ if (!condition)
793
+ throw "Assertion failed: " + msg;
794
+ };
795
+ const d = (..._args) => { };
796
+ const m = (...args) => {
797
+ const text = args.join(" ");
798
+ global.postMessage({
799
+ cmd: "alert",
800
+ text: text,
801
+ threadId: s._pthread_self ? s._pthread_self() : undefined,
802
+ });
803
+ };
804
+ const p = d;
805
+ global.self.alert = m;
806
+ s.instantiateWasm = function (imports, successCallback) {
807
+ const wasmModule = nullthrows(s.wasmModule);
808
+ s.wasmModule = null;
809
+ const instance = new WebAssembly.Instance(wasmModule, imports);
810
+ return successCallback(instance);
811
+ };
812
+ global.self.onunhandledrejection = function (event) {
813
+ throw event.reason ?? event;
814
+ };
815
+ const getActiveWasmModule = () => {
816
+ return _ || global.self.__waModule || s;
817
+ };
818
+ const releaseJsWorkerRawVideoFrameBuffer = (moduleRef) => {
819
+ if (jsWorkerRawVideoFramePtr && moduleRef && typeof moduleRef._free === "function") {
820
+ try {
821
+ moduleRef._free(jsWorkerRawVideoFramePtr);
822
+ }
823
+ catch { }
824
+ }
825
+ jsWorkerRawVideoFramePtr = 0;
826
+ jsWorkerRawVideoFrameSize = 0;
827
+ };
828
+ const handleRawVideoFrameOnJsWorker = (msg) => {
829
+ const moduleRef = getActiveWasmModule();
830
+ const sendFrameFn = msg?.useDesktopCapture
831
+ ? moduleRef?.onDesktopCaptureDataFromJs
832
+ : moduleRef?.onVideoDataFromJs;
833
+ const frameBuffer = msg?.frameBuffer;
834
+ const width = Math.max(0, Math.trunc(Number(msg?.width || 0)));
835
+ const height = Math.max(0, Math.trunc(Number(msg?.height || 0)));
836
+ const fps = Math.max(1, Math.trunc(Number(msg?.fps || 0)) || 1);
837
+ const orientation = Math.trunc(Number(msg?.orientation || 0));
838
+ const format = Math.trunc(Number(msg?.format || 0));
839
+ const timestamp = Math.trunc(Number(msg?.timestamp || 0));
840
+ if (!moduleRef ||
841
+ typeof moduleRef._malloc !== "function" ||
842
+ typeof moduleRef._free !== "function" ||
843
+ typeof sendFrameFn !== "function" ||
844
+ !(frameBuffer instanceof ArrayBuffer || ArrayBuffer.isView(frameBuffer))) {
845
+ return;
846
+ }
847
+ const bytes = ArrayBuffer.isView(frameBuffer)
848
+ ? new Uint8Array(frameBuffer.buffer, frameBuffer.byteOffset, frameBuffer.byteLength)
849
+ : new Uint8Array(frameBuffer);
850
+ if (bytes.byteLength === 0 || width <= 0 || height <= 0) {
851
+ return;
852
+ }
853
+ if (!jsWorkerRawVideoFramePtr || jsWorkerRawVideoFrameSize < bytes.byteLength) {
854
+ releaseJsWorkerRawVideoFrameBuffer(moduleRef);
855
+ jsWorkerRawVideoFramePtr = Number(moduleRef._malloc(bytes.byteLength)) || 0;
856
+ jsWorkerRawVideoFrameSize = jsWorkerRawVideoFramePtr ? bytes.byteLength : 0;
857
+ }
858
+ if (!jsWorkerRawVideoFramePtr || jsWorkerRawVideoFrameSize < bytes.byteLength) {
859
+ return;
860
+ }
861
+ moduleRef.GROWABLE_HEAP_U8().set(bytes, jsWorkerRawVideoFramePtr);
862
+ try {
863
+ sendFrameFn.call(moduleRef, jsWorkerRawVideoFramePtr, bytes.byteLength, width, height, fps, format, orientation);
864
+ }
865
+ catch (error) {
866
+ if (error?.name !== "BindingError") {
867
+ throw error;
868
+ }
869
+ try {
870
+ sendFrameFn.call(moduleRef, jsWorkerRawVideoFramePtr, bytes.byteLength, width, height, fps, format);
871
+ }
872
+ catch (legacyError) {
873
+ if (legacyError?.name !== "BindingError") {
874
+ throw legacyError;
875
+ }
876
+ sendFrameFn.call(moduleRef, jsWorkerRawVideoFramePtr, bytes.byteLength, width, height, orientation, format, timestamp);
877
+ }
878
+ }
879
+ };
880
+ function f(t) {
881
+ try {
882
+ if (t.cmd === "load") {
883
+ const wasmModule = t.wasmModule;
884
+ const wasmMemory = t.wasmMemory;
885
+ const workerID = t.workerID;
886
+ const handlers = t.handlers;
887
+ const pendingMessages = [];
888
+ function g(msg) {
889
+ pendingMessages.push(msg);
890
+ }
891
+ e.removeMessageListener("cmd", f);
892
+ e.addMessageListener("cmd", g);
893
+ global.self.startWorker = function (module) {
894
+ global.self.__waModule = module;
895
+ global.__waModule = module;
896
+ s = module;
897
+ e.postMessage({ type: "cmd", cmd: "loaded" });
898
+ for (const msg of pendingMessages)
899
+ f(msg);
900
+ e.removeMessageListener("cmd", g);
901
+ e.addMessageListener("cmd", f);
902
+ };
903
+ s.wasmModule = wasmModule;
904
+ function h(name) {
905
+ s[name] = function () {
906
+ const args = Array.from(arguments);
907
+ e.postMessage({
908
+ type: "cmd",
909
+ cmd: "callHandler",
910
+ callHandler: { handler: name, args: args },
911
+ });
912
+ };
913
+ }
914
+ for (const handler of handlers)
915
+ h(handler);
916
+ s.wasmMemory = wasmMemory;
917
+ s.buffer = s.wasmMemory.buffer;
918
+ s.workerID = workerID;
919
+ s.ENVIRONMENT_IS_PTHREAD = true;
920
+ if (!s.WhatsAppVoipWasmWorkerCompatibleCallbacks) {
921
+ s.WhatsAppVoipWasmWorkerCompatibleCallbacks =
922
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
923
+ }
924
+ if (wasmLoader) {
925
+ hideNodeEnv();
926
+ wasmLoader(s).then(asyncToGeneratorRuntime.asyncToGenerator(function* (module) {
927
+ if (!module.WhatsAppVoipWasmWorkerCompatibleCallbacks) {
928
+ module.WhatsAppVoipWasmWorkerCompatibleCallbacks =
929
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
930
+ }
931
+ if (!s.WhatsAppVoipWasmWorkerCompatibleCallbacks?.loggingCallback) {
932
+ s.WhatsAppVoipWasmWorkerCompatibleCallbacks =
933
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks;
934
+ }
935
+ _ = module;
936
+ try {
937
+ yield WAWebVoipPersistentFS.initPersistentFS(_);
938
+ }
939
+ catch (err) { }
940
+ }));
941
+ }
942
+ else {
943
+ e.postMessage({ type: "cmd", cmd: "loaded" });
944
+ }
945
+ }
946
+ else if (t.cmd === "run") {
947
+ const pthread_ptr = t.pthread_ptr;
948
+ if (s.__emscripten_thread_init)
949
+ s.__emscripten_thread_init(pthread_ptr, 0, 0, 1);
950
+ if (s.__emscripten_thread_mailbox_await)
951
+ s.__emscripten_thread_mailbox_await(pthread_ptr);
952
+ c(!!pthread_ptr, "pthread_ptr is required in event " + t.cmd);
953
+ if (s.establishStackSpace)
954
+ s.establishStackSpace();
955
+ if (s.PThread)
956
+ s.PThread.receiveObjectTransfer(t);
957
+ if (s.PThread)
958
+ s.PThread.threadInitTLS();
959
+ if (!u) {
960
+ if (s.__embind_initialize_bindings)
961
+ s.__embind_initialize_bindings();
962
+ u = true;
963
+ }
964
+ try {
965
+ if (s.invokeEntryPoint)
966
+ s.invokeEntryPoint(t.start_routine, t.arg);
967
+ }
968
+ catch (err) {
969
+ if (err !== "unwind")
970
+ throw err;
971
+ }
972
+ }
973
+ else if (t.cmd === "cancel") {
974
+ if (s._pthread_self && s._pthread_self()) {
975
+ if (s.__emscripten_thread_exit)
976
+ s.__emscripten_thread_exit(-1);
977
+ }
978
+ }
979
+ else if (t.target !== "setimmediate") {
980
+ if (t.cmd === "checkMailbox") {
981
+ if (u && s.checkMailbox)
982
+ s.checkMailbox();
983
+ }
984
+ else if (t.cmd === "jsWorkerCmd") {
985
+ return;
986
+ }
987
+ else if (t.cmd) {
988
+ p("worker.js received unknown command " + t.cmd);
989
+ p(t);
990
+ }
991
+ }
992
+ }
993
+ catch (err) {
994
+ p("worker.js onmessage() captured an uncaught exception: " + err);
995
+ if (err?.stack)
996
+ p(err.stack);
997
+ if (s.__emscripten_thread_crashed)
998
+ s.__emscripten_thread_crashed();
999
+ throw err;
1000
+ }
1001
+ }
1002
+ e.addMessageListener("cmd", f);
1003
+ e.addMessageListener("jsWorkerCmd", function (msg) {
1004
+ try {
1005
+ if (msg?.jsWorkerCmd === "pushRawVideoFrame") {
1006
+ return handleRawVideoFrameOnJsWorker(msg);
1007
+ }
1008
+ if (msg?.jsWorkerCmd === "releaseRawVideoFrameBuffer") {
1009
+ return releaseJsWorkerRawVideoFrameBuffer(getActiveWasmModule());
1010
+ }
1011
+ return WAWebVoipJsWorkerMessageHandler.handleJsWorkerMessage(_, msg);
1012
+ }
1013
+ catch (err) {
1014
+ throw err;
1015
+ }
1016
+ });
1017
+ e.addMessageListener("waWasmWorkerCompatibleCallback", function (msg) {
1018
+ const callbackName = msg.__name;
1019
+ if (!callbackName)
1020
+ return;
1021
+ if (!global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks)
1022
+ return;
1023
+ if (typeof global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks[callbackName] !== "function")
1024
+ return;
1025
+ try {
1026
+ if (["startCaptureJS", "startPlaybackJS", "stopCaptureJS", "stopPlaybackJS"].includes(callbackName)) {
1027
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks[callbackName]();
1028
+ }
1029
+ else {
1030
+ const args = {};
1031
+ for (const key in msg) {
1032
+ if (key !== "type" && key !== "__name" && !key.startsWith("__"))
1033
+ args[key] = msg[key];
1034
+ }
1035
+ global.self.WhatsAppVoipWasmWorkerCompatibleCallbacks[callbackName](args);
1036
+ }
1037
+ }
1038
+ catch (err) { }
1039
+ });
1040
+ if (parentPort) {
1041
+ parentPort.postMessage({ type: "worker_ready" });
1042
+ }