Skip to content

Commit

Permalink
fix(settings): fix audio (#1421)
Browse files Browse the repository at this point in the history
Co-authored-by: Darius Clark <dariusc93@users.noreply.github.com>
Co-authored-by: Phill Wisniewski <93608357+phillsatellite@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 1, 2023
1 parent 1101a3e commit dd39023
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 206 deletions.
1 change: 1 addition & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ settings-audio = Audio & Sound Settings
.media-sounds-description = When enabled, media related events such as toggling microphone or headphones and other real time events, will play sounds.
.message-sounds = Message Sounds
.message-sounds-description = When enabled you will hear a notification when a new message is received.
.failed = Failed to update settings
settings-files = Files Settings
.local-sync = Local Sync
Expand Down
2 changes: 2 additions & 0 deletions common/src/state/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ pub enum ConfigAction {
SetSettingsNotificationsEnabled(bool),
#[display(fmt = "SetAutoEnableExtensions {_0}")]
SetAutoEnableExtensions(bool),
#[display(fmt = "SetEchoCancellation {_0}")]
SetEchoCancellation(bool),
}
42 changes: 4 additions & 38 deletions common/src/state/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,17 @@ pub struct Privacy {

#[derive(Debug, Deserialize, Serialize, Copy, Clone, Eq, PartialEq)]
pub struct AudioVideo {
#[serde(default)]
pub noise_suppression: bool,
#[serde(default)]
pub echo_cancellation: bool,
pub call_timer: bool,
#[serde(default)]
pub interface_sounds: bool,
#[serde(default = "bool_true")]
pub message_sounds: bool,
#[serde(default = "bool_true")]
pub media_sounds: bool,
}

impl Default for AudioVideo {
fn default() -> Self {
Self {
noise_suppression: false,
echo_cancellation: true,
call_timer: false,
interface_sounds: false,
message_sounds: true,
Expand Down Expand Up @@ -105,16 +100,10 @@ fn bool_true() -> bool {
// This is a good place to start.
#[derive(Debug, Deserialize, Serialize, Copy, Clone, Eq, PartialEq)]
pub struct Notifications {
#[serde(default = "bool_true")]
pub enabled: bool,
#[serde(default)]
pub show_app_icon: bool,
#[serde(default = "bool_true")]
pub friends_notifications: bool,
#[serde(default = "bool_true")]
pub messages_notifications: bool,
// By default we leave this one off.
#[serde(default)]
pub settings_notifications: bool,
}

Expand All @@ -125,6 +114,7 @@ impl Default for Notifications {
show_app_icon: false,
friends_notifications: true,
messages_notifications: true,
// By default we leave this one off.
settings_notifications: false,
}
}
Expand Down Expand Up @@ -177,6 +167,7 @@ impl Configuration {
ConfigAction::SetAutoEnableExtensions(flag) => {
self.extensions.enable_automatically = flag
}
ConfigAction::SetEchoCancellation(flag) => self.audiovideo.echo_cancellation = flag,
}

if self.audiovideo != old_audiovideo {
Expand All @@ -193,28 +184,3 @@ impl Configuration {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn deserialize_notifications_config() {
let empty_str = String::from("{}");
let serde_notifications: Notifications =
serde_json::from_str(&empty_str).expect("failed to deserialize empty string");
let default_notifications = Notifications::default();

assert_eq!(default_notifications, serde_notifications);
}

#[test]
fn deserialize_audiovideo_config() {
let empty_str = String::from("{}");
let serde_audiovideo: AudioVideo =
serde_json::from_str(&empty_str).expect("failed to deserialize empty string");
let default_audiovideo = AudioVideo::default();

assert_eq!(default_audiovideo, serde_audiovideo);
}
}
58 changes: 20 additions & 38 deletions common/src/warp_runner/manager/commands/blink_commands.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use derive_more::Display;
use futures::channel::oneshot;
use uuid::Uuid;
use warp::crypto::DID;
use warp::{blink::AudioDeviceConfig, crypto::DID};

use crate::warp_runner::Calling;

pub struct Devices {
pub available_devices: Vec<String>,
pub selected: Option<String>,
}

#[derive(Display)]
pub enum BlinkCmd {
#[display(fmt = "OfferCall")]
Expand Down Expand Up @@ -46,19 +41,11 @@ pub enum BlinkCmd {
volume: f32,
rsp: oneshot::Sender<Result<(), warp::error::Error>>,
},
#[display(fmt = "GetAllMicrophones")]
GetAllMicrophones {
rsp: oneshot::Sender<Result<Devices, warp::error::Error>>,
},
#[display(fmt = "SetMicrophone")]
SetMicrophone {
device_name: String,
rsp: oneshot::Sender<Result<(), warp::error::Error>>,
},
#[display(fmt = "GetAllSpeakers")]
GetAllSpeakers {
rsp: oneshot::Sender<Result<Devices, warp::error::Error>>,
},
#[display(fmt = "SetSpeaker")]
SetSpeaker {
device_name: String,
Expand All @@ -73,6 +60,15 @@ pub enum BlinkCmd {
StopRecording {
rsp: oneshot::Sender<Result<(), warp::error::Error>>,
},
#[display(fmt = "GetAudioDeviceConfig")]
GetAudioDeviceConfig {
rsp: oneshot::Sender<Box<dyn AudioDeviceConfig>>,
},
#[display(fmt = "SetEchoCancellation")]
SetEchoCancellation {
flag: bool,
rsp: oneshot::Sender<Result<(), warp::error::Error>>,
},
}

pub async fn handle_blink_cmd(cmd: BlinkCmd, blink: &mut Calling) {
Expand Down Expand Up @@ -102,35 +98,11 @@ pub async fn handle_blink_cmd(cmd: BlinkCmd, blink: &mut Calling) {
BlinkCmd::AdjustVolume { user, volume, rsp } => {
let _ = rsp.send(blink.set_peer_audio_gain(user, volume).await);
}
BlinkCmd::GetAllMicrophones { rsp } => {
let audio_config = blink.get_audio_device_config().await;
let selected = audio_config.microphone_device_name();
let result = audio_config
.get_available_microphones()
.map(|available_devices| Devices {
available_devices,
selected,
})
.map_err(warp::error::Error::from);
let _ = rsp.send(result);
}
BlinkCmd::SetMicrophone { device_name, rsp } => {
let mut audio_config = blink.get_audio_device_config().await;
audio_config.set_microphone(&device_name);
let _ = rsp.send(blink.set_audio_device_config(audio_config).await);
}
BlinkCmd::GetAllSpeakers { rsp } => {
let audio_config = blink.get_audio_device_config().await;
let selected = audio_config.speaker_device_name();
let result = audio_config
.get_available_speakers()
.map(|available_devices| Devices {
available_devices,
selected,
})
.map_err(warp::error::Error::from);
let _ = rsp.send(result);
}
BlinkCmd::SetSpeaker { device_name, rsp } => {
let mut audio_config = blink.get_audio_device_config().await;
audio_config.set_speaker(&device_name);
Expand All @@ -142,5 +114,15 @@ pub async fn handle_blink_cmd(cmd: BlinkCmd, blink: &mut Calling) {
BlinkCmd::StopRecording { rsp } => {
let _ = rsp.send(blink.stop_recording().await);
}
BlinkCmd::GetAudioDeviceConfig { rsp } => {
let _ = rsp.send(blink.get_audio_device_config().await);
}
BlinkCmd::SetEchoCancellation { flag, rsp } => {
if flag {
let _ = rsp.send(blink.enable_automute());
} else {
let _ = rsp.send(blink.disable_automute());
}
}
}
}
3 changes: 3 additions & 0 deletions kit/src/elements/range/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Props<'a> {
icon_left: Option<Icon>,
icon_right: Option<Icon>,
aria_label: Option<String>,
disabled: Option<bool>,
}

#[allow(non_snake_case)]
Expand All @@ -42,6 +43,7 @@ pub fn Range<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
rsx!(Button {
icon: Icon::Minus,
appearance: Appearance::PrimaryAlternative,
disabled: cx.props.disabled.unwrap_or_default(),
aria_label: "decrease_range_value_button".into(),
onpress: move |_| {
if internal_state.get() > &cx.props.min {
Expand Down Expand Up @@ -69,6 +71,7 @@ pub fn Range<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
aria_label: "range-input",
step: "{step}",
value: "{internal_state}",
disabled: cx.props.disabled.unwrap_or_default(),
oninput: move |event| {
internal_state.set(event.value.parse().unwrap_or_default());
cx.props.onchange.call(event.value.parse().unwrap_or_default());
Expand Down
Loading

0 comments on commit dd39023

Please sign in to comment.