participant.rs

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