@apocaliss92/nodelink-js 0.4.31 → 0.4.33

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-XVFCEFM6.js";
6
+ } from "../chunk-OZL6C2YJ.js";
7
7
  import "../chunk-AHY4L7JI.js";
8
8
  import {
9
9
  __require
package/dist/index.cjs CHANGED
@@ -19820,6 +19820,13 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
19820
19820
  * Once closed, the API instance should not be reused.
19821
19821
  */
19822
19822
  _closed = false;
19823
+ /**
19824
+ * Off-handle for the auto-bridge between the global email-push bus
19825
+ * and this api's `simpleEventListeners`. Set in the constructor
19826
+ * when `emailPushCameraId` is provided; released in `close()`.
19827
+ * `undefined` means no bridge was requested for this api.
19828
+ */
19829
+ emailPushAutoBridgeOff;
19823
19830
  // ─────────────────────────────────────────────────────────────────────────────
19824
19831
  // SOCKET POOL - Tag-based socket management
19825
19832
  // ─────────────────────────────────────────────────────────────────────────────
@@ -20192,6 +20199,21 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
20192
20199
  // check every 10s
20193
20200
  simpleEventWatchdogSilenceThresholdMs = 5 * 6e4;
20194
20201
  // 5 min without events
20202
+ /**
20203
+ * Whether the silence-based resubscribe path of the watchdog is
20204
+ * enabled. On UDP (battery cameras) silence is the *normal* state
20205
+ * while the device sleeps — firing `ensureSimpleEventSubscribed`
20206
+ * every 5 minutes wakes the camera on every tick, drains the
20207
+ * battery, and is observably wrong because the cam emits a
20208
+ * sleep/awake push when it actually wakes for motion.
20209
+ *
20210
+ * Defaults: `false` on UDP, `true` on TCP / `auto`. The subscription-
20211
+ * failed recovery path (Case 2) stays active regardless — it only
20212
+ * runs when the connection is alive, doesn't wake anyone, and is
20213
+ * useful on every transport when the initial subscribe call lost
20214
+ * the response packet.
20215
+ */
20216
+ eventWatchdogSilenceResubscribeEnabled = true;
20195
20217
  statePollingInterval;
20196
20218
  udpSleepInferenceInterval;
20197
20219
  udpLastInferredSleepStateByChannel = /* @__PURE__ */ new Map();
@@ -21149,6 +21171,12 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
21149
21171
  } else {
21150
21172
  this.eventResubscribeEnabled = opts.transport !== "udp";
21151
21173
  }
21174
+ const explicitWatchdogResubscribe = opts.enableEventWatchdogSilenceResubscribe;
21175
+ if (typeof explicitWatchdogResubscribe === "boolean") {
21176
+ this.eventWatchdogSilenceResubscribeEnabled = explicitWatchdogResubscribe;
21177
+ } else {
21178
+ this.eventWatchdogSilenceResubscribeEnabled = opts.transport !== "udp";
21179
+ }
21152
21180
  const maxSessions = opts.maxDedicatedSessionsBeforeReboot;
21153
21181
  if (typeof maxSessions === "number" && Number.isFinite(maxSessions) && maxSessions > 0) {
21154
21182
  this.maxDedicatedSessionsBeforeReboot = Math.floor(maxSessions);
@@ -21162,6 +21190,12 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
21162
21190
  this.rebootAfterConsecutiveEconnreset = Math.floor(econnresetThreshold);
21163
21191
  }
21164
21192
  this.setupGeneralClientListeners();
21193
+ if (opts.emailPushCameraId) {
21194
+ this.emailPushAutoBridgeOff = this.subscribeEmailPushEvents({
21195
+ cameraId: opts.emailPushCameraId,
21196
+ channel: opts.emailPushChannel ?? 0
21197
+ });
21198
+ }
21165
21199
  }
21166
21200
  /**
21167
21201
  * CGI forward: fetch RTSP URL for a channel via `GetRtspUrl`.
@@ -21965,6 +21999,14 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
21965
21999
  if (this.simpleEventSubscribed && this.simpleEventLastReceivedAt > 0) {
21966
22000
  const silence = now - this.simpleEventLastReceivedAt;
21967
22001
  if (silence < this.simpleEventWatchdogSilenceThresholdMs) return;
22002
+ if (!this.eventWatchdogSilenceResubscribeEnabled) {
22003
+ this.logger.debug?.(
22004
+ `[ReolinkBaichuanApi] event watchdog: silence-based resubscribe disabled (UDP / battery), skipping`,
22005
+ { host: this.host, silenceMs: silence }
22006
+ );
22007
+ this.simpleEventLastReceivedAt = now;
22008
+ return;
22009
+ }
21968
22010
  (this.logger.warn ?? this.logger.log).call(
21969
22011
  this.logger,
21970
22012
  `[ReolinkBaichuanApi] event watchdog: no events for ${Math.round(silence / 6e4)} min, forcing resubscribe`,
@@ -22285,6 +22327,13 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
22285
22327
  async close(options) {
22286
22328
  if (this._closed) return;
22287
22329
  this._closed = true;
22330
+ if (this.emailPushAutoBridgeOff) {
22331
+ try {
22332
+ this.emailPushAutoBridgeOff();
22333
+ } catch {
22334
+ }
22335
+ this.emailPushAutoBridgeOff = void 0;
22336
+ }
22288
22337
  if (this.sessionGuardIntervalTimer) {
22289
22338
  clearInterval(this.sessionGuardIntervalTimer);
22290
22339
  this.sessionGuardIntervalTimer = void 0;