zed/crates/call/src/participant.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

use anyhow::{anyhow, Result};
use client::{proto, User};
2022-10-17 16:00:54 +00:00
use collections::HashMap;
2022-10-24 08:04:08 +00:00
use gpui::WeakModelHandle;
pub use live_kit_client::Frame;
use project::Project;
use std::{fmt, sync::Arc};
2022-09-22 15:08:36 +00:00
2022-10-04 09:46:01 +00:00
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ParticipantLocation {
SharedProject { project_id: u64 },
UnsharedProject,
2022-09-22 15:08:36 +00:00
External,
}
2022-09-19 16:01:34 +00:00
impl ParticipantLocation {
pub fn from_proto(location: Option<proto::ParticipantLocation>) -> Result<Self> {
match location.and_then(|l| l.variant) {
Some(proto::participant_location::Variant::SharedProject(project)) => {
Ok(Self::SharedProject {
project_id: project.id,
})
}
Some(proto::participant_location::Variant::UnsharedProject(_)) => {
Ok(Self::UnsharedProject)
}
Some(proto::participant_location::Variant::External(_)) => Ok(Self::External),
None => Err(anyhow!("participant location was not provided")),
}
}
}
#[derive(Clone, Default)]
pub struct LocalParticipant {
pub projects: Vec<proto::ParticipantProject>,
pub active_project: Option<WeakModelHandle<Project>>,
}
#[derive(Clone, Debug)]
2022-09-19 16:01:34 +00:00
pub struct RemoteParticipant {
pub user: Arc<User>,
pub peer_id: proto::PeerId,
pub projects: Vec<proto::ParticipantProject>,
pub location: ParticipantLocation,
2022-10-24 08:04:08 +00:00
pub tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>,
2022-10-17 16:00:54 +00:00
}
#[derive(Clone)]
pub struct RemoteVideoTrack {
2022-10-24 08:04:08 +00:00
pub(crate) live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
2022-10-17 16:00:54 +00:00
}
impl fmt::Debug for RemoteVideoTrack {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RemoteVideoTrack").finish()
}
}
2022-10-17 16:00:54 +00:00
impl RemoteVideoTrack {
2022-10-24 08:04:08 +00:00
pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
self.live_kit_track.frames()
2022-10-17 16:00:54 +00:00
}
2022-09-19 16:01:34 +00:00
}