Add improved handling of different WebSocket message types

This commit is contained in:
Tobie Morgan Hitchcock 2022-10-19 23:57:05 +01:00
parent f0eaf2bd19
commit 6ff1e250de

View file

@ -102,14 +102,23 @@ impl Rpc {
while let Some(msg) = wrx.next().await { while let Some(msg) = wrx.next().await {
match msg { match msg {
// We've received a message from the client // We've received a message from the client
Ok(msg) => { Ok(msg) => match msg {
if msg.is_ping() { msg if msg.is_ping() => {
let _ = chn.send(Message::pong(vec![])); let _ = chn.send(Message::pong(vec![]));
} }
if msg.is_text() { msg if msg.is_text() => {
tokio::task::spawn(Rpc::call(rpc.clone(), msg, chn.clone())); tokio::task::spawn(Rpc::call(rpc.clone(), msg, chn.clone()));
} }
} msg if msg.is_close() => {
break;
}
msg if msg.is_pong() => {
continue;
}
_ => {
// Ignore everything else
}
},
// There was an error receiving the message // There was an error receiving the message
Err(err) => { Err(err) => {
// Output the WebSocket error to the logs // Output the WebSocket error to the logs