1use anyhow::{anyhow, Result};
2use client2::ParticipantIndex;
3use client2::{proto, User};
4use gpui2::WeakModel;
5pub use live_kit_client::Frame;
6use project2::Project;
7use std::{fmt, sync::Arc};
8
9#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10pub enum ParticipantLocation {
11 SharedProject { project_id: u64 },
12 UnsharedProject,
13 External,
14}
15
16impl ParticipantLocation {
17 pub fn from_proto(location: Option<proto::ParticipantLocation>) -> Result<Self> {
18 match location.and_then(|l| l.variant) {
19 Some(proto::participant_location::Variant::SharedProject(project)) => {
20 Ok(Self::SharedProject {
21 project_id: project.id,
22 })
23 }
24 Some(proto::participant_location::Variant::UnsharedProject(_)) => {
25 Ok(Self::UnsharedProject)
26 }
27 Some(proto::participant_location::Variant::External(_)) => Ok(Self::External),
28 None => Err(anyhow!("participant location was not provided")),
29 }
30 }
31}
32
33#[derive(Clone, Default)]
34pub struct LocalParticipant {
35 pub projects: Vec<proto::ParticipantProject>,
36 pub active_project: Option<WeakModel<Project>>,
37}
38
39#[derive(Clone, Debug)]
40pub struct RemoteParticipant {
41 pub user: Arc<User>,
42 pub peer_id: proto::PeerId,
43 pub projects: Vec<proto::ParticipantProject>,
44 pub location: ParticipantLocation,
45 pub participant_index: ParticipantIndex,
46 pub muted: bool,
47 pub speaking: bool,
48 // pub video_tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>,
49 // pub audio_tracks: HashMap<live_kit_client::Sid, Arc<RemoteAudioTrack>>,
50}
51
52#[derive(Clone)]
53pub struct RemoteVideoTrack {
54 pub(crate) live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
55}
56
57unsafe impl Send for RemoteVideoTrack {}
58// todo!("remove this sync because it's not legit")
59unsafe impl Sync for RemoteVideoTrack {}
60
61impl fmt::Debug for RemoteVideoTrack {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 f.debug_struct("RemoteVideoTrack").finish()
64 }
65}
66
67impl RemoteVideoTrack {
68 pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
69 self.live_kit_track.frames()
70 }
71}