feat: ✨ online counter
This commit is contained in:
parent
ab51292439
commit
63bc49ccf6
1 changed files with 7 additions and 1 deletions
|
@ -4,7 +4,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use axum::{Router, http::StatusCode, response::IntoResponse, routing::get};
|
||||
use axum::{Json, Router, http::StatusCode, response::IntoResponse, routing::get};
|
||||
use fastwebsockets::{
|
||||
Frame, OpCode, WebSocketError,
|
||||
upgrade::{IncomingUpgrade, UpgradeFut},
|
||||
|
@ -32,6 +32,7 @@ pub async fn start_signalling() {
|
|||
let router = Router::new()
|
||||
.route("/", get(alive))
|
||||
.route("/signal", get(signal))
|
||||
.route("/count/online", get(online_counter))
|
||||
.layer(CorsLayer::permissive());
|
||||
|
||||
let listener = TcpListener::bind(SERVER_ADDRESS).await.unwrap();
|
||||
|
@ -44,6 +45,11 @@ async fn alive() -> impl IntoResponse {
|
|||
StatusCode::OK
|
||||
}
|
||||
|
||||
async fn online_counter() -> impl IntoResponse {
|
||||
let online_count = ONLINE_USERS.read().await.len();
|
||||
(StatusCode::OK, Json(online_count))
|
||||
}
|
||||
|
||||
async fn signal(websocket: IncomingUpgrade) -> impl IntoResponse {
|
||||
let (response, websocket) = websocket.upgrade().unwrap();
|
||||
tokio::spawn(websocket_handler(websocket));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue