public async Task SubscribeClient(int eventUserID)
        {
            // int eventUserID = Request.GetUserID();
            // int eventUserID = 1;

            _httpContextAccessor.HttpContext.Response.ContentType = "text/event-stream";
            _httpContextAccessor.HttpContext.Response.Body.Flush();

            SseClient client   = new SseClient(_httpContextAccessor.HttpContext.Response, eventUserID);
            Guid      clientId = _sseService.AddClient(client);

            _httpContextAccessor.HttpContext.RequestAborted.WaitHandle.WaitOne();

            _sseService.RemoveClient(clientId);


            await Task.FromResult(true);
        }
Example #2
0
        // Test subscribe
        public Task Invoke(HttpContext context)
        {
            if (context.Request.Headers["Accept"] == "text/event-stream")
            {
                context.Response.ContentType = "text/event-stream";
                context.Response.Body.Flush();

                SseClient client   = new SseClient(context.Response, 1);
                Guid      clientId = _sseService.AddClient(client);

                context.RequestAborted.WaitHandle.WaitOne();

                _sseService.RemoveClient(clientId);

                return(Task.FromResult(true));
            }
            else
            {
                return(_next(context));
            }
        }