-
This commit is contained in:
parent
b26b0d3916
commit
949ed2b8c7
3 changed files with 12 additions and 12 deletions
|
|
@ -22,7 +22,7 @@ impl ClientHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen() {
|
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() {
|
for stream in listener.incoming() {
|
||||||
thread::spawn(move || match stream {
|
thread::spawn(move || match stream {
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,19 @@ use crate::protocol::{Message, PlaySound};
|
||||||
pub struct Dispatcher;
|
pub struct Dispatcher;
|
||||||
|
|
||||||
impl Dispatcher {
|
impl Dispatcher {
|
||||||
fn load_sound(sound_source: String) -> Vec<u8> {
|
fn load_sound(path: String) -> Vec<u8> {
|
||||||
let path = format!("./audios/{}", sound_source);
|
|
||||||
let file = BufReader::new(File::open(path).unwrap());
|
let file = BufReader::new(File::open(path).unwrap());
|
||||||
let data: Vec<u8> = file.bytes().map(|byte| byte.unwrap()).collect();
|
let data: Vec<u8> = file.bytes().map(|byte| byte.unwrap()).collect();
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_dispatch_sample() {
|
pub fn handle_dispatch_sample(addr: String, sound_path: String) {
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_micros();
|
.as_micros();
|
||||||
let timestamp = now + 10000000;
|
let timestamp = now + 10000000;
|
||||||
let addr = "localhost:3000".to_owned();
|
let sound_data = Dispatcher::load_sound(sound_path);
|
||||||
let sound_source = "augh.mp3".to_owned();
|
|
||||||
let sound_data = Dispatcher::load_sound(sound_source);
|
|
||||||
let msg = Message::PlaySound(PlaySound {
|
let msg = Message::PlaySound(PlaySound {
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
sound_data: sound_data,
|
sound_data: sound_data,
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ use eframe::egui;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use egui_file_dialog::FileDialog;
|
use egui_file_dialog::FileDialog;
|
||||||
|
|
||||||
use crate::dispatcher;
|
use crate::dispatcher::Dispatcher;
|
||||||
|
|
||||||
pub struct UIApp {
|
pub struct UIApp {
|
||||||
file_dialog: FileDialog,
|
file_dialog: FileDialog,
|
||||||
picked_file: Option<PathBuf>,
|
picked_file: Option<PathBuf>,
|
||||||
ip_address: String,
|
address: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UIApp {
|
impl Default for UIApp {
|
||||||
|
|
@ -15,7 +15,7 @@ impl Default for UIApp {
|
||||||
Self {
|
Self {
|
||||||
file_dialog: FileDialog::new(),
|
file_dialog: FileDialog::new(),
|
||||||
picked_file: None,
|
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| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.horizontal(|ui|{
|
ui.horizontal(|ui|{
|
||||||
ui.label("Enter IP of target device: ");
|
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() {
|
if ui.button("Pick file").clicked() {
|
||||||
self.file_dialog.pick_file();
|
self.file_dialog.pick_file();
|
||||||
|
|
@ -36,7 +36,10 @@ impl eframe::App for UIApp {
|
||||||
self.picked_file = Some(path.to_path_buf());
|
self.picked_file = Some(path.to_path_buf());
|
||||||
}
|
}
|
||||||
if ui.button("Play sound").clicked() {
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue