BlueGit

ict rusty-teams

fix(sounds): ringtones and alerts play on the selected speaker

- matched by WASAPI endpoint id or name, default device as fallback

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
b31a4de0342b0ff18a7de922e8de8aa4b7a6589a
Parent
c2a5ee04
5 files changed +50 −4
crates/app-base/src/notify/platform/stub.rs +2 −0
@@ -90,6 +90,8 @@ pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
90 90
91 91 pub fn play_sound() {}
92 92
93 pub fn set_sound_output(_device_key: Option<String>) {}
94
93 95 pub fn play_mp3(_bytes: Vec<u8>) {}
94 96
95 97 pub fn play_mp3_until(_bytes: Vec<u8>, _looped: bool, _stop: Arc<AtomicBool>) {}
@@ -90,6 +90,8 @@ pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
90
90
91pub fn play_sound() {}
91pub fn play_sound() {}
92
92
93pub fn set_sound_output(_device_key: Option<String>) {}
94
93pub fn play_mp3(_bytes: Vec<u8>) {}
95pub fn play_mp3(_bytes: Vec<u8>) {}
94
96
95pub fn play_mp3_until(_bytes: Vec<u8>, _looped: bool, _stop: Arc<AtomicBool>) {}
97pub fn play_mp3_until(_bytes: Vec<u8>, _looped: bool, _stop: Arc<AtomicBool>) {}
crates/app-base/src/notify/platform/windows_impl.rs +35 −3
@@ -568,9 +568,41 @@ pub fn set_window_icon(window: &Window, png: &[u8]) {
568 568 }
569 569 }
570 570
571 static SOUND_OUTPUT: std::sync::Mutex<Option<String>> = std::sync::Mutex::new(None);
572
573 pub fn set_sound_output(device_key: Option<String>) {
574 *SOUND_OUTPUT.lock().unwrap_or_else(|poisoned| poisoned.into_inner()) = device_key;
575 }
576
577 fn open_sound_sink() -> Option<rodio::MixerDeviceSink> {
578 use rodio::cpal::traits::{DeviceTrait, HostTrait};
579 let chosen = SOUND_OUTPUT
580 .lock()
581 .unwrap_or_else(|poisoned| poisoned.into_inner())
582 .clone();
583 let device = chosen.and_then(|device_key| {
584 rodio::cpal::default_host()
585 .output_devices()
586 .ok()?
587 .find(|device| {
588 device.id().is_ok_and(|id| id.1 == device_key)
589 || device
590 .description()
591 .is_ok_and(|description| description.name() == device_key)
592 })
593 });
594 device
595 .and_then(|device| {
596 rodio::DeviceSinkBuilder::from_device(device)
597 .and_then(|builder| builder.open_stream())
598 .ok()
599 })
600 .or_else(|| rodio::DeviceSinkBuilder::open_default_sink().ok())
601 }
602
571 603 pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
572 604 std::thread::spawn(move || {
573 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
605 let Some(mut sink) = open_sound_sink() else {
574 606 return;
575 607 };
576 608 sink.log_on_drop(false);
@@ -594,7 +626,7 @@ pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
594 626
595 627 pub fn play_mp3(bytes: Vec<u8>) {
596 628 std::thread::spawn(move || {
597 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
629 let Some(mut sink) = open_sound_sink() else {
598 630 return;
599 631 };
600 632 sink.log_on_drop(false);
@@ -606,7 +638,7 @@ pub fn play_mp3(bytes: Vec<u8>) {
606 638
607 639 pub fn play_sound() {
608 640 std::thread::spawn(|| {
609 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
641 let Some(mut sink) = open_sound_sink() else {
610 642 return;
611 643 };
612 644 sink.log_on_drop(false);
@@ -568,9 +568,41 @@ pub fn set_window_icon(window: &Window, png: &[u8]) {
568 }
568 }
569}
569}
570
570
571static SOUND_OUTPUT: std::sync::Mutex<Option<String>> = std::sync::Mutex::new(None);
572
573pub fn set_sound_output(device_key: Option<String>) {
574 *SOUND_OUTPUT.lock().unwrap_or_else(|poisoned| poisoned.into_inner()) = device_key;
575}
576
577fn open_sound_sink() -> Option<rodio::MixerDeviceSink> {
578 use rodio::cpal::traits::{DeviceTrait, HostTrait};
579 let chosen = SOUND_OUTPUT
580 .lock()
581 .unwrap_or_else(|poisoned| poisoned.into_inner())
582 .clone();
583 let device = chosen.and_then(|device_key| {
584 rodio::cpal::default_host()
585 .output_devices()
586 .ok()?
587 .find(|device| {
588 device.id().is_ok_and(|id| id.1 == device_key)
589 || device
590 .description()
591 .is_ok_and(|description| description.name() == device_key)
592 })
593 });
594 device
595 .and_then(|device| {
596 rodio::DeviceSinkBuilder::from_device(device)
597 .and_then(|builder| builder.open_stream())
598 .ok()
599 })
600 .or_else(|| rodio::DeviceSinkBuilder::open_default_sink().ok())
601}
602
571pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
603pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
572 std::thread::spawn(move || {
604 std::thread::spawn(move || {
573 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
605 let Some(mut sink) = open_sound_sink() else {
574 return;
606 return;
575 };
607 };
576 sink.log_on_drop(false);
608 sink.log_on_drop(false);
@@ -594,7 +626,7 @@ pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
594
626
595pub fn play_mp3(bytes: Vec<u8>) {
627pub fn play_mp3(bytes: Vec<u8>) {
596 std::thread::spawn(move || {
628 std::thread::spawn(move || {
597 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
629 let Some(mut sink) = open_sound_sink() else {
598 return;
630 return;
599 };
631 };
600 sink.log_on_drop(false);
632 sink.log_on_drop(false);
@@ -606,7 +638,7 @@ pub fn play_mp3(bytes: Vec<u8>) {
606
638
607pub fn play_sound() {
639pub fn play_sound() {
608 std::thread::spawn(|| {
640 std::thread::spawn(|| {
609 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
641 let Some(mut sink) = open_sound_sink() else {
610 return;
642 return;
611 };
643 };
612 sink.log_on_drop(false);
644 sink.log_on_drop(false);
crates/app-state/src/app_state.rs +1 −0
@@ -366,6 +366,7 @@ impl AppState {
366 366 state.call_camera = crate::call::load_camera(&state.store);
367 367 state.call_input = crate::call::load_input(&state.store);
368 368 state.call_output = crate::call::load_output(&state.store);
369 crate::call::apply_sound_output(&state.call_output);
369 370 state.call_mic = crate::call::load_mic(&state.store);
370 371 state.call_effects = crate::call::load_camera_effects(&state.store);
371 372 state.join_options = crate::call::load_join_options(&state.store);
@@ -366,6 +366,7 @@ impl AppState {
366 state.call_camera = crate::call::load_camera(&state.store);
366 state.call_camera = crate::call::load_camera(&state.store);
367 state.call_input = crate::call::load_input(&state.store);
367 state.call_input = crate::call::load_input(&state.store);
368 state.call_output = crate::call::load_output(&state.store);
368 state.call_output = crate::call::load_output(&state.store);
369 crate::call::apply_sound_output(&state.call_output);
369 state.call_mic = crate::call::load_mic(&state.store);
370 state.call_mic = crate::call::load_mic(&state.store);
370 state.call_effects = crate::call::load_camera_effects(&state.store);
371 state.call_effects = crate::call::load_camera_effects(&state.store);
371 state.join_options = crate::call::load_join_options(&state.store);
372 state.join_options = crate::call::load_join_options(&state.store);
crates/app-state/src/call/actions.rs +9 −0
@@ -46,6 +46,14 @@ 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 48 const INPUT_META_KEY: &str = "call_input";
49 pub fn apply_sound_output(choice: &DeviceChoice) {
50 let device_key = match choice {
51 DeviceChoice::SystemDefault => None,
52 DeviceChoice::Device(device_key) => Some(device_key.clone()),
53 };
54 app_base::notify::platform::set_sound_output(device_key);
55 }
56
49 57 const OUTPUT_META_KEY: &str = "call_output";
50 58 const EFFECTS_META_KEY: &str = "call_camera_effects";
51 59 const DEFAULT_DEVICE_META: &str = "default";
@@ -691,6 +699,7 @@ impl AppState {
691 699 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
692 700 let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice));
693 701 self.call_output = choice.clone();
702 apply_sound_output(&choice);
694 703 self.send_call_command(CallCommand::SelectOutput(choice));
695 704 }
696 705
@@ -46,6 +46,14 @@ const 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";
48const INPUT_META_KEY: &str = "call_input";
49pub fn apply_sound_output(choice: &DeviceChoice) {
50 let device_key = match choice {
51 DeviceChoice::SystemDefault => None,
52 DeviceChoice::Device(device_key) => Some(device_key.clone()),
53 };
54 app_base::notify::platform::set_sound_output(device_key);
55}
56
49const OUTPUT_META_KEY: &str = "call_output";
57const OUTPUT_META_KEY: &str = "call_output";
50const EFFECTS_META_KEY: &str = "call_camera_effects";
58const EFFECTS_META_KEY: &str = "call_camera_effects";
51const DEFAULT_DEVICE_META: &str = "default";
59const DEFAULT_DEVICE_META: &str = "default";
@@ -691,6 +699,7 @@ impl AppState {
691 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
699 pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
692 let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice));
700 let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice));
693 self.call_output = choice.clone();
701 self.call_output = choice.clone();
702 apply_sound_output(&choice);
694 self.send_call_command(CallCommand::SelectOutput(choice));
703 self.send_call_command(CallCommand::SelectOutput(choice));
695 }
704 }
696
705
crates/app-state/src/call/mod.rs +3 −1
@@ -25,7 +25,9 @@ pub use app_call_model::{
25 25 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
26 26 };
27 27
28 pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};
28 pub use actions::{
29 apply_sound_output, load_camera, load_camera_effects, load_input, load_output, load_share_sound,
30 };
29 31 pub use mic::load_mic;
30 32 pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
31 33 pub use caption_style::{CaptionPosition, CaptionSize};
@@ -25,7 +25,9 @@ pub use app_call_model::{
25 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
25 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
26};
26};
27
27
28pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};
28pub use actions::{
29 apply_sound_output, load_camera, load_camera_effects, load_input, load_output, load_share_sound,
30};
29pub use mic::load_mic;
31pub use mic::load_mic;
30pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
32pub use agenda::{AgendaRow, fetch_window, join_available, response_label};
31pub use caption_style::{CaptionPosition, CaptionSize};
33pub use caption_style::{CaptionPosition, CaptionSize};