From 6ff1e250de7e5d942f30c742b3173f82effc89c0 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 19 Oct 2022 23:57:05 +0100 Subject: [PATCH] Add improved handling of different WebSocket message types --- src/net/rpc.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/net/rpc.rs b/src/net/rpc.rs index 27b2d277..33ddc581 100644 --- a/src/net/rpc.rs +++ b/src/net/rpc.rs @@ -102,14 +102,23 @@ impl Rpc { while let Some(msg) = wrx.next().await { match msg { // We've received a message from the client - Ok(msg) => { - if msg.is_ping() { + Ok(msg) => match msg { + msg if msg.is_ping() => { 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())); } - } + msg if msg.is_close() => { + break; + } + msg if msg.is_pong() => { + continue; + } + _ => { + // Ignore everything else + } + }, // There was an error receiving the message Err(err) => { // Output the WebSocket error to the logs