diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 0630e2c..045efa1 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -2375,12 +2375,12 @@ impl Yumush { } fn update_waves(&mut self, levels: Levels, cx: &mut Context) { - let silent = self + let deafened = self .chat .voice_flags() - .is_some_and(|(muted, deafened)| muted || deafened); + .is_some_and(|(_, deafened)| deafened); let me = self.user.as_ref().map(|user| user.id); - if self.chat.waves.update(levels, me, silent) { + if self.chat.waves.update(levels, me, deafened) { cx.notify(); } } diff --git a/crates/client/src/gui/dock.rs b/crates/client/src/gui/dock.rs index af8e5e3..80b0262 100644 --- a/crates/client/src/gui/dock.rs +++ b/crates/client/src/gui/dock.rs @@ -186,7 +186,11 @@ impl Yumush { .flex_1() .flex() .justify_center() - .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone)); + .child(wave::wave_slot( + self.chat.waves.voice(me), + 14., + self.chat.waves.tone(me, Some(me), tone), + )); let group = hoverable_with( "dock_mic", div() diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index d97a4db..7f21b1b 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -142,7 +142,10 @@ impl Yumush { fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement { let ids = self.chat.voice_ids(community_id); - let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id)); + let wave = ids + .iter() + .filter(|id| self.chat.waves.speaking.contains(id)) + .find_map(|id| self.chat.waves.voice(*id)); div() .id(format!("voice_chip_{community_id}")) .tip("In call") @@ -197,11 +200,16 @@ impl Yumush { palette: Palette, ) -> impl IntoElement { let user_id = user.id; - let speaking = self.chat.waves.speaking.contains(&user_id); - let wave = speaking.then(|| self.chat.waves.voice(user_id)).flatten(); - let muted = (self.is_me(user_id) - && self.chat.voice_flags().is_some_and(|(muted, _)| muted)) + let me = self.is_me(user_id); + let muted = (me && self.chat.voice_flags().is_some_and(|(muted, _)| muted)) || self.chat.server_muted.contains(&user_id); + let speaking = self.chat.waves.speaking.contains(&user_id); + let shown = speaking || (me && !muted); + let wave = shown.then(|| self.chat.waves.voice(user_id)).flatten(); + let wave_tone = + self.chat + .waves + .tone(user_id, self.user.as_ref().map(|user| user.id), palette.ok); let camera = self .chat .share_of(community_id, user_id, Kind::Camera) @@ -229,7 +237,7 @@ impl Yumush { .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD)) .child(user.username.clone()), ) - .children(wave.map(|history| mini_wave(history, 12., palette.ok))) + .children(wave.map(|history| mini_wave(history, 12., wave_tone))) .children((muted && wave.is_none()).then(|| { Icon::new(IconName::MicOff) .w(px(12.)) diff --git a/crates/client/src/gui/voice_stats.rs b/crates/client/src/gui/voice_stats.rs index 61fae04..5090a82 100644 --- a/crates/client/src/gui/voice_stats.rs +++ b/crates/client/src/gui/voice_stats.rs @@ -554,8 +554,8 @@ fn largest(values: impl Iterator) -> f32 { pub fn rate(kbps: u32) -> String { match kbps { - 0..1000 => format!("{kbps} kb"), - _ => format!("{:.1} Mb", kbps as f32 / 1000.), + 0..1000 => format!("{kbps} kbps"), + _ => format!("{:.1} Mbps", kbps as f32 / 1000.), } } diff --git a/crates/client/src/gui/wave.rs b/crates/client/src/gui/wave.rs index 4cd2ebb..0d9a10c 100644 --- a/crates/client/src/gui/wave.rs +++ b/crates/client/src/gui/wave.rs @@ -81,6 +81,7 @@ fn soften(bands: &[f32]) -> Vec { #[derive(Default)] pub struct Waves { pub speaking: HashSet, + pub own_live: bool, voice: HashMap, share: HashMap, } @@ -100,19 +101,21 @@ fn advance(waves: &mut HashMap, levels: Vec<(Id, Vec)>) -> bool { } impl Waves { - pub fn update(&mut self, levels: Levels, me: Option, silent: bool) -> bool { + pub fn update(&mut self, levels: Levels, me: Option, deafened: bool) -> bool { let mut voice = levels.voice; + let mut speaking: HashSet = voice.iter().map(|(id, _)| *id).collect(); + let own_live = levels.own_sending && !deafened; if let Some(me) = me - && !levels.own.is_empty() + && !deafened { voice.push((me, levels.own)); + if own_live { + speaking.insert(me); + } } - if silent { - voice.retain(|(id, _)| Some(*id) != me); - } - let speaking: HashSet = voice.iter().map(|(id, _)| *id).collect(); - let mut changed = speaking != self.speaking; + let mut changed = speaking != self.speaking || own_live != self.own_live; self.speaking = speaking; + self.own_live = own_live; let had = !self.voice.is_empty() || !self.share.is_empty(); changed |= advance(&mut self.voice, voice); @@ -126,6 +129,14 @@ impl Waves { *self = Self::default(); } + pub fn tone(&self, id: Id, me: Option, color: Hsla) -> Hsla { + if Some(id) == me && !self.own_live { + color.opacity(0.35) + } else { + color + } + } + pub fn voice(&self, id: Id) -> Option<&VecDeque> { self.voice.get(&id).map(|wave| &wave.bars) } diff --git a/crates/client/src/net/media.rs b/crates/client/src/net/media.rs index 6ed7c71..a85d155 100644 --- a/crates/client/src/net/media.rs +++ b/crates/client/src/net/media.rs @@ -613,6 +613,7 @@ impl NetworkHandle { .as_ref() .map(Voice::own_level) .unwrap_or_default(), + own_sending: inner.voice.as_ref().is_some_and(Voice::own_sending), watching: inner .watching .iter() diff --git a/crates/client/src/net/mod.rs b/crates/client/src/net/mod.rs index f1e16f0..1fcc00d 100644 --- a/crates/client/src/net/mod.rs +++ b/crates/client/src/net/mod.rs @@ -43,6 +43,7 @@ struct Shared { pub struct Levels { pub voice: Vec<(Id, Vec)>, pub own: Vec, + pub own_sending: bool, pub watching: Vec<(Id, Vec)>, pub sharing: Option>, } diff --git a/crates/client/src/voice/engine.rs b/crates/client/src/voice/engine.rs index aec6a8d..669e3ce 100644 --- a/crates/client/src/voice/engine.rs +++ b/crates/client/src/voice/engine.rs @@ -240,6 +240,7 @@ impl Engine { let mut packets = Vec::new(); for frame in frames.as_chunks::().0 { + self.sent.record(frame, 1); let loud = rms(frame); self.level_db = db(loud); if loud >= self.gate { @@ -257,9 +258,6 @@ impl Engine { continue; } - if speaking { - self.sent.record(frame, 1); - } let mut samples = *frame; if speaking && !was_sending { for (index, sample) in samples[..FADE_SAMPLES].iter_mut().enumerate() { @@ -450,6 +448,10 @@ impl Engine { self.sent.take() } + pub fn sending(&self) -> bool { + self.sending + } + pub fn level_db(&self) -> f32 { self.level_db } diff --git a/crates/client/src/voice/mod.rs b/crates/client/src/voice/mod.rs index 5f6dbc6..78f9926 100644 --- a/crates/client/src/voice/mod.rs +++ b/crates/client/src/voice/mod.rs @@ -304,6 +304,10 @@ impl Voice { self.with_engine(Vec::new(), Engine::own_level) } + pub fn own_sending(&self) -> bool { + self.with_engine(false, |engine| engine.sending()) + } + pub fn level_db(&self) -> f32 { self.with_engine(SILENT_DB, |engine| engine.level_db()) }