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 peer_id: proto::PeerId,
43 pub projects: Vec<proto::ParticipantProject>,
44 pub location: ParticipantLocation,
45 pub tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>,
46}
47
48#[derive(Clone)]
49pub struct RemoteVideoTrack {
50 pub(crate) live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
51}
52
53impl fmt::Debug for RemoteVideoTrack {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 f.debug_struct("RemoteVideoTrack").finish()
56 }
57}
58
59impl RemoteVideoTrack {
60 pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
61 self.live_kit_track.frames()
62 }
63}