Add support for multiple devices
This commit is contained in:
parent
949ed2b8c7
commit
58f18e5cfd
2 changed files with 46 additions and 11 deletions
|
|
@ -14,7 +14,7 @@ impl Dispatcher {
|
|||
data
|
||||
}
|
||||
|
||||
pub fn handle_dispatch_sample(addr: String, sound_path: String) {
|
||||
pub fn handle_dispatch_sample(addrs: Vec<String>, sound_path: String) {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
|
|
@ -25,8 +25,17 @@ impl Dispatcher {
|
|||
timestamp: timestamp,
|
||||
sound_data: sound_data,
|
||||
});
|
||||
for addr in addrs {
|
||||
if addr.is_empty() {
|
||||
continue;
|
||||
|
||||
} else {
|
||||
let mut sock = TcpStream::connect(addr).expect("Failed to connect");
|
||||
let buf = bincode::serialize(&msg).expect("Failed to serialize");
|
||||
sock.write_all(&buf).unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::dispatcher::Dispatcher;
|
|||
pub struct UIApp {
|
||||
file_dialog: FileDialog,
|
||||
picked_file: Option<PathBuf>,
|
||||
address: String,
|
||||
addresses: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for UIApp {
|
||||
|
|
@ -15,18 +15,42 @@ impl Default for UIApp {
|
|||
Self {
|
||||
file_dialog: FileDialog::new(),
|
||||
picked_file: None,
|
||||
address: "127.0.0.1:3000".to_string(),
|
||||
addresses: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for UIApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
if self.addresses.is_empty() {
|
||||
self.addresses.push("localhost:3000".to_owned());
|
||||
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.horizontal(|ui|{
|
||||
let mut to_remove = Vec::new();
|
||||
for (i, address) in self.addresses.iter_mut().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Enter IP of target device: ");
|
||||
ui.text_edit_singleline(&mut self.address);
|
||||
ui.text_edit_singleline(address);
|
||||
if ui.button("Play sound").clicked() {
|
||||
if let Some(path) = &self.picked_file {
|
||||
Dispatcher::handle_dispatch_sample(vec![address.clone()], path.to_str().unwrap().to_owned());
|
||||
|
||||
}
|
||||
}
|
||||
if ui.button("Remove").clicked() {
|
||||
to_remove.push(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
for i in to_remove.iter().rev() {
|
||||
self.addresses.remove(*i);
|
||||
}
|
||||
if ui.button("Add address").clicked() {
|
||||
self.addresses.push("localhost:3000".to_owned());
|
||||
}
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Pick file").clicked() {
|
||||
self.file_dialog.pick_file();
|
||||
}
|
||||
|
|
@ -35,9 +59,11 @@ impl eframe::App for UIApp {
|
|||
if let Some(path) = self.file_dialog.take_picked() {
|
||||
self.picked_file = Some(path.to_path_buf());
|
||||
}
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Play sound").clicked() {
|
||||
if let Some(path) = &self.picked_file {
|
||||
Dispatcher::handle_dispatch_sample(self.address.clone(), path.to_str().unwrap().to_owned());
|
||||
Dispatcher::handle_dispatch_sample(self.addresses.clone(), path.to_str().unwrap().to_owned());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue