Skip to content

ReplaceableTrack

Defined in: relay-sdks/ts/src/replaceable-track.ts:68

A track that the publisher can replace mid-stream, for barge-in: a voice agent talked over replaces its reply track, and listeners drop the old reply’s audio and play the new track. Create one with createReplaceableTrack.

Type Parameter Default type
F extends Frame Frame
readonly closed: boolean;

Defined in: relay-sdks/ts/src/replaceable-track.ts:88

True once close ran.


readonly replacements: number;

Defined in: relay-sdks/ts/src/replaceable-track.ts:72

How many times the track has been replaced: 0 while the first track plays.


readonly track: string;

Defined in: relay-sdks/ts/src/replaceable-track.ts:70

The current track’s name.

close(): Promise<void>;

Defined in: relay-sdks/ts/src/replaceable-track.ts:86

Drop what has not been sent and close the current track. Idempotent; write and replace reject after it.

Promise<void>


replace(): Promise<TrackReplacement>;

Defined in: relay-sdks/ts/src/replaceable-track.ts:84

Replace the track: register the next track, list it in the catalog in the current track’s place, then drop what the current track has not sent and close it. Resolves once the old track is closed. Frames written from the call on go to the new track.

Promise<TrackReplacement>


write(frame): Promise<FrameOutcome>;

Defined in: relay-sdks/ts/src/replaceable-track.ts:78

Send one frame on the current track and say what happened, as FrameWriter.write does. A frame written to a replacement before the relay has subscribed to it waits (demandWaitMs). A frame of a track that is replaced before it went out is 'dropped'.

Parameter Type
frame F

Promise<FrameOutcome>