mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-14 05:05:35 +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 this_id_clone = this_id.clone();
|
||||||
let (mut ws_sink, mut ws_stream) = ws.split();
|
let (mut ws_sink, mut ws_stream) = ws.split();
|
||||||
let send_task_handle = task::spawn(async move {
|
let send_task_handle = task::spawn(async move {
|
||||||
while let Some(msg) = websocket_receiver.next().await {
|
loop {
|
||||||
trace!(this_id = %this_id_clone, "sending {}", msg);
|
match async_std::future::timeout(
|
||||||
ws_sink.send(WsMessage::Text(msg)).await?;
|
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?;
|
ws_sink.send(WsMessage::Close(None)).await?;
|
||||||
|
@ -153,6 +169,9 @@ impl Server {
|
||||||
info!(this_id = %this_id_clone, "connection closed: {:?}", reason);
|
info!(this_id = %this_id_clone, "connection closed: {:?}", reason);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Ok(WsMessage::Pong(_)) => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Ok(_) => warn!(this_id = %this_id_clone, "Unsupported message type"),
|
Ok(_) => warn!(this_id = %this_id_clone, "Unsupported message type"),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(this_id = %this_id_clone, "recv error: {}", err);
|
warn!(this_id = %this_id_clone, "recv error: {}", err);
|
||||||
|
|
Loading…
Reference in a new issue