From 704d488d643a3a23a292abca0db50057b59a4022 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Fri, 25 Oct 2024 07:35:33 -0500 Subject: [PATCH] unbridged by default --- README.md | 4 +-- config.schema.json | 3 +- package-lock.json | 14 +++------ package.json | 68 ++++++++++++++++++++-------------------- src/index.ts | 35 +++++++++++---------- src/streamingDelegate.ts | 2 +- 6 files changed, 63 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index b07b4785..6208e81f 100755 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Other users have been sharing configurations that work for them on our GitHub si - `model`: Set the model for display in the Home app. (Default: `Camera FFmpeg`) - `serialNumber`: Set the serial number for display in the Home app. (Default: `SerialNumber`) - `firmwareRevision`: Set the firmware revision for display in the Home app. (Default: current plugin version) -- `unbridge`: Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually. (Default: `false`) +- `unbridge`: Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually. (Default: `true`) #### Config Example with Manufacturer and Model Set @@ -94,7 +94,7 @@ Other users have been sharing configurations that work for them on our GitHub si - `maxFPS`: The maximum frame rate used for video streamed to HomeKit. If set to 0, the framerate of the source is used. If not set, will use any frame rate HomeKit requests. - `maxBitrate`: The maximum bitrate used for video streamed to HomeKit, in kbit/s. If not set, will use any bitrate HomeKit requests. - `forceMax`: If set, the settings requested by HomeKit will be overridden with any 'maximum' values defined in this config. (Default: `false`) -- `vcodec`: Set the codec used for encoding video sent to HomeKit, must be H.264-based. You can change to a hardware accelerated video codec with this option, if one is available. (Default: `libx264`) +- `vcodec`: Set the codec used for encoding video sent to HomeKit, must be H.264-based. You can change to a hardware accelerated video codec with this option, if one is available. (Default: `libx264`) - `audio`: Enables audio streaming from camera. (Default: `false`) - `packetSize`: If audio or video is choppy try a smaller value, should be set to a multiple of 188. (Default: `1316`) - `mapvideo`: Selects the stream used for video. (Default: FFmpeg [automatically selects](https://ffmpeg.org/ffmpeg.html#Automatic-stream-selection) a video stream) diff --git a/config.schema.json b/config.schema.json index 9bc210c0..04923669 100644 --- a/config.schema.json +++ b/config.schema.json @@ -118,8 +118,9 @@ "description": "Rings the doorbell when motion is activated. This allows for motion alerts to appear on Apple TVs." }, "unbridge": { - "title": "Unbridge Camera (Recommended)", + "title": "Unbridge Camera", "type": "boolean", + "default": true, "description": "Bridged cameras can cause slowdowns of the entire Homebridge instance. If unbridged, the camera will need to be added to HomeKit manually." }, "videoConfig": { diff --git a/package-lock.json b/package-lock.json index 5348667a..37c02d57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "dependencies": { "ffmpeg-for-homebridge": "^2.1.7", "mqtt": "5.10.1", - "pick-port": "^2.1.0" + "pick-port": "^1.0.1" }, "devDependencies": { "@antfu/eslint-config": "^3.8.0", @@ -410,7 +410,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "dev": true, "inBundle": true, "license": "MIT", "engines": { @@ -9562,15 +9561,12 @@ } }, "node_modules/pick-port": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/pick-port/-/pick-port-2.1.0.tgz", - "integrity": "sha512-nqdK+0cmJLGMHKZCNh6PfA/ZeIhHYKSlLLwyfH/IFQVv9SqwNUdbm+08olnd+PbmLqrHk8Twhq6yO9viqOGkkw==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pick-port/-/pick-port-1.0.1.tgz", + "integrity": "sha512-JzjRIkfG/4pG3tYLl1LwdmFtnlW+Rsxe200DevHZzZLYDUgfnx8LuOFnLwy5Dt59JY1HIN3JXyMXRbUvERkh/g==", "license": "MIT", "dependencies": { - "debug": "^4.3.4" - }, - "engines": { - "node": ">=18" + "debug": "^4.3.1" } }, "node_modules/picocolors": { diff --git a/package.json b/package.json index 70465074..9aed5315 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,10 @@ { - "displayName": "Homebridge Camera FFmpeg", "name": "homebridge-camera-ffmpeg", + "displayName": "Homebridge Camera FFmpeg", + "type": "module", "version": "3.1.4", "description": "Homebridge Plugin Providing FFmpeg-based Camera Support", - "main": "dist/index.js", "license": "ISC", - "type": "module", "funding": [ { "type": "kofi", @@ -24,6 +23,32 @@ "url": "https://liberapay.com/Sunoo" } ], + "repository": { + "type": "git", + "url": "git://github.com/homebridge-plugins/homebridge-camera-ffmpeg.git" + }, + "bugs": { + "url": "http://github.com/homebridge-plugins/homebridge-camera-ffmpeg/issues" + }, + "keywords": [ + "homebridge-plugin", + "camera", + "ffmpeg", + "homebridge" + ], + "main": "dist/index.js", + "files": [ + "CHANGELOG.md", + "LICENSE", + "README.md", + "config.schema.json", + "dist/**/*", + "package.json" + ], + "engines": { + "homebridge": "^1.8.4 || ^2.0.0 || ^2.0.0-beta.22 || ^2.0.0-alpha.37", + "node": "^20 || ^22" + }, "scripts": { "check": "npm install && npm outdated", "update": "ncu -u && npm update && npm install", @@ -38,31 +63,11 @@ "docs": "typedoc", "lint-docs": "typedoc --emit none --treatWarningsAsErrors" }, - "keywords": [ - "homebridge-plugin", - "camera", - "ffmpeg", - "homebridge" - ], - "repository": { - "type": "git", - "url": "git://github.com/homebridge-plugins/homebridge-camera-ffmpeg.git" - }, - "bugs": { - "url": "http://github.com/homebridge-plugins/homebridge-camera-ffmpeg/issues" - }, - "engines": { - "homebridge": "^1.8.4 || ^2.0.0 || ^2.0.0-beta.22 || ^2.0.0-alpha.37", - "node": "^20 || ^22" + "dependencies": { + "ffmpeg-for-homebridge": "^2.1.7", + "mqtt": "5.10.1", + "pick-port": "^1.0.1" }, - "files": [ - "CHANGELOG.md", - "config.schema.json", - "dist/**/*", - "LICENSE", - "package.json", - "README.md" - ], "devDependencies": { "@antfu/eslint-config": "^3.8.0", "@types/aes-js": "^3.1.4", @@ -70,9 +75,9 @@ "@types/fs-extra": "^11.0.4", "@types/mdast": "^4.0.4", "@types/node": "^22.7.9", - "@types/ws": "^8.5.12", "@types/semver": "^7.5.8", "@types/source-map-support": "^0.5.10", + "@types/ws": "^8.5.12", "@vitest/coverage-v8": "^2.1.3", "eslint": "^9.13.0", "eslint-plugin-format": "^0.1.2", @@ -85,10 +90,5 @@ "typedoc": "^0.26.10", "typescript": "^5.6.3", "vitest": "^2.1.3" - }, - "dependencies": { - "ffmpeg-for-homebridge": "^2.1.7", - "mqtt": "5.10.1", - "pick-port": "^2.1.0" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index e91297dd..5a7266e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,7 +58,8 @@ class FfmpegPlatform implements DynamicPlatformPlugin { if (!cameraConfig.name) { this.log.error('One of your cameras has no name configured. This camera will be skipped.') - error = true + cameraConfig.name = `Camera ${this.cameraConfigs.size + 1}` + error = false } if (!cameraConfig.videoConfig) { this.log.error('The videoConfig section is missing from the config. This camera will be skipped.', cameraConfig.name) @@ -85,7 +86,7 @@ class FfmpegPlatform implements DynamicPlatformPlugin { } if (!error) { - const uuid = this.api.hap.uuid.generate(cameraConfig.name!) + const uuid = this.api.hap.uuid.generate(cameraConfig.name ?? `Camera ${this.cameraConfigs.size + 1}`) if (this.cameraConfigs.has(uuid)) { // Camera names must be unique this.log.warn('Multiple cameras are configured with this name. Duplicate cameras will be skipped.', cameraConfig.name) @@ -359,23 +360,17 @@ class FfmpegPlatform implements DynamicPlatformPlugin { didFinishLaunching(): void { for (const [uuid, cameraConfig] of this.cameraConfigs) { - if (cameraConfig.unbridge) { - const accessory = new this.api.platformAccessory(cameraConfig.name!, uuid) - this.log.info('Configuring unbridged accessory...', accessory.displayName) + const unbridge = cameraConfig.unbridge ?? true + const name = cameraConfig.name || `Camera ${this.cameraConfigs.size + 1}` + const cachedAccessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => curAcc.UUID === uuid) + if (!cachedAccessory) { + const accessory = new this.api.platformAccessory(name, uuid) + this.log.info('Configuring bridged accessory...', accessory.displayName) this.setupAccessory(accessory, cameraConfig) - this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]) + this.externalOrPlatform(unbridge, accessory) this.accessories.push(accessory) } else { - const cachedAccessory = this.cachedAccessories.find((curAcc: PlatformAccessory) => curAcc.UUID === uuid) - if (!cachedAccessory) { - const accessory = new this.api.platformAccessory(cameraConfig.name!, uuid) - this.log.info('Configuring bridged accessory...', accessory.displayName) - this.setupAccessory(accessory, cameraConfig) - this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]) - this.accessories.push(accessory) - } else { - this.accessories.push(cachedAccessory) - } + this.accessories.push(cachedAccessory) } } @@ -441,6 +436,14 @@ class FfmpegPlatform implements DynamicPlatformPlugin { } }) } + + public async externalOrPlatform(unbridge: boolean, accessory: PlatformAccessory) { + if (unbridge) { + this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]) + } else { + this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]) + } + } } function getVersion() { diff --git a/src/streamingDelegate.ts b/src/streamingDelegate.ts index ef35251b..08813280 100644 --- a/src/streamingDelegate.ts +++ b/src/streamingDelegate.ts @@ -100,7 +100,7 @@ export class StreamingDelegate implements CameraStreamingDelegate { this.api = api this.cameraName = cameraConfig.name! - this.unbridge = cameraConfig.unbridge ?? false + this.unbridge = cameraConfig.unbridge ?? true this.videoConfig = cameraConfig.videoConfig! this.videoProcessor = videoProcessor || ffmpegPath as unknown as string || 'ffmpeg' this.recording = cameraConfig.videoConfig?.recording ?? false