/// <summary>
 /// Call Action with message
 /// </summary>
 /// <param name="name">message name</param>
 /// <param name="message">message value</param>
 public void Send(string name, string message)
 {
     if (messagesListeners.Exists(l => l.Name.Equals(name)))
     {
         var messageListener = messagesListeners.Find(l => l.Name.Equals(name));
         messageListener.onReceiveMessage.Invoke(message);
     }
     else
     {
         defaultListener.Invoke(message);
     }
 }
Пример #2
0
 private void Listen()
 {
     // в бесконечном цикле
     while (true)
     {
         // получаем сообщения от сервера и сохраняем их в очереди
         var message = GetMessage();
         ReceivedMessages.Enqueue(message);
         OnReceiveMessageEvent?.Invoke(message);
     }
 }
        private void HandleMessageForServer(string data)
        {
            var trData = JsonConvert.DeserializeObject <TransportData>(data);

            if (trData.type == TransportDataType.SERVER_COMMAND_LOGIN)
            {
                var command = ServerCommand.FromJson(trData.data);
                clientName = command.clientName;
            }
            else if (trData.type == TransportDataType.CHAT_MESSAGE)
            {
                OnReceiveMessageEvent?.Invoke(trData);
            }
        }
        private void HandleMessageForClient(string data)
        {
            var trData = JsonConvert.DeserializeObject <TransportData>(data);

            if (trData.type == TransportDataType.EXIT)
            {
                server?.DisconnectUser(this);
                CloseConnection();
            }
            else
            {
                OnReceiveMessageEvent?.Invoke(trData);
            }
        }