Add mute toggling controls
This commit is contained in:
parent
3e3079b513
commit
e58f0ac72f
5 changed files with 189 additions and 61 deletions
|
@ -201,19 +201,6 @@ public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer)
|
|||
return Unmanaged.passRetained(track).toOpaque()
|
||||
}
|
||||
|
||||
@_cdecl("LKRemoteAudioTrackStart")
|
||||
public func LKRemoteAudioTrackStart(track: UnsafeRawPointer, onStart: @escaping @convention(c) (UnsafeRawPointer, Bool) -> Void, callbackData: UnsafeRawPointer) {
|
||||
let track = Unmanaged<Track>.fromOpaque(track).takeUnretainedValue() as! RemoteAudioTrack
|
||||
|
||||
track.start().then { success in
|
||||
onStart(callbackData, success)
|
||||
}
|
||||
.catch { _ in
|
||||
onStart(callbackData, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@_cdecl("LKVideoRendererCreate")
|
||||
public func LKVideoRendererCreate(data: UnsafeRawPointer, onFrame: @escaping @convention(c) (UnsafeRawPointer, CVPixelBuffer) -> Bool, onDrop: @escaping @convention(c) (UnsafeRawPointer) -> Void) -> UnsafeMutableRawPointer {
|
||||
Unmanaged.passRetained(LKVideoRenderer(data: data, onFrame: onFrame, onDrop: onDrop)).toOpaque()
|
||||
|
@ -247,3 +234,34 @@ public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @conven
|
|||
callback(data, nil, error.localizedDescription as CFString)
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("LKLocalTrackPublicationMute")
|
||||
public func LKLocalTrackPublicationMute(
|
||||
publication: UnsafeRawPointer,
|
||||
on_complete: @escaping @convention(c) (UnsafeRawPointer, CFString?) -> Void,
|
||||
callback_data: UnsafeRawPointer
|
||||
) {
|
||||
let publication = Unmanaged<LocalTrackPublication>.fromOpaque(publication).takeUnretainedValue()
|
||||
|
||||
publication.mute().then {
|
||||
on_complete(callback_data, nil)
|
||||
}.catch { error in
|
||||
on_complete(callback_data, error.localizedDescription as CFString)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@_cdecl("LKLocalTrackPublicationUnmute")
|
||||
public func LKLocalTrackPublicationUnmute(
|
||||
publication: UnsafeRawPointer,
|
||||
on_complete: @escaping @convention(c) (UnsafeRawPointer, CFString?) -> Void,
|
||||
callback_data: UnsafeRawPointer
|
||||
) {
|
||||
let publication = Unmanaged<LocalTrackPublication>.fromOpaque(publication).takeUnretainedValue()
|
||||
|
||||
publication.unmute().then {
|
||||
on_complete(callback_data, nil)
|
||||
}.catch { error in
|
||||
on_complete(callback_data, error.localizedDescription as CFString)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,12 +84,6 @@ extern "C" {
|
|||
) -> *const c_void;
|
||||
|
||||
fn LKRemoteAudioTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||
// fn LKRemoteAudioTrackStart(
|
||||
// track: *const c_void,
|
||||
// callback: extern "C" fn(*mut c_void, bool),
|
||||
// callback_data: *mut c_void
|
||||
// );
|
||||
|
||||
fn LKVideoTrackAddRenderer(track: *const c_void, renderer: *const c_void);
|
||||
fn LKRemoteVideoTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||
|
||||
|
@ -103,6 +97,17 @@ extern "C" {
|
|||
);
|
||||
fn LKCreateScreenShareTrackForDisplay(display: *const c_void) -> *const c_void;
|
||||
fn LKLocalAudioTrackCreateTrack() -> *const c_void;
|
||||
|
||||
fn LKLocalTrackPublicationMute(
|
||||
publication: *const c_void,
|
||||
on_complete: extern "C" fn(callback_data: *mut c_void, error: CFStringRef),
|
||||
callback_data: *mut c_void,
|
||||
);
|
||||
fn LKLocalTrackPublicationUnmute(
|
||||
publication: *const c_void,
|
||||
on_complete: extern "C" fn(callback_data: *mut c_void, error: CFStringRef),
|
||||
callback_data: *mut c_void,
|
||||
);
|
||||
}
|
||||
|
||||
pub type Sid = String;
|
||||
|
@ -525,6 +530,56 @@ impl Drop for LocalVideoTrack {
|
|||
|
||||
pub struct LocalTrackPublication(*const c_void);
|
||||
|
||||
impl LocalTrackPublication {
|
||||
pub fn mute(&self) -> impl Future<Output = Result<()>> {
|
||||
let (tx, rx) = futures::channel::oneshot::channel();
|
||||
|
||||
extern "C" fn complete_callback(callback_data: *mut c_void, error: CFStringRef) {
|
||||
let tx = unsafe { Box::from_raw(callback_data as *mut oneshot::Sender<Result<()>>) };
|
||||
if error.is_null() {
|
||||
tx.send(Ok(())).ok();
|
||||
} else {
|
||||
let error = unsafe { CFString::wrap_under_get_rule(error).to_string() };
|
||||
tx.send(Err(anyhow!(error))).ok();
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
LKLocalTrackPublicationMute(
|
||||
self.0,
|
||||
complete_callback,
|
||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||
)
|
||||
}
|
||||
|
||||
async move { rx.await.unwrap() }
|
||||
}
|
||||
|
||||
pub fn unmute(&self) -> impl Future<Output = Result<()>> {
|
||||
let (tx, rx) = futures::channel::oneshot::channel();
|
||||
|
||||
extern "C" fn complete_callback(callback_data: *mut c_void, error: CFStringRef) {
|
||||
let tx = unsafe { Box::from_raw(callback_data as *mut oneshot::Sender<Result<()>>) };
|
||||
if error.is_null() {
|
||||
tx.send(Ok(())).ok();
|
||||
} else {
|
||||
let error = unsafe { CFString::wrap_under_get_rule(error).to_string() };
|
||||
tx.send(Err(anyhow!(error))).ok();
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
LKLocalTrackPublicationUnmute(
|
||||
self.0,
|
||||
complete_callback,
|
||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||
)
|
||||
}
|
||||
|
||||
async move { rx.await.unwrap() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LocalTrackPublication {
|
||||
fn drop(&mut self) {
|
||||
unsafe { CFRelease(self.0) }
|
||||
|
|
|
@ -475,6 +475,20 @@ impl Drop for Room {
|
|||
|
||||
pub struct LocalTrackPublication;
|
||||
|
||||
impl LocalTrackPublication {
|
||||
pub fn mute(&self) -> impl Future<Output = Result<()>> {
|
||||
async {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unmute(&self) -> impl Future<Output = Result<()>> {
|
||||
async {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LocalVideoTrack {
|
||||
frames_rx: async_broadcast::Receiver<Frame>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue