@apocaliss92/nodelink-js 0.6.5 → 0.6.6

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.
@@ -17027,6 +17027,30 @@ function buildSetNtpXml(current, patch) {
17027
17027
  );
17028
17028
  }
17029
17029
 
17030
+ // src/reolink/baichuan/utils/channelEnumeration.ts
17031
+ async function resolveBaichuanChannels(deps) {
17032
+ const fromPush = dedupeSorted(deps.pushChannels);
17033
+ if (fromPush.length > 0) return fromPush;
17034
+ const slots = dedupeSorted(deps.supportChnIds);
17035
+ const candidates = slots.length > 0 ? slots : [0];
17036
+ const probed = await Promise.all(
17037
+ candidates.map(
17038
+ async (channel) => await deps.probe(channel) ? channel : void 0
17039
+ )
17040
+ );
17041
+ return dedupeSorted(
17042
+ probed.filter((c) => c !== void 0)
17043
+ );
17044
+ }
17045
+ function dedupeSorted(values) {
17046
+ const set = /* @__PURE__ */ new Set();
17047
+ for (const v of values) {
17048
+ const n = Number(v);
17049
+ if (Number.isFinite(n) && n >= 0) set.add(n);
17050
+ }
17051
+ return [...set].sort((a, b) => a - b);
17052
+ }
17053
+
17030
17054
  // src/reolink/baichuan/utils/dst.ts
17031
17055
  init_xml();
17032
17056
  var parseNumberSafe3 = (text) => {
@@ -23405,13 +23429,21 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
23405
23429
  * @param options.source - Data source for the channel list (default: `"cgi"`):
23406
23430
  * - `"cgi"`: Uses HTTP `GetChannelstatus` — returns the channel list immediately,
23407
23431
  * no dependency on async push messages. Recommended for first-call discovery.
23408
- * - `"baichuan"`: Uses the cmd_id 145 push cache populated when the NVR sends channel
23409
- * info after login + event subscription. This push is *asynchronous*: if it has not
23410
- * arrived yet, the result will have zero channels. Callers must retry (nvr.ts does this
23411
- * with a 1-second loop). Note: explicitly requesting cmd_id 145 is not supported.
23432
+ * - `"baichuan"`: HTTP-free discovery. Prefers the cmd_id 145 push cache when
23433
+ * populated; otherwise actively probes the channel slots advertised by Support
23434
+ * (`items[].chnID`) via `getInfo`. Use this for hubs with HTTP disabled.
23435
+ *
23436
+ * When the api was constructed with `nativeOnly`, the source is forced to
23437
+ * `"baichuan"` regardless of this option (no HTTP/CGI is ever attempted).
23412
23438
  */
23413
23439
  async getNvrChannelsSummary(options) {
23414
- const source = options?.source ?? "cgi";
23440
+ const source = this.nativeOnly ? "baichuan" : options?.source ?? "cgi";
23441
+ const support = await this.getSupportInfo().catch(() => {
23442
+ this.logger.error?.(
23443
+ "[ReolinkBaichuanApi] getNvrChannelsSummary: failed to get support info"
23444
+ );
23445
+ return void 0;
23446
+ });
23415
23447
  let channels;
23416
23448
  const cgiStatusByChannel = /* @__PURE__ */ new Map();
23417
23449
  if (options?.channels?.length) {
@@ -23441,15 +23473,31 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
23441
23473
  channels = [];
23442
23474
  }
23443
23475
  } else {
23444
- const pushInfo2 = this.getChannelInfoFromPushCache();
23445
- channels = Array.from(pushInfo2.keys()).map((c) => Number(c)).filter((n) => Number.isFinite(n));
23476
+ const pushChannels = Array.from(
23477
+ this.getChannelInfoFromPushCache().keys()
23478
+ ).map((c) => Number(c)).filter((n) => Number.isFinite(n));
23479
+ const supportChnIds = (support?.items ?? []).map((i) => Number(i.chnID)).filter((n) => Number.isFinite(n));
23480
+ const probeTimeoutMs = options?.timeoutMs ?? 2500;
23481
+ channels = await resolveBaichuanChannels({
23482
+ pushChannels,
23483
+ supportChnIds,
23484
+ probe: async (channel) => {
23485
+ try {
23486
+ await this.getInfo(channel, {
23487
+ timeoutMs: probeTimeoutMs,
23488
+ tags: ["type", "name"]
23489
+ });
23490
+ return true;
23491
+ } catch {
23492
+ return false;
23493
+ }
23494
+ }
23495
+ });
23496
+ this.logger.debug?.(
23497
+ `[ReolinkBaichuanApi] getNvrChannelsSummary: baichuan resolved ${channels.length} channel(s): [${channels.join(", ")}]`
23498
+ );
23446
23499
  }
23447
23500
  channels = channels.sort((a, b) => a - b);
23448
- const support = await this.getSupportInfo().catch(() => {
23449
- this.logger.error?.(
23450
- "[ReolinkBaichuanApi] getNvrChannelsSummary: failed to get support info"
23451
- );
23452
- });
23453
23501
  const truthyNumberLike = (v) => {
23454
23502
  if (typeof v === "number") return v > 0;
23455
23503
  if (typeof v === "string") {