From bf252a4ac4bca2bd8a1a5d4d89d4917cb618dec3 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 10 Oct 2021 19:10:04 -0700 Subject: [PATCH] unifi-protect: request exact dimensions. unclear if this is better. --- plugins/unifi-protect/src/main.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/unifi-protect/src/main.ts b/plugins/unifi-protect/src/main.ts index 4da830acd..58a0bfc22 100644 --- a/plugins/unifi-protect/src/main.ts +++ b/plugins/unifi-protect/src/main.ts @@ -1,4 +1,4 @@ -import sdk, { ScryptedDeviceBase, DeviceProvider, Settings, Setting, ScryptedDeviceType, VideoCamera, MediaObject, Device, MotionSensor, ScryptedInterface, Camera, MediaStreamOptions, Intercom, ScryptedMimeTypes, FFMpegInput, ObjectDetection, ObjectDetector } from "@scrypted/sdk"; +import sdk, { ScryptedDeviceBase, DeviceProvider, Settings, Setting, ScryptedDeviceType, VideoCamera, MediaObject, Device, MotionSensor, ScryptedInterface, Camera, MediaStreamOptions, Intercom, ScryptedMimeTypes, FFMpegInput, ObjectDetection, ObjectDetector, PictureOptions } from "@scrypted/sdk"; import { ProtectApi } from "./unifi-protect/src/protect-api"; import { ProtectApiUpdates, ProtectNvrUpdatePayloadCameraUpdate, ProtectNvrUpdatePayloadEventAdd } from "./unifi-protect/src/protect-api-updates"; import { ProtectCameraChannelConfig, ProtectCameraConfigInterface } from "./unifi-protect/src/protect-types"; @@ -76,8 +76,11 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Mot }, 30000); } - async getSnapshot(): Promise { - const url = `https://${this.protect.getSetting('ip')}/proxy/protect/api/cameras/${this.nativeId}/snapshot?ts=${Date.now()}` + async getSnapshot(options?: PictureOptions): Promise { + let size = ''; + if (options?.picture?.width && options?.picture?.height) + size = `&w=${options.picture.width}&h=${options.picture.height}`; + const url = `https://${this.protect.getSetting('ip')}/proxy/protect/api/cameras/${this.nativeId}/snapshot?ts=${Date.now()}${size}` const response = await this.protect.api.loginFetch(url); if (!response) { @@ -87,8 +90,8 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Mot return Buffer.from(data); } - async takePicture(): Promise { - const buffer = await this.getSnapshot(); + async takePicture(options?: PictureOptions): Promise { + const buffer = await this.getSnapshot(options); return mediaManager.createMediaObject(buffer, 'image/jpeg'); } findCamera() {