MCPcopy Create free account
hub / github.com/actix/examples / disconnect

Method disconnect

websockets/chat-actorless/src/server.rs:142–162  ·  view source on GitHub ↗

Unregister connection from room map and broadcast disconnection message.

(&mut self, conn_id: ConnId)

Source from the content-addressed store, hash-verified

140
141 /// Unregister connection from room map and broadcast disconnection message.
142 async fn disconnect(&mut self, conn_id: ConnId) {
143 println!("Someone disconnected");
144
145 let mut rooms: Vec<RoomId> = Vec::new();
146
147 // remove sender
148 if self.sessions.remove(&conn_id).is_some() {
149 // remove session from all rooms
150 for (name, sessions) in &mut self.rooms {
151 if sessions.remove(&conn_id) {
152 rooms.push(name.to_owned());
153 }
154 }
155 }
156
157 // send message to other users
158 for room in rooms {
159 self.send_system_message(&room, 0, "Someone disconnected")
160 .await;
161 }
162 }
163
164 /// Returns list of created room names.
165 fn list_rooms(&mut self) -> Vec<RoomId> {

Callers 2

runMethod · 0.80
chat_wsFunction · 0.80

Calls 1

send_system_messageMethod · 0.80

Tested by

no test coverage detected