public static IApplicationBuilder UseSlarkWebSokcetServer(this IApplicationBuilder app, SlarkWebSokcetServer slarkWebSokcetServer) { app.Use(async(context, next) => { if (context.Request.Path != slarkWebSokcetServer.WebSocketRoutePath) { await next.Invoke(); return; } if (!context.WebSockets.IsWebSocketRequest) { context.Response.StatusCode = 400; return; } WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); var connection = await slarkWebSokcetServer.OnWebSocketConnected(context, webSocket); if (connection != null) { await slarkWebSokcetServer.OnWebSocketInvoked(context, connection); } else { context.Response.StatusCode = 404; } }); return(app); }
public SlarkWebSocketClientConnection(SlarkWebSokcetServer server, WebSocket webSocket) { Server = server; WebSocket = webSocket; Id = StringRandom.RandomHexString(16); }