Keep websocket connection alive on notifications and vault

This commit is contained in:
nicolas.dorier
2021-10-05 14:29:49 +09:00
parent 5c8e62bd90
commit b0ef98dd63
2 changed files with 8 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
@@ -69,14 +70,15 @@ namespace BTCPayServer.Controllers
}
});
while (!cancellationToken.IsCancellationRequested)
{
await Task.Delay(2000, cancellationToken);
}
await websocketHelper.NextMessageAsync(cancellationToken);
}
catch (TaskCanceledException)
{
// ignored
}
catch (WebSocketException)
{
}
finally
{

View File

@@ -23,10 +23,10 @@ wait:
if (completed == waiting)
{
await webSocket.SendAsync(Encoding.UTF8.GetBytes("ping"), WebSocketMessageType.Text, true, cancellationToken);
waiting = Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);
waiting = Task.Delay(TimeSpan.FromSeconds(25), cancellationToken);
goto wait;
}
return receiving.Result;
return await receiving;
}
}
}