Stage strip orders cameras first then screens, oldest to newest (server stamps Share.started_ms)
Browse files at this commit8c8fe48ce8c620e52e40e7bbc98a6336dba03b80Parent: 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
5 changed files +76 -41
- crates/client/src/gui/camera_view.rs +41 -24
- crates/client/src/gui/chat.rs +2 -0
- crates/common/src/share.rs +1 -0
- crates/server/src/call/voice.rs +8 -10
- crates/server/src/rooms.rs +24 -7
crates/client/src/gui/camera_view.rsmodified+41 -24
| @@ -25,7 +25,6 @@ const SLOTS: usize = 6; | ||
| 25 | 25 | const IDLE_TICK: Duration = Duration::from_millis(250); |
| 26 | 26 | const FRAME_TICK: Duration = Duration::from_millis(16); |
| 27 | 27 | const PUMP_STALL: Duration = Duration::from_millis(50); |
| 28 | -const STRIP_MAX: usize = 5; | |
| 29 | 28 | const TILE_W: f32 = size::THUMB * 1.5; |
| 30 | 29 | const TILE_H: f32 = TILE_W * 9. / 16.; |
| 31 | 30 | |
| @@ -195,16 +194,18 @@ impl Yumush { | ||
| 195 | 194 | let Some(community_id) = self.chat.voice_community() else { |
| 196 | 195 | return Vec::new(); |
| 197 | 196 | }; |
| 198 | - let mut sources: Vec<(Id, Kind)> = self | |
| 197 | + let mut shares: Vec<&common::share::Share> = self | |
| 199 | 198 | .chat |
| 200 | 199 | .shares |
| 201 | 200 | .get(&community_id) |
| 202 | 201 | .into_iter() |
| 203 | 202 | .flatten() |
| 204 | - .map(|share| (share.user_id, share.kind)) | |
| 205 | 203 | .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() | |
| 208 | 209 | } |
| 209 | 210 | |
| 210 | 211 | pub(super) fn stage_strip( |
| @@ -221,10 +222,13 @@ impl Yumush { | ||
| 221 | 222 | return None; |
| 222 | 223 | } |
| 223 | 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 | 226 | let strip = (!sources.is_empty()).then(|| { |
| 226 | 227 | div() |
| 227 | 228 | .id("stage_strip") |
| 229 | + .relative() | |
| 230 | + .w_full() | |
| 231 | + .child(probe(entity.clone(), |yumush| &mut yumush.chat.strip_size)) | |
| 228 | 232 | .flex() |
| 229 | 233 | .flex_shrink_0() |
| 230 | 234 | .gap(px(space::LG)) |
| @@ -233,7 +237,7 @@ impl Yumush { | ||
| 233 | 237 | .children( |
| 234 | 238 | sources |
| 235 | 239 | .into_iter() |
| 236 | - .take(STRIP_MAX) | |
| 240 | + .take(shown) | |
| 237 | 241 | .map(|source| stage_tile(entity, self, palette, source).into_any_element()), |
| 238 | 242 | ) |
| 239 | 243 | .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element())) |
| @@ -378,28 +382,41 @@ impl Yumush { | ||
| 378 | 382 | .flex_col() |
| 379 | 383 | .justify_center() |
| 380 | 384 | .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)) | |
| 398 | 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 | 420 | const WIDE: f32 = 16. / 9.; |
| 404 | 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 | 282 | pub(super) camera_task: Option<Task<()>>, |
| 283 | 283 | pub(super) stage: Stage, |
| 284 | 284 | pub(super) grid_size: (f32, f32), |
| 285 | + pub(super) strip_size: (f32, f32), | |
| 285 | 286 | pub(super) typing: HashMap<Id, HashMap<Id, Instant>>, |
| 286 | 287 | pub(super) typing_sent: HashMap<Id, Instant>, |
| 287 | 288 | } |
| @@ -579,6 +580,7 @@ impl Chat { | ||
| 579 | 580 | camera_task: None, |
| 580 | 581 | stage: Stage::Strip, |
| 581 | 582 | grid_size: (1280., 720.), |
| 583 | + strip_size: (1280., 0.), | |
| 582 | 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 | 151 | pub user_id: Id, |
| 152 | 152 | pub kind: Kind, |
| 153 | 153 | pub source: Source, |
| 154 | + pub started_ms: u64, | |
| 154 | 155 | } |
| 155 | 156 | |
| 156 | 157 | pub type Mode = (u32, u32); |
crates/server/src/call/voice.rsmodified+8 -10
| @@ -81,18 +81,16 @@ impl Handle for StartShare { | ||
| 81 | 81 | allowed(&me, community_id, cx.db, permission::can_share).await?; |
| 82 | 82 | ensure(!self.source.encode.is_empty())?; |
| 83 | 83 | 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 | |
| 93 | 85 | .start_share(cx.client.id, self.kind, self.source) |
| 94 | 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 | 94 | cx.out.extend(media); |
| 97 | 95 | |
| 98 | 96 | Ok(()) |
crates/server/src/rooms.rsmodified+24 -7
| @@ -106,12 +106,22 @@ impl Recent { | ||
| 106 | 106 | |
| 107 | 107 | struct Sharing { |
| 108 | 108 | source: Source, |
| 109 | + started_ms: u64, | |
| 109 | 110 | viewers: Vec<Viewer>, |
| 110 | 111 | recent: Recent, |
| 111 | 112 | acked: HashMap<Layer, u32>, |
| 112 | 113 | } |
| 113 | 114 | |
| 114 | 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 | 125 | fn layers(&self) -> BTreeSet<Layer> { |
| 116 | 126 | self.viewers |
| 117 | 127 | .iter() |
| @@ -557,16 +567,19 @@ impl Rooms { | ||
| 557 | 567 | room.seats |
| 558 | 568 | .values() |
| 559 | 569 | .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)) | |
| 565 | 573 | }) |
| 566 | 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 | 583 | let mut inner = self.0.lock().unwrap(); |
| 571 | 584 | let (community_id, room) = inner.seat_mut(id)?; |
| 572 | 585 | let seat = room.seats.get_mut(&id)?; |
| @@ -578,13 +591,17 @@ impl Rooms { | ||
| 578 | 591 | }; |
| 579 | 592 | let sharing = seat.shares.entry(kind).or_insert_with(|| Sharing { |
| 580 | 593 | source: source.clone(), |
| 594 | + started_ms: common::time::now_ms(), | |
| 581 | 595 | viewers: Vec::new(), |
| 582 | 596 | recent: Recent::default(), |
| 583 | 597 | acked: HashMap::new(), |
| 584 | 598 | }); |
| 585 | 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 | 607 | pub fn stop_share(&self, id: ConnId, kind: Kind) -> Option<Id> { |