From f3c83f57c43fbe760be58c003af8c83f38ec0034 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 23 Aug 2022 19:24:08 -0700 Subject: [PATCH] cameras: fix project files --- plugins/amcrest/.vscode/launch.json | 2 +- plugins/amcrest/package-lock.json | 4 +- plugins/amcrest/package.json | 2 +- plugins/amcrest/src/main.ts | 2 +- plugins/hikvision/.vscode/launch.json | 3 +- plugins/hikvision/README.md | 12 ++++-- plugins/hikvision/package-lock.json | 4 +- plugins/hikvision/package.json | 2 +- plugins/hikvision/src/main.ts | 61 ++++++++++++--------------- plugins/onvif/.vscode/launch.json | 3 +- plugins/onvif/src/main.ts | 22 +++++++++- plugins/onvif/src/onvif-api.ts | 4 +- plugins/rtsp/src/rtsp.ts | 2 +- 13 files changed, 70 insertions(+), 53 deletions(-) diff --git a/plugins/amcrest/.vscode/launch.json b/plugins/amcrest/.vscode/launch.json index 03660e3c2..0c868d0cf 100644 --- a/plugins/amcrest/.vscode/launch.json +++ b/plugins/amcrest/.vscode/launch.json @@ -17,7 +17,7 @@ "sourceMaps": true, "localRoot": "${workspaceFolder}/out", "remoteRoot": "/plugin/", - "type": "pwa-node" + "type": "node" } ] } \ No newline at end of file diff --git a/plugins/amcrest/package-lock.json b/plugins/amcrest/package-lock.json index 604eb23bc..d95ff61d9 100644 --- a/plugins/amcrest/package-lock.json +++ b/plugins/amcrest/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/amcrest", - "version": "0.0.106", + "version": "0.0.107", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/amcrest", - "version": "0.0.106", + "version": "0.0.107", "hasInstallScript": true, "license": "Apache", "dependencies": { diff --git a/plugins/amcrest/package.json b/plugins/amcrest/package.json index 7966d3063..c294f627a 100644 --- a/plugins/amcrest/package.json +++ b/plugins/amcrest/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/amcrest", - "version": "0.0.106", + "version": "0.0.107", "description": "Amcrest Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/amcrest/src/main.ts b/plugins/amcrest/src/main.ts index d180bfcf8..ba8abe2dd 100644 --- a/plugins/amcrest/src/main.ts +++ b/plugins/amcrest/src/main.ts @@ -248,7 +248,6 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration, async getUrlSettings() { return [ - ...await super.getUrlSettings(), { key: 'rtspChannel', title: 'Channel Number Override', @@ -257,6 +256,7 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration, placeholder: '1', value: this.storage.getItem('rtspChannel'), }, + ...await super.getUrlSettings(), ] } diff --git a/plugins/hikvision/.vscode/launch.json b/plugins/hikvision/.vscode/launch.json index 0669f79b4..0c868d0cf 100644 --- a/plugins/hikvision/.vscode/launch.json +++ b/plugins/hikvision/.vscode/launch.json @@ -10,13 +10,14 @@ "port": 10081, "request": "attach", "skipFiles": [ + "**/plugin-remote-worker.*", "/**" ], "preLaunchTask": "scrypted: deploy+debug", "sourceMaps": true, "localRoot": "${workspaceFolder}/out", "remoteRoot": "/plugin/", - "type": "pwa-node" + "type": "node" } ] } \ No newline at end of file diff --git a/plugins/hikvision/README.md b/plugins/hikvision/README.md index 64f520082..348555ed9 100644 --- a/plugins/hikvision/README.md +++ b/plugins/hikvision/README.md @@ -7,14 +7,18 @@ If the camera or NVR do not have motion detection, you will have to use a separa ## Two Way Audio -Two Way Audio is supported if the audio codec is set to PCM-ULAW (G.711ulaw) on the camera. This audio codec will also work with HomeKit. Using ONVIF Two Way is recommended. +There are two options for Two Way Audio: +* ONVIF (Recommended) +* HikVision (Untested) -## Codec Settings for HomeKit +Two Way Audio is supported if the audio codec is set to G.711ulaw on the camera, which is usually the default audio codec. This audio codec will also work with HomeKit. Changing the audio codec from G.711ulaw will cause Two Way Audio to fail on the cameras that were tested. + +## Codec Settings Configure optimal codec settings (as required by HomeKit) through HikVision's configuration webpage or device interface (not Scrypted). -HikVision's [iVMS 4200 software](https://www.hikvision.com/en/support/tools/), or similar, may be utilized to configure device as well as create a motion detection grid (required for motion detection and hardware dependent). +HikVision's [iVMS 4200 software](https://www.HikVision.com/en/support/tools/), or similar, may be utilized to configure device as well as create a motion detection grid (required for motion detection and hardware dependent). -Generally, for newer devices the main stream (Stream 1) may be incompatible with HomeKit. +Generally, for newer devices the main stream (Stream 1) may be incompatible with HomeKit as it only outputs HEVC. Configure and specify a substream instead (Stream 2 or 3). The optimal/reliable codec settings can be found in the documentation for the [Homekit Plugin](https://github.com/koush/scrypted/tree/main/plugins/homekit). diff --git a/plugins/hikvision/package-lock.json b/plugins/hikvision/package-lock.json index 0e146636d..884e9ceeb 100644 --- a/plugins/hikvision/package-lock.json +++ b/plugins/hikvision/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/hikvision", - "version": "0.0.98", + "version": "0.0.100", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/hikvision", - "version": "0.0.98", + "version": "0.0.100", "license": "Apache", "dependencies": { "@koush/axios-digest-auth": "^0.8.5", diff --git a/plugins/hikvision/package.json b/plugins/hikvision/package.json index f22de5159..8e8243c13 100644 --- a/plugins/hikvision/package.json +++ b/plugins/hikvision/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/hikvision", - "version": "0.0.98", + "version": "0.0.100", "description": "HikVision Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/hikvision/src/main.ts b/plugins/hikvision/src/main.ts index 4eb1bdacf..7eac65764 100644 --- a/plugins/hikvision/src/main.ts +++ b/plugins/hikvision/src/main.ts @@ -16,25 +16,6 @@ class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { onvifIntercom = new OnvifIntercom(this); cp: ChildProcess; - // bad hack, but whatever. - codecCheck = (async () => { - while (true) { - try { - const streamSetup = await this.client.checkStreamSetup(this.getRtspChannel(), await this.isOld()); - 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.`); - } - if (!this.isAudioDisabled() && streamSetup.audioCodecType && streamSetup.audioCodecType !== 'AAC') { - this.log.a(`This camera is configured for ${streamSetup.audioCodecType} on the main channel. Configuring it for AAC is recommended for optimal performance.`); - } - break; - } - catch (e) { - await sleep(60000); - } - } - })(); - constructor(nativeId: string, provider: RtspProvider) { super(nativeId, provider); @@ -341,25 +322,35 @@ class HikVisionCamera extends RtspSmartCamera implements Camera, Intercom { const socket = this.cp.stdio[3] as Readable; (async () => { - const url = `http://${this.getHttpAddress()}/ISAPI/System/TwoWayAudio/channels/${this.getRtspChannel() || '1'}/audioData`; - this.console.log('posting audio data to', url); - - // seems the dahua doorbells preferred 1024 chunks. should investigate adts - // parsing and sending multipart chunks instead. const passthrough = new PassThrough(); - this.getClient().digestAuth.request({ - httpsAgent: hikvisionHttpsAgent, - method: 'PUT', - url, - headers: { - 'Content-Type': 'Audio/G.711Mu', - // 'Connection': 'close', - // 'Content-Length': '9999999' - }, - data: passthrough, - }); try { + const open = `http://${this.getHttpAddress()}/ISAPI/System/TwoWayAudio/channels/${this.getRtspChannel() || '1'}/open`; + const {data} = await this.getClient().digestAuth.request({ + httpsAgent: hikvisionHttpsAgent, + method: 'PUT', + url: open, + }); + this.console.log('two way audio opened', data); + + const url = `http://${this.getHttpAddress()}/ISAPI/System/TwoWayAudio/channels/${this.getRtspChannel() || '1'}/audioData`; + this.console.log('posting audio data to', url); + + // seems the dahua doorbells preferred 1024 chunks. should investigate adts + // parsing and sending multipart chunks instead. + this.getClient().digestAuth.request({ + httpsAgent: hikvisionHttpsAgent, + method: 'PUT', + url, + headers: { + 'Content-Type': 'application/octet-stream', + // 'Connection': 'close', + 'Content-Length': '0' + }, + data: passthrough, + }); + + while (true) { const data = await readLength(socket, 1024); passthrough.push(data); diff --git a/plugins/onvif/.vscode/launch.json b/plugins/onvif/.vscode/launch.json index 0669f79b4..0c868d0cf 100644 --- a/plugins/onvif/.vscode/launch.json +++ b/plugins/onvif/.vscode/launch.json @@ -10,13 +10,14 @@ "port": 10081, "request": "attach", "skipFiles": [ + "**/plugin-remote-worker.*", "/**" ], "preLaunchTask": "scrypted: deploy+debug", "sourceMaps": true, "localRoot": "${workspaceFolder}/out", "remoteRoot": "/plugin/", - "type": "pwa-node" + "type": "node" } ] } \ No newline at end of file diff --git a/plugins/onvif/src/main.ts b/plugins/onvif/src/main.ts index 4701e1c86..1e6ec950b 100644 --- a/plugins/onvif/src/main.ts +++ b/plugins/onvif/src/main.ts @@ -34,6 +34,24 @@ class OnvifCamera extends RtspSmartCamera implements ObjectDetector, Intercom { rtspMediaStreamOptions: Promise; intercom = new OnvifIntercom(this); + constructor(nativeId: string, provider: RtspProvider) { + super(nativeId, provider); + + this.updateManagementUrl(); + } + + updateManagementUrl() { + const ip = this.storage.getItem('ip'); + if (!ip) + return; + const info = this.info || {}; + const managementUrl = `http://${ip}`; + if (info.managementUrl !== managementUrl) { + info.managementUrl = managementUrl; + this.info = info; + } + } + getDetectionInput(detectionId: any, eventId?: any): Promise { throw new Error("Method not implemented."); } @@ -167,8 +185,6 @@ class OnvifCamera extends RtspSmartCamera implements ObjectDetector, Intercom { this.console.log('listening events'); const events = client.listenEvents(); events.on('event', (event, className) => { - ret.emit('data', ...arguments); - if (event === OnvifEvent.MotionBuggy) { this.motionDetected = true; clearTimeout(motionTimeout); @@ -308,6 +324,8 @@ class OnvifCamera extends RtspSmartCamera implements ObjectDetector, Intercom { this.client = undefined; this.rtspMediaStreamOptions = undefined; + this.updateManagementUrl(); + if (key !== 'onvifDoorbell' && key !== 'onvifTwoWay') return super.putSetting(key, value); diff --git a/plugins/onvif/src/onvif-api.ts b/plugins/onvif/src/onvif-api.ts index 98a16d6c0..37babacb5 100644 --- a/plugins/onvif/src/onvif-api.ts +++ b/plugins/onvif/src/onvif-api.ts @@ -73,7 +73,9 @@ export class OnvifCameraAPI { const ret = new EventEmitter(); this.cam.on('event', (event: any, xml: string) => { - const eventTopic = stripNamespaces(event.topic._) + ret.emit('data', xml); + + const eventTopic = stripNamespaces(event.topic._); if (event.message.message.data && event.message.message.data.simpleItem) { const dataValue = event.message.message.data.simpleItem.$.Value; diff --git a/plugins/rtsp/src/rtsp.ts b/plugins/rtsp/src/rtsp.ts index 7cbc83f31..07b6492ab 100644 --- a/plugins/rtsp/src/rtsp.ts +++ b/plugins/rtsp/src/rtsp.ts @@ -270,7 +270,7 @@ export abstract class RtspSmartCamera extends RtspCamera { key: 'debug', title: 'Debug Events', description: "Log all events to the console. This will be very noisy and should not be left enabled.", - value: !!this.storage.getItem('debug'), + value: this.storage.getItem('debug') === 'true', type: 'boolean', } )