@apocaliss92/scrypted-reolink-native 0.3.8 → 0.3.9

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.3.8",
3
+ "version": "0.3.9",
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",
@@ -485,7 +485,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
485
485
  */
486
486
  private getAllActiveConnections(): ReolinkBaichuanApi[] {
487
487
  const connections: ReolinkBaichuanApi[] = [];
488
-
488
+
489
489
  // Add main connection if exists and is valid
490
490
  if (this.baichuanApi) {
491
491
  const isConnected = this.baichuanApi.client.isSocketConnected();
@@ -494,7 +494,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
494
494
  connections.push(this.baichuanApi);
495
495
  }
496
496
  }
497
-
497
+
498
498
  // Add all stream clients that are valid
499
499
  for (const streamClient of this.streamClients.values()) {
500
500
  const isConnected = streamClient.client.isSocketConnected();
@@ -503,7 +503,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
503
503
  connections.push(streamClient);
504
504
  }
505
505
  }
506
-
506
+
507
507
  return connections;
508
508
  }
509
509
 
@@ -512,7 +512,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
512
512
  */
513
513
  private startConnectionMaintenance(api: ReolinkBaichuanApi): void {
514
514
  const logger = this.getBaichuanLogger();
515
-
515
+
516
516
  // Stop any existing intervals
517
517
  this.stopConnectionMaintenance();
518
518
 
@@ -526,11 +526,11 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
526
526
  // Get all active connections (main + stream clients)
527
527
  const allConnections = this.getAllActiveConnections();
528
528
  logger.debug(`Pinging ${allConnections.length} connections`);
529
-
529
+
530
530
  if (allConnections.length === 0) {
531
531
  this.consecutivePingFailures++;
532
532
  logger.debug(`No active connections found, failures=${this.consecutivePingFailures}`);
533
-
533
+
534
534
  if (this.consecutivePingFailures >= 3) {
535
535
  logger.log('No active connections detected, renewing connection');
536
536
  await this.cleanupBaichuanApi();
@@ -557,7 +557,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
557
557
  if (failedPings.length > 0) {
558
558
  this.consecutivePingFailures++;
559
559
  logger.debug(`Ping failed for ${failedPings.length}/${allConnections.length} connections, failures=${this.consecutivePingFailures}`);
560
-
560
+
561
561
  if (this.consecutivePingFailures >= 3) {
562
562
  logger.log(`Multiple ping failures detected (${failedPings.length} connections), renewing connection`);
563
563
  await this.cleanupBaichuanApi();
@@ -584,7 +584,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
584
584
  try {
585
585
  // Check if there are active streams
586
586
  const hasActiveStreams = this.getStreamManager?.()?.hasActiveStreams() ?? false;
587
-
587
+
588
588
  if (!hasActiveStreams) {
589
589
  logger.log('No active streams detected, renewing connection (auto-renewal)');
590
590
  await this.cleanupBaichuanApi();
@@ -617,7 +617,7 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
617
617
  */
618
618
  private startEventCheck(api: ReolinkBaichuanApi): void {
619
619
  const logger = this.getBaichuanLogger();
620
-
620
+
621
621
  // Stop any existing interval
622
622
  this.stopEventCheck();
623
623
 
@@ -717,13 +717,11 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
717
717
  // Call original handler
718
718
  originalHandler(ev);
719
719
  };
720
-
720
+
721
721
  await api.onSimpleEvent(wrappedHandler);
722
722
  this.eventSubscriptionActive = true;
723
723
  this.lastEventTime = Date.now(); // Initialize on subscription
724
- if (!silent) {
725
- logger.debug('Subscribed to Baichuan events');
726
- }
724
+ logger.debug('Subscribed to Baichuan events');
727
725
  }
728
726
  catch (e) {
729
727
  logger.warn('Failed to subscribe to events', e?.message || String(e));
@@ -743,14 +741,10 @@ export abstract class BaseBaichuanClass extends ScryptedDeviceBase {
743
741
  if (this.eventSubscriptionActive && this.baichuanApi && callbacks.onSimpleEvent) {
744
742
  try {
745
743
  this.baichuanApi.offSimpleEvent(callbacks.onSimpleEvent);
746
- if (!silent) {
747
- logger.debug('Unsubscribed from Baichuan events');
748
- }
744
+ logger.debug('Unsubscribed from Baichuan events');
749
745
  }
750
746
  catch (e) {
751
- if (!silent) {
752
- logger.warn('Error unsubscribing from events', e?.message || String(e));
753
- }
747
+ logger.warn('Error unsubscribing from events', e?.message || String(e));
754
748
  }
755
749
  }
756
750
 
package/src/camera.ts CHANGED
@@ -1731,7 +1731,7 @@ export class ReolinkCamera extends BaseBaichuanClass implements VideoCamera, Cam
1731
1731
  * If this device has a parent (nvrDevice or multiFocalDevice), events will be forwarded from the parent.
1732
1732
  * This ensures that only the root device in the hierarchy subscribes to events, avoiding duplicate subscriptions.
1733
1733
  */
1734
- async subscribeToEvents(): Promise<void> {
1734
+ async subscribeToEvents(silent: boolean = false): Promise<void> {
1735
1735
  // If this device has a parent (NVR or MultiFocal), don't subscribe - events will be forwarded from parent
1736
1736
  if (this.nvrDevice || this.multiFocalDevice) {
1737
1737
  const logger = this.getBaichuanLogger();
@@ -1754,7 +1754,9 @@ export class ReolinkCamera extends BaseBaichuanClass implements VideoCamera, Cam
1754
1754
  }
1755
1755
 
1756
1756
  if (!enabled) {
1757
- logger.log('Event subscription disabled, unsubscribing');
1757
+ if (!silent) {
1758
+ logger.log('Event subscription disabled, unsubscribing');
1759
+ }
1758
1760
  if (this.doorbellBinaryTimeout) {
1759
1761
  clearTimeout(this.doorbellBinaryTimeout);
1760
1762
  this.doorbellBinaryTimeout = undefined;
@@ -1766,8 +1768,10 @@ export class ReolinkCamera extends BaseBaichuanClass implements VideoCamera, Cam
1766
1768
  // IMPORTANT: use base subscription logic so the callback is properly bound.
1767
1769
  // Passing `this.onSimpleEvent` directly would lose `this` and can result in silent failures.
1768
1770
  try {
1769
- await super.subscribeToEvents();
1770
- logger.log(`Subscribed to events (${selection.join(', ')}) on ${this.protocol} connection`);
1771
+ await super.subscribeToEvents(silent);
1772
+ if (!silent) {
1773
+ logger.log(`Subscribed to events (${selection.join(', ')}) on ${this.protocol} connection`);
1774
+ }
1771
1775
  }
1772
1776
  catch (e) {
1773
1777
  logger.warn('Failed to subscribe to Baichuan events', e?.message || String(e));