Skip to content

@seydx/rtsp / Sink

Interface: Sink ​

Defined in: types.ts:515

A consumer of the relayed stream.

The relay calls init once with the resolved stream info, then write for each packet destined for this sink (already keyframe-gated), and finally close on teardown. The relay frees each packet after the write promise resolves, so a sink must not retain a packet beyond that point; if it needs to hold one, it must clone it first.

Example ​

typescript
import { Sink, StreamInfo, MediaPacket } from '@seydx/rtsp';

const sink: Sink = {
  init(info: StreamInfo) { setup(info); },
  write(packet: MediaPacket) { forward(packet); },
  close() { teardown(); },
};

See ​

Methods ​

close() ​

close(): void | Promise<void>

Defined in: types.ts:565

Tear the sink down.

Called when the relay stops, allowing the sink to flush and release any resources it acquired during init.

Returns ​

void | Promise<void>

Nothing, or a promise that resolves once teardown completes

Example ​

typescript
await sink.close();

init() ​

init(info): void | Promise<void>

Defined in: types.ts:531

Initialize the sink with the resolved stream layout.

Called once before any packet is written, giving the sink the chance to configure muxers, encoders, or output channels from the source's tracks.

Parameters ​

info ​

StreamInfo

The resolved stream information for the source being relayed

Returns ​

void | Promise<void>

Nothing, or a promise that resolves once initialization completes

Example ​

typescript
await sink.init(info);

write() ​

write(packet): void | Promise<void>

Defined in: types.ts:550

Write a single packet to the sink.

Called per packet destined for this sink, already keyframe-gated by the relay. The packet is owned by the relay and freed once the returned promise resolves, so the sink must clone it to retain it beyond this call.

Parameters ​

packet ​

MediaPacket

The media packet to consume

Returns ​

void | Promise<void>

Nothing, or a promise that resolves once the packet has been consumed

Example ​

typescript
await sink.write(packet);