feat: 💄 first gui for streamer

fix: 🚑 oneshot fail in listener socket
This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-04-27 15:36:28 +03:00
parent c404f5b23f
commit 21d8781188
7 changed files with 67 additions and 16 deletions

View file

@ -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
View 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)
}
}

View file

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

View file

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

View file

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

View file

@ -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),