ported example app, live_kit_client2 is done
This commit is contained in:
parent
244e8ce101
commit
51fa80ef06
3 changed files with 159 additions and 156 deletions
|
@ -1,175 +1,178 @@
|
||||||
// use std::time::Duration;
|
use std::{sync::Arc, time::Duration};
|
||||||
// todo!()
|
|
||||||
|
|
||||||
// use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
// use gpui2::{actions, keymap_matcher::Binding, Menu, MenuItem};
|
use gpui2::KeyBinding;
|
||||||
// use live_kit_client2::{
|
use live_kit_client2::{
|
||||||
// LocalAudioTrack, LocalVideoTrack, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate, Room,
|
LocalAudioTrack, LocalVideoTrack, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate, Room,
|
||||||
// };
|
};
|
||||||
// use live_kit_server::token::{self, VideoGrant};
|
use live_kit_server::token::{self, VideoGrant};
|
||||||
// use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
// use simplelog::SimpleLogger;
|
use serde_derive::Deserialize;
|
||||||
|
use simplelog::SimpleLogger;
|
||||||
|
|
||||||
// actions!(capture, [Quit]);
|
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
|
struct Quit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||||
|
|
||||||
// gpui2::App::new(()).unwrap().run(|cx| {
|
gpui2::App::production(Arc::new(())).run(|cx| {
|
||||||
// #[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
// println!("USING TEST LIVEKIT");
|
println!("USING TEST LIVEKIT");
|
||||||
|
|
||||||
// #[cfg(not(any(test, feature = "test-support")))]
|
#[cfg(not(any(test, feature = "test-support")))]
|
||||||
// println!("USING REAL LIVEKIT");
|
println!("USING REAL LIVEKIT");
|
||||||
|
|
||||||
// cx.platform().activate(true);
|
cx.activate(true);
|
||||||
// cx.add_global_action(quit);
|
|
||||||
|
|
||||||
// cx.add_bindings([Binding::new("cmd-q", Quit, None)]);
|
cx.on_action(quit);
|
||||||
// cx.set_menus(vec![Menu {
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
||||||
// name: "Zed",
|
|
||||||
// items: vec![MenuItem::Action {
|
|
||||||
// name: "Quit",
|
|
||||||
// action: Box::new(Quit),
|
|
||||||
// os_action: None,
|
|
||||||
// }],
|
|
||||||
// }]);
|
|
||||||
|
|
||||||
// let live_kit_url = std::env::var("LIVE_KIT_URL").unwrap_or("http://localhost:7880".into());
|
// todo!()
|
||||||
// let live_kit_key = std::env::var("LIVE_KIT_KEY").unwrap_or("devkey".into());
|
// cx.set_menus(vec![Menu {
|
||||||
// let live_kit_secret = std::env::var("LIVE_KIT_SECRET").unwrap_or("secret".into());
|
// name: "Zed",
|
||||||
|
// items: vec![MenuItem::Action {
|
||||||
|
// name: "Quit",
|
||||||
|
// action: Box::new(Quit),
|
||||||
|
// os_action: None,
|
||||||
|
// }],
|
||||||
|
// }]);
|
||||||
|
|
||||||
// cx.spawn(|cx| async move {
|
let live_kit_url = std::env::var("LIVE_KIT_URL").unwrap_or("http://localhost:7880".into());
|
||||||
// let user_a_token = token::create(
|
let live_kit_key = std::env::var("LIVE_KIT_KEY").unwrap_or("devkey".into());
|
||||||
// &live_kit_key,
|
let live_kit_secret = std::env::var("LIVE_KIT_SECRET").unwrap_or("secret".into());
|
||||||
// &live_kit_secret,
|
|
||||||
// Some("test-participant-1"),
|
|
||||||
// VideoGrant::to_join("test-room"),
|
|
||||||
// )
|
|
||||||
// .unwrap();
|
|
||||||
// let room_a = Room::new();
|
|
||||||
// room_a.connect(&live_kit_url, &user_a_token).await.unwrap();
|
|
||||||
|
|
||||||
// let user2_token = token::create(
|
cx.spawn_on_main(|cx| async move {
|
||||||
// &live_kit_key,
|
let user_a_token = token::create(
|
||||||
// &live_kit_secret,
|
&live_kit_key,
|
||||||
// Some("test-participant-2"),
|
&live_kit_secret,
|
||||||
// VideoGrant::to_join("test-room"),
|
Some("test-participant-1"),
|
||||||
// )
|
VideoGrant::to_join("test-room"),
|
||||||
// .unwrap();
|
)
|
||||||
// let room_b = Room::new();
|
.unwrap();
|
||||||
// room_b.connect(&live_kit_url, &user2_token).await.unwrap();
|
let room_a = Room::new();
|
||||||
|
room_a.connect(&live_kit_url, &user_a_token).await.unwrap();
|
||||||
|
|
||||||
// let mut audio_track_updates = room_b.remote_audio_track_updates();
|
let user2_token = token::create(
|
||||||
// let audio_track = LocalAudioTrack::create();
|
&live_kit_key,
|
||||||
// let audio_track_publication = room_a.publish_audio_track(audio_track).await.unwrap();
|
&live_kit_secret,
|
||||||
|
Some("test-participant-2"),
|
||||||
|
VideoGrant::to_join("test-room"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let room_b = Room::new();
|
||||||
|
room_b.connect(&live_kit_url, &user2_token).await.unwrap();
|
||||||
|
|
||||||
// if let RemoteAudioTrackUpdate::Subscribed(track, _) =
|
let mut audio_track_updates = room_b.remote_audio_track_updates();
|
||||||
// audio_track_updates.next().await.unwrap()
|
let audio_track = LocalAudioTrack::create();
|
||||||
// {
|
let audio_track_publication = room_a.publish_audio_track(audio_track).await.unwrap();
|
||||||
// let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
|
||||||
// assert_eq!(remote_tracks.len(), 1);
|
|
||||||
// assert_eq!(remote_tracks[0].publisher_id(), "test-participant-1");
|
|
||||||
// assert_eq!(track.publisher_id(), "test-participant-1");
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// audio_track_publication.set_mute(true).await.unwrap();
|
if let RemoteAudioTrackUpdate::Subscribed(track, _) =
|
||||||
|
audio_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
||||||
|
assert_eq!(remote_tracks.len(), 1);
|
||||||
|
assert_eq!(remote_tracks[0].publisher_id(), "test-participant-1");
|
||||||
|
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
// println!("waiting for mute changed!");
|
audio_track_publication.set_mute(true).await.unwrap();
|
||||||
// if let RemoteAudioTrackUpdate::MuteChanged { track_id, muted } =
|
|
||||||
// audio_track_updates.next().await.unwrap()
|
|
||||||
// {
|
|
||||||
// let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
|
||||||
// assert_eq!(remote_tracks[0].sid(), track_id);
|
|
||||||
// assert_eq!(muted, true);
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// audio_track_publication.set_mute(false).await.unwrap();
|
println!("waiting for mute changed!");
|
||||||
|
if let RemoteAudioTrackUpdate::MuteChanged { track_id, muted } =
|
||||||
|
audio_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
||||||
|
assert_eq!(remote_tracks[0].sid(), track_id);
|
||||||
|
assert_eq!(muted, true);
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
// if let RemoteAudioTrackUpdate::MuteChanged { track_id, muted } =
|
audio_track_publication.set_mute(false).await.unwrap();
|
||||||
// audio_track_updates.next().await.unwrap()
|
|
||||||
// {
|
|
||||||
// let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
|
||||||
// assert_eq!(remote_tracks[0].sid(), track_id);
|
|
||||||
// assert_eq!(muted, false);
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// println!("Pausing for 5 seconds to test audio, make some noise!");
|
if let RemoteAudioTrackUpdate::MuteChanged { track_id, muted } =
|
||||||
// let timer = cx.background().timer(Duration::from_secs(5));
|
audio_track_updates.next().await.unwrap()
|
||||||
// timer.await;
|
{
|
||||||
// let remote_audio_track = room_b
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
||||||
// .remote_audio_tracks("test-participant-1")
|
assert_eq!(remote_tracks[0].sid(), track_id);
|
||||||
// .pop()
|
assert_eq!(muted, false);
|
||||||
// .unwrap();
|
} else {
|
||||||
// room_a.unpublish_track(audio_track_publication);
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
// // Clear out any active speakers changed messages
|
println!("Pausing for 5 seconds to test audio, make some noise!");
|
||||||
// let mut next = audio_track_updates.next().await.unwrap();
|
let timer = cx.executor().timer(Duration::from_secs(5));
|
||||||
// while let RemoteAudioTrackUpdate::ActiveSpeakersChanged { speakers } = next {
|
timer.await;
|
||||||
// println!("Speakers changed: {:?}", speakers);
|
let remote_audio_track = room_b
|
||||||
// next = audio_track_updates.next().await.unwrap();
|
.remote_audio_tracks("test-participant-1")
|
||||||
// }
|
.pop()
|
||||||
|
.unwrap();
|
||||||
|
room_a.unpublish_track(audio_track_publication);
|
||||||
|
|
||||||
// if let RemoteAudioTrackUpdate::Unsubscribed {
|
// Clear out any active speakers changed messages
|
||||||
// publisher_id,
|
let mut next = audio_track_updates.next().await.unwrap();
|
||||||
// track_id,
|
while let RemoteAudioTrackUpdate::ActiveSpeakersChanged { speakers } = next {
|
||||||
// } = next
|
println!("Speakers changed: {:?}", speakers);
|
||||||
// {
|
next = audio_track_updates.next().await.unwrap();
|
||||||
// assert_eq!(publisher_id, "test-participant-1");
|
}
|
||||||
// assert_eq!(remote_audio_track.sid(), track_id);
|
|
||||||
// assert_eq!(room_b.remote_audio_tracks("test-participant-1").len(), 0);
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let mut video_track_updates = room_b.remote_video_track_updates();
|
if let RemoteAudioTrackUpdate::Unsubscribed {
|
||||||
// let displays = room_a.display_sources().await.unwrap();
|
publisher_id,
|
||||||
// let display = displays.into_iter().next().unwrap();
|
track_id,
|
||||||
|
} = next
|
||||||
|
{
|
||||||
|
assert_eq!(publisher_id, "test-participant-1");
|
||||||
|
assert_eq!(remote_audio_track.sid(), track_id);
|
||||||
|
assert_eq!(room_b.remote_audio_tracks("test-participant-1").len(), 0);
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
// let local_video_track = LocalVideoTrack::screen_share_for_display(&display);
|
let mut video_track_updates = room_b.remote_video_track_updates();
|
||||||
// let local_video_track_publication =
|
let displays = room_a.display_sources().await.unwrap();
|
||||||
// room_a.publish_video_track(local_video_track).await.unwrap();
|
let display = displays.into_iter().next().unwrap();
|
||||||
|
|
||||||
// if let RemoteVideoTrackUpdate::Subscribed(track) =
|
let local_video_track = LocalVideoTrack::screen_share_for_display(&display);
|
||||||
// video_track_updates.next().await.unwrap()
|
let local_video_track_publication =
|
||||||
// {
|
room_a.publish_video_track(local_video_track).await.unwrap();
|
||||||
// let remote_video_tracks = room_b.remote_video_tracks("test-participant-1");
|
|
||||||
// assert_eq!(remote_video_tracks.len(), 1);
|
|
||||||
// assert_eq!(remote_video_tracks[0].publisher_id(), "test-participant-1");
|
|
||||||
// assert_eq!(track.publisher_id(), "test-participant-1");
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let remote_video_track = room_b
|
if let RemoteVideoTrackUpdate::Subscribed(track) =
|
||||||
// .remote_video_tracks("test-participant-1")
|
video_track_updates.next().await.unwrap()
|
||||||
// .pop()
|
{
|
||||||
// .unwrap();
|
let remote_video_tracks = room_b.remote_video_tracks("test-participant-1");
|
||||||
// room_a.unpublish_track(local_video_track_publication);
|
assert_eq!(remote_video_tracks.len(), 1);
|
||||||
// if let RemoteVideoTrackUpdate::Unsubscribed {
|
assert_eq!(remote_video_tracks[0].publisher_id(), "test-participant-1");
|
||||||
// publisher_id,
|
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||||
// track_id,
|
} else {
|
||||||
// } = video_track_updates.next().await.unwrap()
|
panic!("unexpected message");
|
||||||
// {
|
}
|
||||||
// assert_eq!(publisher_id, "test-participant-1");
|
|
||||||
// assert_eq!(remote_video_track.sid(), track_id);
|
|
||||||
// assert_eq!(room_b.remote_video_tracks("test-participant-1").len(), 0);
|
|
||||||
// } else {
|
|
||||||
// panic!("unexpected message");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// cx.platform().quit();
|
let remote_video_track = room_b
|
||||||
// })
|
.remote_video_tracks("test-participant-1")
|
||||||
// .detach();
|
.pop()
|
||||||
// });
|
.unwrap();
|
||||||
|
room_a.unpublish_track(local_video_track_publication);
|
||||||
|
if let RemoteVideoTrackUpdate::Unsubscribed {
|
||||||
|
publisher_id,
|
||||||
|
track_id,
|
||||||
|
} = video_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
|
assert_eq!(publisher_id, "test-participant-1");
|
||||||
|
assert_eq!(remote_video_track.sid(), track_id);
|
||||||
|
assert_eq!(room_b.remote_video_tracks("test-participant-1").len(), 0);
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.update(|cx| cx.quit()).ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn quit(_: &Quit, cx: &mut gpui2::AppContext) {
|
fn quit(_: &Quit, cx: &mut gpui2::AppContext) {
|
||||||
// cx.platform().quit();
|
cx.quit();
|
||||||
// }
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// #[cfg(not(any(test, feature = "test-support")))]
|
#[cfg(not(any(test, feature = "test-support")))]
|
||||||
pub mod prod;
|
pub mod prod;
|
||||||
|
|
||||||
// #[cfg(not(any(test, feature = "test-support")))]
|
#[cfg(not(any(test, feature = "test-support")))]
|
||||||
pub use prod::*;
|
pub use prod::*;
|
||||||
|
|
||||||
// #[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
// pub mod test;
|
pub mod test;
|
||||||
|
|
||||||
// #[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
// pub use test::*;
|
pub use test::*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result, Context};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use collections::{BTreeMap, HashMap};
|
use collections::{BTreeMap, HashMap};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
|
@ -364,7 +364,7 @@ impl Room {
|
||||||
let token = token.to_string();
|
let token = token.to_string();
|
||||||
async move {
|
async move {
|
||||||
let server = TestServer::get(&url)?;
|
let server = TestServer::get(&url)?;
|
||||||
server.join_room(token.clone(), this.clone()).await?;
|
server.join_room(token.clone(), this.clone()).await.context("room join")?;
|
||||||
*this.0.lock().connection.0.borrow_mut() = ConnectionState::Connected { url, token };
|
*this.0.lock().connection.0.borrow_mut() = ConnectionState::Connected { url, token };
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue