From 73607fd1aac1ff94818545b768abbc6ecad83aa5 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 5 Mar 2024 08:57:14 -0800 Subject: [PATCH] snapshot: fix periodic snapshot timeout regression --- plugins/snapshot/package-lock.json | 4 ++-- plugins/snapshot/package.json | 2 +- plugins/snapshot/src/main.ts | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/snapshot/package-lock.json b/plugins/snapshot/package-lock.json index 7a6cc6d24..0df319be8 100644 --- a/plugins/snapshot/package-lock.json +++ b/plugins/snapshot/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/snapshot", - "version": "0.2.39", + "version": "0.2.40", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/snapshot", - "version": "0.2.39", + "version": "0.2.40", "dependencies": { "@types/node": "^20.10.6", "sharp": "^0.33.1", diff --git a/plugins/snapshot/package.json b/plugins/snapshot/package.json index cef864145..637476ccc 100644 --- a/plugins/snapshot/package.json +++ b/plugins/snapshot/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/snapshot", - "version": "0.2.39", + "version": "0.2.40", "description": "Snapshot Plugin for Scrypted", "scripts": { "scrypted-setup-project": "scrypted-setup-project", diff --git a/plugins/snapshot/src/main.ts b/plugins/snapshot/src/main.ts index dcbc6ca7f..18bd683f8 100644 --- a/plugins/snapshot/src/main.ts +++ b/plugins/snapshot/src/main.ts @@ -292,12 +292,13 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { if (periodicSnapshot && this.currentPicture) { const cp = this.currentPicture; debounced.catch(() => { }); + const timeout = options.timeout || 1000; try { - picture = await (options.timeout ? timeoutPromise(options.timeout, debounced) : debounced); + picture = await timeoutPromise(timeout, debounced); } catch (e) { - if (options.timeout) - this.debugConsole?.log(`Periodic snapshot took longer than ${options.timeout} seconds to retrieve, falling back to cached picture.`) + if (e instanceof TimeoutError) + this.debugConsole?.log(`Periodic snapshot took longer than ${timeout} seconds to retrieve, falling back to cached picture.`) picture = cp; }