feat(calls): view menu with gallery, speaker and focus layouts, full screen, chat bubbles
- View button with Layout (Gallery, Speaker, Focus on content), Hide people without video, Hide me, Chat bubbles, Full screen - Gallery up to 3x3 of 16:9 tiles, "+N" tile with a pin list; swap rule (2 s speech, one per 5 s) as a pure function in call/stage_layout.rs - Speaker view with filmstrip, Focus on content falls back when the share ends - Hide me pill, "Hide for me" in the own tile menu, "N without video" chip - Full screen over the whole window, controls hide after 3 s, Esc or F11 exits - Chat bubbles for new meeting chat messages while the panel is closed - Shortcuts Ctrl+Shift+K, E (share menu), Y (lobby), Alt+Shift+A and V, F11 - Demo scene TEAMS_DEMO_CALL=gallery with 12 guests - DropdownMenuPopover::open in vendor/gpui-component so a shortcut can open a menu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -2,7 +2,7 @@
2
2
3
3
Feature parity with the Microsoft Teams desktop client.
4
4
5
**Parity: 89 %** (81 done, 14 partial, 4 missing of 99). Partial counts half.
5
**Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.
6
6
7
7
## By area
8
8
@@ -18,7 +18,7 @@ Feature parity with the Microsoft Teams desktop client.
18
18
| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
19
19
| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
20
20
| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
21
| [Calls and meetings](#calls-and-meetings) | 62 % | 4 | 13 | 0 |
21
| [Calls and meetings](#calls-and-meetings) | 61 % | 4 | 14 | 0 |
22
22
23
23
## Next
24
24
@@ -138,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.
138
138
| Full-text search over cached messages | Done | |
139
139
| Jump to a message from search | Done | |
140
140
| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
141
| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
141
| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share menu, K raise hand, Y lobby, M mute, F11 full screen, Alt+Shift+A / V start an audio / video call in the open chat; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
142
142
143
143
## Presence and people
144
144
@@ -175,6 +175,7 @@ Feature parity with the Microsoft Teams desktop client.
175
175
| Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |
176
176
| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
177
177
| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
178
| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
178
179
| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
179
180
| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
180
181
| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
@@ -2,7 +2,7 @@2
2
3
Feature parity with the Microsoft Teams desktop client.3
Feature parity with the Microsoft Teams desktop client.4
4
5
**Parity: 89 %** (81 done, 14 partial, 4 missing of 99). Partial counts half.5
**Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.6
6
7
## By area7
## By area8
8
@@ -18,7 +18,7 @@ Feature parity with the Microsoft Teams desktop client.18
| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |18
| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |19
| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |19
| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |20
| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |20
| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |21
| [Calls and meetings](#calls-and-meetings) | 62 % | 4 | 13 | 0 |21
| [Calls and meetings](#calls-and-meetings) | 61 % | 4 | 14 | 0 |22
22
23
## Next23
## Next24
24
@@ -138,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.138
| Full-text search over cached messages | Done | |138
| Full-text search over cached messages | Done | |139
| Jump to a message from search | Done | |139
| Jump to a message from search | Done | |140
| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |140
| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |141
| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |141
| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share menu, K raise hand, Y lobby, M mute, F11 full screen, Alt+Shift+A / V start an audio / video call in the open chat; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |142
142
143
## Presence and people143
## Presence and people144
144
@@ -175,6 +175,7 @@ Feature parity with the Microsoft Teams desktop client.175
| Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |175
| Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |176
| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |176
| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |177
| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |177
| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |178
| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |178
| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |179
| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |179
| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |180
| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |180
| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |181
| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |@@ -124,6 +124,7 @@ pub struct AppState {
124
124
pub call_launcher: Option<Arc<CallLauncher>>,
125
125
pub call_count: u64,
126
126
pub call_share_sound: bool,
127
pub call_view: crate::call::ViewSettings,
127
128
pub call_background: crate::call::BackgroundPick,
128
129
pub call_camera: calling::DeviceChoice,
129
130
pub meet_now_pending: bool,
@@ -221,6 +222,7 @@ impl AppState {
221
222
call_launcher: None,
222
223
call_count: 0,
223
224
call_share_sound: false,
225
call_view: crate::call::ViewSettings::default(),
224
226
call_background: crate::call::BackgroundPick::None,
225
227
call_camera: calling::DeviceChoice::SystemDefault,
226
228
meet_now_pending: false,
@@ -239,6 +241,7 @@ impl AppState {
239
241
state.local_previews = load_local_previews(&state.store);
240
242
state.collapsed = state.load_collapsed();
241
243
state.call_share_sound = crate::call::load_share_sound(&state.store);
244
state.call_view = crate::call::ViewSettings::load(&state.store);
242
245
state.call_background = crate::call::load_background(&state.store);
243
246
state.call_camera = crate::call::load_camera(&state.store);
244
247
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
@@ -124,6 +124,7 @@ pub struct AppState {124
pub call_launcher: Option<Arc<CallLauncher>>,124
pub call_launcher: Option<Arc<CallLauncher>>,125
pub call_count: u64,125
pub call_count: u64,126
pub call_share_sound: bool,126
pub call_share_sound: bool,127
pub call_view: crate::call::ViewSettings,127
pub call_background: crate::call::BackgroundPick,128
pub call_background: crate::call::BackgroundPick,128
pub call_camera: calling::DeviceChoice,129
pub call_camera: calling::DeviceChoice,129
pub meet_now_pending: bool,130
pub meet_now_pending: bool,@@ -221,6 +222,7 @@ impl AppState {221
call_launcher: None,222
call_launcher: None,222
call_count: 0,223
call_count: 0,223
call_share_sound: false,224
call_share_sound: false,225
call_view: crate::call::ViewSettings::default(),224
call_background: crate::call::BackgroundPick::None,226
call_background: crate::call::BackgroundPick::None,225
call_camera: calling::DeviceChoice::SystemDefault,227
call_camera: calling::DeviceChoice::SystemDefault,226
meet_now_pending: false,228
meet_now_pending: false,@@ -239,6 +241,7 @@ impl AppState {239
state.local_previews = load_local_previews(&state.store);241
state.local_previews = load_local_previews(&state.store);240
state.collapsed = state.load_collapsed();242
state.collapsed = state.load_collapsed();241
state.call_share_sound = crate::call::load_share_sound(&state.store);243
state.call_share_sound = crate::call::load_share_sound(&state.store);244
state.call_view = crate::call::ViewSettings::load(&state.store);242
state.call_background = crate::call::load_background(&state.store);245
state.call_background = crate::call::load_background(&state.store);243
state.call_camera = crate::call::load_camera(&state.store);246
state.call_camera = crate::call::load_camera(&state.store);244
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);247
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);@@ -218,6 +218,8 @@ impl AppState {
218
218
if let Some(call) = self.call.as_mut() {
219
219
call.model.background = self.call_background.clone();
220
220
call.model.camera = self.call_camera.clone();
221
call.model.view = self.call_view;
222
call.model.refresh_layout(Instant::now());
221
223
}
222
224
if self.call_camera != DeviceChoice::SystemDefault {
223
225
self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
@@ -260,6 +262,7 @@ impl AppState {
260
262
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {
261
263
state.refresh_share_sources();
262
264
}
265
state.tick_call_layout(cx);
263
266
CallMedia::changed(&state.call_media, cx);
264
267
}
265
268
running
@@ -411,22 +414,6 @@ impl AppState {
411
414
self.send_call_command(CallCommand::StartShare(source));
412
415
}
413
416
414
pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
415
let Some(call) = self.call.as_ref() else {
416
return;
417
};
418
if call.model.local_share.is_some() {
419
self.stop_call_share(cx);
420
return;
421
}
422
if !call.model.can_share() {
423
return;
424
}
425
if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {
426
self.start_call_share(source, cx);
427
}
428
}
429
430
417
pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
431
418
self.send_call_command(CallCommand::StopShare);
432
419
}
@@ -857,7 +844,7 @@ impl AppState {
857
844
)
858
845
} else {
859
846
let script = DemoCall::Meeting {
860
guests: demo_guests(DEMO_SMALL_MEETING),
847
guests: demo_guests(scene.guests().unwrap_or(DEMO_SMALL_MEETING)),
861
848
lobby: false,
862
849
organizer: true,
863
850
};
@@ -877,6 +864,9 @@ impl AppState {
877
864
meeting_data: None,
878
865
});
879
866
}
867
if scene == DemoScene::Gallery {
868
self.queue_demo_bubbles(conversation_id, cx);
869
}
880
870
}
881
871
882
872
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {
@@ -218,6 +218,8 @@ impl AppState {218
if let Some(call) = self.call.as_mut() {218
if let Some(call) = self.call.as_mut() {219
call.model.background = self.call_background.clone();219
call.model.background = self.call_background.clone();220
call.model.camera = self.call_camera.clone();220
call.model.camera = self.call_camera.clone();221
call.model.view = self.call_view;222
call.model.refresh_layout(Instant::now());221
}223
}222
if self.call_camera != DeviceChoice::SystemDefault {224
if self.call_camera != DeviceChoice::SystemDefault {223
self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));225
self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));@@ -260,6 +262,7 @@ impl AppState {260
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {262
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {261
state.refresh_share_sources();263
state.refresh_share_sources();262
}264
}265
state.tick_call_layout(cx);263
CallMedia::changed(&state.call_media, cx);266
CallMedia::changed(&state.call_media, cx);264
}267
}265
running268
running@@ -411,22 +414,6 @@ impl AppState {411
self.send_call_command(CallCommand::StartShare(source));414
self.send_call_command(CallCommand::StartShare(source));412
}415
}413
416
414
pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {415
let Some(call) = self.call.as_ref() else {416
return;417
};418
if call.model.local_share.is_some() {419
self.stop_call_share(cx);420
return;421
}422
if !call.model.can_share() {423
return;424
}425
if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {426
self.start_call_share(source, cx);427
}428
}429
430
pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {417
pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {431
self.send_call_command(CallCommand::StopShare);418
self.send_call_command(CallCommand::StopShare);432
}419
}@@ -857,7 +844,7 @@ impl AppState {857
)844
)858
} else {845
} else {859
let script = DemoCall::Meeting {846
let script = DemoCall::Meeting {860
guests: demo_guests(DEMO_SMALL_MEETING),847
guests: demo_guests(scene.guests().unwrap_or(DEMO_SMALL_MEETING)),861
lobby: false,848
lobby: false,862
organizer: true,849
organizer: true,863
};850
};@@ -877,6 +864,9 @@ impl AppState {877
meeting_data: None,864
meeting_data: None,878
});865
});879
}866
}867
if scene == DemoScene::Gallery {868
self.queue_demo_bubbles(conversation_id, cx);869
}880
}870
}881
871
882
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {872
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {@@ -0,0 +1,75 @@
1
use std::time::{Duration, Instant};
2
3
pub const BUBBLE_SHOWN: Duration = Duration::from_secs(5);
4
pub const BUBBLE_MAX: usize = 3;
5
6
#[derive(Debug, Clone, PartialEq, Eq)]
7
pub struct ChatBubble {
8
pub id: String,
9
pub sender_id: Option<String>,
10
pub name: String,
11
pub text: String,
12
pub at: Instant,
13
}
14
15
pub fn push_bubble(bubbles: &mut Vec<ChatBubble>, bubble: ChatBubble) {
16
if bubbles.iter().any(|shown| shown.id == bubble.id) {
17
return;
18
}
19
bubbles.push(bubble);
20
let surplus = bubbles.len().saturating_sub(BUBBLE_MAX);
21
bubbles.drain(..surplus);
22
}
23
24
pub fn shown_bubbles(bubbles: &[ChatBubble], now: Instant) -> Vec<&ChatBubble> {
25
bubbles
26
.iter()
27
.filter(|bubble| now.saturating_duration_since(bubble.at) < BUBBLE_SHOWN)
28
.collect()
29
}
30
31
#[cfg(test)]
32
mod tests {
33
use super::*;
34
35
fn bubble(id: &str, at: Instant) -> ChatBubble {
36
ChatBubble {
37
id: id.to_owned(),
38
sender_id: None,
39
name: "Ana".to_owned(),
40
text: "hello".to_owned(),
41
at,
42
}
43
}
44
45
#[test]
46
fn only_the_newest_three_stay() {
47
let now = Instant::now();
48
let mut bubbles = Vec::new();
49
for id in ["a", "b", "c", "d"] {
50
push_bubble(&mut bubbles, bubble(id, now));
51
}
52
let ids: Vec<&str> = bubbles.iter().map(|shown| shown.id.as_str()).collect();
53
assert_eq!(ids, ["b", "c", "d"]);
54
}
55
56
#[test]
57
fn a_message_never_shows_twice() {
58
let now = Instant::now();
59
let mut bubbles = Vec::new();
60
push_bubble(&mut bubbles, bubble("a", now));
61
push_bubble(&mut bubbles, bubble("a", now));
62
assert_eq!(bubbles.len(), 1);
63
}
64
65
#[test]
66
fn bubbles_vanish_after_five_seconds() {
67
let now = Instant::now();
68
let bubbles = vec![bubble("a", now)];
69
assert_eq!(
70
shown_bubbles(&bubbles, now + Duration::from_secs(4)).len(),
71
1
72
);
73
assert!(shown_bubbles(&bubbles, now + BUBBLE_SHOWN).is_empty());
74
}
75
}
@@ -0,0 +1,75 @@1
use std::time::{Duration, Instant};2
3
pub const BUBBLE_SHOWN: Duration = Duration::from_secs(5);4
pub const BUBBLE_MAX: usize = 3;5
6
#[derive(Debug, Clone, PartialEq, Eq)]7
pub struct ChatBubble {8
pub id: String,9
pub sender_id: Option<String>,10
pub name: String,11
pub text: String,12
pub at: Instant,13
}14
15
pub fn push_bubble(bubbles: &mut Vec<ChatBubble>, bubble: ChatBubble) {16
if bubbles.iter().any(|shown| shown.id == bubble.id) {17
return;18
}19
bubbles.push(bubble);20
let surplus = bubbles.len().saturating_sub(BUBBLE_MAX);21
bubbles.drain(..surplus);22
}23
24
pub fn shown_bubbles(bubbles: &[ChatBubble], now: Instant) -> Vec<&ChatBubble> {25
bubbles26
.iter()27
.filter(|bubble| now.saturating_duration_since(bubble.at) < BUBBLE_SHOWN)28
.collect()29
}30
31
#[cfg(test)]32
mod tests {33
use super::*;34
35
fn bubble(id: &str, at: Instant) -> ChatBubble {36
ChatBubble {37
id: id.to_owned(),38
sender_id: None,39
name: "Ana".to_owned(),40
text: "hello".to_owned(),41
at,42
}43
}44
45
#[test]46
fn only_the_newest_three_stay() {47
let now = Instant::now();48
let mut bubbles = Vec::new();49
for id in ["a", "b", "c", "d"] {50
push_bubble(&mut bubbles, bubble(id, now));51
}52
let ids: Vec<&str> = bubbles.iter().map(|shown| shown.id.as_str()).collect();53
assert_eq!(ids, ["b", "c", "d"]);54
}55
56
#[test]57
fn a_message_never_shows_twice() {58
let now = Instant::now();59
let mut bubbles = Vec::new();60
push_bubble(&mut bubbles, bubble("a", now));61
push_bubble(&mut bubbles, bubble("a", now));62
assert_eq!(bubbles.len(), 1);63
}64
65
#[test]66
fn bubbles_vanish_after_five_seconds() {67
let now = Instant::now();68
let bubbles = vec![bubble("a", now)];69
assert_eq!(70
shown_bubbles(&bubbles, now + Duration::from_secs(4)).len(),71
172
);73
assert!(shown_bubbles(&bubbles, now + BUBBLE_SHOWN).is_empty());74
}75
}@@ -28,6 +28,8 @@ const SPEAKING_LEVEL: f32 = 0.3;
28
28
const SPEAKER_TICKS: u32 = 10;
29
29
const VIDEO_PERIOD: Duration = Duration::from_millis(125);
30
30
const DEMO_CAMERAS: usize = 4;
31
const GALLERY_CAMERAS: usize = 7;
32
const GALLERY_SPEAKER_TICKS: u32 = 15;
31
33
const SCREEN_EVERY_TICKS: u32 = 4;
32
34
const SHARE_START: Duration = Duration::from_secs(10);
33
35
const SHARE_END: Duration = Duration::from_secs(45);
@@ -59,7 +61,7 @@ const SELF_PHASE: u32 = 211;
59
61
pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";
60
62
pub const DEMO_RING_ID: u64 = 9001;
61
63
const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");
62
const DEMO_GUESTS: [&str; 11] = [
64
const DEMO_GUESTS: [&str; 12] = [
63
65
"Mara Lindqvist",
64
66
"Jonas Ortega",
65
67
"Priya Nair",
@@ -71,6 +73,7 @@ const DEMO_GUESTS: [&str; 11] = [
71
73
"Yuki Tanaka",
72
74
"Carlos Mendez",
73
75
"Sofia Rossi",
76
"Emil Nowak",
74
77
];
75
78
76
79
pub type Person = (String, String);
@@ -86,6 +89,7 @@ pub enum DemoScene {
86
89
Held,
87
90
Breakout,
88
91
Whiteboard,
92
Gallery,
89
93
}
90
94
91
95
impl DemoScene {
@@ -98,6 +102,7 @@ impl DemoScene {
98
102
"held" => DemoScene::Held,
99
103
"breakout" => DemoScene::Breakout,
100
104
"whiteboard" => DemoScene::Whiteboard,
105
"gallery" => DemoScene::Gallery,
101
106
_ => return None,
102
107
})
103
108
}
@@ -105,8 +110,27 @@ impl DemoScene {
105
110
pub fn is_one_to_one(self) -> bool {
106
111
matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held)
107
112
}
113
114
pub fn guests(self) -> Option<usize> {
115
(self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)
116
}
117
118
fn cameras(self) -> usize {
119
match self {
120
DemoScene::Gallery => GALLERY_CAMERAS,
121
_ => DEMO_CAMERAS,
122
}
123
}
124
125
fn speaker_ticks(self) -> u32 {
126
match self {
127
DemoScene::Gallery => GALLERY_SPEAKER_TICKS,
128
_ => SPEAKER_TICKS,
129
}
130
}
108
131
}
109
132
133
pub const DEMO_GALLERY_GUESTS: usize = 12;
110
134
const BREAKOUT_AT_TICKS: u32 = 20;
111
135
const WHITEBOARD_AT_TICKS: u32 = 5;
112
136
const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -215,7 +239,7 @@ pub fn start_demo_scene_call(script: DemoCall, scene: DemoScene) -> CallHandle {
215
239
handle
216
240
}
217
241
218
fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
242
fn roster_of(people: &[Person], cameras: usize) -> Vec<RosterEntry> {
219
243
people
220
244
.iter()
221
245
.enumerate()
@@ -224,7 +248,7 @@ fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
224
248
display_name: name.clone(),
225
249
muted: index % 3 == 1,
226
250
in_lobby: false,
227
has_video: index < DEMO_CAMERAS,
251
has_video: index < cameras,
228
252
sharing: false,
229
253
hand: None,
230
254
spotlight: None,
@@ -268,7 +292,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
268
292
}
269
293
control.send(CallUpdate::Lobby(false));
270
294
}
271
let mut roster = roster_of(&people);
295
let mut roster = roster_of(&people, scene.cameras());
272
296
if matches!(script, DemoCall::People(_)) {
273
297
control.send(CallUpdate::ReplacementLink(
274
298
DEMO_REPLACEMENT_LINK.to_owned(),
@@ -300,7 +324,8 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
300
324
let video = !matches!(script, DemoCall::Test);
301
325
let sharer = matches!(script, DemoCall::Meeting { .. })
302
326
.then(|| people.get(1).map(|person| person.0.clone()))
303
.flatten();
327
.flatten()
328
.filter(|_| scene != DemoScene::Gallery);
304
329
start_scene(&control, scene);
305
330
speak_until_hangup(control, people, roster, video, sharer, scene).await;
306
331
}
@@ -332,6 +357,7 @@ fn publish_demo_video(
332
357
sharing: bool,
333
358
sharer: Option<&str>,
334
359
camera: Option<bool>,
360
cameras: usize,
335
361
) {
336
362
if let Some(blur) = camera {
337
363
control.video.publish(
@@ -339,7 +365,7 @@ fn publish_demo_video(
339
365
self_view((tick + SELF_PHASE) as usize, blur),
340
366
);
341
367
}
342
for (index, (mri, _)) in people.iter().take(DEMO_CAMERAS).enumerate() {
368
for (index, (mri, _)) in people.iter().take(cameras).enumerate() {
343
369
let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);
344
370
control
345
371
.video
@@ -362,7 +388,11 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
362
388
}
363
389
DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
364
390
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
365
DemoScene::Call | DemoScene::Breakout | DemoScene::Whiteboard | DemoScene::Plain => {}
391
DemoScene::Call
392
| DemoScene::Breakout
393
| DemoScene::Whiteboard
394
| DemoScene::Gallery
395
| DemoScene::Plain => {}
366
396
}
367
397
}
368
398
@@ -424,7 +454,7 @@ async fn speak_until_hangup(
424
454
sharing = share_now;
425
455
control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
426
456
}
427
publish_demo_video(&control, &people, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur));
457
publish_demo_video(&control, &people, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur), scene.cameras());
428
458
video_ticks += 1;
429
459
}
430
460
_ = tick.tick() => {
@@ -434,8 +464,8 @@ async fn speak_until_hangup(
434
464
local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },
435
465
remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },
436
466
});
437
if people.len() > 1 && ticks.is_multiple_of(SPEAKER_TICKS) {
438
let speaker = &people[(ticks / SPEAKER_TICKS) as usize % people.len()];
467
if people.len() > 1 && ticks.is_multiple_of(scene.speaker_ticks()) {
468
let speaker = &people[(ticks / scene.speaker_ticks()) as usize % people.len()];
439
469
control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));
440
470
}
441
471
if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2
@@ -649,17 +679,17 @@ mod tests {
649
679
650
680
#[test]
651
681
fn demo_guests_have_distinct_mris_and_names() {
652
let guests = demo_guests(11);
653
assert_eq!(guests.len(), 11);
682
let guests = demo_guests(12);
683
assert_eq!(guests.len(), 12);
654
684
let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();
655
685
mris.sort();
656
686
mris.dedup();
657
assert_eq!(mris.len(), 11);
687
assert_eq!(mris.len(), 12);
658
688
}
659
689
660
690
#[test]
661
691
fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {
662
let mut roster = roster_of(&demo_guests(3));
692
let mut roster = roster_of(&demo_guests(3), DEMO_CAMERAS);
663
693
set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);
664
694
set_demo_hand(&mut roster, DEMO_OWN_MRI, true);
665
695
let ranks: Vec<u64> = roster
@@ -28,6 +28,8 @@ const SPEAKING_LEVEL: f32 = 0.3;28
const SPEAKER_TICKS: u32 = 10;28
const SPEAKER_TICKS: u32 = 10;29
const VIDEO_PERIOD: Duration = Duration::from_millis(125);29
const VIDEO_PERIOD: Duration = Duration::from_millis(125);30
const DEMO_CAMERAS: usize = 4;30
const DEMO_CAMERAS: usize = 4;31
const GALLERY_CAMERAS: usize = 7;32
const GALLERY_SPEAKER_TICKS: u32 = 15;31
const SCREEN_EVERY_TICKS: u32 = 4;33
const SCREEN_EVERY_TICKS: u32 = 4;32
const SHARE_START: Duration = Duration::from_secs(10);34
const SHARE_START: Duration = Duration::from_secs(10);33
const SHARE_END: Duration = Duration::from_secs(45);35
const SHARE_END: Duration = Duration::from_secs(45);@@ -59,7 +61,7 @@ const SELF_PHASE: u32 = 211;59
pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";61
pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";60
pub const DEMO_RING_ID: u64 = 9001;62
pub const DEMO_RING_ID: u64 = 9001;61
const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");63
const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");62
const DEMO_GUESTS: [&str; 11] = [64
const DEMO_GUESTS: [&str; 12] = [63
"Mara Lindqvist",65
"Mara Lindqvist",64
"Jonas Ortega",66
"Jonas Ortega",65
"Priya Nair",67
"Priya Nair",@@ -71,6 +73,7 @@ const DEMO_GUESTS: [&str; 11] = [71
"Yuki Tanaka",73
"Yuki Tanaka",72
"Carlos Mendez",74
"Carlos Mendez",73
"Sofia Rossi",75
"Sofia Rossi",76
"Emil Nowak",74
];77
];75
78
76
pub type Person = (String, String);79
pub type Person = (String, String);@@ -86,6 +89,7 @@ pub enum DemoScene {86
Held,89
Held,87
Breakout,90
Breakout,88
Whiteboard,91
Whiteboard,92
Gallery,89
}93
}90
94
91
impl DemoScene {95
impl DemoScene {@@ -98,6 +102,7 @@ impl DemoScene {98
"held" => DemoScene::Held,102
"held" => DemoScene::Held,99
"breakout" => DemoScene::Breakout,103
"breakout" => DemoScene::Breakout,100
"whiteboard" => DemoScene::Whiteboard,104
"whiteboard" => DemoScene::Whiteboard,105
"gallery" => DemoScene::Gallery,101
_ => return None,106
_ => return None,102
})107
})103
}108
}@@ -105,8 +110,27 @@ impl DemoScene {105
pub fn is_one_to_one(self) -> bool {110
pub fn is_one_to_one(self) -> bool {106
matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held)111
matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held)107
}112
}113
114
pub fn guests(self) -> Option<usize> {115
(self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)116
}117
118
fn cameras(self) -> usize {119
match self {120
DemoScene::Gallery => GALLERY_CAMERAS,121
_ => DEMO_CAMERAS,122
}123
}124
125
fn speaker_ticks(self) -> u32 {126
match self {127
DemoScene::Gallery => GALLERY_SPEAKER_TICKS,128
_ => SPEAKER_TICKS,129
}130
}108
}131
}109
132
133
pub const DEMO_GALLERY_GUESTS: usize = 12;110
const BREAKOUT_AT_TICKS: u32 = 20;134
const BREAKOUT_AT_TICKS: u32 = 20;111
const WHITEBOARD_AT_TICKS: u32 = 5;135
const WHITEBOARD_AT_TICKS: u32 = 5;112
const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";136
const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";@@ -215,7 +239,7 @@ pub fn start_demo_scene_call(script: DemoCall, scene: DemoScene) -> CallHandle {215
handle239
handle216
}240
}217
241
218
fn roster_of(people: &[Person]) -> Vec<RosterEntry> {242
fn roster_of(people: &[Person], cameras: usize) -> Vec<RosterEntry> {219
people243
people220
.iter()244
.iter()221
.enumerate()245
.enumerate()@@ -224,7 +248,7 @@ fn roster_of(people: &[Person]) -> Vec<RosterEntry> {224
display_name: name.clone(),248
display_name: name.clone(),225
muted: index % 3 == 1,249
muted: index % 3 == 1,226
in_lobby: false,250
in_lobby: false,227
has_video: index < DEMO_CAMERAS,251
has_video: index < cameras,228
sharing: false,252
sharing: false,229
hand: None,253
hand: None,230
spotlight: None,254
spotlight: None,@@ -268,7 +292,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc268
}292
}269
control.send(CallUpdate::Lobby(false));293
control.send(CallUpdate::Lobby(false));270
}294
}271
let mut roster = roster_of(&people);295
let mut roster = roster_of(&people, scene.cameras());272
if matches!(script, DemoCall::People(_)) {296
if matches!(script, DemoCall::People(_)) {273
control.send(CallUpdate::ReplacementLink(297
control.send(CallUpdate::ReplacementLink(274
DEMO_REPLACEMENT_LINK.to_owned(),298
DEMO_REPLACEMENT_LINK.to_owned(),@@ -300,7 +324,8 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc300
let video = !matches!(script, DemoCall::Test);324
let video = !matches!(script, DemoCall::Test);301
let sharer = matches!(script, DemoCall::Meeting { .. })325
let sharer = matches!(script, DemoCall::Meeting { .. })302
.then(|| people.get(1).map(|person| person.0.clone()))326
.then(|| people.get(1).map(|person| person.0.clone()))303
.flatten();327
.flatten()328
.filter(|_| scene != DemoScene::Gallery);304
start_scene(&control, scene);329
start_scene(&control, scene);305
speak_until_hangup(control, people, roster, video, sharer, scene).await;330
speak_until_hangup(control, people, roster, video, sharer, scene).await;306
}331
}@@ -332,6 +357,7 @@ fn publish_demo_video(332
sharing: bool,357
sharing: bool,333
sharer: Option<&str>,358
sharer: Option<&str>,334
camera: Option<bool>,359
camera: Option<bool>,360
cameras: usize,335
) {361
) {336
if let Some(blur) = camera {362
if let Some(blur) = camera {337
control.video.publish(363
control.video.publish(@@ -339,7 +365,7 @@ fn publish_demo_video(339
self_view((tick + SELF_PHASE) as usize, blur),365
self_view((tick + SELF_PHASE) as usize, blur),340
);366
);341
}367
}342
for (index, (mri, _)) in people.iter().take(DEMO_CAMERAS).enumerate() {368
for (index, (mri, _)) in people.iter().take(cameras).enumerate() {343
let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);369
let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);344
control370
control345
.video371
.video@@ -362,7 +388,11 @@ fn start_scene(control: &CallControl, scene: DemoScene) {362
}388
}363
DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),389
DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),364
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),390
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),365
DemoScene::Call | DemoScene::Breakout | DemoScene::Whiteboard | DemoScene::Plain => {}391
DemoScene::Call392
| DemoScene::Breakout393
| DemoScene::Whiteboard394
| DemoScene::Gallery395
| DemoScene::Plain => {}366
}396
}367
}397
}368
398
@@ -424,7 +454,7 @@ async fn speak_until_hangup(424
sharing = share_now;454
sharing = share_now;425
control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));455
control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));426
}456
}427
publish_demo_video(&control, &people, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur));457
publish_demo_video(&control, &people, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur), scene.cameras());428
video_ticks += 1;458
video_ticks += 1;429
}459
}430
_ = tick.tick() => {460
_ = tick.tick() => {@@ -434,8 +464,8 @@ async fn speak_until_hangup(434
local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },464
local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },435
remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },465
remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },436
});466
});437
if people.len() > 1 && ticks.is_multiple_of(SPEAKER_TICKS) {467
if people.len() > 1 && ticks.is_multiple_of(scene.speaker_ticks()) {438
let speaker = &people[(ticks / SPEAKER_TICKS) as usize % people.len()];468
let speaker = &people[(ticks / scene.speaker_ticks()) as usize % people.len()];439
control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));469
control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));440
}470
}441
if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2471
if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2@@ -649,17 +679,17 @@ mod tests {649
679
650
#[test]680
#[test]651
fn demo_guests_have_distinct_mris_and_names() {681
fn demo_guests_have_distinct_mris_and_names() {652
let guests = demo_guests(11);682
let guests = demo_guests(12);653
assert_eq!(guests.len(), 11);683
assert_eq!(guests.len(), 12);654
let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();684
let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();655
mris.sort();685
mris.sort();656
mris.dedup();686
mris.dedup();657
assert_eq!(mris.len(), 11);687
assert_eq!(mris.len(), 12);658
}688
}659
689
660
#[test]690
#[test]661
fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {691
fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {662
let mut roster = roster_of(&demo_guests(3));692
let mut roster = roster_of(&demo_guests(3), DEMO_CAMERAS);663
set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);693
set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);664
set_demo_hand(&mut roster, DEMO_OWN_MRI, true);694
set_demo_hand(&mut roster, DEMO_OWN_MRI, true);665
let ranks: Vec<u64> = roster695
let ranks: Vec<u64> = roster@@ -0,0 +1,71 @@
1
use std::time::{Duration, Instant};
2
3
pub const CHROME_IDLE: Duration = Duration::from_secs(3);
4
pub const HINT_SHOWN: Duration = Duration::from_secs(2);
5
6
#[derive(Debug, Clone, Copy)]
7
pub struct FullscreenState {
8
pub entered: Instant,
9
pub active_at: Instant,
10
pub hovered: bool,
11
pub timer_running: bool,
12
}
13
14
impl FullscreenState {
15
pub fn new(now: Instant) -> Self {
16
FullscreenState {
17
entered: now,
18
active_at: now,
19
hovered: false,
20
timer_running: false,
21
}
22
}
23
24
pub fn chrome_visible(&self, now: Instant) -> bool {
25
self.hovered || now.saturating_duration_since(self.active_at) < CHROME_IDLE
26
}
27
28
pub fn hint_visible(&self, now: Instant) -> bool {
29
now.saturating_duration_since(self.entered) < HINT_SHOWN
30
}
31
32
pub fn next_change(&self, now: Instant) -> Option<Duration> {
33
if self.hovered {
34
return None;
35
}
36
let hide_at = self.active_at + CHROME_IDLE;
37
(hide_at > now).then(|| hide_at - now)
38
}
39
}
40
41
#[cfg(test)]
42
mod tests {
43
use super::*;
44
45
#[test]
46
fn controls_hide_after_three_idle_seconds_and_return_on_movement() {
47
let start = Instant::now();
48
let mut state = FullscreenState::new(start);
49
assert!(state.chrome_visible(start + Duration::from_millis(2900)));
50
assert!(!state.chrome_visible(start + CHROME_IDLE));
51
state.active_at = start + Duration::from_secs(10);
52
assert!(state.chrome_visible(start + Duration::from_secs(11)));
53
}
54
55
#[test]
56
fn controls_stay_while_the_pointer_is_over_them() {
57
let start = Instant::now();
58
let mut state = FullscreenState::new(start);
59
state.hovered = true;
60
assert!(state.chrome_visible(start + Duration::from_secs(60)));
61
assert_eq!(state.next_change(start), None);
62
}
63
64
#[test]
65
fn the_exit_hint_shows_for_two_seconds() {
66
let start = Instant::now();
67
let state = FullscreenState::new(start);
68
assert!(state.hint_visible(start + Duration::from_millis(1900)));
69
assert!(!state.hint_visible(start + HINT_SHOWN));
70
}
71
}
@@ -0,0 +1,71 @@1
use std::time::{Duration, Instant};2
3
pub const CHROME_IDLE: Duration = Duration::from_secs(3);4
pub const HINT_SHOWN: Duration = Duration::from_secs(2);5
6
#[derive(Debug, Clone, Copy)]7
pub struct FullscreenState {8
pub entered: Instant,9
pub active_at: Instant,10
pub hovered: bool,11
pub timer_running: bool,12
}13
14
impl FullscreenState {15
pub fn new(now: Instant) -> Self {16
FullscreenState {17
entered: now,18
active_at: now,19
hovered: false,20
timer_running: false,21
}22
}23
24
pub fn chrome_visible(&self, now: Instant) -> bool {25
self.hovered || now.saturating_duration_since(self.active_at) < CHROME_IDLE26
}27
28
pub fn hint_visible(&self, now: Instant) -> bool {29
now.saturating_duration_since(self.entered) < HINT_SHOWN30
}31
32
pub fn next_change(&self, now: Instant) -> Option<Duration> {33
if self.hovered {34
return None;35
}36
let hide_at = self.active_at + CHROME_IDLE;37
(hide_at > now).then(|| hide_at - now)38
}39
}40
41
#[cfg(test)]42
mod tests {43
use super::*;44
45
#[test]46
fn controls_hide_after_three_idle_seconds_and_return_on_movement() {47
let start = Instant::now();48
let mut state = FullscreenState::new(start);49
assert!(state.chrome_visible(start + Duration::from_millis(2900)));50
assert!(!state.chrome_visible(start + CHROME_IDLE));51
state.active_at = start + Duration::from_secs(10);52
assert!(state.chrome_visible(start + Duration::from_secs(11)));53
}54
55
#[test]56
fn controls_stay_while_the_pointer_is_over_them() {57
let start = Instant::now();58
let mut state = FullscreenState::new(start);59
state.hovered = true;60
assert!(state.chrome_visible(start + Duration::from_secs(60)));61
assert_eq!(state.next_change(start), None);62
}63
64
#[test]65
fn the_exit_hint_shows_for_two_seconds() {66
let start = Instant::now();67
let state = FullscreenState::new(start);68
assert!(state.hint_visible(start + Duration::from_millis(1900)));69
assert!(!state.hint_visible(start + HINT_SHOWN));70
}71
}@@ -1,10 +1,12 @@
1
1
mod actions;
2
2
mod agenda;
3
3
mod background;
4
mod bubbles;
4
5
mod calendar;
5
6
mod demo;
6
7
mod demo_scene;
7
8
mod features;
9
mod fullscreen;
8
10
mod history;
9
11
mod join;
10
12
mod launcher;
@@ -16,7 +18,10 @@ mod overlay_layout;
16
18
mod pictures;
17
19
mod preview;
18
20
mod ring;
21
mod stage_layout;
19
22
mod target;
23
mod view_actions;
24
mod view_settings;
20
25
21
26
pub use actions::{load_camera, load_share_sound};
22
27
pub use agenda::{AgendaRow, fetch_window, join_available};
@@ -24,6 +29,7 @@ pub use background::{
24
29
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
25
30
load_custom_backgrounds,
26
31
};
32
pub use bubbles::{BUBBLE_SHOWN, shown_bubbles};
27
33
pub use demo::DemoScene;
28
34
pub use features::TransferCandidate;
29
35
pub use history::CallRow;
@@ -34,10 +40,12 @@ pub use list::{
34
40
};
35
41
pub use media::CallMedia;
36
42
pub use model::{
37
ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES,
38
REACTION_SHOWN, Tile, TileSize, TileState, grid_layout, tile_size,
43
ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,
44
TileState,
39
45
};
40
46
pub use overlay::CallWindows;
41
47
pub use preview::{CameraPreview, preview_backgrounds};
42
48
pub use ring::{MissedCall, RingEntry, Rings};
49
pub use stage_layout::{GALLERY_MAX, filmstrip, gallery_grid, split_overflow};
43
50
pub use target::plan_for_chat;
51
pub use view_settings::{CallLayout, ViewSettings};
@@ -1,10 +1,12 @@1
mod actions;1
mod actions;2
mod agenda;2
mod agenda;3
mod background;3
mod background;4
mod bubbles;4
mod calendar;5
mod calendar;5
mod demo;6
mod demo;6
mod demo_scene;7
mod demo_scene;7
mod features;8
mod features;9
mod fullscreen;8
mod history;10
mod history;9
mod join;11
mod join;10
mod launcher;12
mod launcher;@@ -16,7 +18,10 @@ mod overlay_layout;16
mod pictures;18
mod pictures;17
mod preview;19
mod preview;18
mod ring;20
mod ring;21
mod stage_layout;19
mod target;22
mod target;23
mod view_actions;24
mod view_settings;20
25
21
pub use actions::{load_camera, load_share_sound};26
pub use actions::{load_camera, load_share_sound};22
pub use agenda::{AgendaRow, fetch_window, join_available};27
pub use agenda::{AgendaRow, fetch_window, join_available};@@ -24,6 +29,7 @@ pub use background::{24
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,29
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,25
load_custom_backgrounds,30
load_custom_backgrounds,26
};31
};32
pub use bubbles::{BUBBLE_SHOWN, shown_bubbles};27
pub use demo::DemoScene;33
pub use demo::DemoScene;28
pub use features::TransferCandidate;34
pub use features::TransferCandidate;29
pub use history::CallRow;35
pub use history::CallRow;@@ -34,10 +40,12 @@ pub use list::{34
};40
};35
pub use media::CallMedia;41
pub use media::CallMedia;36
pub use model::{42
pub use model::{37
ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES,43
ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,38
REACTION_SHOWN, Tile, TileSize, TileState, grid_layout, tile_size,44
TileState,39
};45
};40
pub use overlay::CallWindows;46
pub use overlay::CallWindows;41
pub use preview::{CameraPreview, preview_backgrounds};47
pub use preview::{CameraPreview, preview_backgrounds};42
pub use ring::{MissedCall, RingEntry, Rings};48
pub use ring::{MissedCall, RingEntry, Rings};49
pub use stage_layout::{GALLERY_MAX, filmstrip, gallery_grid, split_overflow};43
pub use target::plan_for_chat;50
pub use target::plan_for_chat;51
pub use view_settings::{CallLayout, ViewSettings};@@ -1,3 +1,5 @@
1
use std::cell::Cell;
2
use std::rc::Rc;
1
3
use std::sync::Arc;
2
4
use std::time::{Duration, Instant};
3
5
@@ -9,18 +11,21 @@ use calling::{
9
11
use tokio::sync::mpsc::UnboundedSender;
10
12
11
13
use super::background::BackgroundPick;
14
use super::bubbles::ChatBubble;
15
use super::fullscreen::FullscreenState;
12
16
use super::pictures::CallPictures;
17
use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};
18
use super::view_settings::{CallLayout, ViewSettings};
13
19
14
20
pub const TEST_CALL_TITLE: &str = "Test call";
15
21
pub const ECHO_NAME: &str = "Teams echo";
16
22
pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;
17
pub const MAX_TILES: usize = 9;
18
23
const ORGID_PREFIX: &str = "8:orgid:";
19
const WIDE_TILES: usize = 2;
20
const MEDIUM_TILES: usize = 4;
24
const AVATAR_SHARE: f32 = 0.42;
25
const MIN_AVATAR: f32 = 32.;
26
const MAX_AVATAR: f32 = 96.;
21
27
pub const REACTION_SHOWN: Duration = Duration::from_secs(3);
22
28
const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);
23
pub const CHAT_OPEN_TILES: usize = 6;
24
29
pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);
25
30
const CAPTION_LINES: usize = 2;
26
31
@@ -33,6 +38,11 @@ pub struct ActiveCall {
33
38
pub video: Arc<VideoHub>,
34
39
pub pictures: CallPictures,
35
40
pub stage_fullscreen: bool,
41
pub fullscreen: Option<FullscreenState>,
42
pub stage_size: Rc<Cell<(f32, f32)>>,
43
pub bubbles: Vec<ChatBubble>,
44
pub share_menu_open: bool,
45
pub lobby_list_open: bool,
36
46
pub chat_open: bool,
37
47
pub meeting_target: Option<MeetingTarget>,
38
48
pub pending_move: Option<PendingMove>,
@@ -90,6 +100,11 @@ impl ActiveCall {
90
100
video,
91
101
pictures: CallPictures::default(),
92
102
stage_fullscreen: false,
103
fullscreen: None,
104
stage_size: Rc::default(),
105
bubbles: Vec::new(),
106
share_menu_open: false,
107
lobby_list_open: false,
93
108
chat_open: false,
94
109
meeting_target: None,
95
110
pending_move: None,
@@ -185,27 +200,6 @@ pub struct CaptionLine {
185
200
pub at: Instant,
186
201
}
187
202
188
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
189
pub struct GridLayout {
190
pub shown_others: usize,
191
pub hidden: usize,
192
}
193
194
pub fn grid_layout(others: usize, max_tiles: usize) -> GridLayout {
195
let total = others + 1;
196
if total <= max_tiles {
197
return GridLayout {
198
shown_others: others,
199
hidden: 0,
200
};
201
}
202
let shown_others = max_tiles - 2;
203
GridLayout {
204
shown_others,
205
hidden: others - shown_others,
206
}
207
}
208
209
203
#[derive(Debug, Clone, Copy, PartialEq)]
210
204
pub struct TileSize {
211
205
pub width: f32,
@@ -213,24 +207,13 @@ pub struct TileSize {
213
207
pub avatar: f32,
214
208
}
215
209
216
pub fn tile_size(cells: usize) -> TileSize {
217
if cells <= WIDE_TILES {
218
TileSize {
219
width: 260.,
220
height: 210.,
221
avatar: 96.,
222
}
223
} else if cells <= MEDIUM_TILES {
210
impl TileSize {
211
pub fn sixteen_by_nine(width: f32) -> TileSize {
212
let height = width * 9. / 16.;
224
213
TileSize {
225
width: 220.,
226
height: 180.,
227
avatar: 72.,
228
}
229
} else {
230
TileSize {
231
width: 190.,
232
height: 150.,
233
avatar: 56.,
214
width,
215
height,
216
avatar: (height * AVATAR_SHARE).clamp(MIN_AVATAR, MAX_AVATAR),
234
217
}
235
218
}
236
219
}
@@ -287,6 +270,8 @@ pub struct CallModel {
287
270
pub reactions: Vec<ReactionChip>,
288
271
reaction_serial: u64,
289
272
pub meeting_chat: Option<String>,
273
pub view: ViewSettings,
274
rotation: VisibleRotation,
290
275
local_detector: SpeakingDetector,
291
276
remote_detector: SpeakingDetector,
292
277
}
@@ -336,6 +321,8 @@ impl CallModel {
336
321
reactions: Vec::new(),
337
322
reaction_serial: 0,
338
323
meeting_chat: None,
324
view: ViewSettings::default(),
325
rotation: VisibleRotation::default(),
339
326
local_detector: SpeakingDetector::default(),
340
327
remote_detector: SpeakingDetector::default(),
341
328
}
@@ -417,8 +404,14 @@ impl CallModel {
417
404
CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,
418
405
CallUpdate::Stats { .. } => {}
419
406
CallUpdate::Progress(progress) => self.progress = Some(progress),
420
CallUpdate::Roster(entries) => self.apply_roster(&entries),
421
CallUpdate::Speakers(mris) => self.speaking_mris = mris,
407
CallUpdate::Roster(entries) => {
408
self.apply_roster(&entries);
409
self.refresh_layout(Instant::now());
410
}
411
CallUpdate::Speakers(mris) => {
412
self.speaking_mris = mris;
413
self.refresh_layout(Instant::now());
414
}
422
415
CallUpdate::Lobby(lobby) => self.lobby = lobby,
423
416
CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),
424
417
CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,
@@ -574,6 +567,7 @@ impl CallModel {
574
567
} else {
575
568
Some(mri.to_owned())
576
569
};
570
self.refresh_layout(Instant::now());
577
571
}
578
572
579
573
pub fn is_spotlighted(&self, mri: &str) -> bool {
@@ -737,6 +731,128 @@ impl CallModel {
737
731
tiles
738
732
}
739
733
734
pub fn has_content(&self) -> bool {
735
self.screen_sharer.is_some() || self.whiteboard.is_some()
736
}
737
738
pub fn effective_layout(&self) -> CallLayout {
739
match self.view.layout {
740
CallLayout::Content if self.has_content() => CallLayout::Content,
741
CallLayout::Content => match self.view.layout_before_content {
742
CallLayout::Content => CallLayout::Gallery,
743
before => before,
744
},
745
layout => layout,
746
}
747
}
748
749
fn is_prioritized(&self, tile: &Tile) -> bool {
750
self.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()
751
}
752
753
pub fn hidden_for_no_video(&self, tile: &Tile) -> bool {
754
self.view.hide_no_video
755
&& matches!(self.kind, CallKind::Group | CallKind::Meeting)
756
&& tile.state == TileState::Present
757
&& !tile.has_video
758
&& !self.is_pinned(&tile.mri)
759
&& !self.tile_speaking(tile)
760
}
761
762
pub fn hidden_without_video(&self) -> usize {
763
self.visible_tiles()
764
.into_iter()
765
.filter(|tile| self.hidden_for_no_video(tile))
766
.count()
767
}
768
769
fn layout_members(&self) -> Vec<&Tile> {
770
let mut tiles: Vec<&Tile> = self
771
.visible_tiles()
772
.into_iter()
773
.filter(|tile| !self.hidden_for_no_video(tile))
774
.collect();
775
tiles.sort_by_key(|tile| !self.is_prioritized(tile));
776
tiles
777
}
778
779
pub fn layout_tiles(&self) -> Vec<&Tile> {
780
let members = self.layout_members();
781
let mut ordered: Vec<&Tile> = self
782
.rotation
783
.order()
784
.iter()
785
.filter_map(|mri| members.iter().find(|tile| &tile.mri == mri).copied())
786
.collect();
787
ordered.extend(
788
members
789
.into_iter()
790
.filter(|tile| !self.rotation.order().contains(&tile.mri)),
791
);
792
ordered
793
}
794
795
pub fn own_cells(&self) -> usize {
796
usize::from(!self.view.hide_me)
797
}
798
799
fn rotation_capacity(&self, others: usize) -> usize {
800
let cells = match self.effective_layout() {
801
_ if self.has_content() => return others,
802
CallLayout::Speaker => FILMSTRIP_MAX,
803
CallLayout::Gallery | CallLayout::Content => GALLERY_MAX,
804
};
805
split_overflow(others, self.own_cells(), cells).shown
806
}
807
808
pub fn refresh_layout(&mut self, now: Instant) -> bool {
809
let members: Vec<String> = self
810
.layout_members()
811
.iter()
812
.map(|tile| tile.mri.clone())
813
.collect();
814
let priority: Vec<String> = self
815
.layout_members()
816
.iter()
817
.filter(|tile| self.is_prioritized(tile))
818
.map(|tile| tile.mri.clone())
819
.collect();
820
let capacity = self.rotation_capacity(members.len());
821
let speaking = self.speaking_mris.clone();
822
self.rotation
823
.update(now, &members, &priority, &speaking, capacity)
824
}
825
826
pub fn speaker_focus(&self) -> Option<Focus> {
827
if let Some(focus) = self.focus() {
828
return Some(focus);
829
}
830
let tiles = self.layout_tiles();
831
let spoken = self
832
.speaking_mris
833
.iter()
834
.find(|mri| tiles.iter().any(|tile| &tile.mri == *mri))
835
.map(String::as_str)
836
.or_else(|| {
837
self.rotation
838
.last_speaker()
839
.filter(|mri| tiles.iter().any(|tile| tile.mri == *mri))
840
})
841
.or_else(|| tiles.first().map(|tile| tile.mri.as_str()));
842
let own_mri = self.own_mri.clone().filter(|_| self.own_cells() > 0);
843
let (mri, own) = match (spoken, own_mri) {
844
(Some(mri), _) => (mri.to_owned(), false),
845
(None, Some(own_mri)) => (own_mri, true),
846
(None, None) => return None,
847
};
848
Some(Focus {
849
mri,
850
own,
851
spotlight: false,
852
pinned: false,
853
})
854
}
855
740
856
pub fn sharing_label(&self) -> Option<String> {
741
857
let sharer = self.screen_sharer.as_ref()?;
742
858
let name = self
@@ -1218,61 +1334,107 @@ mod tests {
1218
1334
assert!(lone.tile_speaking(&lone.tiles[0].clone()));
1219
1335
}
1220
1336
1337
fn crowd(count: usize) -> CallModel {
1338
let mut model = meeting_with_me();
1339
model.apply(CallUpdate::Roster(
1340
(0..count)
1341
.map(|index| {
1342
entry(
1343
&format!("8:orgid:p{index}"),
1344
&format!("P{index}"),
1345
false,
1346
false,
1347
)
1348
})
1349
.collect(),
1350
));
1351
model
1352
}
1353
1354
fn shown_mris(model: &CallModel) -> Vec<String> {
1355
model
1356
.layout_tiles()
1357
.iter()
1358
.map(|tile| tile.mri.clone())
1359
.collect()
1360
}
1361
1221
1362
#[test]
1222
fn more_than_nine_cells_collapse_into_a_plus_n_tile() {
1223
assert_eq!(
1224
grid_layout(0, MAX_TILES),
1225
GridLayout {
1226
shown_others: 0,
1227
hidden: 0
1228
}
1229
);
1230
assert_eq!(
1231
grid_layout(8, MAX_TILES),
1232
GridLayout {
1233
shown_others: 8,
1234
hidden: 0
1235
}
1236
);
1237
assert_eq!(
1238
grid_layout(9, MAX_TILES),
1239
GridLayout {
1240
shown_others: 7,
1241
hidden: 2
1242
}
1243
);
1244
assert_eq!(
1245
grid_layout(30, MAX_TILES),
1246
GridLayout {
1247
shown_others: 7,
1248
hidden: 23
1249
}
1250
);
1363
fn hiding_people_without_video_keeps_speakers_and_the_pinned_person() {
1364
let mut model = meeting_with_me();
1365
model.apply(CallUpdate::Roster(vec![
1366
entry("8:orgid:a", "Ana", false, false),
1367
RosterEntry {
1368
has_video: true,
1369
..entry("8:orgid:b", "Bo", false, false)
1370
},
1371
entry("8:orgid:c", "Cy", false, false),
1372
]));
1373
model.view.hide_no_video = true;
1374
assert_eq!(model.hidden_without_video(), 2);
1375
assert_eq!(shown_mris(&model), vec!["8:orgid:b"]);
1376
model.apply(CallUpdate::Speakers(vec!["8:orgid:a".into()]));
1377
assert_eq!(model.hidden_without_video(), 1);
1378
assert!(shown_mris(&model).contains(&"8:orgid:a".to_owned()));
1379
model.toggle_pin("8:orgid:c");
1380
assert_eq!(model.hidden_without_video(), 0);
1251
1381
}
1252
1382
1253
1383
#[test]
1254
fn an_open_chat_panel_leaves_room_for_fewer_tiles() {
1255
assert_eq!(
1256
grid_layout(5, CHAT_OPEN_TILES),
1257
GridLayout {
1258
shown_others: 5,
1259
hidden: 0
1260
}
1261
);
1262
assert_eq!(
1263
grid_layout(6, CHAT_OPEN_TILES),
1264
GridLayout {
1265
shown_others: 4,
1266
hidden: 2
1267
}
1268
);
1384
fn people_without_video_stay_in_one_to_one_calls() {
1385
let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]);
1386
model.view.hide_no_video = true;
1387
model.apply(CallUpdate::Roster(vec![entry(
1388
"8:orgid:b",
1389
"Bea",
1390
false,
1391
false,
1392
)]));
1393
assert_eq!(model.hidden_without_video(), 0);
1394
}
1395
1396
#[test]
1397
fn focus_on_content_falls_back_to_the_previous_layout_when_the_share_ends() {
1398
let mut model = meeting_with_me();
1399
model.view.choose(CallLayout::Speaker);
1400
model.view.choose(CallLayout::Content);
1401
assert_eq!(model.effective_layout(), CallLayout::Speaker);
1402
model.apply(CallUpdate::ScreenShare(Some("8:orgid:a".into())));
1403
assert_eq!(model.effective_layout(), CallLayout::Content);
1404
model.apply(CallUpdate::ScreenShare(None));
1405
assert_eq!(model.effective_layout(), CallLayout::Speaker);
1406
}
1407
1408
#[test]
1409
fn the_speaker_stage_follows_the_active_speaker_and_keeps_the_last_one() {
1410
let mut model = crowd(3);
1411
model.apply(CallUpdate::Speakers(vec!["8:orgid:p1".into()]));
1412
assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1413
model.apply(CallUpdate::Speakers(Vec::new()));
1414
assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1415
model.toggle_pin("8:orgid:p2");
1416
let focus = model.speaker_focus().unwrap();
1417
assert_eq!((focus.mri.as_str(), focus.pinned), ("8:orgid:p2", true));
1418
}
1419
1420
#[test]
1421
fn a_pinned_person_outside_the_grid_moves_into_it() {
1422
let mut model = crowd(12);
1423
let grid = split_overflow(12, 1, GALLERY_MAX).shown;
1424
assert_eq!(grid, 7);
1425
assert!(!shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1426
model.toggle_pin("8:orgid:p11");
1427
assert!(shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1428
assert_eq!(model.layout_tiles().len(), 12);
1269
1429
}
1270
1430
1271
1431
#[test]
1272
fn crowded_calls_get_smaller_tiles() {
1273
assert_eq!(tile_size(2).avatar, 96.);
1274
assert_eq!(tile_size(4).avatar, 72.);
1275
assert_eq!(tile_size(9).avatar, 56.);
1432
fn hiding_me_frees_a_grid_cell() {
1433
let mut model = crowd(12);
1434
assert_eq!(model.own_cells(), 1);
1435
model.view.hide_me = true;
1436
assert_eq!(model.own_cells(), 0);
1437
assert_eq!(split_overflow(12, model.own_cells(), GALLERY_MAX).shown, 8);
1276
1438
}
1277
1439
1278
1440
#[test]
@@ -1,3 +1,5 @@1
use std::cell::Cell;2
use std::rc::Rc;1
use std::sync::Arc;3
use std::sync::Arc;2
use std::time::{Duration, Instant};4
use std::time::{Duration, Instant};3
5
@@ -9,18 +11,21 @@ use calling::{9
use tokio::sync::mpsc::UnboundedSender;11
use tokio::sync::mpsc::UnboundedSender;10
12
11
use super::background::BackgroundPick;13
use super::background::BackgroundPick;14
use super::bubbles::ChatBubble;15
use super::fullscreen::FullscreenState;12
use super::pictures::CallPictures;16
use super::pictures::CallPictures;17
use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};18
use super::view_settings::{CallLayout, ViewSettings};13
19
14
pub const TEST_CALL_TITLE: &str = "Test call";20
pub const TEST_CALL_TITLE: &str = "Test call";15
pub const ECHO_NAME: &str = "Teams echo";21
pub const ECHO_NAME: &str = "Teams echo";16
pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;22
pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;17
pub const MAX_TILES: usize = 9;18
const ORGID_PREFIX: &str = "8:orgid:";23
const ORGID_PREFIX: &str = "8:orgid:";19
const WIDE_TILES: usize = 2;24
const AVATAR_SHARE: f32 = 0.42;20
const MEDIUM_TILES: usize = 4;25
const MIN_AVATAR: f32 = 32.;26
const MAX_AVATAR: f32 = 96.;21
pub const REACTION_SHOWN: Duration = Duration::from_secs(3);27
pub const REACTION_SHOWN: Duration = Duration::from_secs(3);22
const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);28
const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);23
pub const CHAT_OPEN_TILES: usize = 6;24
pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);29
pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);25
const CAPTION_LINES: usize = 2;30
const CAPTION_LINES: usize = 2;26
31
@@ -33,6 +38,11 @@ pub struct ActiveCall {33
pub video: Arc<VideoHub>,38
pub video: Arc<VideoHub>,34
pub pictures: CallPictures,39
pub pictures: CallPictures,35
pub stage_fullscreen: bool,40
pub stage_fullscreen: bool,41
pub fullscreen: Option<FullscreenState>,42
pub stage_size: Rc<Cell<(f32, f32)>>,43
pub bubbles: Vec<ChatBubble>,44
pub share_menu_open: bool,45
pub lobby_list_open: bool,36
pub chat_open: bool,46
pub chat_open: bool,37
pub meeting_target: Option<MeetingTarget>,47
pub meeting_target: Option<MeetingTarget>,38
pub pending_move: Option<PendingMove>,48
pub pending_move: Option<PendingMove>,@@ -90,6 +100,11 @@ impl ActiveCall {90
video,100
video,91
pictures: CallPictures::default(),101
pictures: CallPictures::default(),92
stage_fullscreen: false,102
stage_fullscreen: false,103
fullscreen: None,104
stage_size: Rc::default(),105
bubbles: Vec::new(),106
share_menu_open: false,107
lobby_list_open: false,93
chat_open: false,108
chat_open: false,94
meeting_target: None,109
meeting_target: None,95
pending_move: None,110
pending_move: None,@@ -185,27 +200,6 @@ pub struct CaptionLine {185
pub at: Instant,200
pub at: Instant,186
}201
}187
202
188
#[derive(Debug, Clone, Copy, PartialEq, Eq)]189
pub struct GridLayout {190
pub shown_others: usize,191
pub hidden: usize,192
}193
194
pub fn grid_layout(others: usize, max_tiles: usize) -> GridLayout {195
let total = others + 1;196
if total <= max_tiles {197
return GridLayout {198
shown_others: others,199
hidden: 0,200
};201
}202
let shown_others = max_tiles - 2;203
GridLayout {204
shown_others,205
hidden: others - shown_others,206
}207
}208
209
#[derive(Debug, Clone, Copy, PartialEq)]203
#[derive(Debug, Clone, Copy, PartialEq)]210
pub struct TileSize {204
pub struct TileSize {211
pub width: f32,205
pub width: f32,@@ -213,24 +207,13 @@ pub struct TileSize {213
pub avatar: f32,207
pub avatar: f32,214
}208
}215
209
216
pub fn tile_size(cells: usize) -> TileSize {210
impl TileSize {217
if cells <= WIDE_TILES {211
pub fn sixteen_by_nine(width: f32) -> TileSize {218
TileSize {212
let height = width * 9. / 16.;219
width: 260.,220
height: 210.,221
avatar: 96.,222
}223
} else if cells <= MEDIUM_TILES {224
TileSize {213
TileSize {225
width: 220.,214
width,226
height: 180.,215
height,227
avatar: 72.,216
avatar: (height * AVATAR_SHARE).clamp(MIN_AVATAR, MAX_AVATAR),228
}229
} else {230
TileSize {231
width: 190.,232
height: 150.,233
avatar: 56.,234
}217
}235
}218
}236
}219
}@@ -287,6 +270,8 @@ pub struct CallModel {287
pub reactions: Vec<ReactionChip>,270
pub reactions: Vec<ReactionChip>,288
reaction_serial: u64,271
reaction_serial: u64,289
pub meeting_chat: Option<String>,272
pub meeting_chat: Option<String>,273
pub view: ViewSettings,274
rotation: VisibleRotation,290
local_detector: SpeakingDetector,275
local_detector: SpeakingDetector,291
remote_detector: SpeakingDetector,276
remote_detector: SpeakingDetector,292
}277
}@@ -336,6 +321,8 @@ impl CallModel {336
reactions: Vec::new(),321
reactions: Vec::new(),337
reaction_serial: 0,322
reaction_serial: 0,338
meeting_chat: None,323
meeting_chat: None,324
view: ViewSettings::default(),325
rotation: VisibleRotation::default(),339
local_detector: SpeakingDetector::default(),326
local_detector: SpeakingDetector::default(),340
remote_detector: SpeakingDetector::default(),327
remote_detector: SpeakingDetector::default(),341
}328
}@@ -417,8 +404,14 @@ impl CallModel {417
CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,404
CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,418
CallUpdate::Stats { .. } => {}405
CallUpdate::Stats { .. } => {}419
CallUpdate::Progress(progress) => self.progress = Some(progress),406
CallUpdate::Progress(progress) => self.progress = Some(progress),420
CallUpdate::Roster(entries) => self.apply_roster(&entries),407
CallUpdate::Roster(entries) => {421
CallUpdate::Speakers(mris) => self.speaking_mris = mris,408
self.apply_roster(&entries);409
self.refresh_layout(Instant::now());410
}411
CallUpdate::Speakers(mris) => {412
self.speaking_mris = mris;413
self.refresh_layout(Instant::now());414
}422
CallUpdate::Lobby(lobby) => self.lobby = lobby,415
CallUpdate::Lobby(lobby) => self.lobby = lobby,423
CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),416
CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),424
CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,417
CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,@@ -574,6 +567,7 @@ impl CallModel {574
} else {567
} else {575
Some(mri.to_owned())568
Some(mri.to_owned())576
};569
};570
self.refresh_layout(Instant::now());577
}571
}578
572
579
pub fn is_spotlighted(&self, mri: &str) -> bool {573
pub fn is_spotlighted(&self, mri: &str) -> bool {@@ -737,6 +731,128 @@ impl CallModel {737
tiles731
tiles738
}732
}739
733
734
pub fn has_content(&self) -> bool {735
self.screen_sharer.is_some() || self.whiteboard.is_some()736
}737
738
pub fn effective_layout(&self) -> CallLayout {739
match self.view.layout {740
CallLayout::Content if self.has_content() => CallLayout::Content,741
CallLayout::Content => match self.view.layout_before_content {742
CallLayout::Content => CallLayout::Gallery,743
before => before,744
},745
layout => layout,746
}747
}748
749
fn is_prioritized(&self, tile: &Tile) -> bool {750
self.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()751
}752
753
pub fn hidden_for_no_video(&self, tile: &Tile) -> bool {754
self.view.hide_no_video755
&& matches!(self.kind, CallKind::Group | CallKind::Meeting)756
&& tile.state == TileState::Present757
&& !tile.has_video758
&& !self.is_pinned(&tile.mri)759
&& !self.tile_speaking(tile)760
}761
762
pub fn hidden_without_video(&self) -> usize {763
self.visible_tiles()764
.into_iter()765
.filter(|tile| self.hidden_for_no_video(tile))766
.count()767
}768
769
fn layout_members(&self) -> Vec<&Tile> {770
let mut tiles: Vec<&Tile> = self771
.visible_tiles()772
.into_iter()773
.filter(|tile| !self.hidden_for_no_video(tile))774
.collect();775
tiles.sort_by_key(|tile| !self.is_prioritized(tile));776
tiles777
}778
779
pub fn layout_tiles(&self) -> Vec<&Tile> {780
let members = self.layout_members();781
let mut ordered: Vec<&Tile> = self782
.rotation783
.order()784
.iter()785
.filter_map(|mri| members.iter().find(|tile| &tile.mri == mri).copied())786
.collect();787
ordered.extend(788
members789
.into_iter()790
.filter(|tile| !self.rotation.order().contains(&tile.mri)),791
);792
ordered793
}794
795
pub fn own_cells(&self) -> usize {796
usize::from(!self.view.hide_me)797
}798
799
fn rotation_capacity(&self, others: usize) -> usize {800
let cells = match self.effective_layout() {801
_ if self.has_content() => return others,802
CallLayout::Speaker => FILMSTRIP_MAX,803
CallLayout::Gallery | CallLayout::Content => GALLERY_MAX,804
};805
split_overflow(others, self.own_cells(), cells).shown806
}807
808
pub fn refresh_layout(&mut self, now: Instant) -> bool {809
let members: Vec<String> = self810
.layout_members()811
.iter()812
.map(|tile| tile.mri.clone())813
.collect();814
let priority: Vec<String> = self815
.layout_members()816
.iter()817
.filter(|tile| self.is_prioritized(tile))818
.map(|tile| tile.mri.clone())819
.collect();820
let capacity = self.rotation_capacity(members.len());821
let speaking = self.speaking_mris.clone();822
self.rotation823
.update(now, &members, &priority, &speaking, capacity)824
}825
826
pub fn speaker_focus(&self) -> Option<Focus> {827
if let Some(focus) = self.focus() {828
return Some(focus);829
}830
let tiles = self.layout_tiles();831
let spoken = self832
.speaking_mris833
.iter()834
.find(|mri| tiles.iter().any(|tile| &tile.mri == *mri))835
.map(String::as_str)836
.or_else(|| {837
self.rotation838
.last_speaker()839
.filter(|mri| tiles.iter().any(|tile| tile.mri == *mri))840
})841
.or_else(|| tiles.first().map(|tile| tile.mri.as_str()));842
let own_mri = self.own_mri.clone().filter(|_| self.own_cells() > 0);843
let (mri, own) = match (spoken, own_mri) {844
(Some(mri), _) => (mri.to_owned(), false),845
(None, Some(own_mri)) => (own_mri, true),846
(None, None) => return None,847
};848
Some(Focus {849
mri,850
own,851
spotlight: false,852
pinned: false,853
})854
}855
740
pub fn sharing_label(&self) -> Option<String> {856
pub fn sharing_label(&self) -> Option<String> {741
let sharer = self.screen_sharer.as_ref()?;857
let sharer = self.screen_sharer.as_ref()?;742
let name = self858
let name = self@@ -1218,61 +1334,107 @@ mod tests {1218
assert!(lone.tile_speaking(&lone.tiles[0].clone()));1334
assert!(lone.tile_speaking(&lone.tiles[0].clone()));1219
}1335
}1220
1336
1337
fn crowd(count: usize) -> CallModel {1338
let mut model = meeting_with_me();1339
model.apply(CallUpdate::Roster(1340
(0..count)1341
.map(|index| {1342
entry(1343
&format!("8:orgid:p{index}"),1344
&format!("P{index}"),1345
false,1346
false,1347
)1348
})1349
.collect(),1350
));1351
model1352
}1353
1354
fn shown_mris(model: &CallModel) -> Vec<String> {1355
model1356
.layout_tiles()1357
.iter()1358
.map(|tile| tile.mri.clone())1359
.collect()1360
}1361
1221
#[test]1362
#[test]1222
fn more_than_nine_cells_collapse_into_a_plus_n_tile() {1363
fn hiding_people_without_video_keeps_speakers_and_the_pinned_person() {1223
assert_eq!(1364
let mut model = meeting_with_me();1224
grid_layout(0, MAX_TILES),1365
model.apply(CallUpdate::Roster(vec![1225
GridLayout {1366
entry("8:orgid:a", "Ana", false, false),1226
shown_others: 0,1367
RosterEntry {1227
hidden: 01368
has_video: true,1228
}1369
..entry("8:orgid:b", "Bo", false, false)1229
);1370
},1230
assert_eq!(1371
entry("8:orgid:c", "Cy", false, false),1231
grid_layout(8, MAX_TILES),1372
]));1232
GridLayout {1373
model.view.hide_no_video = true;1233
shown_others: 8,1374
assert_eq!(model.hidden_without_video(), 2);1234
hidden: 01375
assert_eq!(shown_mris(&model), vec!["8:orgid:b"]);1235
}1376
model.apply(CallUpdate::Speakers(vec!["8:orgid:a".into()]));1236
);1377
assert_eq!(model.hidden_without_video(), 1);1237
assert_eq!(1378
assert!(shown_mris(&model).contains(&"8:orgid:a".to_owned()));1238
grid_layout(9, MAX_TILES),1379
model.toggle_pin("8:orgid:c");1239
GridLayout {1380
assert_eq!(model.hidden_without_video(), 0);1240
shown_others: 7,1241
hidden: 21242
}1243
);1244
assert_eq!(1245
grid_layout(30, MAX_TILES),1246
GridLayout {1247
shown_others: 7,1248
hidden: 231249
}1250
);1251
}1381
}1252
1382
1253
#[test]1383
#[test]1254
fn an_open_chat_panel_leaves_room_for_fewer_tiles() {1384
fn people_without_video_stay_in_one_to_one_calls() {1255
assert_eq!(1385
let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]);1256
grid_layout(5, CHAT_OPEN_TILES),1386
model.view.hide_no_video = true;1257
GridLayout {1387
model.apply(CallUpdate::Roster(vec![entry(1258
shown_others: 5,1388
"8:orgid:b",1259
hidden: 01389
"Bea",1260
}1390
false,1261
);1391
false,1262
assert_eq!(1392
)]));1263
grid_layout(6, CHAT_OPEN_TILES),1393
assert_eq!(model.hidden_without_video(), 0);1264
GridLayout {1394
}1265
shown_others: 4,1395
1266
hidden: 21396
#[test]1267
}1397
fn focus_on_content_falls_back_to_the_previous_layout_when_the_share_ends() {1268
);1398
let mut model = meeting_with_me();1399
model.view.choose(CallLayout::Speaker);1400
model.view.choose(CallLayout::Content);1401
assert_eq!(model.effective_layout(), CallLayout::Speaker);1402
model.apply(CallUpdate::ScreenShare(Some("8:orgid:a".into())));1403
assert_eq!(model.effective_layout(), CallLayout::Content);1404
model.apply(CallUpdate::ScreenShare(None));1405
assert_eq!(model.effective_layout(), CallLayout::Speaker);1406
}1407
1408
#[test]1409
fn the_speaker_stage_follows_the_active_speaker_and_keeps_the_last_one() {1410
let mut model = crowd(3);1411
model.apply(CallUpdate::Speakers(vec!["8:orgid:p1".into()]));1412
assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");1413
model.apply(CallUpdate::Speakers(Vec::new()));1414
assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");1415
model.toggle_pin("8:orgid:p2");1416
let focus = model.speaker_focus().unwrap();1417
assert_eq!((focus.mri.as_str(), focus.pinned), ("8:orgid:p2", true));1418
}1419
1420
#[test]1421
fn a_pinned_person_outside_the_grid_moves_into_it() {1422
let mut model = crowd(12);1423
let grid = split_overflow(12, 1, GALLERY_MAX).shown;1424
assert_eq!(grid, 7);1425
assert!(!shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));1426
model.toggle_pin("8:orgid:p11");1427
assert!(shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));1428
assert_eq!(model.layout_tiles().len(), 12);1269
}1429
}1270
1430
1271
#[test]1431
#[test]1272
fn crowded_calls_get_smaller_tiles() {1432
fn hiding_me_frees_a_grid_cell() {1273
assert_eq!(tile_size(2).avatar, 96.);1433
let mut model = crowd(12);1274
assert_eq!(tile_size(4).avatar, 72.);1434
assert_eq!(model.own_cells(), 1);1275
assert_eq!(tile_size(9).avatar, 56.);1435
model.view.hide_me = true;1436
assert_eq!(model.own_cells(), 0);1437
assert_eq!(split_overflow(12, model.own_cells(), GALLERY_MAX).shown, 8);1276
}1438
}1277
1439
1278
#[test]1440
#[test]@@ -0,0 +1,471 @@
1
use std::collections::HashMap;
2
use std::time::{Duration, Instant};
3
4
pub const GALLERY_MAX: usize = 9;
5
pub const FILMSTRIP_MAX: usize = 6;
6
pub const FILMSTRIP_MIN_WIDTH: f32 = 160.;
7
pub const SWAP_AFTER_SPEAKING: Duration = Duration::from_secs(2);
8
pub const SWAP_INTERVAL: Duration = Duration::from_secs(5);
9
const TILE_ASPECT: f32 = 16. / 9.;
10
11
#[derive(Debug, Clone, Copy, PartialEq)]
12
pub struct GalleryGrid {
13
pub columns: usize,
14
pub tile_width: f32,
15
pub tile_height: f32,
16
}
17
18
pub fn gallery_grid(cells: usize, stage_width: f32, stage_height: f32, gap: f32) -> GalleryGrid {
19
let cells = cells.max(1);
20
let mut best = GalleryGrid {
21
columns: 1,
22
tile_width: 0.,
23
tile_height: 0.,
24
};
25
for columns in 1..=cells {
26
let rows = cells.div_ceil(columns);
27
let cell_width = (stage_width - gap * (columns - 1) as f32) / columns as f32;
28
let cell_height = (stage_height - gap * (rows - 1) as f32) / rows as f32;
29
let tile_width = cell_width.min(cell_height * TILE_ASPECT).max(0.);
30
if tile_width > best.tile_width {
31
best = GalleryGrid {
32
columns,
33
tile_width,
34
tile_height: tile_width / TILE_ASPECT,
35
};
36
}
37
}
38
best
39
}
40
41
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42
pub struct Overflow {
43
pub shown: usize,
44
pub hidden: usize,
45
}
46
47
pub fn split_overflow(others: usize, own_cells: usize, capacity: usize) -> Overflow {
48
if others + own_cells <= capacity {
49
return Overflow {
50
shown: others,
51
hidden: 0,
52
};
53
}
54
let shown = capacity.saturating_sub(own_cells + 1);
55
Overflow {
56
shown,
57
hidden: others - shown,
58
}
59
}
60
61
#[derive(Debug, Clone, Copy, PartialEq)]
62
pub struct Filmstrip {
63
pub tile_width: f32,
64
pub tile_height: f32,
65
pub overflow: Overflow,
66
}
67
68
pub fn filmstrip(
69
others: usize,
70
own_cells: usize,
71
stage_width: f32,
72
gap: f32,
73
max_tile_width: f32,
74
) -> Filmstrip {
75
let fitting = ((stage_width + gap) / (FILMSTRIP_MIN_WIDTH + gap)) as usize;
76
let capacity = FILMSTRIP_MAX.min(fitting.max(1));
77
let overflow = split_overflow(others, own_cells, capacity);
78
let cells = (overflow.shown + own_cells + usize::from(overflow.hidden > 0)).max(1);
79
let tile_width = ((stage_width - gap * (cells - 1) as f32) / cells as f32)
80
.clamp(FILMSTRIP_MIN_WIDTH, max_tile_width);
81
Filmstrip {
82
tile_width,
83
tile_height: tile_width / TILE_ASPECT,
84
overflow,
85
}
86
}
87
88
#[derive(Debug, Clone, Default)]
89
pub struct VisibleRotation {
90
order: Vec<String>,
91
speaking_since: HashMap<String, Instant>,
92
last_spoke: HashMap<String, Instant>,
93
last_swap: Option<Instant>,
94
}
95
96
impl VisibleRotation {
97
pub fn order(&self) -> &[String] {
98
&self.order
99
}
100
101
pub fn last_speaker(&self) -> Option<&str> {
102
self.order
103
.iter()
104
.filter_map(|mri| Some((mri, self.last_spoke.get(mri)?)))
105
.max_by_key(|(_, spoke)| **spoke)
106
.map(|(mri, _)| mri.as_str())
107
}
108
109
pub fn update(
110
&mut self,
111
now: Instant,
112
members: &[String],
113
priority: &[String],
114
speaking: &[String],
115
capacity: usize,
116
) -> bool {
117
let before = self.order.clone();
118
self.track_speakers(now, speaking);
119
self.order.retain(|mri| members.contains(mri));
120
let mut arrivals: Vec<(usize, &String)> = members
121
.iter()
122
.enumerate()
123
.filter(|(_, mri)| !self.order.contains(mri))
124
.collect();
125
arrivals.sort_by_key(|(index, mri)| {
126
(
127
!priority.contains(mri),
128
std::cmp::Reverse(self.last_spoke.get(*mri).copied()),
129
*index,
130
)
131
});
132
self.order
133
.extend(arrivals.into_iter().map(|(_, mri)| mri.clone()));
134
if capacity > 0 && capacity < self.order.len() {
135
self.pull_in_priority(priority, capacity);
136
self.pull_in_speaker(now, priority, capacity);
137
}
138
self.order != before
139
}
140
141
fn track_speakers(&mut self, now: Instant, speaking: &[String]) {
142
self.speaking_since.retain(|mri, _| speaking.contains(mri));
143
for mri in speaking {
144
self.speaking_since.entry(mri.clone()).or_insert(now);
145
self.last_spoke.insert(mri.clone(), now);
146
}
147
}
148
149
fn pull_in_priority(&mut self, priority: &[String], capacity: usize) {
150
for mri in priority {
151
if let Some(index) = self.order.iter().position(|other| other == mri)
152
&& index >= capacity
153
{
154
self.swap_in(index, priority, capacity);
155
}
156
}
157
}
158
159
fn pull_in_speaker(&mut self, now: Instant, priority: &[String], capacity: usize) {
160
let rested = self
161
.last_swap
162
.is_none_or(|swapped| now.saturating_duration_since(swapped) >= SWAP_INTERVAL);
163
if !rested {
164
return;
165
}
166
let candidate = self.order[capacity..]
167
.iter()
168
.enumerate()
169
.filter_map(|(offset, mri)| Some((capacity + offset, *self.speaking_since.get(mri)?)))
170
.filter(|(_, since)| now.saturating_duration_since(*since) >= SWAP_AFTER_SPEAKING)
171
.min_by_key(|(_, since)| *since);
172
if let Some((index, _)) = candidate
173
&& self.swap_in(index, priority, capacity)
174
{
175
self.last_swap = Some(now);
176
}
177
}
178
179
fn swap_in(&mut self, index: usize, priority: &[String], capacity: usize) -> bool {
180
let victim = self.order[..capacity]
181
.iter()
182
.enumerate()
183
.filter(|(_, mri)| !priority.contains(mri))
184
.min_by_key(|(position, mri)| {
185
(
186
self.last_spoke.get(*mri).copied(),
187
std::cmp::Reverse(*position),
188
)
189
})
190
.map(|(position, _)| position);
191
let Some(victim) = victim else {
192
return false;
193
};
194
self.order.swap(victim, index);
195
true
196
}
197
}
198
199
#[cfg(test)]
200
mod tests {
201
use super::*;
202
203
fn names(count: usize) -> Vec<String> {
204
(0..count).map(|index| format!("p{index}")).collect()
205
}
206
207
fn visible(rotation: &VisibleRotation, capacity: usize) -> Vec<String> {
208
rotation.order()[..capacity].to_vec()
209
}
210
211
fn speak(mris: &[&str]) -> Vec<String> {
212
mris.iter().map(|mri| (*mri).to_owned()).collect()
213
}
214
215
#[test]
216
fn a_single_tile_takes_the_whole_stage() {
217
let grid = gallery_grid(1, 1600., 900., 20.);
218
assert_eq!(grid.columns, 1);
219
assert!((grid.tile_width - 1600.).abs() < 0.01);
220
}
221
222
#[test]
223
fn two_tiles_sit_side_by_side_on_a_wide_stage() {
224
let grid = gallery_grid(2, 1600., 900., 20.);
225
assert_eq!(grid.columns, 2);
226
assert_eq!(grid.tile_width, 790.);
227
}
228
229
#[test]
230
fn nine_tiles_make_three_by_three_and_fit_the_stage() {
231
let grid = gallery_grid(9, 1600., 900., 20.);
232
assert_eq!(grid.columns, 3);
233
assert!(grid.tile_width * 3. + 40. <= 1600.);
234
assert!(grid.tile_height * 3. + 40. <= 900.);
235
}
236
237
#[test]
238
fn a_tall_stage_prefers_fewer_columns() {
239
let grid = gallery_grid(4, 500., 1200., 20.);
240
assert_eq!(grid.columns, 1);
241
}
242
243
#[test]
244
fn tiles_stay_sixteen_by_nine() {
245
let grid = gallery_grid(7, 1234., 777., 20.);
246
assert!((grid.tile_width / grid.tile_height - 16. / 9.).abs() < 0.001);
247
}
248
249
#[test]
250
fn nine_people_fit_and_ten_end_in_a_plus_tile() {
251
assert_eq!(
252
split_overflow(8, 1, GALLERY_MAX),
253
Overflow {
254
shown: 8,
255
hidden: 0
256
}
257
);
258
assert_eq!(
259
split_overflow(9, 1, GALLERY_MAX),
260
Overflow {
261
shown: 7,
262
hidden: 2
263
}
264
);
265
assert_eq!(
266
split_overflow(12, 0, GALLERY_MAX),
267
Overflow {
268
shown: 8,
269
hidden: 4
270
}
271
);
272
}
273
274
#[test]
275
fn the_filmstrip_holds_six_tiles_then_a_plus_tile() {
276
let strip = filmstrip(5, 1, 1600., 12., 240.);
277
assert_eq!(strip.overflow.hidden, 0);
278
let strip = filmstrip(6, 1, 1600., 12., 240.);
279
assert_eq!(
280
strip.overflow,
281
Overflow {
282
shown: 4,
283
hidden: 2
284
}
285
);
286
assert_eq!(strip.tile_width, 240.);
287
}
288
289
#[test]
290
fn a_narrow_filmstrip_keeps_tiles_at_the_minimum_and_adds_the_plus_tile() {
291
let strip = filmstrip(5, 1, 504., 12., 240.);
292
assert_eq!(strip.tile_width, FILMSTRIP_MIN_WIDTH);
293
assert_eq!(strip.tile_height, 90.);
294
assert_eq!(
295
strip.overflow,
296
Overflow {
297
shown: 1,
298
hidden: 4
299
}
300
);
301
}
302
303
#[test]
304
fn new_members_start_in_priority_order_and_stay_put() {
305
let mut rotation = VisibleRotation::default();
306
let now = Instant::now();
307
let members = names(5);
308
rotation.update(now, &members, &speak(&["p3"]), &[], 4);
309
assert_eq!(rotation.order()[0], "p3");
310
let before = visible(&rotation, 4);
311
rotation.update(now, &members, &speak(&["p3"]), &[], 4);
312
assert_eq!(visible(&rotation, 4), before);
313
}
314
315
#[test]
316
fn an_outside_speaker_swaps_in_only_after_two_seconds_of_speech() {
317
let mut rotation = VisibleRotation::default();
318
let start = Instant::now();
319
let members = names(6);
320
rotation.update(start, &members, &[], &[], 4);
321
let outside = "p5";
322
rotation.update(start, &members, &[], &speak(&[outside]), 4);
323
rotation.update(
324
start + Duration::from_millis(1900),
325
&members,
326
&[],
327
&speak(&[outside]),
328
4,
329
);
330
assert!(!visible(&rotation, 4).contains(&outside.to_owned()));
331
rotation.update(
332
start + SWAP_AFTER_SPEAKING,
333
&members,
334
&[],
335
&speak(&[outside]),
336
4,
337
);
338
assert!(visible(&rotation, 4).contains(&outside.to_owned()));
339
}
340
341
#[test]
342
fn interrupted_speech_restarts_the_two_second_clock() {
343
let mut rotation = VisibleRotation::default();
344
let start = Instant::now();
345
let members = names(6);
346
rotation.update(start, &members, &[], &[], 4);
347
rotation.update(start, &members, &[], &speak(&["p5"]), 4);
348
rotation.update(start + Duration::from_millis(1500), &members, &[], &[], 4);
349
rotation.update(
350
start + Duration::from_millis(2500),
351
&members,
352
&[],
353
&speak(&["p5"]),
354
4,
355
);
356
rotation.update(
357
start + Duration::from_millis(3500),
358
&members,
359
&[],
360
&speak(&["p5"]),
361
4,
362
);
363
assert!(!visible(&rotation, 4).contains(&"p5".to_owned()));
364
}
365
366
#[test]
367
fn the_least_recently_speaking_visible_tile_is_replaced_and_the_others_keep_their_slots() {
368
let mut rotation = VisibleRotation::default();
369
let start = Instant::now();
370
let members = names(6);
371
rotation.update(start, &members, &[], &[], 4);
372
rotation.update(start, &members, &[], &speak(&["p0", "p1", "p3"]), 4);
373
let before = visible(&rotation, 4);
374
rotation.update(start, &members, &[], &speak(&["p5", "p0", "p1", "p3"]), 4);
375
rotation.update(
376
start + SWAP_AFTER_SPEAKING,
377
&members,
378
&[],
379
&speak(&["p5", "p0", "p1", "p3"]),
380
4,
381
);
382
let after = visible(&rotation, 4);
383
let slot = before.iter().position(|mri| mri == "p2").unwrap();
384
assert_eq!(after[slot], "p5");
385
for (index, mri) in before
386
.iter()
387
.enumerate()
388
.filter(|(index, _)| *index != slot)
389
{
390
assert_eq!(&after[index], mri);
391
}
392
}
393
394
#[test]
395
fn at_most_one_speaker_swaps_in_per_five_seconds() {
396
let mut rotation = VisibleRotation::default();
397
let start = Instant::now();
398
let members = names(7);
399
rotation.update(start, &members, &[], &[], 4);
400
let talking = speak(&["p5", "p6"]);
401
rotation.update(start, &members, &[], &talking, 4);
402
rotation.update(start + SWAP_AFTER_SPEAKING, &members, &[], &talking, 4);
403
let swapped = visible(&rotation, 4)
404
.iter()
405
.filter(|mri| *mri == "p5" || *mri == "p6")
406
.count();
407
assert_eq!(swapped, 1);
408
rotation.update(
409
start + SWAP_AFTER_SPEAKING + Duration::from_secs(4),
410
&members,
411
&[],
412
&talking,
413
4,
414
);
415
let still = visible(&rotation, 4)
416
.iter()
417
.filter(|mri| *mri == "p5" || *mri == "p6")
418
.count();
419
assert_eq!(still, 1);
420
rotation.update(
421
start + SWAP_AFTER_SPEAKING + SWAP_INTERVAL,
422
&members,
423
&[],
424
&talking,
425
4,
426
);
427
let both = visible(&rotation, 4)
428
.iter()
429
.filter(|mri| *mri == "p5" || *mri == "p6")
430
.count();
431
assert_eq!(both, 2);
432
}
433
434
#[test]
435
fn a_pinned_person_outside_the_grid_swaps_in_at_once_and_is_never_replaced() {
436
let mut rotation = VisibleRotation::default();
437
let start = Instant::now();
438
let members = names(6);
439
rotation.update(start, &members, &[], &[], 4);
440
let pinned = speak(&["p5"]);
441
rotation.update(start, &members, &pinned, &[], 4);
442
assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
443
let talking = speak(&["p4"]);
444
rotation.update(
445
start + Duration::from_secs(1),
446
&members,
447
&pinned,
448
&talking,
449
4,
450
);
451
rotation.update(
452
start + Duration::from_secs(4),
453
&members,
454
&pinned,
455
&talking,
456
4,
457
);
458
assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
459
}
460
461
#[test]
462
fn people_who_leave_drop_out_and_the_next_one_moves_up() {
463
let mut rotation = VisibleRotation::default();
464
let now = Instant::now();
465
let members = names(5);
466
rotation.update(now, &members, &[], &[], 3);
467
let remaining: Vec<String> = members.into_iter().filter(|mri| mri != "p1").collect();
468
rotation.update(now, &remaining, &[], &[], 3);
469
assert_eq!(visible(&rotation, 3), vec!["p0", "p2", "p3"]);
470
}
471
}
@@ -0,0 +1,471 @@1
use std::collections::HashMap;2
use std::time::{Duration, Instant};3
4
pub const GALLERY_MAX: usize = 9;5
pub const FILMSTRIP_MAX: usize = 6;6
pub const FILMSTRIP_MIN_WIDTH: f32 = 160.;7
pub const SWAP_AFTER_SPEAKING: Duration = Duration::from_secs(2);8
pub const SWAP_INTERVAL: Duration = Duration::from_secs(5);9
const TILE_ASPECT: f32 = 16. / 9.;10
11
#[derive(Debug, Clone, Copy, PartialEq)]12
pub struct GalleryGrid {13
pub columns: usize,14
pub tile_width: f32,15
pub tile_height: f32,16
}17
18
pub fn gallery_grid(cells: usize, stage_width: f32, stage_height: f32, gap: f32) -> GalleryGrid {19
let cells = cells.max(1);20
let mut best = GalleryGrid {21
columns: 1,22
tile_width: 0.,23
tile_height: 0.,24
};25
for columns in 1..=cells {26
let rows = cells.div_ceil(columns);27
let cell_width = (stage_width - gap * (columns - 1) as f32) / columns as f32;28
let cell_height = (stage_height - gap * (rows - 1) as f32) / rows as f32;29
let tile_width = cell_width.min(cell_height * TILE_ASPECT).max(0.);30
if tile_width > best.tile_width {31
best = GalleryGrid {32
columns,33
tile_width,34
tile_height: tile_width / TILE_ASPECT,35
};36
}37
}38
best39
}40
41
#[derive(Debug, Clone, Copy, PartialEq, Eq)]42
pub struct Overflow {43
pub shown: usize,44
pub hidden: usize,45
}46
47
pub fn split_overflow(others: usize, own_cells: usize, capacity: usize) -> Overflow {48
if others + own_cells <= capacity {49
return Overflow {50
shown: others,51
hidden: 0,52
};53
}54
let shown = capacity.saturating_sub(own_cells + 1);55
Overflow {56
shown,57
hidden: others - shown,58
}59
}60
61
#[derive(Debug, Clone, Copy, PartialEq)]62
pub struct Filmstrip {63
pub tile_width: f32,64
pub tile_height: f32,65
pub overflow: Overflow,66
}67
68
pub fn filmstrip(69
others: usize,70
own_cells: usize,71
stage_width: f32,72
gap: f32,73
max_tile_width: f32,74
) -> Filmstrip {75
let fitting = ((stage_width + gap) / (FILMSTRIP_MIN_WIDTH + gap)) as usize;76
let capacity = FILMSTRIP_MAX.min(fitting.max(1));77
let overflow = split_overflow(others, own_cells, capacity);78
let cells = (overflow.shown + own_cells + usize::from(overflow.hidden > 0)).max(1);79
let tile_width = ((stage_width - gap * (cells - 1) as f32) / cells as f32)80
.clamp(FILMSTRIP_MIN_WIDTH, max_tile_width);81
Filmstrip {82
tile_width,83
tile_height: tile_width / TILE_ASPECT,84
overflow,85
}86
}87
88
#[derive(Debug, Clone, Default)]89
pub struct VisibleRotation {90
order: Vec<String>,91
speaking_since: HashMap<String, Instant>,92
last_spoke: HashMap<String, Instant>,93
last_swap: Option<Instant>,94
}95
96
impl VisibleRotation {97
pub fn order(&self) -> &[String] {98
&self.order99
}100
101
pub fn last_speaker(&self) -> Option<&str> {102
self.order103
.iter()104
.filter_map(|mri| Some((mri, self.last_spoke.get(mri)?)))105
.max_by_key(|(_, spoke)| **spoke)106
.map(|(mri, _)| mri.as_str())107
}108
109
pub fn update(110
&mut self,111
now: Instant,112
members: &[String],113
priority: &[String],114
speaking: &[String],115
capacity: usize,116
) -> bool {117
let before = self.order.clone();118
self.track_speakers(now, speaking);119
self.order.retain(|mri| members.contains(mri));120
let mut arrivals: Vec<(usize, &String)> = members121
.iter()122
.enumerate()123
.filter(|(_, mri)| !self.order.contains(mri))124
.collect();125
arrivals.sort_by_key(|(index, mri)| {126
(127
!priority.contains(mri),128
std::cmp::Reverse(self.last_spoke.get(*mri).copied()),129
*index,130
)131
});132
self.order133
.extend(arrivals.into_iter().map(|(_, mri)| mri.clone()));134
if capacity > 0 && capacity < self.order.len() {135
self.pull_in_priority(priority, capacity);136
self.pull_in_speaker(now, priority, capacity);137
}138
self.order != before139
}140
141
fn track_speakers(&mut self, now: Instant, speaking: &[String]) {142
self.speaking_since.retain(|mri, _| speaking.contains(mri));143
for mri in speaking {144
self.speaking_since.entry(mri.clone()).or_insert(now);145
self.last_spoke.insert(mri.clone(), now);146
}147
}148
149
fn pull_in_priority(&mut self, priority: &[String], capacity: usize) {150
for mri in priority {151
if let Some(index) = self.order.iter().position(|other| other == mri)152
&& index >= capacity153
{154
self.swap_in(index, priority, capacity);155
}156
}157
}158
159
fn pull_in_speaker(&mut self, now: Instant, priority: &[String], capacity: usize) {160
let rested = self161
.last_swap162
.is_none_or(|swapped| now.saturating_duration_since(swapped) >= SWAP_INTERVAL);163
if !rested {164
return;165
}166
let candidate = self.order[capacity..]167
.iter()168
.enumerate()169
.filter_map(|(offset, mri)| Some((capacity + offset, *self.speaking_since.get(mri)?)))170
.filter(|(_, since)| now.saturating_duration_since(*since) >= SWAP_AFTER_SPEAKING)171
.min_by_key(|(_, since)| *since);172
if let Some((index, _)) = candidate173
&& self.swap_in(index, priority, capacity)174
{175
self.last_swap = Some(now);176
}177
}178
179
fn swap_in(&mut self, index: usize, priority: &[String], capacity: usize) -> bool {180
let victim = self.order[..capacity]181
.iter()182
.enumerate()183
.filter(|(_, mri)| !priority.contains(mri))184
.min_by_key(|(position, mri)| {185
(186
self.last_spoke.get(*mri).copied(),187
std::cmp::Reverse(*position),188
)189
})190
.map(|(position, _)| position);191
let Some(victim) = victim else {192
return false;193
};194
self.order.swap(victim, index);195
true196
}197
}198
199
#[cfg(test)]200
mod tests {201
use super::*;202
203
fn names(count: usize) -> Vec<String> {204
(0..count).map(|index| format!("p{index}")).collect()205
}206
207
fn visible(rotation: &VisibleRotation, capacity: usize) -> Vec<String> {208
rotation.order()[..capacity].to_vec()209
}210
211
fn speak(mris: &[&str]) -> Vec<String> {212
mris.iter().map(|mri| (*mri).to_owned()).collect()213
}214
215
#[test]216
fn a_single_tile_takes_the_whole_stage() {217
let grid = gallery_grid(1, 1600., 900., 20.);218
assert_eq!(grid.columns, 1);219
assert!((grid.tile_width - 1600.).abs() < 0.01);220
}221
222
#[test]223
fn two_tiles_sit_side_by_side_on_a_wide_stage() {224
let grid = gallery_grid(2, 1600., 900., 20.);225
assert_eq!(grid.columns, 2);226
assert_eq!(grid.tile_width, 790.);227
}228
229
#[test]230
fn nine_tiles_make_three_by_three_and_fit_the_stage() {231
let grid = gallery_grid(9, 1600., 900., 20.);232
assert_eq!(grid.columns, 3);233
assert!(grid.tile_width * 3. + 40. <= 1600.);234
assert!(grid.tile_height * 3. + 40. <= 900.);235
}236
237
#[test]238
fn a_tall_stage_prefers_fewer_columns() {239
let grid = gallery_grid(4, 500., 1200., 20.);240
assert_eq!(grid.columns, 1);241
}242
243
#[test]244
fn tiles_stay_sixteen_by_nine() {245
let grid = gallery_grid(7, 1234., 777., 20.);246
assert!((grid.tile_width / grid.tile_height - 16. / 9.).abs() < 0.001);247
}248
249
#[test]250
fn nine_people_fit_and_ten_end_in_a_plus_tile() {251
assert_eq!(252
split_overflow(8, 1, GALLERY_MAX),253
Overflow {254
shown: 8,255
hidden: 0256
}257
);258
assert_eq!(259
split_overflow(9, 1, GALLERY_MAX),260
Overflow {261
shown: 7,262
hidden: 2263
}264
);265
assert_eq!(266
split_overflow(12, 0, GALLERY_MAX),267
Overflow {268
shown: 8,269
hidden: 4270
}271
);272
}273
274
#[test]275
fn the_filmstrip_holds_six_tiles_then_a_plus_tile() {276
let strip = filmstrip(5, 1, 1600., 12., 240.);277
assert_eq!(strip.overflow.hidden, 0);278
let strip = filmstrip(6, 1, 1600., 12., 240.);279
assert_eq!(280
strip.overflow,281
Overflow {282
shown: 4,283
hidden: 2284
}285
);286
assert_eq!(strip.tile_width, 240.);287
}288
289
#[test]290
fn a_narrow_filmstrip_keeps_tiles_at_the_minimum_and_adds_the_plus_tile() {291
let strip = filmstrip(5, 1, 504., 12., 240.);292
assert_eq!(strip.tile_width, FILMSTRIP_MIN_WIDTH);293
assert_eq!(strip.tile_height, 90.);294
assert_eq!(295
strip.overflow,296
Overflow {297
shown: 1,298
hidden: 4299
}300
);301
}302
303
#[test]304
fn new_members_start_in_priority_order_and_stay_put() {305
let mut rotation = VisibleRotation::default();306
let now = Instant::now();307
let members = names(5);308
rotation.update(now, &members, &speak(&["p3"]), &[], 4);309
assert_eq!(rotation.order()[0], "p3");310
let before = visible(&rotation, 4);311
rotation.update(now, &members, &speak(&["p3"]), &[], 4);312
assert_eq!(visible(&rotation, 4), before);313
}314
315
#[test]316
fn an_outside_speaker_swaps_in_only_after_two_seconds_of_speech() {317
let mut rotation = VisibleRotation::default();318
let start = Instant::now();319
let members = names(6);320
rotation.update(start, &members, &[], &[], 4);321
let outside = "p5";322
rotation.update(start, &members, &[], &speak(&[outside]), 4);323
rotation.update(324
start + Duration::from_millis(1900),325
&members,326
&[],327
&speak(&[outside]),328
4,329
);330
assert!(!visible(&rotation, 4).contains(&outside.to_owned()));331
rotation.update(332
start + SWAP_AFTER_SPEAKING,333
&members,334
&[],335
&speak(&[outside]),336
4,337
);338
assert!(visible(&rotation, 4).contains(&outside.to_owned()));339
}340
341
#[test]342
fn interrupted_speech_restarts_the_two_second_clock() {343
let mut rotation = VisibleRotation::default();344
let start = Instant::now();345
let members = names(6);346
rotation.update(start, &members, &[], &[], 4);347
rotation.update(start, &members, &[], &speak(&["p5"]), 4);348
rotation.update(start + Duration::from_millis(1500), &members, &[], &[], 4);349
rotation.update(350
start + Duration::from_millis(2500),351
&members,352
&[],353
&speak(&["p5"]),354
4,355
);356
rotation.update(357
start + Duration::from_millis(3500),358
&members,359
&[],360
&speak(&["p5"]),361
4,362
);363
assert!(!visible(&rotation, 4).contains(&"p5".to_owned()));364
}365
366
#[test]367
fn the_least_recently_speaking_visible_tile_is_replaced_and_the_others_keep_their_slots() {368
let mut rotation = VisibleRotation::default();369
let start = Instant::now();370
let members = names(6);371
rotation.update(start, &members, &[], &[], 4);372
rotation.update(start, &members, &[], &speak(&["p0", "p1", "p3"]), 4);373
let before = visible(&rotation, 4);374
rotation.update(start, &members, &[], &speak(&["p5", "p0", "p1", "p3"]), 4);375
rotation.update(376
start + SWAP_AFTER_SPEAKING,377
&members,378
&[],379
&speak(&["p5", "p0", "p1", "p3"]),380
4,381
);382
let after = visible(&rotation, 4);383
let slot = before.iter().position(|mri| mri == "p2").unwrap();384
assert_eq!(after[slot], "p5");385
for (index, mri) in before386
.iter()387
.enumerate()388
.filter(|(index, _)| *index != slot)389
{390
assert_eq!(&after[index], mri);391
}392
}393
394
#[test]395
fn at_most_one_speaker_swaps_in_per_five_seconds() {396
let mut rotation = VisibleRotation::default();397
let start = Instant::now();398
let members = names(7);399
rotation.update(start, &members, &[], &[], 4);400
let talking = speak(&["p5", "p6"]);401
rotation.update(start, &members, &[], &talking, 4);402
rotation.update(start + SWAP_AFTER_SPEAKING, &members, &[], &talking, 4);403
let swapped = visible(&rotation, 4)404
.iter()405
.filter(|mri| *mri == "p5" || *mri == "p6")406
.count();407
assert_eq!(swapped, 1);408
rotation.update(409
start + SWAP_AFTER_SPEAKING + Duration::from_secs(4),410
&members,411
&[],412
&talking,413
4,414
);415
let still = visible(&rotation, 4)416
.iter()417
.filter(|mri| *mri == "p5" || *mri == "p6")418
.count();419
assert_eq!(still, 1);420
rotation.update(421
start + SWAP_AFTER_SPEAKING + SWAP_INTERVAL,422
&members,423
&[],424
&talking,425
4,426
);427
let both = visible(&rotation, 4)428
.iter()429
.filter(|mri| *mri == "p5" || *mri == "p6")430
.count();431
assert_eq!(both, 2);432
}433
434
#[test]435
fn a_pinned_person_outside_the_grid_swaps_in_at_once_and_is_never_replaced() {436
let mut rotation = VisibleRotation::default();437
let start = Instant::now();438
let members = names(6);439
rotation.update(start, &members, &[], &[], 4);440
let pinned = speak(&["p5"]);441
rotation.update(start, &members, &pinned, &[], 4);442
assert!(visible(&rotation, 4).contains(&"p5".to_owned()));443
let talking = speak(&["p4"]);444
rotation.update(445
start + Duration::from_secs(1),446
&members,447
&pinned,448
&talking,449
4,450
);451
rotation.update(452
start + Duration::from_secs(4),453
&members,454
&pinned,455
&talking,456
4,457
);458
assert!(visible(&rotation, 4).contains(&"p5".to_owned()));459
}460
461
#[test]462
fn people_who_leave_drop_out_and_the_next_one_moves_up() {463
let mut rotation = VisibleRotation::default();464
let now = Instant::now();465
let members = names(5);466
rotation.update(now, &members, &[], &[], 3);467
let remaining: Vec<String> = members.into_iter().filter(|mri| mri != "p1").collect();468
rotation.update(now, &remaining, &[], &[], 3);469
assert_eq!(visible(&rotation, 3), vec!["p0", "p2", "p3"]);470
}471
}@@ -0,0 +1,277 @@
1
use std::time::{Duration, Instant};
2
3
use gpui_kit::*;
4
5
use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};
6
use super::fullscreen::{FullscreenState, HINT_SHOWN};
7
use super::view_settings::{CallLayout, ViewSettings};
8
use crate::app_state::{AppEvent, AppState};
9
10
const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);
11
const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);
12
const DEMO_BUBBLE_EVERY: Duration = Duration::from_secs(7);
13
const DEMO_BUBBLES: [(&str, &str); 4] = [
14
("Jonas Ortega", "Slides are in the channel now"),
15
(
16
"Priya Nair",
17
"Can you share the release notes with us before we start the demo?",
18
),
19
("Lea Schneider", "Looks good to me, thanks"),
20
("Tobias Klein", "I will join the retro in five minutes"),
21
];
22
const TIMER_SLACK: Duration = Duration::from_millis(30);
23
24
impl AppState {
25
fn change_call_view(&mut self, change: impl FnOnce(&mut ViewSettings), cx: &mut Context<Self>) {
26
change(&mut self.call_view);
27
self.call_view.hide_me = false;
28
self.call_view.save(&self.store);
29
if let Some(call) = self.call.as_mut() {
30
let hide_me = call.model.view.hide_me;
31
call.model.view = self.call_view;
32
call.model.view.hide_me = hide_me;
33
call.model.refresh_layout(Instant::now());
34
}
35
cx.notify();
36
}
37
38
pub fn set_call_layout(&mut self, layout: CallLayout, cx: &mut Context<Self>) {
39
self.change_call_view(|view| view.choose(layout), cx);
40
}
41
42
pub fn toggle_call_hide_no_video(&mut self, cx: &mut Context<Self>) {
43
self.change_call_view(|view| view.hide_no_video = !view.hide_no_video, cx);
44
}
45
46
pub fn toggle_call_chat_bubbles(&mut self, cx: &mut Context<Self>) {
47
self.change_call_view(|view| view.chat_bubbles = !view.chat_bubbles, cx);
48
}
49
50
pub fn set_call_hide_me(&mut self, hidden: bool, cx: &mut Context<Self>) {
51
if let Some(call) = self.call.as_mut() {
52
call.model.view.hide_me = hidden;
53
call.model.refresh_layout(Instant::now());
54
cx.notify();
55
}
56
}
57
58
pub fn tick_call_layout(&mut self, cx: &mut Context<Self>) {
59
let changed = self
60
.call
61
.as_mut()
62
.is_some_and(|call| call.model.refresh_layout(Instant::now()));
63
if changed {
64
cx.notify();
65
}
66
}
67
68
pub fn toggle_call_fullscreen(&mut self, cx: &mut Context<Self>) {
69
let Some(call) = self.call.as_mut().filter(|call| call.viewing) else {
70
return;
71
};
72
call.fullscreen = match call.fullscreen {
73
Some(_) => None,
74
None => Some(FullscreenState::new(Instant::now())),
75
};
76
self.watch_fullscreen_chrome(cx);
77
cx.emit(AppEvent::Call);
78
cx.notify();
79
}
80
81
pub fn escape_call_fullscreen(&mut self, cx: &mut Context<Self>) {
82
if self.stage_fullscreen() {
83
self.leave_stage_fullscreen(cx);
84
return;
85
}
86
let Some(call) = self.call.as_mut().filter(|call| call.fullscreen.is_some()) else {
87
return;
88
};
89
call.fullscreen = None;
90
cx.emit(AppEvent::Call);
91
cx.notify();
92
}
93
94
pub fn call_fullscreen(&self) -> bool {
95
self.call
96
.as_ref()
97
.is_some_and(|call| call.viewing && call.fullscreen.is_some())
98
}
99
100
pub fn touch_call_chrome(&mut self, cx: &mut Context<Self>) {
101
let now = Instant::now();
102
let Some(fullscreen) = self.call.as_mut().and_then(|call| call.fullscreen.as_mut()) else {
103
return;
104
};
105
let was_visible = fullscreen.chrome_visible(now);
106
if was_visible
107
&& now.saturating_duration_since(fullscreen.active_at) < CHROME_TOUCH_THROTTLE
108
{
109
return;
110
}
111
fullscreen.active_at = now;
112
if !was_visible {
113
self.watch_fullscreen_chrome(cx);
114
cx.notify();
115
}
116
}
117
118
pub fn set_call_chrome_hovered(&mut self, hovered: bool, cx: &mut Context<Self>) {
119
let Some(fullscreen) = self
120
.call
121
.as_mut()
122
.and_then(|call| call.fullscreen.as_mut())
123
.filter(|fullscreen| fullscreen.hovered != hovered)
124
else {
125
return;
126
};
127
fullscreen.hovered = hovered;
128
fullscreen.active_at = Instant::now();
129
self.watch_fullscreen_chrome(cx);
130
cx.notify();
131
}
132
133
fn watch_fullscreen_chrome(&mut self, cx: &mut Context<Self>) {
134
let Some(call) = self.call.as_mut() else {
135
return;
136
};
137
let call_id = call.id;
138
let Some(fullscreen) = call
139
.fullscreen
140
.as_mut()
141
.filter(|fullscreen| !fullscreen.timer_running)
142
else {
143
return;
144
};
145
fullscreen.timer_running = true;
146
cx.spawn(async move |this, cx| {
147
while let Ok(Some(wait)) =
148
this.update(cx, |state, cx| state.fullscreen_tick(call_id, cx))
149
{
150
cx.background_executor().timer(wait).await;
151
}
152
})
153
.detach();
154
}
155
156
fn fullscreen_tick(&mut self, call_id: u64, cx: &mut Context<Self>) -> Option<Duration> {
157
cx.notify();
158
let now = Instant::now();
159
let fullscreen = self
160
.call
161
.as_mut()
162
.filter(|call| call.id == call_id)
163
.and_then(|call| call.fullscreen.as_mut())?;
164
let hint_left =
165
HINT_SHOWN.saturating_sub(now.saturating_duration_since(fullscreen.entered));
166
let next = [
167
fullscreen.next_change(now),
168
(!hint_left.is_zero()).then_some(hint_left),
169
]
170
.into_iter()
171
.flatten()
172
.min();
173
if next.is_none() {
174
fullscreen.timer_running = false;
175
}
176
next.map(|wait| wait + TIMER_SLACK)
177
}
178
179
pub fn note_call_chat_message(
180
&mut self,
181
conversation_id: &str,
182
message_id: &str,
183
sender_id: Option<String>,
184
sender_name: &str,
185
text: &str,
186
cx: &mut Context<Self>,
187
) {
188
let Some(call) = self.call.as_mut().filter(|call| {
189
!call.chat_open
190
&& call.model.view.chat_bubbles
191
&& call.chat_thread() == Some(conversation_id)
192
}) else {
193
return;
194
};
195
push_bubble(
196
&mut call.bubbles,
197
ChatBubble {
198
id: message_id.to_owned(),
199
sender_id,
200
name: sender_name.to_owned(),
201
text: text.to_owned(),
202
at: Instant::now(),
203
},
204
);
205
cx.spawn(async move |this, cx| {
206
cx.background_executor()
207
.timer(BUBBLE_SHOWN + TIMER_SLACK)
208
.await;
209
this.update(cx, |_, cx| cx.notify()).ok();
210
})
211
.detach();
212
cx.notify();
213
}
214
215
pub fn set_call_share_menu(&mut self, open: bool, cx: &mut Context<Self>) {
216
if let Some(call) = self.call.as_mut() {
217
call.share_menu_open = open;
218
cx.notify();
219
}
220
}
221
222
pub fn set_call_lobby_list(&mut self, open: bool, cx: &mut Context<Self>) {
223
if let Some(call) = self.call.as_mut() {
224
call.lobby_list_open = open;
225
cx.notify();
226
}
227
}
228
229
pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
230
let Some(call) = self.call.as_ref() else {
231
return;
232
};
233
if call.model.local_share.is_some() {
234
self.stop_call_share(cx);
235
return;
236
}
237
if call.model.can_share() {
238
self.show_call(true, cx);
239
self.set_call_share_menu(true, cx);
240
}
241
}
242
243
pub fn open_call_lobby_list(&mut self, cx: &mut Context<Self>) {
244
let waiting = self
245
.call
246
.as_ref()
247
.is_some_and(|call| call.model.can_admit() && !call.model.lobby_guests().is_empty());
248
if waiting {
249
self.show_call(true, cx);
250
self.set_call_lobby_list(true, cx);
251
}
252
}
253
254
pub(super) fn queue_demo_bubbles(&mut self, thread: &str, cx: &mut Context<Self>) {
255
let thread = thread.to_owned();
256
cx.spawn(async move |this, cx| {
257
cx.background_executor().timer(DEMO_BUBBLE_START).await;
258
for (index, (name, text)) in DEMO_BUBBLES.iter().enumerate() {
259
let sent = this.update(cx, |state, cx| {
260
state.note_call_chat_message(
261
&thread,
262
&format!("demo-bubble-{index}"),
263
Some(format!("demo-guest-{index}")),
264
name,
265
text,
266
cx,
267
)
268
});
269
if sent.is_err() {
270
return;
271
}
272
cx.background_executor().timer(DEMO_BUBBLE_EVERY).await;
273
}
274
})
275
.detach();
276
}
277
}
@@ -0,0 +1,277 @@1
use std::time::{Duration, Instant};2
3
use gpui_kit::*;4
5
use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};6
use super::fullscreen::{FullscreenState, HINT_SHOWN};7
use super::view_settings::{CallLayout, ViewSettings};8
use crate::app_state::{AppEvent, AppState};9
10
const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);11
const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);12
const DEMO_BUBBLE_EVERY: Duration = Duration::from_secs(7);13
const DEMO_BUBBLES: [(&str, &str); 4] = [14
("Jonas Ortega", "Slides are in the channel now"),15
(16
"Priya Nair",17
"Can you share the release notes with us before we start the demo?",18
),19
("Lea Schneider", "Looks good to me, thanks"),20
("Tobias Klein", "I will join the retro in five minutes"),21
];22
const TIMER_SLACK: Duration = Duration::from_millis(30);23
24
impl AppState {25
fn change_call_view(&mut self, change: impl FnOnce(&mut ViewSettings), cx: &mut Context<Self>) {26
change(&mut self.call_view);27
self.call_view.hide_me = false;28
self.call_view.save(&self.store);29
if let Some(call) = self.call.as_mut() {30
let hide_me = call.model.view.hide_me;31
call.model.view = self.call_view;32
call.model.view.hide_me = hide_me;33
call.model.refresh_layout(Instant::now());34
}35
cx.notify();36
}37
38
pub fn set_call_layout(&mut self, layout: CallLayout, cx: &mut Context<Self>) {39
self.change_call_view(|view| view.choose(layout), cx);40
}41
42
pub fn toggle_call_hide_no_video(&mut self, cx: &mut Context<Self>) {43
self.change_call_view(|view| view.hide_no_video = !view.hide_no_video, cx);44
}45
46
pub fn toggle_call_chat_bubbles(&mut self, cx: &mut Context<Self>) {47
self.change_call_view(|view| view.chat_bubbles = !view.chat_bubbles, cx);48
}49
50
pub fn set_call_hide_me(&mut self, hidden: bool, cx: &mut Context<Self>) {51
if let Some(call) = self.call.as_mut() {52
call.model.view.hide_me = hidden;53
call.model.refresh_layout(Instant::now());54
cx.notify();55
}56
}57
58
pub fn tick_call_layout(&mut self, cx: &mut Context<Self>) {59
let changed = self60
.call61
.as_mut()62
.is_some_and(|call| call.model.refresh_layout(Instant::now()));63
if changed {64
cx.notify();65
}66
}67
68
pub fn toggle_call_fullscreen(&mut self, cx: &mut Context<Self>) {69
let Some(call) = self.call.as_mut().filter(|call| call.viewing) else {70
return;71
};72
call.fullscreen = match call.fullscreen {73
Some(_) => None,74
None => Some(FullscreenState::new(Instant::now())),75
};76
self.watch_fullscreen_chrome(cx);77
cx.emit(AppEvent::Call);78
cx.notify();79
}80
81
pub fn escape_call_fullscreen(&mut self, cx: &mut Context<Self>) {82
if self.stage_fullscreen() {83
self.leave_stage_fullscreen(cx);84
return;85
}86
let Some(call) = self.call.as_mut().filter(|call| call.fullscreen.is_some()) else {87
return;88
};89
call.fullscreen = None;90
cx.emit(AppEvent::Call);91
cx.notify();92
}93
94
pub fn call_fullscreen(&self) -> bool {95
self.call96
.as_ref()97
.is_some_and(|call| call.viewing && call.fullscreen.is_some())98
}99
100
pub fn touch_call_chrome(&mut self, cx: &mut Context<Self>) {101
let now = Instant::now();102
let Some(fullscreen) = self.call.as_mut().and_then(|call| call.fullscreen.as_mut()) else {103
return;104
};105
let was_visible = fullscreen.chrome_visible(now);106
if was_visible107
&& now.saturating_duration_since(fullscreen.active_at) < CHROME_TOUCH_THROTTLE108
{109
return;110
}111
fullscreen.active_at = now;112
if !was_visible {113
self.watch_fullscreen_chrome(cx);114
cx.notify();115
}116
}117
118
pub fn set_call_chrome_hovered(&mut self, hovered: bool, cx: &mut Context<Self>) {119
let Some(fullscreen) = self120
.call121
.as_mut()122
.and_then(|call| call.fullscreen.as_mut())123
.filter(|fullscreen| fullscreen.hovered != hovered)124
else {125
return;126
};127
fullscreen.hovered = hovered;128
fullscreen.active_at = Instant::now();129
self.watch_fullscreen_chrome(cx);130
cx.notify();131
}132
133
fn watch_fullscreen_chrome(&mut self, cx: &mut Context<Self>) {134
let Some(call) = self.call.as_mut() else {135
return;136
};137
let call_id = call.id;138
let Some(fullscreen) = call139
.fullscreen140
.as_mut()141
.filter(|fullscreen| !fullscreen.timer_running)142
else {143
return;144
};145
fullscreen.timer_running = true;146
cx.spawn(async move |this, cx| {147
while let Ok(Some(wait)) =148
this.update(cx, |state, cx| state.fullscreen_tick(call_id, cx))149
{150
cx.background_executor().timer(wait).await;151
}152
})153
.detach();154
}155
156
fn fullscreen_tick(&mut self, call_id: u64, cx: &mut Context<Self>) -> Option<Duration> {157
cx.notify();158
let now = Instant::now();159
let fullscreen = self160
.call161
.as_mut()162
.filter(|call| call.id == call_id)163
.and_then(|call| call.fullscreen.as_mut())?;164
let hint_left =165
HINT_SHOWN.saturating_sub(now.saturating_duration_since(fullscreen.entered));166
let next = [167
fullscreen.next_change(now),168
(!hint_left.is_zero()).then_some(hint_left),169
]170
.into_iter()171
.flatten()172
.min();173
if next.is_none() {174
fullscreen.timer_running = false;175
}176
next.map(|wait| wait + TIMER_SLACK)177
}178
179
pub fn note_call_chat_message(180
&mut self,181
conversation_id: &str,182
message_id: &str,183
sender_id: Option<String>,184
sender_name: &str,185
text: &str,186
cx: &mut Context<Self>,187
) {188
let Some(call) = self.call.as_mut().filter(|call| {189
!call.chat_open190
&& call.model.view.chat_bubbles191
&& call.chat_thread() == Some(conversation_id)192
}) else {193
return;194
};195
push_bubble(196
&mut call.bubbles,197
ChatBubble {198
id: message_id.to_owned(),199
sender_id,200
name: sender_name.to_owned(),201
text: text.to_owned(),202
at: Instant::now(),203
},204
);205
cx.spawn(async move |this, cx| {206
cx.background_executor()207
.timer(BUBBLE_SHOWN + TIMER_SLACK)208
.await;209
this.update(cx, |_, cx| cx.notify()).ok();210
})211
.detach();212
cx.notify();213
}214
215
pub fn set_call_share_menu(&mut self, open: bool, cx: &mut Context<Self>) {216
if let Some(call) = self.call.as_mut() {217
call.share_menu_open = open;218
cx.notify();219
}220
}221
222
pub fn set_call_lobby_list(&mut self, open: bool, cx: &mut Context<Self>) {223
if let Some(call) = self.call.as_mut() {224
call.lobby_list_open = open;225
cx.notify();226
}227
}228
229
pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {230
let Some(call) = self.call.as_ref() else {231
return;232
};233
if call.model.local_share.is_some() {234
self.stop_call_share(cx);235
return;236
}237
if call.model.can_share() {238
self.show_call(true, cx);239
self.set_call_share_menu(true, cx);240
}241
}242
243
pub fn open_call_lobby_list(&mut self, cx: &mut Context<Self>) {244
let waiting = self245
.call246
.as_ref()247
.is_some_and(|call| call.model.can_admit() && !call.model.lobby_guests().is_empty());248
if waiting {249
self.show_call(true, cx);250
self.set_call_lobby_list(true, cx);251
}252
}253
254
pub(super) fn queue_demo_bubbles(&mut self, thread: &str, cx: &mut Context<Self>) {255
let thread = thread.to_owned();256
cx.spawn(async move |this, cx| {257
cx.background_executor().timer(DEMO_BUBBLE_START).await;258
for (index, (name, text)) in DEMO_BUBBLES.iter().enumerate() {259
let sent = this.update(cx, |state, cx| {260
state.note_call_chat_message(261
&thread,262
&format!("demo-bubble-{index}"),263
Some(format!("demo-guest-{index}")),264
name,265
text,266
cx,267
)268
});269
if sent.is_err() {270
return;271
}272
cx.background_executor().timer(DEMO_BUBBLE_EVERY).await;273
}274
})275
.detach();276
}277
}@@ -0,0 +1,139 @@
1
const LAYOUT_META_KEY: &str = "call_layout";
2
const HIDE_NO_VIDEO_META_KEY: &str = "call_hide_no_video";
3
const CHAT_BUBBLES_META_KEY: &str = "call_chat_bubbles";
4
5
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6
pub enum CallLayout {
7
#[default]
8
Gallery,
9
Speaker,
10
Content,
11
}
12
13
impl CallLayout {
14
pub fn label(self) -> &'static str {
15
match self {
16
CallLayout::Gallery => "Gallery",
17
CallLayout::Speaker => "Speaker",
18
CallLayout::Content => "Focus on content",
19
}
20
}
21
22
fn meta(self) -> &'static str {
23
match self {
24
CallLayout::Gallery => "gallery",
25
CallLayout::Speaker => "speaker",
26
CallLayout::Content => "content",
27
}
28
}
29
30
fn from_meta(value: &str) -> CallLayout {
31
match value {
32
"speaker" => CallLayout::Speaker,
33
"content" => CallLayout::Content,
34
_ => CallLayout::Gallery,
35
}
36
}
37
}
38
39
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40
pub struct ViewSettings {
41
pub layout: CallLayout,
42
pub layout_before_content: CallLayout,
43
pub hide_no_video: bool,
44
pub chat_bubbles: bool,
45
pub hide_me: bool,
46
}
47
48
impl Default for ViewSettings {
49
fn default() -> Self {
50
ViewSettings {
51
layout: CallLayout::Gallery,
52
layout_before_content: CallLayout::Gallery,
53
hide_no_video: false,
54
chat_bubbles: true,
55
hide_me: false,
56
}
57
}
58
}
59
60
impl ViewSettings {
61
pub fn load(store: &store::Store) -> ViewSettings {
62
let flag = |key: &str, default: bool| match store.meta(key).ok().flatten().as_deref() {
63
Some("1") => true,
64
Some("0") => false,
65
_ => default,
66
};
67
let layout = store
68
.meta(LAYOUT_META_KEY)
69
.ok()
70
.flatten()
71
.map_or(CallLayout::Gallery, |value| CallLayout::from_meta(&value));
72
ViewSettings {
73
layout,
74
hide_no_video: flag(HIDE_NO_VIDEO_META_KEY, false),
75
chat_bubbles: flag(CHAT_BUBBLES_META_KEY, true),
76
..ViewSettings::default()
77
}
78
}
79
80
pub fn save(&self, store: &store::Store) {
81
let _ = store.set_meta(LAYOUT_META_KEY, self.layout.meta());
82
let _ = store.set_meta(
83
HIDE_NO_VIDEO_META_KEY,
84
if self.hide_no_video { "1" } else { "0" },
85
);
86
let _ = store.set_meta(
87
CHAT_BUBBLES_META_KEY,
88
if self.chat_bubbles { "1" } else { "0" },
89
);
90
}
91
92
pub fn choose(&mut self, layout: CallLayout) {
93
if layout == CallLayout::Content && self.layout != CallLayout::Content {
94
self.layout_before_content = self.layout;
95
}
96
self.layout = layout;
97
}
98
}
99
100
#[cfg(test)]
101
mod tests {
102
use super::*;
103
104
#[test]
105
fn the_defaults_are_gallery_with_bubbles_on() {
106
let store = store::Store::open_in_memory().unwrap();
107
let settings = ViewSettings::load(&store);
108
assert_eq!(settings.layout, CallLayout::Gallery);
109
assert!(settings.chat_bubbles);
110
assert!(!settings.hide_no_video);
111
assert!(!settings.hide_me);
112
}
113
114
#[test]
115
fn choices_survive_a_restart() {
116
let store = store::Store::open_in_memory().unwrap();
117
let mut settings = ViewSettings::load(&store);
118
settings.choose(CallLayout::Speaker);
119
settings.hide_no_video = true;
120
settings.chat_bubbles = false;
121
settings.hide_me = true;
122
settings.save(&store);
123
let loaded = ViewSettings::load(&store);
124
assert_eq!(loaded.layout, CallLayout::Speaker);
125
assert!(loaded.hide_no_video);
126
assert!(!loaded.chat_bubbles);
127
assert!(!loaded.hide_me);
128
}
129
130
#[test]
131
fn content_remembers_the_layout_to_fall_back_to() {
132
let mut settings = ViewSettings::default();
133
settings.choose(CallLayout::Speaker);
134
settings.choose(CallLayout::Content);
135
assert_eq!(settings.layout_before_content, CallLayout::Speaker);
136
settings.choose(CallLayout::Content);
137
assert_eq!(settings.layout_before_content, CallLayout::Speaker);
138
}
139
}
@@ -0,0 +1,139 @@1
const LAYOUT_META_KEY: &str = "call_layout";2
const HIDE_NO_VIDEO_META_KEY: &str = "call_hide_no_video";3
const CHAT_BUBBLES_META_KEY: &str = "call_chat_bubbles";4
5
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]6
pub enum CallLayout {7
#[default]8
Gallery,9
Speaker,10
Content,11
}12
13
impl CallLayout {14
pub fn label(self) -> &'static str {15
match self {16
CallLayout::Gallery => "Gallery",17
CallLayout::Speaker => "Speaker",18
CallLayout::Content => "Focus on content",19
}20
}21
22
fn meta(self) -> &'static str {23
match self {24
CallLayout::Gallery => "gallery",25
CallLayout::Speaker => "speaker",26
CallLayout::Content => "content",27
}28
}29
30
fn from_meta(value: &str) -> CallLayout {31
match value {32
"speaker" => CallLayout::Speaker,33
"content" => CallLayout::Content,34
_ => CallLayout::Gallery,35
}36
}37
}38
39
#[derive(Debug, Clone, Copy, PartialEq, Eq)]40
pub struct ViewSettings {41
pub layout: CallLayout,42
pub layout_before_content: CallLayout,43
pub hide_no_video: bool,44
pub chat_bubbles: bool,45
pub hide_me: bool,46
}47
48
impl Default for ViewSettings {49
fn default() -> Self {50
ViewSettings {51
layout: CallLayout::Gallery,52
layout_before_content: CallLayout::Gallery,53
hide_no_video: false,54
chat_bubbles: true,55
hide_me: false,56
}57
}58
}59
60
impl ViewSettings {61
pub fn load(store: &store::Store) -> ViewSettings {62
let flag = |key: &str, default: bool| match store.meta(key).ok().flatten().as_deref() {63
Some("1") => true,64
Some("0") => false,65
_ => default,66
};67
let layout = store68
.meta(LAYOUT_META_KEY)69
.ok()70
.flatten()71
.map_or(CallLayout::Gallery, |value| CallLayout::from_meta(&value));72
ViewSettings {73
layout,74
hide_no_video: flag(HIDE_NO_VIDEO_META_KEY, false),75
chat_bubbles: flag(CHAT_BUBBLES_META_KEY, true),76
..ViewSettings::default()77
}78
}79
80
pub fn save(&self, store: &store::Store) {81
let _ = store.set_meta(LAYOUT_META_KEY, self.layout.meta());82
let _ = store.set_meta(83
HIDE_NO_VIDEO_META_KEY,84
if self.hide_no_video { "1" } else { "0" },85
);86
let _ = store.set_meta(87
CHAT_BUBBLES_META_KEY,88
if self.chat_bubbles { "1" } else { "0" },89
);90
}91
92
pub fn choose(&mut self, layout: CallLayout) {93
if layout == CallLayout::Content && self.layout != CallLayout::Content {94
self.layout_before_content = self.layout;95
}96
self.layout = layout;97
}98
}99
100
#[cfg(test)]101
mod tests {102
use super::*;103
104
#[test]105
fn the_defaults_are_gallery_with_bubbles_on() {106
let store = store::Store::open_in_memory().unwrap();107
let settings = ViewSettings::load(&store);108
assert_eq!(settings.layout, CallLayout::Gallery);109
assert!(settings.chat_bubbles);110
assert!(!settings.hide_no_video);111
assert!(!settings.hide_me);112
}113
114
#[test]115
fn choices_survive_a_restart() {116
let store = store::Store::open_in_memory().unwrap();117
let mut settings = ViewSettings::load(&store);118
settings.choose(CallLayout::Speaker);119
settings.hide_no_video = true;120
settings.chat_bubbles = false;121
settings.hide_me = true;122
settings.save(&store);123
let loaded = ViewSettings::load(&store);124
assert_eq!(loaded.layout, CallLayout::Speaker);125
assert!(loaded.hide_no_video);126
assert!(!loaded.chat_bubbles);127
assert!(!loaded.hide_me);128
}129
130
#[test]131
fn content_remembers_the_layout_to_fall_back_to() {132
let mut settings = ViewSettings::default();133
settings.choose(CallLayout::Speaker);134
settings.choose(CallLayout::Content);135
assert_eq!(settings.layout_before_content, CallLayout::Speaker);136
settings.choose(CallLayout::Content);137
assert_eq!(settings.layout_before_content, CallLayout::Speaker);138
}139
}@@ -120,7 +120,13 @@ mod frames {
120
120
};
121
121
use store::Store;
122
122
123
use std::time::Instant;
124
125
use calling::{CallState, CallUpdate, RosterEntry, call_channel};
126
use gpui_kit::Entity;
127
123
128
use crate::app_state::{AppState, Mode};
129
use crate::call::{ActiveCall, CallModel};
124
130
use crate::demo;
125
131
use crate::user_activity::UserInput;
126
132
use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};
@@ -138,6 +144,11 @@ mod frames {
138
144
"shell/islands/main",
139
145
"shell/status-bar",
140
146
];
147
const CALL_GUARDED: &[&str] = &[
148
"shell/islands/main/call-header",
149
"shell/islands/main/call-stage",
150
"shell/islands/main/call-controls",
151
];
141
152
const MENU: &str = "popup-menu";
142
153
const OWN_STATUS: &str = "shell/title-bar/own-status";
143
154
const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];
@@ -149,6 +160,7 @@ mod frames {
149
160
enum Screen {
150
161
Tab(&'static str, Option<fn(&mut VisualTestContext)>),
151
162
StatusMenu,
163
Call,
152
164
}
153
165
154
166
fn parent_of(path: &str) -> Option<&str> {
@@ -263,12 +275,37 @@ mod frames {
263
275
}
264
276
GUARDED
265
277
.iter()
278
.chain(CALL_GUARDED)
266
279
.chain([&MENU])
267
280
.filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
268
281
.collect()
269
282
}
270
283
271
fn mount(cx: &mut TestAppContext) -> gpui_kit::AnyWindowHandle {
284
fn gallery_call() -> ActiveCall {
285
let (handle, _control) = call_channel();
286
let mut model = CallModel::meeting("Standup", false);
287
model.apply(CallUpdate::State(CallState::Connected {
288
since: Instant::now(),
289
}));
290
model.apply(CallUpdate::Roster(
291
(0..11)
292
.map(|index| RosterEntry {
293
mri: format!("8:orgid:guard-{index}"),
294
display_name: format!("Guest {index}"),
295
muted: false,
296
in_lobby: false,
297
has_video: false,
298
sharing: false,
299
hand: None,
300
spotlight: None,
301
organizer: false,
302
})
303
.collect(),
304
));
305
ActiveCall::new(1, model, handle.commands, None, handle.video)
306
}
307
308
fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
272
309
cx.update(gpui_kit::init);
273
310
cx.update(|cx| {
274
311
crate::theme::apply(cx);
@@ -283,16 +320,18 @@ mod frames {
283
320
let state = cx.new(|_| AppState::new(Arc::new(store), mode));
284
321
install_globals(&state, UserInput::new(), cx);
285
322
demo::start_session(&state, cx);
323
let shared_state = state.clone();
286
324
let startup = Startup {
287
325
switcher_query: None,
288
326
composer_text: None,
289
327
reply_to_last: false,
290
328
};
291
gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
329
let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
292
330
cx.new(|cx| AppShell::new(state, None, startup, window, cx))
293
331
})
294
332
.expect("open test window")
295
.0
333
.0;
334
(window, shared_state)
296
335
})
297
336
}
298
337
@@ -329,7 +368,7 @@ mod frames {
329
368
330
369
#[gpui_kit::test]
331
370
fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
332
let handle = mount(cx);
371
let (handle, app) = mount(cx);
333
372
let mut visual = VisualTestContext::from_window(handle, cx);
334
373
let mut seen_known = HashSet::new();
335
374
let mut unexpected = Vec::new();
@@ -352,6 +391,7 @@ mod frames {
352
391
Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
353
392
Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
354
393
Screen::StatusMenu,
394
Screen::Call,
355
395
];
356
396
for screen in screens {
357
397
let (screen_name, status_menu) = match screen {
@@ -361,6 +401,15 @@ mod frames {
361
401
}
362
402
(name, false)
363
403
}
404
Screen::Call => {
405
visual.update(|_, cx| {
406
app.update(cx, |state, cx| {
407
state.call = Some(gallery_call());
408
cx.notify();
409
})
410
});
411
("call", false)
412
}
364
413
Screen::StatusMenu => {
365
414
let tags = collect(&mut visual, None);
366
415
let button = tags
@@ -374,6 +423,9 @@ mod frames {
374
423
};
375
424
let tags = collect(&mut visual, status_menu.then_some(MENU));
376
425
let mut expected = GUARDED.to_vec();
426
if screen_name == "call" {
427
expected.extend(CALL_GUARDED);
428
}
377
429
if status_menu {
378
430
expected.push(MENU);
379
431
}
@@ -402,6 +454,14 @@ mod frames {
402
454
visual.simulate_keystrokes("escape");
403
455
visual.run_until_parked();
404
456
}
457
if screen_name == "call" {
458
visual.update(|_, cx| {
459
app.update(cx, |state, cx| {
460
state.call = None;
461
cx.notify();
462
})
463
});
464
}
405
465
for (key, message) in found {
406
466
let full_key = format!("{screen_name}@{width}x{height}:{key}");
407
467
if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
@@ -120,7 +120,13 @@ mod frames {120
};120
};121
use store::Store;121
use store::Store;122
122
123
use std::time::Instant;124
125
use calling::{CallState, CallUpdate, RosterEntry, call_channel};126
use gpui_kit::Entity;127
123
use crate::app_state::{AppState, Mode};128
use crate::app_state::{AppState, Mode};129
use crate::call::{ActiveCall, CallModel};124
use crate::demo;130
use crate::demo;125
use crate::user_activity::UserInput;131
use crate::user_activity::UserInput;126
use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};132
use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};@@ -138,6 +144,11 @@ mod frames {138
"shell/islands/main",144
"shell/islands/main",139
"shell/status-bar",145
"shell/status-bar",140
];146
];147
const CALL_GUARDED: &[&str] = &[148
"shell/islands/main/call-header",149
"shell/islands/main/call-stage",150
"shell/islands/main/call-controls",151
];141
const MENU: &str = "popup-menu";152
const MENU: &str = "popup-menu";142
const OWN_STATUS: &str = "shell/title-bar/own-status";153
const OWN_STATUS: &str = "shell/title-bar/own-status";143
const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];154
const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];@@ -149,6 +160,7 @@ mod frames {149
enum Screen {160
enum Screen {150
Tab(&'static str, Option<fn(&mut VisualTestContext)>),161
Tab(&'static str, Option<fn(&mut VisualTestContext)>),151
StatusMenu,162
StatusMenu,163
Call,152
}164
}153
165
154
fn parent_of(path: &str) -> Option<&str> {166
fn parent_of(path: &str) -> Option<&str> {@@ -263,12 +275,37 @@ mod frames {263
}275
}264
GUARDED276
GUARDED265
.iter()277
.iter()278
.chain(CALL_GUARDED)266
.chain([&MENU])279
.chain([&MENU])267
.filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))280
.filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))268
.collect()281
.collect()269
}282
}270
283
271
fn mount(cx: &mut TestAppContext) -> gpui_kit::AnyWindowHandle {284
fn gallery_call() -> ActiveCall {285
let (handle, _control) = call_channel();286
let mut model = CallModel::meeting("Standup", false);287
model.apply(CallUpdate::State(CallState::Connected {288
since: Instant::now(),289
}));290
model.apply(CallUpdate::Roster(291
(0..11)292
.map(|index| RosterEntry {293
mri: format!("8:orgid:guard-{index}"),294
display_name: format!("Guest {index}"),295
muted: false,296
in_lobby: false,297
has_video: false,298
sharing: false,299
hand: None,300
spotlight: None,301
organizer: false,302
})303
.collect(),304
));305
ActiveCall::new(1, model, handle.commands, None, handle.video)306
}307
308
fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {272
cx.update(gpui_kit::init);309
cx.update(gpui_kit::init);273
cx.update(|cx| {310
cx.update(|cx| {274
crate::theme::apply(cx);311
crate::theme::apply(cx);@@ -283,16 +320,18 @@ mod frames {283
let state = cx.new(|_| AppState::new(Arc::new(store), mode));320
let state = cx.new(|_| AppState::new(Arc::new(store), mode));284
install_globals(&state, UserInput::new(), cx);321
install_globals(&state, UserInput::new(), cx);285
demo::start_session(&state, cx);322
demo::start_session(&state, cx);323
let shared_state = state.clone();286
let startup = Startup {324
let startup = Startup {287
switcher_query: None,325
switcher_query: None,288
composer_text: None,326
composer_text: None,289
reply_to_last: false,327
reply_to_last: false,290
};328
};291
gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {329
let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {292
cx.new(|cx| AppShell::new(state, None, startup, window, cx))330
cx.new(|cx| AppShell::new(state, None, startup, window, cx))293
})331
})294
.expect("open test window")332
.expect("open test window")295
.0333
.0;334
(window, shared_state)296
})335
})297
}336
}298
337
@@ -329,7 +368,7 @@ mod frames {329
368
330
#[gpui_kit::test]369
#[gpui_kit::test]331
fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {370
fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {332
let handle = mount(cx);371
let (handle, app) = mount(cx);333
let mut visual = VisualTestContext::from_window(handle, cx);372
let mut visual = VisualTestContext::from_window(handle, cx);334
let mut seen_known = HashSet::new();373
let mut seen_known = HashSet::new();335
let mut unexpected = Vec::new();374
let mut unexpected = Vec::new();@@ -352,6 +391,7 @@ mod frames {352
Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),391
Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),353
Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),392
Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),354
Screen::StatusMenu,393
Screen::StatusMenu,394
Screen::Call,355
];395
];356
for screen in screens {396
for screen in screens {357
let (screen_name, status_menu) = match screen {397
let (screen_name, status_menu) = match screen {@@ -361,6 +401,15 @@ mod frames {361
}401
}362
(name, false)402
(name, false)363
}403
}404
Screen::Call => {405
visual.update(|_, cx| {406
app.update(cx, |state, cx| {407
state.call = Some(gallery_call());408
cx.notify();409
})410
});411
("call", false)412
}364
Screen::StatusMenu => {413
Screen::StatusMenu => {365
let tags = collect(&mut visual, None);414
let tags = collect(&mut visual, None);366
let button = tags415
let button = tags@@ -374,6 +423,9 @@ mod frames {374
};423
};375
let tags = collect(&mut visual, status_menu.then_some(MENU));424
let tags = collect(&mut visual, status_menu.then_some(MENU));376
let mut expected = GUARDED.to_vec();425
let mut expected = GUARDED.to_vec();426
if screen_name == "call" {427
expected.extend(CALL_GUARDED);428
}377
if status_menu {429
if status_menu {378
expected.push(MENU);430
expected.push(MENU);379
}431
}@@ -402,6 +454,14 @@ mod frames {402
visual.simulate_keystrokes("escape");454
visual.simulate_keystrokes("escape");403
visual.run_until_parked();455
visual.run_until_parked();404
}456
}457
if screen_name == "call" {458
visual.update(|_, cx| {459
app.update(cx, |state, cx| {460
state.call = None;461
cx.notify();462
})463
});464
}405
for (key, message) in found {465
for (key, message) in found {406
let full_key = format!("{screen_name}@{width}x{height}:{key}");466
let full_key = format!("{screen_name}@{width}x{height}:{key}");407
if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {467
if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {@@ -302,6 +302,20 @@ impl NotificationCenter {
302
302
}
303
303
304
304
pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
305
let bubble_text = match &incoming.preview {
306
Preview::Text(text) => text.replace('\n', " "),
307
Preview::Image => "Sent a picture".to_owned(),
308
};
309
self.app.update(cx, |state, cx| {
310
state.note_call_chat_message(
311
&incoming.conversation_id,
312
&incoming.message_id,
313
incoming.sender_id.clone(),
314
&incoming.sender_name,
315
&bubble_text,
316
cx,
317
)
318
});
305
319
let environment = self.environment(&incoming.conversation_id, cx);
306
320
if !environment.chat_in_foreground && incoming.mentions_me {
307
321
self.unread_mentions
@@ -302,6 +302,20 @@ impl NotificationCenter {302
}302
}303
303
304
pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {304
pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {305
let bubble_text = match &incoming.preview {306
Preview::Text(text) => text.replace('\n', " "),307
Preview::Image => "Sent a picture".to_owned(),308
};309
self.app.update(cx, |state, cx| {310
state.note_call_chat_message(311
&incoming.conversation_id,312
&incoming.message_id,313
incoming.sender_id.clone(),314
&incoming.sender_name,315
&bubble_text,316
cx,317
)318
});305
let environment = self.environment(&incoming.conversation_id, cx);319
let environment = self.environment(&incoming.conversation_id, cx);306
if !environment.chat_in_foreground && incoming.mentions_me {320
if !environment.chat_in_foreground && incoming.mentions_me {307
self.unread_mentions321
self.unread_mentions@@ -0,0 +1,559 @@
1
use std::time::Instant;
2
3
use gpui_kit::assets::IconName;
4
use gpui_kit::component::{
5
button::{Button, ButtonVariants as _},
6
h_flex,
7
popover::Popover,
8
tooltip::Tooltip,
9
v_flex,
10
};
11
use gpui_kit::prelude::FluentBuilder as _;
12
use gpui_kit::*;
13
14
use super::avatar::person_avatar;
15
use super::call_organizer::render_focus_stage;
16
use super::call_view::{
17
GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
18
};
19
use super::widgets::icon;
20
use crate::app_state::AppState;
21
use crate::call::{
22
ActiveCall, CallLayout, CallModel, GALLERY_MAX, Tile, TileSize, filmstrip, gallery_grid,
23
shown_bubbles, split_overflow,
24
};
25
use crate::theme;
26
27
const FALLBACK_STAGE: (f32, f32) = (900., 560.);
28
const MEASURE_TOLERANCE: f32 = 0.5;
29
const OVERLAY_INSET: f32 = 16.;
30
const CHIP_TOP: f32 = 12.;
31
const FILMSTRIP_TILE_MAX: f32 = 220.;
32
const TILE_RADIUS: f32 = 12.;
33
const HIDDEN_LIST_WIDTH: f32 = 260.;
34
const HIDDEN_LIST_HEIGHT: f32 = 320.;
35
const HIDDEN_AVATAR: f32 = 28.;
36
const STACK_MAX: usize = 3;
37
const STACK_OVERLAP: f32 = 0.35;
38
const BUBBLE_WIDTH: f32 = 340.;
39
const BUBBLE_AVATAR: f32 = 28.;
40
const BUBBLE_GAP: f32 = 8.;
41
const BUBBLE_FADE_FROM: f32 = 0.9;
42
const BUBBLE_BACKGROUND: f32 = 0.72;
43
const CHIP_BACKGROUND: f32 = 0.6;
44
pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";
45
46
fn measured_stage(call: &ActiveCall) -> (f32, f32) {
47
let (width, height) = call.stage_size.get();
48
if width < 1. || height < 1. {
49
return FALLBACK_STAGE;
50
}
51
(width, height)
52
}
53
54
fn measure_stage(call: &ActiveCall) -> impl IntoElement {
55
let stage_size = call.stage_size.clone();
56
canvas(
57
|_, _, _| {},
58
move |bounds, _, window, _| {
59
let measured = (f32::from(bounds.size.width), f32::from(bounds.size.height));
60
let known = stage_size.get();
61
if (known.0 - measured.0).abs() > MEASURE_TOLERANCE
62
|| (known.1 - measured.1).abs() > MEASURE_TOLERANCE
63
{
64
stage_size.set(measured);
65
window.refresh();
66
}
67
},
68
)
69
.absolute()
70
.size_full()
71
}
72
73
fn dark_chip() -> Div {
74
h_flex()
75
.h(px(30.))
76
.px(px(12.))
77
.gap(px(8.))
78
.items_center()
79
.rounded_full()
80
.bg(hsla(0., 0., 0., CHIP_BACKGROUND))
81
.text_color(theme::white())
82
.text_size(px(13.))
83
.font_weight(FontWeight::SEMIBOLD)
84
}
85
86
fn without_video_chip(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
87
let count = model.hidden_without_video();
88
if !model.view.hide_no_video || count == 0 {
89
return None;
90
}
91
let app = app.clone();
92
Some(
93
div()
94
.absolute()
95
.top(px(CHIP_TOP))
96
.left_0()
97
.right_0()
98
.flex()
99
.justify_center()
100
.child(
101
dark_chip()
102
.id("call-no-video-chip")
103
.cursor_pointer()
104
.hover(|chip| chip.opacity(0.85))
105
.tooltip(|window, cx| {
106
Tooltip::new("Show people without video").build(window, cx)
107
})
108
.child(icon(IconName::VideoOff, 15., theme::white()))
109
.child(format!("{count} without video"))
110
.on_click(move |_, _, cx| {
111
app.update(cx, |state, cx| state.toggle_call_hide_no_video(cx))
112
}),
113
)
114
.into_any_element(),
115
)
116
}
117
118
fn show_me_pill(app: &Entity<AppState>, model: &CallModel, bottom: f32) -> Option<AnyElement> {
119
if !model.view.hide_me {
120
return None;
121
}
122
let app = app.clone();
123
Some(
124
div()
125
.absolute()
126
.right(px(OVERLAY_INSET))
127
.bottom(px(bottom))
128
.child(
129
dark_chip()
130
.id("call-show-me")
131
.cursor_pointer()
132
.hover(|chip| chip.opacity(0.85))
133
.tooltip(|window, cx| Tooltip::new("Show me").build(window, cx))
134
.child(icon(IconName::Eye, 15., theme::white()))
135
.child("You")
136
.on_click(move |_, _, cx| {
137
app.update(cx, |state, cx| state.set_call_hide_me(false, cx))
138
}),
139
)
140
.into_any_element(),
141
)
142
}
143
144
fn chat_bubbles(
145
app: &Entity<AppState>,
146
state: &AppState,
147
call: &ActiveCall,
148
now: Instant,
149
bottom: f32,
150
) -> Option<AnyElement> {
151
if call.chat_open || !call.model.view.chat_bubbles {
152
return None;
153
}
154
let bubbles = shown_bubbles(&call.bubbles, now);
155
if bubbles.is_empty() {
156
return None;
157
}
158
let shown = crate::call::BUBBLE_SHOWN;
159
Some(
160
v_flex()
161
.absolute()
162
.left(px(OVERLAY_INSET))
163
.bottom(px(bottom))
164
.gap(px(BUBBLE_GAP))
165
.children(bubbles.into_iter().map(|bubble| {
166
let app = app.clone();
167
let id = SharedString::from(format!("call-bubble-{}", bubble.id));
168
h_flex()
169
.id(id.clone())
170
.max_w(px(BUBBLE_WIDTH))
171
.pl(px(6.))
172
.pr(px(14.))
173
.py(px(6.))
174
.gap(px(8.))
175
.items_center()
176
.rounded_full()
177
.bg(hsla(0., 0., 0., BUBBLE_BACKGROUND))
178
.text_color(theme::white())
179
.text_size(px(13.))
180
.cursor_pointer()
181
.child(person_avatar(
182
&state.directory,
183
bubble.sender_id.as_deref(),
184
&bubble.name,
185
BUBBLE_AVATAR,
186
))
187
.child(
188
h_flex()
189
.min_w_0()
190
.flex_1()
191
.gap(px(6.))
192
.child(
193
div()
194
.flex_none()
195
.font_weight(FontWeight::BOLD)
196
.child(bubble.name.clone()),
197
)
198
.child(div().min_w_0().truncate().child(bubble.text.clone())),
199
)
200
.on_click(move |_, _, cx| {
201
app.update(cx, |state, cx| {
202
if state.call_chat_thread().is_none() {
203
state.toggle_call_chat(cx);
204
}
205
})
206
})
207
.with_animation(id, Animation::new(shown), |bubble, delta| {
208
let fade =
209
((delta - BUBBLE_FADE_FROM) / (1. - BUBBLE_FADE_FROM)).clamp(0., 1.);
210
bubble.opacity(1. - fade)
211
})
212
}))
213
.into_any_element(),
214
)
215
}
216
217
fn fullscreen_hint(call: &ActiveCall, now: Instant, bottom: f32) -> Option<AnyElement> {
218
call.fullscreen
219
.filter(|fullscreen| fullscreen.hint_visible(now))
220
.map(|_| {
221
div()
222
.absolute()
223
.left_0()
224
.right_0()
225
.bottom(px(bottom))
226
.flex()
227
.justify_center()
228
.child(dark_chip().h(px(32.)).child(FULLSCREEN_HINT))
229
.into_any_element()
230
})
231
}
232
233
fn stacked_avatars(state: &AppState, hidden: &[&Tile], diameter: f32) -> Div {
234
let shown: Vec<&&Tile> = hidden.iter().take(STACK_MAX).collect();
235
let step = diameter * (1. - STACK_OVERLAP);
236
div()
237
.relative()
238
.h(px(diameter))
239
.w(px(diameter + step * (shown.len().saturating_sub(1)) as f32))
240
.children(shown.into_iter().enumerate().map(|(index, tile)| {
241
div()
242
.absolute()
243
.top_0()
244
.left(px(step * index as f32))
245
.rounded_full()
246
.bg(theme::row_hover())
247
.child(person_avatar(
248
&state.directory,
249
tile.user_id.as_deref(),
250
&tile.name,
251
diameter,
252
))
253
}))
254
}
255
256
fn overflow_tile(
257
app: &Entity<AppState>,
258
state: &AppState,
259
size: TileSize,
260
hidden: &[&Tile],
261
) -> AnyElement {
262
let people: Vec<(String, String, Option<String>)> = hidden
263
.iter()
264
.map(|tile| (tile.mri.clone(), tile.name.clone(), tile.user_id.clone()))
265
.collect();
266
let diameter = (size.height * 0.3).clamp(22., 44.);
267
let face = v_flex()
268
.w(px(size.width))
269
.h(px(size.height))
270
.items_center()
271
.justify_center()
272
.gap(px(size.height * 0.06))
273
.rounded(px(TILE_RADIUS))
274
.bg(theme::row_hover())
275
.child(stacked_avatars(state, hidden, diameter))
276
.child(
277
div()
278
.text_size(px((size.height * 0.2).clamp(14., 28.)))
279
.font_weight(FontWeight::SEMIBOLD)
280
.text_color(theme::text_muted())
281
.child(format!("+{}", hidden.len())),
282
);
283
let app = app.clone();
284
Popover::new("call-hidden-popover")
285
.anchor(Anchor::BottomLeft)
286
.offset(px(8.))
287
.trigger(
288
Button::new("call-hidden")
289
.ghost()
290
.p_0()
291
.w(px(size.width))
292
.h(px(size.height))
293
.rounded(px(TILE_RADIUS))
294
.child(face),
295
)
296
.content(move |_, _, cx| {
297
let popover = cx.entity().downgrade();
298
v_flex()
299
.id("call-hidden-list")
300
.w(px(HIDDEN_LIST_WIDTH))
301
.max_h(px(HIDDEN_LIST_HEIGHT))
302
.overflow_y_scroll()
303
.gap(px(2.))
304
.children(people.iter().map(|(mri, name, user_id)| {
305
let app_for_click = app.clone();
306
let popover = popover.clone();
307
let pinned_mri = mri.clone();
308
h_flex()
309
.id(SharedString::from(format!("call-hidden-{mri}")))
310
.w_full()
311
.px(px(8.))
312
.py(px(6.))
313
.gap(px(10.))
314
.items_center()
315
.rounded(px(8.))
316
.cursor_pointer()
317
.hover(|row| row.bg(theme::row_hover()))
318
.child(person_avatar(
319
&app.read(cx).directory,
320
user_id.as_deref(),
321
name,
322
HIDDEN_AVATAR,
323
))
324
.child(div().min_w_0().flex_1().truncate().child(name.clone()))
325
.on_click(move |_, window, cx| {
326
app_for_click
327
.update(cx, |state, cx| state.toggle_call_pin(&pinned_mri, cx));
328
popover
329
.update(cx, |state, cx| state.dismiss(window, cx))
330
.ok();
331
})
332
}))
333
})
334
.into_any_element()
335
}
336
337
fn own_slot(model: &CallModel, shown: &[&Tile]) -> usize {
338
match model.own_hand {
339
None => shown.len(),
340
Some(rank) => shown
341
.iter()
342
.filter(|tile| tile.hand.is_some_and(|other| other < rank))
343
.count(),
344
}
345
}
346
347
fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {
348
let mut rows = Vec::new();
349
let mut remaining = cells.into_iter();
350
loop {
351
let row: Vec<AnyElement> = remaining.by_ref().take(columns).collect();
352
if row.is_empty() {
353
return rows;
354
}
355
rows.push(h_flex().gap(px(TILE_GAP)).justify_center().children(row));
356
}
357
}
358
359
fn gallery_body(
360
app: &Entity<AppState>,
361
state: &AppState,
362
model: &CallModel,
363
now: Instant,
364
stage: (f32, f32),
365
) -> AnyElement {
366
let others = model.layout_tiles();
367
let own_cells = model.own_cells();
368
let overflow = split_overflow(others.len(), own_cells, GALLERY_MAX);
369
let cells = overflow.shown + own_cells + usize::from(overflow.hidden > 0);
370
let grid = gallery_grid(
371
cells,
372
stage.0 - 2. * GRID_PADDING,
373
stage.1 - 2. * GRID_PADDING,
374
TILE_GAP,
375
);
376
let size = TileSize::sixteen_by_nine(grid.tile_width.floor());
377
let shown = &others[..overflow.shown];
378
let mut tiles: Vec<AnyElement> = shown
379
.iter()
380
.map(|tile| person_tile(app, state, model, tile, size, now))
381
.collect();
382
if own_cells > 0 {
383
tiles.insert(
384
own_slot(model, shown),
385
own_tile(app, state, model, size, now),
386
);
387
}
388
if overflow.hidden > 0 {
389
tiles.push(overflow_tile(app, state, size, &others[overflow.shown..]));
390
}
391
v_flex()
392
.absolute()
393
.inset_0()
394
.items_center()
395
.justify_center()
396
.gap(px(TILE_GAP))
397
.children(rows_of(tiles, grid.columns))
398
.into_any_element()
399
}
400
401
fn speaker_body(
402
app: &Entity<AppState>,
403
state: &AppState,
404
model: &CallModel,
405
now: Instant,
406
stage: (f32, f32),
407
) -> AnyElement {
408
let focus = model.speaker_focus();
409
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
410
let main = focus
411
.as_ref()
412
.and_then(|focus| render_focus_stage(app, state, focus, now));
413
let others: Vec<&Tile> = model
414
.layout_tiles()
415
.into_iter()
416
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)
417
.collect();
418
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
419
let plan = filmstrip(
420
others.len(),
421
own_cells,
422
stage.0 - 2. * GRID_PADDING,
423
TILE_GAP,
424
FILMSTRIP_TILE_MAX,
425
);
426
let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
427
let shown = &others[..plan.overflow.shown];
428
let mut tiles: Vec<AnyElement> = shown
429
.iter()
430
.map(|tile| person_tile(app, state, model, tile, size, now))
431
.collect();
432
if own_cells > 0 {
433
tiles.insert(
434
own_slot(model, shown),
435
own_tile(app, state, model, size, now),
436
);
437
}
438
if plan.overflow.hidden > 0 {
439
tiles.push(overflow_tile(
440
app,
441
state,
442
size,
443
&others[plan.overflow.shown..],
444
));
445
}
446
v_flex()
447
.absolute()
448
.inset_0()
449
.p(px(GRID_PADDING))
450
.gap(px(TILE_GAP))
451
.child(
452
h_flex()
453
.flex_1()
454
.min_h_0()
455
.w_full()
456
.items_center()
457
.children(main),
458
)
459
.when(!tiles.is_empty(), |column| {
460
column.child(
461
h_flex()
462
.id("call-filmstrip")
463
.flex_none()
464
.w_full()
465
.gap(px(TILE_GAP))
466
.justify_center()
467
.children(tiles),
468
)
469
})
470
.into_any_element()
471
}
472
473
fn people_strip(
474
app: &Entity<AppState>,
475
state: &AppState,
476
model: &CallModel,
477
now: Instant,
478
) -> Stateful<Div> {
479
let mut cells: Vec<AnyElement> = model
480
.strip_tiles()
481
.into_iter()
482
.filter(|tile| !model.hidden_for_no_video(tile))
483
.map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
484
.collect();
485
if model.own_cells() > 0 {
486
let own_index = model.own_cell_index(cells.len());
487
cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
488
}
489
v_flex()
490
.id("call-strip")
491
.flex_none()
492
.w(px(STRIP_TILE.width))
493
.max_h(px(
494
STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
495
))
496
.gap(px(STRIP_GAP))
497
.overflow_y_scroll()
498
.children(cells)
499
}
500
501
fn share_body(
502
app: &Entity<AppState>,
503
state: &AppState,
504
model: &CallModel,
505
now: Instant,
506
stage: AnyElement,
507
layout: CallLayout,
508
) -> AnyElement {
509
h_flex()
510
.absolute()
511
.inset_0()
512
.p(px(GRID_PADDING))
513
.gap(px(TILE_GAP))
514
.items_center()
515
.child(stage)
516
.when(layout != CallLayout::Content, |row| {
517
row.child(people_strip(app, state, model, now))
518
})
519
.into_any_element()
520
}
521
522
pub(super) fn stage_region(
523
app: &Entity<AppState>,
524
state: &AppState,
525
call: &ActiveCall,
526
now: Instant,
527
hold: Option<AnyElement>,
528
share_stage: Option<AnyElement>,
529
) -> AnyElement {
530
let model = &call.model;
531
let layout = model.effective_layout();
532
let stage = measured_stage(call);
533
let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
534
let body = match (hold, share_stage) {
535
(Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
536
(None, Some(share)) => share_body(app, state, model, now, share, layout),
537
(None, None) if layout == CallLayout::Speaker => {
538
speaker_body(app, state, model, now, stage)
539
}
540
(None, None) => gallery_body(app, state, model, now, stage),
541
};
542
div()
543
.relative()
544
.debug_selector(|| "shell/islands/main/call-stage".into())
545
.flex_1()
546
.min_h_0()
547
.w_full()
548
.child(measure_stage(call))
549
.child(body)
550
.children(
551
without_video_chip(app, model)
552
.filter(|_| shows_people)
553
.into_iter()
554
.chain(show_me_pill(app, model, OVERLAY_INSET).filter(|_| shows_people))
555
.chain(chat_bubbles(app, state, call, now, OVERLAY_INSET))
556
.chain(fullscreen_hint(call, now, OVERLAY_INSET)),
557
)
558
.into_any_element()
559
}
@@ -0,0 +1,559 @@1
use std::time::Instant;2
3
use gpui_kit::assets::IconName;4
use gpui_kit::component::{5
button::{Button, ButtonVariants as _},6
h_flex,7
popover::Popover,8
tooltip::Tooltip,9
v_flex,10
};11
use gpui_kit::prelude::FluentBuilder as _;12
use gpui_kit::*;13
14
use super::avatar::person_avatar;15
use super::call_organizer::render_focus_stage;16
use super::call_view::{17
GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,18
};19
use super::widgets::icon;20
use crate::app_state::AppState;21
use crate::call::{22
ActiveCall, CallLayout, CallModel, GALLERY_MAX, Tile, TileSize, filmstrip, gallery_grid,23
shown_bubbles, split_overflow,24
};25
use crate::theme;26
27
const FALLBACK_STAGE: (f32, f32) = (900., 560.);28
const MEASURE_TOLERANCE: f32 = 0.5;29
const OVERLAY_INSET: f32 = 16.;30
const CHIP_TOP: f32 = 12.;31
const FILMSTRIP_TILE_MAX: f32 = 220.;32
const TILE_RADIUS: f32 = 12.;33
const HIDDEN_LIST_WIDTH: f32 = 260.;34
const HIDDEN_LIST_HEIGHT: f32 = 320.;35
const HIDDEN_AVATAR: f32 = 28.;36
const STACK_MAX: usize = 3;37
const STACK_OVERLAP: f32 = 0.35;38
const BUBBLE_WIDTH: f32 = 340.;39
const BUBBLE_AVATAR: f32 = 28.;40
const BUBBLE_GAP: f32 = 8.;41
const BUBBLE_FADE_FROM: f32 = 0.9;42
const BUBBLE_BACKGROUND: f32 = 0.72;43
const CHIP_BACKGROUND: f32 = 0.6;44
pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";45
46
fn measured_stage(call: &ActiveCall) -> (f32, f32) {47
let (width, height) = call.stage_size.get();48
if width < 1. || height < 1. {49
return FALLBACK_STAGE;50
}51
(width, height)52
}53
54
fn measure_stage(call: &ActiveCall) -> impl IntoElement {55
let stage_size = call.stage_size.clone();56
canvas(57
|_, _, _| {},58
move |bounds, _, window, _| {59
let measured = (f32::from(bounds.size.width), f32::from(bounds.size.height));60
let known = stage_size.get();61
if (known.0 - measured.0).abs() > MEASURE_TOLERANCE62
|| (known.1 - measured.1).abs() > MEASURE_TOLERANCE63
{64
stage_size.set(measured);65
window.refresh();66
}67
},68
)69
.absolute()70
.size_full()71
}72
73
fn dark_chip() -> Div {74
h_flex()75
.h(px(30.))76
.px(px(12.))77
.gap(px(8.))78
.items_center()79
.rounded_full()80
.bg(hsla(0., 0., 0., CHIP_BACKGROUND))81
.text_color(theme::white())82
.text_size(px(13.))83
.font_weight(FontWeight::SEMIBOLD)84
}85
86
fn without_video_chip(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {87
let count = model.hidden_without_video();88
if !model.view.hide_no_video || count == 0 {89
return None;90
}91
let app = app.clone();92
Some(93
div()94
.absolute()95
.top(px(CHIP_TOP))96
.left_0()97
.right_0()98
.flex()99
.justify_center()100
.child(101
dark_chip()102
.id("call-no-video-chip")103
.cursor_pointer()104
.hover(|chip| chip.opacity(0.85))105
.tooltip(|window, cx| {106
Tooltip::new("Show people without video").build(window, cx)107
})108
.child(icon(IconName::VideoOff, 15., theme::white()))109
.child(format!("{count} without video"))110
.on_click(move |_, _, cx| {111
app.update(cx, |state, cx| state.toggle_call_hide_no_video(cx))112
}),113
)114
.into_any_element(),115
)116
}117
118
fn show_me_pill(app: &Entity<AppState>, model: &CallModel, bottom: f32) -> Option<AnyElement> {119
if !model.view.hide_me {120
return None;121
}122
let app = app.clone();123
Some(124
div()125
.absolute()126
.right(px(OVERLAY_INSET))127
.bottom(px(bottom))128
.child(129
dark_chip()130
.id("call-show-me")131
.cursor_pointer()132
.hover(|chip| chip.opacity(0.85))133
.tooltip(|window, cx| Tooltip::new("Show me").build(window, cx))134
.child(icon(IconName::Eye, 15., theme::white()))135
.child("You")136
.on_click(move |_, _, cx| {137
app.update(cx, |state, cx| state.set_call_hide_me(false, cx))138
}),139
)140
.into_any_element(),141
)142
}143
144
fn chat_bubbles(145
app: &Entity<AppState>,146
state: &AppState,147
call: &ActiveCall,148
now: Instant,149
bottom: f32,150
) -> Option<AnyElement> {151
if call.chat_open || !call.model.view.chat_bubbles {152
return None;153
}154
let bubbles = shown_bubbles(&call.bubbles, now);155
if bubbles.is_empty() {156
return None;157
}158
let shown = crate::call::BUBBLE_SHOWN;159
Some(160
v_flex()161
.absolute()162
.left(px(OVERLAY_INSET))163
.bottom(px(bottom))164
.gap(px(BUBBLE_GAP))165
.children(bubbles.into_iter().map(|bubble| {166
let app = app.clone();167
let id = SharedString::from(format!("call-bubble-{}", bubble.id));168
h_flex()169
.id(id.clone())170
.max_w(px(BUBBLE_WIDTH))171
.pl(px(6.))172
.pr(px(14.))173
.py(px(6.))174
.gap(px(8.))175
.items_center()176
.rounded_full()177
.bg(hsla(0., 0., 0., BUBBLE_BACKGROUND))178
.text_color(theme::white())179
.text_size(px(13.))180
.cursor_pointer()181
.child(person_avatar(182
&state.directory,183
bubble.sender_id.as_deref(),184
&bubble.name,185
BUBBLE_AVATAR,186
))187
.child(188
h_flex()189
.min_w_0()190
.flex_1()191
.gap(px(6.))192
.child(193
div()194
.flex_none()195
.font_weight(FontWeight::BOLD)196
.child(bubble.name.clone()),197
)198
.child(div().min_w_0().truncate().child(bubble.text.clone())),199
)200
.on_click(move |_, _, cx| {201
app.update(cx, |state, cx| {202
if state.call_chat_thread().is_none() {203
state.toggle_call_chat(cx);204
}205
})206
})207
.with_animation(id, Animation::new(shown), |bubble, delta| {208
let fade =209
((delta - BUBBLE_FADE_FROM) / (1. - BUBBLE_FADE_FROM)).clamp(0., 1.);210
bubble.opacity(1. - fade)211
})212
}))213
.into_any_element(),214
)215
}216
217
fn fullscreen_hint(call: &ActiveCall, now: Instant, bottom: f32) -> Option<AnyElement> {218
call.fullscreen219
.filter(|fullscreen| fullscreen.hint_visible(now))220
.map(|_| {221
div()222
.absolute()223
.left_0()224
.right_0()225
.bottom(px(bottom))226
.flex()227
.justify_center()228
.child(dark_chip().h(px(32.)).child(FULLSCREEN_HINT))229
.into_any_element()230
})231
}232
233
fn stacked_avatars(state: &AppState, hidden: &[&Tile], diameter: f32) -> Div {234
let shown: Vec<&&Tile> = hidden.iter().take(STACK_MAX).collect();235
let step = diameter * (1. - STACK_OVERLAP);236
div()237
.relative()238
.h(px(diameter))239
.w(px(diameter + step * (shown.len().saturating_sub(1)) as f32))240
.children(shown.into_iter().enumerate().map(|(index, tile)| {241
div()242
.absolute()243
.top_0()244
.left(px(step * index as f32))245
.rounded_full()246
.bg(theme::row_hover())247
.child(person_avatar(248
&state.directory,249
tile.user_id.as_deref(),250
&tile.name,251
diameter,252
))253
}))254
}255
256
fn overflow_tile(257
app: &Entity<AppState>,258
state: &AppState,259
size: TileSize,260
hidden: &[&Tile],261
) -> AnyElement {262
let people: Vec<(String, String, Option<String>)> = hidden263
.iter()264
.map(|tile| (tile.mri.clone(), tile.name.clone(), tile.user_id.clone()))265
.collect();266
let diameter = (size.height * 0.3).clamp(22., 44.);267
let face = v_flex()268
.w(px(size.width))269
.h(px(size.height))270
.items_center()271
.justify_center()272
.gap(px(size.height * 0.06))273
.rounded(px(TILE_RADIUS))274
.bg(theme::row_hover())275
.child(stacked_avatars(state, hidden, diameter))276
.child(277
div()278
.text_size(px((size.height * 0.2).clamp(14., 28.)))279
.font_weight(FontWeight::SEMIBOLD)280
.text_color(theme::text_muted())281
.child(format!("+{}", hidden.len())),282
);283
let app = app.clone();284
Popover::new("call-hidden-popover")285
.anchor(Anchor::BottomLeft)286
.offset(px(8.))287
.trigger(288
Button::new("call-hidden")289
.ghost()290
.p_0()291
.w(px(size.width))292
.h(px(size.height))293
.rounded(px(TILE_RADIUS))294
.child(face),295
)296
.content(move |_, _, cx| {297
let popover = cx.entity().downgrade();298
v_flex()299
.id("call-hidden-list")300
.w(px(HIDDEN_LIST_WIDTH))301
.max_h(px(HIDDEN_LIST_HEIGHT))302
.overflow_y_scroll()303
.gap(px(2.))304
.children(people.iter().map(|(mri, name, user_id)| {305
let app_for_click = app.clone();306
let popover = popover.clone();307
let pinned_mri = mri.clone();308
h_flex()309
.id(SharedString::from(format!("call-hidden-{mri}")))310
.w_full()311
.px(px(8.))312
.py(px(6.))313
.gap(px(10.))314
.items_center()315
.rounded(px(8.))316
.cursor_pointer()317
.hover(|row| row.bg(theme::row_hover()))318
.child(person_avatar(319
&app.read(cx).directory,320
user_id.as_deref(),321
name,322
HIDDEN_AVATAR,323
))324
.child(div().min_w_0().flex_1().truncate().child(name.clone()))325
.on_click(move |_, window, cx| {326
app_for_click327
.update(cx, |state, cx| state.toggle_call_pin(&pinned_mri, cx));328
popover329
.update(cx, |state, cx| state.dismiss(window, cx))330
.ok();331
})332
}))333
})334
.into_any_element()335
}336
337
fn own_slot(model: &CallModel, shown: &[&Tile]) -> usize {338
match model.own_hand {339
None => shown.len(),340
Some(rank) => shown341
.iter()342
.filter(|tile| tile.hand.is_some_and(|other| other < rank))343
.count(),344
}345
}346
347
fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {348
let mut rows = Vec::new();349
let mut remaining = cells.into_iter();350
loop {351
let row: Vec<AnyElement> = remaining.by_ref().take(columns).collect();352
if row.is_empty() {353
return rows;354
}355
rows.push(h_flex().gap(px(TILE_GAP)).justify_center().children(row));356
}357
}358
359
fn gallery_body(360
app: &Entity<AppState>,361
state: &AppState,362
model: &CallModel,363
now: Instant,364
stage: (f32, f32),365
) -> AnyElement {366
let others = model.layout_tiles();367
let own_cells = model.own_cells();368
let overflow = split_overflow(others.len(), own_cells, GALLERY_MAX);369
let cells = overflow.shown + own_cells + usize::from(overflow.hidden > 0);370
let grid = gallery_grid(371
cells,372
stage.0 - 2. * GRID_PADDING,373
stage.1 - 2. * GRID_PADDING,374
TILE_GAP,375
);376
let size = TileSize::sixteen_by_nine(grid.tile_width.floor());377
let shown = &others[..overflow.shown];378
let mut tiles: Vec<AnyElement> = shown379
.iter()380
.map(|tile| person_tile(app, state, model, tile, size, now))381
.collect();382
if own_cells > 0 {383
tiles.insert(384
own_slot(model, shown),385
own_tile(app, state, model, size, now),386
);387
}388
if overflow.hidden > 0 {389
tiles.push(overflow_tile(app, state, size, &others[overflow.shown..]));390
}391
v_flex()392
.absolute()393
.inset_0()394
.items_center()395
.justify_center()396
.gap(px(TILE_GAP))397
.children(rows_of(tiles, grid.columns))398
.into_any_element()399
}400
401
fn speaker_body(402
app: &Entity<AppState>,403
state: &AppState,404
model: &CallModel,405
now: Instant,406
stage: (f32, f32),407
) -> AnyElement {408
let focus = model.speaker_focus();409
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());410
let main = focus411
.as_ref()412
.and_then(|focus| render_focus_stage(app, state, focus, now));413
let others: Vec<&Tile> = model414
.layout_tiles()415
.into_iter()416
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)417
.collect();418
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));419
let plan = filmstrip(420
others.len(),421
own_cells,422
stage.0 - 2. * GRID_PADDING,423
TILE_GAP,424
FILMSTRIP_TILE_MAX,425
);426
let size = TileSize::sixteen_by_nine(plan.tile_width.floor());427
let shown = &others[..plan.overflow.shown];428
let mut tiles: Vec<AnyElement> = shown429
.iter()430
.map(|tile| person_tile(app, state, model, tile, size, now))431
.collect();432
if own_cells > 0 {433
tiles.insert(434
own_slot(model, shown),435
own_tile(app, state, model, size, now),436
);437
}438
if plan.overflow.hidden > 0 {439
tiles.push(overflow_tile(440
app,441
state,442
size,443
&others[plan.overflow.shown..],444
));445
}446
v_flex()447
.absolute()448
.inset_0()449
.p(px(GRID_PADDING))450
.gap(px(TILE_GAP))451
.child(452
h_flex()453
.flex_1()454
.min_h_0()455
.w_full()456
.items_center()457
.children(main),458
)459
.when(!tiles.is_empty(), |column| {460
column.child(461
h_flex()462
.id("call-filmstrip")463
.flex_none()464
.w_full()465
.gap(px(TILE_GAP))466
.justify_center()467
.children(tiles),468
)469
})470
.into_any_element()471
}472
473
fn people_strip(474
app: &Entity<AppState>,475
state: &AppState,476
model: &CallModel,477
now: Instant,478
) -> Stateful<Div> {479
let mut cells: Vec<AnyElement> = model480
.strip_tiles()481
.into_iter()482
.filter(|tile| !model.hidden_for_no_video(tile))483
.map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))484
.collect();485
if model.own_cells() > 0 {486
let own_index = model.own_cell_index(cells.len());487
cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));488
}489
v_flex()490
.id("call-strip")491
.flex_none()492
.w(px(STRIP_TILE.width))493
.max_h(px(494
STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP495
))496
.gap(px(STRIP_GAP))497
.overflow_y_scroll()498
.children(cells)499
}500
501
fn share_body(502
app: &Entity<AppState>,503
state: &AppState,504
model: &CallModel,505
now: Instant,506
stage: AnyElement,507
layout: CallLayout,508
) -> AnyElement {509
h_flex()510
.absolute()511
.inset_0()512
.p(px(GRID_PADDING))513
.gap(px(TILE_GAP))514
.items_center()515
.child(stage)516
.when(layout != CallLayout::Content, |row| {517
row.child(people_strip(app, state, model, now))518
})519
.into_any_element()520
}521
522
pub(super) fn stage_region(523
app: &Entity<AppState>,524
state: &AppState,525
call: &ActiveCall,526
now: Instant,527
hold: Option<AnyElement>,528
share_stage: Option<AnyElement>,529
) -> AnyElement {530
let model = &call.model;531
let layout = model.effective_layout();532
let stage = measured_stage(call);533
let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);534
let body = match (hold, share_stage) {535
(Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),536
(None, Some(share)) => share_body(app, state, model, now, share, layout),537
(None, None) if layout == CallLayout::Speaker => {538
speaker_body(app, state, model, now, stage)539
}540
(None, None) => gallery_body(app, state, model, now, stage),541
};542
div()543
.relative()544
.debug_selector(|| "shell/islands/main/call-stage".into())545
.flex_1()546
.min_h_0()547
.w_full()548
.child(measure_stage(call))549
.child(body)550
.children(551
without_video_chip(app, model)552
.filter(|_| shows_people)553
.into_iter()554
.chain(show_me_pill(app, model, OVERLAY_INSET).filter(|_| shows_people))555
.chain(chat_bubbles(app, state, call, now, OVERLAY_INSET))556
.chain(fullscreen_hint(call, now, OVERLAY_INSET)),557
)558
.into_any_element()559
}@@ -111,7 +111,11 @@ fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {
111
111
}))
112
112
}
113
113
114
pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
114
pub fn lobby_banner(
115
app: &Entity<AppState>,
116
model: &CallModel,
117
list_open: bool,
118
) -> Option<AnyElement> {
115
119
if !model.can_admit() {
116
120
return None;
117
121
}
@@ -124,6 +128,7 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
124
128
return None;
125
129
}
126
130
let list_app = app.clone();
131
let open_app = app.clone();
127
132
let admit_app = app.clone();
128
133
Some(
129
134
h_flex()
@@ -144,6 +149,10 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
144
149
Popover::new("call-lobby-popover")
145
150
.anchor(Anchor::TopLeft)
146
151
.offset(px(8.))
152
.open(list_open)
153
.on_open_change(move |open, _, cx| {
154
open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))
155
})
147
156
.trigger(
148
157
Button::new("call-lobby-view")
149
158
.ghost()
@@ -196,6 +205,17 @@ fn confirm_remove(
196
205
});
197
206
}
198
207
208
fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {
209
let hide_app = app.clone();
210
popup.min_w(px(MENU_WIDTH)).item(
211
PopupMenuItem::new("Hide for me")
212
.icon(IconName::EyeOff)
213
.on_click(move |_, _, cx| {
214
hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))
215
}),
216
)
217
}
218
199
219
pub fn tile_menu(
200
220
popup: PopupMenu,
201
221
app: &Entity<AppState>,
@@ -204,14 +224,16 @@ pub fn tile_menu(
204
224
name: &str,
205
225
own: bool,
206
226
) -> PopupMenu {
227
if own {
228
return own_tile_items(popup, app);
229
}
207
230
let pinned = model.is_pinned(mri);
208
231
let spotlighted = model.is_spotlighted(mri);
209
232
let organizes = model.organizes_meeting();
210
let raised = !own
211
&& model
212
.tiles
213
.iter()
214
.any(|tile| tile.mri == mri && tile.hand.is_some());
233
let raised = model
234
.tiles
235
.iter()
236
.any(|tile| tile.mri == mri && tile.hand.is_some());
215
237
let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
216
238
let mut popup = popup.min_w(px(MENU_WIDTH));
217
239
let pin_app = app.clone();
@@ -239,7 +261,7 @@ pub fn tile_menu(
239
261
}),
240
262
);
241
263
}
242
if organizes && !own {
264
if organizes {
243
265
let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
244
266
popup = popup.item(
245
267
PopupMenuItem::new("Mute")
@@ -258,7 +280,7 @@ pub fn tile_menu(
258
280
hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
259
281
}));
260
282
}
261
if organizes && !own {
283
if organizes {
262
284
let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
263
285
popup = popup.separator().item(
264
286
PopupMenuItem::new("Remove from meeting...")
@@ -111,7 +111,11 @@ fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {111
}))111
}))112
}112
}113
113
114
pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {114
pub fn lobby_banner(115
app: &Entity<AppState>,116
model: &CallModel,117
list_open: bool,118
) -> Option<AnyElement> {115
if !model.can_admit() {119
if !model.can_admit() {116
return None;120
return None;117
}121
}@@ -124,6 +128,7 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem124
return None;128
return None;125
}129
}126
let list_app = app.clone();130
let list_app = app.clone();131
let open_app = app.clone();127
let admit_app = app.clone();132
let admit_app = app.clone();128
Some(133
Some(129
h_flex()134
h_flex()@@ -144,6 +149,10 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem144
Popover::new("call-lobby-popover")149
Popover::new("call-lobby-popover")145
.anchor(Anchor::TopLeft)150
.anchor(Anchor::TopLeft)146
.offset(px(8.))151
.offset(px(8.))152
.open(list_open)153
.on_open_change(move |open, _, cx| {154
open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))155
})147
.trigger(156
.trigger(148
Button::new("call-lobby-view")157
Button::new("call-lobby-view")149
.ghost()158
.ghost()@@ -196,6 +205,17 @@ fn confirm_remove(196
});205
});197
}206
}198
207
208
fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {209
let hide_app = app.clone();210
popup.min_w(px(MENU_WIDTH)).item(211
PopupMenuItem::new("Hide for me")212
.icon(IconName::EyeOff)213
.on_click(move |_, _, cx| {214
hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))215
}),216
)217
}218
199
pub fn tile_menu(219
pub fn tile_menu(200
popup: PopupMenu,220
popup: PopupMenu,201
app: &Entity<AppState>,221
app: &Entity<AppState>,@@ -204,14 +224,16 @@ pub fn tile_menu(204
name: &str,224
name: &str,205
own: bool,225
own: bool,206
) -> PopupMenu {226
) -> PopupMenu {227
if own {228
return own_tile_items(popup, app);229
}207
let pinned = model.is_pinned(mri);230
let pinned = model.is_pinned(mri);208
let spotlighted = model.is_spotlighted(mri);231
let spotlighted = model.is_spotlighted(mri);209
let organizes = model.organizes_meeting();232
let organizes = model.organizes_meeting();210
let raised = !own233
let raised = model211
&& model234
.tiles212
.tiles235
.iter()213
.iter()236
.any(|tile| tile.mri == mri && tile.hand.is_some());214
.any(|tile| tile.mri == mri && tile.hand.is_some());215
let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);237
let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);216
let mut popup = popup.min_w(px(MENU_WIDTH));238
let mut popup = popup.min_w(px(MENU_WIDTH));217
let pin_app = app.clone();239
let pin_app = app.clone();@@ -239,7 +261,7 @@ pub fn tile_menu(239
}),261
}),240
);262
);241
}263
}242
if organizes && !own {264
if organizes {243
let (mute_app, mute_mri) = (app.clone(), mri.to_owned());265
let (mute_app, mute_mri) = (app.clone(), mri.to_owned());244
popup = popup.item(266
popup = popup.item(245
PopupMenuItem::new("Mute")267
PopupMenuItem::new("Mute")@@ -258,7 +280,7 @@ pub fn tile_menu(258
hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))280
hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))259
}));281
}));260
}282
}261
if organizes && !own {283
if organizes {262
let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());284
let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());263
popup = popup.separator().item(285
popup = popup.separator().item(264
PopupMenuItem::new("Remove from meeting...")286
PopupMenuItem::new("Remove from meeting...")@@ -132,3 +132,16 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<
132
132
.into_any_element(),
133
133
)
134
134
}
135
136
pub fn render_call_overlay(view: AnyElement) -> AnyElement {
137
v_flex()
138
.id("call-fullscreen-overlay")
139
.occlude()
140
.absolute()
141
.top_0()
142
.left_0()
143
.size_full()
144
.bg(theme::background())
145
.child(view)
146
.into_any_element()
147
}
@@ -132,3 +132,16 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<132
.into_any_element(),132
.into_any_element(),133
)133
)134
}134
}135
136
pub fn render_call_overlay(view: AnyElement) -> AnyElement {137
v_flex()138
.id("call-fullscreen-overlay")139
.occlude()140
.absolute()141
.top_0()142
.left_0()143
.size_full()144
.bg(theme::background())145
.child(view)146
.into_any_element()147
}@@ -20,21 +20,20 @@ use super::call_extras::{
20
20
BackgroundMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,
21
21
room_chip, whiteboard_stage,
22
22
};
23
use super::call_layouts::stage_region;
23
24
use super::call_organizer::{
24
25
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
25
more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu,
26
more_button, pin_chip, spotlight_chip, with_tile_menu,
26
27
};
27
28
use super::call_stage::render_stage;
29
use super::call_view_menu::view_button;
28
30
use super::conversation::ConversationView;
29
31
use super::shell::ISLAND_GAP;
30
32
use super::widgets::{Corner, corner_badge, count_badge, icon};
31
33
use crate::app_state::AppState;
32
34
use crate::call::REACTION_SHOWN;
33
35
use crate::call::TileSize;
34
use crate::call::{
35
CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
36
tile_size,
37
};
36
use crate::call::{CallKind, CallModel, Tile, TileState};
38
37
use crate::rows::reaction_glyph as chat_reaction_glyph;
39
38
use crate::theme;
40
39
@@ -47,16 +46,16 @@ pub(super) const MENU_WIDTH: f32 = 280.;
47
46
const PULSE_PERIOD: Duration = Duration::from_millis(1400);
48
47
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
49
48
const BLINK_DIMMED_OPACITY: f32 = 0.45;
50
const DISABLED_OPACITY: f32 = 0.4;
51
const TILE_GAP: f32 = 20.;
52
const GRID_PADDING: f32 = 24.;
53
const STRIP_TILE: TileSize = TileSize {
49
pub(super) const DISABLED_OPACITY: f32 = 0.4;
50
pub(super) const TILE_GAP: f32 = 20.;
51
pub(super) const GRID_PADDING: f32 = 24.;
52
pub(super) const STRIP_TILE: TileSize = TileSize {
54
53
width: 232.,
55
54
height: 131.,
56
55
avatar: 56.,
57
56
};
58
const STRIP_GAP: f32 = 12.;
59
const STRIP_VISIBLE: f32 = 4.;
57
pub(super) const STRIP_GAP: f32 = 12.;
58
pub(super) const STRIP_VISIBLE: f32 = 4.;
60
59
const TILE_RADIUS: f32 = 12.;
61
60
const NAME_PLATE_BACKGROUND: f32 = 0.6;
62
61
pub const NO_MICROPHONE_HINT: &str = "No microphone found";
@@ -310,23 +309,6 @@ fn tile(
310
309
.children(tile_overlays(extras))
311
310
}
312
311
313
fn overflow_tile(size: TileSize, hidden: usize) -> Div {
314
v_flex()
315
.w(px(size.width))
316
.h(px(size.height))
317
.items_center()
318
.justify_center()
319
.rounded(px(12.))
320
.bg(theme::row_hover())
321
.child(
322
div()
323
.text_size(px(size.avatar * 0.5))
324
.font_weight(FontWeight::SEMIBOLD)
325
.text_color(theme::text_muted())
326
.child(format!("+{hidden}")),
327
)
328
}
329
330
312
fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
331
313
div()
332
314
.id(id)
@@ -495,7 +477,12 @@ fn share_items(
495
477
popup
496
478
}
497
479
498
fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
480
fn share_button(
481
app: &Entity<AppState>,
482
model: &CallModel,
483
sound: bool,
484
menu_open: bool,
485
) -> AnyElement {
499
486
if model.local_share.is_some() {
500
487
let app = app.clone();
501
488
return round_control(
@@ -525,6 +512,7 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
525
512
.into_any_element();
526
513
}
527
514
let app = app.clone();
515
let open_app = app.clone();
528
516
let model = model.clone();
529
517
Button::new("call-share")
530
518
.ghost()
@@ -535,6 +523,10 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
535
523
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
536
524
share_items(popup, &app, &model, sound)
537
525
})
526
.open(menu_open)
527
.on_open_change(move |open, _, cx| {
528
open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
529
})
538
530
.into_any_element()
539
531
}
540
532
@@ -816,7 +808,7 @@ fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElemen
816
808
})
817
809
}
818
810
819
fn person_tile(
811
pub(super) fn person_tile(
820
812
app: &Entity<AppState>,
821
813
state: &AppState,
822
814
model: &CallModel,
@@ -894,7 +886,7 @@ fn person_tile_body(
894
886
.into_any_element()
895
887
}
896
888
897
fn own_tile(
889
pub(super) fn own_tile(
898
890
app: &Entity<AppState>,
899
891
state: &AppState,
900
892
model: &CallModel,
@@ -957,59 +949,11 @@ fn own_tile_body(
957
949
.into_any_element()
958
950
}
959
951
960
fn remote_tiles(
961
app: &Entity<AppState>,
962
state: &AppState,
963
model: &CallModel,
964
size: TileSize,
965
hidden_cap: GridLayout,
966
now: Instant,
967
) -> Vec<AnyElement> {
968
let visible = model.visible_tiles();
969
let mut cells: Vec<AnyElement> = visible
970
.iter()
971
.take(hidden_cap.shown_others)
972
.map(|remote| person_tile(app, state, model, remote, size, now))
973
.collect();
974
if hidden_cap.hidden > 0 {
975
cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
976
}
977
cells
978
}
979
980
fn people_strip(
981
app: &Entity<AppState>,
982
state: &AppState,
983
model: &CallModel,
984
now: Instant,
985
focused: Option<&str>,
986
) -> Stateful<Div> {
987
let mut cells: Vec<AnyElement> = model
988
.strip_tiles()
989
.into_iter()
990
.filter(|remote| Some(remote.mri.as_str()) != focused)
991
.map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
992
.collect();
993
if focused.is_none() || focused != model.own_mri.as_deref() {
994
let own_index = model.own_cell_index(cells.len());
995
cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
996
}
997
v_flex()
998
.id("call-strip")
999
.flex_none()
1000
.w(px(STRIP_TILE.width))
1001
.max_h(px(
1002
STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1003
))
1004
.gap(px(STRIP_GAP))
1005
.overflow_y_scroll()
1006
.children(cells)
1007
}
1008
1009
952
pub fn render_call_view(
1010
953
app: &Entity<AppState>,
1011
954
state: &AppState,
1012
955
chat: Option<Entity<ConversationView>>,
956
fullscreen: bool,
1013
957
) -> Option<AnyElement> {
1014
958
let call = state.call.as_ref()?;
1015
959
let model = &call.model;
@@ -1043,31 +987,9 @@ pub fn render_call_view(
1043
987
.child(div().flex_1())
1044
988
.children(return_button(app, model));
1045
989
1046
let max_tiles = if chat.is_some() {
1047
CHAT_OPEN_TILES
1048
} else {
1049
MAX_TILES
1050
};
1051
let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1052
let cells_for_size = if chat.is_some() {
1053
MAX_TILES
1054
} else {
1055
layout.shown_others + usize::from(layout.hidden > 0) + 1
1056
};
1057
let size = tile_size(cells_for_size);
1058
let mut cells = remote_tiles(app, state, model, size, layout, now);
1059
let own_index = model.own_cell_index(cells.len());
1060
cells.insert(own_index, own_tile(app, state, model, size, now));
1061
let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1062
let stage = render_stage(app, state, false)
1063
.or_else(|| whiteboard_stage(app, model))
1064
.or_else(|| {
1065
focus
1066
.as_ref()
1067
.and_then(|focus| render_focus_stage(app, state, focus, now))
1068
});
1069
990
let hold = hold_panel(app, model);
1070
let focused = focus.as_ref().map(|focus| focus.mri.as_str());
991
let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
992
let region = stage_region(app, state, call, now, hold, share_stage);
1071
993
1072
994
let controls = h_flex()
1073
995
.w_full()
@@ -1094,11 +1016,17 @@ pub fn render_call_view(
1094
1016
.child(camera_button(app, model))
1095
1017
.children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1096
1018
)
1097
.child(share_button(app, model, state.call_share_sound))
1019
.child(share_button(
1020
app,
1021
model,
1022
state.call_share_sound,
1023
call.share_menu_open,
1024
))
1098
1025
.when(model.has_reaction_controls(), |row| {
1099
1026
row.child(hand_button(app, model))
1100
1027
.child(reactions_button(app, model))
1101
1028
})
1029
.child(view_button(app, model, fullscreen))
1102
1030
.children(more_button(app, model))
1103
1031
.when(call.chat_thread().is_some(), |row| {
1104
1032
row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
@@ -1108,51 +1036,51 @@ pub fn render_call_view(
1108
1036
row.child(leave_menu(app, model))
1109
1037
});
1110
1038
1111
let column = v_flex()
1039
let top = v_flex()
1040
.w_full()
1041
.flex_none()
1042
.child(header)
1043
.children(lobby_banner(app, model, call.lobby_list_open))
1044
.children(sharing_banner(app, model, state.call_share_sound))
1045
.children(consult_banner(app, state));
1046
1047
let chrome_visible = call
1048
.fullscreen
1049
.is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1050
let move_app = app.clone();
1051
let base = v_flex()
1112
1052
.relative()
1113
1053
.flex_1()
1114
1054
.min_w_0()
1115
1055
.h_full()
1116
.rounded(px(10.))
1117
1056
.overflow_hidden()
1118
.bg(theme::surface())
1119
.child(header)
1120
.children(lobby_banner(app, model))
1121
.children(sharing_banner(app, model, state.call_share_sound))
1122
.children(consult_banner(app, state))
1123
.child(match stage {
1124
_ if hold.is_some() => hold.expect("checked above"),
1125
Some(stage) => h_flex()
1126
.flex_1()
1127
.min_h_0()
1128
.p(px(GRID_PADDING))
1129
.gap(px(TILE_GAP))
1130
.items_center()
1131
.child(stage)
1132
.child(people_strip(app, state, model, now, focused))
1133
.into_any_element(),
1134
None => h_flex()
1135
.id("call-grid")
1136
.flex_1()
1137
.min_h_0()
1138
.overflow_y_scroll()
1139
.flex_wrap()
1140
.content_center()
1141
.p(px(GRID_PADDING))
1142
.gap(px(TILE_GAP))
1143
.items_center()
1144
.justify_center()
1145
.children(cells)
1146
.into_any_element(),
1057
.bg(theme::surface());
1058
let column = if fullscreen {
1059
base.on_mouse_move(move |_, _, cx| {
1060
move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1147
1061
})
1148
.child(controls)
1149
.children(captions_overlay(model, now))
1150
.children(captions_hint_chip(model))
1151
.children(state.transfer_picker.clone())
1152
.children(consent_overlay(app, model));
1062
.when(chrome_visible, |column| {
1063
column.child(fullscreen_chrome("call-chrome-top", app, top))
1064
})
1065
.child(region)
1066
.when(chrome_visible, |column| {
1067
column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1068
})
1069
} else {
1070
base.rounded(px(10.))
1071
.child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1072
.child(region)
1073
.child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1074
}
1075
.children(captions_overlay(model, now))
1076
.children(captions_hint_chip(model))
1077
.children(state.transfer_picker.clone())
1078
.children(consent_overlay(app, model));
1153
1079
Some(
1154
1080
h_flex()
1155
.debug_selector(|| "shell/islands/main".into())
1081
.when(!fullscreen, |row| {
1082
row.debug_selector(|| "shell/islands/main".into())
1083
})
1156
1084
.flex_1()
1157
1085
.min_w_0()
1158
1086
.h_full()
@@ -1163,6 +1091,18 @@ pub fn render_call_view(
1163
1091
)
1164
1092
}
1165
1093
1094
fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1095
let hover_app = app.clone();
1096
div()
1097
.id(id)
1098
.w_full()
1099
.flex_none()
1100
.on_hover(move |hovered, _, cx| {
1101
hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1102
})
1103
.child(content)
1104
}
1105
1166
1106
fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1167
1107
let app = app.clone();
1168
1108
v_flex()
@@ -20,21 +20,20 @@ use super::call_extras::{20
BackgroundMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,20
BackgroundMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,21
room_chip, whiteboard_stage,21
room_chip, whiteboard_stage,22
};22
};23
use super::call_layouts::stage_region;23
use super::call_organizer::{24
use super::call_organizer::{24
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,25
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,25
more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu,26
more_button, pin_chip, spotlight_chip, with_tile_menu,26
};27
};27
use super::call_stage::render_stage;28
use super::call_stage::render_stage;29
use super::call_view_menu::view_button;28
use super::conversation::ConversationView;30
use super::conversation::ConversationView;29
use super::shell::ISLAND_GAP;31
use super::shell::ISLAND_GAP;30
use super::widgets::{Corner, corner_badge, count_badge, icon};32
use super::widgets::{Corner, corner_badge, count_badge, icon};31
use crate::app_state::AppState;33
use crate::app_state::AppState;32
use crate::call::REACTION_SHOWN;34
use crate::call::REACTION_SHOWN;33
use crate::call::TileSize;35
use crate::call::TileSize;34
use crate::call::{36
use crate::call::{CallKind, CallModel, Tile, TileState};35
CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,36
tile_size,37
};38
use crate::rows::reaction_glyph as chat_reaction_glyph;37
use crate::rows::reaction_glyph as chat_reaction_glyph;39
use crate::theme;38
use crate::theme;40
39
@@ -47,16 +46,16 @@ pub(super) const MENU_WIDTH: f32 = 280.;47
const PULSE_PERIOD: Duration = Duration::from_millis(1400);46
const PULSE_PERIOD: Duration = Duration::from_millis(1400);48
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);47
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);49
const BLINK_DIMMED_OPACITY: f32 = 0.45;48
const BLINK_DIMMED_OPACITY: f32 = 0.45;50
const DISABLED_OPACITY: f32 = 0.4;49
pub(super) const DISABLED_OPACITY: f32 = 0.4;51
const TILE_GAP: f32 = 20.;50
pub(super) const TILE_GAP: f32 = 20.;52
const GRID_PADDING: f32 = 24.;51
pub(super) const GRID_PADDING: f32 = 24.;53
const STRIP_TILE: TileSize = TileSize {52
pub(super) const STRIP_TILE: TileSize = TileSize {54
width: 232.,53
width: 232.,55
height: 131.,54
height: 131.,56
avatar: 56.,55
avatar: 56.,57
};56
};58
const STRIP_GAP: f32 = 12.;57
pub(super) const STRIP_GAP: f32 = 12.;59
const STRIP_VISIBLE: f32 = 4.;58
pub(super) const STRIP_VISIBLE: f32 = 4.;60
const TILE_RADIUS: f32 = 12.;59
const TILE_RADIUS: f32 = 12.;61
const NAME_PLATE_BACKGROUND: f32 = 0.6;60
const NAME_PLATE_BACKGROUND: f32 = 0.6;62
pub const NO_MICROPHONE_HINT: &str = "No microphone found";61
pub const NO_MICROPHONE_HINT: &str = "No microphone found";@@ -310,23 +309,6 @@ fn tile(310
.children(tile_overlays(extras))309
.children(tile_overlays(extras))311
}310
}312
311
313
fn overflow_tile(size: TileSize, hidden: usize) -> Div {314
v_flex()315
.w(px(size.width))316
.h(px(size.height))317
.items_center()318
.justify_center()319
.rounded(px(12.))320
.bg(theme::row_hover())321
.child(322
div()323
.text_size(px(size.avatar * 0.5))324
.font_weight(FontWeight::SEMIBOLD)325
.text_color(theme::text_muted())326
.child(format!("+{hidden}")),327
)328
}329
330
fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {312
fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {331
div()313
div()332
.id(id)314
.id(id)@@ -495,7 +477,12 @@ fn share_items(495
popup477
popup496
}478
}497
479
498
fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {480
fn share_button(481
app: &Entity<AppState>,482
model: &CallModel,483
sound: bool,484
menu_open: bool,485
) -> AnyElement {499
if model.local_share.is_some() {486
if model.local_share.is_some() {500
let app = app.clone();487
let app = app.clone();501
return round_control(488
return round_control(@@ -525,6 +512,7 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl525
.into_any_element();512
.into_any_element();526
}513
}527
let app = app.clone();514
let app = app.clone();515
let open_app = app.clone();528
let model = model.clone();516
let model = model.clone();529
Button::new("call-share")517
Button::new("call-share")530
.ghost()518
.ghost()@@ -535,6 +523,10 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl535
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {523
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {536
share_items(popup, &app, &model, sound)524
share_items(popup, &app, &model, sound)537
})525
})526
.open(menu_open)527
.on_open_change(move |open, _, cx| {528
open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))529
})538
.into_any_element()530
.into_any_element()539
}531
}540
532
@@ -816,7 +808,7 @@ fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElemen816
})808
})817
}809
}818
810
819
fn person_tile(811
pub(super) fn person_tile(820
app: &Entity<AppState>,812
app: &Entity<AppState>,821
state: &AppState,813
state: &AppState,822
model: &CallModel,814
model: &CallModel,@@ -894,7 +886,7 @@ fn person_tile_body(894
.into_any_element()886
.into_any_element()895
}887
}896
888
897
fn own_tile(889
pub(super) fn own_tile(898
app: &Entity<AppState>,890
app: &Entity<AppState>,899
state: &AppState,891
state: &AppState,900
model: &CallModel,892
model: &CallModel,@@ -957,59 +949,11 @@ fn own_tile_body(957
.into_any_element()949
.into_any_element()958
}950
}959
951
960
fn remote_tiles(961
app: &Entity<AppState>,962
state: &AppState,963
model: &CallModel,964
size: TileSize,965
hidden_cap: GridLayout,966
now: Instant,967
) -> Vec<AnyElement> {968
let visible = model.visible_tiles();969
let mut cells: Vec<AnyElement> = visible970
.iter()971
.take(hidden_cap.shown_others)972
.map(|remote| person_tile(app, state, model, remote, size, now))973
.collect();974
if hidden_cap.hidden > 0 {975
cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());976
}977
cells978
}979
980
fn people_strip(981
app: &Entity<AppState>,982
state: &AppState,983
model: &CallModel,984
now: Instant,985
focused: Option<&str>,986
) -> Stateful<Div> {987
let mut cells: Vec<AnyElement> = model988
.strip_tiles()989
.into_iter()990
.filter(|remote| Some(remote.mri.as_str()) != focused)991
.map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))992
.collect();993
if focused.is_none() || focused != model.own_mri.as_deref() {994
let own_index = model.own_cell_index(cells.len());995
cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));996
}997
v_flex()998
.id("call-strip")999
.flex_none()1000
.w(px(STRIP_TILE.width))1001
.max_h(px(1002
STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP1003
))1004
.gap(px(STRIP_GAP))1005
.overflow_y_scroll()1006
.children(cells)1007
}1008
1009
pub fn render_call_view(952
pub fn render_call_view(1010
app: &Entity<AppState>,953
app: &Entity<AppState>,1011
state: &AppState,954
state: &AppState,1012
chat: Option<Entity<ConversationView>>,955
chat: Option<Entity<ConversationView>>,956
fullscreen: bool,1013
) -> Option<AnyElement> {957
) -> Option<AnyElement> {1014
let call = state.call.as_ref()?;958
let call = state.call.as_ref()?;1015
let model = &call.model;959
let model = &call.model;@@ -1043,31 +987,9 @@ pub fn render_call_view(1043
.child(div().flex_1())987
.child(div().flex_1())1044
.children(return_button(app, model));988
.children(return_button(app, model));1045
989
1046
let max_tiles = if chat.is_some() {1047
CHAT_OPEN_TILES1048
} else {1049
MAX_TILES1050
};1051
let layout = grid_layout(model.visible_tiles().len(), max_tiles);1052
let cells_for_size = if chat.is_some() {1053
MAX_TILES1054
} else {1055
layout.shown_others + usize::from(layout.hidden > 0) + 11056
};1057
let size = tile_size(cells_for_size);1058
let mut cells = remote_tiles(app, state, model, size, layout, now);1059
let own_index = model.own_cell_index(cells.len());1060
cells.insert(own_index, own_tile(app, state, model, size, now));1061
let focus = model.focus().filter(|_| model.screen_sharer.is_none());1062
let stage = render_stage(app, state, false)1063
.or_else(|| whiteboard_stage(app, model))1064
.or_else(|| {1065
focus1066
.as_ref()1067
.and_then(|focus| render_focus_stage(app, state, focus, now))1068
});1069
let hold = hold_panel(app, model);990
let hold = hold_panel(app, model);1070
let focused = focus.as_ref().map(|focus| focus.mri.as_str());991
let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));992
let region = stage_region(app, state, call, now, hold, share_stage);1071
993
1072
let controls = h_flex()994
let controls = h_flex()1073
.w_full()995
.w_full()@@ -1094,11 +1016,17 @@ pub fn render_call_view(1094
.child(camera_button(app, model))1016
.child(camera_button(app, model))1095
.children(camera_menu_button(app, model, BackgroundMenu::of(state))),1017
.children(camera_menu_button(app, model, BackgroundMenu::of(state))),1096
)1018
)1097
.child(share_button(app, model, state.call_share_sound))1019
.child(share_button(1020
app,1021
model,1022
state.call_share_sound,1023
call.share_menu_open,1024
))1098
.when(model.has_reaction_controls(), |row| {1025
.when(model.has_reaction_controls(), |row| {1099
row.child(hand_button(app, model))1026
row.child(hand_button(app, model))1100
.child(reactions_button(app, model))1027
.child(reactions_button(app, model))1101
})1028
})1029
.child(view_button(app, model, fullscreen))1102
.children(more_button(app, model))1030
.children(more_button(app, model))1103
.when(call.chat_thread().is_some(), |row| {1031
.when(call.chat_thread().is_some(), |row| {1104
row.child(chat_button(app, call.chat_open, state.call_chat_unread()))1032
row.child(chat_button(app, call.chat_open, state.call_chat_unread()))@@ -1108,51 +1036,51 @@ pub fn render_call_view(1108
row.child(leave_menu(app, model))1036
row.child(leave_menu(app, model))1109
});1037
});1110
1038
1111
let column = v_flex()1039
let top = v_flex()1040
.w_full()1041
.flex_none()1042
.child(header)1043
.children(lobby_banner(app, model, call.lobby_list_open))1044
.children(sharing_banner(app, model, state.call_share_sound))1045
.children(consult_banner(app, state));1046
1047
let chrome_visible = call1048
.fullscreen1049
.is_none_or(|fullscreen| fullscreen.chrome_visible(now));1050
let move_app = app.clone();1051
let base = v_flex()1112
.relative()1052
.relative()1113
.flex_1()1053
.flex_1()1114
.min_w_0()1054
.min_w_0()1115
.h_full()1055
.h_full()1116
.rounded(px(10.))1117
.overflow_hidden()1056
.overflow_hidden()1118
.bg(theme::surface())1057
.bg(theme::surface());1119
.child(header)1058
let column = if fullscreen {1120
.children(lobby_banner(app, model))1059
base.on_mouse_move(move |_, _, cx| {1121
.children(sharing_banner(app, model, state.call_share_sound))1060
move_app.update(cx, |state, cx| state.touch_call_chrome(cx))1122
.children(consult_banner(app, state))1123
.child(match stage {1124
_ if hold.is_some() => hold.expect("checked above"),1125
Some(stage) => h_flex()1126
.flex_1()1127
.min_h_0()1128
.p(px(GRID_PADDING))1129
.gap(px(TILE_GAP))1130
.items_center()1131
.child(stage)1132
.child(people_strip(app, state, model, now, focused))1133
.into_any_element(),1134
None => h_flex()1135
.id("call-grid")1136
.flex_1()1137
.min_h_0()1138
.overflow_y_scroll()1139
.flex_wrap()1140
.content_center()1141
.p(px(GRID_PADDING))1142
.gap(px(TILE_GAP))1143
.items_center()1144
.justify_center()1145
.children(cells)1146
.into_any_element(),1147
})1061
})1148
.child(controls)1062
.when(chrome_visible, |column| {1149
.children(captions_overlay(model, now))1063
column.child(fullscreen_chrome("call-chrome-top", app, top))1150
.children(captions_hint_chip(model))1064
})1151
.children(state.transfer_picker.clone())1065
.child(region)1152
.children(consent_overlay(app, model));1066
.when(chrome_visible, |column| {1067
column.child(fullscreen_chrome("call-chrome-bottom", app, controls))1068
})1069
} else {1070
base.rounded(px(10.))1071
.child(top.debug_selector(|| "shell/islands/main/call-header".into()))1072
.child(region)1073
.child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))1074
}1075
.children(captions_overlay(model, now))1076
.children(captions_hint_chip(model))1077
.children(state.transfer_picker.clone())1078
.children(consent_overlay(app, model));1153
Some(1079
Some(1154
h_flex()1080
h_flex()1155
.debug_selector(|| "shell/islands/main".into())1081
.when(!fullscreen, |row| {1082
row.debug_selector(|| "shell/islands/main".into())1083
})1156
.flex_1()1084
.flex_1()1157
.min_w_0()1085
.min_w_0()1158
.h_full()1086
.h_full()@@ -1163,6 +1091,18 @@ pub fn render_call_view(1163
)1091
)1164
}1092
}1165
1093
1094
fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {1095
let hover_app = app.clone();1096
div()1097
.id(id)1098
.w_full()1099
.flex_none()1100
.on_hover(move |hovered, _, cx| {1101
hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))1102
})1103
.child(content)1104
}1105
1166
fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {1106
fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {1167
let app = app.clone();1107
let app = app.clone();1168
v_flex()1108
v_flex()@@ -5,11 +5,13 @@ pub mod attachments;
5
5
pub mod avatar;
6
6
pub mod call_controls;
7
7
pub mod call_extras;
8
pub mod call_layouts;
8
9
pub mod call_mini;
9
10
pub mod call_mini_window;
10
11
pub mod call_organizer;
11
12
pub mod call_stage;
12
13
pub mod call_view;
14
pub mod call_view_menu;
13
15
pub mod calls_tab;
14
16
pub mod card_carousel;
15
17
pub mod card_chart;
@@ -5,11 +5,13 @@ pub mod attachments;5
pub mod avatar;5
pub mod avatar;6
pub mod call_controls;6
pub mod call_controls;7
pub mod call_extras;7
pub mod call_extras;8
pub mod call_layouts;8
pub mod call_mini;9
pub mod call_mini;9
pub mod call_mini_window;10
pub mod call_mini_window;10
pub mod call_organizer;11
pub mod call_organizer;11
pub mod call_stage;12
pub mod call_stage;12
pub mod call_view;13
pub mod call_view;14
pub mod call_view_menu;13
pub mod calls_tab;15
pub mod calls_tab;14
pub mod card_carousel;16
pub mod card_carousel;15
pub mod card_chart;17
pub mod card_chart;@@ -5,7 +5,7 @@ use gpui_kit::*;
5
5
6
6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7
7
use super::call_mini::render_call_mini;
8
use super::call_stage::render_stage_overlay;
8
use super::call_stage::{render_call_overlay, render_stage_overlay};
9
9
use super::call_view::render_call_view;
10
10
use super::conversation::{ConversationView, ReplyToHovered};
11
11
use super::dialog_overlay::render_task_dialog;
@@ -16,8 +16,9 @@ use super::rail::RailView;
16
16
use super::saved_panel::{SavedPanel, SavedPanelEvent};
17
17
use super::shortcuts::{
18
18
AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19
OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,
20
ToggleCallCamera, ToggleCallShare,
19
OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, Scope,
20
ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21
ToggleCallHand, ToggleCallShare,
21
22
};
22
23
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23
24
use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
@@ -91,6 +92,8 @@ pub struct AppShell {
91
92
agent_dialog: Option<Entity<StartDialog>>,
92
93
profile_card: Option<Entity<ProfileCard>>,
93
94
focus_handle: FocusHandle,
95
call_window_fullscreen: bool,
96
window_was_fullscreen: bool,
94
97
open_target: Option<OpenTarget>,
95
98
update: UpdateStatus,
96
99
user_input: Arc<UserInput>,
@@ -205,7 +208,7 @@ impl AppShell {
205
208
this.user_input.touch();
206
209
if event.keystroke.key == "escape" {
207
210
this.state
208
.update(cx, |state, cx| state.leave_stage_fullscreen(cx));
211
.update(cx, |state, cx| state.escape_call_fullscreen(cx));
209
212
}
210
213
});
211
214
let activation_observation = cx.observe_window_activation(window, |this, window, cx| {
@@ -232,6 +235,8 @@ impl AppShell {
232
235
agent_dialog: None,
233
236
profile_card: None,
234
237
focus_handle,
238
call_window_fullscreen: false,
239
window_was_fullscreen: false,
235
240
open_target,
236
241
update: UpdateStatus::UpToDate,
237
242
user_input,
@@ -562,6 +567,31 @@ impl AppShell {
562
567
cx.notify();
563
568
}
564
569
570
fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) {
571
self.state.update(cx, |state, cx| {
572
if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
573
if with_video {
574
state.start_chat_video_call(&chat_id, cx);
575
} else {
576
state.start_chat_call(&chat_id, cx);
577
}
578
}
579
});
580
}
581
582
fn sync_window_fullscreen(&mut self, wanted: bool, window: &mut Window) {
583
if wanted == self.call_window_fullscreen {
584
return;
585
}
586
self.call_window_fullscreen = wanted;
587
if wanted {
588
self.window_was_fullscreen = window.is_fullscreen();
589
}
590
if wanted != window.is_fullscreen() && (wanted || !self.window_was_fullscreen) {
591
window.toggle_fullscreen();
592
}
593
}
594
565
595
fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
566
596
if self.image_viewer.take().is_some() {
567
597
window.focus(&self.focus_handle, cx);
@@ -683,8 +713,14 @@ impl Render for AppShell {
683
713
self.sync_call_chat(chat_thread, window, cx);
684
714
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
685
715
let state = self.state.read(cx);
686
let call_view =
687
render_call_view(&self.state, state, chat_panel).filter(|_| state.viewing_call());
716
let call_fullscreen = state.call_fullscreen();
717
let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen)
718
.filter(|_| state.viewing_call());
719
let (call_view, call_overlay) = match call_view {
720
Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),
721
view => (view, None),
722
};
723
self.sync_window_fullscreen(call_fullscreen, window);
688
724
let call_mini = render_call_mini(&self.state, state);
689
725
let stage_overlay = render_stage_overlay(&self.state, state);
690
726
let status = render_status_bar(
@@ -773,6 +809,28 @@ impl Render for AppShell {
773
809
this.state
774
810
.update(cx, |state, cx| state.toggle_call_share(cx));
775
811
}))
812
.on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| {
813
this.state
814
.update(cx, |state, cx| state.toggle_call_hand(cx));
815
}))
816
.on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| {
817
this.state
818
.update(cx, |state, cx| state.open_call_lobby_list(cx));
819
}))
820
.on_action(cx.listener(|this, _: &StartAudioCall, _, cx| {
821
this.start_call_in_open_chat(false, cx);
822
}))
823
.on_action(cx.listener(|this, _: &StartVideoCall, _, cx| {
824
this.start_call_in_open_chat(true, cx);
825
}))
826
.on_action(cx.listener(|this, _: &ToggleCallFullscreen, _, cx| {
827
if this.image_viewer.is_some() || !this.state.read(cx).viewing_call() {
828
cx.propagate();
829
return;
830
}
831
this.state
832
.update(cx, |state, cx| state.toggle_call_fullscreen(cx));
833
}))
776
834
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
777
835
this.close_image_viewer(window, cx);
778
836
this.conversation.update(cx, |conversation, cx| {
@@ -795,6 +853,7 @@ impl Render for AppShell {
795
853
.child(status),
796
854
)
797
855
.children(call_mini)
856
.children(call_overlay)
798
857
.children(stage_overlay)
799
858
.children(self.image_viewer.clone())
800
859
.children(self.switcher.clone())
@@ -5,7 +5,7 @@ use gpui_kit::*;5
5
6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};7
use super::call_mini::render_call_mini;7
use super::call_mini::render_call_mini;8
use super::call_stage::render_stage_overlay;8
use super::call_stage::{render_call_overlay, render_stage_overlay};9
use super::call_view::render_call_view;9
use super::call_view::render_call_view;10
use super::conversation::{ConversationView, ReplyToHovered};10
use super::conversation::{ConversationView, ReplyToHovered};11
use super::dialog_overlay::render_task_dialog;11
use super::dialog_overlay::render_task_dialog;@@ -16,8 +16,9 @@ use super::rail::RailView;16
use super::saved_panel::{SavedPanel, SavedPanelEvent};16
use super::saved_panel::{SavedPanel, SavedPanelEvent};17
use super::shortcuts::{17
use super::shortcuts::{18
AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,18
AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,19
OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,19
OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, Scope,20
ToggleCallCamera, ToggleCallShare,20
ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,21
ToggleCallHand, ToggleCallShare,21
};22
};22
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};23
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};23
use super::sidebar::{SIDEBAR_WIDTH, SidebarView};24
use super::sidebar::{SIDEBAR_WIDTH, SidebarView};@@ -91,6 +92,8 @@ pub struct AppShell {91
agent_dialog: Option<Entity<StartDialog>>,92
agent_dialog: Option<Entity<StartDialog>>,92
profile_card: Option<Entity<ProfileCard>>,93
profile_card: Option<Entity<ProfileCard>>,93
focus_handle: FocusHandle,94
focus_handle: FocusHandle,95
call_window_fullscreen: bool,96
window_was_fullscreen: bool,94
open_target: Option<OpenTarget>,97
open_target: Option<OpenTarget>,95
update: UpdateStatus,98
update: UpdateStatus,96
user_input: Arc<UserInput>,99
user_input: Arc<UserInput>,@@ -205,7 +208,7 @@ impl AppShell {205
this.user_input.touch();208
this.user_input.touch();206
if event.keystroke.key == "escape" {209
if event.keystroke.key == "escape" {207
this.state210
this.state208
.update(cx, |state, cx| state.leave_stage_fullscreen(cx));211
.update(cx, |state, cx| state.escape_call_fullscreen(cx));209
}212
}210
});213
});211
let activation_observation = cx.observe_window_activation(window, |this, window, cx| {214
let activation_observation = cx.observe_window_activation(window, |this, window, cx| {@@ -232,6 +235,8 @@ impl AppShell {232
agent_dialog: None,235
agent_dialog: None,233
profile_card: None,236
profile_card: None,234
focus_handle,237
focus_handle,238
call_window_fullscreen: false,239
window_was_fullscreen: false,235
open_target,240
open_target,236
update: UpdateStatus::UpToDate,241
update: UpdateStatus::UpToDate,237
user_input,242
user_input,@@ -562,6 +567,31 @@ impl AppShell {562
cx.notify();567
cx.notify();563
}568
}564
569
570
fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) {571
self.state.update(cx, |state, cx| {572
if let Some(Selection::Chat(chat_id)) = state.selection.clone() {573
if with_video {574
state.start_chat_video_call(&chat_id, cx);575
} else {576
state.start_chat_call(&chat_id, cx);577
}578
}579
});580
}581
582
fn sync_window_fullscreen(&mut self, wanted: bool, window: &mut Window) {583
if wanted == self.call_window_fullscreen {584
return;585
}586
self.call_window_fullscreen = wanted;587
if wanted {588
self.window_was_fullscreen = window.is_fullscreen();589
}590
if wanted != window.is_fullscreen() && (wanted || !self.window_was_fullscreen) {591
window.toggle_fullscreen();592
}593
}594
565
fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {595
fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {566
if self.image_viewer.take().is_some() {596
if self.image_viewer.take().is_some() {567
window.focus(&self.focus_handle, cx);597
window.focus(&self.focus_handle, cx);@@ -683,8 +713,14 @@ impl Render for AppShell {683
self.sync_call_chat(chat_thread, window, cx);713
self.sync_call_chat(chat_thread, window, cx);684
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());714
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());685
let state = self.state.read(cx);715
let state = self.state.read(cx);686
let call_view =716
let call_fullscreen = state.call_fullscreen();687
render_call_view(&self.state, state, chat_panel).filter(|_| state.viewing_call());717
let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen)718
.filter(|_| state.viewing_call());719
let (call_view, call_overlay) = match call_view {720
Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),721
view => (view, None),722
};723
self.sync_window_fullscreen(call_fullscreen, window);688
let call_mini = render_call_mini(&self.state, state);724
let call_mini = render_call_mini(&self.state, state);689
let stage_overlay = render_stage_overlay(&self.state, state);725
let stage_overlay = render_stage_overlay(&self.state, state);690
let status = render_status_bar(726
let status = render_status_bar(@@ -773,6 +809,28 @@ impl Render for AppShell {773
this.state809
this.state774
.update(cx, |state, cx| state.toggle_call_share(cx));810
.update(cx, |state, cx| state.toggle_call_share(cx));775
}))811
}))812
.on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| {813
this.state814
.update(cx, |state, cx| state.toggle_call_hand(cx));815
}))816
.on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| {817
this.state818
.update(cx, |state, cx| state.open_call_lobby_list(cx));819
}))820
.on_action(cx.listener(|this, _: &StartAudioCall, _, cx| {821
this.start_call_in_open_chat(false, cx);822
}))823
.on_action(cx.listener(|this, _: &StartVideoCall, _, cx| {824
this.start_call_in_open_chat(true, cx);825
}))826
.on_action(cx.listener(|this, _: &ToggleCallFullscreen, _, cx| {827
if this.image_viewer.is_some() || !this.state.read(cx).viewing_call() {828
cx.propagate();829
return;830
}831
this.state832
.update(cx, |state, cx| state.toggle_call_fullscreen(cx));833
}))776
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {834
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {777
this.close_image_viewer(window, cx);835
this.close_image_viewer(window, cx);778
this.conversation.update(cx, |conversation, cx| {836
this.conversation.update(cx, |conversation, cx| {@@ -795,6 +853,7 @@ impl Render for AppShell {795
.child(status),853
.child(status),796
)854
)797
.children(call_mini)855
.children(call_mini)856
.children(call_overlay)798
.children(stage_overlay)857
.children(stage_overlay)799
.children(self.image_viewer.clone())858
.children(self.image_viewer.clone())800
.children(self.switcher.clone())859
.children(self.switcher.clone())@@ -25,6 +25,11 @@ actions!(
25
25
HangUpCall,
26
26
ToggleCallCamera,
27
27
ToggleCallShare,
28
ToggleCallHand,
29
OpenLobbyList,
30
StartAudioCall,
31
StartVideoCall,
32
ToggleCallFullscreen,
28
33
ShowShortcuts
29
34
]
30
35
);
@@ -112,7 +117,12 @@ pub const SHORTCUTS: &[Shortcut] = &[
112
117
shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
113
118
shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
114
119
shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
115
shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
120
shortcut!(Calls, GlobalOverTextFields, "Open the share menu or stop sharing", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
121
shortcut!(Calls, GlobalOverTextFields, "Raise or lower hand", "ctrl-shift-k", Some("cmd-shift-k"), ToggleCallHand),
122
shortcut!(Calls, GlobalOverTextFields, "Open the lobby list", "ctrl-shift-y", Some("cmd-shift-y"), OpenLobbyList),
123
shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
124
shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
125
shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
116
126
];
117
127
118
128
impl Shortcut {
@@ -25,6 +25,11 @@ actions!(25
HangUpCall,25
HangUpCall,26
ToggleCallCamera,26
ToggleCallCamera,27
ToggleCallShare,27
ToggleCallShare,28
ToggleCallHand,29
OpenLobbyList,30
StartAudioCall,31
StartVideoCall,32
ToggleCallFullscreen,28
ShowShortcuts33
ShowShortcuts29
]34
]30
);35
);@@ -112,7 +117,12 @@ pub const SHORTCUTS: &[Shortcut] = &[112
shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),117
shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),113
shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),118
shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),114
shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),119
shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),115
shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),120
shortcut!(Calls, GlobalOverTextFields, "Open the share menu or stop sharing", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),121
shortcut!(Calls, GlobalOverTextFields, "Raise or lower hand", "ctrl-shift-k", Some("cmd-shift-k"), ToggleCallHand),122
shortcut!(Calls, GlobalOverTextFields, "Open the lobby list", "ctrl-shift-y", Some("cmd-shift-y"), OpenLobbyList),123
shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),124
shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),125
shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),116
];126
];117
127
118
impl Shortcut {128
impl Shortcut {