@nubisco/openbridge-camera-platform 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +120 -0
- package/config.schema.json +69 -0
- package/dist/SnapshotCache.d.ts +43 -0
- package/dist/SnapshotCache.d.ts.map +1 -0
- package/dist/SnapshotCache.js +108 -0
- package/dist/SnapshotCache.js.map +1 -0
- package/dist/StreamingDelegate.d.ts +48 -0
- package/dist/StreamingDelegate.d.ts.map +1 -0
- package/dist/StreamingDelegate.js +188 -0
- package/dist/StreamingDelegate.js.map +1 -0
- package/dist/config.d.ts +181 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/ffmpeg/args.d.ts +43 -0
- package/dist/ffmpeg/args.d.ts.map +1 -0
- package/dist/ffmpeg/args.js +100 -0
- package/dist/ffmpeg/args.js.map +1 -0
- package/dist/ffmpeg/resolve.d.ts +23 -0
- package/dist/ffmpeg/resolve.d.ts.map +1 -0
- package/dist/ffmpeg/resolve.js +65 -0
- package/dist/ffmpeg/resolve.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/dist/resolutions.d.ts +15 -0
- package/dist/resolutions.d.ts.map +1 -0
- package/dist/resolutions.js +30 -0
- package/dist/resolutions.js.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/package.json +104 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.reserveUdpPort = exports.StreamingDelegate = exports.FfmpegSnapshotRunner = exports.SnapshotCache = void 0;
|
|
18
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
19
|
+
const config_js_1 = require("./config.js");
|
|
20
|
+
const resolve_js_1 = require("./ffmpeg/resolve.js");
|
|
21
|
+
const SnapshotCache_js_1 = require("./SnapshotCache.js");
|
|
22
|
+
const StreamingDelegate_js_1 = require("./StreamingDelegate.js");
|
|
23
|
+
const resolutions_js_1 = require("./resolutions.js");
|
|
24
|
+
const PLUGIN_NAME = '@nubisco/openbridge-camera-platform';
|
|
25
|
+
let PLUGIN_VERSION = '0.1.0';
|
|
26
|
+
try {
|
|
27
|
+
PLUGIN_VERSION = require('../package.json').version;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
/* keep the default */
|
|
31
|
+
}
|
|
32
|
+
function definePlugin(plugin) {
|
|
33
|
+
return plugin;
|
|
34
|
+
}
|
|
35
|
+
const state = { delegates: [] };
|
|
36
|
+
function buildCamera(hap, camera, ffmpegPath, snapshots, log, debug) {
|
|
37
|
+
const { Accessory, Service, Characteristic, uuid, Categories } = hap;
|
|
38
|
+
// Generated from the bare name, matching what homebridge-camera-ffmpeg does.
|
|
39
|
+
// HomeKit identifies an accessory by its UUID, so keeping it identical means
|
|
40
|
+
// replacing that plugin with this one preserves each camera's room and any
|
|
41
|
+
// automations built on it. Verified against a live install: the three cached
|
|
42
|
+
// accessories there have exactly these UUIDs. Prefixing the name, which is
|
|
43
|
+
// what this did first, would have presented three brand new cameras and
|
|
44
|
+
// silently discarded all of it.
|
|
45
|
+
const accessory = new Accessory(camera.name, uuid.generate(camera.name));
|
|
46
|
+
accessory.category = Categories.CAMERA;
|
|
47
|
+
accessory
|
|
48
|
+
.getService(Service.AccessoryInformation)
|
|
49
|
+
.setCharacteristic(Characteristic.Manufacturer, camera.manufacturer ?? 'Nubisco')
|
|
50
|
+
.setCharacteristic(Characteristic.Model, camera.model ?? 'RTSP Camera')
|
|
51
|
+
.setCharacteristic(Characteristic.SerialNumber, camera.serialNumber ?? camera.name)
|
|
52
|
+
.setCharacteristic(Characteristic.FirmwareRevision, PLUGIN_VERSION);
|
|
53
|
+
const delegate = new StreamingDelegate_js_1.StreamingDelegate(hap, camera, ffmpegPath, snapshots, log, debug);
|
|
54
|
+
const controller = new hap.CameraController({
|
|
55
|
+
cameraStreamCount: camera.maxStreams,
|
|
56
|
+
delegate,
|
|
57
|
+
streamingOptions: {
|
|
58
|
+
supportedCryptoSuites: [hap.SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80],
|
|
59
|
+
video: {
|
|
60
|
+
resolutions: (0, resolutions_js_1.resolutionsFor)(camera),
|
|
61
|
+
codec: {
|
|
62
|
+
profiles: [hap.H264Profile.BASELINE, hap.H264Profile.MAIN, hap.H264Profile.HIGH],
|
|
63
|
+
levels: [hap.H264Level.LEVEL3_1, hap.H264Level.LEVEL3_2, hap.H264Level.LEVEL4_0],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
delegate.controller = controller;
|
|
69
|
+
accessory.configureController(controller);
|
|
70
|
+
return { accessory, delegate };
|
|
71
|
+
}
|
|
72
|
+
const plugin = definePlugin({
|
|
73
|
+
manifest: {
|
|
74
|
+
name: PLUGIN_NAME,
|
|
75
|
+
version: PLUGIN_VERSION,
|
|
76
|
+
description: 'RTSP cameras in HomeKit, with structured configuration and no credentials in logs',
|
|
77
|
+
author: 'José Silva',
|
|
78
|
+
},
|
|
79
|
+
async setup(ctx) {
|
|
80
|
+
const parsed = (0, config_js_1.parseConfig)(ctx.config);
|
|
81
|
+
if (!parsed.ok) {
|
|
82
|
+
const issues = parsed.problems.map((p) => ` ${p.path}: ${p.message}`).join('\n');
|
|
83
|
+
ctx.log.error(`Configuration is invalid:\n${issues}`);
|
|
84
|
+
throw new Error('Invalid plugin configuration, check the errors above and restart');
|
|
85
|
+
}
|
|
86
|
+
if (parsed.value.cameras.length === 0) {
|
|
87
|
+
ctx.log.warn('No cameras configured. Add each camera with its name and rtsp:// url.');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Checked here rather than at first stream: a missing ffmpeg is a setup
|
|
91
|
+
// problem, and finding out when someone opens the Home app is too late.
|
|
92
|
+
const ffmpeg = (0, resolve_js_1.resolveFfmpeg)(parsed.value.ffmpegPath);
|
|
93
|
+
if (!ffmpeg) {
|
|
94
|
+
throw new Error('No ffmpeg found. Install it and put it on PATH, install the optional ffmpeg-for-homebridge package, or set ffmpegPath in the plugin configuration.');
|
|
95
|
+
}
|
|
96
|
+
ctx.log.info(`Configuration valid, ${parsed.value.cameras.length} camera(s), ffmpeg from ${ffmpeg.source}`);
|
|
97
|
+
},
|
|
98
|
+
async start(ctx) {
|
|
99
|
+
const parsed = (0, config_js_1.parseConfig)(ctx.config);
|
|
100
|
+
if (!parsed.ok)
|
|
101
|
+
return;
|
|
102
|
+
const config = parsed.value;
|
|
103
|
+
if (config.cameras.length === 0)
|
|
104
|
+
return;
|
|
105
|
+
const ffmpeg = (0, resolve_js_1.resolveFfmpeg)(config.ffmpegPath);
|
|
106
|
+
if (!ffmpeg) {
|
|
107
|
+
ctx.log.error('No ffmpeg available, cameras will not be published');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const hapBridge = ctx.getHapBridge?.();
|
|
111
|
+
if (!hapBridge) {
|
|
112
|
+
ctx.log.warn('No OpenBridge HAP bridge available: cameras cannot be published to HomeKit');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const snapshots = new SnapshotCache_js_1.SnapshotCache(new SnapshotCache_js_1.FfmpegSnapshotRunner(ffmpeg.path));
|
|
116
|
+
for (const camera of config.cameras) {
|
|
117
|
+
const { accessory, delegate } = buildCamera(hapBridge.hap, camera, ffmpeg.path, snapshots, ctx.log, config.debug);
|
|
118
|
+
state.delegates.push(delegate);
|
|
119
|
+
hapBridge.bridge.addBridgedAccessory(accessory);
|
|
120
|
+
// Registered as a device too, so a camera appears in OpenBridge's own
|
|
121
|
+
// list rather than only inside HomeKit.
|
|
122
|
+
ctx.registerDevice({
|
|
123
|
+
id: `camera-${camera.name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`,
|
|
124
|
+
name: camera.name,
|
|
125
|
+
widgetType: 'camera',
|
|
126
|
+
manufacturer: camera.manufacturer ?? 'Nubisco',
|
|
127
|
+
model: camera.model ?? 'RTSP Camera',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
ctx.log.info(`Started with ${config.cameras.length} camera(s), ffmpeg at ${ffmpeg.path}`);
|
|
131
|
+
},
|
|
132
|
+
async stop(ctx) {
|
|
133
|
+
for (const delegate of state.delegates)
|
|
134
|
+
delegate.stopAll();
|
|
135
|
+
state.delegates = [];
|
|
136
|
+
ctx.log.info('Stopped');
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
exports.default = plugin;
|
|
140
|
+
module.exports = plugin;
|
|
141
|
+
module.exports.default = plugin;
|
|
142
|
+
__exportStar(require("./config.js"), exports);
|
|
143
|
+
__exportStar(require("./types.js"), exports);
|
|
144
|
+
__exportStar(require("./ffmpeg/args.js"), exports);
|
|
145
|
+
__exportStar(require("./ffmpeg/resolve.js"), exports);
|
|
146
|
+
__exportStar(require("./resolutions.js"), exports);
|
|
147
|
+
var SnapshotCache_js_2 = require("./SnapshotCache.js");
|
|
148
|
+
Object.defineProperty(exports, "SnapshotCache", { enumerable: true, get: function () { return SnapshotCache_js_2.SnapshotCache; } });
|
|
149
|
+
Object.defineProperty(exports, "FfmpegSnapshotRunner", { enumerable: true, get: function () { return SnapshotCache_js_2.FfmpegSnapshotRunner; } });
|
|
150
|
+
var StreamingDelegate_js_2 = require("./StreamingDelegate.js");
|
|
151
|
+
Object.defineProperty(exports, "StreamingDelegate", { enumerable: true, get: function () { return StreamingDelegate_js_2.StreamingDelegate; } });
|
|
152
|
+
Object.defineProperty(exports, "reserveUdpPort", { enumerable: true, get: function () { return StreamingDelegate_js_2.reserveUdpPort; } });
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,2CAAyC;AACzC,oDAAmD;AACnD,yDAAwE;AACxE,iEAA0D;AAC1D,qDAAiD;AAGjD,MAAM,WAAW,GAAG,qCAAqC,CAAA;AAEzD,IAAI,cAAc,GAAG,OAAO,CAAA;AAC5B,IAAI,CAAC;IACH,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA;AACrD,CAAC;AAAC,MAAM,CAAC;IACP,sBAAsB;AACxB,CAAC;AAqBD,SAAS,YAAY,CAA4D,MAAS;IACxF,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,KAAK,GAAuC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;AAEnE,SAAS,WAAW,CAClB,GAAQ,EACR,MAAoB,EACpB,UAAkB,EAClB,SAAwB,EACxB,GAAiB,EACjB,KAAc;IAEd,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;IAEpE,6EAA6E;IAC7E,6EA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
+
import type { CameraConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The resolution list HomeKit chooses from.
|
|
4
|
+
*
|
|
5
|
+
* Every entry must be one the camera can actually satisfy, so the list is
|
|
6
|
+
* derived from the configured maximum rather than being a fixed menu: offering
|
|
7
|
+
* 1080p for a camera configured at 720p makes HomeKit ask for something that
|
|
8
|
+
* never arrives, and the tile stays black.
|
|
9
|
+
*
|
|
10
|
+
* Its own module rather than living in index.ts, because index.ts carries the
|
|
11
|
+
* CommonJS interop shim the plugin host needs and cannot be imported from an
|
|
12
|
+
* ESM context such as a test runner.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolutionsFor(camera: Pick<CameraConfig, 'maxWidth' | 'maxHeight' | 'maxFps'>): number[][];
|
|
15
|
+
//# sourceMappingURL=resolutions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolutions.d.ts","sourceRoot":"","sources":["../src/resolutions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,WAAW,GAAG,QAAQ,CAAC,GAAG,MAAM,EAAE,EAAE,CAY1G"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolutionsFor = resolutionsFor;
|
|
4
|
+
/**
|
|
5
|
+
* The resolution list HomeKit chooses from.
|
|
6
|
+
*
|
|
7
|
+
* Every entry must be one the camera can actually satisfy, so the list is
|
|
8
|
+
* derived from the configured maximum rather than being a fixed menu: offering
|
|
9
|
+
* 1080p for a camera configured at 720p makes HomeKit ask for something that
|
|
10
|
+
* never arrives, and the tile stays black.
|
|
11
|
+
*
|
|
12
|
+
* Its own module rather than living in index.ts, because index.ts carries the
|
|
13
|
+
* CommonJS interop shim the plugin host needs and cannot be imported from an
|
|
14
|
+
* ESM context such as a test runner.
|
|
15
|
+
*/
|
|
16
|
+
function resolutionsFor(camera) {
|
|
17
|
+
const candidates = [
|
|
18
|
+
[320, 180],
|
|
19
|
+
[480, 270],
|
|
20
|
+
[640, 360],
|
|
21
|
+
[1280, 720],
|
|
22
|
+
[1920, 1080],
|
|
23
|
+
];
|
|
24
|
+
const allowed = candidates.filter(([w, h]) => w <= camera.maxWidth && h <= camera.maxHeight);
|
|
25
|
+
// Always offer at least one, even for an unusually small configured maximum.
|
|
26
|
+
if (allowed.length === 0)
|
|
27
|
+
allowed.push([camera.maxWidth, camera.maxHeight]);
|
|
28
|
+
return allowed.map(([w, h]) => [w, h, camera.maxFps]);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=resolutions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolutions.js","sourceRoot":"","sources":["../src/resolutions.ts"],"names":[],"mappings":";;AAcA,wCAYC;AAxBD;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAAC,MAA+D;IAC5F,MAAM,UAAU,GAAG;QACjB,CAAC,GAAG,EAAE,GAAG,CAAC;QACV,CAAC,GAAG,EAAE,GAAG,CAAC;QACV,CAAC,GAAG,EAAE,GAAG,CAAC;QACV,CAAC,IAAI,EAAE,GAAG,CAAC;QACX,CAAC,IAAI,EAAE,IAAI,CAAC;KACb,CAAA;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,IAAI,MAAM,CAAC,QAAQ,IAAI,CAAE,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;IAC9F,6EAA6E;IAC7E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;IAC3E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAE,EAAE,CAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;AACzD,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera configuration.
|
|
3
|
+
*
|
|
4
|
+
* The important difference from homebridge-camera-ffmpeg is that a camera is
|
|
5
|
+
* described by its parts rather than by a raw ffmpeg argument string. That
|
|
6
|
+
* plugin asks for:
|
|
7
|
+
*
|
|
8
|
+
* "source": "-rtsp_transport tcp -i rtsp://user:pass@192.168.1.138:554/stream1"
|
|
9
|
+
*
|
|
10
|
+
* which makes the person configuring it responsible for ffmpeg's command line,
|
|
11
|
+
* puts their camera password in a field that is printed to the log on every
|
|
12
|
+
* stream, and gives the plugin nothing it can validate. Here the URL, the
|
|
13
|
+
* credentials and the transport are separate fields, the arguments are built
|
|
14
|
+
* from them, and the password never appears in a log line.
|
|
15
|
+
*/
|
|
16
|
+
export type RtspTransport = 'tcp' | 'udp';
|
|
17
|
+
export interface CameraConfig {
|
|
18
|
+
name: string;
|
|
19
|
+
/** `rtsp://host:554/path`. Credentials go in their own fields, not here. */
|
|
20
|
+
url: string;
|
|
21
|
+
username?: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
/** TCP unless a camera genuinely needs UDP: TCP survives packet loss. */
|
|
24
|
+
transport: RtspTransport;
|
|
25
|
+
/** A second, lower-resolution stream used for snapshots when the camera has one. */
|
|
26
|
+
snapshotUrl?: string;
|
|
27
|
+
manufacturer?: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
serialNumber?: string;
|
|
30
|
+
maxWidth: number;
|
|
31
|
+
maxHeight: number;
|
|
32
|
+
maxFps: number;
|
|
33
|
+
maxBitrateKbps: number;
|
|
34
|
+
/** Concurrent HomeKit viewers. Each one is another ffmpeg process. */
|
|
35
|
+
maxStreams: number;
|
|
36
|
+
audio: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Re-encode instead of copying the camera's H.264 stream.
|
|
39
|
+
*
|
|
40
|
+
* Copying is free and is right for almost every camera. Re-encoding costs a
|
|
41
|
+
* lot of CPU on a Raspberry Pi and is only needed when a camera emits a
|
|
42
|
+
* profile HomeKit refuses.
|
|
43
|
+
*/
|
|
44
|
+
transcode: boolean;
|
|
45
|
+
/** How long a cached snapshot stays fresh. */
|
|
46
|
+
snapshotCacheSeconds: number;
|
|
47
|
+
/** Give up on a snapshot after this long rather than making HomeKit wait. */
|
|
48
|
+
snapshotTimeoutMs: number;
|
|
49
|
+
}
|
|
50
|
+
export interface PlatformConfig {
|
|
51
|
+
cameras: CameraConfig[];
|
|
52
|
+
/** Explicit ffmpeg path, when the bundled and PATH lookups are both wrong. */
|
|
53
|
+
ffmpegPath?: string;
|
|
54
|
+
/** Log the full ffmpeg command line, with credentials still redacted. */
|
|
55
|
+
debug: boolean;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAA;AAEzC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yEAAyE;IACzE,SAAS,EAAE,aAAa,CAAA;IACxB,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;IAEd;;;;;;OAMG;IACH,SAAS,EAAE,OAAO,CAAA;IAElB,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,CAAA;IAC5B,6EAA6E;IAC7E,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,yEAAyE;IACzE,KAAK,EAAE,OAAO,CAAA;CACf"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Camera configuration.
|
|
4
|
+
*
|
|
5
|
+
* The important difference from homebridge-camera-ffmpeg is that a camera is
|
|
6
|
+
* described by its parts rather than by a raw ffmpeg argument string. That
|
|
7
|
+
* plugin asks for:
|
|
8
|
+
*
|
|
9
|
+
* "source": "-rtsp_transport tcp -i rtsp://user:pass@192.168.1.138:554/stream1"
|
|
10
|
+
*
|
|
11
|
+
* which makes the person configuring it responsible for ffmpeg's command line,
|
|
12
|
+
* puts their camera password in a field that is printed to the log on every
|
|
13
|
+
* stream, and gives the plugin nothing it can validate. Here the URL, the
|
|
14
|
+
* credentials and the transport are separate fields, the arguments are built
|
|
15
|
+
* from them, and the password never appears in a log line.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nubisco/openbridge-camera-platform",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "RTSP cameras in HomeKit through OpenBridge, with structured config and no credentials in your logs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"config.schema.json",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20.0.0"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Jos\u00e9 Silva <jose@nubisco.io>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/nubisco/openbridge-camera-platform.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/nubisco/openbridge-camera-platform/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://docs.nubisco.io/openbridge-camera-platform/",
|
|
25
|
+
"funding": {
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/joseporto"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"openbridge-plugin",
|
|
31
|
+
"camera",
|
|
32
|
+
"rtsp",
|
|
33
|
+
"ffmpeg",
|
|
34
|
+
"homekit",
|
|
35
|
+
"local"
|
|
36
|
+
],
|
|
37
|
+
"openbridge": {
|
|
38
|
+
"platform": "CameraPlatform",
|
|
39
|
+
"displayName": "Camera Platform"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"prebuild": "npm run clean",
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"dev": "tsc --watch",
|
|
49
|
+
"prepublishOnly": "npm run build",
|
|
50
|
+
"test": "vitest run --passWithNoTests",
|
|
51
|
+
"lint": "eslint src/ tests/",
|
|
52
|
+
"types:check": "tsc --noEmit",
|
|
53
|
+
"format:check": "prettier --check .",
|
|
54
|
+
"quality:check": "npm test && npm run lint && npm run format:check && npm run types:check",
|
|
55
|
+
"docs:dev": "vitepress dev docs",
|
|
56
|
+
"docs:build": "vitepress build docs",
|
|
57
|
+
"docs:preview": "vitepress preview docs"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"hap-nodejs": ">=0.12.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"zod": "^3.25.76"
|
|
64
|
+
},
|
|
65
|
+
"optionalDependencies": {
|
|
66
|
+
"ffmpeg-for-homebridge": "^2.1.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^10.0.1",
|
|
70
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
71
|
+
"@semantic-release/git": "^11.0.1",
|
|
72
|
+
"@types/node": "^22.0.0",
|
|
73
|
+
"eslint": "^10.11.0",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"prettier": "^3.9.9",
|
|
76
|
+
"semantic-release": "^25.0.9",
|
|
77
|
+
"typescript": "^5.0.0",
|
|
78
|
+
"typescript-eslint": "^8.71.0",
|
|
79
|
+
"vitepress": "^1.6.4",
|
|
80
|
+
"vitest": "^3.0.0"
|
|
81
|
+
},
|
|
82
|
+
"release": {
|
|
83
|
+
"branches": [
|
|
84
|
+
"master"
|
|
85
|
+
],
|
|
86
|
+
"plugins": [
|
|
87
|
+
"@semantic-release/commit-analyzer",
|
|
88
|
+
"@semantic-release/release-notes-generator",
|
|
89
|
+
"@semantic-release/changelog",
|
|
90
|
+
"@semantic-release/npm",
|
|
91
|
+
"@semantic-release/github",
|
|
92
|
+
[
|
|
93
|
+
"@semantic-release/git",
|
|
94
|
+
{
|
|
95
|
+
"assets": [
|
|
96
|
+
"package.json",
|
|
97
|
+
"CHANGELOG.md"
|
|
98
|
+
],
|
|
99
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
}
|