participant.rs

 1#![cfg_attr(target_os = "windows", allow(unused))]
 2
 3use anyhow::{anyhow, Result};
 4use client::{proto, ParticipantIndex, User};
 5use collections::HashMap;
 6use gpui::WeakModel;
 7use livekit_client::AudioStream;
 8use project::Project;
 9use std::sync::Arc;
10
11#[cfg(not(target_os = "windows"))]
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<WeakModel<Project>>,
43    pub role: proto::ChannelRole,
44}
45
46pub struct RemoteParticipant {
47    pub user: Arc<User>,
48    pub peer_id: proto::PeerId,
49    pub role: proto::ChannelRole,
50    pub projects: Vec<proto::ParticipantProject>,
51    pub location: ParticipantLocation,
52    pub participant_index: ParticipantIndex,
53    pub muted: bool,
54    pub speaking: bool,
55    #[cfg(not(target_os = "windows"))]
56    pub video_tracks: HashMap<TrackSid, RemoteVideoTrack>,
57    #[cfg(not(target_os = "windows"))]
58    pub audio_tracks: HashMap<TrackSid, (RemoteAudioTrack, AudioStream)>,
59}
60
61impl RemoteParticipant {
62    pub fn has_video_tracks(&self) -> bool {
63        #[cfg(not(target_os = "windows"))]
64        return !self.video_tracks.is_empty();
65        #[cfg(target_os = "windows")]
66        return false;
67    }
68}