@areumtecnologia/wasockets 2.0.0 → 2.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.
Files changed (75) hide show
  1. package/README.md +1987 -1649
  2. package/lib/Client/Builders/Buttons.js +127 -0
  3. package/lib/Client/Builders/EventBuilder.js +122 -0
  4. package/lib/Client/Builders/InteractiveMessage.js +150 -0
  5. package/lib/Client/Builders/Lists.js +78 -0
  6. package/lib/Client/Builders/PollBuilder.js +84 -0
  7. package/lib/Client/Builders/index.js +21 -0
  8. package/lib/Client/Constants.js +54 -0
  9. package/lib/Client/Context/CallContext.js +96 -0
  10. package/lib/Client/Context/MediaObject.js +155 -0
  11. package/lib/Client/Context/MessageContext.js +146 -0
  12. package/lib/Client/Modules/BusinessManager.js +155 -0
  13. package/lib/Client/Modules/ChannelManager.js +144 -0
  14. package/lib/Client/Modules/ChatManager.js +113 -0
  15. package/lib/Client/Modules/CommunityManager.js +136 -0
  16. package/lib/Client/Modules/GroupManager.js +194 -0
  17. package/lib/Client/Modules/LabelManager.js +123 -0
  18. package/lib/Client/Modules/MessageManager.js +198 -0
  19. package/lib/Client/Modules/PresenceManager.js +68 -0
  20. package/lib/Client/Modules/PrivacyManager.js +98 -0
  21. package/lib/Client/Modules/ProfileManager.js +92 -0
  22. package/lib/Client/Modules/UserManager.js +92 -0
  23. package/lib/Client/Modules/VoipManager.js +117 -0
  24. package/lib/Client/Modules/index.js +29 -0
  25. package/lib/Client/Normalizers/EventNormalizer.js +82 -0
  26. package/lib/Client/Normalizers/JidNormalizer.js +93 -0
  27. package/lib/Client/Normalizers/MessageNormalizer.js +134 -0
  28. package/lib/Client/WaClient.js +438 -0
  29. package/lib/Client/index.d.ts +464 -0
  30. package/lib/Client/index.js +76 -0
  31. package/lib/Defaults/baileys-version.json +1 -1
  32. package/lib/Defaults/connection.js +14 -1
  33. package/lib/Socket/index.js +51 -48
  34. package/lib/Socket/messages-recv.js +74 -13
  35. package/lib/Socket/messages-send.js +50 -25
  36. package/lib/Socket/socket.js +13 -0
  37. package/lib/Socket/voip.js +123 -0
  38. package/lib/Store/make-cache-manager-store.js +14 -5
  39. package/lib/Types/index.d.ts +4 -0
  40. package/lib/Utils/auth-utils.js +16 -1
  41. package/lib/Utils/browser-utils.js +6 -2
  42. package/lib/Utils/generics.js +47 -8
  43. package/lib/Utils/index.d.ts +1 -0
  44. package/lib/Utils/messages-media.js +44 -21
  45. package/lib/Utils/pre-key-manager.js +16 -1
  46. package/lib/Utils/validate-connection.js +10 -11
  47. package/lib/VoIP/VoIPCrypto.js +150 -0
  48. package/lib/VoIP/VoIPManager.js +469 -0
  49. package/lib/VoIP/VoIPMediaEngine.js +224 -0
  50. package/lib/VoIP/VoIPProtocol.js +354 -0
  51. package/lib/VoIP/VoIPRelayTransport.js +173 -0
  52. package/lib/VoIP/VoIPSession.js +314 -0
  53. package/lib/VoIP/assets/wasm/loader.js +5 -0
  54. package/lib/VoIP/assets/wasm/whatsapp.wasm +0 -0
  55. package/lib/VoIP/assets/wasm/worker-modules.js +305 -0
  56. package/lib/VoIP/engine/audio-feeder.d.mts +15 -0
  57. package/lib/VoIP/engine/audio-feeder.mjs +243 -0
  58. package/lib/VoIP/engine/index.d.mts +91 -0
  59. package/lib/VoIP/engine/index.mjs +1683 -0
  60. package/lib/VoIP/engine/relay-transport.d.mts +43 -0
  61. package/lib/VoIP/engine/relay-transport.mjs +607 -0
  62. package/lib/VoIP/engine/signaling.d.mts +44 -0
  63. package/lib/VoIP/engine/signaling.mjs +893 -0
  64. package/lib/VoIP/engine/types.d.mts +183 -0
  65. package/lib/VoIP/engine/types.mjs +17 -0
  66. package/lib/VoIP/engine/wasm-engine.d.mts +103 -0
  67. package/lib/VoIP/engine/wasm-engine.mjs +1397 -0
  68. package/lib/VoIP/engine/worker-bootstrap.mjs +1049 -0
  69. package/lib/VoIP/index.js +51 -0
  70. package/lib/VoIP/utils/audio.d.ts +28 -0
  71. package/lib/VoIP/utils/audio.js +148 -0
  72. package/lib/WABinary/generic-utils.js +22 -6
  73. package/lib/index.d.ts +382 -274
  74. package/lib/index.js +5 -0
  75. package/package.json +51 -49
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Shared type definitions for baileys-caller.
3
+ *
4
+ * @author ShellTear
5
+ */
6
+ import type { Readable } from "node:stream";
7
+
8
+ /** Audio stream configuration reported by the WASM. */
9
+ export type AudioConfig = {
10
+ sampleRate: number;
11
+ channels: number;
12
+ bitsPerSample: number;
13
+ framesPerChunk: number;
14
+ };
15
+
16
+ /** Options for placing a call. */
17
+ export type CallOptions = {
18
+ /** Phone number, digits only (e.g. `"12345678901"`). */
19
+ to: string;
20
+ /** Audio source: file path to MP3/WAV, or `"silence"` for an empty uplink. */
21
+ audioSource?: string;
22
+ /** Auto-hangup after N ms (default: 120000). */
23
+ durationMs?: number;
24
+ /** Place as video call */
25
+ isVideo?: boolean;
26
+ };
27
+
28
+ export type VadOptions = {
29
+ thresholdDbfs?: number;
30
+ silenceTimeoutMs?: number;
31
+ speechDebounceFrames?: number;
32
+ enabled?: boolean;
33
+ };
34
+
35
+ export type StreamOptions = {
36
+ format?: "int16" | "float32";
37
+ };
38
+
39
+ export type RecordOptions = {
40
+ channels?: 1 | 2;
41
+ sampleRate?: number;
42
+ source?: "mixed" | "rx" | "tx";
43
+ };
44
+
45
+ export type CallRealtimeStats = {
46
+ callId: string;
47
+ state: number;
48
+ talkDurationSeconds: number;
49
+ rttMs: number | null;
50
+ packetsSent: number;
51
+ packetsReceived: number;
52
+ droppedPackets: number;
53
+ bytesSent: number;
54
+ bytesReceived: number;
55
+ uplinkBps: number;
56
+ downlinkBps: number;
57
+ isSpeaking: boolean;
58
+ audioFeeder: any;
59
+ };
60
+
61
+ export type CallTelemetry = {
62
+ callId: string;
63
+ direction: string;
64
+ peer: {
65
+ phoneNumber: string;
66
+ pnJid: string;
67
+ lidJid: string;
68
+ };
69
+ caller: {
70
+ pnJid: string | null;
71
+ lidJid: string | null;
72
+ displayName: string;
73
+ };
74
+ timing: {
75
+ offerTimestamp: number;
76
+ ringingTimestamp: number | null;
77
+ connectedTimestamp: number | null;
78
+ endedTimestamp: number;
79
+ timeToRingMs: number | null;
80
+ timeToAnswerMs: number | null;
81
+ talkDurationSeconds: number;
82
+ totalDurationSeconds: number;
83
+ };
84
+ status: {
85
+ finalState: string;
86
+ endReason: string;
87
+ answered: boolean;
88
+ };
89
+ audioMetrics: {
90
+ sampleRate: number;
91
+ channels: number;
92
+ frameDurationMs: number;
93
+ samplesPerChunk: number;
94
+ packetsReceived: number;
95
+ packetsSent: number;
96
+ bytesReceived: number;
97
+ bytesSent: number;
98
+ voiceActivity: {
99
+ avgVolumeDbfs: number;
100
+ peakVolumeDbfs: number;
101
+ speechFrames: number;
102
+ silenceFrames: number;
103
+ speechRatio: number;
104
+ };
105
+ };
106
+ networkMetrics: {
107
+ transport: string;
108
+ relayServer: string;
109
+ iceRttMs: number | null;
110
+ droppedPackets: number;
111
+ bytesReceived: number;
112
+ bytesSent: number;
113
+ };
114
+ };
115
+
116
+ /** Events emitted by an `ActiveCall`. */
117
+ export type CallEvents = {
118
+ ringing: () => void;
119
+ connected: () => void;
120
+ /** 16 kHz mono Float32 PCM frame from the remote peer. */
121
+ audio: (pcm: Float32Array) => void;
122
+ /** 16 kHz mono Float32 PCM frame sent to the remote peer (uplink). */
123
+ audio_out: (pcm: Float32Array) => void;
124
+ "audio:out": (pcm: Float32Array) => void;
125
+ audio_tx: (pcm: Float32Array) => void;
126
+ /** Video frame received from remote peer. */
127
+ video?: (data: any) => void;
128
+ /** Video frame sent to remote peer. */
129
+ video_out?: (data: any) => void;
130
+ "video:out"?: (data: any) => void;
131
+ /** Voice activity detection: user started speaking */
132
+ speaking: (event: { volumeDbfs: number; rms: number }) => void;
133
+ /** Voice activity detection: user stopped speaking */
134
+ silence: (event: { durationMs: number }) => void;
135
+ /** Real-time QoS network and throughput stats */
136
+ stats: (stats: CallRealtimeStats) => void;
137
+ /** Full structured telemetry report upon call completion */
138
+ telemetry: (telemetry: CallTelemetry) => void;
139
+ /** Reason: `"hangup"` | `"timeout"` | `"rejected"` | `"remote_end"` | `"disconnect"` | etc. */
140
+ ended: (reason: string) => void;
141
+ error: (err: Error) => void;
142
+ };
143
+
144
+ /** Top-level SDK configuration. */
145
+ export type VoipSdkConfig = {
146
+ /** Path to a Baileys multi-file auth state directory. */
147
+ authDir: string;
148
+ };
149
+
150
+ /** Mirrors the WhatsApp WASM `CallState` enum. */
151
+ export declare const CallState: {
152
+ readonly Idle: 0;
153
+ readonly Calling: 1;
154
+ readonly PreacceptReceived: 2;
155
+ readonly ReceivedCall: 3;
156
+ readonly AcceptSent: 4;
157
+ readonly AcceptReceived: 5;
158
+ readonly Active: 6;
159
+ readonly ActiveElsewhere: 7;
160
+ readonly Ending: 13;
161
+ };
162
+ export type CallState = (typeof CallState)[keyof typeof CallState];
163
+
164
+ /** Relay list update payload from WASM call event 156. */
165
+ export type RelayListUpdate = {
166
+ relay_key: string;
167
+ relay_tokens: string[];
168
+ auth_tokens?: string[];
169
+ enable_edgeray_dtls_active_mode?: boolean;
170
+ relays: ReadonlyArray<{
171
+ relay_id: number;
172
+ relay_name: string;
173
+ token_id: number;
174
+ auth_token_id?: number;
175
+ addresses: ReadonlyArray<{
176
+ protocol: number;
177
+ ipv4?: string;
178
+ ipv6?: string;
179
+ port?: number;
180
+ port_v6?: number;
181
+ }>;
182
+ }>;
183
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shared type definitions for baileys-caller.
3
+ *
4
+ * @author ShellTear
5
+ */
6
+ /** Mirrors the WhatsApp WASM `CallState` enum. */
7
+ export const CallState = {
8
+ Idle: 0,
9
+ Calling: 1,
10
+ PreacceptReceived: 2,
11
+ ReceivedCall: 3,
12
+ AcceptSent: 4,
13
+ AcceptReceived: 5,
14
+ Active: 6,
15
+ ActiveElsewhere: 7,
16
+ Ending: 13,
17
+ };
@@ -0,0 +1,103 @@
1
+ export type WasmAudioConfig = {
2
+ sampleRate: number;
3
+ channels: number;
4
+ bitsPerSample: number;
5
+ framesPerChunk: number;
6
+ };
7
+ export type WasmEngineCallbacks = {
8
+ onSignalingXmpp?: (peerJid: string, callId: string, xmlPayload: Uint8Array) => void;
9
+ onCallEvent?: (eventType: number, eventData?: string) => void;
10
+ onVoipReady?: () => void;
11
+ sendDataToRelay?: (data: Uint8Array, ip: string, port: number) => number;
12
+ onLog?: (level: string, message: string) => void;
13
+ onAudioCaptureInit?: (config: WasmAudioConfig) => void;
14
+ onAudioCaptureStart?: () => void;
15
+ onAudioCaptureStop?: () => void;
16
+ onAudioPlaybackInit?: (config: WasmAudioConfig) => void;
17
+ onAudioPlaybackStart?: () => void;
18
+ onAudioPlaybackStop?: () => void;
19
+ onAudioPlaybackData?: (audioData: Float32Array) => void;
20
+ cryptoHkdf?: (key: Uint8Array, salt: Uint8Array | null, info: Uint8Array, length: number) => Uint8Array;
21
+ hmacSha256?: (data: Uint8Array, key: Uint8Array) => Uint8Array;
22
+ };
23
+ export type WasmEngineConfig = {
24
+ resourcesPath?: string;
25
+ wasmPath?: string;
26
+ wasmBinary?: Uint8Array;
27
+ loaderCode?: string;
28
+ workerModulesCode?: string;
29
+ loaderModuleName?: string;
30
+ callbacks?: WasmEngineCallbacks;
31
+ enableLogs?: boolean;
32
+ options?: {
33
+ heartbeatInterval?: number;
34
+ lobbyTimeout?: number;
35
+ maxParticipantsScreenShare?: number;
36
+ maxGroupSizeLongRingtone?: number;
37
+ logLevel?: number;
38
+ };
39
+ };
40
+ export declare class WasmEngine {
41
+ #private;
42
+ static registerGlobalCallbackListener: (callbackName: string, handler: (data: any) => void) => void;
43
+ static notifyGlobalCallbackListeners: (callbackName: string, data: any) => void;
44
+ constructor(config?: WasmEngineConfig);
45
+ initialize: () => Promise<void>;
46
+ isInitialized: () => boolean;
47
+ destroy: () => void;
48
+ initVoipStack: (selfJid: string, meUserJid: string, selfLid: string) => void;
49
+ waitForVoipStackReady: () => Promise<void>;
50
+ isVoipStackReady: () => boolean;
51
+ startCall: (options: {
52
+ peerJid: string;
53
+ peerPn: string;
54
+ peerList?: string[];
55
+ callId: string;
56
+ isVideo: boolean;
57
+ isLidCall?: boolean;
58
+ isFromDialer?: boolean;
59
+ extraData?: Uint8Array;
60
+ }) => unknown;
61
+ endCall: (reason?: number, sendTerminate?: boolean) => void;
62
+ setMute: (muted: boolean) => number;
63
+ updateNetworkMedium: (networkMedium: number, networkMtu?: number) => void;
64
+ handleSignalingOffer: (msg: {
65
+ payload: string;
66
+ peerPlatform?: number;
67
+ peerAppVersion?: string;
68
+ epochId?: string;
69
+ timestamp?: string;
70
+ isOffline?: boolean;
71
+ isOfferNotContact?: boolean;
72
+ peerJid: string;
73
+ tcToken?: Uint8Array;
74
+ }) => void;
75
+ handleSignalingMessage: (msg: {
76
+ payload: string;
77
+ peerPlatform?: string | number;
78
+ peerAppVersion?: string;
79
+ epochId?: string;
80
+ timestamp?: string;
81
+ isOffline?: boolean;
82
+ peerJid: string;
83
+ tcToken?: Uint8Array;
84
+ }) => void;
85
+ handleSignalingAck: (msg: {
86
+ payload: string;
87
+ ackError?: string;
88
+ msgType?: string;
89
+ peerJid?: string;
90
+ extraData?: Uint8Array;
91
+ }) => void;
92
+ handleSignalingReceipt: (msg: {
93
+ payload: string;
94
+ peerJid: string;
95
+ tcToken?: Uint8Array;
96
+ }) => void;
97
+ handleOnTransportMessage: (data: Uint8Array, ip: string, port: number) => void;
98
+ updateIceRtt: (rttMs: number, relayIp: string, relayPort: number) => void;
99
+ sendAudioData: (data: Float32Array, ptr: number) => void;
100
+ malloc: (size: number) => number;
101
+ free: (ptr: number) => void;
102
+ }
103
+ export default WasmEngine;