2023-03-13 16:18:32 +00:00
|
|
|
use miette::{Context, IntoDiagnostic, Result};
|
|
|
|
use std::{net::SocketAddr, sync::Arc};
|
2023-03-13 15:48:33 +00:00
|
|
|
|
2023-03-13 16:18:32 +00:00
|
|
|
use axum::{routing, Router};
|
2023-03-13 15:48:33 +00:00
|
|
|
use tower_http::{
|
|
|
|
cors::{Any, CorsLayer},
|
|
|
|
trace::TraceLayer,
|
|
|
|
};
|
|
|
|
|
2023-03-13 16:18:32 +00:00
|
|
|
mod streams;
|
|
|
|
mod util;
|
|
|
|
mod wish;
|
2023-03-13 15:48:33 +00:00
|
|
|
|
2023-03-13 16:18:32 +00:00
|
|
|
use crate::wish::{setup_webrtc, whep::handle_whep, whip::handle_whip};
|
2023-03-13 15:48:33 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
2023-03-13 16:18:32 +00:00
|
|
|
pub struct AppState {
|
|
|
|
pub webrtc: Arc<webrtc::api::API>,
|
|
|
|
pub db: Arc<&'static str>,
|
2023-03-13 15:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
2023-03-13 16:18:32 +00:00
|
|
|
let webrtc = Arc::new(setup_webrtc()?);
|
|
|
|
let app_state = AppState {
|
|
|
|
webrtc,
|
|
|
|
db: Arc::new("ooo weee i'm the data base!!!"), // TODO: sqlx
|
|
|
|
};
|
2023-03-13 15:48:33 +00:00
|
|
|
|
|
|
|
let app = Router::new()
|
|
|
|
.route("/api/wish-server/whip", routing::any(handle_whip))
|
|
|
|
.route("/api/wish-server/whep", routing::any(handle_whep))
|
|
|
|
.layer(TraceLayer::new_for_http())
|
|
|
|
.layer(
|
|
|
|
CorsLayer::new()
|
|
|
|
.allow_methods(Any)
|
|
|
|
.allow_origin(Any)
|
|
|
|
.allow_headers(Any),
|
|
|
|
)
|
2023-03-13 16:18:32 +00:00
|
|
|
.with_state(app_state);
|
2023-03-13 15:48:33 +00:00
|
|
|
|
|
|
|
let bind_addr: SocketAddr = "127.0.0.1:3001"
|
|
|
|
.parse()
|
|
|
|
.into_diagnostic()
|
|
|
|
.wrap_err("Couldn't parse bind address")?;
|
|
|
|
|
|
|
|
println!("Listening at http://{bind_addr}/ ...");
|
|
|
|
|
|
|
|
axum::Server::bind(&bind_addr)
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|