mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-27 04:20:28 +00:00
signalling: send pings at 30-second intervals
Some routers might otherwise time out websocket connections Fixes #58
This commit is contained in:
parent
f6f079f3a8
commit
2c855b9cfe
1 changed files with 22 additions and 3 deletions
|
@ -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?;
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue