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

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

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

lk_url
.query_pairs_mut()
.append_pair("sdk", options.sdk.unwrap_or("rust"))
.append_pair("sdk", options.sdk)
.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" })
Expand Down
13 changes: 6 additions & 7 deletions livekit-ffi/src/cabi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use prost::Message;
use server::FfiDataBuffer;
use std::{panic, sync::Arc};
use std::os::raw::c_char;
use std::ffi::CStr;

use crate::{
proto,
Expand All @@ -18,20 +20,17 @@ pub type FfiCallbackFn = unsafe extern "C" fn(*const u8, usize);
pub unsafe extern "C" fn livekit_ffi_initialize(
cb: FfiCallbackFn,
capture_logs: bool,
sdk: Option<&'static [u8; 16]>,
sdk_version: Option<&'static [u8; 16]>,
sdk: *const c_char,
sdk_version: *const c_char,
) {
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');

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),
sdk: CStr::from_ptr(sdk).to_str().ok(),
bcherry marked this conversation as resolved.
Show resolved Hide resolved
sdk_version: CStr::from_ptr(sdk_version).to_str().ok(),
});

log::info!("initializing ffi server v{}", env!("CARGO_PKG_VERSION"));
Expand Down
4 changes: 2 additions & 2 deletions livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl FfiRoom {
&connect.url,
&connect.token,
connect.options.map(Into::into).unwrap_or_default(),
sdk,
sdk_version,
sdk.unwrap(),
sdk_version.unwrap(),
)
.await
{
Expand Down
8 changes: 4 additions & 4 deletions livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ impl Room {
token: &str,
options: RoomOptions,
) -> RoomResult<(Self, mpsc::UnboundedReceiver<RoomEvent>)> {
Self::connect_with_sdk(url, token, options, Some("rust"), Some(SDK_VERSION)).await
Self::connect_with_sdk(url, token, options, "rust", 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>,
sdk: &'static str,
sdk_version: &'static str,
bcherry marked this conversation as resolved.
Show resolved Hide resolved
) -> RoomResult<(Self, mpsc::UnboundedReceiver<RoomEvent>)> {
// TODO(theomonnom): move connection logic to the RoomSession
let e2ee_manager = E2eeManager::new(options.e2ee.clone());
Expand All @@ -352,7 +352,7 @@ impl Room {
auto_subscribe: options.auto_subscribe,
adaptive_stream: options.adaptive_stream,
sdk: sdk,
sdk_version: sdk_version,
sdk_version: Some(sdk_version),
},
join_retries: options.join_retries,
},
Expand Down
Loading