participant.rs

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