Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions signalling/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,25 @@ impl Server {
let this_id_clone = this_id.clone();
let (mut ws_sink, mut ws_stream) = ws.split();
let send_task_handle = task::spawn(async move {
while let Some(msg) = websocket_receiver.next().await {
trace!(this_id = %this_id_clone, "sending {}", msg);
ws_sink.send(WsMessage::Text(msg)).await?;
loop {
match async_std::future::timeout(
std::time::Duration::from_secs(30),
websocket_receiver.next(),
)
.await
{
Ok(Some(msg)) => {
trace!(this_id = %this_id_clone, "sending {}", msg);
ws_sink.send(WsMessage::Text(msg)).await?;
}
Ok(None) => {
break;
}
Err(_) => {
trace!(this_id = %this_id_clone, "timeout, sending ping");
ws_sink.send(WsMessage::Ping(vec![])).await?;
}
}
}

ws_sink.send(WsMessage::Close(None)).await?;
Expand All @@ -153,6 +169,9 @@ impl Server {
info!(this_id = %this_id_clone, "connection closed: {:?}", reason);
break;
}
Ok(WsMessage::Pong(_)) => {
continue;
}
Ok(_) => warn!(this_id = %this_id_clone, "Unsupported message type"),
Err(err) => {
warn!(this_id = %this_id_clone, "recv error: {}", err);
Expand Down