diff --git a/client/src/gui.rs b/client/src/gui.rs index 2d90eaf..1563cd9 100644 --- a/client/src/gui.rs +++ b/client/src/gui.rs @@ -55,7 +55,7 @@ impl Default for State { #[derive(Debug, Clone, Copy)] pub enum Message { - State, + None, JoinRoom, LeaveRoom, UnmuteMicrophone, @@ -105,7 +105,7 @@ impl App { } pub fn update(&mut self, message: Message) -> Task { match message { - Message::State => Task::none(), + Message::None => Task::none(), Message::JoinRoom => { self.gui_status.write().unwrap().room = State::Loading; let client_config = self.client_config.clone(); @@ -124,7 +124,7 @@ impl App { } }, ) - .map(|_| Message::State) + .map(|_| Message::None) } Message::LeaveRoom => { self.gui_status.write().unwrap().room = State::Loading; @@ -143,13 +143,25 @@ impl App { Task::none() } 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_stop_signal = oneshot::channel(); self.signal.microphone = Some(microphone_stop_signal.0); - Task::perform(record(microphone_sender, microphone_stop_signal.1), |_| { - Message::State - }) + let is_microphone_started_signal = oneshot::channel(); + 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 => { self.gui_status.write().unwrap().microphone = State::Loading; diff --git a/client/src/lib.rs b/client/src/lib.rs index fd0e0e7..5449d88 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -12,7 +12,7 @@ impl ClientConfig { fn new() -> Self { Self { certificate_path: "./client/certificates/cert.pem".to_string(), - server_address: "localhost:4546".to_string(), + server_address: "127.0.0.1:4546".to_string(), } } } diff --git a/client/src/voice.rs b/client/src/voice.rs index be4d7bc..bd65c2e 100644 --- a/client/src/voice.rs +++ b/client/src/voice.rs @@ -3,6 +3,7 @@ use tokio::sync::{broadcast, oneshot}; pub async fn record( microphone_sender: broadcast::Sender, + is_microphone_started_signal: oneshot::Sender, microphone_stop_signal: oneshot::Receiver, ) { let host = cpal::default_host(); @@ -24,6 +25,9 @@ pub async fn record( .unwrap(); input_stream.play().unwrap(); println!("Recording Started"); + if let Err(_) = is_microphone_started_signal.send(true) { + eprintln!("Error: Is Microphone Started | Send"); + } tokio::task::block_in_place(|| { let _ = microphone_stop_signal.blocking_recv();