From 8e27dbfe657ac7651a6d94f61e7d63008b9b37d7 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Fri, 25 Oct 2024 11:12:23 -0500 Subject: [PATCH] see if this works --- package.json | 1 - src/index.ts | 18 ++++++++++-------- src/recordingDelegate.ts | 1 + src/streamingDelegate.ts | 6 +++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4efddb60..f0c6d38c 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "watch": "npm run build && npm link && nodemon", "build": "npm run clean && tsc", "prepublishOnly": "npm run lint && npm run build", - "postpublish": "npm run clean && npm ci", "clean": "shx rm -rf ./dist", "test": "npm run lint", "docs": "typedoc", diff --git a/src/index.ts b/src/index.ts index 5a7266e1..13557bc4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import type { } from 'homebridge' import type { AutomationReturn } from './autoTypes.js' -import type { CameraConfig, FfmpegPlatformConfig } from './configTypes.js' +import type { CameraConfig, FfmpegPlatformConfig, VideoConfig } from './configTypes.js' import { readFileSync } from 'node:fs' import http from 'node:http' @@ -42,6 +42,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin { private readonly api: API private readonly config: FfmpegPlatformConfig private readonly cameraConfigs: Map = new Map() + private readonly videoConfig?: VideoConfig private readonly cachedAccessories: Array = [] private readonly accessories: Array = [] private readonly motionTimers: Map = new Map() @@ -57,30 +58,31 @@ class FfmpegPlatform implements DynamicPlatformPlugin { let error = false if (!cameraConfig.name) { - this.log.error('One of your cameras has no name configured. This camera will be skipped.') cameraConfig.name = `Camera ${this.cameraConfigs.size + 1}` + this.log.error(`One of your cameras has no name configured, using ${cameraConfig.name}.`) error = false } if (!cameraConfig.videoConfig) { this.log.error('The videoConfig section is missing from the config. This camera will be skipped.', cameraConfig.name) error = true } else { - if (!cameraConfig.videoConfig.source) { + const videoConfig = cameraConfig.videoConfig + if (!videoConfig.source) { this.log.error('There is no source configured for this camera. This camera will be skipped.', cameraConfig.name) error = true } else { - const sourceArgs = cameraConfig.videoConfig.source.split(/\s+/) + const sourceArgs = videoConfig.source.split(/\s+/) if (!sourceArgs.includes('-i')) { this.log.warn('The source for this camera is missing "-i", it is likely misconfigured.', cameraConfig.name) } } - if (cameraConfig.videoConfig.stillImageSource) { - const stillArgs = cameraConfig.videoConfig.stillImageSource.split(/\s+/) + if (videoConfig.stillImageSource) { + const stillArgs = videoConfig.stillImageSource.split(/\s+/) if (!stillArgs.includes('-i')) { this.log.warn('The stillImageSource for this camera is missing "-i", it is likely misconfigured.', cameraConfig.name) } } - if (cameraConfig.videoConfig.vcodec === 'copy' && cameraConfig.videoConfig.videoFilter) { + if (videoConfig.vcodec === 'copy' && videoConfig.videoFilter) { this.log.warn('A videoFilter is defined, but the copy vcodec is being used. This will be ignored.', cameraConfig.name) } } @@ -142,7 +144,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin { accessory.removeService(doorbellSwitch) } - const delegate = new StreamingDelegate(this.log, cameraConfig, this.api, this.api.hap, accessory, this.config.videoProcessor) + const delegate = new StreamingDelegate(this.log, cameraConfig, this.videoConfig!, this.api, this.api.hap, accessory, this.config.videoProcessor) accessory.configureController(delegate.controller) diff --git a/src/recordingDelegate.ts b/src/recordingDelegate.ts index 9b2fe54a..66c603c6 100644 --- a/src/recordingDelegate.ts +++ b/src/recordingDelegate.ts @@ -150,6 +150,7 @@ export class RecordingDelegate implements CameraRecordingDelegate { this.hap = hap this.cameraName = cameraName this.videoProcessor = videoProcessor || ffmpegPathString || 'ffmpeg' + this.videoConfig = videoConfig api.on(APIEvent.SHUTDOWN, () => { if (this.preBufferSession) { diff --git a/src/streamingDelegate.ts b/src/streamingDelegate.ts index 08813280..227b688e 100644 --- a/src/streamingDelegate.ts +++ b/src/streamingDelegate.ts @@ -94,14 +94,14 @@ export class StreamingDelegate implements CameraStreamingDelegate { ongoingSessions: Map = new Map() timeouts: Map = new Map() - constructor(log: Logger, cameraConfig: CameraConfig, api: API, hap: HAP, accessory: PlatformAccessory, videoProcessor?: string) { + constructor(log: Logger, cameraConfig: CameraConfig, videoConfig: VideoConfig, api: API, hap: HAP, accessory: PlatformAccessory, videoProcessor?: string) { this.log = log this.hap = hap this.api = api this.cameraName = cameraConfig.name! this.unbridge = cameraConfig.unbridge ?? true - this.videoConfig = cameraConfig.videoConfig! + this.videoConfig = videoConfig this.videoProcessor = videoProcessor || ffmpegPath as unknown as string || 'ffmpeg' this.recording = cameraConfig.videoConfig?.recording ?? false this.prebuffer = this.recording && (cameraConfig.videoConfig?.prebuffer ?? false) @@ -131,7 +131,7 @@ export class StreamingDelegate implements CameraStreamingDelegate { } recordingCodecs.push(entry) } - this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, this.videoConfig, this.api, this.hap, this.videoProcessor) : null + this.recordingDelegate = this.recording ? new RecordingDelegate(this.log, this.cameraName, videoConfig, this.api, this.hap, this.videoProcessor) : null const options: CameraControllerOptions = { cameraStreamCount: this.videoConfig.maxStreams || 2, // HomeKit requires at least 2 streams, but 1 is also just fine