Skip to content

Data track integration#1820

Open
1egoman wants to merge 98 commits intomainfrom
data-track-integration
Open

Data track integration#1820
1egoman wants to merge 98 commits intomainfrom
data-track-integration

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented Feb 20, 2026

Integrates the data track managers (both incoming and outgoing) into the existing sdk Room and RemoteParticipant interfaces. Once this is merged, data tracks is fully implemented!

Interface - Publishing

const localDataTrack = await room.publishDataTrack({name: "data track name"});
await localDataTrack.tryPush(new Uint8Array(/* ... */));

// Once you are done with the local data track, it can be unpublished:
await localDataTrack.unpublish();

Interface - Subscribing

// There are two ways to get a remote data track, either a room event:
room.on(RoomEvent.RemoteDataTrackPublished, async (remoteDataTrack) => {
  // ...
});

// Or a new field on `RemoteParticipant`:
const remoteDataTrack = remoteParticipant.dataTracks.get("track name"); // Get a data track which has been published
const remoteDataTrack = await remoteParticipant.dataTracks.getDeferred("track name"); // Get a data track which _will_ be published shortly

// Either way, once you have a remoteDataTrack, you can subscribe:
const stream = await remoteDataTrack.subscribe(/* optional abort signal */);
for await (const frame of stream) {
  console.log(`Received bytes from ${remoteDataTrack.info.name}:`, frame.payload);
}

Todo:

Resolves CLT-2582

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: f63d21c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 24, 2026

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 94.89 KB (+9.4% 🔺)
dist/livekit-client.umd.js 103.7 KB (+6.61% 🔺)

@1egoman 1egoman force-pushed the data-track-integration branch 2 times, most recently from 2f31fbc to 6a5960d Compare February 25, 2026 21:48
@1egoman 1egoman force-pushed the data-track-integration branch from 6a5960d to 2e6f8cf Compare March 5, 2026 20:51
@1egoman 1egoman changed the title (WIP) Data track integration Data track integration Mar 5, 2026
@ladvoc ladvoc self-requested a review March 6, 2026 22:09
@1egoman 1egoman force-pushed the data-track-integration branch from 2619816 to 8e7a138 Compare March 16, 2026 17:40
1egoman added a commit that referenced this pull request Mar 16, 2026
@1egoman 1egoman marked this pull request as ready for review March 16, 2026 18:38
1egoman added 9 commits March 23, 2026 16:44
…dle the separate data tracks data channel

The old way this worked, channelKind was being computed based on
maxRetransmits === 0. But now there are multiple lossy data channels,
the regular one and the data tracks one, so this heuristic no longer
works.
…s are buffered when the dc is in low status

This was encountered when implementing the e2e tests - a large data
track frame could be split up into potentially n packets, and if one
packet is dropped the whole frame is considered dropped. So the behavior
that is really wanted here is to buffer packets and send them once the
data channel can accept more data, even though it is technically a lossy
data channel.
…channels

When operating in dual peer connection contexts, this is required.
@1egoman 1egoman requested a review from lukasIO March 26, 2026 19:37
Copy link
Copy Markdown
Contributor

@lukasIO lukasIO left a comment

Choose a reason for hiding this comment

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

a couple of nits that would be nice to address.

More generally and important: what happens currently when running this against older servers that don't have DataTrack support?

return;
if (!this.isBufferStatusLow(kind)) {
// Depending on the exact circumstance that data is being sent, either drop or wait for the
// buffer status to not be low before continuing.
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's the intention behind this differentiation? Why not just drop them for lossy?

Copy link
Copy Markdown
Contributor Author

@1egoman 1egoman Mar 30, 2026

Choose a reason for hiding this comment

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

That's what I originally was doing but this didn't work for large data track payloads - here is some more context as to why from some notes I wrote up:

  • If the _data_tracks rtc data channel buffer was full, the existing logic would drop packets (what the lossy data channel currently does).
    • This doesn't work though for data track packets, because if the first n packets of a frame get enqueued but the last packet(s) get dropped because there isn't enough room in the rtc data channel buffer, the receiver only receives a partial set of packets which will never fully decode into a data track frame.
    • If packets aren't buffered like this, then it becomes impossible to send data track payloads > ~75k bytes (the e2e tests are checking this case)
    • Solution (commit): buffer data track packets instead of dropping them if the rtc data channel buffer is full

If there's some other way to handle this, I'm open to alternatives but what I did here was the most straightforward way I could think of.

@1egoman
Copy link
Copy Markdown
Contributor Author

1egoman commented Mar 31, 2026

To provide context on this:

what happens currently when running this against older servers that don’t have DataTrack support?

After talking with @ladvoc , I can confirm that on the subscribing end the new messages are just dropped, and on the publishing end the failure would end up as a timeout error. So nothing breaks in a incredibly bad way here.

We decided that including a note in the publish function docstring and also maybe a small comment in the timeout error message would be good enough to guard against this - did this here.

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.

5 participants