private async Task SendingMessage(string messageInput)
        {
            try
            {
                // Obteniendo usuario de LocalStorage
                var us         = LocalStorage.Get <Usuario>("usuario");
                var enroladoID = LocalStorage.Get("enroladoID");
                var salaID     = LocalStorage.Get("salaID");

                DateTime        dateTime = DateTime.Now;
                ChatTracebility message  = new ChatTracebility()
                {
                    AtDate     = dateTime,
                    Message    = messageInput,
                    UserName   = us.Name,
                    UserID     = us.UID,
                    enroladoId = int.Parse($"{enroladoID}")
                };

                // Enviando mensaje por WS
                await chatTracebilityProvider.AddAsync(client, message);

                // Escuchando mensajes por WS
                Receiving();
            }
            catch (System.Exception)
            {
                Console.WriteLine("El Usuario no se ha unido aún");
            }
        }
        public async Task <IActionResult> AddAsync(ChatTracebility chatTracebility)
        {
            if (chatTracebility == null)
            {
                return(BadRequest());
            }

            var result = await chatTracebilityProvider.AddAsync(chatTracebility);

            if (result)
            {
                return(Ok(result));
            }

            return(NotFound());
        }
Exemple #3
0
        public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            // Getting Socket ID
            var socketId = WebSocketConnectionManager.GetId(socket);

            Console.WriteLine(" ---------- socketId: " + socketId);

            // Converte byte to String
            var messageReceived = Encoding.UTF8.GetString(buffer, 0, result.Count);

            // Deserialize content with fastest seserializer included in .NET 3.0
            // Looks for more info https://www.newtonsoft.com/json
            var message = JsonConvert.DeserializeObject <ChatTracebility>(messageReceived);

            await chatTracebilityProvider.AddAsync(message);

            Console.WriteLine(" ------------------ Back receive: " + message);

            // Send Message another users on the room
            await SendMessageToAllAsync(messageReceived);

            // await SendMessageAsync(messageReceived);
        }