matterbridge-example-camera 0.2.0-dev-20260731-d8aa133 → 0.2.0-dev-20260802-7ee18a0
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/CHANGELOG.md +3 -1
- package/README.md +18 -4
- package/dist/behaviors/ffmpeg.js +103 -0
- package/dist/behaviors/snapshot.js +139 -0
- package/dist/behaviors/webRtcTransportProviderServer.js +1 -1
- package/dist/{webrtc → behaviors}/weriftSession.js +7 -91
- package/dist/module.js +1 -1
- package/npm-shrinkwrap.json +9 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -33,11 +33,13 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
33
33
|
### Added
|
|
34
34
|
|
|
35
35
|
- [chip]: Non-skipped CHIP test failures that carry a documented `comment` in `chipTests.json` (known, explained issues) no longer fail the `chip-tests.yml` workflow; only undocumented failures do.
|
|
36
|
+
- [camera]: Add the ffmpeg-based snapshot capture pipeline (`src/behaviors/snapshot.ts`): captures a single JPEG from an RTSP or webcam source, retrying at increasing compression (and a downgraded resolution as a last resort) until it fits the requested byte budget, with request validation, bounded capture timeouts escalating from `SIGTERM` to `SIGKILL`, webcam warm-up frame dropping, empty-capture rejection, and credential redaction in logs and errors.
|
|
37
|
+
- [frontend] Add plugin-frontend agents instructions.
|
|
36
38
|
|
|
37
39
|
### Changed
|
|
38
40
|
|
|
39
41
|
- [plugin]: Require Matterbridge `3.10.3` or later.
|
|
40
|
-
- [
|
|
42
|
+
- [camera]: Move `weriftSession.ts` from `src/webrtc/` to `src/behaviors/` and extract the ffmpeg binary resolution into a shared `src/behaviors/ffmpeg.ts` helper, resolved once at module load and reused by both the WebRTC injection and the snapshot pipeline.
|
|
41
43
|
|
|
42
44
|
## [0.1.0] - Dev branch
|
|
43
45
|
|
package/README.md
CHANGED
|
@@ -195,7 +195,7 @@ Bind Server Intercom 2 to Server Intercom 1 with  wraps a real werift `RTCPeerConnection` for each WebRtcTransportProvider session (see `MatterbridgeWebRtcTransportProviderServer` in `src/behaviors/webRtcTransportProviderServer.ts`), so the session's SDP offer/answer and ICE candidates are handled by a real WebRTC peer connection instead of being just recorded. It can also inject a real ffmpeg-generated video and/or audio track into the negotiated connection, so the end-to-end media path can be validated without a real camera/microphone capture pipeline.
|
|
199
199
|
|
|
200
200
|
The platform configuration controls WebRTC video injection with these properties:
|
|
201
201
|
|
|
@@ -243,9 +243,23 @@ With `videoResolution: "auto"`, a real client's resolution/quality picker (e.g.
|
|
|
243
243
|
|
|
244
244
|
Use ffmpeg itself to list the [available capture devices](https://trac.ffmpeg.org/wiki/Capture/Webcam) and find the right value for `videoSource`:
|
|
245
245
|
|
|
246
|
-
- Linux (v4l2):
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
- Linux (v4l2): video devices are usually exposed as `/dev/video*`; use the device path as the device value.
|
|
247
|
+
|
|
248
|
+
```shell
|
|
249
|
+
ffmpeg -hide_banner -f v4l2 -list_formats all -i /dev/video0
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
- macOS (avfoundation): video devices are listed with their index, e.g. `[0] FaceTime HD Camera`; use that index (e.g. `0`) as the device value.
|
|
253
|
+
|
|
254
|
+
```shell
|
|
255
|
+
ffmpeg -hide_banner -f avfoundation -list_devices true -i dummy
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
- Windows (dshow): video devices are listed by name under "DirectShow video devices", e.g. `"Integrated Camera"`; use that exact name as the device value.
|
|
259
|
+
|
|
260
|
+
```shell
|
|
261
|
+
ffmpeg -hide_banner -f dshow -list_devices true -i dummy
|
|
262
|
+
```
|
|
249
263
|
|
|
250
264
|
Example configuration for a real Linux webcam at 720p:
|
|
251
265
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { access, readdir } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
6
|
+
const log = new AnsiLogger({ logName: 'Ffmpeg', logLevel: "debug", logNameColor: MAGENTA, logTimestampFormat: 4 });
|
|
7
|
+
async function runProbe(command, args) {
|
|
8
|
+
await new Promise((resolve, reject) => {
|
|
9
|
+
const child = spawn(command, args, { stdio: 'ignore' });
|
|
10
|
+
child.once('error', reject);
|
|
11
|
+
child.once('exit', (code) => {
|
|
12
|
+
if (code === 0) {
|
|
13
|
+
resolve();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
reject(new Error(`${command} exited with code ${code ?? -1}`));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function isRunnable(command) {
|
|
21
|
+
for (const versionArg of ['--version', '-version']) {
|
|
22
|
+
try {
|
|
23
|
+
await runProbe(command, [versionArg]);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async function getWindowsCommandCandidates() {
|
|
32
|
+
if (process.platform !== 'win32')
|
|
33
|
+
return [];
|
|
34
|
+
const candidates = [];
|
|
35
|
+
if (process.env.LOCALAPPDATA) {
|
|
36
|
+
const wingetPackages = path.join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Packages');
|
|
37
|
+
try {
|
|
38
|
+
const packageDirs = await readdir(wingetPackages, { withFileTypes: true });
|
|
39
|
+
for (const packageDir of packageDirs) {
|
|
40
|
+
if (!packageDir.isDirectory() || !packageDir.name.startsWith('Gyan.FFmpeg_'))
|
|
41
|
+
continue;
|
|
42
|
+
const packagePath = path.join(wingetPackages, packageDir.name);
|
|
43
|
+
try {
|
|
44
|
+
const versionDirs = await readdir(packagePath, { withFileTypes: true });
|
|
45
|
+
for (const versionDir of versionDirs) {
|
|
46
|
+
if (versionDir.isDirectory() && versionDir.name.startsWith('ffmpeg-'))
|
|
47
|
+
candidates.push(path.join(packagePath, versionDir.name, 'bin', 'ffmpeg.exe'));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const programFiles of [process.env.ProgramFiles, process.env['ProgramFiles(x86)']]) {
|
|
58
|
+
if (!programFiles)
|
|
59
|
+
continue;
|
|
60
|
+
candidates.push(path.join(programFiles, 'ffmpeg', 'bin', 'ffmpeg.exe'), path.join(programFiles, 'Gyan', 'FFmpeg', 'bin', 'ffmpeg.exe'));
|
|
61
|
+
}
|
|
62
|
+
return candidates;
|
|
63
|
+
}
|
|
64
|
+
async function resolveFfmpeg() {
|
|
65
|
+
const candidates = ['ffmpeg', '/usr/bin/ffmpeg', '/bin/ffmpeg', '/usr/local/bin/ffmpeg', ...(await getWindowsCommandCandidates())];
|
|
66
|
+
log.debug(`Resolving ffmpeg: trying ${candidates.length} candidate(s)`);
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
if (path.isAbsolute(candidate)) {
|
|
69
|
+
try {
|
|
70
|
+
await access(candidate, constants.X_OK);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
log.debug(`Candidate ${candidate} is not accessible`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (await isRunnable(candidate)) {
|
|
78
|
+
log.debug(`Found ffmpeg in ${candidate}`);
|
|
79
|
+
return candidate;
|
|
80
|
+
}
|
|
81
|
+
log.debug(`Candidate ${candidate} did not run successfully`);
|
|
82
|
+
}
|
|
83
|
+
log.debug('Could not resolve ffmpeg');
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const ffmpegCommand = await resolveFfmpeg();
|
|
87
|
+
if (ffmpegCommand)
|
|
88
|
+
log.debug(`Using ffmpeg: ${ffmpegCommand}`);
|
|
89
|
+
else
|
|
90
|
+
log.warn('ffmpeg could not be resolved on this host; ffmpeg-dependent features will not work');
|
|
91
|
+
export function hasFfmpeg() {
|
|
92
|
+
return ffmpegCommand !== undefined;
|
|
93
|
+
}
|
|
94
|
+
export function redactSource(source) {
|
|
95
|
+
return source.replace(/^([a-z][a-z\d+.-]*:\/\/)[^/]*@/i, '$1***@');
|
|
96
|
+
}
|
|
97
|
+
export function runFfmpeg(args) {
|
|
98
|
+
if (!ffmpegCommand) {
|
|
99
|
+
throw new Error('Cannot run ffmpeg: not found on this host');
|
|
100
|
+
}
|
|
101
|
+
log.debug(`Spawning ffmpeg: ${ffmpegCommand} ${args.map(redactSource).join(' ')}`);
|
|
102
|
+
return spawn(ffmpegCommand, args);
|
|
103
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
5
|
+
import { hasFfmpeg, redactSource, runFfmpeg } from './ffmpeg.js';
|
|
6
|
+
const MAX_BYTES = 64000;
|
|
7
|
+
const QUALITIES = [6, 10, 14, 18, 24, 31];
|
|
8
|
+
const FALLBACK_WIDTH = 640;
|
|
9
|
+
const WEBCAM_WARMUP_SECONDS = 1;
|
|
10
|
+
const CAPTURE_TIMEOUT_MS = 10_000;
|
|
11
|
+
const TERMINATION_GRACE_MS = 1_000;
|
|
12
|
+
const log = new AnsiLogger({ logName: 'Snapshot', logLevel: "debug", logNameColor: MAGENTA, logTimestampFormat: 4 });
|
|
13
|
+
export async function captureSnapshot(request) {
|
|
14
|
+
const { src, width, height, maxBytes = MAX_BYTES } = request;
|
|
15
|
+
if (typeof src !== 'string' || src.trim().length === 0) {
|
|
16
|
+
throw new Error('Snapshot source must not be empty');
|
|
17
|
+
}
|
|
18
|
+
if (!Number.isFinite(width) || !Number.isInteger(width) || width <= 0) {
|
|
19
|
+
throw new Error(`Snapshot width must be a positive integer, got ${width}`);
|
|
20
|
+
}
|
|
21
|
+
if (!Number.isFinite(height) || !Number.isInteger(height) || height <= 0) {
|
|
22
|
+
throw new Error(`Snapshot height must be a positive integer, got ${height}`);
|
|
23
|
+
}
|
|
24
|
+
if (!Number.isFinite(maxBytes) || !Number.isInteger(maxBytes) || maxBytes <= 0) {
|
|
25
|
+
throw new Error(`Snapshot maxBytes must be a positive integer, got ${maxBytes}`);
|
|
26
|
+
}
|
|
27
|
+
const redactedSrc = redactSource(src);
|
|
28
|
+
log.debug(`Capturing snapshot from ${redactedSrc} at ${width}x${height}, maxBytes=${maxBytes}`);
|
|
29
|
+
let last = Buffer.alloc(0);
|
|
30
|
+
let lastQuality = QUALITIES[QUALITIES.length - 1];
|
|
31
|
+
log.debug(`Pass 1: trying ${width}x${height} at qualities [${QUALITIES.join(', ')}]`);
|
|
32
|
+
for (const q of QUALITIES) {
|
|
33
|
+
log.debug(`Pass 1: grabbing ${width}x${height} at quality ${q}`);
|
|
34
|
+
const buf = await grab(src, width, height, q);
|
|
35
|
+
log.debug(`Pass 1: grabbed ${buf.length}B at quality ${q} (maxBytes=${maxBytes})`);
|
|
36
|
+
last = buf;
|
|
37
|
+
lastQuality = q;
|
|
38
|
+
if (buf.length <= maxBytes) {
|
|
39
|
+
log.debug(`Pass 1: accepted ${buf.length}B at ${width}x${height}, quality ${q}`);
|
|
40
|
+
return { data: buf, byteLength: buf.length, width, height, quality: q, downgraded: false };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const fallbackWidth = Math.min(width, FALLBACK_WIDTH);
|
|
44
|
+
log.debug(`Pass 2: falling back to ${fallbackWidth}px wide at qualities [${QUALITIES.join(', ')}]`);
|
|
45
|
+
for (const q of QUALITIES) {
|
|
46
|
+
log.debug(`Pass 2: grabbing ${fallbackWidth}px wide at quality ${q}`);
|
|
47
|
+
const buf = await grab(src, fallbackWidth, -1, q);
|
|
48
|
+
log.debug(`Pass 2: grabbed ${buf.length}B at quality ${q} (maxBytes=${maxBytes})`);
|
|
49
|
+
last = buf;
|
|
50
|
+
lastQuality = q;
|
|
51
|
+
if (buf.length <= maxBytes) {
|
|
52
|
+
log.warn(`Snapshot downgraded to ${fallbackWidth}px to fit ${maxBytes}B (requested ${width}x${height})`);
|
|
53
|
+
return { data: buf, byteLength: buf.length, width: fallbackWidth, height: -1, quality: q, downgraded: true };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Snapshot capture from ${redactedSrc} exceeds ${maxBytes}B at minimum quality/resolution (${last.length}B at quality ${lastQuality})`);
|
|
57
|
+
}
|
|
58
|
+
function buildInputArgs(src, width, height) {
|
|
59
|
+
if (src.startsWith('rtsp://')) {
|
|
60
|
+
return ['-rtsp_transport', 'tcp', '-i', src];
|
|
61
|
+
}
|
|
62
|
+
const warmup = ['-ss', String(WEBCAM_WARMUP_SECONDS)];
|
|
63
|
+
const videoSize = height === -1 ? [] : ['-video_size', `${width}x${height}`];
|
|
64
|
+
switch (process.platform) {
|
|
65
|
+
case 'linux':
|
|
66
|
+
return ['-f', 'v4l2', ...videoSize, '-i', src, ...warmup];
|
|
67
|
+
case 'darwin':
|
|
68
|
+
return ['-f', 'avfoundation', ...videoSize, '-i', src, ...warmup];
|
|
69
|
+
case 'win32':
|
|
70
|
+
return ['-f', 'dshow', ...videoSize, '-i', `video=${src}`, ...warmup];
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Webcam capture via ffmpeg is not supported on platform "${process.platform}"`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function grab(src, width, height, q) {
|
|
76
|
+
if (!hasFfmpeg()) {
|
|
77
|
+
log.warn('Cannot capture snapshot: missing dependency ffmpeg');
|
|
78
|
+
throw new Error('Cannot capture snapshot: missing dependency ffmpeg');
|
|
79
|
+
}
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const scaleExpr = height === -1 ? `scale=${width}:-1` : `scale=${width}:${height}`;
|
|
82
|
+
const args = ['-y', ...buildInputArgs(src, width, height), '-frames:v', '1', '-vf', scaleExpr, '-q:v', String(q), '-f', 'mjpeg', 'pipe:1'];
|
|
83
|
+
const proc = runFfmpeg(args);
|
|
84
|
+
const chunks = [];
|
|
85
|
+
let stderr = '';
|
|
86
|
+
let forceKillTimeout;
|
|
87
|
+
const timeout = setTimeout(() => {
|
|
88
|
+
proc.kill('SIGTERM');
|
|
89
|
+
forceKillTimeout = setTimeout(() => {
|
|
90
|
+
proc.kill('SIGKILL');
|
|
91
|
+
}, TERMINATION_GRACE_MS);
|
|
92
|
+
reject(new Error(`Snapshot capture from ${redactSource(src)} timed out after ${CAPTURE_TIMEOUT_MS}ms`));
|
|
93
|
+
}, CAPTURE_TIMEOUT_MS);
|
|
94
|
+
proc.stdout?.on('data', (d) => chunks.push(d));
|
|
95
|
+
proc.stderr?.on('data', (d) => {
|
|
96
|
+
stderr += d.toString();
|
|
97
|
+
});
|
|
98
|
+
proc.on('close', (code) => {
|
|
99
|
+
clearTimeout(timeout);
|
|
100
|
+
if (forceKillTimeout)
|
|
101
|
+
clearTimeout(forceKillTimeout);
|
|
102
|
+
if (code === 0) {
|
|
103
|
+
const data = Buffer.concat(chunks);
|
|
104
|
+
if (data.length === 0) {
|
|
105
|
+
reject(new Error(`Snapshot capture from ${redactSource(src)} produced no data`));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
log.debug(`ffmpeg exited 0, captured ${data.length}B`);
|
|
109
|
+
resolve(data);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
log.debug(`ffmpeg exited ${code}: ${stderr}`);
|
|
113
|
+
reject(new Error(`ffmpeg exited ${code}: ${stderr}`));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
proc.on('error', (error) => {
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
if (forceKillTimeout)
|
|
119
|
+
clearTimeout(forceKillTimeout);
|
|
120
|
+
reject(error);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
125
|
+
const src = process.argv[2] ?? 'Surface Camera Front';
|
|
126
|
+
const outputDir = path.join(process.cwd(), 'temp');
|
|
127
|
+
await mkdir(outputDir, { recursive: true });
|
|
128
|
+
const resolutions = [
|
|
129
|
+
{ width: 640, height: 480 },
|
|
130
|
+
{ width: 1280, height: 720 },
|
|
131
|
+
{ width: 1920, height: 1080 },
|
|
132
|
+
];
|
|
133
|
+
for (const { width, height } of resolutions) {
|
|
134
|
+
const result = await captureSnapshot({ src, width, height });
|
|
135
|
+
const outputFile = path.join(outputDir, `snapshot-${width}x${height}.jpeg`);
|
|
136
|
+
await writeFile(outputFile, result.data);
|
|
137
|
+
log.info(`Saved snapshot to ${outputFile} (${result.byteLength}B, ${result.width}x${result.height}, quality=${result.quality}, downgraded=${result.downgraded})`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -3,8 +3,8 @@ import { Node } from 'matterbridge/matter';
|
|
|
3
3
|
import { WebRtcTransportProviderServer, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
|
|
4
4
|
import { WebRtcTransportDefinitions } from 'matterbridge/matter/clusters';
|
|
5
5
|
import { EndpointNumber, FabricIndex, NodeId, StreamUsage, Status, StatusResponseError } from 'matterbridge/matter/types';
|
|
6
|
-
import { WeriftWebRtcSession } from '../webrtc/weriftSession.js';
|
|
7
6
|
import { MatterbridgeCameraAvStreamManagementServer } from './cameraAvStreamManagementServer.js';
|
|
7
|
+
import { WeriftWebRtcSession } from './weriftSession.js';
|
|
8
8
|
const DEFERRED_INVOKE_DELAY_MS = 250;
|
|
9
9
|
const ICE_CANDIDATE_APPLY_TIMEOUT_MS = 5000;
|
|
10
10
|
const MAX_WEB_RTC_SESSION_ID = 0xfffe;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
1
|
import { createSocket } from 'node:dgram';
|
|
3
|
-
import { constants } from 'node:fs';
|
|
4
|
-
import { access, readdir } from 'node:fs/promises';
|
|
5
|
-
import path from 'node:path';
|
|
6
2
|
import { fileURLToPath } from 'node:url';
|
|
7
3
|
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
8
4
|
import { fireAndForget, getErrorMessage } from 'matterbridge/utils';
|
|
9
5
|
import { RTCPeerConnection, RTCRtpCodecParameters, useH264, useOPUS, usePCMU, useVP8 } from 'werift';
|
|
10
6
|
import { navigator } from 'werift/nonstandard';
|
|
7
|
+
import { hasFfmpeg, runFfmpeg } from './ffmpeg.js';
|
|
11
8
|
export class WeriftWebRtcSession {
|
|
12
9
|
static activeSessions = new Set();
|
|
13
10
|
static exitHandlerRegistered = false;
|
|
@@ -75,83 +72,6 @@ export class WeriftWebRtcSession {
|
|
|
75
72
|
.map((line) => line.slice(2).split(' ')[0]);
|
|
76
73
|
return `length=${sdp.length} media=[${mediaKinds.join(',')}]`;
|
|
77
74
|
}
|
|
78
|
-
async runProcess(command, args) {
|
|
79
|
-
await new Promise((resolve, reject) => {
|
|
80
|
-
const child = spawn(command, args, { stdio: 'ignore' });
|
|
81
|
-
child.once('error', reject);
|
|
82
|
-
child.once('exit', (code) => {
|
|
83
|
-
if (code === 0) {
|
|
84
|
-
resolve();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
reject(new Error(`${command} exited with code ${code ?? -1}`));
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
async hasCommand(command) {
|
|
92
|
-
for (const versionArg of ['--version', '-version']) {
|
|
93
|
-
try {
|
|
94
|
-
await this.runProcess(command, [versionArg]);
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
async getWindowsCommandCandidates(command) {
|
|
103
|
-
if (process.platform !== 'win32')
|
|
104
|
-
return [];
|
|
105
|
-
const commandName = command.toLowerCase().replace(/\.exe$/, '');
|
|
106
|
-
const executable = command.toLowerCase().endsWith('.exe') ? command : `${command}.exe`;
|
|
107
|
-
const candidates = [];
|
|
108
|
-
if (commandName === 'ffmpeg' && process.env.LOCALAPPDATA) {
|
|
109
|
-
const wingetPackages = path.join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Packages');
|
|
110
|
-
try {
|
|
111
|
-
const packageDirs = await readdir(wingetPackages, { withFileTypes: true });
|
|
112
|
-
for (const packageDir of packageDirs) {
|
|
113
|
-
if (!packageDir.isDirectory() || !packageDir.name.startsWith('Gyan.FFmpeg_'))
|
|
114
|
-
continue;
|
|
115
|
-
const packagePath = path.join(wingetPackages, packageDir.name);
|
|
116
|
-
try {
|
|
117
|
-
const versionDirs = await readdir(packagePath, { withFileTypes: true });
|
|
118
|
-
for (const versionDir of versionDirs) {
|
|
119
|
-
if (versionDir.isDirectory() && versionDir.name.startsWith('ffmpeg-'))
|
|
120
|
-
candidates.push(path.join(packagePath, versionDir.name, 'bin', executable));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
for (const programFiles of [process.env.ProgramFiles, process.env['ProgramFiles(x86)']]) {
|
|
131
|
-
if (!programFiles)
|
|
132
|
-
continue;
|
|
133
|
-
candidates.push(path.join(programFiles, 'ffmpeg', 'bin', executable), path.join(programFiles, 'Gyan', 'FFmpeg', 'bin', executable));
|
|
134
|
-
}
|
|
135
|
-
return candidates;
|
|
136
|
-
}
|
|
137
|
-
async resolveCommand(command) {
|
|
138
|
-
const candidates = [command, `/usr/bin/${command}`, `/bin/${command}`, `/usr/local/bin/${command}`, ...(await this.getWindowsCommandCandidates(command))];
|
|
139
|
-
for (const candidate of candidates) {
|
|
140
|
-
if (candidate.includes('/')) {
|
|
141
|
-
try {
|
|
142
|
-
await access(candidate, constants.X_OK);
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (await this.hasCommand(candidate)) {
|
|
149
|
-
this.log.debug(`Found ${command} in ${candidate}`);
|
|
150
|
-
return candidate;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
75
|
async getFreeUdpPort() {
|
|
156
76
|
return await new Promise((resolve, reject) => {
|
|
157
77
|
const socket = createSocket('udp4');
|
|
@@ -286,8 +206,7 @@ export class WeriftWebRtcSession {
|
|
|
286
206
|
}
|
|
287
207
|
const videoInput = this.buildFfmpegVideoInputArgs(videoSource, videoResolution);
|
|
288
208
|
this.log.debug(`Attempting to attach ${videoInput.description} video track at ${videoInput.bitrateKbps}kbps`);
|
|
289
|
-
|
|
290
|
-
if (!ffmpegCommand) {
|
|
209
|
+
if (!hasFfmpeg()) {
|
|
291
210
|
this.log.warn('Cannot inject video stream: missing dependency ffmpeg');
|
|
292
211
|
return;
|
|
293
212
|
}
|
|
@@ -317,15 +236,14 @@ export class WeriftWebRtcSession {
|
|
|
317
236
|
String(selectedPayloadType),
|
|
318
237
|
`rtp://127.0.0.1:${udpPort}`,
|
|
319
238
|
];
|
|
320
|
-
|
|
321
|
-
const generator = spawn(ffmpegCommand, ffmpegArgs);
|
|
239
|
+
const generator = runFfmpeg(ffmpegArgs);
|
|
322
240
|
generator.once('error', (error) => {
|
|
323
241
|
this.log.warn(`Video generator failed: ${getErrorMessage(error)}`);
|
|
324
242
|
});
|
|
325
243
|
this.testVideoUdpDisposer = disposer;
|
|
326
244
|
this.testVideoGenerator = generator;
|
|
327
245
|
this.testVideoAttached = true;
|
|
328
|
-
this.log.info(`Attached ${videoInput.description} video track (
|
|
246
|
+
this.log.info(`Attached ${videoInput.description} video track (codec=${selectedMimeType}, payloadType=${selectedPayloadType}, sourcePort=${udpPort})`);
|
|
329
247
|
}
|
|
330
248
|
catch (error) {
|
|
331
249
|
this.log.warn(`Failed to attach ${videoInput.description} video track: ${getErrorMessage(error)}`);
|
|
@@ -417,8 +335,7 @@ export class WeriftWebRtcSession {
|
|
|
417
335
|
}
|
|
418
336
|
const audioInput = this.buildFfmpegAudioInputArgs(audioSource);
|
|
419
337
|
this.log.debug(`Attempting to attach ${audioInput.description} audio track`);
|
|
420
|
-
|
|
421
|
-
if (!ffmpegCommand) {
|
|
338
|
+
if (!hasFfmpeg()) {
|
|
422
339
|
this.log.warn('Cannot inject audio stream: missing dependency ffmpeg');
|
|
423
340
|
return;
|
|
424
341
|
}
|
|
@@ -454,15 +371,14 @@ export class WeriftWebRtcSession {
|
|
|
454
371
|
String(selectedPayloadType),
|
|
455
372
|
`rtp://127.0.0.1:${udpPort}`,
|
|
456
373
|
];
|
|
457
|
-
|
|
458
|
-
const generator = spawn(ffmpegCommand, ffmpegArgs);
|
|
374
|
+
const generator = runFfmpeg(ffmpegArgs);
|
|
459
375
|
generator.once('error', (error) => {
|
|
460
376
|
this.log.warn(`Audio generator failed: ${getErrorMessage(error)}`);
|
|
461
377
|
});
|
|
462
378
|
this.testAudioUdpDisposer = disposer;
|
|
463
379
|
this.testAudioGenerator = generator;
|
|
464
380
|
this.testAudioAttached = true;
|
|
465
|
-
this.log.info(`Attached ${audioInput.description} audio track (
|
|
381
|
+
this.log.info(`Attached ${audioInput.description} audio track (codec=${selectedMimeType}, payloadType=${selectedPayloadType}, sourcePort=${udpPort})`);
|
|
466
382
|
}
|
|
467
383
|
catch (error) {
|
|
468
384
|
this.log.warn(`Failed to attach ${audioInput.description} audio track: ${getErrorMessage(error)}`);
|
package/dist/module.js
CHANGED
|
@@ -7,6 +7,7 @@ import { UINT16_MAX, UINT32_MAX } from 'matterbridge/matter';
|
|
|
7
7
|
import { ChimeClient } from 'matterbridge/matter/behaviors';
|
|
8
8
|
import { Identify, Chime as ChimeCluster, PowerSource } from 'matterbridge/matter/clusters';
|
|
9
9
|
import { isValidNumber, parseVersionString } from 'matterbridge/utils';
|
|
10
|
+
import { WeriftWebRtcSession } from './behaviors/weriftSession.js';
|
|
10
11
|
import { AudioDoorbell } from './devices/audioDoorbell.js';
|
|
11
12
|
import { Camera } from './devices/camera.js';
|
|
12
13
|
import { Chime } from './devices/chime.js';
|
|
@@ -15,7 +16,6 @@ import { FloodlightCamera } from './devices/floodlightCamera.js';
|
|
|
15
16
|
import { Intercom } from './devices/intercom.js';
|
|
16
17
|
import { SnapshotCamera } from './devices/snapshotCamera.js';
|
|
17
18
|
import { VideoDoorbell } from './devices/videoDoorbell.js';
|
|
18
|
-
import { WeriftWebRtcSession } from './webrtc/weriftSession.js';
|
|
19
19
|
export default function initializePlugin(matterbridge, log, config) {
|
|
20
20
|
return new ExampleMatterbridgeCameraPlatform(matterbridge, log, config);
|
|
21
21
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-example-camera",
|
|
3
|
-
"version": "0.2.0-dev-
|
|
3
|
+
"version": "0.2.0-dev-20260802-7ee18a0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-example-camera",
|
|
9
|
-
"version": "0.2.0-dev-
|
|
9
|
+
"version": "0.2.0-dev-20260802-7ee18a0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"node-ansi-logger": "3.3.0",
|
|
13
13
|
"node-persist-manager": "2.1.0",
|
|
14
|
-
"werift": "0.24.
|
|
14
|
+
"werift": "0.24.2"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=20.19.0 <21.0.0 || >=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
|
|
@@ -437,9 +437,9 @@
|
|
|
437
437
|
"license": "MIT"
|
|
438
438
|
},
|
|
439
439
|
"node_modules/mediabunny": {
|
|
440
|
-
"version": "1.52.
|
|
441
|
-
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.52.
|
|
442
|
-
"integrity": "sha512-
|
|
440
|
+
"version": "1.52.2",
|
|
441
|
+
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.52.2.tgz",
|
|
442
|
+
"integrity": "sha512-HIgqL2BAWsWJtaqZRrqcrv7cEajQtCT9noR0dO8cGLKZKML9mmL4BjZOtm6j5I9qAp0v/hr/NmRZhuR6HZyQ7Q==",
|
|
443
443
|
"license": "MPL-2.0",
|
|
444
444
|
"workspaces": [
|
|
445
445
|
".",
|
|
@@ -618,9 +618,9 @@
|
|
|
618
618
|
"license": "Unlicense"
|
|
619
619
|
},
|
|
620
620
|
"node_modules/werift": {
|
|
621
|
-
"version": "0.24.
|
|
622
|
-
"resolved": "https://registry.npmjs.org/werift/-/werift-0.24.
|
|
623
|
-
"integrity": "sha512-
|
|
621
|
+
"version": "0.24.2",
|
|
622
|
+
"resolved": "https://registry.npmjs.org/werift/-/werift-0.24.2.tgz",
|
|
623
|
+
"integrity": "sha512-7zjdi1SAv3CglLe9Yyi15Gl73HxoKFZCbsbqcrfSDOlV6ojiwUjJqACBZGfbX8AyJXDsBZZpU8NwXxWwOQHoEQ==",
|
|
624
624
|
"license": "MIT",
|
|
625
625
|
"dependencies": {
|
|
626
626
|
"@fidm/x509": "^1.2.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-example-camera",
|
|
3
|
-
"version": "0.2.0-dev-
|
|
3
|
+
"version": "0.2.0-dev-20260802-7ee18a0",
|
|
4
4
|
"description": "Matterbridge camera example plugin",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"node-ansi-logger": "3.3.0",
|
|
71
71
|
"node-persist-manager": "2.1.0",
|
|
72
|
-
"werift": "0.24.
|
|
72
|
+
"werift": "0.24.2"
|
|
73
73
|
}
|
|
74
74
|
}
|