BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_layouts.rs

call_layouts.rs

call_layouts.rs 26.9 KiB Download Raw
1use std::time::Instant;
2
3use gpui_kit::assets::IconName;
4use gpui_kit::component::{
5 button::{Button, ButtonVariants as _},
6 h_flex,
7 popover::Popover,
8 tooltip::Tooltip,
9 v_flex,
10};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use super::avatar::person_avatar;
15use super::call_organizer::render_focus_stage;
16use super::call_view::{
17 GRID_PADDING, STRIP_GAP, TILE_GAP, own_tile, person_tile,
18};
19use super::widgets::icon;
20use crate::app_state::AppState;
21use crate::call::{
22 ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,
23 filmstrip, focus_stage_size, gallery_grid, share_strip, shown_bubbles, split_overflow,
24};
25use calling::{TileDetail, VideoWant};
26use crate::theme;
27
28const FALLBACK_STAGE: (f32, f32) = (900., 560.);
29const MEASURE_TOLERANCE: f32 = 0.5;
30const OVERLAY_INSET: f32 = 16.;
31const DIVIDER_LINE: f32 = 4.;
32const DIVIDER_LENGTH: f32 = 48.;
33const CHIP_TOP: f32 = 12.;
34const FILMSTRIP_TILE_MAX: f32 = 220.;
35const TILE_RADIUS: f32 = 12.;
36const HIDDEN_LIST_WIDTH: f32 = 260.;
37const HIDDEN_LIST_HEIGHT: f32 = 320.;
38const HIDDEN_AVATAR: f32 = 28.;
39const STACK_MAX: usize = 3;
40const STACK_OVERLAP: f32 = 0.35;
41const BUBBLE_WIDTH: f32 = 340.;
42const BUBBLE_AVATAR: f32 = 28.;
43const BUBBLE_GAP: f32 = 8.;
44const BUBBLE_FADE_FROM: f32 = 0.9;
45const BUBBLE_BACKGROUND: f32 = 0.72;
46const CHIP_BACKGROUND: f32 = 0.6;
47pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";
48
49pub fn measured_stage(call: &ActiveCall) -> (f32, f32) {
50 let (width, height) = call.stage_size.get();
51 if width < 1. || height < 1. {
52 return FALLBACK_STAGE;
53 }
54 (width, height)
55}
56
57fn measure_stage(call: &ActiveCall) -> impl IntoElement {
58 let stage_size = call.stage_size.clone();
59 canvas(
60 |_, _, _| {},
61 move |bounds, _, window, _| {
62 let measured = (f32::from(bounds.size.width), f32::from(bounds.size.height));
63 let known = stage_size.get();
64 if (known.0 - measured.0).abs() > MEASURE_TOLERANCE
65 || (known.1 - measured.1).abs() > MEASURE_TOLERANCE
66 {
67 stage_size.set(measured);
68 window.refresh();
69 }
70 },
71 )
72 .absolute()
73 .size_full()
74}
75
76fn dark_chip() -> Div {
77 h_flex()
78 .h(px(30.))
79 .px(px(12.))
80 .gap(px(8.))
81 .items_center()
82 .rounded_full()
83 .bg(hsla(0., 0., 0., CHIP_BACKGROUND))
84 .text_color(theme::white())
85 .text_size(px(13.))
86 .font_weight(FontWeight::SEMIBOLD)
87}
88
89fn without_video_chip(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
90 let count = model.hidden_without_video();
91 if !model.view.hide_no_video || count == 0 {
92 return None;
93 }
94 let app = app.clone();
95 Some(
96 div()
97 .absolute()
98 .top(px(CHIP_TOP))
99 .left_0()
100 .right_0()
101 .flex()
102 .justify_center()
103 .child(
104 dark_chip()
105 .id("call-no-video-chip")
106 .cursor_pointer()
107 .hover(|chip| chip.opacity(0.85))
108 .tooltip(|window, cx| {
109 Tooltip::new("Show people without video").build(window, cx)
110 })
111 .child(icon(IconName::VideoOff, 15., theme::white()))
112 .child(format!("{count} without video"))
113 .on_click(move |_, _, cx| {
114 app.update(cx, |state, cx| state.toggle_call_hide_no_video(cx))
115 }),
116 )
117 .into_any_element(),
118 )
119}
120
121fn show_me_pill(app: &Entity<AppState>, model: &CallModel, bottom: f32) -> Option<AnyElement> {
122 if !model.view.hide_me {
123 return None;
124 }
125 let app = app.clone();
126 Some(
127 div()
128 .absolute()
129 .right(px(OVERLAY_INSET))
130 .bottom(px(bottom))
131 .child(
132 dark_chip()
133 .id("call-show-me")
134 .cursor_pointer()
135 .hover(|chip| chip.opacity(0.85))
136 .tooltip(|window, cx| Tooltip::new("Show me").build(window, cx))
137 .child(icon(IconName::Eye, 15., theme::white()))
138 .child("You")
139 .on_click(move |_, _, cx| {
140 app.update(cx, |state, cx| state.set_call_hide_me(false, cx))
141 }),
142 )
143 .into_any_element(),
144 )
145}
146
147fn chat_bubbles(
148 app: &Entity<AppState>,
149 state: &AppState,
150 call: &ActiveCall,
151 now: Instant,
152 bottom: f32,
153) -> Option<AnyElement> {
154 if call.chat_open || !call.model.view.chat_bubbles {
155 return None;
156 }
157 let bubbles = shown_bubbles(&call.bubbles, now);
158 if bubbles.is_empty() {
159 return None;
160 }
161 let shown = crate::call::BUBBLE_SHOWN;
162 Some(
163 v_flex()
164 .absolute()
165 .right(px(OVERLAY_INSET))
166 .bottom(px(bottom))
167 .items_end()
168 .gap(px(BUBBLE_GAP))
169 .children(bubbles.into_iter().map(|bubble| {
170 let app = app.clone();
171 let id = SharedString::from(format!("call-bubble-{}", bubble.id));
172 h_flex()
173 .id(id.clone())
174 .max_w(px(BUBBLE_WIDTH))
175 .pl(px(6.))
176 .pr(px(14.))
177 .py(px(6.))
178 .gap(px(8.))
179 .items_center()
180 .rounded_full()
181 .bg(hsla(0., 0., 0., BUBBLE_BACKGROUND))
182 .text_color(theme::white())
183 .text_size(px(13.))
184 .cursor_pointer()
185 .child(person_avatar(
186 &state.directory,
187 bubble.sender_id.as_deref(),
188 &bubble.name,
189 BUBBLE_AVATAR,
190 ))
191 .child(
192 h_flex()
193 .min_w_0()
194 .flex_1()
195 .gap(px(6.))
196 .child(
197 div()
198 .flex_none()
199 .font_weight(FontWeight::BOLD)
200 .child(bubble.name.clone()),
201 )
202 .child(div().min_w_0().truncate().child(bubble.text.clone())),
203 )
204 .on_click(move |_, _, cx| {
205 app.update(cx, |state, cx| {
206 if state.call_chat_thread().is_none() {
207 state.toggle_call_chat(cx);
208 }
209 })
210 })
211 .with_animation(id, Animation::new(shown), |bubble, delta| {
212 let fade =
213 ((delta - BUBBLE_FADE_FROM) / (1. - BUBBLE_FADE_FROM)).clamp(0., 1.);
214 bubble.opacity(1. - fade)
215 })
216 }))
217 .into_any_element(),
218 )
219}
220
221fn fullscreen_hint(call: &ActiveCall, now: Instant, bottom: f32) -> Option<AnyElement> {
222 call.fullscreen
223 .filter(|fullscreen| fullscreen.hint_visible(now))
224 .map(|_| {
225 div()
226 .absolute()
227 .left_0()
228 .right_0()
229 .bottom(px(bottom))
230 .flex()
231 .justify_center()
232 .child(dark_chip().h(px(32.)).child(FULLSCREEN_HINT))
233 .into_any_element()
234 })
235}
236
237fn stacked_avatars(state: &AppState, hidden: &[&Tile], diameter: f32) -> Div {
238 let shown: Vec<&&Tile> = hidden.iter().take(STACK_MAX).collect();
239 let step = diameter * (1. - STACK_OVERLAP);
240 div()
241 .relative()
242 .h(px(diameter))
243 .w(px(diameter + step * (shown.len().saturating_sub(1)) as f32))
244 .children(shown.into_iter().enumerate().map(|(index, tile)| {
245 div()
246 .absolute()
247 .top_0()
248 .left(px(step * index as f32))
249 .rounded_full()
250 .bg(theme::row_hover())
251 .child(person_avatar(
252 &state.directory,
253 tile.user_id.as_deref(),
254 &tile.name,
255 diameter,
256 ))
257 }))
258}
259
260fn overflow_tile(
261 app: &Entity<AppState>,
262 state: &AppState,
263 size: TileSize,
264 hidden: &[&Tile],
265) -> AnyElement {
266 let people: Vec<(String, String, Option<String>)> = hidden
267 .iter()
268 .map(|tile| (tile.mri.clone(), tile.name.clone(), tile.user_id.clone()))
269 .collect();
270 let diameter = (size.height * 0.3).clamp(22., 44.);
271 let face = v_flex()
272 .w(px(size.width))
273 .h(px(size.height))
274 .items_center()
275 .justify_center()
276 .gap(px(size.height * 0.06))
277 .rounded(px(TILE_RADIUS))
278 .bg(theme::row_hover())
279 .child(stacked_avatars(state, hidden, diameter))
280 .child(
281 div()
282 .text_size(px((size.height * 0.2).clamp(14., 28.)))
283 .font_weight(FontWeight::SEMIBOLD)
284 .text_color(theme::text_muted())
285 .child(format!("+{}", hidden.len())),
286 );
287 let app = app.clone();
288 Popover::new("call-hidden-popover")
289 .anchor(Anchor::BottomLeft)
290 .offset(px(8.))
291 .trigger(
292 Button::new("call-hidden")
293 .ghost()
294 .p_0()
295 .w(px(size.width))
296 .h(px(size.height))
297 .rounded(px(TILE_RADIUS))
298 .child(face),
299 )
300 .content(move |_, _, cx| {
301 let popover = cx.entity().downgrade();
302 v_flex()
303 .id("call-hidden-list")
304 .w(px(HIDDEN_LIST_WIDTH))
305 .max_h(px(HIDDEN_LIST_HEIGHT))
306 .overflow_y_scroll()
307 .gap(px(2.))
308 .children(people.iter().map(|(mri, name, user_id)| {
309 let app_for_click = app.clone();
310 let popover = popover.clone();
311 let pinned_mri = mri.clone();
312 h_flex()
313 .id(SharedString::from(format!("call-hidden-{mri}")))
314 .w_full()
315 .px(px(8.))
316 .py(px(6.))
317 .gap(px(10.))
318 .items_center()
319 .rounded(px(8.))
320 .cursor_pointer()
321 .hover(|row| row.bg(theme::row_hover()))
322 .child(person_avatar(
323 &app.read(cx).directory,
324 user_id.as_deref(),
325 name,
326 HIDDEN_AVATAR,
327 ))
328 .child(div().min_w_0().flex_1().truncate().child(name.clone()))
329 .on_click(move |_, window, cx| {
330 app_for_click
331 .update(cx, |state, cx| state.toggle_call_pin(&pinned_mri, cx));
332 popover
333 .update(cx, |state, cx| state.dismiss(window, cx))
334 .ok();
335 })
336 }))
337 })
338 .into_any_element()
339}
340
341fn own_slot(model: &CallModel, shown: &[&Tile]) -> usize {
342 match model.own_hand {
343 None => shown.len(),
344 Some(rank) => shown
345 .iter()
346 .filter(|tile| tile.hand.is_some_and(|other| other < rank))
347 .count(),
348 }
349}
350
351fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {
352 let mut rows = Vec::new();
353 let mut remaining = cells.into_iter();
354 loop {
355 let row: Vec<AnyElement> = remaining.by_ref().take(columns).collect();
356 if row.is_empty() {
357 return rows;
358 }
359 rows.push(h_flex().gap(px(TILE_GAP)).justify_center().children(row));
360 }
361}
362
363fn gallery_split(model: &CallModel) -> (Vec<&Tile>, Overflow) {
364 let others = model.layout_tiles();
365 let overflow = split_overflow(others.len(), model.own_cells(), GALLERY_MAX);
366 (others, overflow)
367}
368
369fn gallery_body(
370 app: &Entity<AppState>,
371 state: &AppState,
372 model: &CallModel,
373 now: Instant,
374 stage: (f32, f32),
375) -> AnyElement {
376 let (others, overflow) = gallery_split(model);
377 let own_cells = model.own_cells();
378 let cells = overflow.shown + own_cells + usize::from(overflow.hidden > 0);
379 let grid = gallery_grid(
380 cells,
381 stage.0 - 2. * GRID_PADDING,
382 stage.1 - 2. * GRID_PADDING,
383 TILE_GAP,
384 );
385 let size = TileSize::sixteen_by_nine(grid.tile_width.floor());
386 let shown = &others[..overflow.shown];
387 let mut tiles: Vec<AnyElement> = shown
388 .iter()
389 .map(|tile| person_tile(app, state, model, tile, size, now))
390 .collect();
391 if own_cells > 0 {
392 tiles.insert(
393 own_slot(model, shown),
394 own_tile(app, state, model, size, now),
395 );
396 }
397 if overflow.hidden > 0 {
398 tiles.push(overflow_tile(app, state, size, &others[overflow.shown..]));
399 }
400 v_flex()
401 .absolute()
402 .inset_0()
403 .items_center()
404 .justify_center()
405 .gap(px(TILE_GAP))
406 .children(rows_of(tiles, grid.columns))
407 .into_any_element()
408}
409
410struct SpeakerSplit<'a> {
411 focus: Option<Focus>,
412 others: Vec<&'a Tile>,
413 own_cells: usize,
414 plan: Filmstrip,
415}
416
417fn speaker_split(model: &CallModel, stage: (f32, f32)) -> SpeakerSplit<'_> {
418 let focus = model.speaker_focus();
419 let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
420 let mut others: Vec<&Tile> = model
421 .layout_tiles()
422 .into_iter()
423 .filter(|tile| Some(tile.mri.as_str()) != focus_mri)
424 .collect();
425 let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
426 let plan = filmstrip(
427 others.len(),
428 own_cells,
429 stage.0 - 2. * GRID_PADDING,
430 TILE_GAP,
431 FILMSTRIP_TILE_MAX,
432 );
433 if plan.overflow.shown < FILMSTRIP_MAX.min(others.len()) {
434 others.sort_by_key(|tile| !model.is_recent_speaker(&tile.mri));
435 }
436 SpeakerSplit { focus, others, own_cells, plan }
437}
438
439fn speaker_body(
440 app: &Entity<AppState>,
441 state: &AppState,
442 model: &CallModel,
443 now: Instant,
444 stage: (f32, f32),
445) -> AnyElement {
446 let SpeakerSplit { focus, others, own_cells, plan } = speaker_split(model, stage);
447 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
448 let has_filmstrip = plan.overflow.shown + own_cells + usize::from(plan.overflow.hidden > 0) > 0;
449 let focus_size = focus_stage_size(stage, GRID_PADDING, TILE_GAP, has_filmstrip.then_some(size.height));
450 let main = focus
451 .as_ref()
452 .and_then(|focus| render_focus_stage(app, state, focus, focus_size, now));
453 let shown = &others[..plan.overflow.shown];
454 let mut tiles: Vec<AnyElement> = shown
455 .iter()
456 .map(|tile| person_tile(app, state, model, tile, size, now))
457 .collect();
458 if own_cells > 0 {
459 tiles.insert(
460 own_slot(model, shown),
461 own_tile(app, state, model, size, now),
462 );
463 }
464 if plan.overflow.hidden > 0 {
465 tiles.push(overflow_tile(
466 app,
467 state,
468 size,
469 &others[plan.overflow.shown..],
470 ));
471 }
472 v_flex()
473 .absolute()
474 .inset_0()
475 .p(px(GRID_PADDING))
476 .gap(px(TILE_GAP))
477 .child(
478 h_flex()
479 .flex_1()
480 .min_h_0()
481 .w_full()
482 .items_center()
483 .justify_center()
484 .children(main),
485 )
486 .when(!tiles.is_empty(), |column| {
487 column.child(
488 h_flex()
489 .id("call-filmstrip")
490 .flex_none()
491 .w_full()
492 .gap(px(TILE_GAP))
493 .justify_center()
494 .children(tiles),
495 )
496 })
497 .into_any_element()
498}
499
500struct StripSplit<'a> {
501 width: f32,
502 others: Vec<&'a Tile>,
503 plan: Filmstrip,
504}
505
506fn strip_split(model: &CallModel, strip_width: f32, stage: (f32, f32)) -> StripSplit<'_> {
507 let available = (stage.0 - 2. * GRID_PADDING, (stage.1 - 2. * GRID_PADDING).max(0.));
508 let width = strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));
509 let others: Vec<&Tile> = model
510 .strip_tiles()
511 .into_iter()
512 .filter(|tile| !model.hidden_for_no_video(tile))
513 .collect();
514 let plan = share_strip(others.len(), model.own_cells(), (width, available.1), STRIP_GAP);
515 StripSplit { width, others, plan }
516}
517
518fn people_strip(
519 app: &Entity<AppState>,
520 state: &AppState,
521 model: &CallModel,
522 now: Instant,
523 stage: (f32, f32),
524) -> Stateful<Div> {
525 let StripSplit { width, others, plan } = strip_split(model, state.call_strip_width, stage);
526 let size = TileSize::sixteen_by_nine(plan.tile_width);
527 let shown = &others[..plan.overflow.shown];
528 let mut cells: Vec<AnyElement> = shown
529 .iter()
530 .map(|remote| person_tile(app, state, model, remote, size, now))
531 .collect();
532 if model.own_cells() > 0 {
533 let own_index = model.own_cell_index(cells.len());
534 cells.insert(own_index, own_tile(app, state, model, size, now));
535 }
536 if plan.overflow.hidden > 0 {
537 cells.push(overflow_tile(app, state, size, &others[plan.overflow.shown..]));
538 }
539 v_flex()
540 .id("call-strip")
541 .debug_selector(|| "shell/islands/main/call-stage/share-strip".into())
542 .flex_none()
543 .w(px(width))
544 .items_center()
545 .gap(px(STRIP_GAP))
546 .children(cells)
547}
548
549fn strip_divider(app: &Entity<AppState>, dragging: bool) -> Stateful<Div> {
550 let app = app.clone();
551 h_flex()
552 .id("call-strip-divider")
553 .debug_selector(|| "shell/islands/main/call-stage/share-divider".into())
554 .flex_none()
555 .w(px(TILE_GAP))
556 .h_full()
557 .items_center()
558 .justify_center()
559 .cursor_col_resize()
560 .child(
561 div()
562 .w(px(DIVIDER_LINE))
563 .h(px(DIVIDER_LENGTH))
564 .rounded_full()
565 .bg(if dragging { theme::accent() } else { theme::border() }),
566 )
567 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
568 let pointer_x = f32::from(event.position.x);
569 app.update(cx, |state, cx| state.begin_strip_drag(pointer_x, cx));
570 })
571}
572
573fn share_body(
574 app: &Entity<AppState>,
575 state: &AppState,
576 model: &CallModel,
577 now: Instant,
578 share: AnyElement,
579 layout: CallLayout,
580 stage: (f32, f32),
581) -> AnyElement {
582 let move_app = app.clone();
583 let up_app = app.clone();
584 let up_out_app = app.clone();
585 let dragging = state.call.as_ref().is_some_and(|call| call.share_stage.strip_drag.is_some());
586 h_flex()
587 .id("call-share-body")
588 .absolute()
589 .inset_0()
590 .p(px(GRID_PADDING))
591 .items_center()
592 .on_mouse_move(move |event, _, cx| {
593 let pointer_x = f32::from(event.position.x);
594 move_app.update(cx, |state, cx| state.drag_strip_to(pointer_x, cx));
595 })
596 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
597 up_app.update(cx, |state, cx| state.end_strip_drag(cx));
598 })
599 .on_mouse_up_out(MouseButton::Left, move |_, _, cx| {
600 up_out_app.update(cx, |state, cx| state.end_strip_drag(cx));
601 })
602 .child(share)
603 .when(layout != CallLayout::Content, |row| {
604 row.child(strip_divider(app, dragging)).child(people_strip(app, state, model, now, stage))
605 })
606 .into_any_element()
607}
608
609const LARGE_GALLERY_TILES: usize = 4;
610
611fn want(tile: &Tile, detail: TileDetail) -> VideoWant {
612 VideoWant { mri: tile.mri.clone(), detail }
613}
614
615pub fn video_wants(model: &CallModel, stage: (f32, f32), strip_width: f32) -> Vec<VideoWant> {
616 if model.has_content() {
617 if model.effective_layout() == CallLayout::Content {
618 return Vec::new();
619 }
620 let split = strip_split(model, strip_width, stage);
621 return split.others[..split.plan.overflow.shown]
622 .iter()
623 .map(|tile| want(tile, TileDetail::Small))
624 .collect();
625 }
626 if model.effective_layout() == CallLayout::Speaker {
627 let split = speaker_split(model, stage);
628 let stage_person = split.focus.iter().filter(|focus| !focus.own).map(|focus| VideoWant {
629 mri: focus.mri.clone(),
630 detail: TileDetail::Stage,
631 });
632 return stage_person
633 .chain(split.others[..split.plan.overflow.shown].iter().map(|tile| want(tile, TileDetail::Small)))
634 .collect();
635 }
636 let (others, overflow) = gallery_split(model);
637 let detail = if overflow.shown <= LARGE_GALLERY_TILES { TileDetail::Stage } else { TileDetail::Small };
638 others[..overflow.shown].iter().map(|tile| want(tile, detail)).collect()
639}
640
641pub(super) fn stage_region(
642 app: &Entity<AppState>,
643 state: &AppState,
644 call: &ActiveCall,
645 now: Instant,
646 hold: Option<AnyElement>,
647 share_stage: Option<AnyElement>,
648) -> AnyElement {
649 let model = &call.model;
650 let layout = model.effective_layout();
651 let stage = measured_stage(call);
652 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
653 let body = match (hold, share_stage) {
654 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
655 (None, Some(share)) => share_body(app, state, model, now, share, layout, stage),
656 (None, None) if layout == CallLayout::Speaker => {
657 speaker_body(app, state, model, now, stage)
658 }
659 (None, None) => gallery_body(app, state, model, now, stage),
660 };
661 div()
662 .relative()
663 .debug_selector(|| "shell/islands/main/call-stage".into())
664 .flex_1()
665 .min_h_0()
666 .w_full()
667 .child(measure_stage(call))
668 .child(body)
669 .children(
670 without_video_chip(app, model)
671 .filter(|_| shows_people)
672 .into_iter()
673 .chain(show_me_pill(app, model, OVERLAY_INSET).filter(|_| shows_people))
674 .chain(chat_bubbles(app, state, call, now, OVERLAY_INSET))
675 .chain(fullscreen_hint(call, now, OVERLAY_INSET)),
676 )
677 .into_any_element()
678}
679
680#[cfg(test)]
681mod tests {
682 use std::time::Instant;
683
684 use calling::{CallUpdate, RosterEntry, TileDetail, VideoWant};
685
686 use super::{
687 CallLayout, CallModel, FILMSTRIP_TILE_MAX, GALLERY_MAX, GRID_PADDING, TILE_GAP, filmstrip, split_overflow,
688 video_wants,
689 };
690 use crate::call::STRIP_DEFAULT_WIDTH;
691
692 const STAGE: (f32, f32) = (1400., 800.);
693
694 fn person(index: usize, has_video: bool) -> RosterEntry {
695 RosterEntry {
696 mri: format!("8:orgid:p{index}"),
697 display_name: format!("P{index}"),
698 muted: false,
699 in_lobby: false,
700 has_video,
701 sharing: false,
702 hand: None,
703 spotlight: None,
704 organizer: false,
705 role: None,
706 limits: Default::default(),
707 }
708 }
709
710 fn meeting(people: Vec<RosterEntry>) -> CallModel {
711 let mut model = CallModel::meeting("Standup", false);
712 model.apply(CallUpdate::OwnIdentity { mri: "8:orgid:me".into() });
713 model.apply(CallUpdate::Roster(people));
714 model
715 }
716
717 fn crowd(count: usize) -> CallModel {
718 meeting((0..count).map(|index| person(index, true)).collect())
719 }
720
721 fn details(wants: &[VideoWant]) -> Vec<TileDetail> {
722 wants.iter().map(|want| want.detail).collect()
723 }
724
725 #[test]
726 fn a_small_gallery_asks_for_large_pictures() {
727 let wants = video_wants(&crowd(3), STAGE, STRIP_DEFAULT_WIDTH);
728 assert_eq!(wants.len(), 3);
729 assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Stage));
730 }
731
732 #[test]
733 fn a_big_gallery_asks_for_small_pictures_and_skips_the_plus_n_people() {
734 let model = crowd(14);
735 let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
736 assert_eq!(wants.len(), split_overflow(14, 1, GALLERY_MAX).shown);
737 assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
738 let hidden: Vec<&str> = model.layout_tiles()[wants.len()..].iter().map(|tile| tile.mri.as_str()).collect();
739 assert!(wants.iter().all(|want| !hidden.contains(&want.mri.as_str())));
740 }
741
742 #[test]
743 fn people_hidden_for_having_no_video_get_no_picture_request() {
744 let mut model = meeting(vec![person(0, true), person(1, false), person(2, false)]);
745 model.view.hide_no_video = true;
746 let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
747 assert_eq!(wants.iter().map(|want| want.mri.as_str()).collect::<Vec<_>>(), vec!["8:orgid:p0"]);
748 }
749
750 #[test]
751 fn the_speaker_stage_is_large_and_the_filmstrip_small() {
752 let mut model = crowd(5);
753 model.view.choose(CallLayout::Speaker);
754 model.refresh_layout(Instant::now());
755 let focus = model.speaker_focus().expect("a stage person").mri;
756 let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
757 assert_eq!(wants[0], VideoWant { mri: focus.clone(), detail: TileDetail::Stage });
758 assert_eq!(wants.len(), 5);
759 assert!(wants[1..].iter().all(|want| want.detail == TileDetail::Small && want.mri != focus));
760 }
761
762 #[test]
763 fn the_speaker_filmstrip_drops_people_that_do_not_fit() {
764 let mut model = crowd(12);
765 model.view.choose(CallLayout::Speaker);
766 model.refresh_layout(Instant::now());
767 let wants = video_wants(&model, (500., 800.), STRIP_DEFAULT_WIDTH);
768 let fitting = filmstrip(11, 1, 500. - 2. * GRID_PADDING, TILE_GAP, FILMSTRIP_TILE_MAX).overflow.shown;
769 assert!(fitting < 11);
770 assert_eq!(wants.len(), 1 + fitting);
771 }
772
773 #[test]
774 fn next_to_shared_content_everybody_in_the_strip_is_small_and_content_focus_wants_nobody() {
775 let mut model = crowd(3);
776 model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
777 let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
778 assert_eq!(wants.len(), 3);
779 assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
780 model.view.choose(CallLayout::Content);
781 assert!(video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH).is_empty());
782 }
783
784 #[test]
785 fn a_full_share_strip_wants_video_for_every_shown_tile_and_none_behind_the_plus_tile() {
786 let mut model = crowd(9);
787 model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
788 assert_eq!(video_wants(&model, (1400., 1100.), STRIP_DEFAULT_WIDTH).len(), 9);
789 let short = video_wants(&model, (1400., 600.), STRIP_DEFAULT_WIDTH);
790 assert!(short.len() >= 3 && short.len() < 9, "{} wants", short.len());
791 }
792}