Implement disconnect specific client ID

This commit is contained in:
Pierre HUBERT 2025-02-11 22:03:16 +01:00
parent b8a8e14f3c
commit bb1e412d36
2 changed files with 14 additions and 2 deletions

View File

@ -64,7 +64,16 @@ pub async fn ws_handler(
};
match msg {
WsMessage::CloseClientSession(_) => todo!(),
WsMessage::CloseClientSession(id) => {
if let Some(client) = &auth.client {
if client.id == id {
log::info!(
"closing client session {id:?} of user {:?} as requested", auth.user.user_id
);
break None;
}
}
},
WsMessage::CloseAllUserSessions(userid) => {
if userid == auth.user.user_id {
log::info!(

View File

@ -138,7 +138,10 @@ pub async fn home(
config.clients.retain(|c| c.id != delete_client_id);
config.save().await?;
success_message = Some("The client was successfully deleted!".to_string());
// TODO : close connections with given id
if let Err(e) = tx.send(WsMessage::CloseClientSession(delete_client_id)) {
log::error!("Failed to send CloseClientSession: {}", e);
}
}
}