@mega-yfue/eufy-sdk 0.4.0-beta.1 → 0.4.0-beta.3

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 CHANGED
@@ -15188,6 +15188,7 @@ var REORDER_MAX_DATAGRAMS = 128;
15188
15188
  var MAX_TRACED_DATAGRAM_GAPS = 8;
15189
15189
  var CMD_SET_PAYLOAD = 1350;
15190
15190
  var CMD_NOTIFY_PAYLOAD = 1351;
15191
+ var PADDED_RESULT_BYTES = 132;
15191
15192
  var CMD_CAMERA_INFO = 1103;
15192
15193
  var CMD_DATABASE_IMAGE = 1308;
15193
15194
  var CMD_DATABASE = 1306;
@@ -15252,7 +15253,10 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
15252
15253
  cloudLookup;
15253
15254
  /** Local outbound IPv4 reported inside LOOKUP_WITH_KEY requests. */
15254
15255
  selfHost;
15255
- /** In-flight multi-datagram frame per data channel (see onData). */
15256
+ /**
15257
+ * In-flight multi-datagram frame per data channel (see reassemble): the payload gathered so far under its
15258
+ * parsed header, or, without a header, the start of a frame header cut by the datagram boundary.
15259
+ */
15256
15260
  pendingByDataType = /* @__PURE__ */ new Map();
15257
15261
  /** Last delivered datagram sequence number per data type. */
15258
15262
  lastSeqByType = /* @__PURE__ */ new Map();
@@ -16627,7 +16631,13 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
16627
16631
  clearTimeout(reorder.timer);
16628
16632
  reorder.timer = void 0;
16629
16633
  }
16630
- /** Reassemble one in-sequence datagram body into logical frames. */
16634
+ /**
16635
+ * Reassemble one in-sequence datagram body into logical frames.
16636
+ *
16637
+ * Frames are packed back to back, so a frame header can itself be cut by a datagram boundary. The start
16638
+ * of a header left at the end of a datagram is carried into the next one rather than discarded; dropping
16639
+ * it would lose that frame and every frame after it until a datagram happened to begin on a header.
16640
+ */
16631
16641
  reassemble(dataType, datagramBody) {
16632
16642
  const pending = this.pendingByDataType.get(dataType);
16633
16643
  let body = pending ? Buffer.concat([pending.buf, datagramBody]) : datagramBody;
@@ -16651,6 +16661,9 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
16651
16661
  this.handleFrame(header, payload.subarray(0, header.bytesToRead), dataType);
16652
16662
  body = body.subarray(P2P_DATA_HEADER_BYTES + header.bytesToRead);
16653
16663
  }
16664
+ if (body.length > 0 && body.length < P2P_DATA_HEADER_BYTES && MAGIC_WORD.startsWith(body.subarray(0, 4).toString())) {
16665
+ this.pendingByDataType.set(dataType, { buf: body });
16666
+ }
16654
16667
  }
16655
16668
  /**
16656
16669
  * Forget where each data type's sequence numbering had reached, and drop any half-reassembled frame.
@@ -16735,7 +16748,8 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
16735
16748
  this.emit("error", e instanceof Error ? e : new Error(String(e)));
16736
16749
  }
16737
16750
  }
16738
- if (!isMedia && !frame.json && data.length === 4) {
16751
+ const paddedResult = header.commandId === CMD_SET_PAYLOAD && data.length === PADDED_RESULT_BYTES && data.subarray(4).every((b) => b === 0);
16752
+ if (!isMedia && !frame.json && (data.length === 4 || paddedResult)) {
16739
16753
  this.emit("commandResult", { code: data.readInt32LE(0), channel: header.channel });
16740
16754
  }
16741
16755
  this.emit("data", frame);