Example #1
0
 public static IApplicationBuilder MapWebSocket(
     this IApplicationBuilder app,
     PathString path,
     ISocketConnection handler,
     ISocketConnectionManager manager)
 {
     return(app.Map(path, _app => _app.UseMiddleware <WebSocketManagerMiddleware>(handler, manager)));
 }
Example #2
0
 public WebSocketManagerMiddleware(
     RequestDelegate next,
     ISocketConnection handler,
     ISocketConnectionManager manager)
 {
     _next    = next;
     _handler = handler;
     _manager = manager;
 }
Example #3
0
        public async Task InvokeAsync(HttpContext context, ISocketConnectionManager socketConnectionManager)
        {
            if (context.Request.Path == "/ws")
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    var socket = await context.WebSockets.AcceptWebSocketAsync();

                    var socketFinishedTcs = new TaskCompletionSource <object>();

                    socketConnectionManager.TryAddSocket(new WebSocketItem(Guid.NewGuid(), socket, socketFinishedTcs));

                    await socketFinishedTcs.Task;
                }
                else
                {
                    context.Response.StatusCode = 400;
                }
            }

            await _next(context);
        }
Example #4
0
 public DiagnosticsClient(ISocketConnectionManager manager)
 {
     _manager          = manager;
     _contractResolver = new CamelCasePropertyNamesContractResolver();
 }
Example #5
0
        private float RamThreshold = 7000;          // this is random MB threshold, would be better to set it based on machine's physical RAM

        public BackgroundSocketService(ISocketConnectionManager webSocketManager, MonitorService monitorService)
        {
            _webSocketManager = webSocketManager;
            _monitorService   = monitorService;
        }