Skip to content

Enable set_ws_client and set_http_client injectable interfaces - #1290

Open
jhugman wants to merge 2 commits into
mainfrom
jhugman/livekit-net/pr-2
Open

Enable set_ws_client and set_http_client injectable interfaces#1290
jhugman wants to merge 2 commits into
mainfrom
jhugman/livekit-net/pr-2

Conversation

@jhugman

@jhugman jhugman commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

This PR enables the uniffi bindings for livekit-net.

This is not in use by any crates in the livekit-uniffi, so we can safely land it now. However, there should be follow ups to any SDK that uses livekit-uniffi.

Before you submit your PR

Make sure the following is true before submitting your PR:

  • I have read the contributing guidelines and validated that this PR will be accepted.
  • I have read and followed the principles regarding breaking changes, testing, and code quality.

PR description

Describe the changes in this PR. Explain what the PR is meant to solve and how to reproduce the issue in the first place.

Breaking changes

If this PR introduces breaking changes, list them here and document the rationale for introducing such a change.

MSRV

If the PR modifies the crate's MSRV (Minimum Supported Rust Version), document it here.

Testing

Ideally, unit test the code you add, but ensure you're not repeating existing test cases. Use as many already written scaffolding, utilities as possible; write your own, when needed. If external services, APIs, tokens are required (e.g., running an LK server instance), provide the necessary information. Make sure your tests perform useful, context-aware assertions and do not simply emulate "happy paths".

Async

We want the project to be runtime-agnostic, so please reuse what's already in livekit-runtime and feel free to add anything missing. It's ok to use Tokio directly, when writing unit tests, if necessary. When testing, do not use artificial delays for the state to "catch up"; instead, respect the event flow and subscribe properly using channels or other mechanisms.

@jhugman
jhugman requested a review from ladvoc as a code owner July 28, 2026 18:34
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Changeset incomplete

This PR's changeset is missing version bumps for packages that are affected by the change. The following packages still require a bump:

  • livekit
  • livekit-api
  • livekit-ffi

Already covered:

  • livekit-net (patch)
  • livekit-uniffi (patch)

A package must be bumped when its own files change, and whenever a package it depends on is bumped (so downstream consumers get a matching release).

Click here to create a changeset for the missing packages

The link pre-populates a changeset file with patch bumps for the missing packages. You can also add them to your existing changeset. Edit the bump types as needed before committing.

If this change doesn't require a version bump, add the internal label to this PR.

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

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@jhugman
jhugman force-pushed the jhugman/livekit-net/pr-2 branch from 22edc1c to 1546ceb Compare July 28, 2026 18:43
devin-ai-integration[bot]

This comment was marked as resolved.

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

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.

Devin Review found 2 new potential issues.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread livekit-net/src/lib.rs
Comment on lines +85 to +95
/// Test probe: whether a process-wide HTTP client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_http_client() -> bool {
http_client().is_some()
}

/// Test probe: whether a process-wide WebSocket client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_ws_client() -> bool {
ws_client().is_some()
}

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.

🔴 Registration probe reports a client even when none was registered, breaking the new test on native builds

The new probe reports that a client is present (http_client().is_some() at livekit-net/src/lib.rs:88) even when nothing was ever registered, because it counts the crate's built-in fallback, so callers relying on it get the opposite answer to what its description promises and the newly added test fails whenever the crate is built with a built-in backend.
Impact: The transport test suite fails in CI (it is run with the native backend enabled), and hosts using the probe cannot tell whether their own transport was actually installed.

Fallback resolution inside the probes vs. the OnceLock registry

has_http_client/has_ws_client delegate to http_client()/ws_client() (livekit-net/src/lib.rs:99-131), which return Some(native::native_http_client()) whenever the __native marker feature is on, regardless of whether set_http_client was called. The doc comments say "whether a process-wide HTTP client is registered".

The new test asserts the opposite at livekit-net/tests/self_test.rs:61-62 (assert!(!has_http_client())), and CI runs cargo test -p livekit-net --features native-tokio (.github/workflows/tests.yml:172), which enables __native, so both assertions fail.

A correct probe should inspect the registries directly (WS.get().is_some() / HTTP.get().is_some()), or the docs/test need to reflect the fallback.

Suggested change
/// Test probe: whether a process-wide HTTP client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_http_client() -> bool {
http_client().is_some()
}
/// Test probe: whether a process-wide WebSocket client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_ws_client() -> bool {
ws_client().is_some()
}
/// Test probe: whether a process-wide HTTP client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_http_client() -> bool {
HTTP.get().is_some()
}
/// Test probe: whether a process-wide WebSocket client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_ws_client() -> bool {
WS.get().is_some()
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread livekit-net/src/lib.rs
Comment on lines +63 to +95
/// Self-test: GET `url` via the registered HTTP client; returns the full response
/// (status + headers + body) so callers can assert the whole struct round-trips the FFI.
/// Errors if no client is registered or the transport fails.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub async fn self_test_http_get(url: String) -> Result<HttpResponse, TransportError> {
let c =
http_client().ok_or_else(|| TransportError::Other("no http client registered".into()))?;
c.request(HttpMethod::Get, url, Vec::new(), None).await
}

/// Self-test: connect, send `payload`, receive one frame, close; return the echoed bytes.
/// Errors if no client is registered, the transport fails, or the peer closes first.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub async fn self_test_ws_echo(url: String, payload: Vec<u8>) -> Result<Vec<u8>, TransportError> {
let c = ws_client().ok_or_else(|| TransportError::Other("no ws client registered".into()))?;
let conn = c.connect(url, Vec::new(), 5_000).await?.connection;
conn.send(payload).await?;
let got = conn.recv().await?.ok_or(TransportError::Closed)?;
conn.close().await;
Ok(got)
}

/// Test probe: whether a process-wide HTTP client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_http_client() -> bool {
http_client().is_some()
}

/// Test probe: whether a process-wide WebSocket client is registered.
#[cfg_attr(feature = "uniffi", uniffi::export)]
pub fn has_ws_client() -> bool {
ws_client().is_some()
}

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.

🟡 Test-only helper functions are added to the crate's permanent public API

Four self-test helpers are made permanently public (pub async fn self_test_http_get at livekit-net/src/lib.rs:67 and the neighbouring probes) even when the bindings feature is off, so the library's supported surface grows with functions that exist only to exercise tests.
Impact: Consumers see and can depend on test scaffolding as if it were product API, which then cannot be changed without a breaking release.

AGENTS.md rule on new public API surface

AGENTS.md states: "When introducing new API surface, always default to private or pub(crate) unless there is a specific reason to expose publicly" and "Introduce new public APIs sparingly". The only stated reason for these helpers is FFI self-testing, so they should at minimum be gated behind #[cfg(feature = "uniffi")] (with the test using that feature), rather than exported unconditionally at livekit-net/src/lib.rs:63-95.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant