forge
Explore
Log in

Don't you dare go Hollow

Stage strip orders cameras first then screens, oldest to newest (server stamps Share.started_ms)

Browse files at this commit

8c8fe48ce8c620e52e40e7bbc98a6336dba03b80Ahmet Kaan GümüşParent: ca921c9
  • feat
    • stage strip orders cameras first then screens, oldest to newest (server stamps Share.started_ms)
    • strip fills its measured width, +N only when tiles don't fit
Show full message
✨ feat: stage strip orders cameras first then screens, oldest to newest (server stamps Share.started_ms); strip fills its measured width, +N only when tiles don't fit
crates/client/src/gui/camera_view.rsmodified+41 -24
@@ -25,7 +25,6 @@ const SLOTS: usize = 6;
25 const IDLE_TICK: Duration = Duration::from_millis(250);25 const IDLE_TICK: Duration = Duration::from_millis(250);
26 const FRAME_TICK: Duration = Duration::from_millis(16);26 const FRAME_TICK: Duration = Duration::from_millis(16);
27 const PUMP_STALL: Duration = Duration::from_millis(50);27 const PUMP_STALL: Duration = Duration::from_millis(50);
28-const STRIP_MAX: usize = 5;
29 const TILE_W: f32 = size::THUMB * 1.5;28 const TILE_W: f32 = size::THUMB * 1.5;
30 const TILE_H: f32 = TILE_W * 9. / 16.;29 const TILE_H: f32 = TILE_W * 9. / 16.;
31 30
@@ -195,16 +194,18 @@ impl Yumush {
195 let Some(community_id) = self.chat.voice_community() else {194 let Some(community_id) = self.chat.voice_community() else {
196 return Vec::new();195 return Vec::new();
197 };196 };
198- let mut sources: Vec<(Id, Kind)> = self197+ let mut shares: Vec<&common::share::Share> = self
199 .chat198 .chat
200 .shares199 .shares
201 .get(&community_id)200 .get(&community_id)
202 .into_iter()201 .into_iter()
203 .flatten()202 .flatten()
204- .map(|share| (share.user_id, share.kind))
205 .collect();203 .collect();
206- sources.sort();204+ shares.sort_by_key(|share| (share.kind != Kind::Camera, share.started_ms, share.user_id));
207- sources205+ shares
206+ .into_iter()
207+ .map(|share| (share.user_id, share.kind))
208+ .collect()
208 }209 }
209 210
210 pub(super) fn stage_strip(211 pub(super) fn stage_strip(
@@ -221,10 +222,13 @@ impl Yumush {
221 return None;222 return None;
222 }223 }
223 let sources = self.stage_sources();224 let sources = self.stage_sources();
224- let more = sources.len().saturating_sub(STRIP_MAX);225+ let (shown, more) = strip_slots(self.chat.strip_size.0, sources.len());
225 let strip = (!sources.is_empty()).then(|| {226 let strip = (!sources.is_empty()).then(|| {
226 div()227 div()
227 .id("stage_strip")228 .id("stage_strip")
229+ .relative()
230+ .w_full()
231+ .child(probe(entity.clone(), |yumush| &mut yumush.chat.strip_size))
228 .flex()232 .flex()
229 .flex_shrink_0()233 .flex_shrink_0()
230 .gap(px(space::LG))234 .gap(px(space::LG))
@@ -233,7 +237,7 @@ impl Yumush {
233 .children(237 .children(
234 sources238 sources
235 .into_iter()239 .into_iter()
236- .take(STRIP_MAX)240+ .take(shown)
237 .map(|source| stage_tile(entity, self, palette, source).into_any_element()),241 .map(|source| stage_tile(entity, self, palette, source).into_any_element()),
238 )242 )
239 .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element()))243 .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element()))
@@ -378,28 +382,41 @@ impl Yumush {
378 .flex_col()382 .flex_col()
379 .justify_center()383 .justify_center()
380 .gap(px(GRID_GAP))384 .gap(px(GRID_GAP))
381- .child(385+ .child(probe(measure, |yumush| &mut yumush.chat.grid_size))
382- gpui_kit::canvas(
383- move |bounds, _, cx| {
384- let size =
385- (f32::from(bounds.size.width), f32::from(bounds.size.height));
386- measure.update(cx, |yumush, cx| {
387- if yumush.chat.grid_size != size {
388- yumush.chat.grid_size = size;
389- cx.notify();
390- }
391- });
392- },
393- |_, _, _, _| {},
394- )
395- .absolute()
396- .inset_0(),
397- )
398 .children(rows),386 .children(rows),
399 )387 )
400 }388 }
401 }389 }
402 390
391+fn probe(entity: Entity<Yumush>, slot: fn(&mut Yumush) -> &mut (f32, f32)) -> impl IntoElement {
392+ gpui_kit::canvas(
393+ move |bounds, _, cx| {
394+ let size = (f32::from(bounds.size.width), f32::from(bounds.size.height));
395+ entity.update(cx, |yumush, cx| {
396+ let stored = slot(yumush);
397+ if *stored != size {
398+ *stored = size;
399+ cx.notify();
400+ }
401+ });
402+ },
403+ |_, _, _, _| {},
404+ )
405+ .absolute()
406+ .inset_0()
407+}
408+
409+fn strip_slots(width: f32, count: usize) -> (usize, usize) {
410+ let fit =
411+ (((width - 2. * space::XL + space::LG) / (TILE_W + space::LG)).floor() as usize).max(1);
412+ if count <= fit {
413+ (count, 0)
414+ } else {
415+ let shown = fit - 1;
416+ (shown, count - shown)
417+ }
418+}
419+
403 const WIDE: f32 = 16. / 9.;420 const WIDE: f32 = 16. / 9.;
404 const GRID_GAP: f32 = super::style::stroke::LINE;421 const GRID_GAP: f32 = super::style::stroke::LINE;
405 422
crates/client/src/gui/chat.rsmodified+2 -0
@@ -282,6 +282,7 @@ pub struct Chat {
282 pub(super) camera_task: Option<Task<()>>,282 pub(super) camera_task: Option<Task<()>>,
283 pub(super) stage: Stage,283 pub(super) stage: Stage,
284 pub(super) grid_size: (f32, f32),284 pub(super) grid_size: (f32, f32),
285+ pub(super) strip_size: (f32, f32),
285 pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,286 pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,
286 pub(super) typing_sent: HashMap<Id, Instant>,287 pub(super) typing_sent: HashMap<Id, Instant>,
287 }288 }
@@ -579,6 +580,7 @@ impl Chat {
579 camera_task: None,580 camera_task: None,
580 stage: Stage::Strip,581 stage: Stage::Strip,
581 grid_size: (1280., 720.),582 grid_size: (1280., 720.),
583+ strip_size: (1280., 0.),
582 composer: Composer::Compose { reply: None },584 composer: Composer::Compose { reply: None },
583 }585 }
584 }586 }
crates/common/src/share.rsmodified+1 -0
@@ -151,6 +151,7 @@ pub struct Share {
151 pub user_id: Id,151 pub user_id: Id,
152 pub kind: Kind,152 pub kind: Kind,
153 pub source: Source,153 pub source: Source,
154+ pub started_ms: u64,
154 }155 }
155 156
156 pub type Mode = (u32, u32);157 pub type Mode = (u32, u32);
crates/server/src/call/voice.rsmodified+8 -10
@@ -81,18 +81,16 @@ impl Handle for StartShare {
81 allowed(&me, community_id, cx.db, permission::can_share).await?;81 allowed(&me, community_id, cx.db, permission::can_share).await?;
82 ensure(!self.source.encode.is_empty())?;82 ensure(!self.source.encode.is_empty())?;
83 ensure(!db::user::is_ghost(me.id, cx.db).await?)?;83 ensure(!db::user::is_ghost(me.id, cx.db).await?)?;
84- let event = Event::ShareStarted {84+ let (share, media) = rooms
85- community_id,
86- share: Share {
87- user_id: me.id,
88- kind: self.kind,
89- source: self.source.clone(),
90- },
91- };
92- let media = rooms
93 .start_share(cx.client.id, self.kind, self.source)85 .start_share(cx.client.id, self.kind, self.source)
94 .ok_or(Error::NotFound)?;86 .ok_or(Error::NotFound)?;
95- cx.emit(To::Community(community_id), event);87+ cx.emit(
88+ To::Community(community_id),
89+ Event::ShareStarted {
90+ community_id,
91+ share,
92+ },
93+ );
96 cx.out.extend(media);94 cx.out.extend(media);
97 95
98 Ok(())96 Ok(())
crates/server/src/rooms.rsmodified+24 -7
@@ -106,12 +106,22 @@ impl Recent {
106 106
107 struct Sharing {107 struct Sharing {
108 source: Source,108 source: Source,
109+ started_ms: u64,
109 viewers: Vec<Viewer>,110 viewers: Vec<Viewer>,
110 recent: Recent,111 recent: Recent,
111 acked: HashMap<Layer, u32>,112 acked: HashMap<Layer, u32>,
112 }113 }
113 114
114 impl Sharing {115 impl Sharing {
116+ fn share(&self, user_id: Id, kind: Kind) -> Share {
117+ Share {
118+ user_id,
119+ kind,
120+ source: self.source.clone(),
121+ started_ms: self.started_ms,
122+ }
123+ }
124+
115 fn layers(&self) -> BTreeSet<Layer> {125 fn layers(&self) -> BTreeSet<Layer> {
116 self.viewers126 self.viewers
117 .iter()127 .iter()
@@ -557,16 +567,19 @@ impl Rooms {
557 room.seats567 room.seats
558 .values()568 .values()
559 .flat_map(|seat| {569 .flat_map(|seat| {
560- seat.shares.iter().map(|(kind, sharing)| Share {570+ seat.shares
561- user_id: seat.user_id,571+ .iter()
562- kind: *kind,572+ .map(|(kind, sharing)| sharing.share(seat.user_id, *kind))
563- source: sharing.source.clone(),
564- })
565 })573 })
566 .collect()574 .collect()
567 }575 }
568 576
569- pub fn start_share(&self, id: ConnId, kind: Kind, source: Source) -> Option<Vec<Broadcast>> {577+ pub fn start_share(
578+ &self,
579+ id: ConnId,
580+ kind: Kind,
581+ source: Source,
582+ ) -> Option<(Share, Vec<Broadcast>)> {
570 let mut inner = self.0.lock().unwrap();583 let mut inner = self.0.lock().unwrap();
571 let (community_id, room) = inner.seat_mut(id)?;584 let (community_id, room) = inner.seat_mut(id)?;
572 let seat = room.seats.get_mut(&id)?;585 let seat = room.seats.get_mut(&id)?;
@@ -578,13 +591,17 @@ impl Rooms {
578 };591 };
579 let sharing = seat.shares.entry(kind).or_insert_with(|| Sharing {592 let sharing = seat.shares.entry(kind).or_insert_with(|| Sharing {
580 source: source.clone(),593 source: source.clone(),
594+ started_ms: common::time::now_ms(),
581 viewers: Vec::new(),595 viewers: Vec::new(),
582 recent: Recent::default(),596 recent: Recent::default(),
583 acked: HashMap::new(),597 acked: HashMap::new(),
584 });598 });
585 sharing.source = source;599 sharing.source = source;
586 600
587- Some(reroute(&sharer, sharing))601+ Some((
602+ sharing.share(sharer.user_id, kind),
603+ reroute(&sharer, sharing),
604+ ))
588 }605 }
589 606
590 pub fn stop_share(&self, id: ConnId, kind: Kind) -> Option<Id> {607 pub fn stop_share(&self, id: ConnId, kind: Kind) -> Option<Id> {