Skip to content
6 changes: 6 additions & 0 deletions .changeset/sdk_capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
livekit-api: patch
livekit-uniffi: patch
---

Add advertising of SDK client capabilities - #1022 (@chenosaurus)
1 change: 1 addition & 0 deletions livekit-api/src/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ mod tests {
agents: vec![livekit_protocol::RoomAgentDispatch {
agent_name: "test-agent".to_string(),
metadata: "test-metadata".to_string(),
..Default::default()
}],
..Default::default()
};
Expand Down
30 changes: 30 additions & 0 deletions livekit-api/src/signal_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const REGION_FETCH_TIMEOUT: Duration = Duration::from_secs(3);
const VALIDATE_TIMEOUT: Duration = Duration::from_secs(3);
pub const PROTOCOL_VERSION: u32 = 17;

/// Capabilities the Rust SDK advertises to the SFU at connect time.
const CLIENT_CAPABILITIES: &[proto::client_info::Capability] =
&[proto::client_info::Capability::CapPacketTrailer];

#[derive(Error, Debug)]
pub enum SignalError {
#[error("ws failure: {0}")]
Expand Down Expand Up @@ -580,6 +584,7 @@ fn create_join_request_param(
os,
os_version,
device_model,
capabilities: CLIENT_CAPABILITIES.iter().map(|c| *c as i32).collect(),
..Default::default()
};

Expand Down Expand Up @@ -683,6 +688,13 @@ fn get_livekit_url(
lk_url.query_pairs_mut().append_pair("version", sdk_version.as_str());
}

// parse client capabilities
if !CLIENT_CAPABILITIES.is_empty() {
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.

A tiny unit test for this branch would be appreciated.

let caps =
CLIENT_CAPABILITIES.iter().map(|c| c.as_str_name()).collect::<Vec<_>>().join(",");
lk_url.query_pairs_mut().append_pair("capabilities", &caps);
}

// For reconnects in v0 path, add reconnect and sid as separate query parameters
if reconnect {
lk_url
Expand Down Expand Up @@ -802,6 +814,24 @@ mod tests {
assert_eq!(validate_url.scheme(), "https");
}

#[test]
fn livekit_url_includes_client_capabilities() {
let io = SignalOptions::default();
let lk_url = get_livekit_url("wss://localhost:7880", &io, false, false, None, "").unwrap();

let capabilities = lk_url
.query_pairs()
.find_map(|(key, value)| (key == "capabilities").then(|| value.into_owned()))
.unwrap();
let expected = CLIENT_CAPABILITIES
.iter()
.map(|capability| capability.as_str_name())
.collect::<Vec<_>>()
.join(",");

assert_eq!(capabilities, expected);
}

/// Regression test for https://github.com/livekit/rust-sdks/issues/1042.
///
/// Prior to the fix, `SignalInner::validate` issued an auth-less GET to
Expand Down
2 changes: 1 addition & 1 deletion livekit-protocol/protocol
Submodule protocol updated 118 files
Loading
Loading