Fix handling of the close event

This commit is contained in:
Dominik Nakamura 2021-11-24 22:15:10 +09:00
parent 98983b472d
commit 0db0b0058b
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910

View File

@ -206,19 +206,15 @@ impl Client {
let handle = tokio::spawn(async move {
while let Some(Ok(msg)) = read.next().await {
if msg.is_close() {
#[cfg(feature = "events")]
events_tx.send(Event::ServerStopping).ok();
continue;
}
trace!("{}", msg);
let res: Result<(), InnerError> = async {
let text = msg.into_text().map_err(InnerError::IntoText)?;
let text = if text == "Server stopping" {
debug!("Websocket server is stopping");
let event = serde_json::json! {{
"messageType": "Event",
"eventType": "ServerStopping"
}};
event.to_string()
} else {
text
};
let message = serde_json::from_str::<ServerMessage>(&text)
.map_err(InnerError::DeserializeMessage)?;