@mega-yfue/eufy-sdk 0.5.0-beta.34 → 0.5.0-beta.35
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/dist/index.js +12 -9
- package/dist/index.js.map +2 -2
- package/dist/transport/p2p/p2p-session.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17119,32 +17119,35 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
17119
17119
|
* Frames are packed back to back, so a frame header can itself be cut by a datagram boundary. The start
|
|
17120
17120
|
* of a header left at the end of a datagram is carried into the next one rather than discarded; dropping
|
|
17121
17121
|
* it would lose that frame and every frame after it until a datagram happened to begin on a header.
|
|
17122
|
+
* Payload fragments retain their original slices and are copied once, when the complete frame is delivered.
|
|
17122
17123
|
*/
|
|
17123
17124
|
reassemble(dataType, datagramBody) {
|
|
17124
17125
|
const pending = this.pendingByDataType.get(dataType);
|
|
17125
|
-
let body = pending ? Buffer.concat([pending.buf, datagramBody]) : datagramBody;
|
|
17126
|
-
const carryHeader = pending?.header;
|
|
17127
17126
|
this.pendingByDataType.delete(dataType);
|
|
17128
|
-
|
|
17129
|
-
|
|
17130
|
-
|
|
17127
|
+
let body = pending && !pending.header ? Buffer.concat([...pending.chunks, datagramBody]) : datagramBody;
|
|
17128
|
+
if (pending?.header) {
|
|
17129
|
+
const taken = Math.min(pending.header.bytesToRead - pending.byteLength, body.length);
|
|
17130
|
+
pending.chunks.push(body.subarray(0, taken));
|
|
17131
|
+
pending.byteLength += taken;
|
|
17132
|
+
body = body.subarray(taken);
|
|
17133
|
+
if (pending.byteLength < pending.header.bytesToRead) {
|
|
17134
|
+
this.pendingByDataType.set(dataType, pending);
|
|
17131
17135
|
return;
|
|
17132
17136
|
}
|
|
17133
|
-
this.handleFrame(
|
|
17134
|
-
body = body.subarray(carryHeader.bytesToRead);
|
|
17137
|
+
this.handleFrame(pending.header, Buffer.concat(pending.chunks, pending.byteLength), dataType);
|
|
17135
17138
|
}
|
|
17136
17139
|
while (body.length >= P2P_DATA_HEADER_BYTES && body.subarray(0, 4).toString() === MAGIC_WORD) {
|
|
17137
17140
|
const header = parseDataFrameHeader(body);
|
|
17138
17141
|
const payload = body.subarray(P2P_DATA_HEADER_BYTES);
|
|
17139
17142
|
if (payload.length < header.bytesToRead) {
|
|
17140
|
-
this.pendingByDataType.set(dataType, { header,
|
|
17143
|
+
this.pendingByDataType.set(dataType, { header, chunks: [payload], byteLength: payload.length });
|
|
17141
17144
|
return;
|
|
17142
17145
|
}
|
|
17143
17146
|
this.handleFrame(header, payload.subarray(0, header.bytesToRead), dataType);
|
|
17144
17147
|
body = body.subarray(P2P_DATA_HEADER_BYTES + header.bytesToRead);
|
|
17145
17148
|
}
|
|
17146
17149
|
if (body.length > 0 && body.length < P2P_DATA_HEADER_BYTES && MAGIC_WORD.startsWith(body.subarray(0, 4).toString())) {
|
|
17147
|
-
this.pendingByDataType.set(dataType, {
|
|
17150
|
+
this.pendingByDataType.set(dataType, { chunks: [body], byteLength: body.length });
|
|
17148
17151
|
}
|
|
17149
17152
|
}
|
|
17150
17153
|
/**
|