@apocaliss92/scrypted-reolink-native 0.5.28 → 0.5.29

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/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apocaliss92/scrypted-reolink-native",
3
- "version": "0.5.28",
3
+ "version": "0.5.29",
4
4
  "description": "Use any reolink camera with Scrypted, even older/unsupported models without HTTP protocol support",
5
5
  "author": "@apocaliss92",
6
6
  "license": "Apache",
@@ -486,19 +486,30 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
486
486
  this.lastDisconnectTime = now;
487
487
 
488
488
  logger.log(
489
- `Socket closed, resetting client state for reconnection${timeSinceLastDisconnect != null ? ` (last disconnect ${timeSinceLastDisconnect}ms ago)` : " (first disconnect)"}`,
489
+ `Socket closed${timeSinceLastDisconnect != null ? ` (last disconnect ${timeSinceLastDisconnect}ms ago)` : " (first disconnect)"} — api object kept alive, will reconnect on next use`,
490
490
  );
491
491
 
492
- // Mark as disconnected immediately to prevent reuse
493
- // This prevents race conditions where ensureBaichuanClient might check
494
- // isSocketConnected() before cleanup completes
495
- const currentApi = this.baichuanApi;
496
- if (currentApi === api) {
497
- // Only cleanup if this is still the current API instance
498
- // This prevents cleanup of a new connection that was created
499
- // while the old one was closing
500
- await this.cleanupBaichuanApi();
501
- }
492
+ // The api object itself stays alive across socket disconnects:
493
+ // - It's NOT explicitly closed (no `_closed = true`), so simple
494
+ // event listeners, the email-push auto-bridge (when used),
495
+ // recordings cache, sleep inference state, etc. are preserved
496
+ // for the next reconnect cycle.
497
+ // - The next `ensureBaichuanClient` call sees `api.isReady=false`
498
+ // AND `api.isClosed=false` and routes through
499
+ // `api.ensureConnected()`, which reuses the same api with a
500
+ // freshly reconnected socket pool — see the
501
+ // `socket disconnected but API still valid` branch above.
502
+ // - If the lib reconnect fails repeatedly, the same caller
503
+ // falls back to `cleanupBaichuanApi()` + full recreate (the
504
+ // catch around `ensureConnected()` in ensureBaichuanClient).
505
+ //
506
+ // Calling `cleanupBaichuanApi()` here would defeat all of that:
507
+ // it sets `_closed=true` (next ensureBaichuanClient destroys +
508
+ // recreates from scratch), and worse it tears down any consumer
509
+ // registered against `api.simpleEventListeners` — like the lib
510
+ // email-push auto-bridge — for the entire gap until the next
511
+ // `ensureBaichuanClient` call (which on battery cams can be
512
+ // minutes). We deliberately don't.
502
513
 
503
514
  // Call custom close handler if provided
504
515
  if (callbacks.onClose) {