Link up the App and the AudioController in main.rs
This commit is contained in:
parent
f555804f10
commit
cbe1a90fcb
|
@ -10,7 +10,7 @@ use tokio::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
audio_control::{AudioControl},
|
||||
audio_control::AudioControl,
|
||||
types::{AppError, AudioControlMessage, AudioStatusMessage, TrackInfo, TrackSpec, Volume},
|
||||
};
|
||||
|
||||
|
@ -64,6 +64,7 @@ impl App {
|
|||
state.write().unwrap().playing = true;
|
||||
}
|
||||
Some(AudioStatusMessage::Status(track_status)) => {
|
||||
println!("status: {:?}", track_status);
|
||||
state.write().unwrap().track_status = track_status;
|
||||
}
|
||||
msg => println!("message received from audio controller: {:?}", msg),
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
path::PathBuf,
|
||||
sync::{Arc, RwLock}, time::Duration,
|
||||
sync::{Arc, RwLock},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use gstreamer::{prelude::*, ClockTime, MessageType, MessageView};
|
||||
|
@ -19,10 +20,7 @@ pub enum AudioError {
|
|||
InvalidState,
|
||||
}
|
||||
|
||||
pub struct AudioControl {
|
||||
control_rx: Receiver<AudioControlMessage>,
|
||||
status_tx: Sender<AudioStatusMessage>,
|
||||
}
|
||||
pub struct AudioControl {}
|
||||
|
||||
/*
|
||||
impl Default for AudioControl {
|
||||
|
@ -33,25 +31,13 @@ impl Default for AudioControl {
|
|||
*/
|
||||
|
||||
impl AudioControl {
|
||||
pub fn new() -> (
|
||||
Self,
|
||||
Sender<AudioControlMessage>,
|
||||
Receiver<AudioStatusMessage>,
|
||||
) {
|
||||
let (control_tx, control_rx) = tokio::sync::mpsc::channel(5);
|
||||
let (status_tx, status_rx) = tokio::sync::mpsc::channel(5);
|
||||
(
|
||||
Self {
|
||||
control_rx,
|
||||
status_tx,
|
||||
},
|
||||
control_tx,
|
||||
status_rx,
|
||||
)
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub async fn listen(&mut self) {
|
||||
while let Some(msg) = self.control_rx.recv().await {
|
||||
pub async fn listen(&self, mut control_rx: Receiver<AudioControlMessage>) {
|
||||
println!("waiting for control message");
|
||||
while let Some(msg) = control_rx.recv().await {
|
||||
match msg {
|
||||
AudioControlMessage::Play => {
|
||||
unimplemented!()
|
||||
|
@ -72,13 +58,14 @@ impl AudioControl {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn report(&self) {
|
||||
pub async fn report(&self, status_tx: Sender<AudioStatusMessage>) {
|
||||
loop {
|
||||
self.status_tx
|
||||
println!("sending status message");
|
||||
status_tx
|
||||
.send(AudioStatusMessage::Status(vec![]))
|
||||
.await
|
||||
.expect("to successfully send a message");
|
||||
tokio::time::sleep(Duration::from_secs(1));
|
||||
let _ = tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
use std::{net::{Ipv6Addr, SocketAddrV6}, path::PathBuf, sync::Arc};
|
||||
use std::{
|
||||
net::{Ipv6Addr, SocketAddrV6},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use app::App;
|
||||
use audio_control::AudioControl;
|
||||
use pipewire::{context::Context, main_loop::MainLoop};
|
||||
use serde::Deserialize;
|
||||
use tokio::task::spawn_blocking;
|
||||
use warp::{serve, Filter};
|
||||
|
||||
mod audio_control;
|
||||
mod app;
|
||||
mod audio_control;
|
||||
mod types;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -137,6 +142,15 @@ async fn main() {
|
|||
let (audio_status_tx, audio_status_rx) = tokio::sync::mpsc::channel(5);
|
||||
|
||||
let app = Arc::new(App::new(audio_control_tx, audio_status_rx));
|
||||
let audio_controller = Arc::new(AudioControl::new());
|
||||
tokio::spawn({
|
||||
let audio_controller = audio_controller.clone();
|
||||
async move { audio_controller.listen(audio_control_rx).await }
|
||||
});
|
||||
tokio::spawn({
|
||||
let audio_controller = audio_controller.clone();
|
||||
async move { audio_controller.report(audio_status_tx).await }
|
||||
});
|
||||
|
||||
/*
|
||||
spawn_blocking({
|
||||
|
|
Loading…
Reference in New Issue