diff --git a/src/client_handler.rs b/src/client_handler.rs index d4d2f11..b7fe1ba 100644 --- a/src/client_handler.rs +++ b/src/client_handler.rs @@ -22,7 +22,7 @@ impl ClientHandler { } pub fn listen() { - let listener = TcpListener::bind("127.0.0.1:3000").expect("Could not bind to address"); + let listener = TcpListener::bind("0.0.0.0:3000").expect("Could not bind to address"); for stream in listener.incoming() { thread::spawn(move || match stream { diff --git a/src/dispatcher.rs b/src/dispatcher.rs index e6e5e6c..7e01d9a 100644 --- a/src/dispatcher.rs +++ b/src/dispatcher.rs @@ -8,22 +8,19 @@ use crate::protocol::{Message, PlaySound}; pub struct Dispatcher; impl Dispatcher { - fn load_sound(sound_source: String) -> Vec { - let path = format!("./audios/{}", sound_source); + fn load_sound(path: String) -> Vec { let file = BufReader::new(File::open(path).unwrap()); let data: Vec = file.bytes().map(|byte| byte.unwrap()).collect(); data } - pub fn handle_dispatch_sample() { + pub fn handle_dispatch_sample(addr: String, sound_path: String) { let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() .as_micros(); let timestamp = now + 10000000; - let addr = "localhost:3000".to_owned(); - let sound_source = "augh.mp3".to_owned(); - let sound_data = Dispatcher::load_sound(sound_source); + let sound_data = Dispatcher::load_sound(sound_path); let msg = Message::PlaySound(PlaySound { timestamp: timestamp, sound_data: sound_data, diff --git a/src/ui_app.rs b/src/ui_app.rs index 7bb5ec8..af3acb6 100644 --- a/src/ui_app.rs +++ b/src/ui_app.rs @@ -2,12 +2,12 @@ use eframe::egui; use std::path::PathBuf; use egui_file_dialog::FileDialog; -use crate::dispatcher; +use crate::dispatcher::Dispatcher; pub struct UIApp { file_dialog: FileDialog, picked_file: Option, - ip_address: String, + address: String, } impl Default for UIApp { @@ -15,7 +15,7 @@ impl Default for UIApp { Self { file_dialog: FileDialog::new(), picked_file: None, - ip_address: "127.0.0.1".to_string(), + address: "127.0.0.1:3000".to_string(), } } } @@ -25,7 +25,7 @@ impl eframe::App for UIApp { egui::CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui|{ ui.label("Enter IP of target device: "); - ui.text_edit_singleline(&mut self.ip_address); + ui.text_edit_singleline(&mut self.address); }); if ui.button("Pick file").clicked() { self.file_dialog.pick_file(); @@ -36,7 +36,10 @@ impl eframe::App for UIApp { self.picked_file = Some(path.to_path_buf()); } if ui.button("Play sound").clicked() { - dispatcher::Dispatcher::handle_dispatch_sample(); + if let Some(path) = &self.picked_file { + Dispatcher::handle_dispatch_sample(self.address.clone(), path.to_str().unwrap().to_owned()); + + } } }); }