unifi-protect: aspect ratio fixup

This commit is contained in:
Koushik Dutta
2021-10-11 11:19:02 -07:00
parent f67737a9c4
commit e54a8718ee
3 changed files with 16 additions and 5 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/unifi-protect",
"version": "0.0.43",
"version": "0.0.44",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/unifi-protect",
"version": "0.0.43",
"version": "0.0.44",
"license": "Apache",
"dependencies": {
"@types/ws": "^7.4.7",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/unifi-protect",
"version": "0.0.43",
"version": "0.0.44",
"description": "Unifi Protect Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -80,8 +80,19 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Mot
async getSnapshot(options?: PictureOptions): Promise<Buffer> {
let size = '';
if (options?.picture?.width && options?.picture?.height)
size = `&w=${options.picture.width}&h=${options.picture.height}`;
try {
if (options?.picture?.width && options?.picture?.height) {
const camera = this.findCamera();
const mainChannel = camera.channels[0];
const w = options.picture.width;
const h = Math.round((mainChannel.height / mainChannel.width) * w);
size = `&w=${w}&h=${h}`;
}
}
catch (e) {
}
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);