public async Task InvokeAsync(HttpContext context) { if (context.Request.Headers["Accept"] == "text/event-stream") { context.Response.ContentType = "text/event-stream"; var client = new SseClient(Guid.NewGuid(), context.Response); serverSentEventsServie.AddClient(client); await serverSentEventsServie.SendToAll("Client Connected"); context.RequestAborted.WaitHandle.WaitOne(); serverSentEventsServie.RemoveClient(client); await serverSentEventsServie.SendToAll("Client Disconnected"); } else { await next(context); } }
public async Task <IActionResult> Ping() { await eventService.SendToAll($"Ping received"); return(View()); }