diff --git a/src/Aiursoft.ChessServer/Controllers/HomeController.cs b/src/Aiursoft.ChessServer/Controllers/HomeController.cs index 9377914..171e6ab 100644 --- a/src/Aiursoft.ChessServer/Controllers/HomeController.cs +++ b/src/Aiursoft.ChessServer/Controllers/HomeController.cs @@ -1,6 +1,8 @@ +using Aiursoft.AiurObserver; using Aiursoft.ChessServer.Data; using Aiursoft.ChessServer.Models; using Aiursoft.CSTools.Services; +using Aiursoft.WebTools.Services; using Microsoft.AspNetCore.Mvc; namespace Aiursoft.ChessServer.Controllers; @@ -144,4 +146,30 @@ public class HomeController : Controller } return RedirectToAction(nameof(Index)); } + + public async Task ListenChallenge(int id) + { + var pusher = await HttpContext.AcceptWebSocketClient(); + var challenge = _database.GetChallenge(id); + if (challenge == null) + { + return; + } + var outSub = challenge + .ChallengeChangedChannel + .Subscribe(t => pusher.Send(t, HttpContext.RequestAborted)); + try + { + await pusher.Listen(HttpContext.RequestAborted); + } + catch (TaskCanceledException) + { + // Ignore. This happens when the client closes the connection. + } + finally + { + await pusher.Close(HttpContext.RequestAborted); + outSub.Unsubscribe(); + } + } } \ No newline at end of file diff --git a/src/Aiursoft.ChessServer/Views/Games/GetHtml.cshtml b/src/Aiursoft.ChessServer/Views/Games/GetHtml.cshtml index 6456824..241fc7b 100644 --- a/src/Aiursoft.ChessServer/Views/Games/GetHtml.cshtml +++ b/src/Aiursoft.ChessServer/Views/Games/GetHtml.cshtml @@ -1,5 +1,10 @@ @model int -