@camstack/addon-go2rtc 0.1.14 → 0.1.15
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/dist/go2rtc.addon.js +26 -60
- package/dist/go2rtc.addon.js.map +1 -1
- package/dist/go2rtc.addon.mjs +408 -5
- package/dist/go2rtc.addon.mjs.map +1 -1
- package/dist/index.js +6 -449
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-QV2FOMZN.mjs +0 -422
- package/dist/chunk-QV2FOMZN.mjs.map +0 -1
- package/dist/go2rtc.addon-D9qkXBV6.d.mts +0 -62
- package/dist/go2rtc.addon-D9qkXBV6.d.ts +0 -62
- package/dist/go2rtc.addon.d.mts +0 -2
- package/dist/go2rtc.addon.d.ts +0 -2
- package/dist/index.d.mts +0 -22
- package/dist/index.d.ts +0 -22
package/dist/go2rtc.addon.mjs
CHANGED
|
@@ -1,7 +1,410 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
4
|
+
import { errMsg, BaseAddon, streamingEngineCapability, restreamerCapability, webrtcCapability } from "@camstack/types";
|
|
5
|
+
class Go2rtcEngine {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.baseUrl = `http://127.0.0.1:${config.apiPort}`;
|
|
9
|
+
}
|
|
10
|
+
baseUrl;
|
|
11
|
+
streams = /* @__PURE__ */ new Map();
|
|
12
|
+
async initialize(_config) {
|
|
13
|
+
try {
|
|
14
|
+
const res = await fetch(`${this.baseUrl}/api/streams`);
|
|
15
|
+
if (!res.ok) {
|
|
16
|
+
throw new Error(`go2rtc API returned ${res.status}`);
|
|
17
|
+
}
|
|
18
|
+
} catch (err) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Failed to reach go2rtc at ${this.baseUrl}: ${errMsg(err)}`,
|
|
21
|
+
{ cause: err }
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async shutdown() {
|
|
26
|
+
this.streams.clear();
|
|
27
|
+
}
|
|
28
|
+
async registerStream(streamId, source) {
|
|
29
|
+
const url = `${this.baseUrl}/api/streams?src=${encodeURIComponent(streamId)}&url=${encodeURIComponent(source.url)}`;
|
|
30
|
+
const res = await fetch(url, { method: "PUT" });
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
throw new Error(`go2rtc registerStream failed: ${res.status}`);
|
|
33
|
+
}
|
|
34
|
+
this.streams.set(streamId, source);
|
|
35
|
+
}
|
|
36
|
+
async unregisterStream(streamId) {
|
|
37
|
+
const url = `${this.baseUrl}/api/streams?src=${encodeURIComponent(streamId)}`;
|
|
38
|
+
const res = await fetch(url, { method: "DELETE" });
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
throw new Error(`go2rtc unregisterStream failed: ${res.status}`);
|
|
41
|
+
}
|
|
42
|
+
this.streams.delete(streamId);
|
|
43
|
+
}
|
|
44
|
+
getStreamUrl(streamId, format) {
|
|
45
|
+
const encoded = encodeURIComponent(streamId);
|
|
46
|
+
switch (format) {
|
|
47
|
+
case "webrtc":
|
|
48
|
+
return `${this.baseUrl}/api/webrtc?src=${encoded}`;
|
|
49
|
+
case "hls":
|
|
50
|
+
return `${this.baseUrl}/api/stream.m3u8?src=${encoded}`;
|
|
51
|
+
case "mjpeg":
|
|
52
|
+
return `${this.baseUrl}/api/frame.jpeg?src=${encoded}`;
|
|
53
|
+
case "rtsp":
|
|
54
|
+
return `rtsp://127.0.0.1:${this.config.rtspPort}/${streamId}`;
|
|
55
|
+
default:
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async proxyWhepOffer(streamId, sdpOffer) {
|
|
60
|
+
const url = `${this.baseUrl}/api/webrtc?src=${encodeURIComponent(streamId)}`;
|
|
61
|
+
const res = await fetch(url, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "Content-Type": "application/sdp" },
|
|
64
|
+
body: sdpOffer
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
throw new Error(`go2rtc WHEP failed: ${res.status}`);
|
|
68
|
+
}
|
|
69
|
+
return res.text();
|
|
70
|
+
}
|
|
71
|
+
listStreams() {
|
|
72
|
+
return [...this.streams.entries()].map(([id, source]) => ({
|
|
73
|
+
streamId: id,
|
|
74
|
+
source,
|
|
75
|
+
formats: ["webrtc", "hls", "mjpeg", "rtsp"]
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
getStreamStatus(streamId) {
|
|
79
|
+
if (!this.streams.has(streamId)) return null;
|
|
80
|
+
return { active: true, viewers: 0 };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function generateGo2rtcConfig(config) {
|
|
84
|
+
const yaml = `
|
|
85
|
+
api:
|
|
86
|
+
listen: ":${config.apiPort}"
|
|
87
|
+
|
|
88
|
+
rtsp:
|
|
89
|
+
listen: ":${config.rtspPort}"
|
|
90
|
+
|
|
91
|
+
webrtc:
|
|
92
|
+
listen: ":${config.webrtcPort}"
|
|
93
|
+
ice_servers: []
|
|
94
|
+
|
|
95
|
+
streams: {}
|
|
96
|
+
`;
|
|
97
|
+
return yaml.trim();
|
|
98
|
+
}
|
|
99
|
+
const GO2RTC_VERSION = "1.9.14";
|
|
100
|
+
const BASE_URL = `https://github.com/AlexxIT/go2rtc/releases/download/v${GO2RTC_VERSION}`;
|
|
101
|
+
function getGo2rtcDownloadUrl() {
|
|
102
|
+
const os = process.platform;
|
|
103
|
+
const rawArch = process.arch;
|
|
104
|
+
let arch;
|
|
105
|
+
switch (rawArch) {
|
|
106
|
+
case "x64":
|
|
107
|
+
arch = "amd64";
|
|
108
|
+
break;
|
|
109
|
+
case "arm64":
|
|
110
|
+
arch = "arm64";
|
|
111
|
+
break;
|
|
112
|
+
case "arm":
|
|
113
|
+
arch = "arm";
|
|
114
|
+
break;
|
|
115
|
+
case "ia32":
|
|
116
|
+
arch = "i386";
|
|
117
|
+
break;
|
|
118
|
+
default:
|
|
119
|
+
throw new Error(`Unsupported architecture: ${rawArch}`);
|
|
120
|
+
}
|
|
121
|
+
switch (os) {
|
|
122
|
+
case "darwin":
|
|
123
|
+
return { url: `${BASE_URL}/go2rtc_mac_${arch}.zip`, isArchive: true, archiveFormat: "zip" };
|
|
124
|
+
case "linux":
|
|
125
|
+
return { url: `${BASE_URL}/go2rtc_linux_${arch}`, isArchive: false };
|
|
126
|
+
case "win32":
|
|
127
|
+
return { url: `${BASE_URL}/go2rtc_win_${arch}.zip`, isArchive: true, archiveFormat: "zip" };
|
|
128
|
+
default:
|
|
129
|
+
throw new Error(`Unsupported platform: ${os}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function ensureGo2rtcBinary(deps) {
|
|
133
|
+
const { url, isArchive, archiveFormat } = getGo2rtcDownloadUrl();
|
|
134
|
+
return deps.ensureBinary({
|
|
135
|
+
name: "go2rtc",
|
|
136
|
+
downloadUrl: url,
|
|
137
|
+
isArchive,
|
|
138
|
+
archiveFormat
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
class Go2rtcAddon extends BaseAddon {
|
|
142
|
+
/** IRestreamer identity */
|
|
143
|
+
id = "go2rtc";
|
|
144
|
+
name = "go2rtc Restreamer";
|
|
145
|
+
engine = null;
|
|
146
|
+
childProc = null;
|
|
147
|
+
registeredDevices = /* @__PURE__ */ new Map();
|
|
148
|
+
constructor() {
|
|
149
|
+
super({ apiPort: 1984, rtspPort: 8554, webrtcPort: 8555, binaryPath: "go2rtc" });
|
|
150
|
+
}
|
|
151
|
+
async onInitialize() {
|
|
152
|
+
const dataPath = await this.ctx.api.storage.resolve.query({ location: "data", relativePath: "" }).catch(() => "camstack-data");
|
|
153
|
+
const resolvedBinaryPath = await ensureGo2rtcBinary(this.ctx.deps);
|
|
154
|
+
const processConfig = {
|
|
155
|
+
apiPort: this.config.apiPort,
|
|
156
|
+
rtspPort: this.config.rtspPort,
|
|
157
|
+
webrtcPort: this.config.webrtcPort,
|
|
158
|
+
binaryPath: resolvedBinaryPath
|
|
159
|
+
};
|
|
160
|
+
const configYaml = generateGo2rtcConfig(processConfig);
|
|
161
|
+
const configPath = join(dataPath, "go2rtc.yaml");
|
|
162
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
163
|
+
writeFileSync(configPath, configYaml);
|
|
164
|
+
this.childProc = spawn(processConfig.binaryPath, ["-config", configPath], {
|
|
165
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
166
|
+
});
|
|
167
|
+
this.childProc.on("exit", (code, signal) => {
|
|
168
|
+
this.ctx.logger.warn("go2rtc process exited", { meta: { code, signal } });
|
|
169
|
+
});
|
|
170
|
+
this.childProc.stderr?.on("data", (data) => {
|
|
171
|
+
const msg = data.toString().trim();
|
|
172
|
+
if (msg) this.ctx.logger.debug("go2rtc stderr", { meta: { line: msg } });
|
|
173
|
+
});
|
|
174
|
+
this.childProc.stdout?.on("data", (data) => {
|
|
175
|
+
const msg = data.toString().trim();
|
|
176
|
+
if (msg) this.ctx.logger.debug("go2rtc stdout", { meta: { line: msg } });
|
|
177
|
+
});
|
|
178
|
+
const apiUrl = `http://127.0.0.1:${processConfig.apiPort}/api/streams`;
|
|
179
|
+
await this.waitForReady(apiUrl, 1e4);
|
|
180
|
+
const engineConfig = {
|
|
181
|
+
apiPort: processConfig.apiPort,
|
|
182
|
+
rtspPort: processConfig.rtspPort,
|
|
183
|
+
webrtcPort: processConfig.webrtcPort,
|
|
184
|
+
binaryPath: processConfig.binaryPath
|
|
185
|
+
};
|
|
186
|
+
this.engine = new Go2rtcEngine(engineConfig);
|
|
187
|
+
await this.engine.initialize();
|
|
188
|
+
this.ctx.logger.info("go2rtc started", {
|
|
189
|
+
meta: { pid: this.childProc.pid, apiPort: processConfig.apiPort }
|
|
190
|
+
});
|
|
191
|
+
return [
|
|
192
|
+
{ capability: streamingEngineCapability, provider: this.engine },
|
|
193
|
+
{ capability: restreamerCapability, provider: this },
|
|
194
|
+
{ capability: webrtcCapability, provider: this }
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
async onShutdown() {
|
|
198
|
+
await this.engine?.shutdown();
|
|
199
|
+
this.engine = null;
|
|
200
|
+
this.registeredDevices.clear();
|
|
201
|
+
if (this.childProc) {
|
|
202
|
+
this.childProc.kill("SIGTERM");
|
|
203
|
+
this.childProc = null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
getEngine() {
|
|
207
|
+
if (!this.engine) throw new Error("go2rtc not initialized");
|
|
208
|
+
return this.engine;
|
|
209
|
+
}
|
|
210
|
+
// --- IRestreamer implementation ---
|
|
211
|
+
async registerDevice(deviceId, streams) {
|
|
212
|
+
if (!this.engine) {
|
|
213
|
+
throw new Error("go2rtc not initialized — cannot register device");
|
|
214
|
+
}
|
|
215
|
+
const streamIds = [];
|
|
216
|
+
for (const stream of streams) {
|
|
217
|
+
streamIds.push(stream.streamId);
|
|
218
|
+
if (stream.sourceUrl) {
|
|
219
|
+
await this.engine.registerStream(stream.streamId, {
|
|
220
|
+
url: `ffmpeg:${stream.sourceUrl}#video=${stream.codec}`,
|
|
221
|
+
protocol: "rtsp",
|
|
222
|
+
deviceId: `${deviceId}`,
|
|
223
|
+
providerId: "broker"
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.registeredDevices.set(deviceId, {
|
|
228
|
+
deviceId,
|
|
229
|
+
streams,
|
|
230
|
+
streamIds
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
pushPacket(_streamId, _packet) {
|
|
234
|
+
}
|
|
235
|
+
async unregisterDevice(deviceId) {
|
|
236
|
+
const registration = this.registeredDevices.get(deviceId);
|
|
237
|
+
if (!registration) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (this.engine) {
|
|
241
|
+
for (const streamId of registration.streamIds) {
|
|
242
|
+
try {
|
|
243
|
+
await this.engine.unregisterStream(streamId);
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
this.registeredDevices.delete(deviceId);
|
|
249
|
+
}
|
|
250
|
+
getExposedResources(deviceId) {
|
|
251
|
+
const registration = this.registeredDevices.get(deviceId);
|
|
252
|
+
if (!registration || !this.engine) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const resources = [];
|
|
256
|
+
for (const streamId of registration.streamIds) {
|
|
257
|
+
const webrtcUrl = this.engine.getStreamUrl(streamId, "webrtc");
|
|
258
|
+
if (webrtcUrl) {
|
|
259
|
+
resources.push({ type: "url", format: "webrtc", value: webrtcUrl });
|
|
260
|
+
}
|
|
261
|
+
const hlsUrl = this.engine.getStreamUrl(streamId, "hls");
|
|
262
|
+
if (hlsUrl) {
|
|
263
|
+
resources.push({ type: "url", format: "hls", value: hlsUrl });
|
|
264
|
+
}
|
|
265
|
+
const mjpegUrl = this.engine.getStreamUrl(streamId, "mjpeg");
|
|
266
|
+
if (mjpegUrl) {
|
|
267
|
+
resources.push({ type: "url", format: "mjpeg", value: mjpegUrl });
|
|
268
|
+
}
|
|
269
|
+
const rtspUrl = this.engine.getStreamUrl(streamId, "rtsp");
|
|
270
|
+
if (rtspUrl) {
|
|
271
|
+
resources.push({ type: "url", format: "rtsp", value: rtspUrl });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return resources;
|
|
275
|
+
}
|
|
276
|
+
async proxyWhepOffer(streamId, sdpOffer) {
|
|
277
|
+
if (!this.engine) {
|
|
278
|
+
throw new Error("go2rtc not initialized — cannot proxy WHEP");
|
|
279
|
+
}
|
|
280
|
+
return this.engine.proxyWhepOffer(streamId, sdpOffer);
|
|
281
|
+
}
|
|
282
|
+
// --- End IRestreamer ---
|
|
283
|
+
// --- IWebRtcProvider implementation ---
|
|
284
|
+
async handleOffer(streamId, sdpOffer) {
|
|
285
|
+
if (!this.engine) {
|
|
286
|
+
throw new Error("go2rtc not initialized — cannot handle WebRTC offer");
|
|
287
|
+
}
|
|
288
|
+
return this.engine.proxyWhepOffer(streamId, sdpOffer);
|
|
289
|
+
}
|
|
290
|
+
supportsStream(streamId) {
|
|
291
|
+
const prefix = streamId.split("/")[0];
|
|
292
|
+
if (!prefix) return false;
|
|
293
|
+
const deviceId = Number(prefix);
|
|
294
|
+
return Number.isFinite(deviceId) && this.registeredDevices.has(deviceId);
|
|
295
|
+
}
|
|
296
|
+
async registerStream(streamId, _codec) {
|
|
297
|
+
const prefix = streamId.split("/")[0];
|
|
298
|
+
if (!prefix) return;
|
|
299
|
+
const deviceId = Number(prefix);
|
|
300
|
+
if (!Number.isFinite(deviceId)) return;
|
|
301
|
+
if (!this.registeredDevices.has(deviceId)) {
|
|
302
|
+
this.registeredDevices.set(deviceId, {
|
|
303
|
+
deviceId,
|
|
304
|
+
streams: [{ streamId, label: streamId, codec: _codec, type: "video" }],
|
|
305
|
+
streamIds: [streamId]
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async unregisterStream(streamId) {
|
|
310
|
+
if (!this.engine) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
await this.engine.unregisterStream(streamId);
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* go2rtc does not implement adaptive bitrate — it proxies the source
|
|
320
|
+
* stream at its native resolution/bitrate. Use addon-webrtc-adaptive
|
|
321
|
+
* for clients that need dynamic quality adjustment.
|
|
322
|
+
*/
|
|
323
|
+
hasAdaptiveBitrate(_streamId) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
// --- End IWebRtcProvider ---
|
|
327
|
+
/** Exposed for testing */
|
|
328
|
+
async waitForReady(url, timeoutMs) {
|
|
329
|
+
const start = Date.now();
|
|
330
|
+
while (Date.now() - start < timeoutMs) {
|
|
331
|
+
try {
|
|
332
|
+
const res = await fetch(url);
|
|
333
|
+
if (res.ok) return;
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
337
|
+
}
|
|
338
|
+
throw new Error(`go2rtc did not become ready within ${timeoutMs}ms`);
|
|
339
|
+
}
|
|
340
|
+
globalSettingsSchema() {
|
|
341
|
+
return this.schema({
|
|
342
|
+
sections: [
|
|
343
|
+
{
|
|
344
|
+
id: "go2rtc-info",
|
|
345
|
+
title: "go2rtc",
|
|
346
|
+
fields: [
|
|
347
|
+
{
|
|
348
|
+
type: "info",
|
|
349
|
+
key: "binary-info",
|
|
350
|
+
label: "Binary",
|
|
351
|
+
content: "go2rtc is automatically downloaded on first boot.",
|
|
352
|
+
variant: "info"
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
id: "go2rtc-ports",
|
|
358
|
+
title: "Network Ports",
|
|
359
|
+
description: "Port configuration. Changes require a restart.",
|
|
360
|
+
columns: 3,
|
|
361
|
+
fields: [
|
|
362
|
+
{
|
|
363
|
+
type: "info",
|
|
364
|
+
key: "restart-note",
|
|
365
|
+
label: "Restart required",
|
|
366
|
+
content: "Port changes require restarting go2rtc.",
|
|
367
|
+
variant: "warning"
|
|
368
|
+
},
|
|
369
|
+
this.field({
|
|
370
|
+
type: "number",
|
|
371
|
+
key: "apiPort",
|
|
372
|
+
label: "API Port",
|
|
373
|
+
description: "go2rtc HTTP API",
|
|
374
|
+
min: 1024,
|
|
375
|
+
max: 65535,
|
|
376
|
+
step: 1,
|
|
377
|
+
default: 1984
|
|
378
|
+
}),
|
|
379
|
+
this.field({
|
|
380
|
+
type: "number",
|
|
381
|
+
key: "rtspPort",
|
|
382
|
+
label: "RTSP Port",
|
|
383
|
+
description: "RTSP restream output",
|
|
384
|
+
min: 1024,
|
|
385
|
+
max: 65535,
|
|
386
|
+
step: 1,
|
|
387
|
+
default: 8554
|
|
388
|
+
}),
|
|
389
|
+
this.field({
|
|
390
|
+
type: "number",
|
|
391
|
+
key: "webrtcPort",
|
|
392
|
+
label: "WebRTC Port",
|
|
393
|
+
description: "WebRTC UDP/TCP",
|
|
394
|
+
min: 1024,
|
|
395
|
+
max: 65535,
|
|
396
|
+
step: 1,
|
|
397
|
+
default: 8555
|
|
398
|
+
})
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
4
405
|
export {
|
|
5
|
-
|
|
406
|
+
Go2rtcEngine as G,
|
|
407
|
+
Go2rtcAddon,
|
|
408
|
+
generateGo2rtcConfig as g
|
|
6
409
|
};
|
|
7
|
-
//# sourceMappingURL=go2rtc.addon.mjs.map
|
|
410
|
+
//# sourceMappingURL=go2rtc.addon.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"go2rtc.addon.mjs","sources":["../src/go2rtc-engine.ts","../src/go2rtc-config-generator.ts","../src/go2rtc-downloader.ts","../src/go2rtc.addon.ts"],"sourcesContent":["import { errMsg } from '@camstack/types'\nimport type {\n IStreamingEngine,\n StreamFormat,\n StreamInfo,\n StreamingSource,\n StreamStatus,\n} from '@camstack/types'\n\nexport interface Go2rtcConfig {\n readonly apiPort: number\n readonly rtspPort: number\n readonly webrtcPort: number\n readonly binaryPath?: string\n}\n\nexport class Go2rtcEngine implements IStreamingEngine {\n private readonly baseUrl: string\n private readonly streams = new Map<string, StreamingSource>()\n\n constructor(private readonly config: Go2rtcConfig) {\n this.baseUrl = `http://127.0.0.1:${config.apiPort}`\n }\n\n async initialize(_config?: Record<string, unknown>): Promise<void> {\n try {\n const res = await fetch(`${this.baseUrl}/api/streams`)\n if (!res.ok) {\n throw new Error(`go2rtc API returned ${res.status}`)\n }\n } catch (err) {\n throw new Error(\n `Failed to reach go2rtc at ${this.baseUrl}: ${errMsg(err)}`,\n { cause: err },\n )\n }\n }\n\n async shutdown(): Promise<void> {\n this.streams.clear()\n }\n\n async registerStream(streamId: string, source: StreamingSource): Promise<void> {\n const url = `${this.baseUrl}/api/streams?src=${encodeURIComponent(streamId)}&url=${encodeURIComponent(source.url)}`\n const res = await fetch(url, { method: 'PUT' })\n if (!res.ok) {\n throw new Error(`go2rtc registerStream failed: ${res.status}`)\n }\n this.streams.set(streamId, source)\n }\n\n async unregisterStream(streamId: string): Promise<void> {\n const url = `${this.baseUrl}/api/streams?src=${encodeURIComponent(streamId)}`\n const res = await fetch(url, { method: 'DELETE' })\n if (!res.ok) {\n throw new Error(`go2rtc unregisterStream failed: ${res.status}`)\n }\n this.streams.delete(streamId)\n }\n\n getStreamUrl(streamId: string, format: StreamFormat): string | null {\n const encoded = encodeURIComponent(streamId)\n switch (format) {\n case 'webrtc':\n return `${this.baseUrl}/api/webrtc?src=${encoded}`\n case 'hls':\n return `${this.baseUrl}/api/stream.m3u8?src=${encoded}`\n case 'mjpeg':\n return `${this.baseUrl}/api/frame.jpeg?src=${encoded}`\n case 'rtsp':\n return `rtsp://127.0.0.1:${this.config.rtspPort}/${streamId}`\n default:\n return null\n }\n }\n\n async proxyWhepOffer(streamId: string, sdpOffer: string): Promise<string> {\n const url = `${this.baseUrl}/api/webrtc?src=${encodeURIComponent(streamId)}`\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/sdp' },\n body: sdpOffer,\n })\n if (!res.ok) {\n throw new Error(`go2rtc WHEP failed: ${res.status}`)\n }\n return res.text()\n }\n\n listStreams(): StreamInfo[] {\n return [...this.streams.entries()].map(([id, source]) => ({\n streamId: id,\n source,\n formats: ['webrtc', 'hls', 'mjpeg', 'rtsp'] as StreamFormat[],\n }))\n }\n\n getStreamStatus(streamId: string): StreamStatus | null {\n if (!this.streams.has(streamId)) return null\n return { active: true, viewers: 0 }\n }\n}\n","export interface Go2rtcGeneratedConfig {\n api: { listen: string }\n rtsp: { listen: string }\n webrtc: { listen: string }\n streams: Record<string, string[]>\n}\n\nexport function generateGo2rtcConfig(config: {\n apiPort: number\n rtspPort: number\n webrtcPort: number\n}): string {\n const yaml = `\napi:\n listen: \":${config.apiPort}\"\n\nrtsp:\n listen: \":${config.rtspPort}\"\n\nwebrtc:\n listen: \":${config.webrtcPort}\"\n ice_servers: []\n\nstreams: {}\n`\n return yaml.trim()\n}\n","/**\n * Auto-download go2rtc binary for the current platform.\n * Uses IAddonDepsManager (ctx.deps) for binary management.\n */\nimport type { IAddonDepsManager } from '@camstack/types'\n\nconst GO2RTC_VERSION = '1.9.14'\nconst BASE_URL = `https://github.com/AlexxIT/go2rtc/releases/download/v${GO2RTC_VERSION}`\n\nfunction getGo2rtcDownloadUrl(): { url: string; isArchive: boolean; archiveFormat?: 'zip' } {\n const os = process.platform\n const rawArch = process.arch\n\n let arch: string\n switch (rawArch) {\n case 'x64': arch = 'amd64'; break\n case 'arm64': arch = 'arm64'; break\n case 'arm': arch = 'arm'; break\n case 'ia32': arch = 'i386'; break\n default: throw new Error(`Unsupported architecture: ${rawArch}`)\n }\n\n switch (os) {\n case 'darwin':\n return { url: `${BASE_URL}/go2rtc_mac_${arch}.zip`, isArchive: true, archiveFormat: 'zip' }\n case 'linux':\n return { url: `${BASE_URL}/go2rtc_linux_${arch}`, isArchive: false }\n case 'win32':\n return { url: `${BASE_URL}/go2rtc_win_${arch}.zip`, isArchive: true, archiveFormat: 'zip' }\n default:\n throw new Error(`Unsupported platform: ${os}`)\n }\n}\n\n/**\n * Ensure go2rtc binary is available.\n * Returns the absolute path to the binary.\n */\nexport async function ensureGo2rtcBinary(deps: IAddonDepsManager): Promise<string> {\n const { url, isArchive, archiveFormat } = getGo2rtcDownloadUrl()\n\n return deps.ensureBinary({\n name: 'go2rtc',\n downloadUrl: url,\n isArchive,\n archiveFormat,\n })\n}\n","import { spawn, type ChildProcess } from 'node:child_process'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { join, dirname } from 'node:path'\nimport type {\n ProviderRegistration,\n IRestreamer,\n RegisteredStream,\n RestreamerExposedResource as ExposedResource,\n EncodedPacket,\n} from '@camstack/types'\nimport { BaseAddon, streamingEngineCapability, restreamerCapability, webrtcCapability } from '@camstack/types'\nimport type { IWebRtcProvider } from '@camstack/types'\nimport { Go2rtcEngine } from './go2rtc-engine'\nimport type { Go2rtcConfig } from './go2rtc-engine'\nimport { generateGo2rtcConfig } from './go2rtc-config-generator'\nimport { ensureGo2rtcBinary } from './go2rtc-downloader'\n\nexport interface Go2rtcProcessConfig {\n readonly apiPort: number\n readonly rtspPort: number\n readonly webrtcPort: number\n readonly binaryPath: string\n}\n\ninterface DeviceRegistration {\n readonly deviceId: number\n readonly streams: readonly RegisteredStream[]\n /** The original source URL registered with go2rtc (for cleanup) */\n readonly streamIds: readonly string[]\n}\n\nexport class Go2rtcAddon extends BaseAddon<Go2rtcProcessConfig> implements IRestreamer, IWebRtcProvider {\n /** IRestreamer identity */\n readonly id = 'go2rtc'\n readonly name = 'go2rtc Restreamer'\n\n private engine: Go2rtcEngine | null = null\n private childProc: ChildProcess | null = null\n private readonly registeredDevices = new Map<number, DeviceRegistration>()\n\n constructor() {\n super({ apiPort: 1984, rtspPort: 8554, webrtcPort: 8555, binaryPath: 'go2rtc' })\n }\n\n protected async onInitialize(): Promise<ProviderRegistration[]> {\n const dataPath = await this.ctx.api.storage.resolve.query({ location: 'data', relativePath: '' })\n .catch(() => 'camstack-data')\n\n const resolvedBinaryPath = await ensureGo2rtcBinary(this.ctx.deps)\n\n const processConfig: Go2rtcProcessConfig = {\n apiPort: this.config.apiPort,\n rtspPort: this.config.rtspPort,\n webrtcPort: this.config.webrtcPort,\n binaryPath: resolvedBinaryPath,\n }\n\n // Generate config file\n const configYaml = generateGo2rtcConfig(processConfig)\n const configPath = join(dataPath, 'go2rtc.yaml')\n mkdirSync(dirname(configPath), { recursive: true })\n writeFileSync(configPath, configYaml)\n\n // Start go2rtc as a child process\n this.childProc = spawn(processConfig.binaryPath, ['-config', configPath], {\n stdio: ['pipe', 'pipe', 'pipe'],\n })\n\n this.childProc.on('exit', (code, signal) => {\n this.ctx.logger.warn('go2rtc process exited', { meta: { code, signal } })\n })\n\n this.childProc.stderr?.on('data', (data: Buffer) => {\n const msg = data.toString().trim()\n if (msg) this.ctx.logger.debug('go2rtc stderr', { meta: { line: msg } })\n })\n\n this.childProc.stdout?.on('data', (data: Buffer) => {\n const msg = data.toString().trim()\n if (msg) this.ctx.logger.debug('go2rtc stdout', { meta: { line: msg } })\n })\n\n // Wait for API to be ready\n const apiUrl = `http://127.0.0.1:${processConfig.apiPort}/api/streams`\n await this.waitForReady(apiUrl, 10_000)\n\n // Create engine\n const engineConfig: Go2rtcConfig = {\n apiPort: processConfig.apiPort,\n rtspPort: processConfig.rtspPort,\n webrtcPort: processConfig.webrtcPort,\n binaryPath: processConfig.binaryPath,\n }\n this.engine = new Go2rtcEngine(engineConfig)\n await this.engine.initialize()\n\n this.ctx.logger.info('go2rtc started', {\n meta: { pid: this.childProc.pid, apiPort: processConfig.apiPort },\n })\n\n return [\n { capability: streamingEngineCapability, provider: this.engine },\n { capability: restreamerCapability, provider: this },\n { capability: webrtcCapability, provider: this },\n ]\n }\n\n protected async onShutdown(): Promise<void> {\n await this.engine?.shutdown()\n this.engine = null\n this.registeredDevices.clear()\n\n if (this.childProc) {\n this.childProc.kill('SIGTERM')\n this.childProc = null\n }\n }\n\n getEngine(): Go2rtcEngine {\n if (!this.engine) throw new Error('go2rtc not initialized')\n return this.engine\n }\n\n // --- IRestreamer implementation ---\n\n async registerDevice(deviceId: number, streams: readonly RegisteredStream[]): Promise<void> {\n if (!this.engine) {\n throw new Error('go2rtc not initialized — cannot register device')\n }\n\n const streamIds: string[] = []\n\n for (const stream of streams) {\n streamIds.push(stream.streamId)\n\n // Register the stream with go2rtc using the broker's local TCP URL.\n // The broker is the sole reader from the camera; go2rtc consumes the\n // broker's TCP pipe instead of connecting to the camera directly.\n if (stream.sourceUrl) {\n await this.engine.registerStream(stream.streamId, {\n url: `ffmpeg:${stream.sourceUrl}#video=${stream.codec}`,\n protocol: 'rtsp',\n deviceId: `${deviceId}`,\n providerId: 'broker',\n })\n }\n }\n\n this.registeredDevices.set(deviceId, {\n deviceId,\n streams,\n streamIds,\n })\n }\n\n pushPacket(_streamId: string, _packet: EncodedPacket): void {\n // Packet push from the broker is a no-op — go2rtc reads directly from\n // the broker's local TCP pipe server instead.\n }\n\n async unregisterDevice(deviceId: number): Promise<void> {\n const registration = this.registeredDevices.get(deviceId)\n if (!registration) {\n return\n }\n\n if (this.engine) {\n for (const streamId of registration.streamIds) {\n try {\n await this.engine.unregisterStream(streamId)\n } catch {\n // Best-effort cleanup\n }\n }\n }\n\n this.registeredDevices.delete(deviceId)\n }\n\n getExposedResources(deviceId: number): readonly ExposedResource[] {\n const registration = this.registeredDevices.get(deviceId)\n if (!registration || !this.engine) {\n return []\n }\n\n const resources: ExposedResource[] = []\n\n for (const streamId of registration.streamIds) {\n const webrtcUrl = this.engine.getStreamUrl(streamId, 'webrtc')\n if (webrtcUrl) {\n resources.push({ type: 'url', format: 'webrtc', value: webrtcUrl })\n }\n\n const hlsUrl = this.engine.getStreamUrl(streamId, 'hls')\n if (hlsUrl) {\n resources.push({ type: 'url', format: 'hls', value: hlsUrl })\n }\n\n const mjpegUrl = this.engine.getStreamUrl(streamId, 'mjpeg')\n if (mjpegUrl) {\n resources.push({ type: 'url', format: 'mjpeg', value: mjpegUrl })\n }\n\n const rtspUrl = this.engine.getStreamUrl(streamId, 'rtsp')\n if (rtspUrl) {\n resources.push({ type: 'url', format: 'rtsp', value: rtspUrl })\n }\n }\n\n return resources\n }\n\n async proxyWhepOffer(streamId: string, sdpOffer: string): Promise<string> {\n if (!this.engine) {\n throw new Error('go2rtc not initialized — cannot proxy WHEP')\n }\n return this.engine.proxyWhepOffer(streamId, sdpOffer)\n }\n\n // --- End IRestreamer ---\n\n // --- IWebRtcProvider implementation ---\n\n async handleOffer(streamId: string, sdpOffer: string): Promise<string> {\n if (!this.engine) {\n throw new Error('go2rtc not initialized — cannot handle WebRTC offer')\n }\n return this.engine.proxyWhepOffer(streamId, sdpOffer)\n }\n\n supportsStream(streamId: string): boolean {\n const prefix = streamId.split('/')[0]\n if (!prefix) return false\n const deviceId = Number(prefix)\n return Number.isFinite(deviceId) && this.registeredDevices.has(deviceId)\n }\n\n async registerStream(streamId: string, _codec: string): Promise<void> {\n // Stream registration is handled via registerDevice (IRestreamer).\n // This is a no-op since go2rtc manages streams through its own API.\n const prefix = streamId.split('/')[0]\n if (!prefix) return\n const deviceId = Number(prefix)\n if (!Number.isFinite(deviceId)) return\n if (!this.registeredDevices.has(deviceId)) {\n this.registeredDevices.set(deviceId, {\n deviceId,\n streams: [{ streamId, label: streamId, codec: _codec, type: 'video' }],\n streamIds: [streamId],\n })\n }\n }\n\n async unregisterStream(streamId: string): Promise<void> {\n if (!this.engine) {\n return\n }\n try {\n await this.engine.unregisterStream(streamId)\n } catch {\n // Best-effort cleanup\n }\n }\n\n /**\n * go2rtc does not implement adaptive bitrate — it proxies the source\n * stream at its native resolution/bitrate. Use addon-webrtc-adaptive\n * for clients that need dynamic quality adjustment.\n */\n hasAdaptiveBitrate(_streamId: string): boolean {\n return false\n }\n\n // --- End IWebRtcProvider ---\n\n /** Exposed for testing */\n async waitForReady(url: string, timeoutMs: number): Promise<void> {\n const start = Date.now()\n while (Date.now() - start < timeoutMs) {\n try {\n const res = await fetch(url)\n if (res.ok) return\n } catch {\n // Not ready yet\n }\n await new Promise((r) => setTimeout(r, 500))\n }\n throw new Error(`go2rtc did not become ready within ${timeoutMs}ms`)\n }\n\n protected globalSettingsSchema() {\n return this.schema({\n sections: [\n {\n id: 'go2rtc-info',\n title: 'go2rtc',\n fields: [\n {\n type: 'info' as const,\n key: 'binary-info',\n label: 'Binary',\n content: 'go2rtc is automatically downloaded on first boot.',\n variant: 'info' as const,\n },\n ],\n },\n {\n id: 'go2rtc-ports',\n title: 'Network Ports',\n description: 'Port configuration. Changes require a restart.',\n columns: 3,\n fields: [\n {\n type: 'info' as const,\n key: 'restart-note',\n label: 'Restart required',\n content: 'Port changes require restarting go2rtc.',\n variant: 'warning' as const,\n },\n this.field({\n type: 'number', key: 'apiPort', label: 'API Port',\n description: 'go2rtc HTTP API', min: 1024, max: 65535, step: 1, default: 1984,\n }),\n this.field({\n type: 'number', key: 'rtspPort', label: 'RTSP Port',\n description: 'RTSP restream output', min: 1024, max: 65535, step: 1, default: 8554,\n }),\n this.field({\n type: 'number', key: 'webrtcPort', label: 'WebRTC Port',\n description: 'WebRTC UDP/TCP', min: 1024, max: 65535, step: 1, default: 8555,\n }),\n ],\n },\n ],\n })\n }\n\n}\n"],"names":[],"mappings":";;;;AAgBO,MAAM,aAAyC;AAAA,EAIpD,YAA6B,QAAsB;AAAtB,SAAA,SAAA;AAC3B,SAAK,UAAU,oBAAoB,OAAO,OAAO;AAAA,EACnD;AAAA,EALiB;AAAA,EACA,8BAAc,IAAA;AAAA,EAM/B,MAAM,WAAW,SAAkD;AACjE,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,cAAc;AACrD,UAAI,CAAC,IAAI,IAAI;AACX,cAAM,IAAI,MAAM,uBAAuB,IAAI,MAAM,EAAE;AAAA,MACrD;AAAA,IACF,SAAS,KAAK;AACZ,YAAM,IAAI;AAAA,QACR,6BAA6B,KAAK,OAAO,KAAK,OAAO,GAAG,CAAC;AAAA,QACzD,EAAE,OAAO,IAAA;AAAA,MAAI;AAAA,IAEjB;AAAA,EACF;AAAA,EAEA,MAAM,WAA0B;AAC9B,SAAK,QAAQ,MAAA;AAAA,EACf;AAAA,EAEA,MAAM,eAAe,UAAkB,QAAwC;AAC7E,UAAM,MAAM,GAAG,KAAK,OAAO,oBAAoB,mBAAmB,QAAQ,CAAC,QAAQ,mBAAmB,OAAO,GAAG,CAAC;AACjH,UAAM,MAAM,MAAM,MAAM,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