From 2cd2aa1ec26d86a024e4a00919bf67b95f16bfe2 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 30 Oct 2022 10:16:15 -0700 Subject: [PATCH] hikvision: fix camera number detection when more than 10 cameras --- plugins/hikvision/package-lock.json | 4 ++-- plugins/hikvision/package.json | 2 +- plugins/hikvision/src/main.ts | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/hikvision/package-lock.json b/plugins/hikvision/package-lock.json index 8cf2357b0..881664cbe 100644 --- a/plugins/hikvision/package-lock.json +++ b/plugins/hikvision/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/hikvision", - "version": "0.0.110", + "version": "0.0.111", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/hikvision", - "version": "0.0.110", + "version": "0.0.111", "license": "Apache", "dependencies": { "@koush/axios-digest-auth": "^0.8.5", diff --git a/plugins/hikvision/package.json b/plugins/hikvision/package.json index 95b5b51f0..1beb64b79 100644 --- a/plugins/hikvision/package.json +++ b/plugins/hikvision/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/hikvision", - "version": "0.0.110", + "version": "0.0.111", "description": "HikVision Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/hikvision/src/main.ts b/plugins/hikvision/src/main.ts index 4f3247225..88ea6f2b2 100644 --- a/plugins/hikvision/src/main.ts +++ b/plugins/hikvision/src/main.ts @@ -11,6 +11,12 @@ import xml2js from 'xml2js'; const { mediaManager } = sdk; +function channelToCameraNumber(channel: string) { + if (!channel) + return; + return channel.substring(0, channel.length - 2); +} + class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { detectedChannels: Promise>; client: HikVisionCameraAPI; @@ -65,7 +71,7 @@ class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { const channelIds = (await this.detectedChannels).keys(); ignoreCameraNumber = true; for (const id of channelIds) { - if (id === userCameraNumber) { + if (channelToCameraNumber(id) === userCameraNumber) { ignoreCameraNumber = false; break; } @@ -138,12 +144,7 @@ class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { } getCameraNumber() { - const channel = this.getRtspChannel(); - // have users with more than 10 cameras. unsure if it is possible - // to have more than 10 substreams... - if (channel?.length > 3) - return channel.substring(0, channel.length - 2); - return channel?.substring(0, 1) || '1'; + return channelToCameraNumber(this.getRtspChannel()); } getRtspUrlParams() { @@ -231,7 +232,7 @@ class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { let index = 0; const cameraNumber = this.getCameraNumber(); for (const [id, channel] of detectedChannels.entries()) { - if (cameraNumber && id !== cameraNumber) + if (cameraNumber && channelToCameraNumber(id) !== cameraNumber) continue; const mso = this.createRtspMediaStreamOptions(`rtsp://${this.getRtspAddress()}/ISAPI/Streaming/channels/${id}/${params}`, index++); Object.assign(mso.video, channel?.video);