@oxidezap/baileyrs 0.0.30 → 0.0.32
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/lib/Socket/events.js +14 -20
- package/package.json +2 -2
package/lib/Socket/events.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* is a compile error.
|
|
8
8
|
*/
|
|
9
9
|
import Long from 'long';
|
|
10
|
-
import { BinaryReader,
|
|
10
|
+
import { BinaryReader, decodeMessageWireBatch, decodeReceiptWireBatch, decodeServerAckWireBatch } from 'whatsapp-rust-bridge';
|
|
11
11
|
import { adaptBridgeEvent, adaptBridgeMessageWire } from '../Bridge/index.js';
|
|
12
12
|
import { decodeHistorySyncWireBatch } from '../Bridge/history-sync-wire.js';
|
|
13
13
|
import { bridgeGroupMetadataToBaileys } from '../Compatibility/group-metadata.js';
|
|
@@ -25,7 +25,6 @@ import { mapReachoutTimelock } from './reachout.js';
|
|
|
25
25
|
const CANONICAL_MESSAGE_EVENT = 'message';
|
|
26
26
|
const MESSAGE_UPSERT_APPEND = 'append';
|
|
27
27
|
const MESSAGE_UPSERT_NOTIFY = 'notify';
|
|
28
|
-
const MESSAGE_WIRE_OFFSET_SENTINEL_COUNT = 1;
|
|
29
28
|
/** Emit CB: pattern events on the ws EventEmitter for retrocompat. */
|
|
30
29
|
const emitCBEvents = (ctx, node) => {
|
|
31
30
|
const { ws } = ctx;
|
|
@@ -791,35 +790,30 @@ export const makeEventHandlers = (ctx, callbacks) => {
|
|
|
791
790
|
dispatchCanonicalEvent(canonical, dispatchCtx);
|
|
792
791
|
};
|
|
793
792
|
const onMessageBatch = (batch) => {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
const messageCount = batch.messageOffsets.length - MESSAGE_WIRE_OFFSET_SENTINEL_COUNT;
|
|
799
|
-
let infos;
|
|
793
|
+
// The batch crosses as one buffer; the decoder validates its header and
|
|
794
|
+
// returns views over it, so payload count and metadata count agree by
|
|
795
|
+
// construction.
|
|
796
|
+
let view;
|
|
800
797
|
try {
|
|
801
|
-
|
|
798
|
+
view = decodeMessageWireBatch(batch);
|
|
802
799
|
}
|
|
803
800
|
catch (err) {
|
|
804
|
-
ctx.logger.error({ err }, 'failed to decode message wire
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
if (infos.length !== messageCount) {
|
|
808
|
-
ctx.logger.error({ infoCount: infos.length, messageCount }, 'message wire batch metadata count does not match its payload count');
|
|
801
|
+
ctx.logger.error({ err }, 'failed to decode the message wire batch');
|
|
809
802
|
return;
|
|
810
803
|
}
|
|
804
|
+
const { messageData, messageOffsets, infos } = view;
|
|
811
805
|
// Decode through the runtime facade so each payload materializes as a
|
|
812
806
|
// hydrated runtime instance: `WebMessageInfo.fromObject` then keeps the
|
|
813
807
|
// message subtree via its instanceof short-circuit instead of walking
|
|
814
808
|
// and reallocating the whole tree — the dominant per-message allocation
|
|
815
809
|
// cost on the hot path. Lenient like the history-sync decoder: one
|
|
816
810
|
// malformed payload is skipped, not fatal to the batch.
|
|
817
|
-
const messages = Array.from({ length:
|
|
818
|
-
const reader = new BinaryReader(
|
|
819
|
-
for (let index = 0; index <
|
|
811
|
+
const messages = Array.from({ length: infos.length });
|
|
812
|
+
const reader = new BinaryReader(messageData);
|
|
813
|
+
for (let index = 0; index < infos.length; index++) {
|
|
820
814
|
try {
|
|
821
|
-
const start =
|
|
822
|
-
const end =
|
|
815
|
+
const start = messageOffsets[index];
|
|
816
|
+
const end = messageOffsets[index + 1];
|
|
823
817
|
reader.pos = start;
|
|
824
818
|
messages[index] = WAProto.Message.decode(reader, end - start);
|
|
825
819
|
}
|
|
@@ -828,7 +822,7 @@ export const makeEventHandlers = (ctx, callbacks) => {
|
|
|
828
822
|
ctx.logger.warn({ err, index }, 'skipping malformed wire message');
|
|
829
823
|
}
|
|
830
824
|
}
|
|
831
|
-
dispatchCanonicalBatch(ctx, dispatchCtx,
|
|
825
|
+
dispatchCanonicalBatch(ctx, dispatchCtx, infos.length, index => adaptBridgeMessageWire(messages[index], infos[index], ctx.logger));
|
|
832
826
|
};
|
|
833
827
|
const onHistorySyncBatch = (batch) => {
|
|
834
828
|
const decoded = decodeHistorySyncWireBatch(batch, ctx.logger);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxidezap/baileyrs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.32",
|
|
5
5
|
"description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"long": "^5.3.2",
|
|
79
79
|
"pino": "^10.3.1",
|
|
80
80
|
"protobufjs": "^7.6.5",
|
|
81
|
-
"whatsapp-rust-bridge": "0.6.0-alpha.
|
|
81
|
+
"whatsapp-rust-bridge": "0.6.0-alpha.42"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@bufbuild/protobuf": "^2.13.0",
|