@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 ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nubisco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ <p align="center">
2
+ <img src="docs/public/logo.svg" width="120" alt="OpenBridge Camera Platform" />
3
+ </p>
4
+
5
+ # OpenBridge Camera Platform
6
+
7
+ **RTSP cameras in Apple HomeKit, through [OpenBridge](https://github.com/nubisco/openbridge).**
8
+
9
+ Structured configuration, credentials that never reach your logs, and snapshots that give up instead of hanging.
10
+
11
+ [![CI](https://github.com/nubisco/openbridge-camera-platform/actions/workflows/ci.yml/badge.svg)](https://github.com/nubisco/openbridge-camera-platform/actions/workflows/ci.yml)
12
+ [![npm version](https://img.shields.io/npm/v/@nubisco/openbridge-camera-platform)](https://www.npmjs.com/package/@nubisco/openbridge-camera-platform)
13
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20.0.0-339933)](https://www.npmjs.com/package/@nubisco/openbridge-camera-platform)
14
+ [![license](https://img.shields.io/npm/l/@nubisco/openbridge-camera-platform)](LICENSE)
15
+ [![Docs](https://img.shields.io/website?url=https%3A%2F%2Fdocs.nubisco.io%2Fopenbridge-camera-platform%2F&label=docs)](https://docs.nubisco.io/openbridge-camera-platform/)
16
+
17
+ ## Quick Start
18
+
19
+ ```sh
20
+ npm install -g @nubisco/openbridge-camera-platform
21
+ ```
22
+
23
+ ```json
24
+ {
25
+ "name": "@nubisco/openbridge-camera-platform",
26
+ "enabled": true,
27
+ "config": {
28
+ "cameras": [
29
+ {
30
+ "name": "Living Room",
31
+ "url": "rtsp://192.168.1.138:554/stream1",
32
+ "username": "viewer",
33
+ "password": "…",
34
+ "manufacturer": "TP-Link",
35
+ "model": "Tapo"
36
+ }
37
+ ]
38
+ }
39
+ }
40
+ ```
41
+
42
+ That is a complete camera. Everything else has a default that is a decision rather than a placeholder.
43
+
44
+ ## What it does differently
45
+
46
+ **Credentials are fields, not part of a command string.** The usual approach asks you to write the
47
+ ffmpeg invocation yourself:
48
+
49
+ ```json
50
+ "source": "-rtsp_transport tcp -i rtsp://user:pass@192.168.1.138:554/stream1"
51
+ ```
52
+
53
+ That makes you responsible for ffmpeg's command line, and it puts your camera password in a value
54
+ that gets printed on every stream. Here the URL, username, password and transport are separate.
55
+ Configuration that embeds credentials in the URL is **rejected at startup** with an explanation.
56
+
57
+ **Passwords are redacted everywhere, including ffmpeg's own output.** ffmpeg echoes the URL it was
58
+ given in its diagnostics, so redacting only our log lines would still leak the password through
59
+ stderr, which is exactly what ends up pasted into a support thread.
60
+
61
+ **Snapshots time out.** A camera that has dropped off the network does not refuse the connection, it
62
+ simply never answers, and ffmpeg will wait a very long time. Snapshots are bounded (10s by default),
63
+ cached, and shared between concurrent requests, so a Home app opening does not start four ffmpeg
64
+ processes against one camera. When a capture fails and a previous frame exists, the stale frame is
65
+ served rather than a broken tile.
66
+
67
+ **Arguments are arrays, never strings.** A camera path or password containing a space cannot turn
68
+ into a different command.
69
+
70
+ **Resolutions are derived from your configuration.** Offering HomeKit a resolution the camera is not
71
+ configured to deliver makes it ask for something that never arrives, and the tile stays black.
72
+
73
+ **ffmpeg is found, not assumed.** Explicit `ffmpegPath`, then the optional `ffmpeg-for-homebridge`
74
+ binary, then `PATH`. That package is an _optional_ dependency deliberately: it downloads a static
75
+ build at install time and has no artefact for every platform, so depending on it outright would make
76
+ this plugin uninstallable on the hosts it lacks.
77
+
78
+ ## Configuration
79
+
80
+ | Option | Default | Meaning |
81
+ | ------------------------ | --------------- | --------------------------------------------------------------- |
82
+ | `name` | required | HomeKit accessory name. Must be unique |
83
+ | `url` | required | `rtsp://host:554/path`, without credentials |
84
+ | `username` / `password` | — | Camera credentials |
85
+ | `snapshotUrl` | — | Optional lower-resolution substream for stills |
86
+ | `transport` | `tcp` | `tcp` survives packet loss; use `udp` only if a camera needs it |
87
+ | `maxWidth` / `maxHeight` | `1920` / `1080` | Largest stream offered |
88
+ | `maxFps` | `15` | HomeKit tiles are small and most cameras deliver 15 happily |
89
+ | `maxStreams` | `2` | Concurrent viewers. Each one is another ffmpeg process |
90
+ | `transcode` | `false` | Re-encode. Expensive; only for cameras HomeKit refuses |
91
+ | `snapshotCacheSeconds` | `10` | How long a still stays fresh |
92
+ | `snapshotTimeoutMs` | `10000` | Give up rather than making HomeKit wait |
93
+
94
+ ## Documentation
95
+
96
+ **[docs.nubisco.io/openbridge-camera-platform](https://docs.nubisco.io/openbridge-camera-platform/)**
97
+
98
+ ## Contributing
99
+
100
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
101
+
102
+ ```sh
103
+ npm install
104
+ npm run quality:check
105
+ ```
106
+
107
+ ## Security
108
+
109
+ Camera credentials are involved, so please report vulnerabilities privately rather than in a public
110
+ issue. See [SECURITY.md](SECURITY.md).
111
+
112
+ ## Support this project
113
+
114
+ Maintaining camera integrations means testing against real hardware, which costs money.
115
+
116
+ - ❤️ [Sponsor via GitHub](https://github.com/sponsors/joseporto)
117
+
118
+ ## License
119
+
120
+ [MIT](LICENSE) © Nubisco
@@ -0,0 +1,69 @@
1
+ {
2
+ "pluginAlias": "CameraPlatform",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "headerDisplay": "RTSP cameras in HomeKit. Credentials go in their own fields, never in the URL, so they stay out of your logs.",
6
+ "schema": {
7
+ "type": "object",
8
+ "properties": {
9
+ "ffmpegPath": {
10
+ "title": "ffmpeg path",
11
+ "type": "string",
12
+ "description": "Only needed when the bundled binary and PATH are both wrong."
13
+ },
14
+ "debug": {
15
+ "title": "Log ffmpeg commands",
16
+ "type": "boolean",
17
+ "default": false,
18
+ "description": "Logs the full command line, with credentials still redacted."
19
+ },
20
+ "cameras": {
21
+ "title": "Cameras",
22
+ "type": "array",
23
+ "items": {
24
+ "type": "object",
25
+ "properties": {
26
+ "name": { "title": "Name", "type": "string", "required": true },
27
+ "url": {
28
+ "title": "RTSP URL",
29
+ "type": "string",
30
+ "required": true,
31
+ "description": "rtsp://host:554/path — without credentials."
32
+ },
33
+ "username": { "title": "Username", "type": "string" },
34
+ "password": { "title": "Password", "type": "string", "x-schema-form": { "type": "password" } },
35
+ "snapshotUrl": {
36
+ "title": "Snapshot URL",
37
+ "type": "string",
38
+ "description": "Optional lower-resolution substream, used for stills."
39
+ },
40
+ "transport": {
41
+ "title": "Transport",
42
+ "type": "string",
43
+ "default": "tcp",
44
+ "oneOf": [
45
+ { "title": "TCP (recommended)", "enum": ["tcp"] },
46
+ { "title": "UDP", "enum": ["udp"] }
47
+ ]
48
+ },
49
+ "manufacturer": { "title": "Manufacturer", "type": "string" },
50
+ "model": { "title": "Model", "type": "string" },
51
+ "maxWidth": { "title": "Max width", "type": "integer", "default": 1920 },
52
+ "maxHeight": { "title": "Max height", "type": "integer", "default": 1080 },
53
+ "maxFps": { "title": "Max FPS", "type": "integer", "default": 15 },
54
+ "maxBitrateKbps": { "title": "Max bitrate (kbps)", "type": "integer", "default": 2000 },
55
+ "maxStreams": { "title": "Concurrent viewers", "type": "integer", "default": 2 },
56
+ "transcode": {
57
+ "title": "Re-encode",
58
+ "type": "boolean",
59
+ "default": false,
60
+ "description": "Leave off unless the camera emits a profile HomeKit refuses. Re-encoding is expensive."
61
+ },
62
+ "snapshotCacheSeconds": { "title": "Snapshot cache (seconds)", "type": "number", "default": 10 },
63
+ "snapshotTimeoutMs": { "title": "Snapshot timeout (ms)", "type": "integer", "default": 10000 }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,43 @@
1
+ export interface SnapshotRunner {
2
+ /** Runs ffmpeg with these arguments and resolves the bytes it wrote to stdout. */
3
+ capture(args: string[], timeoutMs: number): Promise<Buffer>;
4
+ }
5
+ /**
6
+ * Captures a still frame, with a hard timeout.
7
+ *
8
+ * The timeout is the point. A camera that has dropped off the network does not
9
+ * refuse a connection, it simply never answers, and ffmpeg will wait a very
10
+ * long time. The plugin this replaces was seen holding a snapshot request for
11
+ * **133 seconds** on exactly that: HomeKit had given up long before, and the
12
+ * bridge was left with a stuck process per attempt.
13
+ */
14
+ export declare class FfmpegSnapshotRunner implements SnapshotRunner {
15
+ private readonly binary;
16
+ constructor(binary: string);
17
+ capture(args: string[], timeoutMs: number): Promise<Buffer>;
18
+ }
19
+ /**
20
+ * One snapshot per camera, reused while it is fresh, with concurrent requests
21
+ * sharing one capture.
22
+ *
23
+ * HomeKit asks several times in quick succession when a Home app opens, and
24
+ * each unshared request would be another ffmpeg process pulling the same RTSP
25
+ * stream from the same camera. Cheap hardware falls over doing that.
26
+ */
27
+ export declare class SnapshotCache {
28
+ private readonly runner;
29
+ private readonly now;
30
+ private entries;
31
+ private inFlight;
32
+ constructor(runner: SnapshotRunner, now?: () => number);
33
+ get(key: string, args: string[], cacheSeconds: number, timeoutMs: number): Promise<Buffer>;
34
+ /**
35
+ * The last image captured, however old.
36
+ *
37
+ * A stale frame is better than a broken tile when a camera is temporarily
38
+ * unreachable, as long as the caller knows it is stale and does not cache it
39
+ * again as if it were current.
40
+ */
41
+ lastKnown(key: string): Buffer | undefined;
42
+ }
43
+ //# sourceMappingURL=SnapshotCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapshotCache.d.ts","sourceRoot":"","sources":["../src/SnapshotCache.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,kFAAkF;IAClF,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5D;AAED;;;;;;;;GAQG;AACH,qBAAa,oBAAqB,YAAW,cAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAoC5D;AAOD;;;;;;;GAOG;AACH,qBAAa,aAAa;IAKtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,QAAQ,CAAqC;gBAGlC,MAAM,EAAE,cAAc,EACtB,GAAG,GAAE,MAAM,MAAiB;IAGzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBhG;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAG3C"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapshotCache = exports.FfmpegSnapshotRunner = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const args_js_1 = require("./ffmpeg/args.js");
6
+ /**
7
+ * Captures a still frame, with a hard timeout.
8
+ *
9
+ * The timeout is the point. A camera that has dropped off the network does not
10
+ * refuse a connection, it simply never answers, and ffmpeg will wait a very
11
+ * long time. The plugin this replaces was seen holding a snapshot request for
12
+ * **133 seconds** on exactly that: HomeKit had given up long before, and the
13
+ * bridge was left with a stuck process per attempt.
14
+ */
15
+ class FfmpegSnapshotRunner {
16
+ binary;
17
+ constructor(binary) {
18
+ this.binary = binary;
19
+ }
20
+ capture(args, timeoutMs) {
21
+ return new Promise((resolve, reject) => {
22
+ const child = (0, node_child_process_1.spawn)(this.binary, args, { stdio: ['ignore', 'pipe', 'pipe'] });
23
+ const chunks = [];
24
+ let stderr = '';
25
+ let settled = false;
26
+ const finish = (err, value) => {
27
+ if (settled)
28
+ return;
29
+ settled = true;
30
+ clearTimeout(timer);
31
+ if (err)
32
+ reject(err);
33
+ else
34
+ resolve(value);
35
+ };
36
+ const timer = setTimeout(() => {
37
+ // SIGKILL rather than SIGTERM: ffmpeg blocked on a socket read that
38
+ // will never complete does not always act on a polite signal, and a
39
+ // process that outlives its timeout is worse than no snapshot.
40
+ child.kill('SIGKILL');
41
+ finish(new Error(`Snapshot timed out after ${timeoutMs}ms`));
42
+ }, timeoutMs);
43
+ child.stdout.on('data', (c) => chunks.push(c));
44
+ child.stderr.on('data', (c) => {
45
+ stderr += c.toString();
46
+ });
47
+ child.on('error', (err) => finish(new Error((0, args_js_1.redact)(err.message))));
48
+ child.on('close', (code) => {
49
+ const data = Buffer.concat(chunks);
50
+ if (code === 0 && data.length > 0)
51
+ return finish(null, data);
52
+ const detail = stderr.trim().split('\n').slice(-2).join(' ');
53
+ finish(new Error((0, args_js_1.redact)(detail || `ffmpeg exited with code ${code} and produced no image`)));
54
+ });
55
+ });
56
+ }
57
+ }
58
+ exports.FfmpegSnapshotRunner = FfmpegSnapshotRunner;
59
+ /**
60
+ * One snapshot per camera, reused while it is fresh, with concurrent requests
61
+ * sharing one capture.
62
+ *
63
+ * HomeKit asks several times in quick succession when a Home app opens, and
64
+ * each unshared request would be another ffmpeg process pulling the same RTSP
65
+ * stream from the same camera. Cheap hardware falls over doing that.
66
+ */
67
+ class SnapshotCache {
68
+ runner;
69
+ now;
70
+ entries = new Map();
71
+ inFlight = new Map();
72
+ constructor(runner, now = Date.now) {
73
+ this.runner = runner;
74
+ this.now = now;
75
+ }
76
+ async get(key, args, cacheSeconds, timeoutMs) {
77
+ const cached = this.entries.get(key);
78
+ if (cached && this.now() - cached.capturedAt < cacheSeconds * 1000) {
79
+ return cached.image;
80
+ }
81
+ const existing = this.inFlight.get(key);
82
+ if (existing)
83
+ return existing;
84
+ const pending = this.runner
85
+ .capture(args, timeoutMs)
86
+ .then((image) => {
87
+ this.entries.set(key, { image, capturedAt: this.now() });
88
+ return image;
89
+ })
90
+ .finally(() => {
91
+ this.inFlight.delete(key);
92
+ });
93
+ this.inFlight.set(key, pending);
94
+ return pending;
95
+ }
96
+ /**
97
+ * The last image captured, however old.
98
+ *
99
+ * A stale frame is better than a broken tile when a camera is temporarily
100
+ * unreachable, as long as the caller knows it is stale and does not cache it
101
+ * again as if it were current.
102
+ */
103
+ lastKnown(key) {
104
+ return this.entries.get(key)?.image;
105
+ }
106
+ }
107
+ exports.SnapshotCache = SnapshotCache;
108
+ //# sourceMappingURL=SnapshotCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapshotCache.js","sourceRoot":"","sources":["../src/SnapshotCache.ts"],"names":[],"mappings":";;;AAAA,2DAA0C;AAC1C,8CAAyC;AAOzC;;;;;;;;GAQG;AACH,MAAa,oBAAoB;IACF;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,OAAO,CAAC,IAAc,EAAE,SAAiB;QACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,KAAK,GAAG,IAAA,0BAAK,EAAC,IAAI,CAAC,MAAM,EA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AAQ;YAAE,OAAO,QAAQ,CAAA;QAE7B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM;aACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;aACxB,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;YACxD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QAEJ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC/B,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAA;IACrC,CAAC;CACF;AA1CD,sCA0CC"}
@@ -0,0 +1,48 @@
1
+ import type { SnapshotCache } from './SnapshotCache.js';
2
+ import type { CameraConfig } from './types.js';
3
+ export interface DelegateLogger {
4
+ debug(message: string): void;
5
+ info(message: string): void;
6
+ warn(message: string): void;
7
+ error(message: string): void;
8
+ }
9
+ /**
10
+ * Bridges one camera to HomeKit's streaming protocol.
11
+ *
12
+ * HomeKit negotiates in two steps: `prepareStream` reserves ports and exchanges
13
+ * SRTP keys, then `handleStreamRequest` starts, reconfigures or stops the flow.
14
+ * ffmpeg is only spawned on start, so a client that negotiates and walks away
15
+ * costs nothing.
16
+ */
17
+ export declare class StreamingDelegate {
18
+ private readonly hap;
19
+ private readonly camera;
20
+ private readonly ffmpegPath;
21
+ private readonly snapshots;
22
+ private readonly log;
23
+ private readonly debug;
24
+ private sessions;
25
+ controller: any;
26
+ constructor(hap: any, camera: CameraConfig, ffmpegPath: string, snapshots: SnapshotCache, log: DelegateLogger, debug: boolean);
27
+ /**
28
+ * HomeKit's snapshot request.
29
+ *
30
+ * Never rejects when a previous image exists: a stale frame beats the broken
31
+ * tile HomeKit shows on an error, and a camera that is slow right now is
32
+ * usually fine a moment later.
33
+ */
34
+ handleSnapshotRequest(request: {
35
+ width: number;
36
+ height: number;
37
+ }, callback: (error?: Error | null, buffer?: Buffer) => void): Promise<void>;
38
+ /** Reserves a local port and returns the SRTP parameters HomeKit needs. */
39
+ prepareStream(request: any, callback: (error?: Error | null, response?: any) => void): Promise<void>;
40
+ handleStreamRequest(request: any, callback: (error?: Error | null) => void): void;
41
+ private startStream;
42
+ private stopStream;
43
+ /** Kills every stream, for plugin shutdown. */
44
+ stopAll(): void;
45
+ }
46
+ /** Asks the OS for a free UDP port by binding port 0 and reading it back. */
47
+ export declare function reserveUdpPort(): Promise<number>;
48
+ //# sourceMappingURL=StreamingDelegate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingDelegate.d.ts","sourceRoot":"","sources":["../src/StreamingDelegate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAWD;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAK1B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IATxB,OAAO,CAAC,QAAQ,CAAmC;IACnD,UAAU,EAAE,GAAG,CAAA;gBAGI,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,aAAa,EACxB,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,OAAO;IAGjC;;;;;;OAMG;IACG,qBAAqB,CACzB,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAC1C,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,GACxD,OAAO,CAAC,IAAI,CAAC;IAyBhB,2EAA2E;IACrE,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B1G,mBAAmB,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAoBjF,OAAO,CAAC,WAAW;IA2DnB,OAAO,CAAC,UAAU;IAWlB,+CAA+C;IAC/C,OAAO,IAAI,IAAI;CAGhB;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAShD"}
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamingDelegate = void 0;
4
+ exports.reserveUdpPort = reserveUdpPort;
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
+ const node_child_process_1 = require("node:child_process");
7
+ const node_dgram_1 = require("node:dgram");
8
+ const args_js_1 = require("./ffmpeg/args.js");
9
+ /**
10
+ * Bridges one camera to HomeKit's streaming protocol.
11
+ *
12
+ * HomeKit negotiates in two steps: `prepareStream` reserves ports and exchanges
13
+ * SRTP keys, then `handleStreamRequest` starts, reconfigures or stops the flow.
14
+ * ffmpeg is only spawned on start, so a client that negotiates and walks away
15
+ * costs nothing.
16
+ */
17
+ class StreamingDelegate {
18
+ hap;
19
+ camera;
20
+ ffmpegPath;
21
+ snapshots;
22
+ log;
23
+ debug;
24
+ sessions = new Map();
25
+ controller;
26
+ constructor(hap, camera, ffmpegPath, snapshots, log, debug) {
27
+ this.hap = hap;
28
+ this.camera = camera;
29
+ this.ffmpegPath = ffmpegPath;
30
+ this.snapshots = snapshots;
31
+ this.log = log;
32
+ this.debug = debug;
33
+ }
34
+ /**
35
+ * HomeKit's snapshot request.
36
+ *
37
+ * Never rejects when a previous image exists: a stale frame beats the broken
38
+ * tile HomeKit shows on an error, and a camera that is slow right now is
39
+ * usually fine a moment later.
40
+ */
41
+ async handleSnapshotRequest(request, callback) {
42
+ const args = (0, args_js_1.snapshotArgs)(this.camera, { width: request.width, height: request.height });
43
+ if (this.debug)
44
+ this.log.debug(`snapshot: ${(0, args_js_1.describeCommand)(this.ffmpegPath, args)}`);
45
+ try {
46
+ const image = await this.snapshots.get(this.camera.name, args, this.camera.snapshotCacheSeconds, this.camera.snapshotTimeoutMs);
47
+ callback(null, image);
48
+ }
49
+ catch (err) {
50
+ const message = (0, args_js_1.redact)(err instanceof Error ? err.message : String(err));
51
+ const stale = this.snapshots.lastKnown(this.camera.name);
52
+ if (stale) {
53
+ this.log.warn(`${this.camera.name}: snapshot failed (${message}), serving the last known frame`);
54
+ callback(null, stale);
55
+ return;
56
+ }
57
+ this.log.warn(`${this.camera.name}: snapshot failed (${message})`);
58
+ callback(new Error(message));
59
+ }
60
+ }
61
+ /** Reserves a local port and returns the SRTP parameters HomeKit needs. */
62
+ async prepareStream(request, callback) {
63
+ try {
64
+ const localPort = await reserveUdpPort();
65
+ const videoSsrc = this.hap.CameraController.generateSynchronisationSource();
66
+ this.sessions.set(request.sessionID, {
67
+ targetAddress: request.targetAddress,
68
+ videoPort: request.video.port,
69
+ videoSsrc,
70
+ videoSrtp: Buffer.concat([request.video.srtp_key, request.video.srtp_salt]).toString('base64'),
71
+ localPort,
72
+ });
73
+ callback(null, {
74
+ video: {
75
+ port: localPort,
76
+ ssrc: videoSsrc,
77
+ srtp_key: request.video.srtp_key,
78
+ srtp_salt: request.video.srtp_salt,
79
+ },
80
+ });
81
+ }
82
+ catch (err) {
83
+ callback(err instanceof Error ? err : new Error(String(err)));
84
+ }
85
+ }
86
+ handleStreamRequest(request, callback) {
87
+ switch (request.type) {
88
+ case 'start':
89
+ this.startStream(request, callback);
90
+ return;
91
+ case 'reconfigure':
92
+ // Nothing to do: the stream is copied, so bitrate hints do not change
93
+ // what ffmpeg is producing. Answering rather than ignoring keeps
94
+ // HomeKit from treating the session as dead.
95
+ callback();
96
+ return;
97
+ case 'stop':
98
+ this.stopStream(request.sessionID);
99
+ callback();
100
+ return;
101
+ default:
102
+ callback();
103
+ }
104
+ }
105
+ startStream(request, callback) {
106
+ const session = this.sessions.get(request.sessionID);
107
+ if (!session) {
108
+ callback(new Error('No prepared session for this stream request'));
109
+ return;
110
+ }
111
+ const args = (0, args_js_1.streamArgs)(this.camera, {
112
+ width: request.video.width,
113
+ height: request.video.height,
114
+ fps: request.video.fps,
115
+ bitrateKbps: request.video.max_bit_rate,
116
+ targetAddress: session.targetAddress,
117
+ videoPort: session.videoPort,
118
+ videoSsrc: session.videoSsrc,
119
+ videoSrtp: session.videoSrtp,
120
+ videoPayloadType: request.video.pt,
121
+ videoMtu: request.video.mtu ?? 1316,
122
+ });
123
+ if (this.debug)
124
+ this.log.debug(`stream: ${(0, args_js_1.describeCommand)(this.ffmpegPath, args)}`);
125
+ const child = (0, node_child_process_1.spawn)(this.ffmpegPath, args, { stdio: ['ignore', 'ignore', 'pipe'] });
126
+ session.process = child;
127
+ let started = false;
128
+ const done = (err) => {
129
+ if (started)
130
+ return;
131
+ started = true;
132
+ callback(err ?? null);
133
+ };
134
+ child.stderr?.on('data', (chunk) => {
135
+ // Redacted before it reaches the log: ffmpeg echoes the URL it was given,
136
+ // credentials included, in its own error output.
137
+ const text = (0, args_js_1.redact)(chunk.toString().trim());
138
+ if (text)
139
+ this.log.debug(`${this.camera.name}: ${text}`);
140
+ });
141
+ child.on('error', (err) => {
142
+ this.log.error(`${this.camera.name}: failed to start ffmpeg: ${(0, args_js_1.redact)(err.message)}`);
143
+ done(err);
144
+ });
145
+ child.on('close', (code) => {
146
+ this.sessions.delete(request.sessionID);
147
+ // Code 255 is ffmpeg's own exit on SIGKILL, which is how a stop is
148
+ // implemented here, so it is not worth reporting as a failure.
149
+ if (code !== 0 && code !== 255 && code !== null) {
150
+ this.log.warn(`${this.camera.name}: stream ended unexpectedly (ffmpeg exit ${code})`);
151
+ }
152
+ done();
153
+ });
154
+ // ffmpeg does not announce readiness, and waiting for first output would
155
+ // delay the HomeKit tile. Answering now is what the protocol expects.
156
+ done();
157
+ }
158
+ stopStream(sessionID) {
159
+ const session = this.sessions.get(sessionID);
160
+ if (!session)
161
+ return;
162
+ try {
163
+ session.process?.kill('SIGKILL');
164
+ }
165
+ catch {
166
+ /* already gone */
167
+ }
168
+ this.sessions.delete(sessionID);
169
+ }
170
+ /** Kills every stream, for plugin shutdown. */
171
+ stopAll() {
172
+ for (const id of [...this.sessions.keys()])
173
+ this.stopStream(id);
174
+ }
175
+ }
176
+ exports.StreamingDelegate = StreamingDelegate;
177
+ /** Asks the OS for a free UDP port by binding port 0 and reading it back. */
178
+ function reserveUdpPort() {
179
+ return new Promise((resolve, reject) => {
180
+ const socket = (0, node_dgram_1.createSocket)('udp4');
181
+ socket.once('error', reject);
182
+ socket.bind(0, () => {
183
+ const { port } = socket.address();
184
+ socket.close(() => resolve(port));
185
+ });
186
+ });
187
+ }
188
+ //# sourceMappingURL=StreamingDelegate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingDelegate.js","sourceRoot":"","sources":["../src/StreamingDelegate.ts"],"names":[],"mappings":";;;AA2MA,wCASC;AApND,uDAAuD;AACvD,2DAA6D;AAC7D,2CAAyC;AACzC,8CAAoF;AAoBpF;;;;;;;GAOG;AACH,MAAa,iBAAiB;IAKT;IACA;IACA;IACA;IACA;IACA;IATX,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAA;IACnD,UAAU,CAAK;IAEf,YACmB,GAAQ,EACR,MAAoB,EACpB,UAAkB,EAClB,SAAwB,EACxB,GAAmB,EACnB,KAAc;QALd,QAAG,GAAH,GAAG,CAAK;QACR,WAAM,GAAN,MAAM,CAAc;QACpB,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAe;QACxB,QAAG,GAAH,GAAG,CAAgB;QACnB,UAAK,GAAL,KAAK,CAAS;IAC9B,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,qBAAqB,CACzB,OAA0C,EAC1C,QAAyD;QAEzD,MAAM,IAAI,GAAG,IAAA,sBAAY,EAAC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QACxF,IAAI,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,IAAA,yBAAe,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;QAErF,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CACpC,IAAI,CAAC,MAAM,CAAC,IAAI,EAChB,IAAI,EACJ,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAC9B,CAAA;YACD,QAAQ,CAAC,IAAI,E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