diff --git a/plugins/snapshot/package-lock.json b/plugins/snapshot/package-lock.json index ec98a4ce9..9c783cfd3 100644 --- a/plugins/snapshot/package-lock.json +++ b/plugins/snapshot/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/snapshot", - "version": "0.0.21", + "version": "0.0.22", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/snapshot", - "version": "0.0.21", + "version": "0.0.22", "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 fea3bc47c..6c4c63fac 100644 --- a/plugins/snapshot/package.json +++ b/plugins/snapshot/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/snapshot", - "version": "0.0.21", + "version": "0.0.22", "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 1eb0383d6..e772c7009 100644 --- a/plugins/snapshot/src/main.ts +++ b/plugins/snapshot/src/main.ts @@ -119,17 +119,19 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { try { const realDevice = systemManager.getDeviceById(this.id); const msos = await realDevice.getVideoStreamOptions(); - for (const mso of msos) { - if (mso.prebuffer) { - const request = mso as RequestMediaStreamOptions; - request.refresh = false; - takePicture = async () => mediaManager.convertMediaObjectToBuffer(await realDevice.getVideoStream(request), 'image/jpeg'); - // a prebuffer snapshot should wipe out any pending pictures - // that may not have come from the prebuffer to allow a safe-ish/fast refresh. - this.pendingPicture = undefined; - this.console.log('snapshotting active prebuffer'); - break; - } + let prebufferChannel = msos?.find(mso => mso.prebuffer); + if (prebufferChannel || !this.lastAvailablePicture) { + prebufferChannel = prebufferChannel || { + id: undefined, + }; + + const request = prebufferChannel as RequestMediaStreamOptions; + request.refresh = false; + takePicture = async () => mediaManager.convertMediaObjectToBuffer(await realDevice.getVideoStream(request), 'image/jpeg'); + // a prebuffer snapshot should wipe out any pending pictures + // that may not have come from the prebuffer to allow a safe-ish/fast refresh. + this.pendingPicture = undefined; + this.console.log('snapshotting active prebuffer'); } } catch (e) { @@ -292,8 +294,9 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { } async createErrorImage(e: any) { - this.console.log('creating error snapshot', e); if (e instanceof TimeoutError) { + if (!this.timeoutPicture) + this.console.log('creating timeout snapshot'); this.timeoutPicture = singletonPromise(this.timeoutPicture, () => this.createTextErrorImage('Snapshot Timed Out'), FOREVER); @@ -306,6 +309,8 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { return this.progressPicture.promise; } else { + if (!this.errorPicture) + this.console.log('creating error snapshot', e); this.errorPicture = singletonPromise(this.errorPicture, () => this.createTextErrorImage('Snapshot Failed'), FOREVER);