forge
Explore
Log in

Don't you dare go Hollow

Own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission

Browse files at this commit

24aef4b3223f010e4f22b434d0200bd62565feccAhmet Kaan GümüşParent: 19bdbbf
  • feat
    • own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission
    • stats rates read kbps/Mbps
Show full message
✨ feat: own voice meter always shows the mic (dimmed while gated/muted-off), speaking state still follows transmission; stats rates read kbps/Mbps
crates/client/src/gui/chat.rsmodified+3 -3
@@ -2375,12 +2375,12 @@ impl Yumush {
23752375 }
23762376
23772377 fn update_waves(&mut self, levels: Levels, cx: &mut Context<Self>) {
2378- let silent = self
2378+ let deafened = self
23792379 .chat
23802380 .voice_flags()
2381- .is_some_and(|(muted, deafened)| muted || deafened);
2381+ .is_some_and(|(_, deafened)| deafened);
23822382 let me = self.user.as_ref().map(|user| user.id);
2383- if self.chat.waves.update(levels, me, silent) {
2383+ if self.chat.waves.update(levels, me, deafened) {
23842384 cx.notify();
23852385 }
23862386 }
crates/client/src/gui/dock.rsmodified+5 -1
@@ -186,7 +186,11 @@ impl Yumush {
186186 .flex_1()
187187 .flex()
188188 .justify_center()
189- .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone));
189+ .child(wave::wave_slot(
190+ self.chat.waves.voice(me),
191+ 14.,
192+ self.chat.waves.tone(me, Some(me), tone),
193+ ));
190194 let group = hoverable_with(
191195 "dock_mic",
192196 div()
crates/client/src/gui/sidebar.rsmodified+14 -6
@@ -142,7 +142,10 @@ impl Yumush {
142142
143143 fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement {
144144 let ids = self.chat.voice_ids(community_id);
145- let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id));
145+ let wave = ids
146+ .iter()
147+ .filter(|id| self.chat.waves.speaking.contains(id))
148+ .find_map(|id| self.chat.waves.voice(*id));
146149 div()
147150 .id(format!("voice_chip_{community_id}"))
148151 .tip("In call")
@@ -197,11 +200,16 @@ impl Yumush {
197200 palette: Palette,
198201 ) -> impl IntoElement {
199202 let user_id = user.id;
200- let speaking = self.chat.waves.speaking.contains(&user_id);
201- let wave = speaking.then(|| self.chat.waves.voice(user_id)).flatten();
202- let muted = (self.is_me(user_id)
203- && self.chat.voice_flags().is_some_and(|(muted, _)| muted))
203+ let me = self.is_me(user_id);
204+ let muted = (me && self.chat.voice_flags().is_some_and(|(muted, _)| muted))
204205 || self.chat.server_muted.contains(&user_id);
206+ let speaking = self.chat.waves.speaking.contains(&user_id);
207+ let shown = speaking || (me && !muted);
208+ let wave = shown.then(|| self.chat.waves.voice(user_id)).flatten();
209+ let wave_tone =
210+ self.chat
211+ .waves
212+ .tone(user_id, self.user.as_ref().map(|user| user.id), palette.ok);
205213 let camera = self
206214 .chat
207215 .share_of(community_id, user_id, Kind::Camera)
@@ -229,7 +237,7 @@ impl Yumush {
229237 .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD))
230238 .child(user.username.clone()),
231239 )
232- .children(wave.map(|history| mini_wave(history, 12., palette.ok)))
240+ .children(wave.map(|history| mini_wave(history, 12., wave_tone)))
233241 .children((muted && wave.is_none()).then(|| {
234242 Icon::new(IconName::MicOff)
235243 .w(px(12.))
crates/client/src/gui/voice_stats.rsmodified+2 -2
@@ -554,8 +554,8 @@ fn largest(values: impl Iterator<Item = u32>) -> f32 {
554554
555555 pub fn rate(kbps: u32) -> String {
556556 match kbps {
557- 0..1000 => format!("{kbps} kb"),
558- _ => format!("{:.1} Mb", kbps as f32 / 1000.),
557+ 0..1000 => format!("{kbps} kbps"),
558+ _ => format!("{:.1} Mbps", kbps as f32 / 1000.),
559559 }
560560 }
561561
crates/client/src/gui/wave.rsmodified+18 -7
@@ -81,6 +81,7 @@ fn soften(bands: &[f32]) -> Vec<f32> {
8181 #[derive(Default)]
8282 pub struct Waves {
8383 pub speaking: HashSet<Id>,
84+ pub own_live: bool,
8485 voice: HashMap<Id, Wave>,
8586 share: HashMap<Id, Wave>,
8687 }
@@ -100,19 +101,21 @@ fn advance(waves: &mut HashMap<Id, Wave>, levels: Vec<(Id, Vec<f32>)>) -> bool {
100101 }
101102
102103 impl Waves {
103- pub fn update(&mut self, levels: Levels, me: Option<Id>, silent: bool) -> bool {
104+ pub fn update(&mut self, levels: Levels, me: Option<Id>, deafened: bool) -> bool {
104105 let mut voice = levels.voice;
106+ let mut speaking: HashSet<Id> = voice.iter().map(|(id, _)| *id).collect();
107+ let own_live = levels.own_sending && !deafened;
105108 if let Some(me) = me
106- && !levels.own.is_empty()
109+ && !deafened
107110 {
108111 voice.push((me, levels.own));
112+ if own_live {
113+ speaking.insert(me);
114+ }
109115 }
110- if silent {
111- voice.retain(|(id, _)| Some(*id) != me);
112- }
113- let speaking: HashSet<Id> = voice.iter().map(|(id, _)| *id).collect();
114- let mut changed = speaking != self.speaking;
116+ let mut changed = speaking != self.speaking || own_live != self.own_live;
115117 self.speaking = speaking;
118+ self.own_live = own_live;
116119 let had = !self.voice.is_empty() || !self.share.is_empty();
117120 changed |= advance(&mut self.voice, voice);
118121
@@ -126,6 +129,14 @@ impl Waves {
126129 *self = Self::default();
127130 }
128131
132+ pub fn tone(&self, id: Id, me: Option<Id>, color: Hsla) -> Hsla {
133+ if Some(id) == me && !self.own_live {
134+ color.opacity(0.35)
135+ } else {
136+ color
137+ }
138+ }
139+
129140 pub fn voice(&self, id: Id) -> Option<&VecDeque<f32>> {
130141 self.voice.get(&id).map(|wave| &wave.bars)
131142 }
crates/client/src/net/media.rsmodified+1 -0
@@ -613,6 +613,7 @@ impl NetworkHandle {
613613 .as_ref()
614614 .map(Voice::own_level)
615615 .unwrap_or_default(),
616+ own_sending: inner.voice.as_ref().is_some_and(Voice::own_sending),
616617 watching: inner
617618 .watching
618619 .iter()
crates/client/src/net/mod.rsmodified+1 -0
@@ -43,6 +43,7 @@ struct Shared {
4343 pub struct Levels {
4444 pub voice: Vec<(Id, Vec<f32>)>,
4545 pub own: Vec<f32>,
46+ pub own_sending: bool,
4647 pub watching: Vec<(Id, Vec<f32>)>,
4748 pub sharing: Option<Vec<f32>>,
4849 }
crates/client/src/voice/engine.rsmodified+5 -3
@@ -240,6 +240,7 @@ impl Engine {
240240
241241 let mut packets = Vec::new();
242242 for frame in frames.as_chunks::<VOICE_FRAME_SAMPLES>().0 {
243+ self.sent.record(frame, 1);
243244 let loud = rms(frame);
244245 self.level_db = db(loud);
245246 if loud >= self.gate {
@@ -257,9 +258,6 @@ impl Engine {
257258 continue;
258259 }
259260
260- if speaking {
261- self.sent.record(frame, 1);
262- }
263261 let mut samples = *frame;
264262 if speaking && !was_sending {
265263 for (index, sample) in samples[..FADE_SAMPLES].iter_mut().enumerate() {
@@ -450,6 +448,10 @@ impl Engine {
450448 self.sent.take()
451449 }
452450
451+ pub fn sending(&self) -> bool {
452+ self.sending
453+ }
454+
453455 pub fn level_db(&self) -> f32 {
454456 self.level_db
455457 }
crates/client/src/voice/mod.rsmodified+4 -0
@@ -304,6 +304,10 @@ impl Voice {
304304 self.with_engine(Vec::new(), Engine::own_level)
305305 }
306306
307+ pub fn own_sending(&self) -> bool {
308+ self.with_engine(false, |engine| engine.sending())
309+ }
310+
307311 pub fn level_db(&self) -> f32 {
308312 self.with_engine(SILENT_DB, |engine| engine.level_db())
309313 }