@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.
@@ -3,7 +3,7 @@ import {
3
3
  BaichuanRtspServer,
4
4
  ReolinkBaichuanApi,
5
5
  autoDetectDeviceType
6
- } from "../chunk-WQ2TQCYP.js";
6
+ } from "../chunk-JQ5NSEVD.js";
7
7
  import "../chunk-IQVVVSXO.js";
8
8
  import {
9
9
  __require
package/dist/index.cjs CHANGED
@@ -17700,6 +17700,30 @@ function buildSetNtpXml(current, patch) {
17700
17700
  );
17701
17701
  }
17702
17702
 
17703
+ // src/reolink/baichuan/utils/channelEnumeration.ts
17704
+ async function resolveBaichuanChannels(deps) {
17705
+ const fromPush = dedupeSorted(deps.pushChannels);
17706
+ if (fromPush.length > 0) return fromPush;
17707
+ const slots = dedupeSorted(deps.supportChnIds);
17708
+ const candidates = slots.length > 0 ? slots : [0];
17709
+ const probed = await Promise.all(
17710
+ candidates.map(
17711
+ async (channel) => await deps.probe(channel) ? channel : void 0
17712
+ )
17713
+ );
17714
+ return dedupeSorted(
17715
+ probed.filter((c) => c !== void 0)
17716
+ );
17717
+ }
17718
+ function dedupeSorted(values) {
17719
+ const set = /* @__PURE__ */ new Set();
17720
+ for (const v of values) {
17721
+ const n = Number(v);
17722
+ if (Number.isFinite(n) && n >= 0) set.add(n);
17723
+ }
17724
+ return [...set].sort((a, b) => a - b);
17725
+ }
17726
+
17703
17727
  // src/reolink/baichuan/utils/dst.ts
17704
17728
  init_xml();
17705
17729
  var parseNumberSafe3 = (text) => {
@@ -24109,13 +24133,21 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
24109
24133
  * @param options.source - Data source for the channel list (default: `"cgi"`):
24110
24134
  * - `"cgi"`: Uses HTTP `GetChannelstatus` — returns the channel list immediately,
24111
24135
  * no dependency on async push messages. Recommended for first-call discovery.
24112
- * - `"baichuan"`: Uses the cmd_id 145 push cache populated when the NVR sends channel
24113
- * info after login + event subscription. This push is *asynchronous*: if it has not
24114
- * arrived yet, the result will have zero channels. Callers must retry (nvr.ts does this
24115
- * with a 1-second loop). Note: explicitly requesting cmd_id 145 is not supported.
24136
+ * - `"baichuan"`: HTTP-free discovery. Prefers the cmd_id 145 push cache when
24137
+ * populated; otherwise actively probes the channel slots advertised by Support
24138
+ * (`items[].chnID`) via `getInfo`. Use this for hubs with HTTP disabled.
24139
+ *
24140
+ * When the api was constructed with `nativeOnly`, the source is forced to
24141
+ * `"baichuan"` regardless of this option (no HTTP/CGI is ever attempted).
24116
24142
  */
24117
24143
  async getNvrChannelsSummary(options) {
24118
- const source = options?.source ?? "cgi";
24144
+ const source = this.nativeOnly ? "baichuan" : options?.source ?? "cgi";
24145
+ const support = await this.getSupportInfo().catch(() => {
24146
+ this.logger.error?.(
24147
+ "[ReolinkBaichuanApi] getNvrChannelsSummary: failed to get support info"
24148
+ );
24149
+ return void 0;
24150
+ });
24119
24151
  let channels;
24120
24152
  const cgiStatusByChannel = /* @__PURE__ */ new Map();
24121
24153
  if (options?.channels?.length) {
@@ -24145,15 +24177,31 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
24145
24177
  channels = [];
24146
24178
  }
24147
24179
  } else {
24148
- const pushInfo2 = this.getChannelInfoFromPushCache();
24149
- channels = Array.from(pushInfo2.keys()).map((c) => Number(c)).filter((n) => Number.isFinite(n));
24180
+ const pushChannels = Array.from(
24181
+ this.getChannelInfoFromPushCache().keys()
24182
+ ).map((c) => Number(c)).filter((n) => Number.isFinite(n));
24183
+ const supportChnIds = (support?.items ?? []).map((i) => Number(i.chnID)).filter((n) => Number.isFinite(n));
24184
+ const probeTimeoutMs = options?.timeoutMs ?? 2500;
24185
+ channels = await resolveBaichuanChannels({
24186
+ pushChannels,
24187
+ supportChnIds,
24188
+ probe: async (channel) => {
24189
+ try {
24190
+ await this.getInfo(channel, {
24191
+ timeoutMs: probeTimeoutMs,
24192
+ tags: ["type", "name"]
24193
+ });
24194
+ return true;
24195
+ } catch {
24196
+ return false;
24197
+ }
24198
+ }
24199
+ });
24200
+ this.logger.debug?.(
24201
+ `[ReolinkBaichuanApi] getNvrChannelsSummary: baichuan resolved ${channels.length} channel(s): [${channels.join(", ")}]`
24202
+ );
24150
24203
  }
24151
24204
  channels = channels.sort((a, b) => a - b);
24152
- const support = await this.getSupportInfo().catch(() => {
24153
- this.logger.error?.(
24154
- "[ReolinkBaichuanApi] getNvrChannelsSummary: failed to get support info"
24155
- );
24156
- });
24157
24205
  const truthyNumberLike = (v) => {
24158
24206
  if (typeof v === "number") return v > 0;
24159
24207
  if (typeof v === "string") {