fix: ⚡ better reliability for microphone state
This commit is contained in:
parent
1e9808579a
commit
d930888abb
3 changed files with 24 additions and 8 deletions
|
@ -55,7 +55,7 @@ impl Default for State {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
State,
|
None,
|
||||||
JoinRoom,
|
JoinRoom,
|
||||||
LeaveRoom,
|
LeaveRoom,
|
||||||
UnmuteMicrophone,
|
UnmuteMicrophone,
|
||||||
|
@ -105,7 +105,7 @@ impl App {
|
||||||
}
|
}
|
||||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::State => Task::none(),
|
Message::None => Task::none(),
|
||||||
Message::JoinRoom => {
|
Message::JoinRoom => {
|
||||||
self.gui_status.write().unwrap().room = State::Loading;
|
self.gui_status.write().unwrap().room = State::Loading;
|
||||||
let client_config = self.client_config.clone();
|
let client_config = self.client_config.clone();
|
||||||
|
@ -124,7 +124,7 @@ impl App {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map(|_| Message::State)
|
.map(|_| Message::None)
|
||||||
}
|
}
|
||||||
Message::LeaveRoom => {
|
Message::LeaveRoom => {
|
||||||
self.gui_status.write().unwrap().room = State::Loading;
|
self.gui_status.write().unwrap().room = State::Loading;
|
||||||
|
@ -143,13 +143,25 @@ impl App {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::UnmuteMicrophone => {
|
Message::UnmuteMicrophone => {
|
||||||
self.gui_status.write().unwrap().microphone = State::Active;
|
self.gui_status.write().unwrap().microphone = State::Loading;
|
||||||
let microphone_sender = self.channel.microphone.clone();
|
let microphone_sender = self.channel.microphone.clone();
|
||||||
let microphone_stop_signal = oneshot::channel();
|
let microphone_stop_signal = oneshot::channel();
|
||||||
self.signal.microphone = Some(microphone_stop_signal.0);
|
self.signal.microphone = Some(microphone_stop_signal.0);
|
||||||
Task::perform(record(microphone_sender, microphone_stop_signal.1), |_| {
|
let is_microphone_started_signal = oneshot::channel();
|
||||||
Message::State
|
tokio::spawn(record(
|
||||||
})
|
microphone_sender,
|
||||||
|
is_microphone_started_signal.0,
|
||||||
|
microphone_stop_signal.1,
|
||||||
|
));
|
||||||
|
let gui_status = self.gui_status.clone();
|
||||||
|
Task::perform(
|
||||||
|
async move {
|
||||||
|
if let Ok(_) = is_microphone_started_signal.1.await {
|
||||||
|
gui_status.write().unwrap().microphone = State::Active;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|_| Message::None,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Message::MuteMicrophone => {
|
Message::MuteMicrophone => {
|
||||||
self.gui_status.write().unwrap().microphone = State::Loading;
|
self.gui_status.write().unwrap().microphone = State::Loading;
|
||||||
|
|
|
@ -12,7 +12,7 @@ impl ClientConfig {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
certificate_path: "./client/certificates/cert.pem".to_string(),
|
certificate_path: "./client/certificates/cert.pem".to_string(),
|
||||||
server_address: "localhost:4546".to_string(),
|
server_address: "127.0.0.1:4546".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use tokio::sync::{broadcast, oneshot};
|
||||||
|
|
||||||
pub async fn record(
|
pub async fn record(
|
||||||
microphone_sender: broadcast::Sender<f32>,
|
microphone_sender: broadcast::Sender<f32>,
|
||||||
|
is_microphone_started_signal: oneshot::Sender<bool>,
|
||||||
microphone_stop_signal: oneshot::Receiver<bool>,
|
microphone_stop_signal: oneshot::Receiver<bool>,
|
||||||
) {
|
) {
|
||||||
let host = cpal::default_host();
|
let host = cpal::default_host();
|
||||||
|
@ -24,6 +25,9 @@ pub async fn record(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
input_stream.play().unwrap();
|
input_stream.play().unwrap();
|
||||||
println!("Recording Started");
|
println!("Recording Started");
|
||||||
|
if let Err(_) = is_microphone_started_signal.send(true) {
|
||||||
|
eprintln!("Error: Is Microphone Started | Send");
|
||||||
|
}
|
||||||
|
|
||||||
tokio::task::block_in_place(|| {
|
tokio::task::block_in_place(|| {
|
||||||
let _ = microphone_stop_signal.blocking_recv();
|
let _ = microphone_stop_signal.blocking_recv();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue