parent
0fd67e0c6e
commit
a1f7b3ab52
5 changed files with 32 additions and 849 deletions
793
Cargo.lock
generated
793
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,21 +6,13 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1.83"
|
async-trait = "0.1.83"
|
||||||
atoi_radix10 = "0.0.1"
|
atoi_radix10 = "0.0.1"
|
||||||
axum = { version = "0.7.7", features = ["ws"] }
|
|
||||||
axum-extra = { version = "0.9.4", features = ["typed-header"] }
|
|
||||||
bytes = "1.6.0"
|
bytes = "1.6.0"
|
||||||
chrono = "0.4.38"
|
chrono = "0.4.38"
|
||||||
debug_print = "1.0.0"
|
debug_print = "1.0.0"
|
||||||
futures = "0.3.31"
|
|
||||||
futures-util = { version = "0.3.31", features = ["sink", "std"] }
|
|
||||||
headers = "0.4.0"
|
|
||||||
image = "0.25.2"
|
image = "0.25.2"
|
||||||
rand = "*"
|
rand = "*"
|
||||||
tokio = { version = "1.38", features = ["full"] }
|
tokio = { version = "1.38", features = ["full"] }
|
||||||
tokio-test = "*"
|
tokio-test = "*"
|
||||||
tower-http = { version = "0.6.1", features = ["fs", "trace"] }
|
|
||||||
tracing = "0.1.40"
|
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "*"
|
tempfile = "*"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ pub mod flutclient;
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
pub mod protocols;
|
pub mod protocols;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod webapi;
|
|
||||||
|
|
||||||
mod color;
|
mod color;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ use flurry::{
|
||||||
COUNTER,
|
COUNTER,
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
|
||||||
net::TcpListener,
|
net::TcpListener,
|
||||||
time::interval
|
time::{interval, sleep, timeout, Instant},
|
||||||
};
|
};
|
||||||
type Never = Infallible;
|
type Never = Infallible;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
use axum::{
|
|
||||||
extract::{ws::{Message, WebSocket, WebSocketUpgrade}, ConnectInfo},
|
|
||||||
response::IntoResponse,
|
|
||||||
routing::any,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
use axum_extra::TypedHeader;
|
|
||||||
use futures::StreamExt;
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
||||||
use tower_http::{
|
|
||||||
services::ServeDir,
|
|
||||||
trace::{DefaultMakeSpan, TraceLayer},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async fn serve() {
|
|
||||||
// diagnostics
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(
|
|
||||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
|
||||||
format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into()
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.with(tracing_subscriber::fmt::layer())
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let app = Router::new()
|
|
||||||
.route("/imgstream", any(ws_handler))
|
|
||||||
// logging middleware
|
|
||||||
.layer(
|
|
||||||
TraceLayer::new_for_http()
|
|
||||||
.make_span_with(DefaultMakeSpan::default().include_headers(true)),
|
|
||||||
);
|
|
||||||
|
|
||||||
// run it with hyper
|
|
||||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
tracing::debug!("listening on {}", listener.local_addr().unwrap());
|
|
||||||
|
|
||||||
axum::serve(
|
|
||||||
listener,
|
|
||||||
app.into_make_service_with_connect_info::<SocketAddr>(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fn ws_handler(
|
|
||||||
ws: WebSocketUpgrade,
|
|
||||||
user_agent: Option<TypedHeader<headers::UserAgent>>,
|
|
||||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let user_agent = if let Some(TypedHeader(user_agent)) = user_agent {
|
|
||||||
user_agent.to_string()
|
|
||||||
} else {
|
|
||||||
String::from("Unknown browser")
|
|
||||||
};
|
|
||||||
println!("`{user_agent}` at {addr} connected.");
|
|
||||||
|
|
||||||
// finalize the upgrade process by returning upgrade callback.
|
|
||||||
// we can customize the callback by sending additional info such as address.
|
|
||||||
ws.on_upgrade(move |socket| img_stream(socket, addr))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn img_stream(mut socket: WebSocket, who: SocketAddr) {
|
|
||||||
let (mut sender, mut receiver) = socket.split();
|
|
||||||
|
|
||||||
while true {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue