felixid 1.1.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.
Files changed (109) hide show
  1. package/WAProto/GenerateStatics.sh +4 -0
  2. package/WAProto/WAProto.proto +4775 -0
  3. package/WAProto/index.js +169661 -0
  4. package/WAProto/p.html +1 -0
  5. package/engine-requirements.js +10 -0
  6. package/lib/Defaults/index.js +120 -0
  7. package/lib/Defaults/wileys-version.json +3 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.js +96 -0
  11. package/lib/Signal/Group/index.js +57 -0
  12. package/lib/Signal/Group/keyhelper.js +55 -0
  13. package/lib/Signal/Group/queue-job.js +57 -0
  14. package/lib/Signal/Group/sender-chain-key.js +34 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  16. package/lib/Signal/Group/sender-key-message.js +69 -0
  17. package/lib/Signal/Group/sender-key-name.js +51 -0
  18. package/lib/Signal/Group/sender-key-record.js +53 -0
  19. package/lib/Signal/Group/sender-key-state.js +99 -0
  20. package/lib/Signal/Group/sender-message-key.js +29 -0
  21. package/lib/Signal/libsignal.js +174 -0
  22. package/lib/Socket/Client/index.js +18 -0
  23. package/lib/Socket/Client/types.js +13 -0
  24. package/lib/Socket/Client/websocket.js +72 -0
  25. package/lib/Socket/business.js +260 -0
  26. package/lib/Socket/chats.js +997 -0
  27. package/lib/Socket/groups.js +332 -0
  28. package/lib/Socket/index.js +10 -0
  29. package/lib/Socket/messages-recv.js +1106 -0
  30. package/lib/Socket/messages-send.js +874 -0
  31. package/lib/Socket/newsletter.js +286 -0
  32. package/lib/Socket/socket.js +648 -0
  33. package/lib/Socket/usync.js +70 -0
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/make-in-memory-store.js +439 -0
  36. package/lib/Store/make-ordered-dictionary.js +81 -0
  37. package/lib/Store/object-repository.js +27 -0
  38. package/lib/Types/Auth.js +2 -0
  39. package/lib/Types/Call.js +2 -0
  40. package/lib/Types/Chat.js +4 -0
  41. package/lib/Types/Contact.js +2 -0
  42. package/lib/Types/Events.js +2 -0
  43. package/lib/Types/GroupMetadata.js +2 -0
  44. package/lib/Types/Label.js +27 -0
  45. package/lib/Types/LabelAssociation.js +9 -0
  46. package/lib/Types/Message.js +7 -0
  47. package/lib/Types/Newsletter.js +18 -0
  48. package/lib/Types/Product.js +2 -0
  49. package/lib/Types/Signal.js +2 -0
  50. package/lib/Types/Socket.js +2 -0
  51. package/lib/Types/State.js +2 -0
  52. package/lib/Types/USync.js +2 -0
  53. package/lib/Types/index.js +42 -0
  54. package/lib/Utils/auth-utils.js +199 -0
  55. package/lib/Utils/browser-utils.js +35 -0
  56. package/lib/Utils/business.js +234 -0
  57. package/lib/Utils/chat-utils.js +730 -0
  58. package/lib/Utils/crypto.js +193 -0
  59. package/lib/Utils/decode-wa-message.js +217 -0
  60. package/lib/Utils/event-buffer.js +518 -0
  61. package/lib/Utils/generics.js +467 -0
  62. package/lib/Utils/history.js +94 -0
  63. package/lib/Utils/index.js +35 -0
  64. package/lib/Utils/link-preview.js +126 -0
  65. package/lib/Utils/logger.js +7 -0
  66. package/lib/Utils/lt-hash.js +51 -0
  67. package/lib/Utils/make-mutex.js +43 -0
  68. package/lib/Utils/message-retry-manager.js +128 -0
  69. package/lib/Utils/messages-media.js +879 -0
  70. package/lib/Utils/messages.js +1049 -0
  71. package/lib/Utils/noise-handler.js +150 -0
  72. package/lib/Utils/process-message.js +404 -0
  73. package/lib/Utils/signal.js +153 -0
  74. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  75. package/lib/Utils/validate-connection.js +229 -0
  76. package/lib/Utils/wileys-event-stream.js +63 -0
  77. package/lib/Voip/audio-feeder.js +166 -0
  78. package/lib/Voip/index.js +562 -0
  79. package/lib/Voip/relay-transport.js +829 -0
  80. package/lib/Voip/signaling.js +1092 -0
  81. package/lib/Voip/types.js +23 -0
  82. package/lib/Voip/wasm-engine.js +1255 -0
  83. package/lib/Voip/worker-bootstrap.js +1078 -0
  84. package/lib/WABinary/constants.js +1303 -0
  85. package/lib/WABinary/decode.js +265 -0
  86. package/lib/WABinary/encode.js +250 -0
  87. package/lib/WABinary/generic-utils.js +110 -0
  88. package/lib/WABinary/index.js +21 -0
  89. package/lib/WABinary/jid-utils.js +85 -0
  90. package/lib/WABinary/types.js +2 -0
  91. package/lib/WAM/BinaryInfo.js +13 -0
  92. package/lib/WAM/constants.js +15350 -0
  93. package/lib/WAM/encode.js +155 -0
  94. package/lib/WAM/index.js +19 -0
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  101. package/lib/WAUSync/Protocols/index.js +20 -0
  102. package/lib/WAUSync/USyncQuery.js +89 -0
  103. package/lib/WAUSync/USyncUser.js +26 -0
  104. package/lib/WAUSync/index.js +19 -0
  105. package/lib/assets/wasm/loader.js +5 -0
  106. package/lib/assets/wasm/whatsapp.wasm +0 -0
  107. package/lib/assets/wasm/worker-modules.js +273 -0
  108. package/lib/index.js +41 -0
  109. package/package.json +119 -0
