Publish screen-sharing video track on the newly-created Room
This commit is contained in:
parent
7bf64ec23e
commit
df3ab13441
4 changed files with 58 additions and 10 deletions
|
@ -41,7 +41,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let room = live_kit::Room::new();
|
let room = Room::new();
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
println!("connecting...");
|
println!("connecting...");
|
||||||
|
@ -51,6 +51,7 @@ fn main() {
|
||||||
|
|
||||||
let window_id = windows.iter().next().unwrap().id;
|
let window_id = windows.iter().next().unwrap().id;
|
||||||
let track = LocalVideoTrack::screen_share_for_window(window_id);
|
let track = LocalVideoTrack::screen_share_for_window(window_id);
|
||||||
|
room.publish_video_track(&track).await;
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,17 @@ public func LKRoomConnect(room: UnsafeRawPointer, url: CFString, token: CFString
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKRoomPublishVideoTrack")
|
||||||
|
public func LKRoomPublishVideoTrack(room: UnsafeRawPointer, track: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer) -> Void, callback_data: UnsafeRawPointer) {
|
||||||
|
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue();
|
||||||
|
let track = Unmanaged<LocalVideoTrack>.fromOpaque(track).takeUnretainedValue();
|
||||||
|
room.localParticipant?.publishVideoTrack(track: track).then { _ in
|
||||||
|
callback(callback_data);
|
||||||
|
}.catch { error in
|
||||||
|
print(error);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@_cdecl("LKCreateScreenShareTrackForWindow")
|
@_cdecl("LKCreateScreenShareTrackForWindow")
|
||||||
public func LKCreateScreenShareTrackForWindow(windowId: uint32) -> UnsafeMutableRawPointer {
|
public func LKCreateScreenShareTrackForWindow(windowId: uint32) -> UnsafeMutableRawPointer {
|
||||||
let track = LocalVideoTrack.createMacOSScreenShareTrack(source: .window(id: windowId));
|
let track = LocalVideoTrack.createMacOSScreenShareTrack(source: .window(id: windowId));
|
||||||
|
|
|
@ -37,7 +37,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_bridge(swift_target: &SwiftTarget) {
|
fn build_bridge(swift_target: &SwiftTarget) {
|
||||||
println!("cargo:rerun-if-changed={}", SWIFT_PACKAGE_NAME);
|
println!("cargo:rerun-if-changed={}/Sources", SWIFT_PACKAGE_NAME);
|
||||||
|
println!(
|
||||||
|
"cargo:rerun-if-changed={}/Package.swift",
|
||||||
|
SWIFT_PACKAGE_NAME
|
||||||
|
);
|
||||||
let swift_package_root = swift_package_root();
|
let swift_package_root = swift_package_root();
|
||||||
if !Command::new("swift")
|
if !Command::new("swift")
|
||||||
.args(&["build", "-c", &env::var("PROFILE").unwrap()])
|
.args(&["build", "-c", &env::var("PROFILE").unwrap()])
|
||||||
|
|
|
@ -14,6 +14,7 @@ use std::ffi::c_void;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn LKRelease(object: *const c_void);
|
fn LKRelease(object: *const c_void);
|
||||||
|
|
||||||
fn LKRoomCreate() -> *const c_void;
|
fn LKRoomCreate() -> *const c_void;
|
||||||
fn LKRoomConnect(
|
fn LKRoomConnect(
|
||||||
room: *const c_void,
|
room: *const c_void,
|
||||||
|
@ -22,6 +23,13 @@ extern "C" {
|
||||||
callback: extern "C" fn(*mut c_void) -> (),
|
callback: extern "C" fn(*mut c_void) -> (),
|
||||||
callback_data: *mut c_void,
|
callback_data: *mut c_void,
|
||||||
);
|
);
|
||||||
|
fn LKRoomPublishVideoTrack(
|
||||||
|
room: *const c_void,
|
||||||
|
track: *const c_void,
|
||||||
|
callback: extern "C" fn(*mut c_void) -> (),
|
||||||
|
callback_data: *mut c_void,
|
||||||
|
);
|
||||||
|
|
||||||
fn LKCreateScreenShareTrackForWindow(windowId: u32) -> *const c_void;
|
fn LKCreateScreenShareTrackForWindow(windowId: u32) -> *const c_void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,25 +43,49 @@ impl Room {
|
||||||
pub fn connect(&self, url: &str, token: &str) -> impl Future<Output = ()> {
|
pub fn connect(&self, url: &str, token: &str) -> impl Future<Output = ()> {
|
||||||
let url = CFString::new(url);
|
let url = CFString::new(url);
|
||||||
let token = CFString::new(token);
|
let token = CFString::new(token);
|
||||||
|
let (did_connect, tx, rx) = Self::build_done_callback();
|
||||||
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 {
|
unsafe {
|
||||||
LKRoomConnect(
|
LKRoomConnect(
|
||||||
self.0,
|
self.0,
|
||||||
url.as_concrete_TypeRef(),
|
url.as_concrete_TypeRef(),
|
||||||
token.as_concrete_TypeRef(),
|
token.as_concrete_TypeRef(),
|
||||||
did_connect,
|
did_connect,
|
||||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
tx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async { rx.await.unwrap() }
|
async { rx.await.unwrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn publish_video_track(&self, track: &LocalVideoTrack) -> impl Future<Output = ()> {
|
||||||
|
let (did_publish, tx, rx) = Self::build_done_callback();
|
||||||
|
unsafe {
|
||||||
|
LKRoomPublishVideoTrack(
|
||||||
|
self.0,
|
||||||
|
track.0,
|
||||||
|
did_publish,
|
||||||
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
async { rx.await.unwrap() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_done_callback() -> (
|
||||||
|
extern "C" fn(*mut c_void),
|
||||||
|
*mut c_void,
|
||||||
|
oneshot::Receiver<()>,
|
||||||
|
) {
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
extern "C" fn done_callback(tx: *mut c_void) {
|
||||||
|
let tx = unsafe { Box::from_raw(tx as *mut oneshot::Sender<()>) };
|
||||||
|
let _ = tx.send(());
|
||||||
|
}
|
||||||
|
(
|
||||||
|
done_callback,
|
||||||
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
rx,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Room {
|
impl Drop for Room {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue