public static IApplicationBuilder MapWebSocket( this IApplicationBuilder app, PathString path, ISocketConnection handler, ISocketConnectionManager manager) { return(app.Map(path, _app => _app.UseMiddleware <WebSocketManagerMiddleware>(handler, manager))); }
public WebSocketManagerMiddleware( RequestDelegate next, ISocketConnection handler, ISocketConnectionManager manager) { _next = next; _handler = handler; _manager = manager; }
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); }
public DiagnosticsClient(ISocketConnectionManager manager) { _manager = manager; _contractResolver = new CamelCasePropertyNamesContractResolver(); }
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; }