snapshot: fix another spin loop in Never Wait mode

This commit is contained in:
Koushik Dutta
2022-03-25 10:38:24 -07:00
parent 7a67bc8016
commit bc3d6b314c
3 changed files with 10 additions and 7 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -196,7 +196,8 @@ class SnapshotMixin extends SettingsMixinDeviceBase<Camera> 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<Camera> 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<Camera> 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 {