2022-09-23 13:05:32 +00:00
|
|
|
use anyhow::{anyhow, Result};
|
2022-10-03 14:09:49 +00:00
|
|
|
use client::{proto, User};
|
2022-10-17 16:00:54 +00:00
|
|
|
use collections::HashMap;
|
|
|
|
use gpui::{Task, WeakModelHandle};
|
2022-10-19 17:20:31 +00:00
|
|
|
use live_kit_client::Frame;
|
2022-10-11 13:24:31 +00:00
|
|
|
use project::Project;
|
2022-10-03 14:09:49 +00:00
|
|
|
use std::sync::Arc;
|
2022-09-22 15:08:36 +00:00
|
|
|
|
2022-10-04 09:46:01 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
2022-09-23 13:05:32 +00:00
|
|
|
pub enum ParticipantLocation {
|
2022-10-11 13:24:31 +00:00
|
|
|
SharedProject { project_id: u64 },
|
|
|
|
UnsharedProject,
|
2022-09-22 15:08:36 +00:00
|
|
|
External,
|
|
|
|
}
|
2022-09-19 16:01:34 +00:00
|
|
|
|
2022-09-23 13:05:32 +00:00
|
|
|
impl ParticipantLocation {
|
|
|
|
pub fn from_proto(location: Option<proto::ParticipantLocation>) -> Result<Self> {
|
|
|
|
match location.and_then(|l| l.variant) {
|
2022-10-11 13:24:31 +00:00
|
|
|
Some(proto::participant_location::Variant::SharedProject(project)) => {
|
|
|
|
Ok(Self::SharedProject {
|
|
|
|
project_id: project.id,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
Some(proto::participant_location::Variant::UnsharedProject(_)) => {
|
|
|
|
Ok(Self::UnsharedProject)
|
|
|
|
}
|
2022-09-23 13:05:32 +00:00
|
|
|
Some(proto::participant_location::Variant::External(_)) => Ok(Self::External),
|
|
|
|
None => Err(anyhow!("participant location was not provided")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 13:24:31 +00:00
|
|
|
#[derive(Clone, Default)]
|
2022-10-11 10:23:15 +00:00
|
|
|
pub struct LocalParticipant {
|
|
|
|
pub projects: Vec<proto::ParticipantProject>,
|
2022-10-11 13:24:31 +00:00
|
|
|
pub active_project: Option<WeakModelHandle<Project>>,
|
2022-10-11 10:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 16:00:54 +00:00
|
|
|
#[derive(Clone)]
|
2022-09-19 16:01:34 +00:00
|
|
|
pub struct RemoteParticipant {
|
2022-10-03 14:09:49 +00:00
|
|
|
pub user: Arc<User>,
|
2022-10-10 23:56:03 +00:00
|
|
|
pub projects: Vec<proto::ParticipantProject>,
|
2022-09-23 13:05:32 +00:00
|
|
|
pub location: ParticipantLocation,
|
2022-10-18 10:18:49 +00:00
|
|
|
pub tracks: HashMap<live_kit_client::Sid, RemoteVideoTrack>,
|
2022-10-17 16:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct RemoteVideoTrack {
|
2022-10-19 17:20:31 +00:00
|
|
|
pub(crate) frame: Option<Frame>,
|
2022-10-17 16:00:54 +00:00
|
|
|
pub(crate) _live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
|
|
|
|
pub(crate) _maintain_frame: Arc<Task<()>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RemoteVideoTrack {
|
2022-10-19 17:20:31 +00:00
|
|
|
pub fn frame(&self) -> Option<&Frame> {
|
2022-10-17 16:00:54 +00:00
|
|
|
self.frame.as_ref()
|
|
|
|
}
|
2022-09-19 16:01:34 +00:00
|
|
|
}
|