mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
172 lines
6.5 KiB
Rust
172 lines
6.5 KiB
Rust
use std::time::Duration;
|
|
|
|
use futures::StreamExt;
|
|
use gpui::{actions, KeyBinding, Menu, MenuItem};
|
|
use livekit_client_macos::{LocalAudioTrack, LocalVideoTrack, Room, RoomUpdate};
|
|
use livekit_server::token::{self, VideoGrant};
|
|
use log::LevelFilter;
|
|
use simplelog::SimpleLogger;
|
|
|
|
actions!(livekit_client_macos, [Quit]);
|
|
|
|
fn main() {
|
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
|
|
|
gpui::Application::new().run(|cx| {
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
println!("USING TEST LIVEKIT");
|
|
|
|
#[cfg(not(any(test, feature = "test-support")))]
|
|
println!("USING REAL LIVEKIT");
|
|
|
|
cx.activate(true);
|
|
|
|
cx.on_action(quit);
|
|
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
|
|
|
|
cx.set_menus(vec![Menu {
|
|
name: "Zed".into(),
|
|
items: vec![MenuItem::Action {
|
|
name: "Quit".into(),
|
|
action: Box::new(Quit),
|
|
os_action: None,
|
|
}],
|
|
}]);
|
|
|
|
let live_kit_url = std::env::var("LIVE_KIT_URL").unwrap_or("http://localhost:7880".into());
|
|
let live_kit_key = std::env::var("LIVE_KIT_KEY").unwrap_or("devkey".into());
|
|
let live_kit_secret = std::env::var("LIVE_KIT_SECRET").unwrap_or("secret".into());
|
|
|
|
cx.spawn(|cx| async move {
|
|
let user_a_token = token::create(
|
|
&live_kit_key,
|
|
&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(
|
|
&live_kit_key,
|
|
&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();
|
|
|
|
let mut room_updates = room_b.updates();
|
|
let audio_track = LocalAudioTrack::create();
|
|
let audio_track_publication = room_a.publish_audio_track(audio_track).await.unwrap();
|
|
|
|
if let RoomUpdate::SubscribedToRemoteAudioTrack(track, _) =
|
|
room_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");
|
|
}
|
|
|
|
audio_track_publication.set_mute(true).await.unwrap();
|
|
|
|
println!("waiting for mute changed!");
|
|
if let RoomUpdate::RemoteAudioTrackMuteChanged { track_id, muted } =
|
|
room_updates.next().await.unwrap()
|
|
{
|
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
|
assert_eq!(remote_tracks[0].sid(), track_id);
|
|
assert!(muted);
|
|
} else {
|
|
panic!("unexpected message");
|
|
}
|
|
|
|
audio_track_publication.set_mute(false).await.unwrap();
|
|
|
|
if let RoomUpdate::RemoteAudioTrackMuteChanged { track_id, muted } =
|
|
room_updates.next().await.unwrap()
|
|
{
|
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
|
assert_eq!(remote_tracks[0].sid(), track_id);
|
|
assert!(!muted);
|
|
} else {
|
|
panic!("unexpected message");
|
|
}
|
|
|
|
println!("Pausing for 5 seconds to test audio, make some noise!");
|
|
let timer = cx.background_executor().timer(Duration::from_secs(5));
|
|
timer.await;
|
|
let remote_audio_track = room_b
|
|
.remote_audio_tracks("test-participant-1")
|
|
.pop()
|
|
.unwrap();
|
|
room_a.unpublish_track(audio_track_publication);
|
|
|
|
// Clear out any active speakers changed messages
|
|
let mut next = room_updates.next().await.unwrap();
|
|
while let RoomUpdate::ActiveSpeakersChanged { speakers } = next {
|
|
println!("Speakers changed: {:?}", speakers);
|
|
next = room_updates.next().await.unwrap();
|
|
}
|
|
|
|
if let RoomUpdate::UnsubscribedFromRemoteAudioTrack {
|
|
publisher_id,
|
|
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 displays = room_a.display_sources().await.unwrap();
|
|
let display = displays.into_iter().next().unwrap();
|
|
|
|
let local_video_track = LocalVideoTrack::screen_share_for_display(&display);
|
|
let local_video_track_publication =
|
|
room_a.publish_video_track(local_video_track).await.unwrap();
|
|
|
|
if let RoomUpdate::SubscribedToRemoteVideoTrack(track) =
|
|
room_updates.next().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
|
|
.remote_video_tracks("test-participant-1")
|
|
.pop()
|
|
.unwrap();
|
|
room_a.unpublish_track(local_video_track_publication);
|
|
if let RoomUpdate::UnsubscribedFromRemoteVideoTrack {
|
|
publisher_id,
|
|
track_id,
|
|
} = room_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.shutdown()).ok();
|
|
})
|
|
.detach();
|
|
});
|
|
}
|
|
|
|
fn quit(_: &Quit, cx: &mut gpui::App) {
|
|
cx.quit();
|
|
}
|