feat: get online users

This commit is contained in:
Ahmet Kaan Gümüş 2025-05-12 04:54:34 +03:00
parent 63bc49ccf6
commit 00c46240ba

View file

@ -32,7 +32,8 @@ pub async fn start_signalling() {
let router = Router::new()
.route("/", get(alive))
.route("/signal", get(signal))
.route("/count/online", get(online_counter))
.route("/users/online", get(online_users))
.route("/count/users/online", get(online_counter))
.layer(CorsLayer::permissive());
let listener = TcpListener::bind(SERVER_ADDRESS).await.unwrap();
@ -45,6 +46,16 @@ async fn alive() -> impl IntoResponse {
StatusCode::OK
}
async fn online_users() -> impl IntoResponse {
let online_users = ONLINE_USERS
.read()
.await
.iter()
.map(|user_message| user_message.user.to_owned())
.collect::<Vec<_>>();
(StatusCode::OK, Json(online_users))
}
async fn online_counter() -> impl IntoResponse {
let online_count = ONLINE_USERS.read().await.len();
(StatusCode::OK, Json(online_count))