augmented websocket push to contain the type of the message conditionally

This commit is contained in:
commercium-sys 2023-12-25 17:35:46 -05:00
parent 5e9ea796ed
commit d536cd116f
2 changed files with 16 additions and 2 deletions

View File

@ -651,6 +651,18 @@ async fn maintain_websocket(
match read {
Some(Ok(msg)) => {
let ws_msg_type = if msg.is_text() {
WsMessageType::Text
} else if msg.is_binary() {
WsMessageType::Binary
} else if msg.is_ping() {
WsMessageType::Ping
} else if msg.is_pong() {
WsMessageType::Pong
} else {
WsMessageType::Close
};
let _ = send_to_loop.send(KernelMessage {
id: rand::random(),
source: Address {
@ -667,7 +679,7 @@ async fn maintain_websocket(
expects_response: None,
ipc: serde_json::to_vec(&HttpServerRequest::WebSocketPush {
channel_id,
message_type: WsMessageType::Binary,
message_type: ws_msg_type,
}).unwrap(),
metadata: Some("ws".into()),
}),
@ -1003,7 +1015,8 @@ async fn handle_app_message(
} else {
warp::ws::Message::pong(payload.bytes)
}
}
},
WsMessageType::Close => { unreachable!(); }
};
// Send to the websocket if registered
if let Some(got) = ws_senders.get(&channel_id) {

View File

@ -149,6 +149,7 @@ pub enum WsMessageType {
Binary,
Ping,
Pong,
Close,
}
/// Part of the Response type issued by http_server