| 1 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 2 | pub enum MuteCommand { |
| 3 | Mute, |
| 4 | Unmute, |
| 5 | Toggle, |
| 6 | } |
| 7 | |
| 8 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 9 | pub struct MuteEffect { |
| 10 | pub muted: bool, |
| 11 | pub track_enabled: bool, |
| 12 | pub endpoint_is_muted: bool, |
| 13 | } |
| 14 | |
| 15 | impl MuteCommand { |
| 16 | pub fn target(self, currently_muted: bool) -> bool { |
| 17 | match self { |
| 18 | MuteCommand::Mute => true, |
| 19 | MuteCommand::Unmute => false, |
| 20 | MuteCommand::Toggle => !currently_muted, |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl MuteEffect { |
| 26 | pub fn for_muted(muted: bool) -> Self { |
| 27 | MuteEffect { |
| 28 | muted, |
| 29 | track_enabled: !muted, |
| 30 | endpoint_is_muted: muted, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub fn initial(is_meeting: bool) -> Self { |
| 35 | MuteEffect::for_muted(is_meeting) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | #[cfg(test)] |
| 40 | mod tests { |
| 41 | use super::*; |
| 42 | |
| 43 | #[test] |
| 44 | fn commands_map_to_a_target_state() { |
| 45 | assert!(MuteCommand::Mute.target(false)); |
| 46 | assert!(MuteCommand::Mute.target(true)); |
| 47 | assert!(!MuteCommand::Unmute.target(true)); |
| 48 | assert!(MuteCommand::Toggle.target(false)); |
| 49 | assert!(!MuteCommand::Toggle.target(true)); |
| 50 | } |
| 51 | |
| 52 | #[test] |
| 53 | fn muting_stops_the_track_and_tells_teams() { |
| 54 | let muted = MuteEffect::for_muted(true); |
| 55 | assert!(!muted.track_enabled); |
| 56 | assert!(muted.endpoint_is_muted); |
| 57 | let open = MuteEffect::for_muted(false); |
| 58 | assert!(open.track_enabled); |
| 59 | assert!(!open.endpoint_is_muted); |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn meetings_start_muted_and_other_calls_do_not() { |
| 64 | let meeting = MuteEffect::initial(true); |
| 65 | assert!(meeting.muted && !meeting.track_enabled && meeting.endpoint_is_muted); |
| 66 | let direct = MuteEffect::initial(false); |
| 67 | assert!(!direct.muted && direct.track_enabled && !direct.endpoint_is_muted); |
| 68 | } |
| 69 | } |