@apocaliss92/nodelink-js 0.3.4 → 0.3.5

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.
@@ -11371,6 +11371,22 @@ var BaichuanClient = class _BaichuanClient extends import_node_events4.EventEmit
11371
11371
  static coverPreviewBackoffMs = /* @__PURE__ */ new Map();
11372
11372
  static COVER_PREVIEW_INITIAL_BACKOFF_MS = 1e3;
11373
11373
  static COVER_PREVIEW_MAX_BACKOFF_MS = 3e4;
11374
+ /**
11375
+ * Per-client snapshot (cmd_id=109) serialization queue.
11376
+ *
11377
+ * WHY: On NVR/multi-camera devices sharing one socket, concurrent snapshot requests
11378
+ * can cause JPEG data to mix (even with per-request msgNum filtering):
11379
+ * - Camera A and B both send frames on same socket
11380
+ * - Frame listener is global per socket
11381
+ * - Timing quirks can cause chunk reordering or listener confusion
11382
+ *
11383
+ * FIX: Serialize all cmd_id=109 requests on THIS client instance.
11384
+ * Each snapshot waits for previous one to complete before starting.
11385
+ * This ensures clean frame sequences per request, zero data corruption.
11386
+ *
11387
+ * Impact: Snapshots are ~0–50ms slower per camera (negligible for users).
11388
+ */
11389
+ snapshotQueueTail = Promise.resolve();
11374
11390
  opts;
11375
11391
  debugCfg;
11376
11392
  logger;
@@ -13852,6 +13868,20 @@ var BaichuanClient = class _BaichuanClient extends import_node_events4.EventEmit
13852
13868
  });
13853
13869
  }
13854
13870
  async sendBinarySnapshot109(params) {
13871
+ const prevTail = this.snapshotQueueTail;
13872
+ let resolve;
13873
+ const newTail = new Promise((r) => {
13874
+ resolve = r;
13875
+ });
13876
+ this.snapshotQueueTail = newTail;
13877
+ try {
13878
+ await prevTail;
13879
+ return await this.sendBinarySnapshot109Impl(params);
13880
+ } finally {
13881
+ resolve();
13882
+ }
13883
+ }
13884
+ async sendBinarySnapshot109Impl(params) {
13855
13885
  await this.connect();
13856
13886
  const channel = params.channel ?? this.opts.channel ?? 0;
13857
13887
  const channelId = params.channelIdOverride ?? (params.channel == null ? this.hostChannelId : channel + 1);
@@ -13911,7 +13941,8 @@ var BaichuanClient = class _BaichuanClient extends import_node_events4.EventEmit
13911
13941
  };
13912
13942
  const onFrame = (frame) => {
13913
13943
  if (frame.header.cmdId !== cmdId) return;
13914
- if (frame.header.msgNum === msgNum && frame.header.responseCode >= 400) {
13944
+ if (frame.header.msgNum !== msgNum) return;
13945
+ if (frame.header.responseCode >= 400) {
13915
13946
  fail(
13916
13947
  new Error(
13917
13948
  `Baichuan snapshot request rejected (cmdId=${cmdId} msgNum=${msgNum} responseCode=${frame.header.responseCode})`