BlueGit

ict rusty-teams

Files

rusty-teams / crates / calling / src / mute.rs

mute.rs

mute.rs 1.4 KiB Download Raw
1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum MuteCommand {
3 Mute,
4 Unmute,
5 Toggle,
6}
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct MuteEffect {
10 pub muted: bool,
11 pub track_enabled: bool,
12 pub endpoint_is_muted: bool,
13}
14
15impl 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
25impl 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
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn commands_map_to_a_target_state() {
41 assert!(MuteCommand::Mute.target(false));
42 assert!(MuteCommand::Mute.target(true));
43 assert!(!MuteCommand::Unmute.target(true));
44 assert!(MuteCommand::Toggle.target(false));
45 assert!(!MuteCommand::Toggle.target(true));
46 }
47
48 #[test]
49 fn muting_stops_the_track_and_tells_teams() {
50 let muted = MuteEffect::for_muted(true);
51 assert!(!muted.track_enabled);
52 assert!(muted.endpoint_is_muted);
53 let open = MuteEffect::for_muted(false);
54 assert!(open.track_enabled);
55 assert!(!open.endpoint_is_muted);
56 }
57}