1use anyhow::{anyhow, Result};
2use client::{proto, User};
3use collections::HashMap;
4use gpui::{Task, WeakModelHandle};
5use media::core_video::CVImageBuffer;
6use project::Project;
7use std::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)]
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, RemoteVideoTrack>,
45}
46
47#[derive(Clone)]
48pub struct RemoteVideoTrack {
49 pub(crate) frame: Option<CVImageBuffer>,
50 pub(crate) _live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
51 pub(crate) _maintain_frame: Arc<Task<()>>,
52}
53
54impl RemoteVideoTrack {
55 pub fn frame(&self) -> Option<&CVImageBuffer> {
56 self.frame.as_ref()
57 }
58}