@apocaliss92/scrypted-reolink-native 0.1.21 → 0.1.22

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.1.21",
3
+ "version": "0.1.22",
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",
package/src/multifocal.ts CHANGED
@@ -61,6 +61,8 @@ export class ReolinkNativeMultiFocalDevice extends BaseBaichuanClass implements
61
61
  cameraNativeMap = new Map<string, ReolinkNativeCamera | ReolinkNativeBatteryCamera>();
62
62
  private channelToNativeIdMap = new Map<number, string>();
63
63
  processing = false;
64
+ private syncInProgress = false;
65
+ private syncPromise: Promise<void> | undefined;
64
66
  private initReinitTimeout: NodeJS.Timeout | undefined;
65
67
 
66
68
  constructor(nativeId: string, plugin: ReolinkNativePlugin, transport: BaichuanTransport = 'tcp') {
@@ -197,10 +199,21 @@ export class ReolinkNativeMultiFocalDevice extends BaseBaichuanClass implements
197
199
  }
198
200
 
199
201
  async syncEntitiesFromRemote() {
200
- const api = await this.ensureBaichuanClient();
201
- const logger = this.getBaichuanLogger();
202
+ // If sync is already in progress, wait for it to complete
203
+ if (this.syncInProgress && this.syncPromise) {
204
+ const logger = this.getBaichuanLogger();
205
+ logger.debug('Sync already in progress, waiting for completion...');
206
+ await this.syncPromise;
207
+ return;
208
+ }
202
209
 
203
- try {
210
+ // Start new sync
211
+ this.syncInProgress = true;
212
+ this.syncPromise = (async () => {
213
+ const api = await this.ensureBaichuanClient();
214
+ const logger = this.getBaichuanLogger();
215
+
216
+ try {
204
217
  // const channelsInfo = await api.getNvrChannelsInfo();
205
218
  // const deviceInfo = await api.getInfo();
206
219
  const { support } = await api.getDeviceCapabilities();
@@ -266,16 +279,22 @@ export class ReolinkNativeMultiFocalDevice extends BaseBaichuanClass implements
266
279
  }
267
280
 
268
281
  // logger.log(`Channel discovery completed. ${JSON.stringify({ devicesData, channels })}`);
269
- } catch (e) {
270
- logger.error('Failed to sync entities from remote', e);
271
- if (e instanceof Error) {
272
- logger.error(`Error in syncEntitiesFromRemote: ${e.message}`);
273
- logger.error(`Stack: ${e.stack}`);
274
- } else {
275
- logger.error(`Error details: ${JSON.stringify(e)}`);
282
+ } catch (e) {
283
+ logger.error('Failed to sync entities from remote', e);
284
+ if (e instanceof Error) {
285
+ logger.error(`Error in syncEntitiesFromRemote: ${e.message}`);
286
+ logger.error(`Stack: ${e.stack}`);
287
+ } else {
288
+ logger.error(`Error details: ${JSON.stringify(e)}`);
289
+ }
290
+ throw e;
291
+ } finally {
292
+ this.syncInProgress = false;
293
+ this.syncPromise = undefined;
276
294
  }
277
- throw e;
278
- }
295
+ })();
296
+
297
+ await this.syncPromise;
279
298
  }
280
299
 
281
300
  async discoverDevices(scan?: boolean): Promise<DiscoveredDevice[]> {