BlueGit

ict rusty-teams

fix(calls): mic and speaker chosen in a call are used for the next calls

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-15 · 6 weeks ago

Hash
33c09e8b9b02ef515ae77cd8e79566fc00c9ad9e
Parent
36cd2191
5 files changed +125 −61
crates/app/src/app_state.rs +6 −0
@@ -135,6 +135,8 @@ pub struct AppState {
135 135 pub call_view: crate::call::ViewSettings,
136 136 pub call_background: crate::call::BackgroundPick,
137 137 pub call_camera: calling::DeviceChoice,
138 pub call_input: calling::DeviceChoice,
139 pub call_output: calling::DeviceChoice,
138 140 pub call_mic: calling::MicSettings,
139 141 pub call_effects: calling::CameraEffects,
140 142 pub meet_now_pending: bool,
@@ -249,6 +251,8 @@ impl AppState {
249 251 call_view: crate::call::ViewSettings::default(),
250 252 call_background: crate::call::BackgroundPick::None,
251 253 call_camera: calling::DeviceChoice::SystemDefault,
254 call_input: calling::DeviceChoice::SystemDefault,
255 call_output: calling::DeviceChoice::SystemDefault,
252 256 call_mic: calling::MicSettings::default(),
253 257 call_effects: calling::CameraEffects::default(),
254 258 meet_now_pending: false,
@@ -281,6 +285,8 @@ impl AppState {
281 285 state.call_view = crate::call::ViewSettings::load(&state.store);
282 286 state.call_background = crate::call::load_background(&state.store);
283 287 state.call_camera = crate::call::load_camera(&state.store);
288 state.call_input = crate::call::load_input(&state.store);
289 state.call_output = crate::call::load_output(&state.store);
284 290 state.call_mic = crate::call::load_mic(&state.store);
285 291 state.call_effects = crate::call::load_camera_effects(&state.store);
286 292 state.join_options = crate::call::load_join_options(&state.store);
@@ -135,6 +135,8 @@ pub struct AppState {
135 pub call_view: crate::call::ViewSettings,
135 pub call_view: crate::call::ViewSettings,
136 pub call_background: crate::call::BackgroundPick,
136 pub call_background: crate::call::BackgroundPick,
137 pub call_camera: calling::DeviceChoice,
137 pub call_camera: calling::DeviceChoice,
138 pub call_input: calling::DeviceChoice,
139 pub call_output: calling::DeviceChoice,
138 pub call_mic: calling::MicSettings,
140 pub call_mic: calling::MicSettings,
139 pub call_effects: calling::CameraEffects,
141 pub call_effects: calling::CameraEffects,
140 pub meet_now_pending: bool,
142 pub meet_now_pending: bool,
@@ -249,6 +251,8 @@ impl AppState {
249 call_view: crate::call::ViewSettings::default(),
251 call_view: crate::call::ViewSettings::default(),
250 call_background: crate::call::BackgroundPick::None,
252 call_background: crate::call::BackgroundPick::None,
251 call_camera: calling::DeviceChoice::SystemDefault,
253 call_camera: calling::DeviceChoice::SystemDefault,
254 call_input: calling::DeviceChoice::SystemDefault,
255 call_output: calling::DeviceChoice::SystemDefault,
252 call_mic: calling::MicSettings::default(),
256 call_mic: calling::MicSettings::default(),
253 call_effects: calling::CameraEffects::default(),
257 call_effects: calling::CameraEffects::default(),
254 meet_now_pending: false,
258 meet_now_pending: false,
@@ -281,6 +285,8 @@ impl AppState {
281 state.call_view = crate::call::ViewSettings::load(&state.store);
285 state.call_view = crate::call::ViewSettings::load(&state.store);
282 state.call_background = crate::call::load_background(&state.store);
286 state.call_background = crate::call::load_background(&state.store);
283 state.call_camera = crate::call::load_camera(&state.store);
287 state.call_camera = crate::call::load_camera(&state.store);
288 state.call_input = crate::call::load_input(&state.store);
289 state.call_output = crate::call::load_output(&state.store);
284 state.call_mic = crate::call::load_mic(&state.store);
290 state.call_mic = crate::call::load_mic(&state.store);
285 state.call_effects = crate::call::load_camera_effects(&state.store);
291 state.call_effects = crate::call::load_camera_effects(&state.store);
286 state.join_options = crate::call::load_join_options(&state.store);
292 state.join_options = crate::call::load_join_options(&state.store);
crates/app/src/call/actions.rs +96 −7
@@ -45,8 +45,10 @@ const DEMO_LIVE_MINUTES: i64 = 60;
45 45 const ORGID_PREFIX: &str = "8:orgid:";
46 46 pub const SHARE_SOUND_META_KEY: &str = "call_share_sound";
47 47 const CAMERA_META_KEY: &str = "call_camera";
48 const INPUT_META_KEY: &str = "call_input";
49 const OUTPUT_META_KEY: &str = "call_output";
48 50 const EFFECTS_META_KEY: &str = "call_camera_effects";
49 const DEFAULT_CAMERA_META: &str = "default";
51 const DEFAULT_DEVICE_META: &str = "default";
50 52 const REPORT_SAVED_NOTICE: &str = "Test report saved";
51 53
52 54 pub fn load_share_sound(store: &store::Store) -> bool {
@@ -54,8 +56,20 @@ pub fn load_share_sound(store: &store::Store) -> bool {
54 56 }
55 57
56 58 pub fn load_camera(store: &store::Store) -> DeviceChoice {
57 match store.meta(CAMERA_META_KEY).ok().flatten() {
58 Some(key) if !key.is_empty() && key != DEFAULT_CAMERA_META => DeviceChoice::Device(key),
59 load_device(store, CAMERA_META_KEY)
60 }
61
62 pub fn load_input(store: &store::Store) -> DeviceChoice {
63 load_device(store, INPUT_META_KEY)
64 }
65
66 pub fn load_output(store: &store::Store) -> DeviceChoice {
67 load_device(store, OUTPUT_META_KEY)
68 }
69
70 fn load_device(store: &store::Store, key: &str) -> DeviceChoice {
71 match store.meta(key).ok().flatten() {
72 Some(key) if !key.is_empty() && key != DEFAULT_DEVICE_META => DeviceChoice::Device(key),
59 73 _ => DeviceChoice::SystemDefault,
60 74 }
61 75 }
@@ -70,9 +84,9 @@ pub fn load_camera_effects(store: &store::Store) -> CameraEffects {
70 84 })
71 85 }
72 86
73 fn camera_meta(choice: &DeviceChoice) -> &str {
87 fn device_meta(choice: &DeviceChoice) -> &str {
74 88 match choice {
75 DeviceChoice::SystemDefault => DEFAULT_CAMERA_META,
89 DeviceChoice::SystemDefault => DEFAULT_DEVICE_META,
76 90 DeviceChoice::Device(key) => key,
77 91 }
78 92 }
@@ -260,6 +274,12 @@ impl AppState {
260 274 if self.call_camera != DeviceChoice::SystemDefault {
261 275 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
262 276 }
277 if self.call_input != DeviceChoice::SystemDefault {
278 self.send_call_command(CallCommand::SelectInput(self.call_input.clone()));
279 }
280 if self.call_output != DeviceChoice::SystemDefault {
281 self.send_call_command(CallCommand::SelectOutput(self.call_output.clone()));
282 }
263 283 if self.call_background != BackgroundPick::None {
264 284 self.send_background_command(cx);
265 285 }
@@ -609,7 +629,7 @@ impl AppState {
609 629 }
610 630
611 631 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
612 let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
632 let _ = self.store.set_meta(CAMERA_META_KEY, device_meta(&choice));
613 633 self.call_camera = choice.clone();
614 634 if let Some(launcher) = &self.call_launcher {
615 635 launcher.set_default_camera(choice.clone());
@@ -653,10 +673,14 @@ impl AppState {
653 673 }
654 674
655 675 pub fn select_call_input(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
676 let _ = self.store.set_meta(INPUT_META_KEY, device_meta(&choice));
677 self.call_input = choice.clone();
656 678 self.send_call_command(CallCommand::SelectInput(choice));
657 679 }
658 680
659 681 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
682 let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice));
683 self.call_output = choice.clone();
660 684 self.send_call_command(CallCommand::SelectOutput(choice));
661 685 }
662 686
@@ -1315,7 +1339,7 @@ mod tests {
1315 1339 use gpui_kit::{AppContext as _, Entity, TestAppContext};
1316 1340 use store::{ChatRecord, MemberRecord, Store};
1317 1341
1318 use super::{ActiveCall, CallModel, load_camera, load_camera_effects};
1342 use super::{ActiveCall, CallModel, load_camera, load_camera_effects, load_input, load_output};
1319 1343 use crate::app_state::{AppEvent, AppState, Mode, Selection};
1320 1344 use crate::call::TransferCandidate;
1321 1345 use crate::call::background::BackgroundPick;
@@ -1438,6 +1462,71 @@ mod tests {
1438 1462 assert!(!cx.update(|cx| reopened.read(cx).call_share_sound));
1439 1463 }
1440 1464
1465 #[gpui_kit::test]
1466 fn in_call_device_picks_are_saved_including_system_default(cx: &mut TestAppContext) {
1467 let (app, mut control) = app_with_commands(cx, live_meeting(false), None);
1468 let store = cx.update(|cx| app.read(cx).store.clone());
1469 assert_eq!(load_input(&store), DeviceChoice::SystemDefault);
1470 cx.update(|cx| {
1471 app.update(cx, |state, cx| {
1472 state.select_call_input(DeviceChoice::Device("headset-mic".into()), cx);
1473 state.select_call_output(DeviceChoice::Device("headset".into()), cx);
1474 })
1475 });
1476 assert_eq!(load_input(&store), DeviceChoice::Device("headset-mic".into()));
1477 assert_eq!(load_output(&store), DeviceChoice::Device("headset".into()));
1478 assert_eq!(
1479 control.try_recv_command(),
1480 Some(CallCommand::SelectInput(DeviceChoice::Device("headset-mic".into())))
1481 );
1482 cx.update(|cx| {
1483 app.update(cx, |state, cx| {
1484 state.select_call_input(DeviceChoice::SystemDefault, cx)
1485 })
1486 });
1487 assert_eq!(load_input(&store), DeviceChoice::SystemDefault);
1488 let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default())));
1489 assert_eq!(
1490 cx.update(|cx| reopened.read(cx).call_output.clone()),
1491 DeviceChoice::Device("headset".into())
1492 );
1493 }
1494
1495 #[gpui_kit::test]
1496 fn every_call_starts_with_the_saved_devices_even_when_they_are_not_present(
1497 cx: &mut TestAppContext,
1498 ) {
1499 cx.update(gpui_kit::init);
1500 let store = Arc::new(Store::open_in_memory().unwrap());
1501 let app = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default())));
1502 cx.update(|cx| {
1503 app.update(cx, |state, cx| {
1504 state.select_call_input(DeviceChoice::Device("unplugged-mic".into()), cx);
1505 state.select_call_output(DeviceChoice::Device("headset".into()), cx);
1506 })
1507 });
1508 let (handle, mut control) = call_channel();
1509 cx.update(|cx| {
1510 app.update(cx, |state, cx| {
1511 state.begin_call(handle, CallModel::test(), None, cx)
1512 })
1513 });
1514 let mut commands = Vec::new();
1515 while let Some(command) = control.try_recv_command() {
1516 commands.push(command);
1517 }
1518 assert!(commands.contains(&CallCommand::SelectInput(DeviceChoice::Device(
1519 "unplugged-mic".into()
1520 ))));
1521 assert!(commands.contains(&CallCommand::SelectOutput(DeviceChoice::Device(
1522 "headset".into()
1523 ))));
1524 assert_eq!(
1525 load_input(&store),
1526 DeviceChoice::Device("unplugged-mic".into())
1527 );
1528 }
1529
1441 1530 #[gpui_kit::test]
1442 1531 fn the_camera_pick_is_remembered_and_the_next_call_starts_with_it(cx: &mut TestAppContext) {
1443 1532 let (app, _control) = app_with_commands(cx, live_meeting(false), None);
@@ -45,8 +45,10 @@ const DEMO_LIVE_MINUTES: i64 = 60;
45const ORGID_PREFIX: &str = "8:orgid:";
45const ORGID_PREFIX: &str = "8:orgid:";
46pub const SHARE_SOUND_META_KEY: &str = "call_share_sound";
46pub const SHARE_SOUND_META_KEY: &str = "call_share_sound";
47const CAMERA_META_KEY: &str = "call_camera";
47const CAMERA_META_KEY: &str = "call_camera";
48const INPUT_META_KEY: &str = "call_input";
49const OUTPUT_META_KEY: &str = "call_output";
48const EFFECTS_META_KEY: &str = "call_camera_effects";
50const EFFECTS_META_KEY: &str = "call_camera_effects";
49const DEFAULT_CAMERA_META: &str = "default";
51const DEFAULT_DEVICE_META: &str = "default";
50const REPORT_SAVED_NOTICE: &str = "Test report saved";
52const REPORT_SAVED_NOTICE: &str = "Test report saved";
51
53
52pub fn load_share_sound(store: &store::Store) -> bool {
54pub fn load_share_sound(store: &store::Store) -> bool {
@@ -54,8 +56,20 @@ pub fn load_share_sound(store: &store::Store) -> bool {
54}
56}
55
57
56pub fn load_camera(store: &store::Store) -> DeviceChoice {
58pub fn load_camera(store: &store::Store) -> DeviceChoice {
57 match store.meta(CAMERA_META_KEY).ok().flatten() {
59 load_device(store, CAMERA_META_KEY)
58 Some(key) if !key.is_empty() && key != DEFAULT_CAMERA_META => DeviceChoice::Device(key),
60}
61
62pub fn load_input(store: &store::Store) -> DeviceChoice {
63 load_device(store, INPUT_META_KEY)
64}
65
66pub fn load_output(store: &store::Store) -> DeviceChoice {
67 load_device(store, OUTPUT_META_KEY)
68}
69
70fn load_device(store: &store::Store, key: &str) -> DeviceChoice {
71 match store.meta(key).ok().flatten() {
72 Some(key) if !key.is_empty() && key != DEFAULT_DEVICE_META => DeviceChoice::Device(key),
59 _ => DeviceChoice::SystemDefault,
73 _ => DeviceChoice::SystemDefault,
60 }
74 }
61}
75}
@@ -70,9 +84,9 @@ pub fn load_camera_effects(store: &store::Store) -> CameraEffects {
70 })
84 })
71}
85}
72
86
73fn camera_meta(choice: &DeviceChoice) -> &str {
87fn device_meta(choice: &DeviceChoice) -> &str {
74 match choice {
88 match choice {
75 DeviceChoice::SystemDefault => DEFAULT_CAMERA_META,
89 DeviceChoice::SystemDefault => DEFAULT_DEVICE_META,
76 DeviceChoice::Device(key) => key,
90 DeviceChoice::Device(key) => key,
77 }
91 }
78}
92}
@@ -260,6 +274,12 @@ impl AppState {
260 if self.call_camera != DeviceChoice::SystemDefault {
274 if self.call_camera != DeviceChoice::SystemDefault {
261 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
275 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
262 }
276 }
277 if self.call_input != DeviceChoice::SystemDefault {
278 self.send_call_command(CallCommand::SelectInput(self.call_input.clone()));
279 }
280 if self.call_output != DeviceChoice::SystemDefault {
281 self.send_call_command(CallCommand::SelectOutput(self.call_output.clone()));
282 }
263 if self.call_background != BackgroundPick::None {
283 if self.call_background != BackgroundPick::None {
264 self.send_background_command(cx);
284 self.send_background_command(cx);
265 }
285 }
@@ -609,7 +629,7 @@ impl AppState {
609 }
629 }
610
630
611 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
631 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
612 let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
632 let _ = self.store.set_meta(CAMERA_META_KEY, device_meta(&choice));
613 self.call_camera = choice.clone();
633 self.call_camera = choice.clone();
614 if let Some(launcher) = &self.call_launcher {
634 if let Some(launcher) = &self.call_launcher {
615 launcher.set_default_camera(choice.clone());
635 launcher.set_default_camera(choice.clone());
@@ -653,10 +673,14 @@ impl AppState {
653 }
673 }
654
674
655 pub fn select_call_input(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
675 pub fn select_call_input(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
676 let _ = self.store.set_meta(INPUT_META_KEY, device_meta(&choice));
677 self.call_input = choice.clone();
656 self.send_call_command(CallCommand::SelectInput(choice));
678 self.send_call_command(CallCommand::SelectInput(choice));
657 }
679 }
658
680
659 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
681 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
682 let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice));
683 self.call_output = choice.clone();
660 self.send_call_command(CallCommand::SelectOutput(choice));
684 self.send_call_command(CallCommand::SelectOutput(choice));
661 }
685 }
662
686
@@ -1315,7 +1339,7 @@ mod tests {
1315 use gpui_kit::{AppContext as _, Entity, TestAppContext};
1339 use gpui_kit::{AppContext as _, Entity, TestAppContext};
1316 use store::{ChatRecord, MemberRecord, Store};
1340 use store::{ChatRecord, MemberRecord, Store};
1317
1341
1318 use super::{ActiveCall, CallModel, load_camera, load_camera_effects};
1342 use super::{ActiveCall, CallModel, load_camera, load_camera_effects, load_input, load_output};
1319 use crate::app_state::{AppEvent, AppState, Mode, Selection};
1343 use crate::app_state::{AppEvent, AppState, Mode, Selection};
1320 use crate::call::TransferCandidate;
1344 use crate::call::TransferCandidate;
1321 use crate::call::background::BackgroundPick;
1345 use crate::call::background::BackgroundPick;
@@ -1438,6 +1462,71 @@ mod tests {
1438 assert!(!cx.update(|cx| reopened.read(cx).call_share_sound));
1462 assert!(!cx.update(|cx| reopened.read(cx).call_share_sound));
1439 }
1463 }
1440
1464
1465 #[gpui_kit::test]
1466 fn in_call_device_picks_are_saved_including_system_default(cx: &mut TestAppContext) {
1467 let (app, mut control) = app_with_commands(cx, live_meeting(false), None);
1468 let store = cx.update(|cx| app.read(cx).store.clone());
1469 assert_eq!(load_input(&store), DeviceChoice::SystemDefault);
1470 cx.update(|cx| {
1471 app.update(cx, |state, cx| {
1472 state.select_call_input(DeviceChoice::Device("headset-mic".into()), cx);
1473 state.select_call_output(DeviceChoice::Device("headset".into()), cx);
1474 })
1475 });
1476 assert_eq!(load_input(&store), DeviceChoice::Device("headset-mic".into()));
1477 assert_eq!(load_output(&store), DeviceChoice::Device("headset".into()));
1478 assert_eq!(
1479 control.try_recv_command(),
1480 Some(CallCommand::SelectInput(DeviceChoice::Device("headset-mic".into())))
1481 );
1482 cx.update(|cx| {
1483 app.update(cx, |state, cx| {
1484 state.select_call_input(DeviceChoice::SystemDefault, cx)
1485 })
1486 });
1487 assert_eq!(load_input(&store), DeviceChoice::SystemDefault);
1488 let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default())));
1489 assert_eq!(
1490 cx.update(|cx| reopened.read(cx).call_output.clone()),
1491 DeviceChoice::Device("headset".into())
1492 );
1493 }
1494
1495 #[gpui_kit::test]
1496 fn every_call_starts_with_the_saved_devices_even_when_they_are_not_present(
1497 cx: &mut TestAppContext,
1498 ) {
1499 cx.update(gpui_kit::init);
1500 let store = Arc::new(Store::open_in_memory().unwrap());
1501 let app = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default())));
1502 cx.update(|cx| {
1503 app.update(cx, |state, cx| {
1504 state.select_call_input(DeviceChoice::Device("unplugged-mic".into()), cx);
1505 state.select_call_output(DeviceChoice::Device("headset".into()), cx);
1506 })
1507 });
1508 let (handle, mut control) = call_channel();
1509 cx.update(|cx| {
1510 app.update(cx, |state, cx| {
1511 state.begin_call(handle, CallModel::test(), None, cx)
1512 })
1513 });
1514 let mut commands = Vec::new();
1515 while let Some(command) = control.try_recv_command() {
1516 commands.push(command);
1517 }
1518 assert!(commands.contains(&CallCommand::SelectInput(DeviceChoice::Device(
1519 "unplugged-mic".into()
1520 ))));
1521 assert!(commands.contains(&CallCommand::SelectOutput(DeviceChoice::Device(
1522 "headset".into()
1523 ))));
1524 assert_eq!(
1525 load_input(&store),
1526 DeviceChoice::Device("unplugged-mic".into())
1527 );
1528 }
1529
1441 #[gpui_kit::test]
1530 #[gpui_kit::test]
1442 fn the_camera_pick_is_remembered_and_the_next_call_starts_with_it(cx: &mut TestAppContext) {
1531 fn the_camera_pick_is_remembered_and_the_next_call_starts_with_it(cx: &mut TestAppContext) {
1443 let (app, _control) = app_with_commands(cx, live_meeting(false), None);
1532 let (app, _control) = app_with_commands(cx, live_meeting(false), None);
crates/app/src/call/mod.rs +1 −1
@@ -39,7 +39,7 @@ mod transcript;
39 39 mod view_actions;
40 40 mod view_settings;
41 41
42 pub use actions::{load_camera, load_camera_effects, load_share_sound};
42 pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};
43 43 pub use mic::load_mic;
44 44 pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
45 45 pub use caption_style::{CaptionPosition, CaptionSize};
@@ -39,7 +39,7 @@ mod transcript;
39mod view_actions;
39mod view_actions;
40mod view_settings;
40mod view_settings;
41
41
42pub use actions::{load_camera, load_camera_effects, load_share_sound};
42pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};
43pub use mic::load_mic;
43pub use mic::load_mic;
44pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
44pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
45pub use caption_style::{CaptionPosition, CaptionSize};
45pub use caption_style::{CaptionPosition, CaptionSize};
crates/app/src/call/prejoin.rs +9 −49
@@ -1,4 +1,4 @@
1 use calling::{CallCommand, CallSpec, DeviceChoice, MeetingTarget, MuteCommand};
1 use calling::{CallCommand, CallSpec, MeetingTarget, MuteCommand};
2 2 use gpui_kit::Context;
3 3
4 4 use super::demo::{DemoCall, demo_guests};
@@ -6,7 +6,6 @@ use super::model::CallModel;
6 6 use crate::app_state::AppState;
7 7
8 8 const OPTIONS_META_KEY: &str = "prejoin_options";
9 const DEFAULT_DEVICE_META: &str = "default";
10 9
11 10 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
12 11 pub enum AudioChoice {
@@ -29,8 +28,6 @@ pub struct JoinOptions {
29 28 pub camera_on: bool,
30 29 pub mic_on: bool,
31 30 pub audio: AudioChoice,
32 pub input: DeviceChoice,
33 pub output: DeviceChoice,
34 31 }
35 32
36 33 impl Default for JoinOptions {
@@ -39,34 +36,16 @@ impl Default for JoinOptions {
39 36 camera_on: false,
40 37 mic_on: true,
41 38 audio: AudioChoice::Computer,
42 input: DeviceChoice::SystemDefault,
43 output: DeviceChoice::SystemDefault,
44 39 }
45 40 }
46 41 }
47 42
48 fn device_meta(choice: &DeviceChoice) -> &str {
49 match choice {
50 DeviceChoice::SystemDefault => DEFAULT_DEVICE_META,
51 DeviceChoice::Device(key) => key,
52 }
53 }
54
55 fn device_from_meta(value: &str) -> DeviceChoice {
56 match value {
57 "" | DEFAULT_DEVICE_META => DeviceChoice::SystemDefault,
58 key => DeviceChoice::Device(key.to_owned()),
59 }
60 }
61
62 43 impl JoinOptions {
63 44 pub fn to_meta(&self) -> String {
64 45 format!(
65 "camera={}\nmic={}\ninput={}\noutput={}",
46 "camera={}\nmic={}",
66 47 u8::from(self.camera_on),
67 u8::from(self.mic_on),
68 device_meta(&self.input),
69 device_meta(&self.output)
48 u8::from(self.mic_on)
70 49 )
71 50 }
72 51
@@ -76,8 +55,6 @@ impl JoinOptions {
76 55 match key {
77 56 "camera" => options.camera_on = value == "1",
78 57 "mic" => options.mic_on = value == "1",
79 "input" => options.input = device_from_meta(value),
80 "output" => options.output = device_from_meta(value),
81 58 _ => {}
82 59 }
83 60 }
@@ -88,17 +65,11 @@ impl JoinOptions {
88 65 if self.audio == AudioChoice::NoAudio {
89 66 return vec![CallCommand::DisableAudio];
90 67 }
91 let mut commands = Vec::new();
92 68 if self.mic_on {
93 commands.push(CallCommand::Mute(MuteCommand::Unmute));
94 }
95 if self.input != DeviceChoice::SystemDefault {
96 commands.push(CallCommand::SelectInput(self.input.clone()));
97 }
98 if self.output != DeviceChoice::SystemDefault {
99 commands.push(CallCommand::SelectOutput(self.output.clone()));
69 vec![CallCommand::Mute(MuteCommand::Unmute)]
70 } else {
71 Vec::new()
100 72 }
101 commands
102 73 }
103 74 }
104 75
@@ -210,8 +181,6 @@ mod tests {
210 181 camera_on: true,
211 182 mic_on: false,
212 183 audio: AudioChoice::Computer,
213 input: DeviceChoice::Device("usb-mic".into()),
214 output: DeviceChoice::SystemDefault,
215 184 };
216 185 assert_eq!(JoinOptions::from_meta(&options.to_meta()), options);
217 186 }
@@ -223,32 +192,23 @@ mod tests {
223 192 }
224 193
225 194 #[test]
226 fn computer_audio_unmutes_and_selects_chosen_devices_only() {
195 fn computer_audio_unmutes_only_when_the_mic_is_on() {
227 196 let default = JoinOptions::default();
228 197 assert_eq!(
229 198 default.commands_after_join(),
230 199 vec![CallCommand::Mute(MuteCommand::Unmute)]
231 200 );
232 let chosen = JoinOptions {
201 let muted = JoinOptions {
233 202 mic_on: false,
234 input: DeviceChoice::Device("mic".into()),
235 output: DeviceChoice::Device("speaker".into()),
236 203 ..default
237 204 };
238 assert_eq!(
239 chosen.commands_after_join(),
240 vec![
241 CallCommand::SelectInput(DeviceChoice::Device("mic".into())),
242 CallCommand::SelectOutput(DeviceChoice::Device("speaker".into())),
243 ]
244 );
205 assert_eq!(muted.commands_after_join(), Vec::<CallCommand>::new());
245 206 }
246 207
247 208 #[test]
248 209 fn without_audio_only_the_audio_is_switched_off() {
249 210 let options = JoinOptions {
250 211 audio: AudioChoice::NoAudio,
251 input: DeviceChoice::Device("mic".into()),
252 212 ..JoinOptions::default()
253 213 };
254 214 assert_eq!(
@@ -1,4 +1,4 @@
1use calling::{CallCommand, CallSpec, DeviceChoice, MeetingTarget, MuteCommand};
1use calling::{CallCommand, CallSpec, MeetingTarget, MuteCommand};
2use gpui_kit::Context;
2use gpui_kit::Context;
3
3
4use super::demo::{DemoCall, demo_guests};
4use super::demo::{DemoCall, demo_guests};
@@ -6,7 +6,6 @@ use super::model::CallModel;
6use crate::app_state::AppState;
6use crate::app_state::AppState;
7
7
8const OPTIONS_META_KEY: &str = "prejoin_options";
8const OPTIONS_META_KEY: &str = "prejoin_options";
9const DEFAULT_DEVICE_META: &str = "default";
10
9
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
12pub enum AudioChoice {
11pub enum AudioChoice {
@@ -29,8 +28,6 @@ pub struct JoinOptions {
29 pub camera_on: bool,
28 pub camera_on: bool,
30 pub mic_on: bool,
29 pub mic_on: bool,
31 pub audio: AudioChoice,
30 pub audio: AudioChoice,
32 pub input: DeviceChoice,
33 pub output: DeviceChoice,
34}
31}
35
32
36impl Default for JoinOptions {
33impl Default for JoinOptions {
@@ -39,34 +36,16 @@ impl Default for JoinOptions {
39 camera_on: false,
36 camera_on: false,
40 mic_on: true,
37 mic_on: true,
41 audio: AudioChoice::Computer,
38 audio: AudioChoice::Computer,
42 input: DeviceChoice::SystemDefault,
43 output: DeviceChoice::SystemDefault,
44 }
39 }
45 }
40 }
46}
41}
47
42
48fn device_meta(choice: &DeviceChoice) -> &str {
49 match choice {
50 DeviceChoice::SystemDefault => DEFAULT_DEVICE_META,
51 DeviceChoice::Device(key) => key,
52 }
53}
54
55fn device_from_meta(value: &str) -> DeviceChoice {
56 match value {
57 "" | DEFAULT_DEVICE_META => DeviceChoice::SystemDefault,
58 key => DeviceChoice::Device(key.to_owned()),
59 }
60}
61
62impl JoinOptions {
43impl JoinOptions {
63 pub fn to_meta(&self) -> String {
44 pub fn to_meta(&self) -> String {
64 format!(
45 format!(
65 "camera={}\nmic={}\ninput={}\noutput={}",
46 "camera={}\nmic={}",
66 u8::from(self.camera_on),
47 u8::from(self.camera_on),
67 u8::from(self.mic_on),
48 u8::from(self.mic_on)
68 device_meta(&self.input),
69 device_meta(&self.output)
70 )
49 )
71 }
50 }
72
51
@@ -76,8 +55,6 @@ impl JoinOptions {
76 match key {
55 match key {
77 "camera" => options.camera_on = value == "1",
56 "camera" => options.camera_on = value == "1",
78 "mic" => options.mic_on = value == "1",
57 "mic" => options.mic_on = value == "1",
79 "input" => options.input = device_from_meta(value),
80 "output" => options.output = device_from_meta(value),
81 _ => {}
58 _ => {}
82 }
59 }
83 }
60 }
@@ -88,17 +65,11 @@ impl JoinOptions {
88 if self.audio == AudioChoice::NoAudio {
65 if self.audio == AudioChoice::NoAudio {
89 return vec![CallCommand::DisableAudio];
66 return vec![CallCommand::DisableAudio];
90 }
67 }
91 let mut commands = Vec::new();
92 if self.mic_on {
68 if self.mic_on {
93 commands.push(CallCommand::Mute(MuteCommand::Unmute));
69 vec![CallCommand::Mute(MuteCommand::Unmute)]
94 }
70 } else {
95 if self.input != DeviceChoice::SystemDefault {
71 Vec::new()
96 commands.push(CallCommand::SelectInput(self.input.clone()));
97 }
98 if self.output != DeviceChoice::SystemDefault {
99 commands.push(CallCommand::SelectOutput(self.output.clone()));
100 }
72 }
101 commands
102 }
73 }
103}
74}
104
75
@@ -210,8 +181,6 @@ mod tests {
210 camera_on: true,
181 camera_on: true,
211 mic_on: false,
182 mic_on: false,
212 audio: AudioChoice::Computer,
183 audio: AudioChoice::Computer,
213 input: DeviceChoice::Device("usb-mic".into()),
214 output: DeviceChoice::SystemDefault,
215 };
184 };
216 assert_eq!(JoinOptions::from_meta(&options.to_meta()), options);
185 assert_eq!(JoinOptions::from_meta(&options.to_meta()), options);
217 }
186 }
@@ -223,32 +192,23 @@ mod tests {
223 }
192 }
224
193
225 #[test]
194 #[test]
226 fn computer_audio_unmutes_and_selects_chosen_devices_only() {
195 fn computer_audio_unmutes_only_when_the_mic_is_on() {
227 let default = JoinOptions::default();
196 let default = JoinOptions::default();
228 assert_eq!(
197 assert_eq!(
229 default.commands_after_join(),
198 default.commands_after_join(),
230 vec![CallCommand::Mute(MuteCommand::Unmute)]
199 vec![CallCommand::Mute(MuteCommand::Unmute)]
231 );
200 );
232 let chosen = JoinOptions {
201 let muted = JoinOptions {
233 mic_on: false,
202 mic_on: false,
234 input: DeviceChoice::Device("mic".into()),
235 output: DeviceChoice::Device("speaker".into()),
236 ..default
203 ..default
237 };
204 };
238 assert_eq!(
205 assert_eq!(muted.commands_after_join(), Vec::<CallCommand>::new());
239 chosen.commands_after_join(),
240 vec![
241 CallCommand::SelectInput(DeviceChoice::Device("mic".into())),
242 CallCommand::SelectOutput(DeviceChoice::Device("speaker".into())),
243 ]
244 );
245 }
206 }
246
207
247 #[test]
208 #[test]
248 fn without_audio_only_the_audio_is_switched_off() {
209 fn without_audio_only_the_audio_is_switched_off() {
249 let options = JoinOptions {
210 let options = JoinOptions {
250 audio: AudioChoice::NoAudio,
211 audio: AudioChoice::NoAudio,
251 input: DeviceChoice::Device("mic".into()),
252 ..JoinOptions::default()
212 ..JoinOptions::default()
253 };
213 };
254 assert_eq!(
214 assert_eq!(
crates/app/src/views/prejoin_view.rs +13 −4
@@ -42,6 +42,8 @@ pub struct PrejoinView {
42 42 cameras: Vec<DeviceEntry>,
43 43 devices: DeviceLists,
44 44 camera: DeviceChoice,
45 input: DeviceChoice,
46 output: DeviceChoice,
45 47 applied_background: crate::call::BackgroundPick,
46 48 tick: u32,
47 49 _subscription: Subscription,
@@ -99,6 +101,7 @@ impl PrejoinView {
99 101 let mut options = state.join_options.clone();
100 102 options.camera_on = options.camera_on && !state.mode.read_only;
101 103 let camera = state.call_camera.clone();
104 let (input, output) = (state.call_input.clone(), state.call_output.clone());
102 105 let mut view = PrejoinView {
103 106 pending_id: pending.id,
104 107 demo,
@@ -111,6 +114,8 @@ impl PrejoinView {
111 114 DeviceLists::default()
112 115 },
113 116 camera,
117 input,
118 output,
114 119 applied_background: crate::call::BackgroundPick::None,
115 120 tick: 0,
116 121 _subscription: subscription,
@@ -239,12 +244,16 @@ impl PrejoinView {
239 244 }
240 245
241 246 fn pick_input(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
242 self.options.input = choice;
247 self.input = choice.clone();
248 self.app
249 .update(cx, |state, cx| state.select_call_input(choice, cx));
243 250 cx.notify();
244 251 }
245 252
246 253 fn pick_output(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
247 self.options.output = choice;
254 self.output = choice.clone();
255 self.app
256 .update(cx, |state, cx| state.select_call_output(choice, cx));
248 257 cx.notify();
249 258 }
250 259
@@ -454,8 +463,8 @@ impl Render for PrejoinView {
454 463 .unwrap_or_default();
455 464 let audio_on = self.options.audio == AudioChoice::Computer;
456 465 let (cameras, camera) = (self.cameras.clone(), self.camera.clone());
457 let (inputs, input) = (self.devices.input_entries(), self.options.input.clone());
458 let (outputs, output) = (self.devices.output_entries(), self.options.output.clone());
466 let (inputs, input) = (self.devices.input_entries(), self.input.clone());
467 let (outputs, output) = (self.devices.output_entries(), self.output.clone());
459 468 let devices = h_flex()
460 469 .debug_selector(|| "shell/islands/main/prejoin/devices".into())
461 470 .flex_none()
@@ -42,6 +42,8 @@ pub struct PrejoinView {
42 cameras: Vec<DeviceEntry>,
42 cameras: Vec<DeviceEntry>,
43 devices: DeviceLists,
43 devices: DeviceLists,
44 camera: DeviceChoice,
44 camera: DeviceChoice,
45 input: DeviceChoice,
46 output: DeviceChoice,
45 applied_background: crate::call::BackgroundPick,
47 applied_background: crate::call::BackgroundPick,
46 tick: u32,
48 tick: u32,
47 _subscription: Subscription,
49 _subscription: Subscription,
@@ -99,6 +101,7 @@ impl PrejoinView {
99 let mut options = state.join_options.clone();
101 let mut options = state.join_options.clone();
100 options.camera_on = options.camera_on && !state.mode.read_only;
102 options.camera_on = options.camera_on && !state.mode.read_only;
101 let camera = state.call_camera.clone();
103 let camera = state.call_camera.clone();
104 let (input, output) = (state.call_input.clone(), state.call_output.clone());
102 let mut view = PrejoinView {
105 let mut view = PrejoinView {
103 pending_id: pending.id,
106 pending_id: pending.id,
104 demo,
107 demo,
@@ -111,6 +114,8 @@ impl PrejoinView {
111 DeviceLists::default()
114 DeviceLists::default()
112 },
115 },
113 camera,
116 camera,
117 input,
118 output,
114 applied_background: crate::call::BackgroundPick::None,
119 applied_background: crate::call::BackgroundPick::None,
115 tick: 0,
120 tick: 0,
116 _subscription: subscription,
121 _subscription: subscription,
@@ -239,12 +244,16 @@ impl PrejoinView {
239 }
244 }
240
245
241 fn pick_input(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
246 fn pick_input(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
242 self.options.input = choice;
247 self.input = choice.clone();
248 self.app
249 .update(cx, |state, cx| state.select_call_input(choice, cx));
243 cx.notify();
250 cx.notify();
244 }
251 }
245
252
246 fn pick_output(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
253 fn pick_output(&mut self, choice: DeviceChoice, cx: &mut Context<Self>) {
247 self.options.output = choice;
254 self.output = choice.clone();
255 self.app
256 .update(cx, |state, cx| state.select_call_output(choice, cx));
248 cx.notify();
257 cx.notify();
249 }
258 }
250
259
@@ -454,8 +463,8 @@ impl Render for PrejoinView {
454 .unwrap_or_default();
463 .unwrap_or_default();
455 let audio_on = self.options.audio == AudioChoice::Computer;
464 let audio_on = self.options.audio == AudioChoice::Computer;
456 let (cameras, camera) = (self.cameras.clone(), self.camera.clone());
465 let (cameras, camera) = (self.cameras.clone(), self.camera.clone());
457 let (inputs, input) = (self.devices.input_entries(), self.options.input.clone());
466 let (inputs, input) = (self.devices.input_entries(), self.input.clone());
458 let (outputs, output) = (self.devices.output_entries(), self.options.output.clone());
467 let (outputs, output) = (self.devices.output_entries(), self.output.clone());
459 let devices = h_flex()
468 let devices = h_flex()
460 .debug_selector(|| "shell/islands/main/prejoin/devices".into())
469 .debug_selector(|| "shell/islands/main/prejoin/devices".into())
461 .flex_none()
470 .flex_none()