Connect to LiveKit room in capture example
This commit is contained in:
parent
45d83b557b
commit
5347c7d678
12 changed files with 173 additions and 474 deletions
|
@ -9,6 +9,8 @@ path = "src/live_kit.rs"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
core-foundation = "0.9.3"
|
||||
futures = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||
|
|
|
@ -10,3 +10,14 @@ public func LKRoomCreate() -> UnsafeMutableRawPointer {
|
|||
public func LKRoomDestroy(ptr: UnsafeRawPointer) {
|
||||
let _ = Unmanaged<Room>.fromOpaque(ptr).takeRetainedValue();
|
||||
}
|
||||
|
||||
@_cdecl("LKRoomConnect")
|
||||
public func LKRoomConnect(room: UnsafeRawPointer, url: CFString, token: CFString, callback: @escaping @convention(c) (UnsafeRawPointer) -> Void, callback_data: UnsafeRawPointer) {
|
||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue();
|
||||
|
||||
room.connect(url as String, token as String).then { _ in
|
||||
callback(callback_data);
|
||||
}.catch { error in
|
||||
print(error);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn build_bridge(swift_target: &SwiftTarget) {
|
||||
println!("cargo:rerun-if-changed={}", SWIFT_PACKAGE_NAME);
|
||||
let swift_package_root = swift_package_root();
|
||||
if !Command::new("swift")
|
||||
.args(&["build", "-c", &env::var("PROFILE").unwrap()])
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
use core_foundation::{
|
||||
base::TCFType,
|
||||
string::{CFString, CFStringRef},
|
||||
};
|
||||
use futures::{channel::oneshot, Future};
|
||||
use std::ffi::c_void;
|
||||
|
||||
extern "C" {
|
||||
fn LKRoomCreate() -> *const c_void;
|
||||
fn LKRoomDestroy(ptr: *const c_void);
|
||||
fn LKRoomDestroy(room: *const c_void);
|
||||
fn LKRoomConnect(
|
||||
room: *const c_void,
|
||||
url: CFStringRef,
|
||||
token: CFStringRef,
|
||||
callback: extern "C" fn(*mut c_void) -> (),
|
||||
callback_data: *mut c_void,
|
||||
);
|
||||
}
|
||||
|
||||
pub struct Room {
|
||||
|
@ -15,6 +27,29 @@ impl Room {
|
|||
native_room: unsafe { LKRoomCreate() },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect(&self, url: &str, token: &str) -> impl Future<Output = ()> {
|
||||
let url = CFString::new(url);
|
||||
let token = CFString::new(token);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
extern "C" fn did_connect(tx: *mut c_void) {
|
||||
let tx = unsafe { Box::from_raw(tx as *mut oneshot::Sender<()>) };
|
||||
let _ = tx.send(());
|
||||
}
|
||||
|
||||
unsafe {
|
||||
LKRoomConnect(
|
||||
self.native_room,
|
||||
url.as_concrete_TypeRef(),
|
||||
token.as_concrete_TypeRef(),
|
||||
did_connect,
|
||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||
)
|
||||
}
|
||||
|
||||
async { rx.await.unwrap() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Room {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue