@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
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
- Sink For the sink contract this implements
- CallbackSinkHandlers For the available lifecycle handlers
Implements
Constructors
Constructor
new CallbackSink(
handlers):CallbackSink
Defined in: sinks/callback.ts:75
Create a callback-backed sink.
Parameters
handlers
Lifecycle callbacks invoked on init, per packet, and on close
Returns
CallbackSink
Example
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
await sink.close();Implementation of
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
Resolved description of the tracks the source carries
Returns
void | Promise<void>
The handler's result, awaited by the relay before packets flow
Example
await sink.init(streamInfo);Implementation of
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
The keyframe-gated media packet to consume
Returns
void | Promise<void>
The handler's result, awaited by the relay before the next packet
Example
await sink.write(packet);