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;
2525 const IDLE_TICK: Duration = Duration::from_millis(250);
2626 const FRAME_TICK: Duration = Duration::from_millis(16);
2727 const PUMP_STALL: Duration = Duration::from_millis(50);
28-const STRIP_MAX: usize = 5;
2928 const TILE_W: f32 = size::THUMB * 1.5;
3029 const TILE_H: f32 = TILE_W * 9. / 16.;
3130
@@ -195,16 +194,18 @@ impl Yumush {
195194 let Some(community_id) = self.chat.voice_community() else {
196195 return Vec::new();
197196 };
198- let mut sources: Vec<(Id, Kind)> = self
197+ let mut shares: Vec<&common::share::Share> = self
199198 .chat
200199 .shares
201200 .get(&community_id)
202201 .into_iter()
203202 .flatten()
204- .map(|share| (share.user_id, share.kind))
205203 .collect();
206- sources.sort();
207- sources
204+ shares.sort_by_key(|share| (share.kind != Kind::Camera, share.started_ms, share.user_id));
205+ shares
206+ .into_iter()
207+ .map(|share| (share.user_id, share.kind))
208+ .collect()
208209 }
209210
210211 pub(super) fn stage_strip(
@@ -221,10 +222,13 @@ impl Yumush {
221222 return None;
222223 }
223224 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());
225226 let strip = (!sources.is_empty()).then(|| {
226227 div()
227228 .id("stage_strip")
229+ .relative()
230+ .w_full()
231+ .child(probe(entity.clone(), |yumush| &mut yumush.chat.strip_size))
228232 .flex()
229233 .flex_shrink_0()
230234 .gap(px(space::LG))
@@ -233,7 +237,7 @@ impl Yumush {
233237 .children(
234238 sources
235239 .into_iter()
236- .take(STRIP_MAX)
240+ .take(shown)
237241 .map(|source| stage_tile(entity, self, palette, source).into_any_element()),
238242 )
239243 .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element()))
@@ -378,28 +382,41 @@ impl Yumush {
378382 .flex_col()
379383 .justify_center()
380384 .gap(px(GRID_GAP))
381- .child(
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- )
385+ .child(probe(measure, |yumush| &mut yumush.chat.grid_size))
398386 .children(rows),
399387 )
400388 }
401389 }
402390
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+
403420 const WIDE: f32 = 16. / 9.;
404421 const GRID_GAP: f32 = super::style::stroke::LINE;
405422
crates/client/src/gui/chat.rsmodified+2 -0
@@ -282,6 +282,7 @@ pub struct Chat {
282282 pub(super) camera_task: Option<Task<()>>,
283283 pub(super) stage: Stage,
284284 pub(super) grid_size: (f32, f32),
285+ pub(super) strip_size: (f32, f32),
285286 pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,
286287 pub(super) typing_sent: HashMap<Id, Instant>,
287288 }
@@ -579,6 +580,7 @@ impl Chat {
579580 camera_task: None,
580581 stage: Stage::Strip,
581582 grid_size: (1280., 720.),
583+ strip_size: (1280., 0.),
582584 composer: Composer::Compose { reply: None },
583585 }
584586 }
crates/common/src/share.rsmodified+1 -0
@@ -151,6 +151,7 @@ pub struct Share {
151151 pub user_id: Id,
152152 pub kind: Kind,
153153 pub source: Source,
154+ pub started_ms: u64,
154155 }
155156
156157 pub type Mode = (u32, u32);
crates/server/src/call/voice.rsmodified+8 -10
@@ -81,18 +81,16 @@ impl Handle for StartShare {
8181 allowed(&me, community_id, cx.db, permission::can_share).await?;
8282 ensure(!self.source.encode.is_empty())?;
8383 ensure(!db::user::is_ghost(me.id, cx.db).await?)?;
84- let event = Event::ShareStarted {
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
84+ let (share, media) = rooms
9385 .start_share(cx.client.id, self.kind, self.source)
9486 .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+ );
9694 cx.out.extend(media);
9795
9896 Ok(())
crates/server/src/rooms.rsmodified+24 -7
@@ -106,12 +106,22 @@ impl Recent {
106106
107107 struct Sharing {
108108 source: Source,
109+ started_ms: u64,
109110 viewers: Vec<Viewer>,
110111 recent: Recent,
111112 acked: HashMap<Layer, u32>,
112113 }
113114
114115 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+
115125 fn layers(&self) -> BTreeSet<Layer> {
116126 self.viewers
117127 .iter()
@@ -557,16 +567,19 @@ impl Rooms {
557567 room.seats
558568 .values()
559569 .flat_map(|seat| {
560- seat.shares.iter().map(|(kind, sharing)| Share {
561- user_id: seat.user_id,
562- kind: *kind,
563- source: sharing.source.clone(),
564- })
570+ seat.shares
571+ .iter()
572+ .map(|(kind, sharing)| sharing.share(seat.user_id, *kind))
565573 })
566574 .collect()
567575 }
568576
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>)> {
570583 let mut inner = self.0.lock().unwrap();
571584 let (community_id, room) = inner.seat_mut(id)?;
572585 let seat = room.seats.get_mut(&id)?;
@@ -578,13 +591,17 @@ impl Rooms {
578591 };
579592 let sharing = seat.shares.entry(kind).or_insert_with(|| Sharing {
580593 source: source.clone(),
594+ started_ms: common::time::now_ms(),
581595 viewers: Vec::new(),
582596 recent: Recent::default(),
583597 acked: HashMap::new(),
584598 });
585599 sharing.source = source;
586600
587- Some(reroute(&sharer, sharing))
601+ Some((
602+ sharing.share(sharer.user_id, kind),
603+ reroute(&sharer, sharing),
604+ ))
588605 }
589606
590607 pub fn stop_share(&self, id: ConnId, kind: Kind) -> Option<Id> {