(&mut self, msg: Message)
| 145 | } |
| 146 | |
| 147 | async fn handle_ws_message(&mut self, msg: Message) -> WsResult { |
| 148 | match msg { |
| 149 | Message::Text(s) => { |
| 150 | let cmd: WsCommand = |
| 151 | serde_json::from_str(&s).map_err(|_| WsCloseReason::JsonDecodeError)?; |
| 152 | self.handle_ws_command(cmd).await |
| 153 | } |
| 154 | Message::Binary(b) => { |
| 155 | let cmd: WsCommand = |
| 156 | serde_json::from_slice(&b).map_err(|_| WsCloseReason::JsonDecodeError)?; |
| 157 | self.handle_ws_command(cmd).await |
| 158 | } |
| 159 | Message::Ping(d) => self.send(Message::Pong(d)).await, |
| 160 | Message::Pong(_) => Ok(()), |
| 161 | Message::Close(_) => Err(WsCloseReason::ClientDisconnected), |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | async fn handle_ws_command(&mut self, cmd: WsCommand) -> WsResult { |
| 166 | match &self.state { |
no test coverage detected