violetics 7.0.6-alpha → 7.0.7-alpha

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.
@@ -123,9 +123,12 @@ export const makeSocket = (config) => {
123
123
  node.attrs.id = generateMessageTag();
124
124
  }
125
125
  const msgId = node.attrs.id;
126
- const resultPromise = waitForMessage(msgId, timeoutMs);
127
- await sendNode(node);
128
- const result = await resultPromise;
126
+ const result = await promiseTimeout(timeoutMs, async (resolve, reject) => {
127
+ const result = waitForMessage(msgId, timeoutMs).catch(reject);
128
+ sendNode(node)
129
+ .then(async () => resolve(await result))
130
+ .catch(reject);
131
+ });
129
132
  if (result && 'tag' in result) {
130
133
  assertNodeErrorFree(result);
131
134
  }
@@ -480,18 +483,15 @@ export const makeSocket = (config) => {
480
483
  logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed');
481
484
  clearInterval(keepAliveReq);
482
485
  clearTimeout(qrTimer);
483
- // Clear all WS listeners (CB:*, TAG:*, frame, error, etc.) to prevent memory leaks
484
- ws.removeAllListeners();
486
+ ws.removeAllListeners('close');
487
+ ws.removeAllListeners('open');
488
+ ws.removeAllListeners('message');
485
489
  if (!ws.isClosed && !ws.isClosing) {
486
490
  try {
487
491
  await ws.close();
488
492
  }
489
493
  catch { }
490
494
  }
491
- // Clean up noise handler buffers
492
- if (noise.destroy) {
493
- noise.destroy();
494
- }
495
495
  ev.emit('connection.update', {
496
496
  connection: 'close',
497
497
  lastDisconnect: {
@@ -499,11 +499,7 @@ export const makeSocket = (config) => {
499
499
  date: new Date()
500
500
  }
501
501
  });
502
- // Remove only internal socket listeners — preserve user-registered listeners
503
502
  ev.removeAllListeners('connection.update');
504
- ev.removeAllListeners('creds.update');
505
- ev.removeAllListeners('call');
506
- ev.removeAllListeners('lid-mapping.update');
507
503
  };
508
504
  const waitForSocketOpen = async () => {
509
505
  if (ws.isOpen) {
@@ -526,8 +522,7 @@ export const makeSocket = (config) => {
526
522
  ws.off('error', onClose);
527
523
  });
528
524
  };
529
- const startKeepAliveRequest = () => {
530
- keepAliveReq = setInterval(() => {
525
+ const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
531
526
  if (!lastDateRecv) {
532
527
  lastDateRecv = new Date();
533
528
  }
@@ -557,12 +552,7 @@ export const makeSocket = (config) => {
557
552
  else {
558
553
  logger.warn('keep alive called when WS not open');
559
554
  }
560
- }, keepAliveIntervalMs);
561
- // unref so the interval doesn't prevent Node.js process from exiting
562
- if (keepAliveReq?.unref) {
563
- keepAliveReq.unref();
564
- }
565
- };
555
+ }, keepAliveIntervalMs));
566
556
  /** i have no idea why this exists. pls enlighten me */
567
557
  const sendPassiveIq = (tag) => query({
568
558
  tag: 'iq',
@@ -608,7 +598,7 @@ export const makeSocket = (config) => {
608
598
  id: jidEncode(phoneNumber, 's.whatsapp.net'),
609
599
  name: '~'
610
600
  };
611
- ev.emit('creds.update', { pairingCode: authState.creds.pairingCode, me: authState.creds.me });
601
+ ev.emit('creds.update', authState.creds);
612
602
  await sendNode({
613
603
  tag: 'iq',
614
604
  attrs: {
@@ -820,7 +810,7 @@ export const makeSocket = (config) => {
820
810
  const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
821
811
  if (routingInfo?.content) {
822
812
  authState.creds.routingInfo = Buffer.from(routingInfo?.content);
823
- ev.emit('creds.update', { routingInfo: authState.creds.routingInfo });
813
+ ev.emit('creds.update', authState.creds);
824
814
  }
825
815
  });
826
816
  let didStartBuffer = false;
@@ -1,7 +1,7 @@
1
1
  import { proto } from '../../WAProto/index.js';
2
2
  // export the WAMessage Prototypes
3
3
  export { proto as WAProto };
4
- // vltcs@changes 03-02-26 --- Add exported message-related enum types from proto.Message
4
+ // Lia@Changes 03-02-26 --- Add exported message-related enum types from proto.Message
5
5
  export const AssociationType = proto.MessageAssociation.AssociationType;
6
6
  export const ButtonHeaderType = proto.Message.ButtonsMessage.HeaderType;
7
7
  export const ButtonType = proto.Message.ButtonsMessage.Button.Type;
@@ -149,7 +149,7 @@ export const makeEventBuffer = (logger) => {
149
149
  if (isBuffering && bufferCount === 1) {
150
150
  flush();
151
151
  }
152
- }, 10); // Minimal delay to allow nested buffers without adding latency
152
+ }, 100); // Small delay to allow nested buffers
153
153
  }
154
154
  return result;
155
155
  }
@@ -161,7 +161,7 @@ export const makeEventBuffer = (logger) => {
161
161
  if (bufferCount === 0) {
162
162
  // Only schedule ONE timeout, not 10,000
163
163
  if (!flushPendingTimeout) {
164
- flushPendingTimeout = setTimeout(flush, 10);
164
+ flushPendingTimeout = setTimeout(flush, 100);
165
165
  }
166
166
  }
167
167
  }
