forge
Explore
Log in

Don't you dare go Hollow

Paced share sending, auto quality ladder bounded by source so it no longer sticks at 1440p15, blank lines kept in messages, screen stream as its own voice sub-row with audio wave, viewer speaker toggles mute

Browse files at this commit

7acf9fc5a8ffce45ac5338ea5288cbdadb9efb7aAhmet Kaan GümüşParent: 52deafb
  • fix
    • paced share sending, auto quality ladder bounded by source so it no longer sticks at 1440p15, blank lines kept in messages, screen stream as its own voice sub-row with audio wave, viewer speaker toggles mute
Show full message
🐛 fix: paced share sending, auto quality ladder bounded by source so it no longer sticks at 1440p15, blank lines kept in messages, screen stream as its own voice sub-row with audio wave, viewer speaker toggles mute
crates/client/src/gui/camera_view.rsmodified+10 -20
@@ -4,10 +4,8 @@ use std::sync::Arc;
4 use common::share::{Fps, Kind, Quality, Resolution};4 use common::share::{Fps, Kind, Quality, Resolution};
5 use gpui_kit::{5 use gpui_kit::{
6 AnyElement, Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement,6 AnyElement, Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement,
7- RenderImage, StatefulInteractiveElement, Styled, StyledImage, Task, Window,7+ RenderImage, StatefulInteractiveElement, Styled, StyledImage, Task, Window, assets::IconName,
8- assets::IconName,8+ component::Icon, div, img, px,
9- component::Icon,
10- div, img, px,
11 };9 };
12 10
13 use super::{11 use super::{
@@ -78,9 +76,10 @@ impl Yumush {
78 let network = self.network.clone();76 let network = self.network.clone();
79 let volume = self.settings.share.volume;77 let volume = self.settings.share.volume;
80 let choice = self.settings.voice.choice.clone();78 let choice = self.settings.voice.choice.clone();
79+ let top = self.share_top(user_id, kind);
81 spawn_warn(cx, "tile watch", async move {80 spawn_warn(cx, "tile watch", async move {
82 network81 network
83- .watch_share(user_id, kind, quality, volume, choice)82+ .watch_share(user_id, kind, quality, top, volume, choice)
84 .await83 .await
85 });84 });
86 }85 }
@@ -93,12 +92,7 @@ impl Yumush {
93 .copied()92 .copied()
94 .collect();93 .collect();
95 for source in gone {94 for source in gone {
96- if let Some(frame) = self95+ if let Some(frame) = self.chat.tiles.remove(&source).and_then(|tile| tile.frame) {
97- .chat
98- .tiles
99- .remove(&source)
100- .and_then(|tile| tile.frame)
101- {
102 cx.drop_image(frame, None);96 cx.drop_image(frame, None);
103 }97 }
104 if viewing != Some(source) {98 if viewing != Some(source) {
@@ -280,10 +274,7 @@ pub(super) fn ticker(cx: &mut Context<Yumush>) -> Task<()> {
280 cx.spawn(async move |this, cx| {274 cx.spawn(async move |this, cx| {
281 loop {275 loop {
282 cx.background_executor().timer(FRAME_TICK).await;276 cx.background_executor().timer(FRAME_TICK).await;
283- if this277+ if this.update(cx, |yumush, cx| yumush.tick_tiles(cx)).is_err() {
284- .update(cx, |yumush, cx| yumush.tick_tiles(cx))
285- .is_err()
286- {
287 break;278 break;
288 }279 }
289 }280 }
@@ -468,11 +459,10 @@ fn grid_cell(
468 .flex()459 .flex()
469 .items_center()460 .items_center()
470 .gap(px(4.))461 .gap(px(4.))
471- .children((kind == Kind::Screen).then(|| {462+ .children(
472- Icon::new(share_view::kind_icon(kind))463+ (kind == Kind::Screen)
473- .w(px(12.))464+ .then(|| Icon::new(share_view::kind_icon(kind)).w(px(12.)).h(px(12.))),
474- .h(px(12.))465+ )
475- }))
476 .child(name.to_string()),466 .child(name.to_string()),
477 );467 );
478 468
crates/client/src/gui/chat.rsmodified+59 -45
@@ -296,7 +296,9 @@ impl Chat {
296 &message_input,296 &message_input,
297 window,297 window,
298 |this, input, event, window, cx| match event {298 |this, input, event, window, cx| match event {
299- InputEvent::PressEnter { shift: false, .. } => this.submit_composer(input, window, cx),299+ InputEvent::PressEnter { shift: false, .. } => {
300+ this.submit_composer(input, window, cx)
301+ }
300 InputEvent::Change => this.send_typing(cx),302 InputEvent::Change => this.send_typing(cx),
301 _ => {}303 _ => {}
302 },304 },
@@ -531,8 +533,12 @@ impl Chat {
531 533
532 pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) {534 pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) {
533 match self.selected_community_id {535 match self.selected_community_id {
534- Some(_) => self.message_input.update(cx, |input, cx| input.focus(window, cx)),536+ Some(_) => self
535- None => self.search_input.update(cx, |input, cx| input.focus(window, cx)),537+ .message_input
538+ .update(cx, |input, cx| input.focus(window, cx)),
539+ None => self
540+ .search_input
541+ .update(cx, |input, cx| input.focus(window, cx)),
536 }542 }
537 }543 }
538 544
@@ -726,8 +732,11 @@ impl Chat {
726 self.delete_step = DeleteStep::Idle;732 self.delete_step = DeleteStep::Idle;
727 }733 }
728 self.selected_community_id = community_id;734 self.selected_community_id = community_id;
729- self.users735+ self.users.extend(
730- .extend(self.members.drain(..).map(|member| (member.user.id, member.user)));736+ self.members
737+ .drain(..)
738+ .map(|member| (member.user.id, member.user)),
739+ );
731 self.bans.clear();740 self.bans.clear();
732 self.logs.clear();741 self.logs.clear();
733 self.pending_user_delete = None;742 self.pending_user_delete = None;
@@ -2503,35 +2512,33 @@ impl Yumush {
2503 .when(index > 0, |this| this.ml(px(-6.))),2512 .when(index > 0, |this| this.ml(px(-6.))),
2504 )2513 )
2505 }))2514 }))
2506- .children(2515+ .children(self.in_stage_chat().then(|| {
2507- self.in_stage_chat().then(|| {2516+ div()
2508- div()2517+ .ml(px(8.))
2509- .ml(px(8.))2518+ .flex()
2510- .flex()2519+ .items_center()
2511- .items_center()2520+ .p(px(2.))
2512- .p(px(2.))2521+ .gap(px(2.))
2513- .gap(px(2.))2522+ .rounded(px(6.))
2514- .rounded(px(6.))2523+ .border_1()
2515- .border_1()2524+ .border_color(palette.border)
2516- .border_color(palette.border)2525+ .child(stage_button(
2517- .child(stage_button(2526+ entity,
2518- entity,2527+ palette,
2519- palette,2528+ Stage::Strip,
2520- Stage::Strip,2529+ current == Stage::Strip,
2521- current == Stage::Strip,2530+ IconName::GalleryHorizontal,
2522- IconName::GalleryHorizontal,2531+ "Strip",
2523- "Strip",2532+ ))
2524- ))2533+ .child(stage_button(
2525- .child(stage_button(2534+ entity,
2526- entity,2535+ palette,
2527- palette,2536+ Stage::Grid,
2528- Stage::Grid,2537+ current == Stage::Grid,
2529- current == Stage::Grid,2538+ IconName::LayoutGrid,
2530- IconName::LayoutGrid,2539+ "Grid",
2531- "Grid",2540+ ))
2532- ))2541+ })),
2533- }),
2534- ),
2535 )2542 )
2536 }2543 }
2537 2544
@@ -2932,14 +2939,16 @@ fn render_message(
2932 .child(2939 .child(
2933 div()2940 div()
2934 .min_w_0()2941 .min_w_0()
2935- .when(message.body.contains("```"), |this| this.w_full())2942+ .when(message.body.contains("```"), |this| {
2943+ this.w_full()
2944+ })
2936 .child(2945 .child(
2937- TextView::markdown(2946+ TextView::markdown(
2938- format!("message-body-{}", message.id),2947+ format!("message-body-{}", message.id),
2939- hard_breaks(&message.body),2948+ hard_breaks(&message.body),
2940- )2949+ )
2941- .selectable(true),2950+ .selectable(true),
2942- ),2951+ ),
2943 )2952 )
2944 .when(message.edited, |this| {2953 .when(message.edited, |this| {
2945 this.child(2954 this.child(
@@ -3056,9 +3065,10 @@ fn hard_breaks(body: &str) -> String {
3056 fenced = !fenced;3065 fenced = !fenced;
3057 return line.to_string();3066 return line.to_string();
3058 }3067 }
3059- match fenced || line.trim().is_empty() {3068+ match (fenced, line.trim().is_empty()) {
3060- true => line.to_string(),3069+ (true, _) => line.to_string(),
3061- false => format!("{line} "),3070+ (false, true) => "\u{a0} ".to_string(),
3071+ (false, false) => format!("{line} "),
3062 }3072 }
3063 })3073 })
3064 .collect();3074 .collect();
@@ -3088,6 +3098,10 @@ fn stage_button(
3088 .justify_center()3098 .justify_center()
3089 .rounded(px(4.))3099 .rounded(px(4.))
3090 .when(active, |this| this.bg(palette.hover))3100 .when(active, |this| this.bg(palette.hover))
3091- .text_color(if active { palette.accent } else { palette.muted })3101+ .text_color(if active {
3102+ palette.accent
3103+ } else {
3104+ palette.muted
3105+ })
3092 .child(Icon::new(icon).w(px(14.)).h(px(14.)))3106 .child(Icon::new(icon).w(px(14.)).h(px(14.)))
3093 }3107 }
crates/client/src/gui/composer.rsmodified+65 -53
@@ -17,16 +17,20 @@ use gpui_kit::{
17 IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions,17 IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions,
18 assets::IconName,18 assets::IconName,
19 component::{19 component::{
20- Icon, WindowExt, checkbox::Checkbox, input::{InputEvent, InputState, TextareaState}, notification::Notification,20+ Icon, WindowExt,
21- popover::Popover, text::TextView,21+ checkbox::Checkbox,
22+ input::{InputEvent, InputState, TextareaState},
23+ notification::Notification,
24+ popover::Popover,
25+ text::TextView,
22 },26 },
23 div, px,27 div, px,
24 };28 };
25 29
26 use super::{30 use super::{
27- Palette, Trigger, Yumush, clickable,31+ Palette, Trigger, Yumush,
28 chat::{Chat, TYPING_SEND_INTERVAL},32 chat::{Chat, TYPING_SEND_INTERVAL},
29- hoverable, new_input, notify_error, pop_in, primary_button,33+ clickable, hoverable, new_input, notify_error, pop_in, primary_button,
30 };34 };
31 35
32 actions!(composer, [Bold, Italic, Code, Strike]);36 actions!(composer, [Bold, Italic, Code, Strike]);
@@ -141,9 +145,7 @@ fn reply_bar(
141 .map_or("unknown", |user| user.username.as_str())145 .map_or("unknown", |user| user.username.as_str())
142 .to_string();146 .to_string();
143 let quote = message147 let quote = message
144- .map(|message| {148+ .map(super::message_actions::message_text)
145- super::message_actions::message_text(message)
146- })
147 .unwrap_or_default();149 .unwrap_or_default();
148 150
149 bar(palette)151 bar(palette)
@@ -197,7 +199,13 @@ impl Yumush {
197 if self.chat.media.uploading() {199 if self.chat.media.uploading() {
198 return;200 return;
199 }201 }
200- let body = input.read(cx).text().to_string();202+ let body = input
203+ .read(cx)
204+ .text()
205+ .to_string()
206+ .trim_end()
207+ .trim_start_matches(['\n', '\r'])
208+ .to_string();
201 209
202 match self.chat.composer.clone() {210 match self.chat.composer.clone() {
203 Composer::Compose { reply } => self.create_message(reply, body, input, window, cx),211 Composer::Compose { reply } => self.create_message(reply, body, input, window, cx),
@@ -686,19 +694,23 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
686 .min_w_0()694 .min_w_0()
687 .child(compact_field(palette, option)),695 .child(compact_field(palette, option)),
688 )696 )
689- .children((options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| {697+ .children(
690- icon_button(698+ (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(
691- format!("poll_remove_{index}"),699+ || {
692- palette,700+ icon_button(
693- IconName::Close,701+ format!("poll_remove_{index}"),
694- "Remove option",702+ palette,
695- move |_, cx| {703+ IconName::Close,
696- remove.update(cx, |yumush, cx| {704+ "Remove option",
697- yumush.remove_poll_option(index, cx)705+ move |_, cx| {
698- });706+ remove.update(cx, |yumush, cx| {
707+ yumush.remove_poll_option(index, cx)
708+ });
709+ },
710+ )
699 },711 },
700- )712+ ),
701- }))713+ )
702 }))714 }))
703 .child(715 .child(
704 div()716 div()
@@ -719,44 +731,44 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
719 .px(px(6.))731 .px(px(6.))
720 .py(px(2.))732 .py(px(2.))
721 .rounded(px(4.))733 .rounded(px(4.))
722- .text_color(if active { palette.accent } else { palette.muted })734+ .text_color(if active {
735+ palette.accent
736+ } else {
737+ palette.muted
738+ })
723 .bg(palette.accent.opacity(if active { 0.15 } else { 0. }))739 .bg(palette.accent.opacity(if active { 0.15 } else { 0. }))
724 .child(label)740 .child(label)
725 })),741 })),
726 )742 )
727 .child(743 .child(
728- div()744+ div().flex().items_center().justify_between().child(
729- .flex()745+ div()
730- .items_center()746+ .flex()
731- .justify_between()747+ .items_center()
732- .child(748+ .gap(px(12.))
733- div()749+ .child(
734- .flex()750+ Checkbox::new("poll_multiple")
735- .items_center()751+ .label("Multiple answers")
736- .gap(px(12.))752+ .checked(multiple)
737- .child(753+ .on_click(move |_, _, cx| {
738- Checkbox::new("poll_multiple")754+ toggle.update(cx, |yumush, cx| {
739- .label("Multiple answers")755+ yumush.chat.poll_multiple =
740- .checked(multiple)756+ !yumush.chat.poll_multiple;
741- .on_click(move |_, _, cx| {757+ cx.notify();
742- toggle.update(cx, |yumush, cx| {758+ })
743- yumush.chat.poll_multiple =759+ }),
744- !yumush.chat.poll_multiple;760+ )
745- cx.notify();761+ .child(
746- })762+ Checkbox::new("poll_public")
747- }),763+ .label("Show voters")
748- )764+ .checked(public)
749- .child(765+ .on_click(move |_, _, cx| {
750- Checkbox::new("poll_public")766+ toggle_public.update(cx, |yumush, cx| {
751- .label("Show voters")767+ yumush.toggle_poll_public(cx)
752- .checked(public)768+ })
753- .on_click(move |_, _, cx| {769+ }),
754- toggle_public.update(cx, |yumush, cx| {770+ ),
755- yumush.toggle_poll_public(cx)771+ ),
756- })
757- }),
758- ),
759- ),
760 )772 )
761 .child(773 .child(
762 primary_button("poll_create", palette, move |window, cx| {774 primary_button("poll_create", palette, move |window, cx| {
crates/client/src/gui/poll.rsmodified+50 -40
@@ -1,15 +1,15 @@
1-use common::model::Id;
2 use common::call::{ClosePoll, MyVotes, Vote};1 use common::call::{ClosePoll, MyVotes, Vote};
2+use common::model::Id;
3 use common::model::{Message, Poll, Rank, User};3 use common::model::{Message, Poll, Rank, User};
4 use common::time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms};4 use common::time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms};
5 use gpui_kit::{5 use gpui_kit::{
6 Anchor, AnyElement, Context, Div, Entity, FontWeight, InteractiveElement, IntoElement,6 Anchor, AnyElement, Context, Div, Entity, FontWeight, InteractiveElement, IntoElement,
7- ParentElement, StatefulInteractiveElement, Styled, Window, assets::IconName, component::Icon, component::popover::Popover,7+ ParentElement, StatefulInteractiveElement, Styled, Window, assets::IconName, component::Icon,
8- div, prelude::FluentBuilder as _, px, relative,8+ component::popover::Popover, div, prelude::FluentBuilder as _, px, relative,
9 };9 };
10 10
11 use super::{11 use super::{
12- Palette, Trigger, Tooltip as _, Yumush, avatar,12+ Palette, Tooltip as _, Trigger, Yumush, avatar,
13 chat::Chat,13 chat::Chat,
14 clickable, hoverable, pop_in, text,14 clickable, hoverable, pop_in, text,
15 widget::{icon_button, panel, spawn_done},15 widget::{icon_button, panel, spawn_done},
@@ -50,7 +50,12 @@ pub enum PollMode<'a> {
50 Snapshot(Id),50 Snapshot(Id),
51 }51 }
52 52
53-fn status_icon(id: String, icon: IconName, tip: &'static str, palette: Palette) -> impl IntoElement {53+fn status_icon(
54+ id: String,
55+ icon: IconName,
56+ tip: &'static str,
57+ palette: Palette,
58+) -> impl IntoElement {
54 div()59 div()
55 .id(id)60 .id(id)
56 .tip(tip)61 .tip(tip)
@@ -119,13 +124,7 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
119 .items_center()124 .items_center()
120 .gap(px(8.))125 .gap(px(8.))
121 .text_size(text(12.))126 .text_size(text(12.))
122- .child(avatar(127+ .child(avatar(palette, user, px(18.), text(8.), &chat.avatars))
123- palette,
124- user,
125- px(18.),
126- text(8.),
127- &chat.avatars,
128- ))
129 .child(128 .child(
130 div()129 div()
131 .flex_1()130 .flex_1()
@@ -208,11 +207,7 @@ pub fn poll_card(
208 let next = me_id207 let next = me_id
209 .map(|_| next_votes(&mine, position as u32, poll.multiple))208 .map(|_| next_votes(&mine, position as u32, poll.multiple))
210 .unwrap_or_default();209 .unwrap_or_default();
211- let voters_here: &[Id] = if poll.public {210+ let voters_here: &[Id] = if poll.public { &option.voter_ids } else { &[] };
212- &option.voter_ids
213- } else {
214- &[]
215- };
216 let entity = entity.clone();211 let entity = entity.clone();
217 let id = format!("poll_option_{key}_{position}");212 let id = format!("poll_option_{key}_{position}");
218 match vote_id {213 match vote_id {
@@ -278,16 +273,20 @@ pub fn poll_card(
278 div()273 div()
279 .flex()274 .flex()
280 .items_center()275 .items_center()
281- .children(voters_here.iter().take(3).enumerate().filter_map(276+ .children(
282- |(index, id)| {277+ voters_here
283- chat.author(*id).map(|user| {278+ .iter()
284- avatar(palette, user, px(18.), text(8.), &chat.avatars)279+ .take(3)
285- .border_2()280+ .enumerate()
286- .border_color(palette.panel)281+ .filter_map(|(index, id)| {
287- .when(index > 0, |el| el.ml(px(-6.)))282+ chat.author(*id).map(|user| {
288- })283+ avatar(palette, user, px(18.), text(8.), &chat.avatars)
289- },284+ .border_2()
290- ))285+ .border_color(palette.panel)
286+ .when(index > 0, |el| el.ml(px(-6.)))
287+ })
288+ }),
289+ )
291 .children((voters_here.len() > 3).then(|| {290 .children((voters_here.len() > 3).then(|| {
292 div()291 div()
293 .ml(px(4.))292 .ml(px(4.))
@@ -312,17 +311,14 @@ pub fn poll_card(
312 voters_label(voters).into_any_element()311 voters_label(voters).into_any_element()
313 };312 };
314 313
315- let timer = poll314+ let timer = poll.ends_at.filter(|_| !closed).map(|end| {
316- .ends_at315+ div()
317- .filter(|_| !closed)316+ .flex()
318- .map(|end| {317+ .items_center()
319- div()318+ .gap(px(4.))
320- .flex()319+ .child(Icon::new(IconName::Timer).w(px(12.)).h(px(12.)))
321- .items_center()320+ .child(remaining(end))
322- .gap(px(4.))321+ });
323- .child(Icon::new(IconName::Timer).w(px(12.)).h(px(12.)))
324- .child(remaining(end))
325- });
326 322
327 let footer = div()323 let footer = div()
328 .flex()324 .flex()
@@ -504,9 +500,23 @@ impl Yumush {
504 .gap(px(2.))500 .gap(px(2.))
505 .text_size(text(11.))501 .text_size(text(11.))
506 .text_color(palette.muted)502 .text_color(palette.muted)
507- .child(page_button("poll_page_back", IconName::ChevronLeft, "Previous", count - 1, entity, palette))503+ .child(page_button(
504+ "poll_page_back",
505+ IconName::ChevronLeft,
506+ "Previous",
507+ count - 1,
508+ entity,
509+ palette,
510+ ))
508 .child(format!("{}/{count}", page + 1))511 .child(format!("{}/{count}", page + 1))
509- .child(page_button("poll_page_next", IconName::ChevronRight, "Next", 1, entity, palette))512+ .child(page_button(
513+ "poll_page_next",
514+ IconName::ChevronRight,
515+ "Next",
516+ 1,
517+ entity,
518+ palette,
519+ ))
510 }))520 }))
511 .child(icon_button(521 .child(icon_button(
512 "poll_banner_jump",522 "poll_banner_jump",
crates/client/src/gui/share_view.rsmodified+48 -9
@@ -1,11 +1,18 @@
1 use common::model::Id;1 use common::model::Id;
2 use std::{sync::Arc, time::Duration};2 use std::{sync::Arc, time::Duration};
3 3
4-use common::share::{Codec, Fps, Kind, Resolution, Source, options};4+use common::share::{Codec, Fps, Kind, Quality, Resolution, Source, options};
5+
6+const FULL_VOLUME: f32 = 100.;
7+
8+const TOP_QUALITY: Quality = Quality {
9+ resolution: Resolution::P2160,
10+ fps: Fps::F60,
11+};
5 use gpui_kit::{12 use gpui_kit::{
6- Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement,13+ Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement,
7- IntoElement, MouseButton, ObjectFit, ParentElement, RenderImage, StatefulInteractiveElement,14+ MouseButton, ObjectFit, ParentElement, RenderImage, StatefulInteractiveElement, Styled,
8- Styled, StyledImage, Subscription, Task, Window,15+ StyledImage, Subscription, Task, Window,
9 assets::IconName,16 assets::IconName,
10 component::{17 component::{
11 Icon,18 Icon,
@@ -83,6 +90,7 @@ pub(super) struct Viewer {
83 frame: Option<Arc<RenderImage>>,90 frame: Option<Arc<RenderImage>>,
84 pub(super) fullscreen: bool,91 pub(super) fullscreen: bool,
85 volume: Entity<SliderState>,92 volume: Entity<SliderState>,
93+ restore: f32,
86 _subscriptions: Vec<Subscription>,94 _subscriptions: Vec<Subscription>,
87 _tick: Task<()>,95 _tick: Task<()>,
88 }96 }
@@ -119,6 +127,22 @@ impl Yumush {
119 .detach();127 .detach();
120 }128 }
121 129
130+ fn toggle_share_mute(&mut self, window: &mut Window, cx: &mut Context<Self>) {
131+ let current = self.settings.share.volume;
132+ let Some(viewer) = self.chat.viewer.as_mut() else {
133+ return;
134+ };
135+ let next = if current > 0. {
136+ viewer.restore = current;
137+ 0.
138+ } else {
139+ viewer.restore
140+ };
141+ let slider = viewer.volume.clone();
142+ slider.update(cx, |slider, cx| slider.set_value(next, window, cx));
143+ self.update_share(cx, |settings| settings.volume = next);
144+ }
145+
122 fn update_share(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut ShareSettings)) {146 fn update_share(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut ShareSettings)) {
123 let before = self.settings.share.clone();147 let before = self.settings.share.clone();
124 change(&mut self.settings.share);148 change(&mut self.settings.share);
@@ -191,6 +215,13 @@ impl Yumush {
191 });215 });
192 }216 }
193 217
218+ pub(super) fn share_top(&self, user_id: Id, kind: Kind) -> Quality {
219+ self.chat
220+ .voice_community()
221+ .and_then(|community_id| self.chat.share_of(community_id, user_id, kind))
222+ .map_or(TOP_QUALITY, |share| share.source.top)
223+ }
224+
194 pub(super) fn is_watching(&self, user_id: Id, kind: Kind) -> bool {225 pub(super) fn is_watching(&self, user_id: Id, kind: Kind) -> bool {
195 self.chat226 self.chat
196 .viewer227 .viewer
@@ -258,6 +289,7 @@ impl Yumush {
258 frame: None,289 frame: None,
259 fullscreen: false,290 fullscreen: false,
260 volume,291 volume,
292+ restore: FULL_VOLUME,
261 _subscriptions: subscriptions,293 _subscriptions: subscriptions,
262 _tick: tick,294 _tick: tick,
263 });295 });
@@ -266,12 +298,13 @@ impl Yumush {
266 let watch = WatchQuality::Auto;298 let watch = WatchQuality::Auto;
267 let volume = self.settings.share.volume;299 let volume = self.settings.share.volume;
268 let choice = self.settings.voice.choice.clone();300 let choice = self.settings.voice.choice.clone();
301+ let top = self.share_top(user_id, kind);
269 if self.chat.tiles.contains_key(&(user_id, kind)) {302 if self.chat.tiles.contains_key(&(user_id, kind)) {
270 network.set_watch_quality(user_id, kind, watch);303 network.set_watch_quality(user_id, kind, watch);
271 } else {304 } else {
272 cx.spawn_in(window, async move |this, cx| {305 cx.spawn_in(window, async move |this, cx| {
273 if let Err(error) = network306 if let Err(error) = network
274- .watch_share(user_id, kind, watch, volume, choice)307+ .watch_share(user_id, kind, watch, top, volume, choice)
275 .await308 .await
276 {309 {
277 let _ = this.update(cx, |yumush, cx| {310 let _ = this.update(cx, |yumush, cx| {
@@ -478,10 +511,16 @@ impl Yumush {
478 .child(name.to_string())511 .child(name.to_string())
479 .child(div().flex_1())512 .child(div().flex_1())
480 .children(audio.then(|| {513 .children(audio.then(|| {
481- Icon::new(IconName::Volume2)514+ let muted = self.settings.share.volume == 0.;
482- .w(px(14.))515+ icon_button(
483- .h(px(14.))516+ format!("share_mute_{muted}"),
484- .text_color(palette.muted)517+ palette,
518+ if muted { IconName::VolumeX } else { IconName::Volume2 },
519+ if muted { "Unmute" } else { "Mute" },
520+ entity_action(entity, |yumush, window, cx| {
521+ yumush.toggle_share_mute(window, cx)
522+ }),
523+ )
485 }))524 }))
486 .children(audio.then(|| {525 .children(audio.then(|| {
487 div().w(px(80.)).child(526 div().w(px(80.)).child(
crates/client/src/gui/sidebar.rsmodified+55 -42
@@ -30,7 +30,7 @@ use super::{
30 settings_page::{segment, segment_track},30 settings_page::{segment, segment_track},
31 social::Relation,31 social::Relation,
32 voice_stats,32 voice_stats,
33- wave::{mini_wave_slot, wave_slot},33+ wave::wave_slot,
34 widget::{bare_input, compact_frame, icon_button},34 widget::{bare_input, compact_frame, icon_button},
35 };35 };
36 36
@@ -237,8 +237,14 @@ impl Yumush {
237 palette: Palette,237 palette: Palette,
238 ) -> impl IntoElement {238 ) -> impl IntoElement {
239 let speaking = self.chat.waves.speaking.contains(&user.id);239 let speaking = self.chat.waves.speaking.contains(&user.id);
240- let screen = self.chat.share_of(community_id, user.id, Kind::Screen).is_some();240+ let screen = self
241- let camera = self.chat.share_of(community_id, user.id, Kind::Camera).is_some();241+ .chat
242+ .share_of(community_id, user.id, Kind::Screen)
243+ .is_some();
244+ let camera = self
245+ .chat
246+ .share_of(community_id, user.id, Kind::Camera)
247+ .is_some();
242 248
243 let user_id = user.id;249 let user_id = user.id;
244 let watch_screen = entity.clone();250 let watch_screen = entity.clone();
@@ -285,47 +291,15 @@ impl Yumush {
285 }),291 }),
286 );292 );
287 293
288- div()294+ let row = div()
289 .flex()295 .flex()
290 .items_center()296 .items_center()
291 .gap(px(4.))297 .gap(px(4.))
292 .px(px(4.))298 .px(px(4.))
293 .py(px(2.))299 .py(px(2.))
294 .rounded(px(6.))300 .rounded(px(6.))
295- .when(ghost, |row| row.opacity(0.5))
296 .hover(move |style| style.bg(palette.hover))301 .hover(move |style| style.bg(palette.hover))
297 .child(div().flex_1().min_w_0().child(member))302 .child(div().flex_1().min_w_0().child(member))
298- .child(
299- div()
300- .w(px(20.))
301- .h(px(20.))
302- .flex_shrink_0()
303- .when(screen, |slot| {
304- slot.child(
305- clickable(format!("voice_screen_{user_id}"), palette, move |window, cx| {
306- watch_screen.update(cx, |yumush, cx| {
307- yumush.toggle_viewer(user_id, Kind::Screen, window, cx)
308- });
309- })
310- .tip("Watch")
311- .size_full()
312- .flex()
313- .items_center()
314- .justify_center()
315- .rounded(px(4.))
316- .child(match self.chat.waves.share(user_id) {
317- Some(history) => mini_wave_slot(Some(history), 12., palette.ok)
318- .into_any_element(),
319- None => Icon::new(IconName::ScreenShare)
320- .w(px(12.))
321- .h(px(12.))
322- .text_color(palette.alert)
323- .into_any_element(),
324- }),
325- )
326- }),
327- )
328-
329 .child(303 .child(
330 div()304 div()
331 .w(px(20.))305 .w(px(20.))
@@ -333,11 +307,15 @@ impl Yumush {
333 .flex_shrink_0()307 .flex_shrink_0()
334 .when(camera, |slot| {308 .when(camera, |slot| {
335 slot.child(309 slot.child(
336- clickable(format!("voice_camera_{user_id}"), palette, move |window, cx| {310+ clickable(
337- watch_camera.update(cx, |yumush, cx| {311+ format!("voice_camera_{user_id}"),
338- yumush.toggle_viewer(user_id, Kind::Camera, window, cx)312+ palette,
339- });313+ move |window, cx| {
340- })314+ watch_camera.update(cx, |yumush, cx| {
315+ yumush.toggle_viewer(user_id, Kind::Camera, window, cx)
316+ });
317+ },
318+ )
341 .tip("Watch")319 .tip("Watch")
342 .size_full()320 .size_full()
343 .flex()321 .flex()
@@ -353,7 +331,42 @@ impl Yumush {
353 )331 )
354 }),332 }),
355 )333 )
356- .child(wave_slot(self.chat.waves.voice(user_id), 12., palette.ok))334+ .child(wave_slot(self.chat.waves.voice(user_id), 12., palette.ok));
335+
336+ let stream = screen.then(|| {
337+ clickable(
338+ format!("voice_screen_{user_id}"),
339+ palette,
340+ move |window, cx| {
341+ watch_screen.update(cx, |yumush, cx| {
342+ yumush.toggle_viewer(user_id, Kind::Screen, window, cx)
343+ });
344+ },
345+ )
346+ .tip("Watch")
347+ .flex()
348+ .items_center()
349+ .gap(px(4.))
350+ .h(px(20.))
351+ .pl(px(28.))
352+ .pr(px(4.))
353+ .rounded(px(6.))
354+ .child(
355+ Icon::new(IconName::ScreenShare)
356+ .w(px(12.))
357+ .h(px(12.))
358+ .text_color(palette.alert),
359+ )
360+ .child(div().flex_1())
361+ .child(wave_slot(self.chat.waves.share(user_id), 12., palette.ok))
362+ });
363+
364+ div()
365+ .flex()
366+ .flex_col()
367+ .when(ghost, |member| member.opacity(0.5))
368+ .child(row)
369+ .children(stream)
357 }370 }
358 371
359 fn voice_dot(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {372 fn voice_dot(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {
crates/client/src/gui/wave.rsmodified+4 -20
@@ -10,7 +10,6 @@ const GONE: f32 = 0.02;
10 const AUDIBLE: f32 = 0.1;10 const AUDIBLE: f32 = 0.1;
11 const BAR_WIDTH: f32 = 2.;11 const BAR_WIDTH: f32 = 2.;
12 const MIN_BAR: f32 = 1.5;12 const MIN_BAR: f32 = 1.5;
13-const MINI_GROUP: usize = 4;
14 13
15 pub struct Wave {14 pub struct Wave {
16 bars: VecDeque<f32>,15 bars: VecDeque<f32>,
@@ -91,34 +90,19 @@ impl Waves {
91 }90 }
92 91
93 pub fn wave_slot(history: Option<&VecDeque<f32>>, size: f32, color: Hsla) -> Div {92 pub fn wave_slot(history: Option<&VecDeque<f32>>, size: f32, color: Hsla) -> Div {
94- slot(spectrum::BANDS, history.map(|history| history.iter().copied().collect()), size, color)
95-}
96-
97-pub fn mini_wave_slot(history: Option<&VecDeque<f32>>, size: f32, color: Hsla) -> Div {
98- let bars = history.map(|history| {
99- let history: Vec<f32> = history.iter().copied().collect();
100- history
101- .chunks(MINI_GROUP)
102- .map(|group| group.iter().copied().fold(0., f32::max))
103- .collect()
104- });
105- slot(spectrum::BANDS / MINI_GROUP, bars, size, color)
106-}
107-
108-fn slot(count: usize, bars: Option<Vec<f32>>, size: f32, color: Hsla) -> Div {
109 div()93 div()
110 .flex_shrink_0()94 .flex_shrink_0()
111- .w(px(count as f32 * (BAR_WIDTH + 1.)))95+ .w(px(spectrum::BANDS as f32 * (BAR_WIDTH + 1.)))
112- .children(bars.map(|bars| wave(&bars, size, color)))96+ .children(history.map(|history| wave(history, size, color)))
113 }97 }
114 98
115-fn wave(bars: &[f32], size: f32, color: Hsla) -> Div {99+fn wave(history: &VecDeque<f32>, size: f32, color: Hsla) -> Div {
116 div()100 div()
117 .flex()101 .flex()
118 .items_center()102 .items_center()
119 .gap(px(1.))103 .gap(px(1.))
120 .h(px(size))104 .h(px(size))
121- .children(bars.iter().map(|bar| {105+ .children(history.iter().map(|bar| {
122 div()106 div()
123 .w(px(BAR_WIDTH))107 .w(px(BAR_WIDTH))
124 .h(px((size * bar).max(MIN_BAR)))108 .h(px((size * bar).max(MIN_BAR)))
crates/client/src/net/link.rsmodified+2 -1
@@ -80,7 +80,8 @@ impl Endpoints {
80 }80 }
81 81
82 let bind: SocketAddr = bind.parse().map_err(|_| LinkError::Unreachable)?;82 let bind: SocketAddr = bind.parse().map_err(|_| LinkError::Unreachable)?;
83- let mut endpoint = common::transport::endpoint(bind, None).map_err(|_| LinkError::Unreachable)?;83+ let mut endpoint =
84+ common::transport::endpoint(bind, None).map_err(|_| LinkError::Unreachable)?;
84 endpoint.set_default_client_config(config()?);85 endpoint.set_default_client_config(config()?);
85 *slot = Some(endpoint.clone());86 *slot = Some(endpoint.clone());
86 87
crates/client/src/net/media.rsmodified+2 -1
@@ -629,12 +629,13 @@ impl NetworkHandle {
629 user_id: Id,629 user_id: Id,
630 kind: Kind,630 kind: Kind,
631 watch: WatchQuality,631 watch: WatchQuality,
632+ top: Quality,
632 volume: f32,633 volume: f32,
633 choice: Choice,634 choice: Choice,
634 ) -> Result<(), Fail> {635 ) -> Result<(), Fail> {
635 let media = self.media().clone();636 let media = self.media().clone();
636 let key = (user_id, kind);637 let key = (user_id, kind);
637- let watching = Watching::new(kind, watch, volume, choice);638+ let watching = Watching::new(kind, watch, top, volume, choice);
638 let quality = watching.wanted();639 let quality = watching.wanted();
639 640
640 self.media()641 self.media()
crates/client/src/share/encode.rsmodified+7 -0
@@ -319,6 +319,13 @@ impl Encoders {
319 }319 }
320 }320 }
321 321
322+ pub fn bitrate(&self) -> u32 {
323+ self.lanes
324+ .keys()
325+ .map(|layer| layer.bitrate(self.source_width, self.source_height))
326+ .sum()
327+ }
328+
322 pub fn set_scale(&self, scale: f32) {329 pub fn set_scale(&self, scale: f32) {
323 self.scale.store(scale.to_bits(), Ordering::Relaxed);330 self.scale.store(scale.to_bits(), Ordering::Relaxed);
324 }331 }
crates/client/src/share/mod.rsmodified+1 -0
@@ -16,6 +16,7 @@ pub mod encode;
16 #[cfg(any(target_os = "linux", target_os = "windows"))]16 #[cfg(any(target_os = "linux", target_os = "windows"))]
17 pub mod fake;17 pub mod fake;
18 pub mod frame;18 pub mod frame;
19+pub mod pacer;
19 pub mod reassembly;20 pub mod reassembly;
20 pub mod session;21 pub mod session;
21 #[cfg(not(any(target_os = "linux", target_os = "windows")))]22 #[cfg(not(any(target_os = "linux", target_os = "windows")))]
crates/client/src/share/pacer.rsadded+37 -0
@@ -0,0 +1,37 @@
1+use std::time::{Duration, Instant};
2+
3+const FACTOR: f64 = 2.5;
4+const BURST_BYTES: f64 = 16. * 1024.;
5+const MIN_BYTES_PER_SECOND: f64 = 256. * 1024.;
6+
7+pub struct Pacer {
8+ budget: f64,
9+ at: Instant,
10+}
11+
12+impl Default for Pacer {
13+ fn default() -> Self {
14+ Self {
15+ budget: BURST_BYTES,
16+ at: Instant::now(),
17+ }
18+ }
19+}
20+
21+impl Pacer {
22+ pub fn wait(&mut self, bytes: usize, bitrate: u32) {
23+ let rate = (f64::from(bitrate) / 8. * FACTOR).max(MIN_BYTES_PER_SECOND);
24+ let bytes = bytes as f64;
25+ loop {
26+ let now = Instant::now();
27+ self.budget =
28+ (self.budget + now.duration_since(self.at).as_secs_f64() * rate).min(BURST_BYTES);
29+ self.at = now;
30+ if self.budget >= bytes {
31+ self.budget -= bytes;
32+ return;
33+ }
34+ std::thread::sleep(Duration::from_secs_f64((bytes - self.budget) / rate));
35+ }
36+ }
37+}
crates/client/src/share/session.rsmodified+34 -9
@@ -32,6 +32,7 @@ use super::{
32 congestion::{self, Controller, Uplink},32 congestion::{self, Controller, Uplink},
33 encode::{self, Encoders},33 encode::{self, Encoders},
34 frame::{Encoded, Frame},34 frame::{Encoded, Frame},
35+ pacer::Pacer,
35 reassembly::{Assembled, Reassembler},36 reassembly::{Assembled, Reassembler},
36 };37 };
37 use crate::media::{38 use crate::media::{
@@ -258,9 +259,9 @@ impl Sharing {
258 })259 })
259 };260 };
260 let sender = {261 let sender = {
261- let sent = sent.clone();262+ let (sent, encoders) = (sent.clone(), encoders.clone());
262 Worker::spawn("share-send", move |stop| {263 Worker::spawn("share-send", move |stop| {
263- send(kind, encoded, connection, sent, stop)264+ send(kind, encoded, connection, encoders, sent, stop)
264 })265 })
265 };266 };
266 267
@@ -371,11 +372,14 @@ fn send(
371 kind: Kind,372 kind: Kind,
372 rx: Receiver<Encoded>,373 rx: Receiver<Encoded>,
373 connection: Connection,374 connection: Connection,
375+ encoders: Arc<Mutex<Encoders>>,
374 sent: Arc<Mutex<Sent>>,376 sent: Arc<Mutex<Sent>>,
375 stop: &AtomicBool,377 stop: &AtomicBool,
376 ) {378 ) {
377 let mut counters: HashMap<Layer, u32> = HashMap::new();379 let mut counters: HashMap<Layer, u32> = HashMap::new();
380+ let mut pacer = Pacer::default();
378 while let Some(item) = next(&rx, stop) {381 while let Some(item) = next(&rx, stop) {
382+ let bitrate = lock(&encoders).bitrate();
379 lock(&sent).record(&item);383 lock(&sent).record(&item);
380 let counter = counters.entry(item.layer).or_default();384 let counter = counters.entry(item.layer).or_default();
381 let number = *counter;385 let number = *counter;
@@ -387,7 +391,10 @@ fn send(
387 item.keyframe,391 item.keyframe,
388 item.timestamp_ms,392 item.timestamp_ms,
389 &item.data,393 &item.data,
390- |packet| datagram::send(&connection, Bytes::copy_from_slice(packet)),394+ |packet| {
395+ pacer.wait(packet.len(), bitrate);
396+ datagram::send(&connection, Bytes::copy_from_slice(packet));
397+ },
391 );398 );
392 }399 }
393 }400 }
@@ -485,13 +492,21 @@ pub struct Watching {
485 _output: Option<Audio>,492 _output: Option<Audio>,
486 quality: WatchQuality,493 quality: WatchQuality,
487 emitted: Option<Quality>,494 emitted: Option<Quality>,
495+ ladder: Vec<Quality>,
488 rung: usize,496 rung: usize,
489 clean: u32,497 clean: u32,
490 requested: Option<Instant>,498 requested: Option<Instant>,
491 }499 }
492 500
493 impl Watching {501 impl Watching {
494- pub fn new(kind: Kind, quality: WatchQuality, volume: f32, choice: Choice) -> Watching {502+ pub fn new(
503+ kind: Kind,
504+ quality: WatchQuality,
505+ top: Quality,
506+ volume: f32,
507+ choice: Choice,
508+ ) -> Watching {
509+ let ladder = ladder(top);
495 let clock = Arc::new(Clock {510 let clock = Arc::new(Clock {
496 started: Instant::now(),511 started: Instant::now(),
497 offset: AtomicI64::new(i64::MAX),512 offset: AtomicI64::new(i64::MAX),
@@ -540,10 +555,11 @@ impl Watching {
540 _output: output,555 _output: output,
541 quality,556 quality,
542 emitted: None,557 emitted: None,
543- rung: rungs()558+ rung: ladder
544 .iter()559 .iter()
545 .position(|quality| *quality == SHARE_QUALITY)560 .position(|quality| *quality == SHARE_QUALITY)
546 .unwrap_or(0),561 .unwrap_or(0),
562+ ladder,
547 clean: 0,563 clean: 0,
548 requested: None,564 requested: None,
549 };565 };
@@ -554,7 +570,7 @@ impl Watching {
554 pub fn wanted(&self) -> Quality {570 pub fn wanted(&self) -> Quality {
555 match self.quality {571 match self.quality {
556 WatchQuality::Fixed(quality) => quality,572 WatchQuality::Fixed(quality) => quality,
557- WatchQuality::Auto => rungs()[self.rung],573+ WatchQuality::Auto => self.ladder[self.rung],
558 }574 }
559 }575 }
560 576
@@ -655,12 +671,12 @@ impl Watching {
655 fn adapt(&mut self, loss: f32, served: Option<Layer>) {671 fn adapt(&mut self, loss: f32, served: Option<Layer>) {
656 let rung = self.rung;672 let rung = self.rung;
657 if loss > LOSS_LIMIT {673 if loss > LOSS_LIMIT {
658- self.rung = (self.rung + 1).min(rungs().len() - 1);674+ self.rung = (self.rung + 1).min(self.ladder.len() - 1);
659 self.clean = 0;675 self.clean = 0;
660 } else if loss < CLEAN_LOSS {676 } else if loss < CLEAN_LOSS {
661 self.clean += 1;677 self.clean += 1;
662 if self.clean >= CLEAN_SECONDS678 if self.clean >= CLEAN_SECONDS
663- && served.is_some_and(|layer| layer.quality == rungs()[self.rung])679+ && served.is_some_and(|layer| layer.quality == self.ladder[self.rung])
664 {680 {
665 self.rung = self.rung.saturating_sub(1);681 self.rung = self.rung.saturating_sub(1);
666 self.clean = 0;682 self.clean = 0;
@@ -669,11 +685,20 @@ impl Watching {
669 self.clean = 0;685 self.clean = 0;
670 }686 }
671 if self.rung != rung {687 if self.rung != rung {
672- tracing::info!(loss, quality = ?rungs()[self.rung], "share watch quality");688+ tracing::info!(loss, quality = ?self.ladder[self.rung], "share watch quality");
673 }689 }
674 }690 }
675 }691 }
676 692
693+fn ladder(top: Quality) -> Vec<Quality> {
694+ let ladder: Vec<Quality> = rungs()
695+ .iter()
696+ .filter(|quality| quality.resolution <= top.resolution && quality.fps <= top.fps)
697+ .copied()
698+ .collect();
699+ if ladder.is_empty() { vec![top] } else { ladder }
700+}
701+
677 fn rungs() -> &'static [Quality] {702 fn rungs() -> &'static [Quality] {
678 static RUNGS: LazyLock<Vec<Quality>> = LazyLock::new(|| {703 static RUNGS: LazyLock<Vec<Quality>> = LazyLock::new(|| {
679 let mut rungs: Vec<Quality> = Resolution::ALL704 let mut rungs: Vec<Quality> = Resolution::ALL