player.rs

  1use gpui2::{Hsla, ViewContext};
  2
  3use crate::prelude::*;
  4
  5#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
  6pub enum PlayerStatus {
  7    #[default]
  8    Offline,
  9    Online,
 10    InCall,
 11    Away,
 12    DoNotDisturb,
 13    Invisible,
 14}
 15
 16#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
 17pub enum MicStatus {
 18    Muted,
 19    #[default]
 20    Unmuted,
 21}
 22
 23impl MicStatus {
 24    pub fn inverse(&self) -> Self {
 25        match self {
 26            Self::Muted => Self::Unmuted,
 27            Self::Unmuted => Self::Muted,
 28        }
 29    }
 30}
 31
 32#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
 33pub enum VideoStatus {
 34    On,
 35    #[default]
 36    Off,
 37}
 38
 39impl VideoStatus {
 40    pub fn inverse(&self) -> Self {
 41        match self {
 42            Self::On => Self::Off,
 43            Self::Off => Self::On,
 44        }
 45    }
 46}
 47
 48#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
 49pub enum ScreenShareStatus {
 50    Shared,
 51    #[default]
 52    NotShared,
 53}
 54
 55impl ScreenShareStatus {
 56    pub fn inverse(&self) -> Self {
 57        match self {
 58            Self::Shared => Self::NotShared,
 59            Self::NotShared => Self::Shared,
 60        }
 61    }
 62}
 63
 64#[derive(Clone)]
 65pub struct PlayerCallStatus {
 66    pub mic_status: MicStatus,
 67    /// Indicates if the player is currently speaking
 68    /// And the intensity of the volume coming through
 69    ///
 70    /// 0.0 - 1.0
 71    pub voice_activity: f32,
 72    pub video_status: VideoStatus,
 73    pub screen_share_status: ScreenShareStatus,
 74    pub in_current_project: bool,
 75    pub disconnected: bool,
 76    pub following: Option<Vec<Player>>,
 77    pub followers: Option<Vec<Player>>,
 78}
 79
 80impl PlayerCallStatus {
 81    pub fn new() -> Self {
 82        Self {
 83            mic_status: MicStatus::default(),
 84            voice_activity: 0.,
 85            video_status: VideoStatus::default(),
 86            screen_share_status: ScreenShareStatus::default(),
 87            in_current_project: true,
 88            disconnected: false,
 89            following: None,
 90            followers: None,
 91        }
 92    }
 93}
 94
 95#[derive(PartialEq, Clone)]
 96pub struct Player {
 97    index: usize,
 98    avatar_src: String,
 99    username: String,
100    status: PlayerStatus,
101}
102
103#[derive(Clone)]
104pub struct PlayerWithCallStatus {
105    player: Player,
106    call_status: PlayerCallStatus,
107}
108
109impl PlayerWithCallStatus {
110    pub fn new(player: Player, call_status: PlayerCallStatus) -> Self {
111        Self {
112            player,
113            call_status,
114        }
115    }
116
117    pub fn get_player(&self) -> &Player {
118        &self.player
119    }
120
121    pub fn get_call_status(&self) -> &PlayerCallStatus {
122        &self.call_status
123    }
124}
125
126impl Player {
127    pub fn new(index: usize, avatar_src: String, username: String) -> Self {
128        Self {
129            index,
130            avatar_src,
131            username,
132            status: Default::default(),
133        }
134    }
135
136    pub fn set_status(mut self, status: PlayerStatus) -> Self {
137        self.status = status;
138        self
139    }
140
141    pub fn cursor_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
142        cx.theme().styles.player.0[self.index].cursor
143    }
144
145    pub fn selection_color<V: 'static>(&self, cx: &mut ViewContext<V>) -> Hsla {
146        cx.theme().styles.player.0[self.index].selection
147    }
148
149    pub fn avatar_src(&self) -> &str {
150        &self.avatar_src
151    }
152
153    pub fn index(&self) -> usize {
154        self.index
155    }
156}