Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDK version, allow override of SDK and version from FFI #471

Merged
merged 24 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions livekit-api/src/signal_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ pub enum SignalError {
pub struct SignalOptions {
pub auto_subscribe: bool,
pub adaptive_stream: bool,
pub sdk: Option<&'static str>,
pub sdk_version: Option<&'static str>,
}

impl Default for SignalOptions {
fn default() -> Self {
Self { auto_subscribe: true, adaptive_stream: false }
Self { auto_subscribe: true, adaptive_stream: false, sdk: Some("rust"), sdk_version: None }
}
}

Expand Down Expand Up @@ -431,12 +433,16 @@ fn get_livekit_url(url: &str, token: &str, options: &SignalOptions) -> SignalRes

lk_url
.query_pairs_mut()
.append_pair("sdk", "rust")
.append_pair("access_token", token)
.append_pair("sdk", options.sdk.unwrap_or("rust"))
.append_pair("protocol", PROTOCOL_VERSION.to_string().as_str())
.append_pair("access_token", token)
.append_pair("auto_subscribe", if options.auto_subscribe { "1" } else { "0" })
.append_pair("adaptive_stream", if options.adaptive_stream { "1" } else { "0" });

if let Some(sdk_version) = options.sdk_version {
lk_url.query_pairs_mut().append_pair("version", sdk_version);
}

Ok(lk_url)
}

Expand Down
12 changes: 11 additions & 1 deletion livekit-ffi/src/cabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ pub type FfiCallbackFn = unsafe extern "C" fn(*const u8, usize);
///
/// The foreign language must only provide valid pointers
#[no_mangle]
pub unsafe extern "C" fn livekit_ffi_initialize(cb: FfiCallbackFn, capture_logs: bool) {
pub unsafe extern "C" fn livekit_ffi_initialize(
cb: FfiCallbackFn,
capture_logs: bool,
sdk: Option<&'static [u8; 16]>,
sdk_version: Option<&'static [u8; 16]>,
) {
let sdk = std::str::from_utf8(sdk.unwrap()).unwrap().trim_end_matches('\0');
let sdk_version = std::str::from_utf8(sdk_version.unwrap()).unwrap().trim_end_matches('\0');
bcherry marked this conversation as resolved.
Show resolved Hide resolved

FFI_SERVER.setup(FfiConfig {
callback_fn: Arc::new(move |event| {
let data = event.encode_to_vec();
cb(data.as_ptr(), data.len());
}),
capture_logs,
sdk: Some(sdk),
sdk_version: Some(sdk_version),
});

log::info!("initializing ffi server v{}", env!("CARGO_PKG_VERSION"));
Expand Down
2 changes: 2 additions & 0 deletions livekit-ffi/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub mod video_stream;
pub struct FfiConfig {
pub callback_fn: Arc<dyn Fn(FfiEvent) + Send + Sync>,
pub capture_logs: bool,
pub sdk: Option<&'static str>,
pub sdk_version: Option<&'static str>,
}

/// To make sure we use the right types, only types that implement this trait
Expand Down
12 changes: 11 additions & 1 deletion livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,21 @@ impl FfiRoom {
) -> proto::ConnectResponse {
let async_id = server.next_id();

let sdk;
let sdk_version;
{
let config = server.config.lock();
sdk = config.as_ref().map(|c| c.sdk).unwrap();
sdk_version = config.as_ref().map(|c| c.sdk_version).unwrap();
}

let connect = async move {
match Room::connect(
match Room::connect_with_sdk(
&connect.url,
&connect.token,
connect.options.map(Into::into).unwrap_or_default(),
sdk,
sdk_version,
)
.await
{
Expand Down
14 changes: 14 additions & 0 deletions livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub mod publication;
pub mod track;
pub(crate) mod utils;

pub const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");

pub type RoomResult<T> = Result<T, RoomError>;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -328,6 +330,16 @@ impl Room {
url: &str,
token: &str,
options: RoomOptions,
) -> RoomResult<(Self, mpsc::UnboundedReceiver<RoomEvent>)> {
Self::connect_with_sdk(url, token, options, Some("rust"), Some(SDK_VERSION)).await
}

pub async fn connect_with_sdk(
bcherry marked this conversation as resolved.
Show resolved Hide resolved
bcherry marked this conversation as resolved.
Show resolved Hide resolved
url: &str,
token: &str,
options: RoomOptions,
sdk: Option<&'static str>,
sdk_version: Option<&'static str>,
) -> RoomResult<(Self, mpsc::UnboundedReceiver<RoomEvent>)> {
// TODO(theomonnom): move connection logic to the RoomSession
let e2ee_manager = E2eeManager::new(options.e2ee.clone());
Expand All @@ -339,6 +351,8 @@ impl Room {
signal_options: SignalOptions {
auto_subscribe: options.auto_subscribe,
adaptive_stream: options.adaptive_stream,
sdk: sdk,
sdk_version: sdk_version,
},
join_retries: options.join_retries,
},
Expand Down
Loading