From ceb35e58ce9c64e5058130073a3c40e9fa44f494 Mon Sep 17 00:00:00 2001 From: Yannick Funk Date: Mon, 23 Aug 2021 14:22:23 +0200 Subject: [PATCH] Parse ws spec ping messages --- src/notifications/events.rs | 4 ++++ src/notifications/websocket.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/notifications/events.rs b/src/notifications/events.rs index 74b55755..8a304878 100644 --- a/src/notifications/events.rs +++ b/src/notifications/events.rs @@ -36,6 +36,7 @@ pub enum ServerboundNotification { Authenticate(AuthType), BeginTyping { channel: String }, EndTyping { channel: String }, + Ping { data: Vec } } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -180,6 +181,9 @@ pub enum ClientboundNotification { id: String, update: Value, }, + Pong { + data: Vec + } } impl ClientboundNotification { diff --git a/src/notifications/websocket.rs b/src/notifications/websocket.rs index 66322407..76123732 100644 --- a/src/notifications/websocket.rs +++ b/src/notifications/websocket.rs @@ -81,7 +81,7 @@ async fn accept(stream: TcpStream) { .peer_addr() .expect("Connected streams should have a peer address."); let (sender, receiver) = oneshot::channel::(); - + let ws_stream = async_tungstenite::accept_hdr_async_with_config(stream, HeaderCallback { sender }, None) .await .expect("Error during websocket handshake."); @@ -120,6 +120,7 @@ async fn accept(stream: TcpStream) { let maybe_decoded = match msg { Message::Text(text) => serde_json::from_str::(&text).map_err(|e| e.to_string()), Message::Binary(vec) => rmp_serde::decode::from_read::<&[u8], ServerboundNotification>(vec.as_slice()).map_err(|e| e.to_string()), + Message::Ping(vec) => Ok(ServerboundNotification::Ping { data: vec }), _ => return Ok(()) }; @@ -296,6 +297,9 @@ async fn accept(stream: TcpStream) { return Ok(()); } } + ServerboundNotification::Ping { data } => { + info!("Ping received from User {}. Payload: {:?}", &addr, data); + } } Ok(()) });