participant.rs

 1use anyhow::{anyhow, Result};
 2use client::{proto, User};
 3use collections::HashMap;
 4use gpui::WeakModelHandle;
 5pub use live_kit_client::Frame;
 6use live_kit_client::RemoteAudioTrack;
 7use project::Project;
 8use std::{fmt, sync::Arc};
 9
10#[derive(Copy, Clone, Debug, Eq, PartialEq)]
11pub enum ParticipantLocation {
12    SharedProject { project_id: u64 },
13    UnsharedProject,
14    External,
15}
16
17impl ParticipantLocation {
18    pub fn from_proto(location: Option<proto::ParticipantLocation>) -> Result<Self> {
19        match location.and_then(|l| l.variant) {
20            Some(proto::participant_location::Variant::SharedProject(project)) => {
21                Ok(Self::SharedProject {
22                    project_id: project.id,
23                })
24            }
25            Some(proto::participant_location::Variant::UnsharedProject(_)) => {
26                Ok(Self::UnsharedProject)
27            }
28            Some(proto::participant_location::Variant::External(_)) => Ok(Self::External),
29            None => Err(anyhow!("participant location was not provided")),
30        }
31    }
32}
33
34#[derive(Clone, Default)]
35pub struct LocalParticipant {
36    pub projects: Vec<proto::ParticipantProject>,
37    pub active_project: Option<WeakModelHandle<Project>>,
38}
39
40#[derive(Clone, Debug)]
41pub struct RemoteParticipant {
42    pub user: Arc<User>,
43    pub peer_id: proto::PeerId,
44    pub projects: Vec<proto::ParticipantProject>,
45    pub location: ParticipantLocation,
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
57impl fmt::Debug for RemoteVideoTrack {
58    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59        f.debug_struct("RemoteVideoTrack").finish()
60    }
61}
62
63impl RemoteVideoTrack {
64    pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
65        self.live_kit_track.frames()
66    }
67}