Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Jan 21, 2024
1 parent 332f5d5 commit e8207e4
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod ffmpeg;
mod utils;

use axum::{
http::header,
response::{Html, IntoResponse},
routing::get,
Router,
Expand Down Expand Up @@ -87,21 +88,27 @@ async fn main() {
.await
.unwrap_or_else(|_| panic!("tcp listener should bind to {}", cli.http_server_address));

// Configure HTTP server routes
let frame_image = SharedImageData::default();
let frame_image_2 = frame_image.clone();
let app = Router::new()
.route("/player", get(Html(include_str!("player.html"))))
.route(
"/frame.jpg",
get(move || async move {
match frame_image_2.lock().unwrap().as_ref() {
Some(image) => image.clone().into_response(),
None => axum::http::StatusCode::NOT_FOUND.into_response(),
}
}),
)
.nest_service("/", ServeDir::new(config.video_directory.clone()));

// Configure HTTP server routes
let app = {
let frame_image = frame_image.clone();

Router::new()
.route("/player", get(Html(include_str!("player.html"))))
.route(
"/frame.jpg",
get(move || async move {
match frame_image.lock().unwrap().as_ref() {
Some(image) => {
([(header::CONTENT_TYPE, "image/jpeg")], image.clone()).into_response()
}
None => axum::http::StatusCode::NOT_FOUND.into_response(),
}
}),
)
.nest_service("/", ServeDir::new(config.video_directory.clone()))
};

// Start HTTP server
info!("Starting HTTP server on {}", cli.http_server_address);
Expand Down

0 comments on commit e8207e4

Please sign in to comment.