public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(120), ReceiveBufferSize = BUFFER_SIZE }; app.UseWebSockets(webSocketOptions); var deafultLobbyId = Guid.NewGuid(); var deafultLobby = new MessageLobby(deafultLobbyId, new UserLobbyCommandProcessor()); var lobbyCoordinator = new LobbyCoordinator(deafultLobby, new LobbyCoordinatorCommandProcessor()); app.Use(async(context, next) => { if (context.WebSockets.IsWebSocketRequest) { var socket = await context.WebSockets.AcceptWebSocketAsync(); var user = new User(socket, BUFFER_SIZE, deafultLobbyId); deafultLobby.AddUserToLobby(user).GetAwaiter().GetResult(); await lobbyCoordinator.RunUserSession(user); } else { context.Response.StatusCode = 405; } }); }
private async Task AddUserToMessageLobby(IUser user, List <ILobby> lobbies, Guid deafultLobbyId) { await RemoveFromLobby(user, lobbies, deafultLobbyId); var lobbyId = Guid.NewGuid(); var newLobby = new MessageLobby(lobbyId, new UserLobbyCommandProcessor()); await AddToLobby(user, newLobby, lobbyId); lobbies.Add(newLobby); }