feat: ✨ get online users
This commit is contained in:
parent
63bc49ccf6
commit
00c46240ba
1 changed files with 12 additions and 1 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue