Skip to content

@seydx/rtsp / Source

Interface: Source

Defined in: types.ts:438

A single-connection upstream that produces media.

Models the lifecycle of one upstream connection: open establishes it and resolves the stream layout, packets yields demuxed packets until the caller aborts or the stream ends, and close tears the connection down. The relay drives exactly one source at a time and fans its packets out to the configured sinks.

Example

typescript
import { Source } from '@seydx/rtsp';

const info = await source.open();
const controller = new AbortController();
for await (const packet of source.packets(controller.signal)) {
  // route packet.streamIndex to the matching sink
}
await source.close();

See

  • Sink For the consuming side of the relay
  • StreamInfo For what open resolves

Methods

close()

close(): Promise<void>

Defined in: types.ts:488

Release the upstream connection and associated resources.

Closes the connection opened by open. Safe to call after iteration has finished or been aborted.

Returns

Promise<void>

A promise that resolves once the connection is fully closed

Example

typescript
await source.close();

open()

open(): Promise<StreamInfo>

Defined in: types.ts:454

Establish the connection and resolve the stream layout.

Connects to the upstream and probes its tracks, returning the resolved description once the layout is known. Must complete before packets is consumed.

Returns

Promise<StreamInfo>

The resolved stream information describing the source's tracks and optional backchannel

Example

typescript
const info = await source.open();

packets()

packets(signal): AsyncIterable<MediaPacket>

Defined in: types.ts:473

Yield demuxed packets until aborted or the stream ends.

Produces an async iterable of MediaPacket values. Iteration stops when the provided signal aborts or the upstream stream ends.

Parameters

signal

AbortSignal

Abort signal that stops iteration when triggered

Returns

AsyncIterable<MediaPacket>

An async iterable of demuxed media packets

Example

typescript
for await (const packet of source.packets(controller.signal)) {
  handle(packet);
}