mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
Keep websocket connection alive on notifications and vault
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.WebSockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Abstractions.Constants;
|
using BTCPayServer.Abstractions.Constants;
|
||||||
@@ -69,14 +70,15 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
await websocketHelper.NextMessageAsync(cancellationToken);
|
||||||
{
|
|
||||||
await Task.Delay(2000, cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
{
|
{
|
||||||
// ignored
|
// ignored
|
||||||
|
}
|
||||||
|
catch (WebSocketException)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ wait:
|
|||||||
if (completed == waiting)
|
if (completed == waiting)
|
||||||
{
|
{
|
||||||
await webSocket.SendAsync(Encoding.UTF8.GetBytes("ping"), WebSocketMessageType.Text, true, cancellationToken);
|
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;
|
goto wait;
|
||||||
}
|
}
|
||||||
return receiving.Result;
|
return await receiving;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user