Method is called on actor start. We register ws session with ChatServer
(&mut self, ctx: &mut Self::Context)
| 62 | } |
| 63 | |
| 64 | outgoing = inbox.recv() => { |
| 65 | match outgoing { |
| 66 | Some(text) => if session.text(text).await.is_err() { break None; }, |
| 67 | None => break None, |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | _ = timer.tick() => { |
| 72 | if heartbeat.elapsed() > CLIENT_TIMEOUT || session.ping(b"").await.is_err() { |
| 73 | break None; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | let _ = server.cast(Command::Disconnect { id }); |
| 80 | |
| 81 | // A slow peer must not hold up shutdown while the close frame is queued. |
| 82 | let _ = session.close(reason).timeout(Duration::from_secs(1)).await; |
| 83 | } |
| 84 | |
| 85 | async fn process_text( |
| 86 | server: &ActorRef<Command>, |
| 87 | session: &mut actix_ws::Session, |
| 88 | id: u64, |
| 89 | room: &mut String, |
| 90 | name: &mut Option<String>, |
| 91 | text: &str, |