@@ -1,7 +1,7 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { createHash, randomBytes } from 'crypto';
3
3
  import { proto } from '../../WAProto/index.js';
4
- const baileysVersion = [2, 3000, 1033846690];
4
+ const baileysVersion = [2, 3000, 1035194821];
5
5
  import { DisconnectReason } from '../Types/index.js';
6
6
  import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
7
7
  import { sha256 } from './crypto.js';
@@ -148,7 +148,6 @@ export const generateMessageIDV2 = (userId) => {
148
148
  };
149
149
  // generate a random ID to attach to a message
150
150
  export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').toUpperCase();
151
-
152
151
  export function bindWaitForEvent(ev, event) {
153
152
  return async (check, timeoutMs) => {
154
153
  let listener;
@@ -11,6 +11,7 @@ export * from './chat-utils.js';
11
11
  export * from './lt-hash.js';
12
12
  export * from './auth-utils.js';
13
13
  export * from './use-multi-file-auth-state.js';
14
+ export * from './use-single-file-auth-state.js';
14
15
  export * from './link-preview.js';
15
16
  export * from './event-buffer.js';
16
17
  export * from './process-message.js';
@@ -4,7 +4,7 @@ const RECENT_MESSAGES_SIZE = 512;
4
4
  const MESSAGE_KEY_SEPARATOR = '\u0000';
5
5
  /** Timeout for session recreation - 1 hour */
6
6
  const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
7
- const PHONE_REQUEST_DELAY = 1000;
7
+ const PHONE_REQUEST_DELAY = 3000;
8
8
  // Retry reason codes matching WhatsApp Web's Signal error codes.
9
9
  export var RetryReason;
10
10
  (function (RetryReason) {
@@ -98,10 +98,11 @@ export async function getMediaKeys(buffer, mediaType) {
98
98
  }
99
99
  /** Extracts video thumb using FFMPEG */
100
100
  export const extractVideoThumb = async (path, time, size) => {
101
- const ff = spawn('ffmpeg', [
101
+ const ffmpeg = spawn('ffmpeg', [
102
102
  '-loglevel', 'error',
103
103
  '-ss', String(time),
104
104
  '-i', path,
105
+ '-an', '-sn', '-dn',
105
106
  '-map_metadata', '-1',
106
107
  '-vf', `scale=${size.width}:-1`,
107
108
  '-frames:v', '1',
@@ -111,18 +112,20 @@ export const extractVideoThumb = async (path, time, size) => {
111
112
  ], {
112
113
  stdio: ['ignore', 'pipe', 'pipe']
113
114
  });
114
- const stdoutChunks = [];
115
+ let buffer = Buffer.alloc(0);
115
116
  const stderrChunks = [];
116
- ff.stdout.on('data', chunk => stdoutChunks.push(chunk));
117
- ff.stderr.on('data', chunk => stderrChunks.push(chunk));
118
- const [code] = await once(ff, 'close');
117
+ ffmpeg.stdout.on('data', (chunk) => {
118
+ buffer = Buffer.concat([buffer, chunk]);
119
+ });
120
+ ffmpeg.stderr.on('data', (chunk) => stderrChunks.push(chunk));
121
+ const [code] = await once(ffmpeg, 'close');
119
122
  if (code !== 0) {
120
123
  throw new Boom(
121
124
  `FFmpeg failed (code ${code}):\n` +
122
125
  Buffer.concat(stderrChunks).toString('utf8')
123
126
  );
124
127
  }
125
- return Buffer.concat(stdoutChunks);
128
+ return buffer;
126
129
  };
127
130
  export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
128
131
  // TODO: Move entirely to sharp, removing jimp as it supports readable streams
@@ -196,8 +199,8 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
196
199
  .default(buffer)
197
200
  .resize(w, h)
198
201
  .jpeg({
199
- quality: 80
200
- })
202
+ quality: 80
203
+ })
201
204
  .toBuffer();
202
205
  }
203
206
  else if ('image' in lib && lib.image?.Transformer) {
@@ -696,9 +699,11 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
696
699
  for (const { hostname } of hosts) {
697
700
  logger.debug(`uploading to "${hostname}"`);
698
701
  const auth = encodeURIComponent(uploadInfo.auth);
699
- // vltcs@changes 06-02-26 --- Switch media path map for newsletter uploads
700
- const mediaPathMap = newsletter ? NEWSLETTER_MEDIA_PATH_MAP : MEDIA_PATH_MAP
701
- const url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
702
+ // Lia@Changes 06-02-26 --- Switch media path map for newsletter uploads
703
+ const mediaPathMap = (newsletter ? NEWSLETTER_MEDIA_PATH_MAP : undefined) || MEDIA_PATH_MAP
704
+ // Lia@Changes 20-03-26 --- Add server thumb for newsletter media
705
+ const serverThumb = newsletter ? '&server_thumb_gen=1' : ''
706
+ const url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}${serverThumb}`;
702
707
  let result;
703
708
  try {
704
709
  result = await uploadMedia({
@@ -715,7 +720,8 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
715
720
  meta_hmac: result.meta_hmac,
716
721
  fbid: result.fbid,
717
722
  ts: result.ts,
718
- handle: result.handle
723
+ thumbnailDirectPath: result.thumbnail_info?.thumbnail_direct_path,
724
+ thumbnailSha256: result.thumbnail_info?.thumbnail_sha256
719
725
  };
720
726
  break;
721
727
  }