(&mut self, msg: Connect, _: &mut Context<Self>)
| 117 | let id = rand::rng().random::<u64>(); |
| 118 | state.sessions.insert(id, addr); |
| 119 | |
| 120 | // auto join session to main room |
| 121 | state.rooms.entry("main".to_owned()).or_default().insert(id); |
| 122 | |
| 123 | let count = state.visitor_count.fetch_add(1, Ordering::SeqCst); |
| 124 | state.send_message("main", &format!("Total visitors {count}"), 0); |
| 125 | |
| 126 | // send id back |
| 127 | let _ = reply.send(id); |
| 128 | } |
| 129 | Command::Disconnect { id } => { |
| 130 | tracing::info!("Someone disconnected"); |
| 131 | |
| 132 | let mut rooms: Vec<String> = Vec::new(); |
| 133 | |
| 134 | // remove address |
| 135 | if state.sessions.remove(&id).is_some() { |
| 136 | // remove session from all rooms |
| 137 | for (name, sessions) in &mut state.rooms { |
| 138 | if sessions.remove(&id) { |
| 139 | rooms.push(name.to_owned()); |
| 140 | } |
nothing calls this directly
no test coverage detected