Skip to content

Commit

Permalink
fix 1
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed Apr 23, 2024
1 parent e09508a commit 3eb845d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ async fn handle_socket(socket: WebSocket, _who: SocketAddr, state: Arc<AppState>
*USER_ID.lock().unwrap() += 1;
let user_id = USER_ID.lock().unwrap().clone();

let mut user = Arc::new(User::new("".into(), user_id));
let mut user = Arc::new(Mutex::new(User::new("".into(), user_id)));

// We subscribe *before* sending the "joined" message, so that we will also
// display it to our client.
let mut rx = state.tx.subscribe();

// Now send the "joined" message to all subscribers.
let msg = format!("user {0} connected.", user.name);
let msg = format!("user {0} connected.", user.lock().unwrap().name);
tracing::debug!("{msg}");

let msg_vec = (*MESSAGES.lock().unwrap().clone()).to_vec();
Expand Down Expand Up @@ -178,7 +178,7 @@ async fn handle_socket(socket: WebSocket, _who: SocketAddr, state: Arc<AppState>
},
MessageTypes::UserJoin(mut request) => {
/*let _ = state.tx.send(
serde_json::to_string(&(UserJoin { userjoin: user.name.clone() })).expect("")
serde_json::to_string(&(UserJoin { userjoin: user.lock().unwrap().name.clone() })).expect("")
);*/
continue;
}
Expand All @@ -196,10 +196,10 @@ async fn handle_socket(socket: WebSocket, _who: SocketAddr, state: Arc<AppState>
}

// Send "user left" message (similar to "joined" above).
let msg = format!("{0} left.", user.name);
let msg = format!("{0} left.", user.lock().unwrap().name);
tracing::debug!("{msg}");
let _ = state.tx.send(
serde_json::to_string(&(UserLeft { userleft: user.name.clone() })).expect("")
serde_json::to_string(&(UserLeft { userleft: user.lock().unwrap().name.clone() })).expect("")
);

*USER_ID.lock().unwrap() -= 1;
Expand Down

0 comments on commit 3eb845d

Please sign in to comment.