Update Websocket to fix premature closing w 1006

This commit is contained in:
kozabrada123 2023-05-06 10:39:58 +02:00
parent 1f8a38545b
commit 45a2dc0b2b
1 changed files with 18 additions and 11 deletions

View File

@ -341,18 +341,25 @@ impl<'a> WebSocketConnection {
let (mut ws_tx, mut ws_rx) = ws_stream.split(); let (mut ws_tx, mut ws_rx) = ws_stream.split();
// Send messages from the send channel loop {
while let Some(msg) = send_channel_read.recv().await {
ws_tx.send(msg).await.unwrap();
}
// Write received messages to the receive channel // Write received messages to the receive channel
while let Some(msg) = ws_rx.next().await { let msg = ws_rx.next().await;
receive_channel_write if msg.as_ref().is_some() {
.send(msg.unwrap()) let msg_unwrapped = msg.unwrap().unwrap();
.await receive_channel_write
.unwrap(); .send(msg_unwrapped)
}; .await
.unwrap();
};
// Send messages from the send channel
let msg = send_channel_read.recv().await;
if msg.as_ref().is_some() {
let msg_unwrapped = msg.unwrap();
ws_tx.send(msg_unwrapped).await.unwrap();
}
}
}); });
WebSocketConnection { WebSocketConnection {