refact: seperate audio device for voice call (#8703)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-07-14 04:07:02 +08:00
committed by GitHub
parent d18e95703e
commit 30afe4f779
9 changed files with 162 additions and 74 deletions

View File

@@ -308,7 +308,7 @@ pub async fn new_listener(postfix: &str) -> ResultType<Incoming> {
}
}
pub struct CheckIfRestart(String, Vec<String>, String);
pub struct CheckIfRestart(String, Vec<String>, String, String);
impl CheckIfRestart {
pub fn new() -> CheckIfRestart {
@@ -316,6 +316,7 @@ impl CheckIfRestart {
Config::get_option("stop-service"),
Config::get_rendezvous_servers(),
Config::get_option("audio-input"),
Config::get_option("voice-call-input"),
)
}
}
@@ -329,6 +330,12 @@ impl Drop for CheckIfRestart {
if self.2 != Config::get_option("audio-input") {
crate::audio_service::restart();
}
if self.3 != Config::get_option("voice-call-input") {
crate::audio_service::set_voice_call_input_device(
Some(Config::get_option("voice-call-input")),
true,
)
}
}
}
@@ -457,6 +464,8 @@ async fn handle(data: Data, stream: &mut Connection) {
} else {
None
};
} else if name == "voice-call-input" {
value = crate::audio_service::get_voice_call_input_device();
} else {
value = None;
}
@@ -472,6 +481,8 @@ async fn handle(data: Data, stream: &mut Connection) {
Config::set_permanent_password(&value);
} else if name == "salt" {
Config::set_salt(&value);
} else if name == "voice-call-input" {
crate::audio_service::set_voice_call_input_device(Some(value), true);
} else {
return;
}
@@ -488,12 +499,7 @@ async fn handle(data: Data, stream: &mut Connection) {
if let Some(v) = value.get("privacy-mode-impl-key") {
crate::privacy_mode::switch(v);
}
let pre_opts = Config::get_options();
let new_audio_input = pre_opts.get("audio-input");
Config::set_options(value);
if new_audio_input != pre_opts.get("audio-input") {
crate::audio_service::restart();
}
allow_err!(stream.send(&Data::Options(None)).await);
}
},