@apocaliss92/nodelink-js 0.2.5 → 0.3.4

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/index.js CHANGED
@@ -22,7 +22,11 @@ import {
22
22
  createTaggedLogger,
23
23
  decodeHeader,
24
24
  discoverReolinkDevices,
25
+ discoverViaArpTable,
26
+ discoverViaDhcpListener,
25
27
  discoverViaHttpScan,
28
+ discoverViaOnvif,
29
+ discoverViaTcpPortScan,
26
30
  discoverViaUdpBroadcast,
27
31
  discoverViaUdpDirect,
28
32
  encodeHeader,
@@ -38,7 +42,7 @@ import {
38
42
  normalizeUid,
39
43
  parseSupportXml,
40
44
  setGlobalLogger
41
- } from "./chunk-EG5IY3CM.js";
45
+ } from "./chunk-YSEFEQYV.js";
42
46
  import {
43
47
  AesStreamDecryptor,
44
48
  BC_AES_IV,
@@ -586,51 +590,18 @@ var AutodiscoveryClient = class {
586
590
  scanTimer = null;
587
591
  isRunning = false;
588
592
  currentScanPromise = null;
589
- /**
590
- * Costruttore del client di autodiscovery.
591
- *
592
- * @param options - Opzioni di configurazione per il discovery
593
- */
594
593
  constructor(options = {}) {
595
594
  this.options = {
596
- scanIntervalMs: options.scanIntervalMs ?? 6e4,
597
- // Default: 60 secondi
595
+ ...options,
596
+ scanIntervalMs: options.scanIntervalMs ?? 12e4,
598
597
  autoStart: options.autoStart ?? false
599
598
  };
600
- if (options.networkCidr !== void 0) {
601
- this.options.networkCidr = options.networkCidr;
602
- }
603
- if (options.username !== void 0) {
604
- this.options.username = options.username;
605
- }
606
- if (options.password !== void 0) {
607
- this.options.password = options.password;
608
- }
609
- if (options.httpProbeTimeoutMs !== void 0) {
610
- this.options.httpProbeTimeoutMs = options.httpProbeTimeoutMs;
611
- }
612
- if (options.maxConcurrentProbes !== void 0) {
613
- this.options.maxConcurrentProbes = options.maxConcurrentProbes;
614
- }
615
- if (options.logger !== void 0) {
616
- this.options.logger = options.logger;
617
- }
618
- if (options.httpPorts !== void 0) {
619
- this.options.httpPorts = options.httpPorts;
620
- }
621
- if (options.discoveryMethod !== void 0) {
622
- this.options.discoveryMethod = options.discoveryMethod;
623
- }
624
- if (options.udpBroadcastTimeoutMs !== void 0) {
625
- this.options.udpBroadcastTimeoutMs = options.udpBroadcastTimeoutMs;
626
- }
627
599
  if (this.options.autoStart) {
628
600
  this.start();
629
601
  }
630
602
  }
631
603
  /**
632
- * Avvia il discovery continuato.
633
- * Se già in esecuzione, non fa nulla.
604
+ * Start continuous discovery. If already running, does nothing.
634
605
  */
635
606
  start() {
636
607
  if (this.isRunning) {
@@ -645,8 +616,7 @@ var AutodiscoveryClient = class {
645
616
  this.scheduleNextScan();
646
617
  }
647
618
  /**
648
- * Ferma il discovery continuato.
649
- * Se non è in esecuzione, non fa nulla.
619
+ * Stop continuous discovery. If not running, does nothing.
650
620
  */
651
621
  stop() {
652
622
  if (!this.isRunning) {
@@ -661,50 +631,41 @@ var AutodiscoveryClient = class {
661
631
  this.options.logger?.log?.("[Autodiscovery] Discovery stopped");
662
632
  }
663
633
  /**
664
- * Restituisce la lista corrente delle telecamere discoverate.
665
- *
666
- * @returns Array di dispositivi discoverati, ordinati per host
634
+ * Returns the current list of discovered devices, sorted by host IP.
667
635
  */
668
636
  getDiscoveredDevices() {
669
- return Array.from(this.discoveredDevices.values()).sort((a, b) => {
670
- return a.host.localeCompare(b.host);
671
- });
637
+ return Array.from(this.discoveredDevices.values()).sort(
638
+ (a, b) => a.host.localeCompare(b.host)
639
+ );
672
640
  }
673
641
  /**
674
- * Restituisce il numero di telecamere attualmente discoverate.
675
- *
676
- * @returns Numero di dispositivi discoverati
642
+ * Returns the number of currently discovered devices.
677
643
  */
678
644
  getDeviceCount() {
679
645
  return this.discoveredDevices.size;
680
646
  }
681
647
  /**
682
- * Verifica se il discovery è attualmente in esecuzione.
683
- *
684
- * @returns `true` se il discovery è in esecuzione, `false` altrimenti
648
+ * Returns whether continuous discovery is currently running.
685
649
  */
686
650
  isActive() {
687
651
  return this.isRunning;
688
652
  }
689
653
  /**
690
- * Forza un scan immediato (non aspetta l'intervallo programmato).
691
- * Se uno scan è già in corso, attende il completamento prima di avviarne uno nuovo.
692
- *
693
- * @returns Promise che si risolve quando lo scan è completato
654
+ * Force an immediate scan (doesn't wait for the scheduled interval).
655
+ * If a scan is already in progress, waits for it to complete.
694
656
  */
695
657
  async scanNow() {
696
658
  if (this.currentScanPromise) {
697
- this.options.logger?.log?.("[Autodiscovery] Scan already in progress, waiting for completion...");
659
+ this.options.logger?.log?.(
660
+ "[Autodiscovery] Scan already in progress, waiting for completion..."
661
+ );
698
662
  await this.currentScanPromise;
699
663
  return;
700
664
  }
701
665
  await this.performScan();
702
666
  }
703
667
  /**
704
- * Rimuove un dispositivo dalla lista (utile se si sa che non è più disponibile).
705
- *
706
- * @param host - Indirizzo IP del dispositivo da rimuovere
707
- * @returns `true` se il dispositivo è stato rimosso, `false` se non era presente
668
+ * Remove a device from the discovered list.
708
669
  */
709
670
  removeDevice(host) {
710
671
  const removed = this.discoveredDevices.delete(host);
@@ -714,59 +675,20 @@ var AutodiscoveryClient = class {
714
675
  return removed;
715
676
  }
716
677
  /**
717
- * Pulisce tutte le telecamere discoverate dalla lista.
678
+ * Clear all discovered devices.
718
679
  */
719
680
  clearDevices() {
720
681
  const count = this.discoveredDevices.size;
721
682
  this.discoveredDevices.clear();
722
- this.options.logger?.log?.(`[Autodiscovery] Removed ${count} device(s) from list`);
683
+ this.options.logger?.log?.(
684
+ `[Autodiscovery] Removed ${count} device(s) from list`
685
+ );
723
686
  }
724
- /**
725
- * Esegue un singolo scan della rete.
726
- */
727
687
  async performScan() {
728
688
  const scanPromise = (async () => {
729
689
  try {
730
690
  this.options.logger?.log?.("[Autodiscovery] Starting scan...");
731
- const discoveryMethod = this.options.discoveryMethod ?? "http";
732
- const discoveryOptions = {
733
- enableHttpScanning: discoveryMethod === "http" || discoveryMethod === "both",
734
- enableUdpDiscovery: discoveryMethod === "udp" || discoveryMethod === "both"
735
- };
736
- if (this.options.networkCidr !== void 0) {
737
- discoveryOptions.networkCidr = this.options.networkCidr;
738
- }
739
- if (this.options.username !== void 0) {
740
- discoveryOptions.username = this.options.username;
741
- }
742
- if (this.options.password !== void 0) {
743
- discoveryOptions.password = this.options.password;
744
- }
745
- if (this.options.httpProbeTimeoutMs !== void 0) {
746
- discoveryOptions.httpProbeTimeoutMs = this.options.httpProbeTimeoutMs;
747
- }
748
- if (this.options.maxConcurrentProbes !== void 0) {
749
- discoveryOptions.maxConcurrentProbes = this.options.maxConcurrentProbes;
750
- }
751
- if (this.options.logger !== void 0) {
752
- discoveryOptions.logger = this.options.logger;
753
- }
754
- if (this.options.httpPorts !== void 0) {
755
- discoveryOptions.httpPorts = this.options.httpPorts;
756
- }
757
- if (this.options.udpBroadcastTimeoutMs !== void 0) {
758
- discoveryOptions.udpBroadcastTimeoutMs = this.options.udpBroadcastTimeoutMs;
759
- }
760
- let discovered = [];
761
- if (discoveryMethod === "http" || discoveryMethod === "both") {
762
- const httpDevices = await discoverViaHttpScan(discoveryOptions);
763
- discovered.push(...httpDevices);
764
- }
765
- if (discoveryMethod === "udp" || discoveryMethod === "both") {
766
- const udpDevices = await discoverViaUdpBroadcast(discoveryOptions);
767
- discovered.push(...udpDevices);
768
- }
769
- const beforeCount = this.discoveredDevices.size;
691
+ const discovered = await discoverReolinkDevices(this.options);
770
692
  const newDevices = [];
771
693
  const updatedDevices = [];
772
694
  for (const device of discovered) {
@@ -781,38 +703,35 @@ var AutodiscoveryClient = class {
781
703
  newDevices.push(device);
782
704
  }
783
705
  }
784
- const afterCount = this.discoveredDevices.size;
785
706
  this.options.logger?.log?.(
786
- `[Autodiscovery] Scan completed: ${newDevices.length} new, ${updatedDevices.length} updated, total: ${afterCount}`
707
+ `[Autodiscovery] Scan completed: ${newDevices.length} new, ${updatedDevices.length} updated, total: ${this.discoveredDevices.size}`
787
708
  );
788
709
  for (const device of newDevices) {
789
- const details = [];
790
- if (device.model) details.push(`Model: ${device.model}`);
791
- if (device.name) details.push(`Name: ${device.name}`);
792
- if (device.uid) details.push(`UID: ${device.uid}`);
793
- if (device.firmwareVersion) details.push(`Firmware: ${device.firmwareVersion}`);
794
- if (device.httpPort) details.push(`HTTP Port: ${device.httpPort}`);
795
- if (device.httpsPort) details.push(`HTTPS Port: ${device.httpsPort}`);
796
- details.push(`Discovery Method: ${device.discoveryMethod}`);
797
- if (device.supportsHttps !== void 0) details.push(`HTTPS: ${device.supportsHttps}`);
798
- if (device.httpAccessible !== void 0) details.push(`HTTP Accessible: ${device.httpAccessible}`);
799
710
  this.options.logger?.log?.(
800
- `[Autodiscovery] \u{1F195} NEW DEVICE DISCOVERED - Host: ${device.host}${details.length > 0 ? ` | ${details.join(" | ")}` : ""}`
711
+ `[Autodiscovery] NEW DEVICE - ${device.host} | ${device.model ?? "unknown"} | ${device.name ?? ""} | via ${device.discoveryMethod}`
801
712
  );
713
+ try {
714
+ this.options.onDeviceDiscovered?.(device);
715
+ } catch {
716
+ }
717
+ }
718
+ for (const device of updatedDevices) {
719
+ try {
720
+ this.options.onDeviceUpdated?.(device);
721
+ } catch {
722
+ }
802
723
  }
803
724
  } catch (error) {
804
725
  const msg = error instanceof Error ? error.message : String(error);
805
- this.options.logger?.error?.(`[Autodiscovery] Error during scan: ${msg}`);
726
+ this.options.logger?.error?.(
727
+ `[Autodiscovery] Error during scan: ${msg}`
728
+ );
806
729
  }
807
730
  })();
808
731
  this.currentScanPromise = scanPromise;
809
732
  await scanPromise;
810
733
  this.currentScanPromise = null;
811
734
  }
812
- /**
813
- * Unisce le informazioni di un dispositivo esistente con quelle di un nuovo scan.
814
- * Restituisce il dispositivo aggiornato se ci sono state modifiche, altrimenti `null`.
815
- */
816
735
  mergeDeviceInfo(existing, updated) {
817
736
  let hasChanges = false;
818
737
  if (!existing.model && updated.model) {
@@ -849,13 +768,8 @@ var AutodiscoveryClient = class {
849
768
  }
850
769
  return hasChanges ? existing : null;
851
770
  }
852
- /**
853
- * Programma il prossimo scan.
854
- */
855
771
  scheduleNextScan() {
856
- if (!this.isRunning) {
857
- return;
858
- }
772
+ if (!this.isRunning) return;
859
773
  this.scanTimer = setTimeout(() => {
860
774
  this.scanTimer = null;
861
775
  if (this.isRunning) {
@@ -7315,7 +7229,11 @@ export {
7315
7229
  detectIosClient,
7316
7230
  detectVideoCodecFromNal,
7317
7231
  discoverReolinkDevices,
7232
+ discoverViaArpTable,
7233
+ discoverViaDhcpListener,
7318
7234
  discoverViaHttpScan,
7235
+ discoverViaOnvif,
7236
+ discoverViaTcpPortScan,
7319
7237
  discoverViaUdpBroadcast,
7320
7238
  discoverViaUdpDirect,
7321
7239
  encodeHeader,