@x4r1s3/baileys 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -4,13 +4,13 @@
4
4
 
5
5
  The intelligent interactive and productivity layer for WhatsApp protocols.
6
6
 
7
- <img src="https://readme-typing-svg.demolab.com?font=Space+Mono&size=22&pause=1200&color=00FFF0&center=true&vCenter=true&width=900&height=70&repeat=true&lines=BAILEYS+PROTOCOL.;NODE.JS+%2B+TYPESCRIPT.;RICH+MESSAGES+%2B+MEDIA.;BUILD+RELIABLE+INTEGRATIONS." alt="X4R1S3 TECHNOLOGY Baileys animated keywords" />
7
+ <img src="https://readme-typing-svg.demolab.com?font=Space+Mono&size=22&pause=1200&color=00FFF0&center=true&vCenter=true&width=900&height=70&repeat=true&lines=BAILEYS+PROTOCOL.;NODE.JS+%2B+TYPESCRIPT.;RICH+MESSAGES+%2B+MEDIA.;BUILD+RELIABLE+INTEGRATIONS." alt="X4R1S3 INNOVATIONS Baileys animated keywords" />
8
8
 
9
- <a href="https://github.com/X4R1S3/baileys"><img src="./assets/x4r1s3-banner.svg" width="92%" alt="X4R1S3 TECHNOLOGY Baileys banner" /></a>
9
+ <a href="https://github.com/X4R1S3/baileys"><img src="./assets/x4r1s3-banner.svg" width="92%" alt="X4R1S3 INNOVATIONS Baileys banner" /></a>
10
10
 
11
11
  <a href="https://github.com/X4R1S3/ASTRALENA/blob/main/assets/rolling-circle.svg"><img src="./assets/rolling-circle.svg" width="110" alt="ASTRALENA rolling circle by X4R1S3" /></a>
12
12
 
