diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index ca4ed13634..8f1cc9f54e 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -1,5 +1,4 @@ pub mod call_settings; -pub mod participant; pub mod room; use anyhow::{anyhow, Result}; @@ -19,7 +18,6 @@ use settings::Settings; use std::sync::Arc; pub use live_kit_client::{Frame, RemoteAudioTrack, RemoteVideoTrack}; -pub use participant::ParticipantLocation; pub use room::Room; pub fn init(client: Arc, user_store: Model, cx: &mut AppContext) { diff --git a/crates/call/src/participant.rs b/crates/call/src/participant.rs deleted file mode 100644 index bad09d9833..0000000000 --- a/crates/call/src/participant.rs +++ /dev/null @@ -1,49 +0,0 @@ -use anyhow::{anyhow, Result}; -use client::ParticipantIndex; -use client::{proto, User}; -use gpui::WeakModel; -use project::Project; -use std::sync::Arc; - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum ParticipantLocation { - SharedProject { project_id: u64 }, - UnsharedProject, - External, -} - -impl ParticipantLocation { - pub fn from_proto(location: Option) -> Result { - match location.and_then(|l| l.variant) { - Some(proto::participant_location::Variant::SharedProject(project)) => { - Ok(Self::SharedProject { - project_id: project.id, - }) - } - Some(proto::participant_location::Variant::UnsharedProject(_)) => { - Ok(Self::UnsharedProject) - } - Some(proto::participant_location::Variant::External(_)) => Ok(Self::External), - None => Err(anyhow!("participant location was not provided")), - } - } -} - -#[derive(Clone, Default)] -pub struct LocalParticipant { - pub projects: Vec, - pub active_project: Option>, - pub role: proto::ChannelRole, -} - -#[derive(Clone, Debug)] -pub struct RemoteParticipant { - pub user: Arc, - pub peer_id: proto::PeerId, - pub role: proto::ChannelRole, - pub projects: Vec, - pub location: ParticipantLocation, - pub participant_index: ParticipantIndex, - pub muted: bool, - pub speaking: bool, -} diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 9d168d6de8..2944112ec9 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -1,12 +1,9 @@ -use crate::{ - call_settings::CallSettings, - participant::{LocalParticipant, ParticipantLocation, RemoteParticipant}, -}; +use crate::call_settings::CallSettings; use anyhow::{anyhow, Result}; use audio::{Audio, Sound}; use client::{ proto::{self, PeerId}, - Client, ParticipantIndex, TypedEnvelope, User, UserStore, + Client, Participant, ParticipantIndex, ParticipantLocation, TypedEnvelope, User, UserStore, }; use collections::{BTreeMap, HashMap, HashSet}; use fs::Fs; @@ -63,7 +60,7 @@ pub struct Room { shared_projects: HashSet>, joined_projects: HashSet>, local_participant: LocalParticipant, - remote_participants: BTreeMap, + remote_participants: BTreeMap, remote_audio_tracks: BTreeMap>>, remote_video_tracks: BTreeMap>>, pending_participants: Vec>, @@ -81,6 +78,13 @@ pub struct Room { maintain_connection: Option>>, } +#[derive(Clone, Default)] +pub struct LocalParticipant { + pub projects: Vec, + pub active_project: Option>, + pub role: proto::ChannelRole, +} + impl EventEmitter for Room {} impl Room { @@ -604,11 +608,11 @@ impl Room { &self.local_participant } - pub fn remote_participants(&self) -> &BTreeMap { + pub fn remote_participants(&self) -> &BTreeMap { &self.remote_participants } - pub fn remote_participant_for_peer_id(&self, peer_id: PeerId) -> Option<&RemoteParticipant> { + pub fn remote_participant_for_peer_id(&self, peer_id: PeerId) -> Option<&Participant> { self.remote_participants .values() .find(|p| p.peer_id == peer_id) @@ -824,7 +828,7 @@ impl Room { } else { this.remote_participants.insert( participant.user_id, - RemoteParticipant { + Participant { user: user.clone(), participant_index, peer_id, diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index b08d423cae..cca5c488f6 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -29,6 +29,25 @@ pub struct Collaborator { pub user_id: UserId, } +#[derive(Clone, Debug)] +pub struct Participant { + pub user: Arc, + pub peer_id: proto::PeerId, + pub role: proto::ChannelRole, + pub projects: Vec, + pub location: ParticipantLocation, + pub participant_index: ParticipantIndex, + pub muted: bool, + pub speaking: bool, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum ParticipantLocation { + SharedProject { project_id: u64 }, + UnsharedProject, + External, +} + impl PartialOrd for User { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) @@ -692,3 +711,20 @@ impl Collaborator { }) } } + +impl ParticipantLocation { + pub fn from_proto(location: Option) -> Result { + match location.and_then(|l| l.variant) { + Some(proto::participant_location::Variant::SharedProject(project)) => { + Ok(Self::SharedProject { + project_id: project.id, + }) + } + Some(proto::participant_location::Variant::UnsharedProject(_)) => { + Ok(Self::UnsharedProject) + } + Some(proto::participant_location::Variant::External(_)) => Ok(Self::External), + None => Err(anyhow!("participant location was not provided")), + } + } +} diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index 1dc48bf1ec..fc06f5d488 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -2,8 +2,8 @@ use crate::{ rpc::{CLEANUP_TIMEOUT, RECONNECT_TIMEOUT}, tests::{channel_id, room_participants, RoomParticipants, TestClient, TestServer}, }; -use call::{room, ActiveCall, ParticipantLocation, Room}; -use client::{User, RECEIVE_TIMEOUT}; +use call::{room, ActiveCall, Room}; +use client::{ParticipantLocation, User, RECEIVE_TIMEOUT}; use collections::{HashMap, HashSet}; use fs::{repository::GitFileStatus, FakeFs, Fs as _, RemoveOptions}; use futures::StreamExt as _; diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index 132410a62a..ee68b4cbc1 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -1,7 +1,7 @@ use crate::face_pile::FacePile; use auto_update::AutoUpdateStatus; -use call::{ActiveCall, ParticipantLocation, Room}; -use client::{proto::PeerId, Client, ParticipantIndex, User, UserStore}; +use call::{ActiveCall, Room}; +use client::{proto::PeerId, Client, ParticipantIndex, ParticipantLocation, User, UserStore}; use gpui::{ actions, canvas, div, point, px, rems, Action, AnyElement, AppContext, Element, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render, diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs index a7368f6136..0dc2899508 100644 --- a/crates/workspace/src/pane_group.rs +++ b/crates/workspace/src/pane_group.rs @@ -1,6 +1,7 @@ use crate::{pane_group::element::pane_axis, AppState, FollowerState, Pane, Workspace}; use anyhow::{anyhow, Result}; -use call::{ActiveCall, ParticipantLocation}; +use call::ActiveCall; +use client::ParticipantLocation; use collections::HashMap; use gpui::{ point, size, AnyWeakView, Axis, Bounds, Entity as _, IntoElement, Model, Pixels, Point, View, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index bb2e34e001..8d78921dcc 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -15,7 +15,7 @@ use anyhow::{anyhow, Context as _, Result}; use call::ActiveCall; use client::{ proto::{self, PeerId}, - Client, Status, TypedEnvelope, UserStore, + Client, ParticipantLocation, Status, TypedEnvelope, UserStore, }; use collections::{hash_map, HashMap, HashSet}; use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle}; @@ -2398,9 +2398,9 @@ impl Workspace { let project = self.project.read(cx); let other_project_id = match remote_participant.location { - call::ParticipantLocation::External => None, - call::ParticipantLocation::UnsharedProject => None, - call::ParticipantLocation::SharedProject { project_id } => { + ParticipantLocation::External => None, + ParticipantLocation::UnsharedProject => None, + ParticipantLocation::SharedProject { project_id } => { if Some(project_id) == project.remote_id() { None } else { @@ -2789,15 +2789,15 @@ impl Workspace { let leader_in_this_app; let leader_in_this_project; match participant.location { - call::ParticipantLocation::SharedProject { project_id } => { + ParticipantLocation::SharedProject { project_id } => { leader_in_this_app = true; leader_in_this_project = Some(project_id) == self.project.read(cx).remote_id(); } - call::ParticipantLocation::UnsharedProject => { + ParticipantLocation::UnsharedProject => { leader_in_this_app = true; leader_in_this_project = false; } - call::ParticipantLocation::External => { + ParticipantLocation::External => { leader_in_this_app = false; leader_in_this_project = false; }