Keep connection alive on checkout page by sending ping messages

This commit is contained in:
nicolas.dorier
2021-10-05 13:37:30 +09:00
parent a32ace1dcb
commit dea747a9a9
2 changed files with 5 additions and 2 deletions

View File

@@ -654,7 +654,7 @@ namespace BTCPayServer.Controllers
[Route("invoice/{invoiceId}/status/ws")]
[Route("invoice/{invoiceId}/{paymentMethodId}/status")]
[Route("invoice/status/ws")]
public async Task<IActionResult> GetStatusWebSocket(string invoiceId)
public async Task<IActionResult> GetStatusWebSocket(string invoiceId, CancellationToken cancellationToken)
{
if (!HttpContext.WebSockets.IsWebSocketRequest)
return NotFound();
@@ -670,7 +670,7 @@ namespace BTCPayServer.Controllers
leases.Add(_EventAggregator.Subscribe<Events.InvoiceEvent>(async o => await NotifySocket(webSocket, o.Invoice.Id, invoiceId)));
while (true)
{
var message = await webSocket.ReceiveAsync(DummyBuffer, default(CancellationToken));
var message = await webSocket.ReceiveAndPingAsync(DummyBuffer, default(CancellationToken));
if (message.MessageType == WebSocketMessageType.Close)
break;
}