matterbridge-example-camera 0.0.8-dev-20260726-02502e0 → 0.0.8
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 +13 -1
- package/README.md +58 -19
- package/dist/module.js +5 -0
- package/dist/webrtc/weriftSession.js +66 -14
- package/matterbridge-example-camera.schema.json +7 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -28,7 +28,7 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
28
28
|
|
|
29
29
|
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
|
|
30
30
|
|
|
31
|
-
## [0.0.8] -
|
|
31
|
+
## [0.0.8] - 2026-07-26
|
|
32
32
|
|
|
33
33
|
### Added
|
|
34
34
|
|
|
@@ -43,11 +43,23 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
43
43
|
- [platform]: Add an `audioGenerator` config property (`none`/`test`, defaulting to `none`) replacing the undocumented `MATTERBRIDGE_CAMERA_DISABLE_TEST_AUDIO=1` env var toggle, mirroring `videoGenerator`'s pattern via the new `MATTERBRIDGE_CAMERA_AUDIO_SOURCE` env var. Test-voice audio injection is now opt-in instead of on by default.
|
|
44
44
|
- [docs]: Document `audioGenerator` in the README and schema.
|
|
45
45
|
- [tests]: Extend `vitest/module.test.ts` with `audioGenerator` normalization/apply coverage; update `vitest/webrtc/weriftSession.test.ts` for the new `MATTERBRIDGE_CAMERA_AUDIO_SOURCE` gate.
|
|
46
|
+
- [webrtc]: Add a periodic diagnostics log (`WeriftWebRtcSession.logDiagnosticsSnapshot`, every 10s) reporting `connectionState`, `iceConnectionState`, `iceGatheringState`, `signalingState`, per-transport ICE/DTLS states, and `getStats()`-derived packet-flow counters (nominated candidate-pair and outbound-rtp packets, with deltas since the previous tick). Needed because werift's ICE consent-freshness check (RFC 7675) can latch `iceConnectionState` at `disconnected` forever after a single missed keepalive, even on a healthy, actively-streaming session — the packet-flow deltas are unaffected by that bug and are a reliable "is media still moving" signal. A dedicated log line also fires immediately on any DTLS transport state change instead of waiting for the next tick.
|
|
47
|
+
- [webrtc]: Auto-close a `WeriftWebRtcSession` (peer connection plus any injected ffmpeg generators) when one of its DTLS transports reaches `closed` or `failed` on its own — a real, one-way teardown signal from the peer, unlike `iceConnectionState`'s `disconnected`, which must never trigger a close by itself. Fixes an orphaned-session leak: a controller that abandons a live view without ever sending `EndSession` (e.g. just closing the window) previously left the peer connection and its ffmpeg processes running indefinitely, piling up on every reconnect.
|
|
48
|
+
- [tests]: Add DTLS-triggered auto-close coverage in `vitest/webrtc/weriftSession.test.ts` (`closed`, `failed`, and a regression test ensuring a normal `close()` doesn't re-enter itself via the same DTLS state change).
|
|
49
|
+
- [webrtc]: Add `microphone` and `rtsp` options to `audioGenerator`, mirroring `videoGenerator`'s pattern: `microphone` captures from a local capture device via `ffmpeg -f alsa/avfoundation/dshow`, and `rtsp` pulls just the audio from a real RTSP camera stream (dropping any video) via `ffmpeg -rtsp_transport tcp -i <url> -vn`. Add the corresponding `audioSource` config property and `MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE` env var (device identifier for `microphone`, or the RTSP url for `rtsp`), mirroring `videoSource`/`MATTERBRIDGE_CAMERA_VIDEO_SOURCE_DEVICE`. The `-af volume=6dB` boost is now only applied to the `test` clip (recorded quietly), not to `microphone`/`rtsp` capture.
|
|
50
|
+
- [docs]: Document the `microphone` and `rtsp` audio generators and the new `audioSource` property in the README and schema, with example configurations.
|
|
51
|
+
- [tests]: Extend `vitest/module.test.ts` and `vitest/webrtc/weriftSession.test.ts` with `microphone`/`rtsp` audio source coverage.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- [webrtc]: Replace inline `error instanceof Error ? error.message : String(error)` error-message extraction with `getErrorMessage` from `matterbridge/utils` throughout `weriftSession.ts`; use `fireAndForget` for the auto-close's fire-and-forget `close()` call, matching the pattern already used elsewhere in the plugin.
|
|
46
56
|
|
|
47
57
|
### Fixed
|
|
48
58
|
|
|
49
59
|
- [webrtc]: The per-session requested webcam resolution (from a client's `CameraAvStreamManagement.VideoStreamAllocate`) was never actually applied: `buildFfmpegVideoInputArgs` read `MATTERBRIDGE_CAMERA_VIDEO_RESOLUTION` directly before falling back to `getConfiguredVideoResolution(requestedResolution)`, and since the plugin always sets that env var (default `640x480` at the time of this fix, before `videoResolution` defaulted to `auto`), the fallback — and therefore the requested resolution — was never reached.
|
|
50
60
|
|
|
61
|
+
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
|
|
62
|
+
|
|
51
63
|
## [0.0.7] - 2026-07-25
|
|
52
64
|
|
|
53
65
|
### Added
|
package/README.md
CHANGED
|
@@ -36,6 +36,27 @@ Thanks to [Ludovic BOUÉ](https://github.com/lboue) for his contributions to thi
|
|
|
36
36
|
- `src/devices/` contains all single class device types (it will be moved directly in matterbridge core package).
|
|
37
37
|
- `src/behaviors/` contains all required behaviors (it will be moved directly in matterbridge core package).
|
|
38
38
|
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
Requires [`ffmpeg`](https://ffmpeg.org/) to be installed. The resolver checks the system command and common installation directories on Linux, macOS, and Windows.
|
|
42
|
+
|
|
43
|
+
Install it with the platform's package manager:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Linux (Debian/Ubuntu)
|
|
47
|
+
sudo apt update && sudo apt install -y ffmpeg
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```powershell
|
|
51
|
+
# Windows
|
|
52
|
+
winget install --id Gyan.FFmpeg -e
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# macOS
|
|
57
|
+
brew install ffmpeg
|
|
58
|
+
```
|
|
59
|
+
|
|
39
60
|
## TODO
|
|
40
61
|
|
|
41
62
|
- Track matter.js PR #4128 (https://github.com/matter-js/matter.js/pull/4128) and, once merged and released in the consumed `@matter/*` version, remove the temporary ImageControl workaround used by Audio Doorbell and Intercom for CameraAvStreamManagement choice conformance.
|
|
@@ -75,22 +96,14 @@ Features:
|
|
|
75
96
|
- Supports configurable stream usages and priorities, encoder limits, video sensor parameters, viewport, rate-distortion trade-off points, and microphone capabilities.
|
|
76
97
|
- Optional Identify cluster support, with configurable identify time and type. Set to Identify.IdentifyType.None to omit the cluster entirely.
|
|
77
98
|
- Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
|
|
78
|
-
|
|
79
|
-
Supported by:
|
|
80
|
-
|
|
81
|
-
- [Matterserver dashboard](screenshots/matterserver-camera.png)
|
|
82
|
-
|
|
83
|
-
### PTZ Camera
|
|
84
|
-
|
|
85
|
-
Features:
|
|
86
|
-
|
|
87
|
-
- Same device type and Camera AV Stream Management setup as Camera (Video, Audio, Snapshot and ImageControl features, plus the WebRtcTransportProvider cluster and a WebRtcTransportRequestor client).
|
|
88
99
|
- Additionally exposes the Camera AV Settings User Level Management cluster with the MechanicalPan, MechanicalTilt and MechanicalZoom features, so a controller can move the camera to an absolute pan/tilt/zoom position (`MPTZSetPosition`) or by a relative delta (`MPTZRelativeMove`). The MechanicalPresets and DigitalPtz features are not part of this example.
|
|
89
100
|
- `MPTZSetPosition` rejects an absolute pan, tilt, or zoom value outside of the configured range with a ConstraintError.
|
|
90
101
|
- `MPTZRelativeMove` adds the pan/tilt/zoom delta directly to the current position, clamping the result to the configured range instead of rejecting it, since a relative move is expected to just stop at the mechanical limit.
|
|
91
102
|
- Configurable pan (`panMin`/`panMax`), tilt (`tiltMin`/`tiltMax`) and zoom (`zoomMax`) ranges, and initial `mptzPosition`. Defaults: pan -170° to 170°, tilt -20° to 90°, zoom 1 to 10, starting position `{ pan: 0, tilt: 0, zoom: 1 }`.
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
|
|
104
|
+
Supported by:
|
|
105
|
+
|
|
106
|
+
- [Matterserver dashboard](screenshots/matterserver-camera.png)
|
|
94
107
|
|
|
95
108
|
### Snapshot Camera
|
|
96
109
|
|
|
@@ -200,15 +213,41 @@ The platform configuration controls WebRTC video injection with these properties
|
|
|
200
213
|
|
|
201
214
|
- `videoBitrate` is required and accepts a number (the target encoder bitrate in kbps). It defaults to `1000`. It applies to the `webcam` and `rtsp` sources only; the `test` pattern is always encoded at a fixed 1000 kbps regardless of this setting. Since the encoder always uses `-preset ultrafast -tune zerolatency` for low-latency live view (lower compression efficiency than slower presets), suggested values are higher than typical streaming guides: ~800 for `640x480`, ~2000 for `1280x720`, ~2500 for `1920x1080`.
|
|
202
215
|
|
|
203
|
-
The platform configuration controls WebRTC audio injection with
|
|
216
|
+
The platform configuration controls WebRTC audio injection with these properties:
|
|
204
217
|
|
|
205
|
-
- `audioGenerator` is required and accepts `none` or `
|
|
218
|
+
- `audioGenerator` is required and accepts `none`, `test`, `microphone`, or `rtsp`. It defaults to `none`, which negotiates the audio transceiver (e.g. for an Intercom's "Listen" live view) without attaching a track. `test` injects a recorded test-voice clip, looped, so the end-to-end audio path can be validated without a real microphone capture pipeline. `microphone` captures from the configured local microphone, and `rtsp` pulls just the audio from the RTSP url configured in `audioSource` (any video in the stream is dropped).
|
|
206
219
|
|
|
207
|
-
|
|
220
|
+
- `audioSource` is optional and has no default. For the `microphone` generator it contains the OS-specific ffmpeg device identifier — e.g. an ALSA device such as `hw:0,0` on Linux, an avfoundation audio index such as `0` on macOS, or a device name such as `Microphone Array` on Windows (dshow). For the `rtsp` generator it instead holds the RTSP url, e.g. `rtsp://user:password@host:554/path` (it can be a different camera/url than `videoSource`). Selecting the `microphone` or `rtsp` generator without this property falls back to the test-voice clip with a warning.
|
|
221
|
+
|
|
222
|
+
Use ffmpeg itself to list the [available capture devices](https://trac.ffmpeg.org/wiki/Capture/Webcam) and find the right value for `audioSource`:
|
|
223
|
+
|
|
224
|
+
- Linux (alsa): `arecord -l`, or `ffmpeg -f alsa -i default` to try the default device.
|
|
225
|
+
- macOS (avfoundation): `ffmpeg -f avfoundation -list_devices true -i dummy` — audio devices are listed with their index under "AVFoundation audio devices", e.g. `[0] MacBook Pro Microphone`; use that index (e.g. `0`) as the device value.
|
|
226
|
+
- Windows (dshow): `ffmpeg -f dshow -list_devices true -i dummy` — audio devices are listed by name under "DirectShow audio devices", e.g. `"Microphone Array"`; use that exact name as the device value.
|
|
208
227
|
|
|
209
|
-
|
|
228
|
+
Example configuration for a real Linux microphone:
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"audioGenerator": "microphone",
|
|
233
|
+
"audioSource": "hw:0,0"
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Example, pulling the audio from the same RTSP camera used for `videoSource`:
|
|
238
|
+
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"videoGenerator": "rtsp",
|
|
242
|
+
"videoSource": "rtsp://admin:password@192.168.1.100:554/ch1/main",
|
|
243
|
+
"audioGenerator": "rtsp",
|
|
244
|
+
"audioSource": "rtsp://admin:password@192.168.1.100:554/ch1/main"
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
With `videoResolution: "auto"`, a real client's resolution/quality picker (e.g. in Home Assistant) drives the capture/output resolution: it allocates a video stream with `CameraAvStreamManagement.VideoStreamAllocate` before soliciting or providing a WebRTC offer, and `MatterbridgeWebRtcTransportProviderServer` looks up that stream's `maxResolution` to select the resolution for the session. For `webcam` this is the capture resolution passed to ffmpeg; for `rtsp` the camera keeps streaming at its own native resolution and ffmpeg scales it to match.
|
|
210
249
|
|
|
211
|
-
Use ffmpeg itself to list the available capture devices and find the right value for `videoSource`:
|
|
250
|
+
Use ffmpeg itself to list the [available capture devices](https://trac.ffmpeg.org/wiki/Capture/Webcam) and find the right value for `videoSource`:
|
|
212
251
|
|
|
213
252
|
- Linux (v4l2): `v4l2-ctl --list-devices` (from `v4l-utils`), or `ls /dev/video*`.
|
|
214
253
|
- macOS (avfoundation): `ffmpeg -f avfoundation -list_devices true -i dummy` — video devices are listed with their index, e.g. `[0] FaceTime HD Camera`; use that index (e.g. `0`) as the device value.
|
|
@@ -246,7 +285,7 @@ Finding your camera's RTSP url for `videoSource` when `videoGenerator` is `rtsp`
|
|
|
246
285
|
- Dahua: `/cam/realmonitor?channel=1&subtype=0`
|
|
247
286
|
- Reolink: `/h264Preview_01_main`
|
|
248
287
|
|
|
249
|
-
Verify the url works standalone before adding it to the config, e.g. `ffprobe rtsp://admin:password@192.168.1.100:554/ch1/main`, or open it in VLC via "Open Network Stream". Note that the url (with credentials in plaintext) ends up stored in Matterbridge's plugin config on disk, like any other password-bearing config value.
|
|
288
|
+
Verify the url works standalone before adding it to the config, e.g. `ffprobe rtsp://admin:password@192.168.1.100:554/ch1/main` or `ffplay rtsp://admin:password@192.168.1.100:554/ch1/main`, or open it in VLC via "Open Network Stream". Note that the url (with credentials in plaintext) ends up stored in Matterbridge's plugin config on disk, like any other password-bearing config value.
|
|
250
289
|
|
|
251
290
|
Example, pulling from a real RTSP camera, scaled to a fixed 1280x720 and re-encoded at `videoBitrate` (the camera's own frame rate is kept):
|
|
252
291
|
|
|
@@ -334,7 +373,7 @@ npm run test -- vitest/werift.test.ts
|
|
|
334
373
|
The `assets` directory contains deterministic three-second media fixtures for extending the werift test to real media tracks:
|
|
335
374
|
|
|
336
375
|
- `test-video.h264`: raw H.264 Constrained Baseline video, 640×360 at 15 FPS, with a moving test pattern. Use this elementary stream when implementing H.264 NAL-unit parsing and RTP packetization.
|
|
337
|
-
- `test-audio.opus`: Ogg container with mono Opus audio at 48 kHz and 64 kbit/s, containing a
|
|
376
|
+
- `test-audio.opus`: Ogg container with mono Opus audio at 48 kHz and 64 kbit/s, containing a recorded voice track. Use the Opus packets for an audio RTP track; the Ogg container itself is not sent over WebRTC.
|
|
338
377
|
- `test-camera.mp4`: playable reference containing the same 640×360 H.264 test pattern and a mono 1 kHz AAC track. The werift test transfers the complete file over its SCTP data channel and verifies its integrity. This exercises binary file transport, not a WebRTC video RTP track.
|
|
339
378
|
- `camera-color-1920-1080.jpeg`: 1920×1080 simplified ffmpeg-generated color-rectangle snapshot.
|
|
340
379
|
- `camera-color-1280-720.jpeg`: 1280×720 simplified ffmpeg-generated color-rectangle snapshot.
|
package/dist/module.js
CHANGED
|
@@ -47,6 +47,10 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
|
|
|
47
47
|
process.env.MATTERBRIDGE_CAMERA_VIDEO_RESOLUTION = this.config.videoResolution;
|
|
48
48
|
process.env.MATTERBRIDGE_CAMERA_VIDEO_BITRATE = String(this.config.videoBitrate);
|
|
49
49
|
process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE = this.config.audioGenerator;
|
|
50
|
+
if (this.config.audioSource === undefined)
|
|
51
|
+
delete process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE;
|
|
52
|
+
else
|
|
53
|
+
process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE = this.config.audioSource;
|
|
50
54
|
this.log.debug(`Platform ${this.config.name} config:\n${RESET}${inspect(this.config, { depth: 10, colors: true })}`);
|
|
51
55
|
this.log.debug(`Platform ${this.config.name} environment variables:\n${RESET}${inspect({
|
|
52
56
|
MATTERBRIDGE_CAMERA_VIDEO_SOURCE: process.env.MATTERBRIDGE_CAMERA_VIDEO_SOURCE,
|
|
@@ -54,6 +58,7 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
|
|
|
54
58
|
MATTERBRIDGE_CAMERA_VIDEO_RESOLUTION: process.env.MATTERBRIDGE_CAMERA_VIDEO_RESOLUTION,
|
|
55
59
|
MATTERBRIDGE_CAMERA_VIDEO_BITRATE: process.env.MATTERBRIDGE_CAMERA_VIDEO_BITRATE,
|
|
56
60
|
MATTERBRIDGE_CAMERA_AUDIO_SOURCE: process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE,
|
|
61
|
+
MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE: process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE,
|
|
57
62
|
}, { depth: 10, colors: true })}`);
|
|
58
63
|
this.log.info(`Platform ${this.config.name} initialized successfully`);
|
|
59
64
|
}
|
|
@@ -5,6 +5,7 @@ import { access, readdir } from 'node:fs/promises';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
8
|
+
import { fireAndForget, getErrorMessage } from 'matterbridge/utils';
|
|
8
9
|
import { RTCPeerConnection, RTCRtpCodecParameters, useH264, useOPUS, usePCMU, useVP8 } from 'werift';
|
|
9
10
|
import { navigator } from 'werift/nonstandard';
|
|
10
11
|
export class WeriftWebRtcSession {
|
|
@@ -319,7 +320,7 @@ export class WeriftWebRtcSession {
|
|
|
319
320
|
this.log.debug(`Spawning ffmpeg: ${ffmpegCommand} ${ffmpegArgs.join(' ')}`);
|
|
320
321
|
const generator = spawn(ffmpegCommand, ffmpegArgs);
|
|
321
322
|
generator.once('error', (error) => {
|
|
322
|
-
this.log.warn(`Video generator failed: ${
|
|
323
|
+
this.log.warn(`Video generator failed: ${getErrorMessage(error)}`);
|
|
323
324
|
});
|
|
324
325
|
this.testVideoUdpDisposer = disposer;
|
|
325
326
|
this.testVideoGenerator = generator;
|
|
@@ -327,7 +328,7 @@ export class WeriftWebRtcSession {
|
|
|
327
328
|
this.log.info(`Attached ${videoInput.description} video track (ffmpeg=${ffmpegCommand}, codec=${selectedMimeType}, payloadType=${selectedPayloadType}, sourcePort=${udpPort})`);
|
|
328
329
|
}
|
|
329
330
|
catch (error) {
|
|
330
|
-
this.log.warn(`Failed to attach ${videoInput.description} video track: ${
|
|
331
|
+
this.log.warn(`Failed to attach ${videoInput.description} video track: ${getErrorMessage(error)}`);
|
|
331
332
|
}
|
|
332
333
|
}
|
|
333
334
|
preferVideoCodecOnTransceivers(mimeType) {
|
|
@@ -361,13 +362,61 @@ export class WeriftWebRtcSession {
|
|
|
361
362
|
}
|
|
362
363
|
}
|
|
363
364
|
static TEST_VOICE_PATH = fileURLToPath(new URL('../../assets/test-voice.opus', import.meta.url));
|
|
365
|
+
getConfiguredAudioSource() {
|
|
366
|
+
const source = process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE?.trim().toLowerCase() ?? 'none';
|
|
367
|
+
switch (source) {
|
|
368
|
+
case 'none':
|
|
369
|
+
case 'test':
|
|
370
|
+
case 'microphone':
|
|
371
|
+
case 'rtsp':
|
|
372
|
+
return source;
|
|
373
|
+
default:
|
|
374
|
+
this.log.warn(`Unsupported MATTERBRIDGE_CAMERA_AUDIO_SOURCE "${source}" (supported: test, microphone, rtsp, none); falling back to none`);
|
|
375
|
+
return 'none';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
buildFfmpegAudioInputArgs(audioSource) {
|
|
379
|
+
const testVoiceInput = {
|
|
380
|
+
args: ['-re', '-stream_loop', '-1', '-i', WeriftWebRtcSession.TEST_VOICE_PATH],
|
|
381
|
+
description: 'recorded test-voice clip',
|
|
382
|
+
volumeFilter: 'volume=6dB',
|
|
383
|
+
};
|
|
384
|
+
if (audioSource === 'test')
|
|
385
|
+
return testVoiceInput;
|
|
386
|
+
const device = process.env.MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE;
|
|
387
|
+
if (!device) {
|
|
388
|
+
this.log.warn(`MATTERBRIDGE_CAMERA_AUDIO_SOURCE=${audioSource} requires MATTERBRIDGE_CAMERA_AUDIO_SOURCE_DEVICE to be set; falling back to the recorded test-voice clip`);
|
|
389
|
+
return testVoiceInput;
|
|
390
|
+
}
|
|
391
|
+
if (audioSource === 'rtsp') {
|
|
392
|
+
const description = `RTSP camera audio (${device})`;
|
|
393
|
+
this.log.debug(`RTSP audio capture params: url=${device}, description="${description}"`);
|
|
394
|
+
return { args: ['-rtsp_transport', 'tcp', '-i', device], description };
|
|
395
|
+
}
|
|
396
|
+
const description = `local microphone (${device})`;
|
|
397
|
+
this.log.debug(`Microphone capture params: device=${device}, description="${description}"`);
|
|
398
|
+
switch (process.platform) {
|
|
399
|
+
case 'linux':
|
|
400
|
+
return { args: ['-f', 'alsa', '-i', device], description };
|
|
401
|
+
case 'darwin':
|
|
402
|
+
return { args: ['-f', 'avfoundation', '-i', `:${device}`], description };
|
|
403
|
+
case 'win32':
|
|
404
|
+
return { args: ['-f', 'dshow', '-i', `audio=${device}`], description };
|
|
405
|
+
default:
|
|
406
|
+
this.log.warn(`Microphone capture via ffmpeg is not supported on platform "${process.platform}"; falling back to the recorded test-voice clip`);
|
|
407
|
+
return testVoiceInput;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
364
410
|
async generateAudioTrack(codec) {
|
|
365
411
|
if (this.testAudioAttached)
|
|
366
412
|
return;
|
|
367
|
-
|
|
368
|
-
|
|
413
|
+
const audioSource = this.getConfiguredAudioSource();
|
|
414
|
+
if (audioSource === 'none') {
|
|
415
|
+
this.log.debug('Audio injection disabled by MATTERBRIDGE_CAMERA_AUDIO_SOURCE=none');
|
|
369
416
|
return;
|
|
370
417
|
}
|
|
418
|
+
const audioInput = this.buildFfmpegAudioInputArgs(audioSource);
|
|
419
|
+
this.log.debug(`Attempting to attach ${audioInput.description} audio track`);
|
|
371
420
|
const ffmpegCommand = await this.resolveCommand('ffmpeg');
|
|
372
421
|
if (!ffmpegCommand) {
|
|
373
422
|
this.log.warn('Cannot inject audio stream: missing dependency ffmpeg');
|
|
@@ -388,14 +437,9 @@ export class WeriftWebRtcSession {
|
|
|
388
437
|
'-hide_banner',
|
|
389
438
|
'-loglevel',
|
|
390
439
|
'error',
|
|
391
|
-
|
|
392
|
-
'-stream_loop',
|
|
393
|
-
'-1',
|
|
394
|
-
'-i',
|
|
395
|
-
WeriftWebRtcSession.TEST_VOICE_PATH,
|
|
440
|
+
...audioInput.args,
|
|
396
441
|
'-vn',
|
|
397
|
-
'-af',
|
|
398
|
-
'volume=6dB',
|
|
442
|
+
...(audioInput.volumeFilter ? ['-af', audioInput.volumeFilter] : []),
|
|
399
443
|
'-c:a',
|
|
400
444
|
'libopus',
|
|
401
445
|
'-b:a',
|
|
@@ -413,15 +457,15 @@ export class WeriftWebRtcSession {
|
|
|
413
457
|
this.log.debug(`Spawning ffmpeg: ${ffmpegCommand} ${ffmpegArgs.join(' ')}`);
|
|
414
458
|
const generator = spawn(ffmpegCommand, ffmpegArgs);
|
|
415
459
|
generator.once('error', (error) => {
|
|
416
|
-
this.log.warn(`Audio generator failed: ${
|
|
460
|
+
this.log.warn(`Audio generator failed: ${getErrorMessage(error)}`);
|
|
417
461
|
});
|
|
418
462
|
this.testAudioUdpDisposer = disposer;
|
|
419
463
|
this.testAudioGenerator = generator;
|
|
420
464
|
this.testAudioAttached = true;
|
|
421
|
-
this.log.info(`Attached
|
|
465
|
+
this.log.info(`Attached ${audioInput.description} audio track (ffmpeg=${ffmpegCommand}, codec=${selectedMimeType}, payloadType=${selectedPayloadType}, sourcePort=${udpPort})`);
|
|
422
466
|
}
|
|
423
467
|
catch (error) {
|
|
424
|
-
this.log.warn(`Failed to attach
|
|
468
|
+
this.log.warn(`Failed to attach ${audioInput.description} audio track: ${getErrorMessage(error)}`);
|
|
425
469
|
}
|
|
426
470
|
}
|
|
427
471
|
cleanupTestVideoArtifacts() {
|
|
@@ -512,6 +556,7 @@ export class WeriftWebRtcSession {
|
|
|
512
556
|
this.log.debug(`Applying ICE candidate (mid=${sdpMid ?? 'null'}, mLine=${sdpMLineIndex ?? 'null'}, endOfCandidates=${candidate.trim() === ''})`);
|
|
513
557
|
await this.peerConnection.addIceCandidate({ candidate, sdpMid: sdpMid ?? undefined, sdpMLineIndex: sdpMLineIndex ?? undefined });
|
|
514
558
|
}
|
|
559
|
+
closing = false;
|
|
515
560
|
logDtlsTransportStateChanges() {
|
|
516
561
|
for (const transport of this.peerConnection.dtlsTransports) {
|
|
517
562
|
if (this.dtlsTransportsWithStateLogging.has(transport))
|
|
@@ -519,6 +564,10 @@ export class WeriftWebRtcSession {
|
|
|
519
564
|
this.dtlsTransportsWithStateLogging.add(transport);
|
|
520
565
|
transport.onStateChange.subscribe((state) => {
|
|
521
566
|
this.log.info(`DTLS transport state: ${state}`);
|
|
567
|
+
if ((state === 'closed' || state === 'failed') && !this.closing) {
|
|
568
|
+
this.log.info(`Closing session ${this.webRtcSessionId}: DTLS transport reached ${state}`);
|
|
569
|
+
fireAndForget(this.close(), this.log, `Failed to auto-close session ${this.webRtcSessionId} after DTLS transport reached ${state}`);
|
|
570
|
+
}
|
|
522
571
|
});
|
|
523
572
|
}
|
|
524
573
|
}
|
|
@@ -551,6 +600,9 @@ export class WeriftWebRtcSession {
|
|
|
551
600
|
].join('\n'));
|
|
552
601
|
}
|
|
553
602
|
async close() {
|
|
603
|
+
if (this.closing)
|
|
604
|
+
return;
|
|
605
|
+
this.closing = true;
|
|
554
606
|
this.log.debug('Closing RTCPeerConnection');
|
|
555
607
|
clearInterval(this.diagnosticsInterval);
|
|
556
608
|
this.diagnosticsInterval = undefined;
|
|
@@ -69,11 +69,16 @@
|
|
|
69
69
|
},
|
|
70
70
|
"audioGenerator": {
|
|
71
71
|
"title": "Audio Generator",
|
|
72
|
-
"description": "Select the WebRTC audio generator: none disables track injection (only the audio transceiver is negotiated),
|
|
72
|
+
"description": "Select the WebRTC audio generator: none disables track injection (only the audio transceiver is negotiated), test injects a recorded test-voice clip, looped, e.g. for an Intercom's Listen live view, microphone captures from the configured local microphone, and rtsp pulls the audio from the RTSP url configured in Audio Source.",
|
|
73
73
|
"type": "string",
|
|
74
|
-
"enum": ["none", "test"],
|
|
74
|
+
"enum": ["none", "test", "microphone", "rtsp"],
|
|
75
75
|
"default": "none"
|
|
76
76
|
},
|
|
77
|
+
"audioSource": {
|
|
78
|
+
"title": "Audio Source",
|
|
79
|
+
"description": "OS-specific ffmpeg microphone identifier, such as hw:0,0 on Linux (alsa), 0 on macOS (avfoundation audio index), or Microphone Array on Windows (dshow). When Audio Generator is rtsp, this holds the RTSP url instead, e.g. rtsp://user:password@host:554/path.",
|
|
80
|
+
"type": "string"
|
|
81
|
+
},
|
|
77
82
|
"debug": {
|
|
78
83
|
"title": "Enable Debug",
|
|
79
84
|
"description": "Enable the debug for the plugin (development only)",
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-example-camera",
|
|
3
|
-
"version": "0.0.8
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-example-camera",
|
|
9
|
-
"version": "0.0.8
|
|
9
|
+
"version": "0.0.8",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"node-ansi-logger": "3.3.0",
|