@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/config.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CameraSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
url: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
username: z.ZodOptional<z.ZodString>;
|
|
6
|
+
password: z.ZodOptional<z.ZodString>;
|
|
7
|
+
transport: z.ZodDefault<z.ZodEnum<["tcp", "udp"]>>;
|
|
8
|
+
snapshotUrl: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
9
|
+
manufacturer: z.ZodOptional<z.ZodString>;
|
|
10
|
+
model: z.ZodOptional<z.ZodString>;
|
|
11
|
+
serialNumber: z.ZodOptional<z.ZodString>;
|
|
12
|
+
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
maxHeight: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
maxFps: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
maxBitrateKbps: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
maxStreams: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
audio: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
transcode: z.ZodDefault<z.ZodBoolean>;
|
|
19
|
+
snapshotCacheSeconds: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
snapshotTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
url: string;
|
|
23
|
+
name: string;
|
|
24
|
+
transport: "tcp" | "udp";
|
|
25
|
+
maxWidth: number;
|
|
26
|
+
maxHeight: number;
|
|
27
|
+
maxFps: number;
|
|
28
|
+
maxBitrateKbps: number;
|
|
29
|
+
maxStreams: number;
|
|
30
|
+
audio: boolean;
|
|
31
|
+
transcode: boolean;
|
|
32
|
+
snapshotCacheSeconds: number;
|
|
33
|
+
snapshotTimeoutMs: number;
|
|
34
|
+
username?: string | undefined;
|
|
35
|
+
password?: string | undefined;
|
|
36
|
+
snapshotUrl?: string | undefined;
|
|
37
|
+
manufacturer?: string | undefined;
|
|
38
|
+
model?: string | undefined;
|
|
39
|
+
serialNumber?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
url: string;
|
|
42
|
+
name: string;
|
|
43
|
+
username?: string | undefined;
|
|
44
|
+
password?: string | undefined;
|
|
45
|
+
transport?: "tcp" | "udp" | undefined;
|
|
46
|
+
snapshotUrl?: string | undefined;
|
|
47
|
+
manufacturer?: string | undefined;
|
|
48
|
+
model?: string | undefined;
|
|
49
|
+
serialNumber?: string | undefined;
|
|
50
|
+
maxWidth?: number | undefined;
|
|
51
|
+
maxHeight?: number | undefined;
|
|
52
|
+
maxFps?: number | undefined;
|
|
53
|
+
maxBitrateKbps?: number | undefined;
|
|
54
|
+
maxStreams?: number | undefined;
|
|
55
|
+
audio?: boolean | undefined;
|
|
56
|
+
transcode?: boolean | undefined;
|
|
57
|
+
snapshotCacheSeconds?: number | undefined;
|
|
58
|
+
snapshotTimeoutMs?: number | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
export declare const PlatformSchema: z.ZodObject<{
|
|
61
|
+
cameras: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
url: z.ZodEffects<z.ZodString, string, string>;
|
|
64
|
+
username: z.ZodOptional<z.ZodString>;
|
|
65
|
+
password: z.ZodOptional<z.ZodString>;
|
|
66
|
+
transport: z.ZodDefault<z.ZodEnum<["tcp", "udp"]>>;
|
|
67
|
+
snapshotUrl: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
68
|
+
manufacturer: z.ZodOptional<z.ZodString>;
|
|
69
|
+
model: z.ZodOptional<z.ZodString>;
|
|
70
|
+
serialNumber: z.ZodOptional<z.ZodString>;
|
|
71
|
+
maxWidth: z.ZodDefault<z.ZodNumber>;
|
|
72
|
+
maxHeight: z.ZodDefault<z.ZodNumber>;
|
|
73
|
+
maxFps: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
maxBitrateKbps: z.ZodDefault<z.ZodNumber>;
|
|
75
|
+
maxStreams: z.ZodDefault<z.ZodNumber>;
|
|
76
|
+
audio: z.ZodDefault<z.ZodBoolean>;
|
|
77
|
+
transcode: z.ZodDefault<z.ZodBoolean>;
|
|
78
|
+
snapshotCacheSeconds: z.ZodDefault<z.ZodNumber>;
|
|
79
|
+
snapshotTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
80
|
+
}, "strip", z.ZodTypeAny, {
|
|
81
|
+
url: string;
|
|
82
|
+
name: string;
|
|
83
|
+
transport: "tcp" | "udp";
|
|
84
|
+
maxWidth: number;
|
|
85
|
+
maxHeight: number;
|
|
86
|
+
maxFps: number;
|
|
87
|
+
maxBitrateKbps: number;
|
|
88
|
+
maxStreams: number;
|
|
89
|
+
audio: boolean;
|
|
90
|
+
transcode: boolean;
|
|
91
|
+
snapshotCacheSeconds: number;
|
|
92
|
+
snapshotTimeoutMs: number;
|
|
93
|
+
username?: string | undefined;
|
|
94
|
+
password?: string | undefined;
|
|
95
|
+
snapshotUrl?: string | undefined;
|
|
96
|
+
manufacturer?: string | undefined;
|
|
97
|
+
model?: string | undefined;
|
|
98
|
+
serialNumber?: string | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
url: string;
|
|
101
|
+
name: string;
|
|
102
|
+
username?: string | undefined;
|
|
103
|
+
password?: string | undefined;
|
|
104
|
+
transport?: "tcp" | "udp" | undefined;
|
|
105
|
+
snapshotUrl?: string | undefined;
|
|
106
|
+
manufacturer?: string | undefined;
|
|
107
|
+
model?: string | undefined;
|
|
108
|
+
serialNumber?: string | undefined;
|
|
109
|
+
maxWidth?: number | undefined;
|
|
110
|
+
maxHeight?: number | undefined;
|
|
111
|
+
maxFps?: number | undefined;
|
|
112
|
+
maxBitrateKbps?: number | undefined;
|
|
113
|
+
maxStreams?: number | undefined;
|
|
114
|
+
audio?: boolean | undefined;
|
|
115
|
+
transcode?: boolean | undefined;
|
|
116
|
+
snapshotCacheSeconds?: number | undefined;
|
|
117
|
+
snapshotTimeoutMs?: number | undefined;
|
|
118
|
+
}>, "many">>;
|
|
119
|
+
ffmpegPath: z.ZodOptional<z.ZodString>;
|
|
120
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
121
|
+
}, "strip", z.ZodTypeAny, {
|
|
122
|
+
cameras: {
|
|
123
|
+
url: string;
|
|
124
|
+
name: string;
|
|
125
|
+
transport: "tcp" | "udp";
|
|
126
|
+
maxWidth: number;
|
|
127
|
+
maxHeight: number;
|
|
128
|
+
maxFps: number;
|
|
129
|
+
maxBitrateKbps: number;
|
|
130
|
+
maxStreams: number;
|
|
131
|
+
audio: boolean;
|
|
132
|
+
transcode: boolean;
|
|
133
|
+
snapshotCacheSeconds: number;
|
|
134
|
+
snapshotTimeoutMs: number;
|
|
135
|
+
username?: string | undefined;
|
|
136
|
+
password?: string | undefined;
|
|
137
|
+
snapshotUrl?: string | undefined;
|
|
138
|
+
manufacturer?: string | undefined;
|
|
139
|
+
model?: string | undefined;
|
|
140
|
+
serialNumber?: string | undefined;
|
|
141
|
+
}[];
|
|
142
|
+
debug: boolean;
|
|
143
|
+
ffmpegPath?: string | undefined;
|
|
144
|
+
}, {
|
|
145
|
+
cameras?: {
|
|
146
|
+
url: string;
|
|
147
|
+
name: string;
|
|
148
|
+
username?: string | undefined;
|
|
149
|
+
password?: string | undefined;
|
|
150
|
+
transport?: "tcp" | "udp" | undefined;
|
|
151
|
+
snapshotUrl?: string | undefined;
|
|
152
|
+
manufacturer?: string | undefined;
|
|
153
|
+
model?: string | undefined;
|
|
154
|
+
serialNumber?: string | undefined;
|
|
155
|
+
maxWidth?: number | undefined;
|
|
156
|
+
maxHeight?: number | undefined;
|
|
157
|
+
maxFps?: number | undefined;
|
|
158
|
+
maxBitrateKbps?: number | undefined;
|
|
159
|
+
maxStreams?: number | undefined;
|
|
160
|
+
audio?: boolean | undefined;
|
|
161
|
+
transcode?: boolean | undefined;
|
|
162
|
+
snapshotCacheSeconds?: number | undefined;
|
|
163
|
+
snapshotTimeoutMs?: number | undefined;
|
|
164
|
+
}[] | undefined;
|
|
165
|
+
ffmpegPath?: string | undefined;
|
|
166
|
+
debug?: boolean | undefined;
|
|
167
|
+
}>;
|
|
168
|
+
export type ParsedPlatformConfig = z.infer<typeof PlatformSchema>;
|
|
169
|
+
export interface ConfigProblem {
|
|
170
|
+
path: string;
|
|
171
|
+
message: string;
|
|
172
|
+
}
|
|
173
|
+
/** Parses config, returning either the value or every problem found. */
|
|
174
|
+
export declare function parseConfig(raw: unknown): {
|
|
175
|
+
ok: true;
|
|
176
|
+
value: ParsedPlatformConfig;
|
|
177
|
+
} | {
|
|
178
|
+
ok: false;
|
|
179
|
+
problems: ConfigProblem[];
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAuBvB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BvB,CAAA;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIzB,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAEjE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wEAAwE;AACxE,wBAAgB,WAAW,CACzB,GAAG,EAAE,OAAO,GACX;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,aAAa,EAAE,CAAA;CAAE,CAqBtF"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformSchema = exports.CameraSchema = void 0;
|
|
4
|
+
exports.parseConfig = parseConfig;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
/**
|
|
7
|
+
* Config validation.
|
|
8
|
+
*
|
|
9
|
+
* Every default here is a decision rather than a placeholder, and the comments
|
|
10
|
+
* say which. A camera plugin that starts with a half-valid configuration wastes
|
|
11
|
+
* an evening of someone's time: the stream simply never appears in HomeKit and
|
|
12
|
+
* nothing says why. So this refuses to start instead, naming each problem.
|
|
13
|
+
*/
|
|
14
|
+
const RTSP_URL = /^rtsps?:\/\/[^\s]+$/i;
|
|
15
|
+
const urlWithoutCredentials = zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(RTSP_URL, 'must be an rtsp:// or rtsps:// URL')
|
|
18
|
+
// Credentials in the URL are the thing this plugin exists to stop. They end
|
|
19
|
+
// up in logs, in screenshots and in pasted config, and they cannot be
|
|
20
|
+
// redacted reliably once they are part of a string someone else composed.
|
|
21
|
+
.refine((u) => !/^rtsps?:\/\/[^/@]*@/i.test(u), {
|
|
22
|
+
message: 'must not embed credentials: put them in the username and password fields',
|
|
23
|
+
});
|
|
24
|
+
exports.CameraSchema = zod_1.z.object({
|
|
25
|
+
name: zod_1.z.string().min(1),
|
|
26
|
+
url: urlWithoutCredentials,
|
|
27
|
+
username: zod_1.z.string().optional(),
|
|
28
|
+
password: zod_1.z.string().optional(),
|
|
29
|
+
transport: zod_1.z.enum(['tcp', 'udp']).default('tcp'),
|
|
30
|
+
snapshotUrl: urlWithoutCredentials.optional(),
|
|
31
|
+
manufacturer: zod_1.z.string().optional(),
|
|
32
|
+
model: zod_1.z.string().optional(),
|
|
33
|
+
serialNumber: zod_1.z.string().optional(),
|
|
34
|
+
maxWidth: zod_1.z.number().int().positive().default(1920),
|
|
35
|
+
maxHeight: zod_1.z.number().int().positive().default(1080),
|
|
36
|
+
// 15 rather than 30: HomeKit tiles are small, most cameras deliver 15 happily,
|
|
37
|
+
// and halving the frame rate halves the work on a low-powered bridge host.
|
|
38
|
+
maxFps: zod_1.z.number().int().positive().max(60).default(15),
|
|
39
|
+
maxBitrateKbps: zod_1.z.number().int().positive().default(2000),
|
|
40
|
+
// Two viewers covers a phone and an Apple TV. Each stream is another ffmpeg
|
|
41
|
+
// process, and on a Pi the fourth one is what makes the first three stutter.
|
|
42
|
+
maxStreams: zod_1.z.number().int().positive().max(8).default(2),
|
|
43
|
+
audio: zod_1.z.boolean().default(false),
|
|
44
|
+
transcode: zod_1.z.boolean().default(false),
|
|
45
|
+
snapshotCacheSeconds: zod_1.z.number().nonnegative().default(10),
|
|
46
|
+
// HomeKit gives up on a slow snapshot itself and shows a stale tile. Ten
|
|
47
|
+
// seconds is already generous; the plugin this replaces was observed taking
|
|
48
|
+
// 133 seconds on a camera that had stopped answering, holding the request
|
|
49
|
+
// open the whole time.
|
|
50
|
+
snapshotTimeoutMs: zod_1.z.number().int().positive().default(10_000),
|
|
51
|
+
});
|
|
52
|
+
exports.PlatformSchema = zod_1.z.object({
|
|
53
|
+
cameras: zod_1.z.array(exports.CameraSchema).default([]),
|
|
54
|
+
ffmpegPath: zod_1.z.string().optional(),
|
|
55
|
+
debug: zod_1.z.boolean().default(false),
|
|
56
|
+
});
|
|
57
|
+
/** Parses config, returning either the value or every problem found. */
|
|
58
|
+
function parseConfig(raw) {
|
|
59
|
+
const result = exports.PlatformSchema.safeParse(raw);
|
|
60
|
+
if (result.success) {
|
|
61
|
+
const duplicates = findDuplicateNames(result.data.cameras.map((c) => c.name));
|
|
62
|
+
if (duplicates.length > 0) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
problems: duplicates.map((name) => ({
|
|
66
|
+
path: 'cameras',
|
|
67
|
+
// Names become HomeKit accessory names, and two accessories sharing
|
|
68
|
+
// one is how a camera silently replaces another.
|
|
69
|
+
message: `duplicate camera name "${name}": each camera needs its own`,
|
|
70
|
+
})),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return { ok: true, value: result.data };
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
problems: result.error.issues.map((i) => ({ path: i.path.join('.') || '(root)', message: i.message })),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function findDuplicateNames(names) {
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
const duplicates = new Set();
|
|
83
|
+
for (const name of names) {
|
|
84
|
+
const key = name.trim().toLowerCase();
|
|
85
|
+
if (seen.has(key))
|
|
86
|
+
duplicates.add(name);
|
|
87
|
+
seen.add(key);
|
|
88
|
+
}
|
|
89
|
+
return [...duplicates];
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAqEA,kCAuBC;AA5FD,6BAAuB;AAEvB;;;;;;;GAOG;AAEH,MAAM,QAAQ,GAAG,sBAAsB,CAAA;AAEvC,MAAM,qBAAqB,GAAG,OAAC;KAC5B,MAAM,EAAE;KACR,KAAK,CAAC,QAAQ,EAAE,oCAAoC,CAAC;IACtD,4EAA4E;IAC5E,sEAAsE;IACtE,0EAA0E;KACzE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;IAC9C,OAAO,EAAE,0EAA0E;CACpF,CAAC,CAAA;AAES,QAAA,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,GAAG,EAAE,qBAAqB;IAC1B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CA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KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACvG,CAAA;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAe;IACzC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAA;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;QACrC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACvC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,CAAC;IACD,OAAO,CAAC,GAAG,UAAU,CAAC,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CameraConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds ffmpeg argument lists, and keeps credentials out of anything printed.
|
|
4
|
+
*
|
|
5
|
+
* Arguments are an array, never a string. A string would have to be split
|
|
6
|
+
* somewhere, and a camera path containing a space (or a password containing
|
|
7
|
+
* one) is then a command that runs with the wrong arguments.
|
|
8
|
+
*/
|
|
9
|
+
/** Puts the credentials into the URL at the last possible moment. */
|
|
10
|
+
export declare function authenticatedUrl(camera: Pick<CameraConfig, 'url' | 'username' | 'password'>, url?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Replaces the userinfo of any RTSP URL in a string with `***`.
|
|
13
|
+
*
|
|
14
|
+
* Applied to every line before it reaches a log or an error message. ffmpeg
|
|
15
|
+
* prints the URL it was given in its own diagnostics, so redacting only our
|
|
16
|
+
* own log lines would still leak the password through ffmpeg's stderr, which
|
|
17
|
+
* is exactly how camera passwords end up in a pasted support log.
|
|
18
|
+
*/
|
|
19
|
+
export declare function redact(text: string): string;
|
|
20
|
+
export interface SnapshotArgsOptions {
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
}
|
|
24
|
+
/** ffmpeg arguments for a single still frame. */
|
|
25
|
+
export declare function snapshotArgs(camera: CameraConfig, options?: SnapshotArgsOptions): string[];
|
|
26
|
+
export interface StreamArgsOptions {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
fps: number;
|
|
30
|
+
bitrateKbps: number;
|
|
31
|
+
/** Destination for the SRTP video stream. */
|
|
32
|
+
targetAddress: string;
|
|
33
|
+
videoPort: number;
|
|
34
|
+
videoSsrc: number;
|
|
35
|
+
videoSrtp: string;
|
|
36
|
+
videoPayloadType: number;
|
|
37
|
+
videoMtu: number;
|
|
38
|
+
}
|
|
39
|
+
/** ffmpeg arguments for a live SRTP stream to a HomeKit client. */
|
|
40
|
+
export declare function streamArgs(camera: CameraConfig, options: StreamArgsOptions): string[];
|
|
41
|
+
/** A command line safe to log: arguments joined, credentials replaced. */
|
|
42
|
+
export declare function describeCommand(binary: string, args: string[]): string;
|
|
43
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/ffmpeg/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C;;;;;;GAMG;AAEH,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAQlH;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,iDAAiD;AACjD,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,EAAE,CA8B9F;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,EAAE,CA+DrF;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAEtE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authenticatedUrl = authenticatedUrl;
|
|
4
|
+
exports.redact = redact;
|
|
5
|
+
exports.snapshotArgs = snapshotArgs;
|
|
6
|
+
exports.streamArgs = streamArgs;
|
|
7
|
+
exports.describeCommand = describeCommand;
|
|
8
|
+
/**
|
|
9
|
+
* Builds ffmpeg argument lists, and keeps credentials out of anything printed.
|
|
10
|
+
*
|
|
11
|
+
* Arguments are an array, never a string. A string would have to be split
|
|
12
|
+
* somewhere, and a camera path containing a space (or a password containing
|
|
13
|
+
* one) is then a command that runs with the wrong arguments.
|
|
14
|
+
*/
|
|
15
|
+
/** Puts the credentials into the URL at the last possible moment. */
|
|
16
|
+
function authenticatedUrl(camera, url) {
|
|
17
|
+
const target = url ?? camera.url;
|
|
18
|
+
if (!camera.username)
|
|
19
|
+
return target;
|
|
20
|
+
const parsed = new URL(target);
|
|
21
|
+
parsed.username = encodeURIComponent(camera.username);
|
|
22
|
+
if (camera.password)
|
|
23
|
+
parsed.password = encodeURIComponent(camera.password);
|
|
24
|
+
return parsed.toString();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Replaces the userinfo of any RTSP URL in a string with `***`.
|
|
28
|
+
*
|
|
29
|
+
* Applied to every line before it reaches a log or an error message. ffmpeg
|
|
30
|
+
* prints the URL it was given in its own diagnostics, so redacting only our
|
|
31
|
+
* own log lines would still leak the password through ffmpeg's stderr, which
|
|
32
|
+
* is exactly how camera passwords end up in a pasted support log.
|
|
33
|
+
*/
|
|
34
|
+
function redact(text) {
|
|
35
|
+
return text.replace(/(rtsps?:\/\/)[^@\s/]+@/gi, '$1***@');
|
|
36
|
+
}
|
|
37
|
+
/** ffmpeg arguments for a single still frame. */
|
|
38
|
+
function snapshotArgs(camera, options = {}) {
|
|
39
|
+
const source = authenticatedUrl(camera, camera.snapshotUrl ?? camera.url);
|
|
40
|
+
const args = [
|
|
41
|
+
'-hide_banner',
|
|
42
|
+
'-loglevel',
|
|
43
|
+
'error',
|
|
44
|
+
'-rtsp_transport',
|
|
45
|
+
camera.transport,
|
|
46
|
+
// Analyse less before deciding it understands the stream. The default
|
|
47
|
+
// spends up to five seconds on a stream whose format we already know, and
|
|
48
|
+
// a snapshot is on the path of someone opening the Home app.
|
|
49
|
+
'-analyzeduration',
|
|
50
|
+
'1000000',
|
|
51
|
+
'-probesize',
|
|
52
|
+
'1000000',
|
|
53
|
+
'-i',
|
|
54
|
+
source,
|
|
55
|
+
'-frames:v',
|
|
56
|
+
'1',
|
|
57
|
+
];
|
|
58
|
+
const width = options.width ?? camera.maxWidth;
|
|
59
|
+
const height = options.height ?? camera.maxHeight;
|
|
60
|
+
// Preserve aspect ratio and never upscale: HomeKit asks for the tile size,
|
|
61
|
+
// which is often larger than a camera's substream, and stretching a 640px
|
|
62
|
+
// substream to 1920 costs time and looks worse than the original.
|
|
63
|
+
args.push('-vf', `scale='min(${width},iw)':'min(${height},ih)':force_original_aspect_ratio=decrease`);
|
|
64
|
+
args.push('-f', 'image2', '-');
|
|
65
|
+
return args;
|
|
66
|
+
}
|
|
67
|
+
/** ffmpeg arguments for a live SRTP stream to a HomeKit client. */
|
|
68
|
+
function streamArgs(camera, options) {
|
|
69
|
+
const source = authenticatedUrl(camera);
|
|
70
|
+
const args = [
|
|
71
|
+
'-hide_banner',
|
|
72
|
+
'-loglevel',
|
|
73
|
+
'error',
|
|
74
|
+
'-rtsp_transport',
|
|
75
|
+
camera.transport,
|
|
76
|
+
'-i',
|
|
77
|
+
source,
|
|
78
|
+
'-an',
|
|
79
|
+
'-sn',
|
|
80
|
+
'-dn',
|
|
81
|
+
];
|
|
82
|
+
if (camera.transcode) {
|
|
83
|
+
// Only when a camera emits something HomeKit will not take. `veryfast` and
|
|
84
|
+
// `zerolatency` because a live view that is correct but three seconds
|
|
85
|
+
// behind is worse than one that is slightly softer.
|
|
86
|
+
args.push('-codec:v', 'libx264', '-preset', 'veryfast', '-tune', 'zerolatency', '-pix_fmt', 'yuv420p', '-profile:v', 'high', '-r', String(options.fps), '-vf', `scale='min(${options.width},iw)':'min(${options.height},ih)':force_original_aspect_ratio=decrease`, '-b:v', `${options.bitrateKbps}k`, '-bufsize', `${options.bitrateKbps * 2}k`, '-maxrate', `${options.bitrateKbps}k`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Copy: no re-encoding, which is what makes several cameras viable at once
|
|
90
|
+
// on a Raspberry Pi.
|
|
91
|
+
args.push('-codec:v', 'copy');
|
|
92
|
+
}
|
|
93
|
+
args.push('-payload_type', String(options.videoPayloadType), '-ssrc', String(options.videoSsrc), '-f', 'rtp', '-srtp_out_suite', 'AES_CM_128_HMAC_SHA1_80', '-srtp_out_params', options.videoSrtp, `srtp://${options.targetAddress}:${options.videoPort}?rtcpport=${options.videoPort}&pkt_size=${options.videoMtu}`);
|
|
94
|
+
return args;
|
|
95
|
+
}
|
|
96
|
+
/** A command line safe to log: arguments joined, credentials replaced. */
|
|
97
|
+
function describeCommand(binary, args) {
|
|
98
|
+
return redact([binary, ...args].join(' '));
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/ffmpeg/args.ts"],"names":[],"mappings":";;AAWA,4CAQC;AAUD,wBAEC;AAQD,oCA8BC;AAiBD,gCA+DC;AAGD,0CAEC;AAxJD;;;;;;GAMG;AAEH,qEAAqE;AACrE,SAAgB,gBAAgB,CAAC,MAA2D,EAAE,GAAY;IACxG,MAAM,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAA;IAChC,IAAI,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,MAAM,CAAA;IAEnC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;IAC9B,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACrD,IAAI,MAAM,CAAC,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC1E,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;AAC1B,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,MAAM,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAA;AAC3D,CAAC;AAOD,iDAAiD;AACjD,SAAgB,YAAY,CAAC,MAAoB,EAAE,UAA+B,EAAE;IAClF,MAAM,MAAM,GAAG,g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M,CAAC,OAAO,CAAC,GAAG,CAAC,EACnB,KAAK,EACL,cAAc,OAAO,CAAC,KAAK,cAAc,OAAO,CAAC,MAAM,4CAA4C,EACnG,MAAM,EACN,GAAG,OAAO,CAAC,WAAW,GAAG,EACzB,UAAU,EACV,GAAG,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAC7B,UAAU,EACV,GAAG,OAAO,CAAC,WAAW,GAAG,CAC1B,CAAA;IACH,CAAC;SAAM,CAAC;QACN,2EAA2E;QAC3E,qBAAqB;QACrB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,CAAC,IAAI,CACP,eAAe,EACf,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAChC,OAAO,EACP,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EACzB,IAAI,EACJ,KAAK,EACL,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,EAClB,OAAO,CAAC,SAAS,EACjB,UAAU,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,SAAS,aAAa,OAAO,CAAC,SAAS,aAAa,OAAO,CAAC,QAAQ,EAAE,CAClH,CAAA;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,0EAA0E;AAC1E,SAAgB,eAAe,CAAC,MAAc,EAAE,IAAc;IAC5D,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface FfmpegResolution {
|
|
2
|
+
path: string;
|
|
3
|
+
/** Where it came from, so a support question can be answered in one line. */
|
|
4
|
+
source: 'config' | 'bundled' | 'path';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Finds an ffmpeg to use, in order of how much the operator meant it.
|
|
8
|
+
*
|
|
9
|
+
* 1. `ffmpegPath` in config, because an explicit choice wins over any guess.
|
|
10
|
+
* 2. The binary from `ffmpeg-for-homebridge`, if installed. It is an
|
|
11
|
+
* **optional** dependency deliberately: it downloads a static build at
|
|
12
|
+
* install time and has no artefact for every platform, so depending on it
|
|
13
|
+
* outright would make this plugin uninstallable on the hosts it lacks,
|
|
14
|
+
* including musl-based ones. Missing it is survivable, a failed install is
|
|
15
|
+
* not.
|
|
16
|
+
* 3. `ffmpeg` on PATH.
|
|
17
|
+
*
|
|
18
|
+
* Returns null rather than throwing so the caller can report every camera's
|
|
19
|
+
* situation at once instead of dying on the first.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveFfmpeg(configuredPath?: string): FfmpegResolution | null;
|
|
22
|
+
export declare function findOnPath(binary: string): string | null;
|
|
23
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/ffmpeg/resolve.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAY9E;AAcD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOxD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveFfmpeg = resolveFfmpeg;
|
|
4
|
+
exports.findOnPath = findOnPath;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
/**
|
|
8
|
+
* Finds an ffmpeg to use, in order of how much the operator meant it.
|
|
9
|
+
*
|
|
10
|
+
* 1. `ffmpegPath` in config, because an explicit choice wins over any guess.
|
|
11
|
+
* 2. The binary from `ffmpeg-for-homebridge`, if installed. It is an
|
|
12
|
+
* **optional** dependency deliberately: it downloads a static build at
|
|
13
|
+
* install time and has no artefact for every platform, so depending on it
|
|
14
|
+
* outright would make this plugin uninstallable on the hosts it lacks,
|
|
15
|
+
* including musl-based ones. Missing it is survivable, a failed install is
|
|
16
|
+
* not.
|
|
17
|
+
* 3. `ffmpeg` on PATH.
|
|
18
|
+
*
|
|
19
|
+
* Returns null rather than throwing so the caller can report every camera's
|
|
20
|
+
* situation at once instead of dying on the first.
|
|
21
|
+
*/
|
|
22
|
+
function resolveFfmpeg(configuredPath) {
|
|
23
|
+
if (configuredPath && isExecutable(configuredPath)) {
|
|
24
|
+
return { path: configuredPath, source: 'config' };
|
|
25
|
+
}
|
|
26
|
+
const bundled = resolveBundled();
|
|
27
|
+
if (bundled)
|
|
28
|
+
return { path: bundled, source: 'bundled' };
|
|
29
|
+
const onPath = findOnPath('ffmpeg');
|
|
30
|
+
if (onPath)
|
|
31
|
+
return { path: onPath, source: 'path' };
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function resolveBundled() {
|
|
35
|
+
try {
|
|
36
|
+
// The package's main export is the path to the binary it downloaded.
|
|
37
|
+
const mod = require('ffmpeg-for-homebridge');
|
|
38
|
+
const candidate = typeof mod === 'string' ? mod : mod?.default;
|
|
39
|
+
if (candidate && isExecutable(candidate))
|
|
40
|
+
return candidate;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Not installed, which is an expected state for an optional dependency.
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function findOnPath(binary) {
|
|
48
|
+
const paths = (process.env.PATH ?? '').split(node_path_1.delimiter).filter(Boolean);
|
|
49
|
+
for (const dir of paths) {
|
|
50
|
+
const candidate = (0, node_path_1.join)(dir, binary);
|
|
51
|
+
if (isExecutable(candidate))
|
|
52
|
+
return candidate;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function isExecutable(path) {
|
|
57
|
+
try {
|
|
58
|
+
(0, node_fs_1.accessSync)(path, node_fs_1.constants.X_OK);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/ffmpeg/resolve.ts"],"names":[],"mappings":";;AAwBA,sCAYC;AAcD,gCAOC;AAzDD,qCAA+C;AAC/C,yCAA2C;AAQ3C;;;;;;;;;;;;;;GAcG;AACH,SAAgB,aAAa,CAAC,cAAuB;IACnD,IAAI,cAAc,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;IACnD,CAAC;IAED,MAAM,OAAO,GAAG,cAAc,EAAE,CAAA;IAChC,IAAI,OAAO;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;IAExD,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IACnC,IAAI,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;IAEnD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,qEAAqE;QACrE,MAAM,GAAG,GAAG,OAAO,CAAC,uBAAuB,CAAY,CAAA;QACvD,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAE,GAA4B,EAAE,OAAO,CAAA;QACxF,IAAI,SAAS,IAAI,YAAY,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAgB,UAAU,CAAC,MAAc;IACvC,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACvE,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACnC,IAAI,YAAY,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;IAC/C,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,IAAA,oBAAU,EAAC,IAAI,EAAE,mBAAS,CAAC,IAAI,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface PluginLogger {
|
|
2
|
+
debug(message: string, ...args: unknown[]): void;
|
|
3
|
+
info(message: string, ...args: unknown[]): void;
|
|
4
|
+
warn(message: string, ...args: unknown[]): void;
|
|
5
|
+
error(message: string, ...args: unknown[]): void;
|
|
6
|
+
}
|
|
7
|
+
interface PluginContext {
|
|
8
|
+
config: Record<string, unknown>;
|
|
9
|
+
log: PluginLogger;
|
|
10
|
+
reportTelemetry(deviceId: string, data: Record<string, unknown>): void;
|
|
11
|
+
registerDevice(device: {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
widgetType: string;
|
|
15
|
+
manufacturer?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
}): void;
|
|
18
|
+
registerControl(deviceId: string, controlId: string, handler: (value: unknown) => void | Promise<void>): void;
|
|
19
|
+
getHapBridge?(): {
|
|
20
|
+
hap: any;
|
|
21
|
+
bridge: any;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}
|
|
24
|
+
declare const plugin: {
|
|
25
|
+
manifest: {
|
|
26
|
+
name: string;
|
|
27
|
+
version: string;
|
|
28
|
+
description: string;
|
|
29
|
+
author: string;
|
|
30
|
+
};
|
|
31
|
+
setup(ctx: PluginContext): Promise<void>;
|
|
32
|
+
start(ctx: PluginContext): Promise<void>;
|
|
33
|
+
stop(ctx: PluginContext): Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
export default plugin;
|
|
36
|
+
export * from './config.js';
|
|
37
|
+
export * from './types.js';
|
|
38
|
+
export * from './ffmpeg/args.js';
|
|
39
|
+
export * from './ffmpeg/resolve.js';
|
|
40
|
+
export * from './resolutions.js';
|
|
41
|
+
export { SnapshotCache, FfmpegSnapshotRunner } from './SnapshotCache.js';
|
|
42
|
+
export { StreamingDelegate, reserveUdpPort } from './StreamingDelegate.js';
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,UAAU,YAAY;IACpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CACjD;AAED,UAAU,aAAa;IACrB,MAAM,EAAE,M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