diff --git a/.gitignore b/.gitignore index da719a0..cacc1a2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target/ .vscode/ dist/ certificates/ +audios/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html diff --git a/back/Cargo.toml b/back/Cargo.toml index 30e8c07..5d80e63 100644 --- a/back/Cargo.toml +++ b/back/Cargo.toml @@ -12,4 +12,6 @@ rand = "0.8.5" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" tokio = { version = "1.36.0", features = ["full"] } +#tokio-stream = { version = "0.1.15", features = ["full"] } +tokio-util = { version = "0.7.10", features = ["full"] } tower-http = { version = "0.5.2", features = ["full"] } diff --git a/back/src/routing.rs b/back/src/routing.rs index 8caef3c..3892e00 100644 --- a/back/src/routing.rs +++ b/back/src/routing.rs @@ -1,5 +1,7 @@ use crate::{AppState, ServerStatus, CoinStatus}; -use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router}; +use axum::{body::Body, extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router}; +use tokio::fs::File; +use tokio_util::io::ReaderStream; use tower_http::cors::CorsLayer; use rand::prelude::*; @@ -7,6 +9,7 @@ pub async fn routing(State(state): State) -> Router { Router::new() .route("/", get(alive)) .route("/coin", get(flip_coin)) + .route("/stream", get(stream)) .layer(CorsLayer::permissive()) .with_state(state.clone()) } @@ -32,3 +35,9 @@ async fn flip_coin() -> impl IntoResponse { println!("{}", coin_json); (StatusCode::OK, Json(coin_json)) } + +async fn stream() -> impl IntoResponse { + let file = File::open("audios/audio.mp3").await.unwrap(); + let stream = ReaderStream::new(file); + Body::from_stream(stream) +} \ No newline at end of file diff --git a/front/src/main.rs b/front/src/main.rs index e04a162..675a203 100644 --- a/front/src/main.rs +++ b/front/src/main.rs @@ -77,7 +77,7 @@ fn app() -> Element { page_base {} div { audio{ - src:"https://radioxide.tahinli.com.tr/audios/music.opus", + src:"https://radioxide.tahinli.com.tr:2323/stream", controls:true, autoplay: true, muted:false,