Skip to content

Commit

Permalink
Fix channel mark as active when the websocket connection isn't succes…
Browse files Browse the repository at this point in the history
…sful
  • Loading branch information
Angelillo15 committed May 24, 2024
1 parent e6aba42 commit 7f698f7
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/services/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,6 @@ async fn index(
let id = info.uuid.clone();
let channel_manager = app_state.channel_manager.clone();

{
let channel_manager = channel_manager.lock().unwrap();

if !channel_manager.channel_exists(id.clone()) {
return Ok(HttpResponse::NotFound().finish());
}

match Uuid::parse_str(&id) {
Ok(uuid) => {
channel_manager.mark_channel_as_active(uuid);
}
Err(_) => {
error!("Could not parse uuid: {}", id.clone());
return Ok(HttpResponse::NotFound().finish());
}
}
}

let resp = ws::start(
Handler {
app_state: app_state.clone(),
Expand All @@ -150,8 +132,33 @@ async fn index(
stream,
);

debug!("{:?}", resp);
resp
return match resp {
Ok(_) => {
let channel_manager = channel_manager.lock().unwrap();

if !channel_manager.channel_exists(id.clone()) {
return Ok(HttpResponse::NotFound().finish());
}

match Uuid::parse_str(&id) {
Ok(uuid) => {
channel_manager.mark_channel_as_active(uuid);
}
Err(_) => {
error!("Could not parse uuid: {}", id.clone());
return Ok(HttpResponse::NotFound().finish());
}
}

debug!("Connection established: {:?}", id);
debug!("Response: {:?}", resp);
resp
}
Err(e) => {
error!("{:?}", e);
Ok(HttpResponse::from_error(e))
}
}
}

pub fn endpoints(scope: actix_web::Scope) -> actix_web::Scope {
Expand Down

0 comments on commit 7f698f7

Please sign in to comment.