Skip to content

Commit

Permalink
Initialize dispatcher for livekit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Jun 21, 2024
1 parent 53dd196 commit 56c53a8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/live_kit_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async-broadcast = "0.7"
async-trait = { workspace = true, optional = true }
collections = { workspace = true, optional = true }
futures.workspace = true
gpui = { workspace = true, optional = true }
gpui.workspace = true
livekit.workspace = true
live_kit_server = { workspace = true, optional = true }
log.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/live_kit_client/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-arg=-Objc");
}
2 changes: 2 additions & 0 deletions crates/live_kit_client/examples/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fn main() {
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");

gpui::App::new().run(|cx| {
live_kit_client::init(cx.background_executor().dispatcher.clone());

#[cfg(any(test, feature = "test-support"))]
println!("USING TEST LIVEKIT");

Expand Down
24 changes: 23 additions & 1 deletion crates/live_kit_client/src/live_kit_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::Arc;

use anyhow::Result;
use futures::{Stream, StreamExt as _};
use gpui::{ScreenCaptureFrame, ScreenCaptureSource, ScreenCaptureStream};
use gpui::{AppContext, ScreenCaptureFrame, ScreenCaptureSource, ScreenCaptureStream};
use webrtc::{
audio_source::{native::NativeAudioSource, AudioSourceOptions, RtcAudioSource},
video_frame::{native::NativeBuffer, VideoFrame, VideoRotation},
Expand All @@ -16,6 +18,26 @@ pub mod test;
#[cfg(any(test, feature = "test-support"))]
pub use test::*;

pub fn init(dispatcher: Arc<dyn gpui::PlatformDispatcher>) {
struct Dispatcher(Arc<dyn gpui::PlatformDispatcher>);

impl livekit::dispatcher::Dispatcher for Dispatcher {
fn dispatch(&self, runnable: livekit::dispatcher::Runnable) {
self.0.dispatch(runnable, None);
}

fn dispatch_after(
&self,
duration: std::time::Duration,
runnable: livekit::dispatcher::Runnable,
) {
self.0.dispatch_after(duration, runnable);
}
}

livekit::dispatcher::set_dispatcher(Dispatcher(dispatcher));
}

pub async fn create_video_track_from_screen_capture_source(
capture_source: &dyn ScreenCaptureSource,
) -> Result<(track::LocalVideoTrack, Box<dyn ScreenCaptureStream>)> {
Expand Down

0 comments on commit 56c53a8

Please sign in to comment.