This commit is contained in:
cediackermann 2025-01-06 15:53:51 +01:00
parent b26b0d3916
commit 949ed2b8c7
3 changed files with 12 additions and 12 deletions

View file

@ -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 {

View file

@ -8,22 +8,19 @@ use crate::protocol::{Message, PlaySound};
pub struct Dispatcher;
impl Dispatcher {
fn load_sound(sound_source: String) -> Vec<u8> {
let path = format!("./audios/{}", sound_source);
fn load_sound(path: String) -> Vec<u8> {
let file = BufReader::new(File::open(path).unwrap());
let data: Vec<u8> = 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,

View file

@ -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<PathBuf>,
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());
}
}
});
}