From 997f9a8d00adca799e6bae93b09beffcc3e34001 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 26 Sep 2021 16:02:54 -0700 Subject: [PATCH] hikvision: reduce request spam --- plugins/hikvision/package-lock.json | 4 ++-- plugins/hikvision/package.json | 2 +- plugins/hikvision/src/main.ts | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/hikvision/package-lock.json b/plugins/hikvision/package-lock.json index 7edbea028..76ec1b0a7 100644 --- a/plugins/hikvision/package-lock.json +++ b/plugins/hikvision/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/hikvision", - "version": "0.0.48", + "version": "0.0.49", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/hikvision", - "version": "0.0.48", + "version": "0.0.49", "license": "Apache", "dependencies": { "@mhoc/axios-digest-auth": "^0.7.0", diff --git a/plugins/hikvision/package.json b/plugins/hikvision/package.json index 320170ca2..a737ab9ac 100644 --- a/plugins/hikvision/package.json +++ b/plugins/hikvision/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/hikvision", - "version": "0.0.48", + "version": "0.0.49", "description": "HikVision Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/hikvision/src/main.ts b/plugins/hikvision/src/main.ts index 716c77441..0fada78e8 100644 --- a/plugins/hikvision/src/main.ts +++ b/plugins/hikvision/src/main.ts @@ -6,6 +6,8 @@ import { HikVisionCameraEvent } from "./hikvision-camera-api"; const { mediaManager } = sdk; class HikVisionCamera extends RtspSmartCamera implements Camera { + hasCheckedCodec = false; + listenEvents() { let motionTimeout: NodeJS.Timeout; const ret = new EventEmitter() as (EventEmitter & Destroyable); @@ -41,13 +43,12 @@ class HikVisionCamera extends RtspSmartCamera implements Camera { createClient() { const client = new HikVisionCameraAPI(this.getHttpAddress(), this.getUsername(), this.getPassword(), this.getRtspChannel()); - return client; - } - async takePicture(): Promise { - const api = this.createClient(); (async () => { - const streamSetup = await api.checkStreamSetup(); + if (this.hasCheckedCodec) + return; + const streamSetup = await client.checkStreamSetup(); + this.hasCheckedCodec = true; if (streamSetup.videoCodecType !== 'H.264') { this.log.a(`This camera is configured for ${streamSetup.videoCodecType} on the main channel. Configuring it it for H.264 is recommended for optimal performance.`); } @@ -55,6 +56,13 @@ class HikVisionCamera extends RtspSmartCamera implements Camera { this.log.a(`This camera is configured for ${streamSetup.audioCodecType} on the main channel. Configuring it it for AAC is recommended for optimal performance.`); } })(); + + return client; + } + + async takePicture(): Promise { + const api = this.createClient(); + return mediaManager.createMediaObject(api.jpegSnapshot(), 'image/jpeg'); }