@hiroosy/baileys-lite 0.3.6 → 0.3.8
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/package.json +1 -1
- package/src/socket/chats.js +1 -1
- package/src/utils/auth-state-core.js +1 -1
- package/src/utils/auth-state-storage.js +1 -1
- package/src/utils/message-processing.js +2 -2
- package/src/voip/app-data/WaAppDataStream.js +0 -39
- package/src/voip/call/WaCallManager.js +4 -32
- package/src/voip/call/WaCallMediaSession.js +35 -309
- package/src/voip/index.js +75 -18
- package/src/voip/media/WaAudioEngine.js +150 -122
- package/src/voip/media/WaVideoEngine.js +7 -22
- package/src/voip/media/mlow-codec.js +7 -141
- package/src/voip/relay/WaManualRelay.js +91 -94
- package/src/voip/relay/dtls/handshake.js +4 -42
- package/src/voip/relay/sctp/association.js +89 -54
- package/src/voip/relay/stun.js +6 -6
- package/src/voip/types.js +1 -1
- package/src/voip/voipClient.js +3 -1
package/package.json
CHANGED
package/src/socket/chats.js
CHANGED
|
@@ -61,7 +61,7 @@ export const makeChatsSocket = config => {
|
|
|
61
61
|
const historySyncStatus = { initialBootstrapComplete: false, recentSyncComplete: false }
|
|
62
62
|
let historySyncPausedTimeout
|
|
63
63
|
const blockedCollections = new Set()
|
|
64
|
-
const placeholderResendCache = config.placeholderResendCache || new Cache({ ttl: DEFAULT_CACHE_TTLS.MSG_RETRY * 1000 })
|
|
64
|
+
const placeholderResendCache = config.placeholderResendCache || new Cache({ max: 1024, ttl: DEFAULT_CACHE_TTLS.MSG_RETRY * 1000 })
|
|
65
65
|
|
|
66
66
|
const getAppStateSyncKey = async keyId => {
|
|
67
67
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId])
|
|
@@ -100,7 +100,7 @@ export class PreKeyManager {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const txStorage = new AsyncLocalStorage()
|
|
103
|
-
const SIGNAL_CACHE_BYTES =
|
|
103
|
+
const SIGNAL_CACHE_BYTES = 1024 * 1024
|
|
104
104
|
|
|
105
105
|
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
106
106
|
|
|
@@ -89,7 +89,7 @@ const SIGNAL_STORE_TTL_MS = 5 * 60 * 1000
|
|
|
89
89
|
const FLUSH_TIMEOUT_MS = 3000
|
|
90
90
|
|
|
91
91
|
export const useSingleFileAuthState = async fileName => {
|
|
92
|
-
const cache = new Cache({ max:
|
|
92
|
+
const cache = new Cache({ max: 4096, ttl: SIGNAL_STORE_TTL_MS })
|
|
93
93
|
const mutex = makeKeyedMutex()
|
|
94
94
|
let fileData = {}
|
|
95
95
|
let isLoaded = false
|
|
@@ -483,8 +483,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
483
483
|
|
|
484
484
|
export default processMessage
|
|
485
485
|
|
|
486
|
-
const RECENT_MESSAGES_SIZE =
|
|
487
|
-
const RECENT_MESSAGES_BYTES =
|
|
486
|
+
const RECENT_MESSAGES_SIZE = 256
|
|
487
|
+
const RECENT_MESSAGES_BYTES = 1024 * 1024
|
|
488
488
|
const MESSAGE_KEY_SEPARATOR = '\u0000'
|
|
489
489
|
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000
|
|
490
490
|
const PHONE_REQUEST_DELAY = 3000
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { toError } from '../shim/util.js';
|
|
2
1
|
import { randomInt } from '../crypto/primitives.js';
|
|
3
2
|
import { RtpHeader, RtpPacket } from '../media/rtp.js';
|
|
4
3
|
import { decodeAppDataPayload, encodeReactionPayload } from './protocol.js';
|
|
@@ -55,10 +54,6 @@ export class WaAppDataStream {
|
|
|
55
54
|
if (this.configuredPayloadType !== null || this.learnedPayloadType === payloadType)
|
|
56
55
|
return;
|
|
57
56
|
this.learnedPayloadType = payloadType;
|
|
58
|
-
this.logger.debug('app data payload type learned from peer', {
|
|
59
|
-
payloadType,
|
|
60
|
-
ssrc: `0x${this.ssrc.toString(16)}`
|
|
61
|
-
});
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
setSframe(required, protect) {
|
|
@@ -74,13 +69,6 @@ export class WaAppDataStream {
|
|
|
74
69
|
this.txReactionCount++;
|
|
75
70
|
const sent = this.transmit();
|
|
76
71
|
this.armRetransmission();
|
|
77
|
-
this.logger.debug('call reaction queued', {
|
|
78
|
-
reaction,
|
|
79
|
-
transactionId: transactionId.toString(),
|
|
80
|
-
ssrc: `0x${this.ssrc.toString(16)}`,
|
|
81
|
-
firstAttemptSent: sent,
|
|
82
|
-
total: this.txReactionCount
|
|
83
|
-
});
|
|
84
72
|
return sent;
|
|
85
73
|
}
|
|
86
74
|
|
|
@@ -89,20 +77,8 @@ export class WaAppDataStream {
|
|
|
89
77
|
return EMPTY_REACTIONS;
|
|
90
78
|
const decoded = decodeAppDataPayload(payload);
|
|
91
79
|
if (!decoded) {
|
|
92
|
-
this.logger.debug('app data payload not understood', {
|
|
93
|
-
ssrc: `0x${this.ssrc.toString(16)}`,
|
|
94
|
-
bytes: payload.length,
|
|
95
|
-
sframeRequired: this.sframeRequired,
|
|
96
|
-
sframeKeyed: this.sframeProtect !== null
|
|
97
|
-
});
|
|
98
80
|
return EMPTY_REACTIONS;
|
|
99
81
|
}
|
|
100
|
-
if (decoded.truncated) {
|
|
101
|
-
this.logger.debug('app data payload carried more messages than are read', {
|
|
102
|
-
ssrc: `0x${ssrc.toString(16)}`,
|
|
103
|
-
read: decoded.items.length
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
82
|
const fresh = [];
|
|
107
83
|
for (const item of decoded.items) {
|
|
108
84
|
const reaction = item.reaction;
|
|
@@ -115,13 +91,6 @@ export class WaAppDataStream {
|
|
|
115
91
|
this.rxReactionCount++;
|
|
116
92
|
fresh.push(reaction);
|
|
117
93
|
}
|
|
118
|
-
if (fresh.length > 0) {
|
|
119
|
-
this.logger.debug('call reaction received', {
|
|
120
|
-
shape: decoded.shape,
|
|
121
|
-
count: fresh.length,
|
|
122
|
-
total: this.rxReactionCount
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
94
|
return fresh;
|
|
126
95
|
}
|
|
127
96
|
close() {
|
|
@@ -151,9 +120,6 @@ export class WaAppDataStream {
|
|
|
151
120
|
return;
|
|
152
121
|
}
|
|
153
122
|
if (Date.now() >= outgoing.clearAt) {
|
|
154
|
-
this.logger.debug('call reaction cleared from send buffer', {
|
|
155
|
-
transactionId: outgoing.transactionId.toString()
|
|
156
|
-
});
|
|
157
123
|
this.clearOutgoing();
|
|
158
124
|
return;
|
|
159
125
|
}
|
|
@@ -181,11 +147,6 @@ export class WaAppDataStream {
|
|
|
181
147
|
}
|
|
182
148
|
catch (err) {
|
|
183
149
|
this.txReactionErrorCount++;
|
|
184
|
-
this.logger.debug('failed to send app data rtp packet', {
|
|
185
|
-
ssrc: `0x${this.ssrc.toString(16)}`,
|
|
186
|
-
errors: this.txReactionErrorCount,
|
|
187
|
-
message: toError(err).message
|
|
188
|
-
});
|
|
189
150
|
return false;
|
|
190
151
|
}
|
|
191
152
|
}
|
|
@@ -51,7 +51,6 @@ export class WaCallManager extends EventEmitter {
|
|
|
51
51
|
}
|
|
52
52
|
info.applyTransition({ type: 'offer_sent' });
|
|
53
53
|
this.emitState(info);
|
|
54
|
-
this.logger.debug('outgoing offer sent', { callId, peerJid });
|
|
55
54
|
return callId;
|
|
56
55
|
}
|
|
57
56
|
async acceptCall(callId) {
|
|
@@ -154,7 +153,6 @@ export class WaCallManager extends EventEmitter {
|
|
|
154
153
|
const existing = this.calls.get(callId);
|
|
155
154
|
if (existing) {
|
|
156
155
|
if (!existing.info.isEnded) {
|
|
157
|
-
this.logger.debug('duplicate offer for active call, ignoring', { callId });
|
|
158
156
|
return;
|
|
159
157
|
}
|
|
160
158
|
existing.cleanup();
|
|
@@ -197,11 +195,7 @@ export class WaCallManager extends EventEmitter {
|
|
|
197
195
|
try {
|
|
198
196
|
info.applyTransition({ type: 'terminated', reason: EndCallReason.Failed });
|
|
199
197
|
}
|
|
200
|
-
catch
|
|
201
|
-
this.logger.trace('failed-activation transition skipped', {
|
|
202
|
-
message: toError(transitionErr).message
|
|
203
|
-
});
|
|
204
|
-
}
|
|
198
|
+
catch { }
|
|
205
199
|
this.emit('call_ended', info);
|
|
206
200
|
this.emitState(info);
|
|
207
201
|
session.cleanup();
|
|
@@ -210,23 +204,8 @@ export class WaCallManager extends EventEmitter {
|
|
|
210
204
|
return;
|
|
211
205
|
}
|
|
212
206
|
}
|
|
213
|
-
else {
|
|
214
|
-
this.logger.debug('incoming call waiting, at capacity', {
|
|
215
|
-
callId,
|
|
216
|
-
peerJid,
|
|
217
|
-
maxConcurrentCalls: this.maxConcurrentCalls
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
207
|
this.emit('call_incoming', info);
|
|
221
208
|
this.emitState(info);
|
|
222
|
-
this.logger.debug('incoming call', {
|
|
223
|
-
callId,
|
|
224
|
-
peerJid,
|
|
225
|
-
callCreator,
|
|
226
|
-
isVideo,
|
|
227
|
-
relayCount: relays.length,
|
|
228
|
-
acceptBlocked: atCapacity
|
|
229
|
-
});
|
|
230
209
|
}
|
|
231
210
|
async handleCallAccept(node, peerJid) {
|
|
232
211
|
const session = this.resolveSessionFromNode(node);
|
|
@@ -349,6 +328,8 @@ export class WaCallManager extends EventEmitter {
|
|
|
349
328
|
emitCallReaction: (call, reaction) => this.emit('call_reaction', call, reaction),
|
|
350
329
|
emitScreenShare: (call, share) => this.emit('call_screen_share', call, share),
|
|
351
330
|
emitOutboundAudioFinished: (call) => this.emit('call_outbound_audio_finished', call),
|
|
331
|
+
emitReconnecting: (call, detail) => this.emit('call_reconnecting', call, detail),
|
|
332
|
+
emitReconnected: (call) => this.emit('call_reconnected', call),
|
|
352
333
|
|
|
353
334
|
emitVideoState: (call, videoState) => this.emit('call_video_state', call, videoState),
|
|
354
335
|
|
|
@@ -368,12 +349,10 @@ export class WaCallManager extends EventEmitter {
|
|
|
368
349
|
resolveSessionFromNode(node) {
|
|
369
350
|
const nodeInfo = extractNodeInfo(node);
|
|
370
351
|
if (!nodeInfo?.callId) {
|
|
371
|
-
this.logger.debug('stanza missing call-id, ignored');
|
|
372
352
|
return null;
|
|
373
353
|
}
|
|
374
354
|
const session = this.calls.get(nodeInfo.callId);
|
|
375
355
|
if (!session) {
|
|
376
|
-
this.logger.debug('no session for call-id', { callId: nodeInfo.callId });
|
|
377
356
|
return null;
|
|
378
357
|
}
|
|
379
358
|
return session;
|
|
@@ -397,10 +376,6 @@ export class WaCallManager extends EventEmitter {
|
|
|
397
376
|
if (outgoing.length === 1)
|
|
398
377
|
return outgoing[0];
|
|
399
378
|
|
|
400
|
-
this.logger.trace('offer ack could not be routed', {
|
|
401
|
-
callId: callId ?? null,
|
|
402
|
-
candidateCount: outgoing.length
|
|
403
|
-
});
|
|
404
379
|
return null;
|
|
405
380
|
}
|
|
406
381
|
emitState(call) {
|
|
@@ -414,9 +389,7 @@ export class WaCallManager extends EventEmitter {
|
|
|
414
389
|
if (mapped?.lidJid)
|
|
415
390
|
return mapped.lidJid;
|
|
416
391
|
}
|
|
417
|
-
catch
|
|
418
|
-
this.logger.trace('lid resolution failed', { message: toError(err).message });
|
|
419
|
-
}
|
|
392
|
+
catch { }
|
|
420
393
|
return peerJid;
|
|
421
394
|
}
|
|
422
395
|
async maybeUnblockWaitingCalls() {
|
|
@@ -437,6 +410,5 @@ export class WaCallManager extends EventEmitter {
|
|
|
437
410
|
await session.sendIncomingPreaccept(session.info.peerJid);
|
|
438
411
|
await session.sendIncomingRelayLatency();
|
|
439
412
|
this.emitState(session.info);
|
|
440
|
-
this.logger.debug('waiting incoming call unblocked', { callId: session.callId });
|
|
441
413
|
}
|
|
442
414
|
}
|