iobroker.agent-dvr 0.8.1 → 0.9.1

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.
@@ -0,0 +1,651 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var recording_exports = {};
30
+ __export(recording_exports, {
31
+ MAX_MESSAGE_BYTES: () => MAX_MESSAGE_BYTES,
32
+ MB: () => MB,
33
+ TELEGRAM_MAX_BYTES: () => TELEGRAM_MAX_BYTES,
34
+ assertNoBinary: () => assertNoBinary,
35
+ cameraRecordingFiles: () => cameraRecordingFiles,
36
+ clampNumber: () => clampNumber,
37
+ containsBinary: () => containsBinary,
38
+ detectFfmpeg: () => detectFfmpeg,
39
+ downloadToBuffer: () => downloadToBuffer,
40
+ exceedsLimit: () => exceedsLimit,
41
+ extOf: () => extOf,
42
+ ffmpegCandidates: () => ffmpegCandidates,
43
+ ffmpegStatusText: () => ffmpegStatusText,
44
+ findCamera: () => findCamera,
45
+ fmtMb: () => fmtMb,
46
+ isHevcMkv: () => isHevcMkv,
47
+ isValidRecordingName: () => isValidRecordingName,
48
+ maxRecordingBytes: () => maxRecordingBytes,
49
+ mimeOf: () => mimeOf,
50
+ needsInitialFill: () => needsInitialFill,
51
+ parseFfmpegVersion: () => parseFfmpegVersion,
52
+ probeFfmpeg: () => probeFfmpeg,
53
+ recordingAbsPath: () => recordingAbsPath,
54
+ recordingFileName: () => recordingFileName,
55
+ recordingFinished: () => recordingFinished,
56
+ recordingSlots: () => recordingSlots,
57
+ recordingStoragePath: () => recordingStoragePath,
58
+ recordingUri: () => recordingUri,
59
+ recordingUrl: () => recordingUrl,
60
+ remuxArgs: () => remuxArgs,
61
+ remuxToMp4: () => remuxToMp4,
62
+ resolveOnPath: () => resolveOnPath,
63
+ runFfmpeg: () => runFfmpeg,
64
+ safeMessage: () => safeMessage,
65
+ sendFileStoragePath: () => sendFileStoragePath,
66
+ videoInfo: () => videoInfo
67
+ });
68
+ module.exports = __toCommonJS(recording_exports);
69
+ var import_node_child_process = require("node:child_process");
70
+ var fs = __toESM(require("node:fs"));
71
+ var http = __toESM(require("node:http"));
72
+ var path = __toESM(require("node:path"));
73
+ const TELEGRAM_MAX_BYTES = 50 * 1024 * 1024;
74
+ const MB = 1024 * 1024;
75
+ function clampNumber(raw, def, min, max) {
76
+ const n = typeof raw === "number" ? raw : parseFloat(typeof raw === "string" ? raw : "");
77
+ if (!Number.isFinite(n)) {
78
+ return def;
79
+ }
80
+ return Math.max(min, Math.min(max, Math.round(n)));
81
+ }
82
+ function recordingSlots(raw) {
83
+ return clampNumber(raw, 1, 1, 3);
84
+ }
85
+ function maxRecordingBytes(rawMb) {
86
+ return clampNumber(rawMb, 50, 1, 2e3) * MB;
87
+ }
88
+ function exceedsLimit(bytes, limit) {
89
+ return Number.isFinite(bytes) && bytes > 0 && bytes > limit;
90
+ }
91
+ function fmtMb(bytes) {
92
+ return `${(Math.round(bytes / MB * 10) / 10).toFixed(1)} MB`;
93
+ }
94
+ function recordingFileName(slot, ext) {
95
+ return `rec${slot}.${ext}`;
96
+ }
97
+ function recordingStoragePath(fid, slot, ext) {
98
+ return `${fid}/${recordingFileName(slot, ext)}`;
99
+ }
100
+ function sendFileStoragePath(fid, ext) {
101
+ return `${fid}/send.${ext}`;
102
+ }
103
+ function cameraRecordingFiles() {
104
+ const out = [];
105
+ for (const ext of ["mp4", "mkv"]) {
106
+ for (let i = 1; i <= 3; i++) {
107
+ out.push(`rec${i}.${ext}`);
108
+ }
109
+ out.push(`send.${ext}`);
110
+ }
111
+ return out;
112
+ }
113
+ function needsInitialFill(slot1Exists, name1, lastFn) {
114
+ if (!lastFn) {
115
+ return false;
116
+ }
117
+ return !slot1Exists || name1 !== lastFn;
118
+ }
119
+ function recordingUri(namespace, fid, slot, ext) {
120
+ return `iobfile://${namespace}/${recordingStoragePath(fid, slot, ext)}`;
121
+ }
122
+ function recordingAbsPath(dataDir, namespace, fid, slot, ext) {
123
+ return path.join(dataDir, "files", namespace, fid, recordingFileName(slot, ext));
124
+ }
125
+ function recordingUrl(webBase, namespace, fid, slot, ext) {
126
+ return webBase ? `${webBase}/${namespace}/recordings/${fid}/${recordingFileName(slot, ext)}` : "";
127
+ }
128
+ function extOf(fn) {
129
+ const m = /\.([A-Za-z0-9]+)$/.exec(fn || "");
130
+ return m ? m[1].toLowerCase() : "mkv";
131
+ }
132
+ function mimeOf(ext) {
133
+ return ext === "mp4" ? "video/mp4" : ext === "mkv" ? "video/x-matroska" : "application/octet-stream";
134
+ }
135
+ function isValidRecordingName(fn) {
136
+ return /^[\w.-]{1,200}\.(mkv|mp4)$/i.test(fn) && !fn.includes("..");
137
+ }
138
+ function ffmpegCandidates(configPath, platform) {
139
+ const out = [];
140
+ const add = (p) => {
141
+ const v = (p || "").trim();
142
+ if (v && !out.includes(v)) {
143
+ out.push(v);
144
+ }
145
+ };
146
+ add(configPath);
147
+ add("ffmpeg");
148
+ if (platform === "win32") {
149
+ add("C:\\ffmpeg\\bin\\ffmpeg.exe");
150
+ add("C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe");
151
+ } else {
152
+ add("/usr/bin/ffmpeg");
153
+ add("/usr/local/bin/ffmpeg");
154
+ add("/opt/homebrew/bin/ffmpeg");
155
+ }
156
+ return out;
157
+ }
158
+ function resolveOnPath(bin, platform, exists = (p) => fs.existsSync(p)) {
159
+ if (/[\\/]/.test(bin)) {
160
+ return bin;
161
+ }
162
+ const win = platform === "win32";
163
+ const pathMod = win ? path.win32 : path.posix;
164
+ const dirs = win ? ["C:\\ffmpeg\\bin", "C:\\Program Files\\ffmpeg\\bin"] : ["/usr/bin", "/usr/local/bin", "/opt/homebrew/bin", "/bin"];
165
+ const names = win && !/\.exe$/i.test(bin) ? [`${bin}.exe`, bin] : [bin];
166
+ for (const d of dirs) {
167
+ for (const n of names) {
168
+ const full = pathMod.join(d, n);
169
+ if (exists(full)) {
170
+ return full;
171
+ }
172
+ }
173
+ }
174
+ return bin;
175
+ }
176
+ function parseFfmpegVersion(out) {
177
+ const m = /ffmpeg version\s+(\S+)/i.exec(out || "");
178
+ if (!m) {
179
+ return "";
180
+ }
181
+ const v = /^n?(\d+(?:\.\d+)*)/.exec(m[1]);
182
+ return v ? v[1] : m[1];
183
+ }
184
+ function probeFfmpeg(bin, timeoutMs = 5e3) {
185
+ return new Promise((resolve) => {
186
+ var _a;
187
+ let out = "";
188
+ let done = false;
189
+ const timer = {};
190
+ const finish = (v) => {
191
+ if (!done) {
192
+ done = true;
193
+ clearTimeout(timer.id);
194
+ resolve(v);
195
+ }
196
+ };
197
+ let child;
198
+ try {
199
+ child = (0, import_node_child_process.spawn)(bin, ["-version"], { shell: false, windowsHide: true });
200
+ } catch {
201
+ resolve("");
202
+ return;
203
+ }
204
+ timer.id = setTimeout(() => {
205
+ try {
206
+ child.kill("SIGKILL");
207
+ } catch {
208
+ }
209
+ finish("");
210
+ }, timeoutMs);
211
+ (_a = child.stdout) == null ? void 0 : _a.on("data", (c) => {
212
+ if (out.length < 4096) {
213
+ out += c.toString();
214
+ }
215
+ });
216
+ child.on("error", () => finish(""));
217
+ child.on("close", (code) => finish(code === 0 ? parseFfmpegVersion(out) : ""));
218
+ });
219
+ }
220
+ async function detectFfmpeg(candidates, probe = (b) => probeFfmpeg(b)) {
221
+ for (const c of candidates) {
222
+ const version = await probe(c);
223
+ if (version) {
224
+ return { found: true, version, path: c };
225
+ }
226
+ }
227
+ return { found: false, version: "", path: "" };
228
+ }
229
+ function ffmpegStatusText(info) {
230
+ return info.found ? `${info.version} (${info.path})` : "not found";
231
+ }
232
+ function recordingFinished(prevSize, size, recording) {
233
+ return !recording && size > 0 && size === prevSize;
234
+ }
235
+ function* mp4Boxes(buf, from, to) {
236
+ let p = from;
237
+ while (p + 8 <= to) {
238
+ let size = buf.readUInt32BE(p);
239
+ const type = buf.toString("latin1", p + 4, p + 8);
240
+ let head = 8;
241
+ if (size === 1) {
242
+ if (p + 16 > to) {
243
+ return;
244
+ }
245
+ size = Number(buf.readBigUInt64BE(p + 8));
246
+ head = 16;
247
+ } else if (size === 0) {
248
+ size = to - p;
249
+ }
250
+ if (size < head) {
251
+ return;
252
+ }
253
+ yield { type, start: p + head, end: Math.min(p + size, to) };
254
+ p += size;
255
+ }
256
+ }
257
+ function mp4Child(buf, parent, type) {
258
+ for (const b of mp4Boxes(buf, parent.start, parent.end)) {
259
+ if (b.type === type) {
260
+ return b;
261
+ }
262
+ }
263
+ return void 0;
264
+ }
265
+ function mp4Info(buf) {
266
+ const info = { width: 0, height: 0, duration: 0 };
267
+ const top = [...mp4Boxes(buf, 0, buf.length)];
268
+ const moov = top.find((b) => b.type === "moov");
269
+ if (!moov) {
270
+ return info;
271
+ }
272
+ let videoId = 0;
273
+ let videoScale = 0;
274
+ for (const trak of mp4Boxes(buf, moov.start, moov.end)) {
275
+ if (trak.type !== "trak") {
276
+ continue;
277
+ }
278
+ const tkhd = mp4Child(buf, trak, "tkhd");
279
+ if (!tkhd || tkhd.end - tkhd.start < 84) {
280
+ continue;
281
+ }
282
+ const w = buf.readUInt32BE(tkhd.end - 8) / 65536;
283
+ const h = buf.readUInt32BE(tkhd.end - 4) / 65536;
284
+ if (w > 0 && h > 0) {
285
+ const v1 = buf[tkhd.start] === 1;
286
+ videoId = buf.readUInt32BE(tkhd.start + (v1 ? 20 : 12));
287
+ info.width = Math.round(w);
288
+ info.height = Math.round(h);
289
+ const mdia = mp4Child(buf, trak, "mdia");
290
+ const mdhd = mdia && mp4Child(buf, mdia, "mdhd");
291
+ if (mdhd) {
292
+ videoScale = buf.readUInt32BE(mdhd.start + (buf[mdhd.start] === 1 ? 20 : 12));
293
+ }
294
+ break;
295
+ }
296
+ }
297
+ const mvhd = mp4Child(buf, moov, "mvhd");
298
+ if (mvhd) {
299
+ const v1 = buf[mvhd.start] === 1;
300
+ const scale = buf.readUInt32BE(mvhd.start + (v1 ? 20 : 12));
301
+ const dur = v1 ? Number(buf.readBigUInt64BE(mvhd.start + 24)) : buf.readUInt32BE(mvhd.start + 16);
302
+ if (scale > 0 && dur > 0) {
303
+ info.duration = Math.round(dur / scale);
304
+ }
305
+ }
306
+ if (!info.duration && videoId && videoScale) {
307
+ let end = 0;
308
+ for (const moof of top) {
309
+ if (moof.type !== "moof") {
310
+ continue;
311
+ }
312
+ for (const traf of mp4Boxes(buf, moof.start, moof.end)) {
313
+ if (traf.type !== "traf") {
314
+ continue;
315
+ }
316
+ const tfhd = mp4Child(buf, traf, "tfhd");
317
+ if (!tfhd || buf.readUInt32BE(tfhd.start + 4) !== videoId) {
318
+ continue;
319
+ }
320
+ const tfFlags = buf.readUInt32BE(tfhd.start) & 16777215;
321
+ let q = tfhd.start + 8;
322
+ if (tfFlags & 1) {
323
+ q += 8;
324
+ }
325
+ if (tfFlags & 2) {
326
+ q += 4;
327
+ }
328
+ const defDur = tfFlags & 8 ? buf.readUInt32BE(q) : 0;
329
+ const tfdt = mp4Child(buf, traf, "tfdt");
330
+ let t = 0;
331
+ if (tfdt) {
332
+ t = buf[tfdt.start] === 1 ? Number(buf.readBigUInt64BE(tfdt.start + 4)) : buf.readUInt32BE(tfdt.start + 4);
333
+ }
334
+ for (const trun of mp4Boxes(buf, traf.start, traf.end)) {
335
+ if (trun.type !== "trun") {
336
+ continue;
337
+ }
338
+ const flags = buf.readUInt32BE(trun.start) & 16777215;
339
+ const count = buf.readUInt32BE(trun.start + 4);
340
+ let r = trun.start + 8 + (flags & 1 ? 4 : 0) + (flags & 4 ? 4 : 0);
341
+ const per = (flags & 256 ? 4 : 0) + (flags & 512 ? 4 : 0) + (flags & 1024 ? 4 : 0) + (flags & 2048 ? 4 : 0);
342
+ for (let i = 0; i < count && r + per <= trun.end; i++) {
343
+ t += flags & 256 ? buf.readUInt32BE(r) : defDur;
344
+ r += per;
345
+ }
346
+ }
347
+ end = Math.max(end, t);
348
+ }
349
+ }
350
+ if (end > 0) {
351
+ info.duration = Math.round(end / videoScale);
352
+ }
353
+ }
354
+ return info;
355
+ }
356
+ function ebmlVint(buf, p, keepMarker) {
357
+ if (p >= buf.length) {
358
+ return null;
359
+ }
360
+ const first = buf[p];
361
+ let len = 1;
362
+ while (len <= 8 && !(first & 128 >> len - 1)) {
363
+ len++;
364
+ }
365
+ if (len > 8 || p + len > buf.length) {
366
+ return null;
367
+ }
368
+ let val = keepMarker ? first : first & 255 >> len;
369
+ let allOnes = (first & 255 >> len) === 255 >> len;
370
+ for (let i = 1; i < len; i++) {
371
+ val = val * 256 + buf[p + i];
372
+ if (buf[p + i] !== 255) {
373
+ allOnes = false;
374
+ }
375
+ }
376
+ return { val, len, unknown: allOnes };
377
+ }
378
+ function mkvInfo(buf) {
379
+ const info = { width: 0, height: 0, duration: 0 };
380
+ let scale = 1e6;
381
+ let durTicks = 0;
382
+ const MASTER = /* @__PURE__ */ new Set([408125543, 357149030, 374648427, 174, 224]);
383
+ const walk = (from, to, depth) => {
384
+ let p = from;
385
+ while (p < to && depth < 6) {
386
+ const id = ebmlVint(buf, p, true);
387
+ const size = id && ebmlVint(buf, p + id.len, false);
388
+ if (!id || !size) {
389
+ return;
390
+ }
391
+ const start = p + id.len + size.len;
392
+ const end = size.unknown ? to : Math.min(start + size.val, to);
393
+ if (id.val === 524531317) {
394
+ return;
395
+ }
396
+ if (MASTER.has(id.val)) {
397
+ walk(start, end, depth + 1);
398
+ } else if (id.val === 176 || id.val === 186 || id.val === 2807729) {
399
+ let v = 0;
400
+ for (let i = start; i < end; i++) {
401
+ v = v * 256 + buf[i];
402
+ }
403
+ if (id.val === 176 && !info.width) {
404
+ info.width = v;
405
+ } else if (id.val === 186 && !info.height) {
406
+ info.height = v;
407
+ } else if (id.val === 2807729) {
408
+ scale = v;
409
+ }
410
+ } else if (id.val === 17545) {
411
+ durTicks = end - start === 8 ? buf.readDoubleBE(start) : end - start === 4 ? buf.readFloatBE(start) : 0;
412
+ }
413
+ if (size.unknown) {
414
+ return;
415
+ }
416
+ p = end;
417
+ }
418
+ };
419
+ walk(0, buf.length, 0);
420
+ if (durTicks > 0) {
421
+ info.duration = Math.round(durTicks * scale / 1e9);
422
+ }
423
+ return info;
424
+ }
425
+ function videoInfo(buf, format) {
426
+ try {
427
+ return format === "mkv" ? mkvInfo(buf) : mp4Info(buf);
428
+ } catch {
429
+ return { width: 0, height: 0, duration: 0 };
430
+ }
431
+ }
432
+ function isHevcMkv(buf) {
433
+ return buf.subarray(0, 256 * 1024).includes("V_MPEGH/ISO/HEVC");
434
+ }
435
+ function remuxArgs(hevc, dropAudio) {
436
+ const args = ["-hide_banner", "-loglevel", "error", "-i", "pipe:0", "-map", "0:v:0"];
437
+ if (!dropAudio) {
438
+ args.push("-map", "0:a?");
439
+ }
440
+ args.push("-c", "copy");
441
+ if (hevc) {
442
+ args.push("-tag:v", "hvc1");
443
+ }
444
+ if (dropAudio) {
445
+ args.push("-an");
446
+ }
447
+ args.push("-movflags", "frag_keyframe+empty_moov", "-f", "mp4", "pipe:1");
448
+ return args;
449
+ }
450
+ function runFfmpeg(bin, input, args, timeoutMs, maxBytes) {
451
+ return new Promise((resolve, reject) => {
452
+ let done = false;
453
+ const timer = {};
454
+ const chunks = [];
455
+ let size = 0;
456
+ let err = "";
457
+ const child = (0, import_node_child_process.spawn)(bin, args, { shell: false, windowsHide: true });
458
+ const fail = (e) => {
459
+ if (!done) {
460
+ done = true;
461
+ clearTimeout(timer.id);
462
+ try {
463
+ child.kill("SIGKILL");
464
+ } catch {
465
+ }
466
+ reject(e);
467
+ }
468
+ };
469
+ timer.id = setTimeout(
470
+ () => fail(new Error(`ffmpeg timeout after ${Math.round(timeoutMs / 1e3)} s`)),
471
+ timeoutMs
472
+ );
473
+ child.stdout.on("data", (c) => {
474
+ size += c.length;
475
+ if (size > maxBytes) {
476
+ fail(new Error(`MP4 larger than ${fmtMb(maxBytes)}`));
477
+ return;
478
+ }
479
+ chunks.push(c);
480
+ });
481
+ child.stderr.on("data", (c) => {
482
+ if (err.length < 2e3) {
483
+ err += c.toString();
484
+ }
485
+ });
486
+ child.on("error", (e) => fail(e));
487
+ child.on("close", (code) => {
488
+ if (done) {
489
+ return;
490
+ }
491
+ done = true;
492
+ clearTimeout(timer.id);
493
+ if (code === 0 && size > 0) {
494
+ resolve(Buffer.concat(chunks));
495
+ } else {
496
+ reject(new Error(`ffmpeg exit code ${code}: ${err.trim().split("\n").pop() || "no output"}`));
497
+ }
498
+ });
499
+ child.stdin.on("error", () => {
500
+ });
501
+ child.stdin.end(input);
502
+ });
503
+ }
504
+ async function remuxToMp4(bin, mkv, timeoutMs, maxBytes, onAudioDropped, run = runFfmpeg) {
505
+ const hevc = isHevcMkv(mkv);
506
+ try {
507
+ return await run(bin, mkv, remuxArgs(hevc, false), timeoutMs, maxBytes);
508
+ } catch (e) {
509
+ const msg = e.message;
510
+ if (/timeout|larger than|ENOENT|Invalid data|Error opening input/i.test(msg)) {
511
+ throw e;
512
+ }
513
+ const out = await run(bin, mkv, remuxArgs(hevc, true), timeoutMs, maxBytes);
514
+ onAudioDropped == null ? void 0 : onAudioDropped(msg);
515
+ return out;
516
+ }
517
+ }
518
+ function downloadToBuffer(opts, maxBytes, timeoutMs) {
519
+ return new Promise((resolve) => {
520
+ let done = false;
521
+ const timer = {};
522
+ let req;
523
+ const finish = (r) => {
524
+ if (!done) {
525
+ done = true;
526
+ clearTimeout(timer.id);
527
+ resolve(r);
528
+ }
529
+ };
530
+ timer.id = setTimeout(() => {
531
+ req == null ? void 0 : req.destroy();
532
+ finish({ ok: false, error: `timeout after ${Math.round(timeoutMs / 1e3)} s` });
533
+ }, timeoutMs);
534
+ try {
535
+ req = http.request({ ...opts, method: "GET" }, (res) => {
536
+ var _a;
537
+ if (res.statusCode && res.statusCode >= 400) {
538
+ res.resume();
539
+ finish({ ok: false, error: `HTTP ${res.statusCode}` });
540
+ return;
541
+ }
542
+ const len = parseInt(String((_a = res.headers["content-length"]) != null ? _a : ""), 10);
543
+ if (exceedsLimit(len, maxBytes)) {
544
+ req == null ? void 0 : req.destroy();
545
+ finish({ ok: false, tooLarge: true, size: len, error: `${fmtMb(len)} > limit ${fmtMb(maxBytes)}` });
546
+ return;
547
+ }
548
+ const chunks = [];
549
+ let size = 0;
550
+ res.on("data", (c) => {
551
+ size += c.length;
552
+ if (size > maxBytes) {
553
+ req == null ? void 0 : req.destroy();
554
+ finish({ ok: false, tooLarge: true, size, error: `more than ${fmtMb(maxBytes)}` });
555
+ return;
556
+ }
557
+ chunks.push(c);
558
+ });
559
+ res.on("end", () => finish({ ok: true, data: Buffer.concat(chunks), size }));
560
+ res.on("error", (e) => finish({ ok: false, error: e.message }));
561
+ });
562
+ req.on("error", (e) => finish({ ok: false, error: e.message }));
563
+ req.end();
564
+ } catch (e) {
565
+ finish({ ok: false, error: e.message });
566
+ }
567
+ });
568
+ }
569
+ function findCamera(query, cams) {
570
+ if (query === void 0 || query === null || query === "") {
571
+ return void 0;
572
+ }
573
+ const q = (typeof query === "number" ? String(query) : typeof query === "string" ? query : "").trim();
574
+ const ql = q.toLowerCase();
575
+ return cams.find((c) => c.fid === q) || cams.find((c) => String(c.oid) === q) || cams.find((c) => c.name.toLowerCase() === ql) || cams.find((c) => q.endsWith(`.${c.fid}`));
576
+ }
577
+ const MAX_MESSAGE_BYTES = 64 * 1024;
578
+ function containsBinary(value, depth = 0) {
579
+ if (value === null || typeof value !== "object") {
580
+ return false;
581
+ }
582
+ if (depth > 20) {
583
+ return true;
584
+ }
585
+ if (Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
586
+ return true;
587
+ }
588
+ const o = value;
589
+ if (o.type === "Buffer" && Array.isArray(o.data)) {
590
+ return true;
591
+ }
592
+ const children = Array.isArray(value) ? value : Object.values(o);
593
+ return children.some((v) => containsBinary(v, depth + 1));
594
+ }
595
+ function assertNoBinary(value) {
596
+ if (containsBinary(value)) {
597
+ throw new Error("refusing to put binary data on the ioBroker message bus");
598
+ }
599
+ const len = Buffer.byteLength(JSON.stringify(value != null ? value : null));
600
+ if (len > MAX_MESSAGE_BYTES) {
601
+ throw new Error(`refusing to put ${len} bytes on the ioBroker message bus`);
602
+ }
603
+ }
604
+ function safeMessage(value) {
605
+ try {
606
+ assertNoBinary(value);
607
+ return value;
608
+ } catch (e) {
609
+ return { ok: false, error: e.message };
610
+ }
611
+ }
612
+ // Annotate the CommonJS export names for ESM import in node:
613
+ 0 && (module.exports = {
614
+ MAX_MESSAGE_BYTES,
615
+ MB,
616
+ TELEGRAM_MAX_BYTES,
617
+ assertNoBinary,
618
+ cameraRecordingFiles,
619
+ clampNumber,
620
+ containsBinary,
621
+ detectFfmpeg,
622
+ downloadToBuffer,
623
+ exceedsLimit,
624
+ extOf,
625
+ ffmpegCandidates,
626
+ ffmpegStatusText,
627
+ findCamera,
628
+ fmtMb,
629
+ isHevcMkv,
630
+ isValidRecordingName,
631
+ maxRecordingBytes,
632
+ mimeOf,
633
+ needsInitialFill,
634
+ parseFfmpegVersion,
635
+ probeFfmpeg,
636
+ recordingAbsPath,
637
+ recordingFileName,
638
+ recordingFinished,
639
+ recordingSlots,
640
+ recordingStoragePath,
641
+ recordingUri,
642
+ recordingUrl,
643
+ remuxArgs,
644
+ remuxToMp4,
645
+ resolveOnPath,
646
+ runFfmpeg,
647
+ safeMessage,
648
+ sendFileStoragePath,
649
+ videoInfo
650
+ });
651
+ //# sourceMappingURL=recording.js.map