Skip to content

Move data streams into their own crate#1227

Draft
1egoman wants to merge 15 commits into
mainfrom
data-streams-refactor
Draft

Move data streams into their own crate#1227
1egoman wants to merge 15 commits into
mainfrom
data-streams-refactor

Conversation

@1egoman

@1egoman 1egoman commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

PR description

Breaks out a subset of the changes from #1192 into a pull request which exclusively moves the existing data streams implementation into its own crate, livekit-data-streams, and adds a new livekit-common crate (kept fairly minimal for now) for common utilities which livekit-data-streams and livekit both need.

This is largely being scoped to a "lift and shift" type effort, more extensive refactoring of the livekit-data-streams crate will be done in #1192.

Breaking changes

There should not be any breaking changes from the perspective of livekit's public api. If so, please surface them.

Testing

This pull request doesn't right now add any new test coverage beyond the existing fairly minimal e2e test coverage.

@1egoman 1egoman requested a review from ladvoc as a code owner July 7, 2026 20:23
@1egoman 1egoman marked this pull request as draft July 7, 2026 20:23
@1egoman 1egoman removed the request for review from ladvoc July 7, 2026 20:23
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit patch
livekit-ffi patch

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Open in Devin Review

Comment thread Cargo.toml
Comment thread livekit-data-stream/src/lib.rs Outdated
Comment thread livekit/src/utils/take_cell.rs
@1egoman 1egoman force-pushed the data-streams-refactor branch from 1e4e420 to 4492d6e Compare July 7, 2026 20:57
Comment on lines 241 to +244
impl IncomingStreamManager {
pub fn new() -> (Self, UnboundedReceiver<(AnyStreamReader, String)>) {
pub fn new(
reserved_topics: Vec<String>,
) -> (Self, UnboundedReceiver<(AnyStreamReader, String)>) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Notable change: Instead of looking at a well known global, IncomingStreamManager now takes a list of reserved_topics so that upstream layers can pass down a list of reserved topics in a decoupled fashion.

Comment on lines 254 to 261
impl AnyStreamInfo {
enum_dispatch!(
[Byte, Text];
pub fn id(self: &Self) -> &str;
pub fn total_length(self: &Self) -> Option<u64>;
pub fn encryption_type(self: &Self) -> EncryptionType;
);
pub fn id(&self) -> &str {
match self {
Self::Byte(info) => info.id(),
Self::Text(info) => info.id(),
}
}

pub fn total_length(&self) -> Option<u64> {
match self {
Self::Byte(info) => info.total_length(),
Self::Text(info) => info.total_length(),
}
}

pub fn encryption_type(&self) -> EncryptionType {
match self {
Self::Byte(info) => info.encryption_type(),
Self::Text(info) => info.encryption_type(),
}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: I have dropped libwebrtc::enum_dispatch and written the implementation myself to avoid making libwebrtc a dependency of livekit-data-streams.

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.

How about moving enum_dispatch to livekit-common?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yea, I could do that - done in 433b85d.

I've kept the libwebrtc copy around so that it isn't coupled to livekit-common, IMO the goal should be to migrate all users to livekit_common::enum_dispatch and then drop the libwebrtc version.

Comment on lines 28 to 41

/// Take ownership of the value in the cell if it matches some predicate.
///
/// This method will only take the value if the provided predicate returns `true` when called with the current value.
/// If the predicate returns `false` or the value has already been taken, this method returns `None`.
pub(crate) fn take_if_raw(&self, predicate: impl FnOnce(&T) -> bool) -> Option<T> {
if self.value.read().as_ref().map_or(false, |v| predicate(v)) {
self.take()
} else {
None
}
}

/// Take ownership of the value in the cell. If the value has,

@1egoman 1egoman Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers - this was dead code.

Comment thread livekit-data-stream/src/lib.rs
Comment on lines +9 to +15

[features]
# End-to-end testing hooks (exposes is_compressed/is_inline on stream info). Forwarded from
# the `livekit` crate's `__lk-e2e-test` feature.
__e2e-test = []
# Exposes constructors used by downstream crates' test suites (e.g. `TextStreamReader::new_for_test`).
test-utils = []

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: should these be separate features or just one?

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 we need to keep them, they should be separate (I plan to eventually drop the special feature for E2E testing and instead just skip E2E tests based on env).

However, there's the bigger question of if we should be using non-public methods in integration tests in the first place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

However, there's the bigger question of if we should be using non-public methods in integration tests in the first place.

Right now, that's how it works so I don't think this makes it worse. IMO I'd rather decouple that conversation and revisit as part of the data streams v2 pull request since I will be making some more extensive updates there.

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