Skip to content

createReplaceableTrack

function createReplaceableTrack<F>(publisher, options): ReplaceableTrack<F>;

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

Publish a track that can be replaced by a new one, listed in the catalog in its place (spec/media-layer.md, “Track replacement”). msf-01 §5.3 makes a changed track a new name; a listener that sees the catalog list a new track in place of the one it plays (@caprid/moq-media’s findReplacementTrack) drops the old track’s audio and plays the new one.

const catalog = createDocumentService(publisher.registerTrack({ track: CATALOG_TRACK }));
void catalog.serve();
const reply = createReplaceableTrack(publisher, {
track: AUDIO_TRACK,
trackProperties: locTrackProperties(),
catalog: { service: catalog, build: (name) => buildMsfCatalog({ namespace, media: [{ role: 'audio', name }] }) },
});
void reply.write(frame);
// Talked over: the reply so far is dropped, and the next one goes out on a new track.
await reply.replace();
Type Parameter Default type
F extends Frame Frame
Parameter Type
publisher Pick<RelayPublisher, "registerTrack">
options ReplaceableTrackOptions<F>

ReplaceableTrack<F>