@oxidezap/baileyrs 0.2.0 → 0.2.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.
- package/lib/Socket/transport.js +23 -3
- package/package.json +2 -2
package/lib/Socket/transport.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `WebSocket.send()` takes a `BufferSource`, which is `ArrayBufferView<ArrayBuffer>
|
|
3
|
+
* | ArrayBuffer` — a `SharedArrayBuffer`-backed view is outside that contract.
|
|
4
|
+
* The bridge hands us the wider `Uint8Array<ArrayBufferLike>`, so the backing
|
|
5
|
+
* buffer has to be discriminated at runtime; this predicate is what carries that
|
|
6
|
+
* runtime check into the type system.
|
|
7
|
+
*/
|
|
8
|
+
const isArrayBufferBacked = (data) => data.buffer instanceof ArrayBuffer;
|
|
9
|
+
/**
|
|
10
|
+
* Narrows an outgoing frame to what `WebSocket.send()` accepts.
|
|
11
|
+
*
|
|
12
|
+
* The `ArrayBuffer` case returns the caller's view as-is. Rebuilding it — the
|
|
13
|
+
* `new Uint8Array(data.buffer, data.byteOffset, data.byteLength)` this used to
|
|
14
|
+
* do — produced a view over the same buffer at the same offset and length: an
|
|
15
|
+
* allocation per outgoing frame that existed only to restate the type. It also
|
|
16
|
+
* did not detach the view from WASM memory growth, so returning the original
|
|
17
|
+
* gives the payload exactly the lifetime it had before; both are aliases of the
|
|
18
|
+
* same linear memory, consumed synchronously by the `ws.send()` on the next line.
|
|
19
|
+
*
|
|
20
|
+
* The `SharedArrayBuffer` case still copies: that one is not a type formality,
|
|
21
|
+
* the send API genuinely cannot take a view over shared memory.
|
|
22
|
+
*/
|
|
23
|
+
const asWebSocketPayload = (data) => isArrayBufferBacked(data) ? data : new Uint8Array(data);
|
|
4
24
|
export const makeTransport = (config) => {
|
|
5
25
|
const { waWebSocketUrl, logger } = config;
|
|
6
26
|
let ws;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxidezap/baileyrs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@hapi/boom": "^9.1.4",
|
|
85
|
-
"@oxidezap/whatsapp-rust-bridge": "0.
|
|
85
|
+
"@oxidezap/whatsapp-rust-bridge": "0.12.0",
|
|
86
86
|
"long": "^5.3.2",
|
|
87
87
|
"pino": "^10.3.1",
|
|
88
88
|
"protobufjs": "^7.6.5"
|