13
- [![Version](https://img.shields.io/badge/version-1.0.0-00FFF0?style=for-the-badge&labelColor=07111F)](https://www.npmjs.com/package/@x4r1s3/baileys)
13
+ [![Version](https://img.shields.io/badge/version-1.0.1-00FFF0?style=for-the-badge&labelColor=07111F)](https://www.npmjs.com/package/@x4r1s3/baileys)
14
14
  [![Node.js](https://img.shields.io/badge/node-%3E%3D20-7CFFB2?style=for-the-badge&logo=node.js&logoColor=white&labelColor=07111F)](https://nodejs.org/)
15
15
  [![Powered by X4R1S3 INNOVATIONS](https://img.shields.io/badge/powered%20by-X4R1S3%20INNOVATIONS-25D366?style=for-the-badge&logo=whatsapp&logoColor=white&labelColor=07111F)](https://www.npmjs.com/package/@x4r1s3/baileys)
16
16
  [![License](https://img.shields.io/badge/license-MIT-B88CFF?style=for-the-badge&labelColor=07111F)](#license-and-maintenance)
@@ -21,7 +21,7 @@ The intelligent interactive and productivity layer for WhatsApp protocols.
21
21
 
22
22
  `@x4r1s3/baileys` is a Node.js and TypeScript library for creating WhatsApp automations over the Baileys protocol. It provides a socket-oriented API for authentication, messaging, media, interactive content, rich responses, newsletters, groups, communities, business features, account utilities, and carefully documented extensions.
23
23
 
24
- The package is maintained by **X4R1S3** under the **X4R1S3 TECHNOLOGY** organization. It is intended for developers who want a practical Baileys foundation with familiar interfaces, public TypeScript declarations, readable source code, explicit behavior, and room for carefully tested improvements.
24
+ The package is maintained by **X4R1S3** under the **X4R1S3 INNOVATIONS** organization. It is intended for developers who want a practical Baileys foundation with familiar interfaces, public TypeScript declarations, readable source code, explicit behavior, and room for carefully tested improvements.
25
25
 
26
26
  ## Table of contents
27
27
 
@@ -43,6 +43,7 @@ The package is maintained by **X4R1S3** under the **X4R1S3 TECHNOLOGY** organiza
43
43
  - [Disclaimer](#disclaimer)
44
44
  - [Privacy policy](#privacy-policy)
45
45
  - [License and maintenance](#license-and-maintenance)
46
+ - [Acknowledgement](#acknowledgement)
46
47
  - [Compatibility additions](#compatibility-additions)
47
48
  - [Comparison references](#comparison-references)
48
49
  - [Additional functional compatibility helpers](#additional-functional-compatibility-helpers)
@@ -54,7 +55,7 @@ The package is maintained by **X4R1S3** under the **X4R1S3 TECHNOLOGY** organiza
54
55
  | Property | Value |
55
56
  | --- | --- |
56
57
  | Package | `@x4r1s3/baileys` |
57
- | Version | `1.0.0` |
58
+ | Version | `1.0.1` |
58
59
  | Runtime | Node.js 20 or newer |
59
60
  | Module format | ESM, with CommonJS compatibility where supported |
60
61
  | Type declarations | Included at `lib/index.d.ts` |
@@ -69,7 +70,7 @@ The package is maintained by **X4R1S3** under the **X4R1S3 TECHNOLOGY** organiza
69
70
  | Method | Command | Notes |
70
71
  | --- | --- | --- |
71
72
  | From npm | `npm install @x4r1s3/baileys` | Standard install when published under your organization |
72
- | From local archive | `npm install ./X4R1S3-baileys-1.0.0.tgz` | Place the `.tgz` beside your application |
73
+ | From local archive | `npm install ./X4R1S3-baileys-1.0.1.tgz` | Place the `.tgz` beside your application |
73
74
  | Source audit (no scripts) | `npm install --ignore-scripts` | Skips install hooks for local review |
74
75
 
75
76
  Both npm and archive installs use the same import name:
@@ -281,7 +282,7 @@ await sock.richMenu(jid, {
281
282
  ]
282
283
  },
283
284
  footer: {
284
- text: 'X4R1S3 TECHNOLOGY',
285
+ text: 'X4R1S3 INNOVATIONS',
285
286
  url: 'https://example.com'
286
287
  }
287
288
  })
@@ -415,11 +416,11 @@ Please do not publish credentials, session files, personal data, exploit details
415
416
 
416
417
  This project provides general-purpose developer tooling. A feature being available in the library does not mean that every possible use of that feature is lawful, safe, authorized, or permitted by WhatsApp. Developers must review WhatsApp’s current terms, business policies, developer requirements, applicable privacy and communications laws, and the rules of every service they connect to before deploying an application.
417
418
 
418
- X4R1S3, X4R1S3 TECHNOLOGY, its contributors, and maintainers do not operate or control third-party applications, accounts, deployments, recipient lists, message content, credentials, or infrastructure built with this package. Each developer and operator is solely responsible for authorization, consent, security, content, compliance, rate limiting, user notices, data protection, and all consequences of their deployment. This includes account restrictions, suspensions, bans, message delivery failures, data loss, privacy incidents, legal claims, financial loss, and harm caused by misuse or by changes to WhatsApp’s systems.
419
+ X4R1S3, X4R1S3 INNOVATIONS, its contributors, and maintainers do not operate or control third-party applications, accounts, deployments, recipient lists, message content, credentials, or infrastructure built with this package. Each developer and operator is solely responsible for authorization, consent, security, content, compliance, rate limiting, user notices, data protection, and all consequences of their deployment. This includes account restrictions, suspensions, bans, message delivery failures, data loss, privacy incidents, legal claims, financial loss, and harm caused by misuse or by changes to WhatsApp’s systems.
419
420
 
420
421
  To the fullest extent permitted by applicable law, the project and its maintainers are not liable for any direct, indirect, incidental, special, consequential, exemplary, or punitive loss arising from use of, inability to use, or reliance on this package or on an application built with it. The software is provided **“as is” and “as available,” without warranties**, including warranties of merchantability, fitness for a particular purpose, non-infringement, security, availability, compatibility, or uninterrupted operation. No statement in this README guarantees account standing, access to WhatsApp, message delivery, protocol stability, or compliance for a particular deployment.
421
422
 
422
- This disclaimer does not authorize harmful use. The project supports useful, consent-based, transparent automation and interoperable tooling only. Anyone who violates WhatsApp’s rules or applicable law does so independently and may not represent that X4R1S3 or X4R1S3 TECHNOLOGY directed, approved, or accepted that conduct.
423
+ This disclaimer does not authorize harmful use. The project supports useful, consent-based, transparent automation and interoperable tooling only. Anyone who violates WhatsApp’s rules or applicable law does so independently and may not represent that X4R1S3 or X4R1S3 INNOVATIONS directed, approved, or accepted that conduct.
423
424
 
424
425
  ## Privacy policy
425
426
 
@@ -430,11 +431,11 @@ This section describes what the package itself does and does not do with data. I
430
431
  | Data type | How it's handled |
431
432
  | --- | --- |
432
433
  | Authentication/session state | Generated and stored wherever your application configures it (e.g. `useMultiFileAuthState('./session')`). The package does not upload this elsewhere. Keep it private, as noted in [Security and responsible use](#security-and-responsible-use). |
433
- | Messages and media | Sent to and received from WhatsApp's own servers as part of normal protocol operation. The package does not copy, log, or relay this content to X4R1S3, X4R1S3 TECHNOLOGY, or any other third party. |
434
- | Phone numbers passed to optional helpers | `checkStatusWA` sends a phone number to whatever endpoint you configure for that call. This only happens if your code explicitly calls it; the destination and its own privacy practices are your responsibility to review before use. |
434
+ | Messages and media | Sent to and received from WhatsApp's own servers as part of normal protocol operation. The package does not copy, log, or relay this content to X4R1S3, X4R1S3 INNOVATIONS, or any other third party. |
435
+ | Phone numbers passed to optional network helpers | Any phone number is sent only to the endpoint configured by your application when you explicitly call the relevant helper; review that destination and its own privacy practices before use. |
435
436
 
436
437
  **What the package does not do:**
437
- - It does not phone home, run analytics/telemetry, or transmit usage data to X4R1S3, X4R1S3 TECHNOLOGY, or any other party.
438
+ - It does not phone home, run analytics/telemetry, or transmit usage data to X4R1S3, X4R1S3 INNOVATIONS, or any other party.
438
439
  - It does not embed hidden credentials, tracking identifiers, or remote "kill switches."
439
440
  - It does not access data outside of what your application explicitly wires it up to.
440
441
 
@@ -446,7 +447,13 @@ This section describes what the package itself does and does not do with data. I
446
447
 
447
448
  This distribution is provided under the license declared in `package.json` and the accompanying license file. Review those terms before redistributing or combining this package with third-party code.
448
449
 
449
- **@x4r1s3/baileys is built and maintained by X4R1S3 under the X4R1S3 TECHNOLOGY organization.** Contributions, bug reports, and carefully documented improvements are welcome through the project repository.
450
+ **@x4r1s3/baileys is developed and maintained by X4R1S3 under the X4R1S3 INNOVATIONS organization.** Contributions, bug reports, and carefully documented improvements are welcome through the project repository.
451
+
452
+ ### Acknowledgement
453
+
454
+ This X4R1S3 distribution is a downstream fork and enhancement built within the [plogme](https://www.npmjs.com/package/plogme) source, authored by **crysnovax**. The plogme/CODY lineage supplies the underlying Baileys protocol structure and foundational APIs used here. X4R1S3 remains the developer and maintainer of this fork, with its own branding, documentation, and distribution under X4R1S3 INNOVATIONS.
455
+
456
+ **Reference keywords:** X4R1S3, X4R1S3 INNOVATIONS, X4R1S3 TECHNOLOGY, Baileys, WhatsApp, WhatsApp Web, WhatsApp chat, WhatsApp API, WhatsApp automation, WhatsApp protocol, rich messages, AIRich, A2UI, Gen4 menus, albums, video grids, Node.js, and TypeScript.
450
457
 
451
458
  ## Compatibility additions
452
459
 
@@ -493,30 +500,6 @@ const html = generateSlotMachineHtml({
493
500
 
494
501
  The generator does not by itself send HTML through WhatsApp. Applications should only use an HTML-capable message primitive when that primitive is available and authorized for their deployment.
495
502
 
496
- ### Optional ban-status checker
497
-
498
- `checkStatusWA` is an explicit, caller-invoked diagnostic helper. It is never called during installation, socket creation, reconnection, or message sending. The endpoint is configurable, credentials are not embedded, and callers should review the endpoint's terms and privacy implications before sending a phone number.
499
-
500
- ```javascript
501
- import { checkStatusWA } from '@x4r1s3/baileys'
502
-
503
- const result = await checkStatusWA('+447700900123', {
504
- diagnostic: true
505
- })
506
- console.log(result.status) // active, banned, blocked, not_registered, rate_limited, or unknown
507
- ```
508
-
509
- | Status value | Meaning |
510
- | --- | --- |
511
- | `active` | Number appears active on WhatsApp |
512
- | `banned` | Number appears banned |
513
- | `blocked` | Number appears blocked |
514
- | `not_registered` | Number is not registered on WhatsApp |
515
- | `rate_limited` | Check was rate limited |
516
- | `unknown` | Status could not be determined |
517
-
518
- This helper is not an anti-ban guarantee, does not bypass enforcement, and should not be used for bulk enumeration or unsolicited checking.
519
-
520
503
  ## Comparison references
521
504
 
522
505
  The feature comparison was based on the published package metadata and documentation available from [npm][1] and the independent package analysis page at [Socket][2]. The X4R1S3 implementation adds compatible behavior through readable, package-owned code rather than copying upstream-specific integrity, attribution, or remote-verification mechanisms.
@@ -778,7 +761,7 @@ await sock.sendAIRichCommandMenu(jid, {
778
761
  buttons: [
779
762
  { id: 'docs', text: 'Documentation', url: 'https://example.com/docs' }
780
763
  ],
781
- footer: 'Developed by - X4R1S3 TECHNOLOGY'
764
+ footer: 'Developed by - X4R1S3 INNOVATIONS'
782
765
  })
783
766
  ```
784
767
 
@@ -864,7 +847,7 @@ The compatibility update also exposes `sendRichHtmlMessage`, which uses the inte
864
847
  ```ts
865
848
  const jid = '15551234567@s.whatsapp.net'
866
849
  await sock.sendRichHtmlMessage(jid, {
867
- title: 'X4R1S3 TECHNOLOGY',
850
+ title: 'X4R1S3 INNOVATIONS',
868
851
  html: '<h1>Hello</hi>',
869
852
  url: 'https://X4R1S3-ai.site',
870
853
  trustedSources: ['X4R1S3-ai.site']
@@ -1220,7 +1203,7 @@ const commandOutput = 'X4R1S3 command completed'
1220
1203
  await sock.sendInteractiveContactCard(jid, {
1221
1204
  title: 'X4R1S3',
1222
1205
  body: commandOutput,
1223
- footer: 'X4R1S3 TECHNOLOGY',
1206
+ footer: 'X4R1S3 INNOVATIONS',
1224
1207
  buttonParams: {
1225
1208
  command: commandName,
1226
1209
  status: 'completed'
@@ -1258,6 +1241,6 @@ await sock.X4R1S3(jid, { id: messageId })
1258
1241
 
1259
1242
  <sub>Thanks for reading my README.</sub>
1260
1243
 
1261
- [![X4R1S3 TECHNOLOGY](https://img.shields.io/badge/X4R1S3%20TECHNOLOGY-Baileys-00FFF0?style=for-the-badge&labelColor=07111F)](https://github.com/X4R1S3/baileys)
1244
+ [![X4R1S3 INNOVATIONS](https://img.shields.io/badge/X4R1S3%20INNOVATIONS-Baileys-00FFF0?style=for-the-badge&labelColor=07111F)](https://github.com/X4R1S3/baileys)
1262
1245
 
1263
1246
  </div>
@@ -1,5 +1,5 @@
1
1
  <svg width="1200" height="220" viewBox="0 0 1200 220" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="title desc">
2
- <title id="title">X4R1S3 TECHNOLOGY Baileys banner</title>
2
+ <title id="title">X4R1S3 INNOVATIONS Baileys banner</title>
3
3
  <desc id="desc">A branded banner for the X4R1S3 Baileys protocol toolkit.</desc>
4
4
  <defs>
5
5
  <linearGradient id="background" x1="0" y1="0" x2="1200" y2="220" gradientUnits="userSpaceOnUse">
@@ -26,7 +26,7 @@
26
26
  <path d="M70 176C250 52 410 216 600 120C790 24 950 188 1130 64" stroke="url(#accent)" stroke-opacity="0.78" stroke-width="2"/>
27
27
  <circle cx="1070" cy="64" r="7" fill="#00FFF0" filter="url(#softGlow)"/>
28
28
  <circle cx="1070" cy="64" r="3" fill="#D9FFFF"/>
29
- <text x="70" y="88" fill="#F4FFFF" font-family="Space Mono, ui-monospace, SFMono-Regular, Menlo, monospace" font-size="34" font-weight="700" letter-spacing="4">X4R1S3 TECHNOLOGY</text>
29
+ <text x="70" y="88" fill="#F4FFFF" font-family="Space Mono, ui-monospace, SFMono-Regular, Menlo, monospace" font-size="34" font-weight="700" letter-spacing="4">X4R1S3 INNOVATIONS</text>
30
30
  <text x="72" y="132" fill="url(#accent)" font-family="Space Mono, ui-monospace, SFMono-Regular, Menlo, monospace" font-size="24" font-weight="700" letter-spacing="2">@x4r1s3/baileys</text>
31
31
  <text x="74" y="166" fill="#C7D4F4" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="16" letter-spacing="1">RESPONSIBLE • INSPECTABLE • RELIABLE WHATSAPP PROTOCOL TOOLING</text>
32
32
  </svg>
@@ -0,0 +1,96 @@
1
+ /**
2
+ * CODY V2 same-socket VoIP orchestration for Plogme.
3
+ *
4
+ * This controller does not create a second Baileys client or authentication
5
+ * directory. It wraps the existing Plogme VoipClient and keeps the call
6
+ * lifecycle in the same CODY WhatsApp session.
7
+ *
8
+ * Based on @crysnovax/baileys by Crysnovax.
9
+ */
10
+ import { EventEmitter } from 'node:events';
11
+ import { VoipClient } from './index.mjs';
12
+
13
+ const asBoolean = (value, fallback = false) => {
14
+ if (value === undefined || value === null || value === '') return fallback;
15
+ return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
16
+ };
17
+
18
+ export class AstralenaV3VoipClient extends EventEmitter {
19
+ #client;
20
+ #config;
21
+ #bound = false;
22
+ #activeCalls = new Map();
23
+ #onIncoming;
24
+ #onEnded;
25
+
26
+ constructor(config = {}) {
27
+ super();
28
+ if (!config.sock) {
29
+ throw new Error('AstralenaV3VoipClient requires the existing Astralena socket as { sock }.');
30
+ }
31
+ this.#config = { ...config };
32
+ this.#client = config.client || new VoipClient(config);
33
+ this.#onIncoming = info => this.#handleIncoming(info);
34
+ this.#onEnded = info => this.#handleEnded(info);
35
+ }
36
+
37
+ get client() { return this.#client; }
38
+ get activeCalls() { return [...this.#activeCalls.values()]; }
39
+
40
+ async connect() {
41
+ this.#client.on('incomingCall', this.#onIncoming);
42
+ this.#client.on('incomingCallEnded', this.#onEnded);
43
+ this.#bound = true;
44
+ try {
45
+ await this.#client.connect();
46
+ this.emit('ready', { client: this.#client });
47
+ return this;
48
+ } catch (error) {
49
+ this.disconnectListeners();
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ async disconnect() {
55
+ this.disconnectListeners();
56
+ await this.#client.disconnect();
57
+ this.#activeCalls.clear();
58
+ }
59
+
60
+ disconnectListeners() {
61
+ if (!this.#bound) return;
62
+ this.#client.off('incomingCall', this.#onIncoming);
63
+ this.#client.off('incomingCallEnded', this.#onEnded);
64
+ this.#bound = false;
65
+ }
66
+
67
+ answerIncomingCall(callId, options = {}) {
68
+ return this.#client.answerIncomingCall(callId, options);
69
+ }
70
+
71
+ rejectIncomingCall(callId) {
72
+ return this.#client.rejectIncomingCall(callId);
73
+ }
74
+
75
+ #handleIncoming(info) {
76
+ this.emit('incomingCall', info);
77
+ const autoAnswer = this.#config.autoAnswer ?? asBoolean(process.env.ASTRALENAV3_VOIP_AUTO_ANSWER, false);
78
+ if (!autoAnswer || info?.isVideo && this.#config.answerVideo !== true) return;
79
+ void this.answerIncomingCall(info.callId, this.#config.answerOptions || {})
80
+ .then(call => {
81
+ this.#activeCalls.set(info.callId, call);
82
+ call.once('ended', () => this.#activeCalls.delete(info.callId));
83
+ this.emit('callAnswered', call, info);
84
+ })
85
+ .catch(error => this.emit('answerError', error, info));
86
+ }
87
+
88
+ #handleEnded(info) {
89
+ if (info?.callId) this.#activeCalls.delete(info.callId);
90
+ this.emit('incomingCallEnded', info);
91
+ }
92
+ }
93
+
94
+ export const createAstralenaV3VoipClient = config => new AstralenaV3VoipClient(config);
95
+
96
+ export { asBoolean as astralenaV3Boolean };
@@ -21,6 +21,7 @@ export class AudioFeeder {
21
21
  #queue = [];
22
22
  #emitTimer = null;
23
23
  #nextEmitAtMs = 0;
24
+ #chunkIntervalMs = 0;
24
25
  #warmupUntilMs = 0;
25
26
  #started = false;
26
27
  #chunkSamples = 0;
@@ -45,6 +46,7 @@ export class AudioFeeder {
45
46
  this.#chunkSamples = this.framesPerChunk * this.channels;
46
47
  this.#chunkBytes = this.#chunkSamples * Float32Array.BYTES_PER_ELEMENT;
47
48
  const chunkIntervalMs = (this.framesPerChunk / this.sampleRate) * 1000;
49
+ this.#chunkIntervalMs = chunkIntervalMs;
48
50
 
49
51
  if (this.source && typeof this.source !== "string") {
50
52
  if (typeof this.source.on !== "function") {
@@ -91,6 +93,26 @@ export class AudioFeeder {
91
93
  this.#scheduleNext(chunkIntervalMs);
92
94
  };
93
95
 
96
+ /** Queue interleaved Float32 PCM for an already-running call. */
97
+ enqueuePcm = (pcm) => {
98
+ if (!this.#started) this.start();
99
+ if (!(pcm instanceof Float32Array)) {
100
+ if (ArrayBuffer.isView(pcm)) {
101
+ pcm = new Float32Array(pcm.buffer, pcm.byteOffset, Math.floor(pcm.byteLength / Float32Array.BYTES_PER_ELEMENT));
102
+ } else if (pcm instanceof ArrayBuffer) {
103
+ pcm = new Float32Array(pcm);
104
+ } else {
105
+ throw new TypeError("PCM must be a Float32Array or an ArrayBuffer view.");
106
+ }
107
+ }
108
+ if (pcm.length === 0) return;
109
+ this.#ingest(Buffer.from(pcm.buffer, pcm.byteOffset, pcm.byteLength));
110
+ if (!this.#emitTimer && this.#queue.length > 0) {
111
+ this.#nextEmitAtMs = Date.now();
112
+ this.#scheduleNext(this.#chunkIntervalMs);
113
+ }
114
+ };
115
+
94
116
  stop = () => {
95
117
  if (this.#emitTimer) {
96
118
  clearTimeout(this.#emitTimer);
@@ -21,6 +21,7 @@ import { AudioFeeder } from "./audio-feeder.mjs";
21
21
  import { VideoFeeder } from "./video-feeder.mjs";
22
22
  import { CallRecorder } from "./audio-recorder.mjs";
23
23
  import { CallState } from "./types.mjs";
24
+ import { ensureVoipResources } from "./voip-resources.mjs";
24
25
  export { CallState } from "./types.mjs";
25
26
  const SHA256_LEN = 32;
26
27
  const loadBaileys = async () => {
@@ -85,6 +86,8 @@ export class ActiveCall extends EventEmitter {
85
86
  isVideo = false;
86
87
  /** @internal mirrors the source path for the audio feeder */
87
88
  _audioSource = "silence";
89
+ /** @internal live outbound PCM feeder */
90
+ _audioFeeder = null;
88
91
  /** @internal async iterable of raw NV12 frames */
89
92
  _videoSource = null;
90
93
  constructor(callId, engine, durationMs, { direction = "outgoing", peerJid = "" } = {}) {
@@ -125,6 +128,14 @@ export class ActiveCall extends EventEmitter {
125
128
  }
126
129
  catch { }
127
130
  };
131
+ /** Queue interleaved Float32 PCM for playback on this active call. */
132
+ writeAudio = (pcm) => {
133
+ if (this.#ended)
134
+ throw new Error("Cannot write audio after the call has ended.");
135
+ if (!this._audioFeeder)
136
+ throw new Error("Call audio playback is not ready yet.");
137
+ this._audioFeeder.enqueuePcm(pcm);
138
+ };
128
139
  /** Request enabling local video on this active audio call. */
129
140
  requestVideoUpgrade = (videoSource) => {
130
141
  if (!this.#videoUpgradeHandler)
@@ -133,6 +144,8 @@ export class ActiveCall extends EventEmitter {
133
144
  };
134
145
  /** @internal */
135
146
  _setVideoUpgradeHandler = (handler) => { this.#videoUpgradeHandler = handler; };
147
+ /** @internal */
148
+ _setAudioFeeder = (feeder) => { this._audioFeeder = feeder; };
136
149
  waitForEnd = () => this.#endPromise;
137
150
  waitForRecording = () => this.#recordingDone;
138
151
  /** @internal — called by VoipClient on WASM call-state change */
@@ -171,6 +184,7 @@ export class ActiveCall extends EventEmitter {
171
184
  const recorder = this.#recorder;
172
185
  this.#recorder = null;
173
186
  this._videoSource = null;
187
+ this._audioFeeder = null;
174
188
  this.#recordingDone = recorder?.close?.() ?? Promise.resolve(undefined);
175
189
  this.#recordingDone.then((result) => {
176
190
  if (result) this.emit("recordingComplete", result);
@@ -212,7 +226,18 @@ export class VoipClient extends EventEmitter {
212
226
  }
213
227
  /** Connect to WhatsApp and bring up the WASM VoIP stack. */
214
228
  connect = async () => {
215
- const resourcesPath = this.#config.resourcesPath ?? process.env.X4R1S3_VOIP_RESOURCES;
229
+ const resourcesPath = this.#config.resourcesPath ?? process.env.X4R1S3_VOIP_RESOURCES ?? "call-resources";
230
+ if (this.#config.autoFetchResources) {
231
+ await ensureVoipResources({
232
+ resourcesPath,
233
+ sock: this.#config.sock,
234
+ resourceProvider: this.#config.resourceProvider,
235
+ runtimePackage: this.#config.runtimePackage,
236
+ resourceUrls: this.#config.resourceUrls,
237
+ debuggerUrl: this.#config.debuggerUrl,
238
+ wasmId: this.#config.wasmId,
239
+ });
240
+ }
216
241
  const wasmPath = this.#config.wasmPath ? resolve(this.#config.wasmPath) : resourcesPath ? join(resolve(resourcesPath), "assets", "wasm", "whatsapp.wasm") : undefined;
217
242
  const workerPath = resourcesPath ? join(resolve(resourcesPath), "assets", "wasm", "worker-modules.js") : undefined;
218
243
  if (!this.#config.wasmBinary && (!wasmPath || !existsSync(wasmPath))) {
@@ -570,10 +595,12 @@ export class VoipClient extends EventEmitter {
570
595
  if (this.#engine && this.#capturePtr)
571
596
  this.#engine.sendAudioData(chunk, this.#capturePtr);
572
597
  }, audioSource);
598
+ this.#activeCall?._setAudioFeeder(this.#feeder);
573
599
  this.#feeder.start();
574
600
  };
575
601
  #handleAudioCaptureStop = () => {
576
602
  this.#feeder?.stop();
603
+ this.#activeCall?._setAudioFeeder(null);
577
604
  this.#feeder = null;
578
605
  if (this.#engine && this.#capturePtr) {
579
606
  try {
@@ -345,6 +345,7 @@ export class SignalingBridge {
345
345
  const tcToken = await this.ensureTcToken(routedPeerJid, callbackPeerJid);
346
346
  switch (usableNode.tag) {
347
347
  case "offer":
348
+ await this.#sendOfferReceipt(node, usableNode);
348
349
  voip.handleSignalingOffer({
349
350
  payload: b64,
350
351
  peerPlatform: Number(platform || 0),
@@ -402,6 +403,24 @@ export class SignalingBridge {
402
403
  break;
403
404
  }
404
405
  };
406
+ /** A valid incoming offer must be acknowledged before answer signaling. */
407
+ #sendOfferReceipt = async (callNode, offerNode) => {
408
+ const to = String(callNode.attrs?.from ?? "").trim();
409
+ const stanzaId = String(callNode.attrs?.id ?? "").trim();
410
+ const callId = String(offerNode.attrs?.["call-id"] ?? offerNode.attrs?.call_id ?? "").trim();
411
+ const creator = String(offerNode.attrs?.["call-creator"] ?? offerNode.attrs?.call_creator ?? "").trim();
412
+ if (!to || !stanzaId || !callId || !creator || typeof this.#sock.sendNode !== "function") return;
413
+ try {
414
+ await this.#sock.sendNode({
415
+ tag: "receipt",
416
+ attrs: { to, id: stanzaId },
417
+ content: [{ tag: "offer", attrs: { "call-id": callId, "call-creator": creator } }],
418
+ });
419
+ }
420
+ catch {
421
+ // The generic server ack and WASM path remain useful on older servers.
422
+ }
423
+ };
405
424
  #doProcessIncomingReceipt = async (node, voip, activeCallId) => {
406
425
  const { getAllBinaryNodeChildren, encodeBinaryNode } = this.#baileys;
407
426
  const receiptChild = getAllBinaryNodeChildren(node)[0];