# ReplaceableTrack

URL: https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/replaceabletrack/

Defined in: [relay-sdks/ts/src/replaceable-track.ts:68](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L68)

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](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/functions/createreplaceabletrack/).

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-f"></a> `F` *extends* [`Frame`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/frame/) | [`Frame`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/frame/) |

## Properties

### closed

```ts
readonly closed: boolean;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:88](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L88)

True once [close](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/replaceabletrack/#close) ran.

***

### replacements

```ts
readonly replacements: number;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:72](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L72)

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

***

### track

```ts
readonly track: string;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:70](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L70)

The current track's name.

## Methods

### close()

```ts
close(): Promise<void>;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:86](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L86)

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

#### Returns

`Promise`\<`void`\>

***

### replace()

```ts
replace(): Promise<TrackReplacement>;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:84](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L84)

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.

#### Returns

`Promise`\<[`TrackReplacement`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/trackreplacement/)\>

***

### write()

```ts
write(frame): Promise<FrameOutcome>;
```

Defined in: [relay-sdks/ts/src/replaceable-track.ts:78](https://github.com/caprids/relay-sdks/blob/main/ts/src/replaceable-track.ts#L78)

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'`.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `frame` | `F` |

#### Returns

`Promise`\<[`FrameOutcome`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/frameoutcome/)\>
