Skip to content

Add local data track flush method#1925

Open
1egoman wants to merge 2 commits intomainfrom
add-local-data-track-flush
Open

Add local data track flush method#1925
1egoman wants to merge 2 commits intomainfrom
add-local-data-track-flush

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented Apr 28, 2026

When called, waits for all in flight packets to be sent before resolving. Use this to:

  1. Send frames exactly in order:
await localDataTrack.tryPush(/* ... */);
await localDataTrack.flush();

await localDataTrack.tryPush(/* ... */);
await localDataTrack.flush();

// ... etc ...
  1. Wait for frames to all be delivered before unpublishing a local data track:
await localDataTrack.tryPush(/* ... */);
await localDataTrack.tryPush(/* ... */);
await localDataTrack.tryPush(/* ... */);
// ... etc ...
await localDataTrack.flush();
await localDataTrack.unpublish();

When called, waits for all in flight packets to be sent before resolving. Use this to:

1. Send frames exactly in order:
```ts
await track.tryPush(/* ... *\/);
await track.flush();
await track.tryPush(/* ... *\/);
await track.flush();
// ... etc ...
```

2. Wait for frames to all be delivered before unpublishing a local data track:

```ts
await track.tryPush(/* ... *\/);
await track.tryPush(/* ... *\/);
await track.tryPush(/* ... *\/);
// ... etc ...
await track.flush();
await track.unpublish();
```
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: 0914a18

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 97.14 KB (+0.21% 🔺)
dist/livekit-client.umd.js 106.02 KB (+0.12% 🔺)

protected log: StructuredLogger = log;

/** Resolves once the data track has sent all pending packets the rtc data channel buffer. */
protected flushedFuture = new Future<void, never>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should happen to this future if the room disconnects while flushing?

Comment thread src/room/Room.ts
this.engine.sendLossyBytes(bytes, DataChannelKind.DATA_TRACK_LOSSY, 'wait');
.on('packetAvailable', ({ handle, bytes }) => {
this.engine
.sendLossyBytes(bytes, DataChannelKind.DATA_TRACK_LOSSY, 'wait')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sendLossyBytes rejects should we still call the handlePacketSendComplete ? Otherwise the counter might get out of sync as there are no retries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants