From bc3d6b314cd677ef9cdec204f52fa56872f6c040 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 25 Mar 2022 10:38:24 -0700 Subject: [PATCH] snapshot: fix another spin loop in Never Wait mode --- plugins/snapshot/package-lock.json | 4 ++-- plugins/snapshot/package.json | 2 +- plugins/snapshot/src/main.ts | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/snapshot/package-lock.json b/plugins/snapshot/package-lock.json index 15b3837e6..ec98a4ce9 100644 --- a/plugins/snapshot/package-lock.json +++ b/plugins/snapshot/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/snapshot", - "version": "0.0.20", + "version": "0.0.21", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/snapshot", - "version": "0.0.20", + "version": "0.0.21", "dependencies": { "@koush/axios-digest-auth": "^0.8.5", "@types/node": "^16.6.1", diff --git a/plugins/snapshot/package.json b/plugins/snapshot/package.json index 762098a1f..fea3bc47c 100644 --- a/plugins/snapshot/package.json +++ b/plugins/snapshot/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/snapshot", - "version": "0.0.20", + "version": "0.0.21", "description": "Snapshot Plugin for Scrypted", "scripts": { "prepublishOnly": "NODE_ENV=production scrypted-webpack", diff --git a/plugins/snapshot/src/main.ts b/plugins/snapshot/src/main.ts index 2c46ea2c3..1eb0383d6 100644 --- a/plugins/snapshot/src/main.ts +++ b/plugins/snapshot/src/main.ts @@ -196,7 +196,8 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { } } - if (!this.pendingPicture) { + const hadPendingPicture = !!this.pendingPicture; + if (!hadPendingPicture) { const pendingPicture = (async () => { let picture: Buffer; try { @@ -219,9 +220,6 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { this.pendingPicture = pendingPicture; - // this triggers an event to refresh the web ui. - this.pendingPicture.then(() => this.onDeviceEvent(ScryptedInterface.Camera, undefined)); - // prevent infinite loop from onDeviceEvent triggering picture updates. // retain this promise for a bit while everything settles. pendingPicture.finally(() => { @@ -240,6 +238,11 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { try { if (this.storageSettings.values.snapshotMode === 'Never Wait') { if (!this.currentPicture) { + // this triggers an event to refresh the web ui. + // but only trigger a refresh if this call fetched the picture. + if (!hadPendingPicture) + this.pendingPicture.then(() => this.onDeviceEvent(ScryptedInterface.Camera, undefined)); + data = await this.createErrorImage(new NeverWaitError()); } else {