participant.rs

 1use anyhow::{anyhow, Result};
 2use client::ParticipantIndex;
 3use client::{proto, User};
 4use collections::HashMap;
 5use gpui::WeakEntity;
 6pub use livekit_client_macos::Frame;
 7pub use livekit_client_macos::{RemoteAudioTrack, RemoteVideoTrack};
 8use project::Project;
 9use std::sync::Arc;
10
11#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12pub enum ParticipantLocation {
13    SharedProject { project_id: u64 },
14    UnsharedProject,
15    External,
16}
17
18impl ParticipantLocation {
19    pub fn from_proto(location: Option<proto::ParticipantLocation>) -> Result<Self> {
20        match location.and_then(|l| l.variant) {
21            Some(proto::participant_location::Variant::SharedProject(project)) => {
22                Ok(Self::SharedProject {
23                    project_id: project.id,
24                })
25            }
26            Some(proto::participant_location::Variant::UnsharedProject(_)) => {
27                Ok(Self::UnsharedProject)
28            }
29            Some(proto::participant_location::Variant::External(_)) => Ok(Self::External),
30            None => Err(anyhow!("participant location was not provided")),
31        }
32    }
33}
34
35#[derive(Clone, Default)]
36pub struct LocalParticipant {
37    pub projects: Vec<proto::ParticipantProject>,
38    pub active_project: Option<WeakEntity<Project>>,
39    pub role: proto::ChannelRole,
40}
41
42impl LocalParticipant {
43    pub fn can_write(&self) -> bool {
44        matches!(
45            self.role,
46            proto::ChannelRole::Admin | proto::ChannelRole::Member
47        )
48    }
49}
50
51#[derive(Clone, Debug)]
52pub struct RemoteParticipant {
53    pub user: Arc<User>,
54    pub peer_id: proto::PeerId,
55    pub role: proto::ChannelRole,
56    pub projects: Vec<proto::ParticipantProject>,
57    pub location: ParticipantLocation,
58    pub participant_index: ParticipantIndex,
59    pub muted: bool,
60    pub speaking: bool,
61    pub video_tracks: HashMap<livekit_client_macos::Sid, Arc<RemoteVideoTrack>>,
62    pub audio_tracks: HashMap<livekit_client_macos::Sid, Arc<RemoteAudioTrack>>,
63}
64
65impl RemoteParticipant {
66    pub fn has_video_tracks(&self) -> bool {
67        !self.video_tracks.is_empty()
68    }
69
70    pub fn can_write(&self) -> bool {
71        matches!(
72            self.role,
73            proto::ChannelRole::Admin | proto::ChannelRole::Member
74        )
75    }
76}