Skip to content

@seydx/rtsp / CallbackSink

Class: CallbackSink ​

Defined in: sinks/callback.ts:64

The simplest sink: hands every keyframe-gated packet to a callback.

Wraps a set of lifecycle handlers behind the Sink interface so raw consumers, tests, and ad-hoc integrations can observe the relayed stream without implementing a full sink class. It is also the canonical reference implementation of Sink. Each delivered packet is only valid for the duration of the packet handler — copy out anything that must be kept.

Example ​

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

const sink = new CallbackSink({
  onInit: (info) => console.log('tracks:', info.tracks.length),
  onPacket: (packet) => console.log('packet on stream', packet.streamIndex),
  onClose: () => console.log('done'),
});

See ​

Implements ​

Constructors ​

Constructor ​

new CallbackSink(handlers): CallbackSink

Defined in: sinks/callback.ts:75

Create a callback-backed sink.

Parameters ​

handlers ​

CallbackSinkHandlers

Lifecycle callbacks invoked on init, per packet, and on close

Returns ​

CallbackSink

Example ​

typescript
const sink = new CallbackSink({ onPacket: (packet) => buffer.push(packet.clone()) });

Methods ​

close() ​

close(): void | Promise<void>

Defined in: sinks/callback.ts:129

Tear down the sink.

Forwards to the CallbackSinkHandlers.onClose handler if one was provided; otherwise resolves immediately.

Returns ​

void | Promise<void>

The handler's result, awaited by the relay during teardown

Example ​

typescript
await sink.close();

Implementation of ​

Sink.close


init() ​

init(info): void | Promise<void>

Defined in: sinks/callback.ts:92

Initialize the sink with the resolved stream layout.

Forwards to the CallbackSinkHandlers.onInit handler if one was provided; otherwise resolves immediately.

Parameters ​

info ​

StreamInfo

Resolved description of the tracks the source carries

Returns ​

void | Promise<void>

The handler's result, awaited by the relay before packets flow

Example ​

typescript
await sink.init(streamInfo);

Implementation of ​

Sink.init


write() ​

write(packet): void | Promise<void>

Defined in: sinks/callback.ts:112

Deliver one packet to the consumer.

Forwards to the CallbackSinkHandlers.onPacket handler if one was provided. The packet is freed by the relay once the returned promise resolves, so the handler must copy out any payload it needs to retain.

Parameters ​

packet ​

MediaPacket

The keyframe-gated media packet to consume

Returns ​

void | Promise<void>

The handler's result, awaited by the relay before the next packet

Example ​

typescript
await sink.write(packet);

Implementation of ​

Sink.write