@apocaliss92/scrypted-reolink-native 0.1.33 → 0.1.36

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/src/nvr.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { DeviceInfoResponse, DeviceInputData, EventsResponse, ReolinkBaichuanApi, ReolinkCgiApi, ReolinkSimpleEvent } from "@apocaliss92/reolink-baichuan-js" with { "resolution-mode": "import" };
2
- import sdk, { AdoptDevice, Device, DeviceDiscovery, DeviceProvider, DiscoveredDevice, Reboot, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, Setting, Settings, SettingValue } from "@scrypted/sdk";
1
+ import type { DeviceInfoResponse, EnrichedRecordingFile, EventsResponse, ReolinkBaichuanApi, ReolinkCgiApi, ReolinkSimpleEvent } from "@apocaliss92/reolink-baichuan-js" with { "resolution-mode": "import" };
2
+ import sdk, { AdoptDevice, Device, DeviceDiscovery, DeviceProvider, DiscoveredDevice, Reboot, ScryptedDeviceType, ScryptedInterface, Setting, Settings, SettingValue } from "@scrypted/sdk";
3
3
  import { StorageSettings } from "@scrypted/sdk/storage-settings";
4
- import { BaseBaichuanClass, type BaichuanConnectionConfig, type BaichuanConnectionCallbacks } from "./baichuan-base";
4
+ import { BaseBaichuanClass, type BaichuanConnectionCallbacks, type BaichuanConnectionConfig } from "./baichuan-base";
5
5
  import { ReolinkNativeCamera } from "./camera";
6
6
  import { ReolinkNativeBatteryCamera } from "./camera-battery";
7
7
  import { normalizeUid } from "./connect";
@@ -80,8 +80,8 @@ export class ReolinkNativeNvrDevice extends BaseBaichuanClass implements Setting
80
80
  }
81
81
 
82
82
  async reboot(): Promise<void> {
83
- const api = await this.ensureClient();
84
- await api.Reboot();
83
+ const api = await this.ensureBaichuanClient();
84
+ await api.reboot();
85
85
  }
86
86
 
87
87
  // BaseBaichuanClass abstract methods implementation
@@ -175,16 +175,41 @@ export class ReolinkNativeNvrDevice extends BaseBaichuanClass implements Setting
175
175
  }
176
176
 
177
177
  const { ReolinkCgiApi } = await import("@apocaliss92/reolink-baichuan-js");
178
+ const logger = this.getBaichuanLogger();
178
179
  this.nvrApi = new ReolinkCgiApi({
179
180
  host: ipAddress,
180
181
  username,
181
182
  password,
183
+ logger,
182
184
  });
183
185
 
184
186
  await this.nvrApi.login();
185
187
  return this.nvrApi;
186
188
  }
187
189
 
190
+ /**
191
+ * List enriched VOD files (with proper parsing and detection info)
192
+ * This uses the library's enrichVodFile which handles all parsing correctly
193
+ */
194
+ async listEnrichedVodFiles(params: {
195
+ channel: number;
196
+ start: Date;
197
+ end: Date;
198
+ streamType?: "main" | "sub";
199
+ autoSearchByDay?: boolean;
200
+ bypassCache?: boolean;
201
+ }): Promise<Array<EnrichedRecordingFile>> {
202
+ const api = await this.ensureClient();
203
+ return await api.listEnrichedVodFiles({
204
+ channel: params.channel,
205
+ start: params.start,
206
+ end: params.end,
207
+ streamType: params.streamType,
208
+ autoSearchByDay: params.autoSearchByDay,
209
+ bypassCache: params.bypassCache,
210
+ });
211
+ }
212
+
188
213
  private forwardNativeEvent(ev: ReolinkSimpleEvent): void {
189
214
  const logger = this.getBaichuanLogger();
190
215
 
@@ -467,33 +492,15 @@ export class ReolinkNativeNvrDevice extends BaseBaichuanClass implements Setting
467
492
  async syncEntitiesFromRemote() {
468
493
  const logger = this.getBaichuanLogger();
469
494
 
470
- // Ensure both APIs are ready before syncing
471
- const api = await this.ensureClient();
472
- const baichuanApi = await this.ensureBaichuanClient();
473
-
474
- // Wait for Baichuan connection to be fully established
475
- if (baichuanApi?.client) {
476
- // Check if already connected
477
- if (!baichuanApi.client.isSocketConnected()) {
478
- logger.debug('Waiting for Baichuan connection to be established...');
479
- // Wait up to 5 seconds for connection
480
- let attempts = 0;
481
- while (!baichuanApi.client.isSocketConnected() && attempts < 50) {
482
- await new Promise(resolve => setTimeout(resolve, 100));
483
- attempts++;
484
- }
485
- if (!baichuanApi.client.isSocketConnected()) {
486
- logger.warn('Baichuan connection not established after waiting, proceeding anyway');
487
- } else {
488
- logger.debug('Baichuan connection established');
489
- }
490
- }
491
- }
495
+ const cgiApi = await this.ensureClient();
496
+ const { devicesData, channels } = await cgiApi.getDevicesInfo();
492
497
 
493
- const { devicesData, channels } = await api.getDevicesInfo();
498
+ // const api = await this.ensureBaichuanClient();
499
+ // const devicesMap = api.getDevicesInfo();
500
+ // const deviceEntries = Object.entries(devicesMap);
494
501
 
495
502
  if (!channels.length) {
496
- logger.debug(`No channels found, ${JSON.stringify({ devicesData, channels })}`);
503
+ logger.debug(`No channels found, ${JSON.stringify({ channels, devicesData })}`);
497
504
  return;
498
505
  }
499
506