feat: 💄 first gui for streamer
fix: 🚑 oneshot fail in listener socket
This commit is contained in:
parent
c404f5b23f
commit
21d8781188
7 changed files with 67 additions and 16 deletions
|
@ -64,8 +64,9 @@ pub async fn start(relay_configs: Config) {
|
|||
ip: "127.0.0.1".to_string().parse().unwrap(),
|
||||
port: 0000,
|
||||
};
|
||||
let mut is_streaming = false;
|
||||
let mut is_streaming;
|
||||
loop {
|
||||
is_streaming = false;
|
||||
match streamer_socket.accept().await {
|
||||
Ok((streamer_tcp, streamer_info)) => {
|
||||
new_streamer.ip = streamer_info.ip();
|
||||
|
@ -258,7 +259,9 @@ async fn status_checker(
|
|||
let cleaning_timer = Instant::now();
|
||||
message_organizer_task.as_ref().unwrap().abort();
|
||||
buffer_layer_task.as_ref().unwrap().abort();
|
||||
listener_socket_killer_producer.send(true).unwrap();
|
||||
if let Err(_) = listener_socket_killer_producer.send(true) {
|
||||
eprintln!("Error: Cleaning | Socket Kill Failed, Receiver Dropped");
|
||||
}
|
||||
let mut listener_task_counter = 0;
|
||||
while listener_stream_tasks_receiver.len() > 0 {
|
||||
match listener_stream_tasks_receiver.recv().await {
|
||||
|
|
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||
brotli = "5.0.0"
|
||||
cpal = "0.15.3"
|
||||
futures-util = { version = "0.3.30", features = ["futures-sink", "sink"] }
|
||||
iced = { git = "https://github.com/iced-rs/iced", features = ["tokio"] }
|
||||
ringbuf = "0.3.3"
|
||||
rustls-pemfile = "2.1.2"
|
||||
rustls-platform-verifier = "0.2.0"
|
||||
|
|
52
streamer/src/gui.rs
Normal file
52
streamer/src/gui.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use iced::{widget::{button, column, Column}, Command};
|
||||
use tokio::sync::broadcast::{channel, Sender};
|
||||
|
||||
use crate::{recording, streaming, utils::get_config, Config, BUFFER_LENGTH};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
StartStreaming,
|
||||
ConfigLoad(Config),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Streamer {
|
||||
config: Option<Config>,
|
||||
sound_stream_producer:Sender<f32>,
|
||||
}
|
||||
impl Default for Streamer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Streamer {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
config: None,
|
||||
sound_stream_producer: channel(BUFFER_LENGTH).0,
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, message:Message) {
|
||||
match message {
|
||||
Message::StartStreaming => {
|
||||
tokio::spawn(streaming::connect(self.sound_stream_producer.subscribe(), self.config.clone().unwrap()));
|
||||
tokio::spawn(recording::record(self.sound_stream_producer.clone()));
|
||||
}
|
||||
Message::ConfigLoad(config) => {
|
||||
self.config = Some(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn view(&self) -> Column<Message> {
|
||||
column![
|
||||
button("Start Streaming").on_press(Message::StartStreaming)
|
||||
]
|
||||
}
|
||||
pub fn load_config() -> Command<Message> {
|
||||
Command::perform(get_config(), Message::ConfigLoad)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
pub mod recording;
|
||||
pub mod streaming;
|
||||
pub mod utils;
|
||||
pub mod gui;
|
||||
|
||||
pub const BUFFER_LENGTH: usize = 1000000;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub address: String,
|
||||
pub quality: u8,
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use streamer::{recording::recording, streaming::start, utils::get_config, BUFFER_LENGTH};
|
||||
use tokio::sync::broadcast::channel;
|
||||
use streamer::gui::Streamer;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
async fn main() -> iced::Result{
|
||||
println!("Hello, world!");
|
||||
let streamer_config = get_config().await;
|
||||
let (sound_stream_producer, sound_stream_consumer) = channel(BUFFER_LENGTH);
|
||||
tokio::spawn(recording(sound_stream_producer));
|
||||
tokio::spawn(start(sound_stream_consumer, streamer_config));
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(1000000000)).await;
|
||||
}
|
||||
iced::program("Streamer GUI", Streamer::update, Streamer::view)
|
||||
.load(Streamer::load_config)
|
||||
.run()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use tokio::sync::broadcast::Sender;
|
||||
|
||||
pub async fn recording(sound_stream_producer: Sender<f32>) {
|
||||
pub async fn record(sound_stream_producer: Sender<f32>) {
|
||||
let host = cpal::default_host();
|
||||
let input_device = host.default_input_device().unwrap();
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use tokio_tungstenite::tungstenite::Message;
|
|||
use crate::{Config, BUFFER_LENGTH};
|
||||
const MAX_TOLERATED_MESSAGE_COUNT: usize = 10;
|
||||
|
||||
pub async fn start(sound_stream_consumer: Receiver<f32>, streamer_config:Config) {
|
||||
pub async fn connect(sound_stream_consumer: Receiver<f32>, streamer_config:Config) {
|
||||
let connect_addr =
|
||||
match streamer_config.tls {
|
||||
true => format!("wss://{}", streamer_config.address),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue