public override async Task OnConnected(HttpContext context, WebSocket socket) { string name = "Nome"; if (!string.IsNullOrEmpty(name) && salaService.GetPlayers().Count < 6) { WebSocketConnectionManager.AddSocket(socket); var jogador = salaService.AdicionarJogador(WebSocketConnectionManager.GetId(socket), name); await SendMessageAsync(WebSocketConnectionManager.GetId(socket), JsonConvert.SerializeObject(jogador.ToJogadorViewItem())); // await GetPlayers(); } }
public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer) { string message = Encoding.UTF8.GetString(buffer, 0, result.Count); var comandPayload = message.Split("|"); if (comandPayload.Count() == 2) { if (comandPayload[0].Contains("pronto")) { salaService.SetReady(WebSocketConnectionManager.GetId(socket)); await GetPlayers(); } else { await SendMessageToAllAsync(message); } } }
public WebSocketHandler(WebSocketConnectionManager webSocketConnectionManager) { WebSocketConnectionManager = webSocketConnectionManager; }
public RoomHandler(WebSocketConnectionManager webSocketConnectionManager, ISalaService salaService) : base(webSocketConnectionManager) { this.salaService = salaService; }