@@ -0,0 +1,562 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoipClient = exports.ActiveCall = exports.CallState = void 0;
4
+
5
+ const events_1 = require("node:events");
6
+ const crypto_1 = require("node:crypto");
7
+ const path_1 = require("node:path");
8
+ const wasm_engine_js_1 = require("./wasm-engine.js");
9
+ const relay_transport_js_1 = require("./relay-transport.js");
10
+ const signaling_js_1 = require("./signaling.js");
11
+ const audio_feeder_js_1 = require("./audio-feeder.js");
12
+ const types_js_1 = require("./types.js");
13
+
14
+ Object.defineProperty(exports, "CallState", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return types_js_1.CallState;
18
+ }
19
+ });
20
+
21
+ const SHA256_LEN = 32;
22
+
23
+ const loadBaileys = async () => {
24
+ try {
25
+ return await import("../index.js");
26
+ } catch {
27
+ throw new Error("Could not import internal Erine Baileys module.");
28
+ }
29
+ };
30
+
31
+ const toBareJid = jid => {
32
+ if (!jid) return jid;
33
+ const value = String(jid);
34
+ const at = value.indexOf("@");
35
+ if (at < 0) return value;
36
+ const user = value.slice(0, at).split(":")[0];
37
+ return `${user}@${value.slice(at + 1)}`;
38
+ };
39
+
40
+ const toDeviceJid = jid => {
41
+ if (!jid) return jid;
42
+ const value = String(jid);
43
+ const at = value.indexOf("@");
44
+ if (at < 0) return value;
45
+ const user = value.slice(0, at).split(":")[0];
46
+ const server = value.slice(at + 1);
47
+ return `${user}:0@${server}`;
48
+ };
49
+
50
+ const computeHkdf = (key, salt, info, length) => {
51
+ const effectiveSalt = salt && salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(SHA256_LEN, 0);
52
+ const prk = (0, crypto_1.createHmac)("sha256", effectiveSalt).update(key).digest();
53
+ const blocks = Math.ceil(length / SHA256_LEN);
54
+ const okm = Buffer.alloc(blocks * SHA256_LEN);
55
+ let prev = Buffer.alloc(0);
56
+
57
+ for (let i = 1; i <= blocks; i += 1) {
58
+ prev = (0, crypto_1.createHmac)("sha256", prk)
59
+ .update(prev)
60
+ .update(info)
61
+ .update(Buffer.from([i]))
62
+ .digest();
63
+ prev.copy(okm, (i - 1) * SHA256_LEN);
64
+ }
65
+
66
+ return new Uint8Array(okm.buffer, okm.byteOffset, length);
67
+ };
68
+
69
+ const computeHmacSha256 = (data, key) => {
70
+ const result = (0, crypto_1.createHmac)("sha256", Buffer.from(key)).update(data).digest();
71
+ return new Uint8Array(result.buffer, result.byteOffset, result.byteLength);
72
+ };
73
+
74
+ const isCallReceiptNode = node => {
75
+ if (node?.tag !== "receipt") return false;
76
+ const child = Array.isArray(node.content) ? node.content[0] : null;
77
+ return !!(child?.attrs?.["call-id"] || child?.attrs?.call_id);
78
+ };
79
+
80
+ class ActiveCall extends events_1.EventEmitter {
81
+ constructor(callId, engine, durationMs) {
82
+ super();
83
+ this.callId = callId;
84
+ this.engine = engine;
85
+ this._state = types_js_1.CallState.Idle;
86
+ this._endResolver = undefined;
87
+ this._endPromise = undefined;
88
+ this._endTimer = null;
89
+ this._ended = false;
90
+ this._audioSource = "silence";
91
+
92
+ this.end = () => {
93
+ if (this._ended) return;
94
+ try { this.engine.endCall(0, true); } catch {}
95
+ this._forceEnd("local_end");
96
+ };
97
+
98
+ this.mute = muted => {
99
+ try { this.engine.setMute(muted); } catch {}
100
+ };
101
+
102
+ this.waitForEnd = () => this._endPromise;
103
+
104
+ this._updateState = state => {
105
+ this._state = state;
106
+ if (state === types_js_1.CallState.PreacceptReceived) {
107
+ this.emit("ringing");
108
+ } else if (state === types_js_1.CallState.Active) {
109
+ this.emit("connected");
110
+ } else if (state === types_js_1.CallState.Idle || state === types_js_1.CallState.Ending) {
111
+ this._forceEnd("ended");
112
+ }
113
+ };
114
+
115
+ this._emitAudio = pcm => {
116
+ this.emit("audio", pcm);
117
+ };
118
+
119
+ this._forceEnd = reason => {
120
+ if (this._ended) return;
121
+ this._ended = true;
122
+ if (this._endTimer) {
123
+ clearTimeout(this._endTimer);
124
+ this._endTimer = null;
125
+ }
126
+ this.emit("ended", reason);
127
+ this._endResolver(reason);
128
+ };
129
+
130
+ this._endPromise = new Promise(resolve => {
131
+ this._endResolver = resolve;
132
+ });
133
+
134
+ if (durationMs > 0) {
135
+ this._endTimer = setTimeout(() => this.end(), durationMs);
136
+ }
137
+ }
138
+
139
+ get state() {
140
+ return this._state;
141
+ }
142
+ }
143
+
144
+ exports.ActiveCall = ActiveCall;
145
+
146
+ class VoipClient {
147
+ constructor(config = {}) {
148
+ this._config = config;
149
+ this._engine = null;
150
+ this._relay = null;
151
+ this._signaling = null;
152
+ this._sock = config.socket || config.sock || config.conn || null;
153
+ this._activeCall = null;
154
+ this._baileys = null;
155
+ this._externalSocket = !!this._sock;
156
+ this._capturePtr = 0;
157
+ this._captureChunkBytes = 0;
158
+ this._captureSampleRate = 16000;
159
+ this._captureChannels = 1;
160
+ this._captureFramesPerChunk = 320;
161
+ this._feeder = null;
162
+
163
+ this.connect = async () => {
164
+ this._baileys = await loadBaileys();
165
+
166
+ if (this._sock) {
167
+ await this._initVoipStack();
168
+ return;
169
+ }
170
+
171
+ const { useMultiFileAuthState, default: makeWASocket, DisconnectReason } = this._baileys;
172
+ const makeSocket = makeWASocket ?? this._baileys.makeWASocket ?? this._baileys;
173
+
174
+ if (!this._config.authDir) {
175
+ throw new Error("authDir wajib diisi jika tidak memakai socket/conn.");
176
+ }
177
+
178
+ const authDir = (0, path_1.resolve)(this._config.authDir);
179
+ const { state, saveCreds } = await useMultiFileAuthState(authDir);
180
+
181
+ const silentLogger = {
182
+ level: "silent",
183
+ child: () => silentLogger,
184
+ trace: () => {},
185
+ debug: () => {},
186
+ info: () => {},
187
+ warn: () => {},
188
+ error: () => {},
189
+ fatal: () => {}
190
+ };
191
+
192
+ const createSocket = () => makeSocket({
193
+ auth: state,
194
+ emitOwnEvents: true,
195
+ logger: silentLogger
196
+ });
197
+
198
+ await new Promise((resolveOpen, rejectOpen) => {
199
+ let opened = false;
200
+ let retries = 0;
201
+ const maxRetries = 5;
202
+
203
+ const connectSocket = () => {
204
+ this._sock = createSocket();
205
+ this._sock.ev.on("creds.update", saveCreds);
206
+
207
+ const onUncaughtException = err => {
208
+ const code = err?.output?.statusCode ?? err?.data?.attrs?.code;
209
+ if ((code === 515 || code === "515") && !opened && retries < maxRetries) {
210
+ retries += 1;
211
+ setTimeout(connectSocket, 1500);
212
+ return;
213
+ }
214
+ if (!opened) {
215
+ process.off("uncaughtException", onUncaughtException);
216
+ rejectOpen(err);
217
+ }
218
+ };
219
+
220
+ process.on("uncaughtException", onUncaughtException);
221
+
222
+ this._sock.ev.on("connection.update", update => {
223
+ if (update.qr) {
224
+ console.log("QR diterima, tapi qrcode-terminal tidak dipakai.");
225
+ console.log(update.qr);
226
+ }
227
+ if (update.connection === "open") {
228
+ opened = true;
229
+ process.off("uncaughtException", onUncaughtException);
230
+ resolveOpen();
231
+ return;
232
+ }
233
+ if (update.connection === "close" && !opened) {
234
+ const statusCode = update.lastDisconnect?.error?.output?.statusCode;
235
+ const shouldReconnect = statusCode === 515 || statusCode === DisconnectReason?.restartRequired;
236
+ if (shouldReconnect && retries < maxRetries) {
237
+ retries += 1;
238
+ setTimeout(connectSocket, 1000);
239
+ } else {
240
+ process.off("uncaughtException", onUncaughtException);
241
+ rejectOpen(update.lastDisconnect?.error ?? new Error("socket closed before open"));
242
+ }
243
+ }
244
+ });
245
+ };
246
+
247
+ connectSocket();
248
+ });
249
+
250
+ await this._initVoipStack();
251
+ };
252
+
253
+ this.call = async (phoneNumber, opts = {}) => {
254
+ if (!this._engine || !this._signaling) {
255
+ throw new Error("Not connected. Call connect() first.");
256
+ }
257
+
258
+ if (this._activeCall) {
259
+ try { this._activeCall._forceEnd("replaced"); } catch {}
260
+ try { this._engine?.endCall?.(0, true); } catch {}
261
+ try { this._feeder?.stop(); } catch {}
262
+ this._feeder = null;
263
+ this._activeCall = null;
264
+ }
265
+
266
+ const targetNumber = phoneNumber.replace(/\D/g, "");
267
+ if (!targetNumber) {
268
+ throw new Error("Nomor target tidak valid.");
269
+ }
270
+
271
+ const targetPnJid = `${targetNumber}@s.whatsapp.net`;
272
+ const durationMs = opts.durationMs ?? 120000;
273
+ const audioSource = opts.audioSource ?? "silence";
274
+
275
+ const peerLid = await this._signaling.resolveLid(targetPnJid);
276
+ if (!peerLid) {
277
+ throw new Error(`Tidak bisa resolve LID untuk ${targetPnJid}. Pastikan target valid dan sudah tersimpan mapping LID/PN atau USync LID bisa diakses.`);
278
+ }
279
+
280
+ const peerJid = peerLid;
281
+ const peerPn = targetPnJid;
282
+ const isLidCall = true;
283
+
284
+ for (const jid of [targetPnJid, peerLid]) {
285
+ try { await this._sock.presenceSubscribe(jid); } catch {}
286
+ }
287
+ await new Promise(resolve => setTimeout(resolve, 750));
288
+
289
+ let peerDeviceJids = [];
290
+ try {
291
+ peerDeviceJids = await this._signaling.discoverPeerDevices(peerLid);
292
+ } catch (err) {
293
+ console.error("[RTC DISCOVER DEVICES ERROR]", err?.message || err);
294
+ }
295
+
296
+ const deviceList = peerDeviceJids.length ? peerDeviceJids : [toBareJid(peerLid)];
297
+
298
+ try {
299
+ await this._signaling.ensureSessionsForPeers(deviceList);
300
+ } catch (err) {
301
+ console.error("[RTC ENSURE SESSIONS WARNING]", err?.message || err);
302
+ }
303
+
304
+ await new Promise(resolve => setTimeout(resolve, 500));
305
+
306
+ try {
307
+ await this._signaling.issueTcToken(peerLid);
308
+ } catch (err) {
309
+ console.error("[RTC ISSUE TC TOKEN ERROR]", err?.message || err);
310
+ }
311
+
312
+ let tcToken = null;
313
+ try {
314
+ tcToken = await this._signaling.ensureTcToken(peerLid, targetPnJid);
315
+ } catch (err) {
316
+ console.error("[RTC ENSURE TC TOKEN ERROR]", err?.message || err);
317
+ }
318
+
319
+ if (!tcToken || !tcToken.length) {
320
+ console.warn("[RTC TC TOKEN WARNING] TC token kosong, lanjut startCall dengan token kosong seperti baileys-caller rc11.");
321
+ tcToken = undefined;
322
+ }
323
+
324
+ const callId = ("00" + (0, crypto_1.randomBytes)(16).toString("hex").slice(2)).toUpperCase();
325
+ const call = new ActiveCall(callId, this._engine, durationMs);
326
+
327
+ call._audioSource = audioSource;
328
+ this._activeCall = call;
329
+
330
+ call.once("ended", () => {
331
+ if (this._activeCall === call) this._activeCall = null;
332
+ });
333
+
334
+ call.once("error", () => {
335
+ if (this._activeCall === call) this._activeCall = null;
336
+ });
337
+
338
+ console.log("[RTC START CALL PARAMS]", {
339
+ peerJid,
340
+ peerPn,
341
+ peerList: deviceList,
342
+ callId,
343
+ isLidCall,
344
+ targetPnJid,
345
+ peerLid,
346
+ hasTcToken: !!tcToken,
347
+ tcTokenLength: tcToken?.length || 0
348
+ });
349
+
350
+ try {
351
+ const startResult = this._engine.startCall({
352
+ peerJid,
353
+ peerPn,
354
+ peerList: deviceList,
355
+ callId,
356
+ isVideo: false,
357
+ isLidCall,
358
+ isFromDialer: false,
359
+ extraData: tcToken
360
+ });
361
+ console.log("[RTC START CALL RESULT]", startResult);
362
+ setTimeout(() => {
363
+ try {
364
+ this._startAudioFeeder?.();
365
+ } catch (err) {
366
+ console.error("[RTC AUDIO FORCE START ERROR]", err?.message || err);
367
+ }
368
+ }, 1500);
369
+ } catch (err) {
370
+ if (this._activeCall === call) this._activeCall = null;
371
+ try { call._forceEnd("start_call_failed"); } catch {}
372
+ throw err;
373
+ }
374
+
375
+ return call;
376
+ };
377
+
378
+ this.disconnect = () => {
379
+ this._activeCall?._forceEnd("disconnect");
380
+ this._activeCall = null;
381
+ try { this._feeder?.stop(); } catch {}
382
+ this._feeder = null;
383
+ this._relay?.closeAll();
384
+ this._engine?.destroy();
385
+ if (!this._externalSocket) {
386
+ this._sock?.end?.();
387
+ }
388
+ this._engine = null;
389
+ this._relay = null;
390
+ this._signaling = null;
391
+ if (!this._externalSocket) {
392
+ this._sock = null;
393
+ }
394
+ };
395
+
396
+ this.resetCallState = () => {
397
+ try { this._activeCall?._forceEnd("reset"); } catch {}
398
+ try { this._engine?.endCall?.(0, true); } catch {}
399
+ try { this._feeder?.stop(); } catch {}
400
+ this._feeder = null;
401
+ this._activeCall = null;
402
+ };
403
+
404
+ this._initVoipStack = async () => {
405
+ if (!this._sock) {
406
+ throw new Error("Socket Baileys belum tersedia.");
407
+ }
408
+
409
+ this._signaling = new signaling_js_1.SignalingBridge({ sock: this._sock });
410
+ await this._signaling.init();
411
+
412
+ this._relay = new relay_transport_js_1.RelayRtcTransport({
413
+ onTransportMessage: (data, ip, port) => this._engine?.handleOnTransportMessage(data, ip, port),
414
+ onIceRtt: (rttMs, ip, port) => this._engine?.updateIceRtt(rttMs, ip, port)
415
+ });
416
+
417
+ this._engine = new wasm_engine_js_1.WasmEngine({
418
+ callbacks: {
419
+ onSignalingXmpp: (peerJid, callId, xmlPayload) => {
420
+ console.log("[RTC WASM SIGNALING XMPP]", {
421
+ peerJid,
422
+ callId,
423
+ payloadLength: xmlPayload?.length || 0
424
+ });
425
+ return this._signaling.sendSignaling(peerJid, callId, xmlPayload);
426
+ },
427
+ onCallEvent: (eventType, eventData) => this._handleCallEvent(eventType, eventData),
428
+ sendDataToRelay: (data, ip, port) => this._relay.send(data, ip, port),
429
+ onAudioCaptureInit: config => this._handleAudioCaptureInit(config),
430
+ onAudioCaptureStart: () => this._handleAudioCaptureStart(),
431
+ onAudioCaptureStop: () => this._handleAudioCaptureStop(),
432
+ onAudioPlaybackData: audioData => this._activeCall?._emitAudio(audioData),
433
+ cryptoHkdf: computeHkdf,
434
+ hmacSha256: computeHmacSha256
435
+ }
436
+ });
437
+
438
+ await this._engine.initialize();
439
+ this._signaling.attachEngine(this._engine);
440
+
441
+ const selfPnJidRaw =
442
+ this._sock.authState?.creds?.me?.id ||
443
+ this._sock.authState?.creds?.me?.jid ||
444
+ this._sock.user?.id ||
445
+ this._sock.user?.jid;
446
+
447
+ const selfPnJid = toBareJid(selfPnJidRaw);
448
+ const selfLidJid =
449
+ this._sock.authState?.creds?.me?.lid ||
450
+ this._sock.authState?.creds?.me?.lidJid ||
451
+ "";
452
+
453
+ if (!selfPnJid) {
454
+ throw new Error("Tidak bisa membaca JID bot dari socket utama.");
455
+ }
456
+
457
+ console.log("[RTC SELF JID]", { selfPnJid, selfLidJid });
458
+
459
+ this._engine.initVoipStack(selfPnJid, selfPnJid, selfLidJid);
460
+ await this._engine.waitForVoipStackReady();
461
+
462
+ try { this._engine.updateNetworkMedium(2, 0); } catch {}
463
+
464
+ if (this._sock.ws?.on) {
465
+ this._sock.ws.on("CB:call", node => {
466
+ this._signaling.processIncomingCall(node, this._engine, this._activeCall?.callId ?? "");
467
+ });
468
+
469
+ this._sock.ws.on("CB:receipt", node => {
470
+ if (!isCallReceiptNode(node)) return;
471
+ this._signaling.processIncomingReceipt(node, this._engine, this._activeCall?.callId ?? "");
472
+ });
473
+ }
474
+ };
475
+
476
+ this._handleCallEvent = (eventType, eventData) => {
477
+ console.log("[RTC CALL EVENT]", { eventType, hasData: !!eventData, data: eventData });
478
+
479
+ if (eventType === 16 && eventData) {
480
+ try {
481
+ const parsed = JSON.parse(eventData);
482
+ const info = parsed.call_info ?? parsed.callInfo ?? {};
483
+ const callState = Number(info.call_state ?? info.callState ?? 0);
484
+ console.log("[RTC CALL STATE]", callState);
485
+ this._activeCall?._updateState(callState);
486
+ } catch {}
487
+ } else if (eventType === 156 && eventData) {
488
+ try {
489
+ const update = JSON.parse(eventData);
490
+ this._relay?.updateRelayList(update);
491
+ } catch {}
492
+ } else if (eventType === 2) {
493
+ this._activeCall?._forceEnd("remote_end");
494
+ }
495
+ };
496
+
497
+ this._handleAudioCaptureInit = config => {
498
+ if (!this._engine) return;
499
+ this._captureSampleRate = config.sampleRate || 16000;
500
+ this._captureChannels = config.channels || 1;
501
+ this._captureFramesPerChunk = config.framesPerChunk || 320;
502
+ const chunkSamples = this._captureFramesPerChunk * this._captureChannels;
503
+ this._captureChunkBytes = chunkSamples * Float32Array.BYTES_PER_ELEMENT;
504
+ this._capturePtr = this._engine.malloc(this._captureChunkBytes);
505
+ };
506
+
507
+ this._startAudioFeeder = () => {
508
+ if (!this._engine || !this._capturePtr) {
509
+ console.warn("[RTC AUDIO] capturePtr belum siap, audio feeder batal start");
510
+ return;
511
+ }
512
+
513
+ if (this._feeder) return;
514
+
515
+ const audioSource = this._activeCall?._audioSource ?? "silence";
516
+
517
+ console.log("[RTC AUDIO] start feeder:", {
518
+ audioSource,
519
+ sampleRate: this._captureSampleRate,
520
+ channels: this._captureChannels,
521
+ framesPerChunk: this._captureFramesPerChunk
522
+ });
523
+
524
+ this._feeder = new audio_feeder_js_1.AudioFeeder(
525
+ this._captureSampleRate,
526
+ this._captureChannels,
527
+ this._captureFramesPerChunk,
528
+ chunk => {
529
+ if (this._engine && this._capturePtr) {
530
+ this._engine.sendAudioData(chunk, this._capturePtr);
531
+ }
532
+ },
533
+ audioSource
534
+ );
535
+
536
+ this._feeder.start();
537
+ };
538
+
539
+ this._handleAudioCaptureStart = () => {
540
+ this._startAudioFeeder();
541
+ };
542
+
543
+ this._handleAudioCaptureStop = () => {
544
+ this._feeder?.stop();
545
+ this._feeder = null;
546
+ if (this._engine && this._capturePtr) {
547
+ try { this._engine.free(this._capturePtr); } catch {}
548
+ this._capturePtr = 0;
549
+ }
550
+ };
551
+ }
552
+ }
553
+
554
+ exports.VoipClient = VoipClient;
555
+ exports.default = VoipClient;
556
+
557
+ module.exports = VoipClient;
558
+ module.exports.VoipClient = VoipClient;
559
+ module.exports.ActiveCall = ActiveCall;
560
+ module.exports.CallState = types_js_1.CallState;
561
+ module.exports.default = VoipClient;
562
+ Object.defineProperty(module.exports, "__esModule", { value: true });