@seydx/rtsp / AvSource
Class: AvSource
Defined in: sources/av.ts:184
A relay source backed by node-av's demuxer.
Because libav handles the input, a single instance covers RTSP, TCP, HTTP(S), local files and raw byte streams behind one uniform interface — the relay never sees the difference. When pointed at an RTSP camera, it can also expose the ONVIF backchannel so viewer audio can be sent back upstream, and it can pace or loop finite inputs to behave like a continuous live stream.
Examples
import { AvSource, Relay } from '@seydx/rtsp';
// Live RTSP camera over TCP with talkback enabled.
const source = new AvSource('rtsp://user:pass@camera.local/stream', {
transport: 'tcp',
backchannel: true,
});
const relay = new Relay({ source });
await relay.start();import { AvSource } from '@seydx/rtsp';
// Serve a file as a looping live stream paced to real time.
const source = new AvSource('/media/clip.mp4', { readrate: 1, loop: true });See
- Source For the relay source contract
- BackchannelSource For the talkback contract this source implements
- Relay For wiring a source to one or more sinks
Implements
Constructors
Constructor
new AvSource(
input,opts?):AvSource
Defined in: sources/av.ts:203
Create a source for the given input.
No I/O happens here; the input is opened lazily by AvSource.open.
Parameters
input
URL, path, or in-memory buffer to demux
opts?
AvSourceOptions = {}
Options controlling transport, timeout, pacing, looping and the backchannel
Returns
AvSource
Accessors
backchannel
Get Signature
get backchannel():
BackchannelInfo|undefined
Defined in: sources/av.ts:223
The upstream talkback format, once known.
Populated by AvSource.open when AvSourceOptions.backchannel is enabled and the camera advertises a send-only stream; otherwise undefined.
Example
await source.open();
if (source.backchannel) {
console.log('talkback codec:', source.backchannel.codec);
}Returns
BackchannelInfo | undefined
The negotiated backchannel format, once known.
Present only after the upstream is open and has advertised a backchannel; remains undefined while closed or when the upstream offers no talkback.
Implementation of
Methods
close()
close():
Promise<void>
Defined in: sources/av.ts:343
Release the input and all associated native resources.
Safe to call more than once and at any time, including before AvSource.open. After closing, the source can be reopened with a fresh AvSource.open call.
Returns
Promise<void>
A promise that resolves once the source is fully closed
Example
await source.close();Implementation of
open()
open():
Promise<StreamInfo>
Defined in: sources/av.ts:245
Open the input and resolve its stream layout.
Establishes the demuxer connection and, when the backchannel is requested, reads the camera's talkback descriptor. Must be called once before AvSource.packets.
Returns
Promise<StreamInfo>
The resolved stream info, including tracks and an optional backchannel descriptor
Throws
If node-av fails to open the input
Example
const source = new AvSource('rtsp://camera.local/stream');
const info = await source.open();
console.log(info.tracks.map((t) => t.codec));Implementation of
packets()
packets(
signal):AsyncIterable<MediaPacket>
Defined in: sources/av.ts:301
Yield demuxed media packets until the signal aborts or the input ends.
Drives one read pass over the input; when AvSourceOptions.loop is enabled, the input is reopened on completion and streaming continues on the same wall clock until aborted. AvSource.open must have been called first.
Parameters
signal
AbortSignal
Abort signal that stops iteration and aborts any in-flight pacing delay
Returns
AsyncIterable<MediaPacket>
Yields
Demuxed media packets (each must be freed by the caller)
Throws
If called before AvSource.open
Example
const ac = new AbortController();
await source.open();
for await (const packet of source.packets(ac.signal)) {
handle(packet);
packet.free();
}Implementation of
sendBackchannel()
sendBackchannel(
rtp):void
Defined in: sources/av.ts:269
Send one RTP packet of talkback audio back to the camera.
The payload must already be encoded in the backchannel codec described by AvSource.backchannel. The call is a no-op when the input is not open or no backchannel is available, and send failures are logged rather than thrown.
Parameters
rtp
Buffer
A single RTP packet in the backchannel codec
Returns
void
Example
if (source.backchannel) {
source.sendBackchannel(rtpPacket);
}