hikvision: reduce request spam

This commit is contained in:
Koushik Dutta
2021-09-26 16:02:54 -07:00
parent 41b6e26eb1
commit 997f9a8d00
3 changed files with 16 additions and 8 deletions

View File

@@ -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",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/hikvision",
"version": "0.0.48",
"version": "0.0.49",
"description": "HikVision Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -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<MediaObject> {
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<MediaObject> {
const api = this.createClient();
return mediaManager.createMediaObject(api.jpegSnapshot(), 'image/jpeg');
}