diff --git a/crates/client/src/gui/camera_view.rs b/crates/client/src/gui/camera_view.rs index d06964e..0b9341a 100644 --- a/crates/client/src/gui/camera_view.rs +++ b/crates/client/src/gui/camera_view.rs @@ -25,7 +25,6 @@ const SLOTS: usize = 6; const IDLE_TICK: Duration = Duration::from_millis(250); const FRAME_TICK: Duration = Duration::from_millis(16); const PUMP_STALL: Duration = Duration::from_millis(50); -const STRIP_MAX: usize = 5; const TILE_W: f32 = size::THUMB * 1.5; const TILE_H: f32 = TILE_W * 9. / 16.; @@ -195,16 +194,18 @@ impl Yumush { let Some(community_id) = self.chat.voice_community() else { return Vec::new(); }; - let mut sources: Vec<(Id, Kind)> = self + let mut shares: Vec<&common::share::Share> = self .chat .shares .get(&community_id) .into_iter() .flatten() - .map(|share| (share.user_id, share.kind)) .collect(); - sources.sort(); - sources + shares.sort_by_key(|share| (share.kind != Kind::Camera, share.started_ms, share.user_id)); + shares + .into_iter() + .map(|share| (share.user_id, share.kind)) + .collect() } pub(super) fn stage_strip( @@ -221,10 +222,13 @@ impl Yumush { return None; } let sources = self.stage_sources(); - let more = sources.len().saturating_sub(STRIP_MAX); + let (shown, more) = strip_slots(self.chat.strip_size.0, sources.len()); let strip = (!sources.is_empty()).then(|| { div() .id("stage_strip") + .relative() + .w_full() + .child(probe(entity.clone(), |yumush| &mut yumush.chat.strip_size)) .flex() .flex_shrink_0() .gap(px(space::LG)) @@ -233,7 +237,7 @@ impl Yumush { .children( sources .into_iter() - .take(STRIP_MAX) + .take(shown) .map(|source| stage_tile(entity, self, palette, source).into_any_element()), ) .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element())) @@ -378,28 +382,41 @@ impl Yumush { .flex_col() .justify_center() .gap(px(GRID_GAP)) - .child( - gpui_kit::canvas( - move |bounds, _, cx| { - let size = - (f32::from(bounds.size.width), f32::from(bounds.size.height)); - measure.update(cx, |yumush, cx| { - if yumush.chat.grid_size != size { - yumush.chat.grid_size = size; - cx.notify(); - } - }); - }, - |_, _, _, _| {}, - ) - .absolute() - .inset_0(), - ) + .child(probe(measure, |yumush| &mut yumush.chat.grid_size)) .children(rows), ) } } +fn probe(entity: Entity, slot: fn(&mut Yumush) -> &mut (f32, f32)) -> impl IntoElement { + gpui_kit::canvas( + move |bounds, _, cx| { + let size = (f32::from(bounds.size.width), f32::from(bounds.size.height)); + entity.update(cx, |yumush, cx| { + let stored = slot(yumush); + if *stored != size { + *stored = size; + cx.notify(); + } + }); + }, + |_, _, _, _| {}, + ) + .absolute() + .inset_0() +} + +fn strip_slots(width: f32, count: usize) -> (usize, usize) { + let fit = + (((width - 2. * space::XL + space::LG) / (TILE_W + space::LG)).floor() as usize).max(1); + if count <= fit { + (count, 0) + } else { + let shown = fit - 1; + (shown, count - shown) + } +} + const WIDE: f32 = 16. / 9.; const GRID_GAP: f32 = super::style::stroke::LINE; diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 1558ac5..909fc0b 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -282,6 +282,7 @@ pub struct Chat { pub(super) camera_task: Option>, pub(super) stage: Stage, pub(super) grid_size: (f32, f32), + pub(super) strip_size: (f32, f32), pub(super) typing: HashMap>, pub(super) typing_sent: HashMap, } @@ -579,6 +580,7 @@ impl Chat { camera_task: None, stage: Stage::Strip, grid_size: (1280., 720.), + strip_size: (1280., 0.), composer: Composer::Compose { reply: None }, } } diff --git a/crates/common/src/share.rs b/crates/common/src/share.rs index 912db63..dfa5075 100644 --- a/crates/common/src/share.rs +++ b/crates/common/src/share.rs @@ -151,6 +151,7 @@ pub struct Share { pub user_id: Id, pub kind: Kind, pub source: Source, + pub started_ms: u64, } pub type Mode = (u32, u32); diff --git a/crates/server/src/call/voice.rs b/crates/server/src/call/voice.rs index 3124a1a..57a74c8 100644 --- a/crates/server/src/call/voice.rs +++ b/crates/server/src/call/voice.rs @@ -81,18 +81,16 @@ impl Handle for StartShare { allowed(&me, community_id, cx.db, permission::can_share).await?; ensure(!self.source.encode.is_empty())?; ensure(!db::user::is_ghost(me.id, cx.db).await?)?; - let event = Event::ShareStarted { - community_id, - share: Share { - user_id: me.id, - kind: self.kind, - source: self.source.clone(), - }, - }; - let media = rooms + let (share, media) = rooms .start_share(cx.client.id, self.kind, self.source) .ok_or(Error::NotFound)?; - cx.emit(To::Community(community_id), event); + cx.emit( + To::Community(community_id), + Event::ShareStarted { + community_id, + share, + }, + ); cx.out.extend(media); Ok(()) diff --git a/crates/server/src/rooms.rs b/crates/server/src/rooms.rs index 85835a0..2058604 100644 --- a/crates/server/src/rooms.rs +++ b/crates/server/src/rooms.rs @@ -106,12 +106,22 @@ impl Recent { struct Sharing { source: Source, + started_ms: u64, viewers: Vec, recent: Recent, acked: HashMap, } impl Sharing { + fn share(&self, user_id: Id, kind: Kind) -> Share { + Share { + user_id, + kind, + source: self.source.clone(), + started_ms: self.started_ms, + } + } + fn layers(&self) -> BTreeSet { self.viewers .iter() @@ -557,16 +567,19 @@ impl Rooms { room.seats .values() .flat_map(|seat| { - seat.shares.iter().map(|(kind, sharing)| Share { - user_id: seat.user_id, - kind: *kind, - source: sharing.source.clone(), - }) + seat.shares + .iter() + .map(|(kind, sharing)| sharing.share(seat.user_id, *kind)) }) .collect() } - pub fn start_share(&self, id: ConnId, kind: Kind, source: Source) -> Option> { + pub fn start_share( + &self, + id: ConnId, + kind: Kind, + source: Source, + ) -> Option<(Share, Vec)> { let mut inner = self.0.lock().unwrap(); let (community_id, room) = inner.seat_mut(id)?; let seat = room.seats.get_mut(&id)?; @@ -578,13 +591,17 @@ impl Rooms { }; let sharing = seat.shares.entry(kind).or_insert_with(|| Sharing { source: source.clone(), + started_ms: common::time::now_ms(), viewers: Vec::new(), recent: Recent::default(), acked: HashMap::new(), }); sharing.source = source; - Some(reroute(&sharer, sharing)) + Some(( + sharing.share(sharer.user_id, kind), + reroute(&sharer, sharing), + )) } pub fn stop_share(&self, id: ConnId, kind: Kind) -> Option {