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