Пример #1
0
        public void Connect(string _username)
        {
            Connection = new HubConnection(BASE_URL, new Dictionary <string, string>
            {
                { "username", _username }
            });

            Proxy = Connection.CreateHubProxy("ChatHub");

            Proxy.On <string, string>("GetMessage", (username, message) =>
            {
                OnGetMessage?.Invoke(username, message);
            });

            Proxy.On <string>("GetMe", (message) =>
            {
                OnGetMyMessage?.Invoke(message);
            });


            Proxy.On <string>("GetInfo", (info) =>
            {
                OnGetInfo?.Invoke(info);
            });

            Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    ConnectionErrorOcurned?.Invoke();
                }
            });
        }
Пример #2
0
 protected void NotifyListener(string message)
 {
     if (message != string.Empty)
     {
         OnGetMessage?.Invoke(message);
     }
 }
Пример #3
0
        //Gets Called When The Server Send Status.Message
        void GetMessage(Message msg)
        {
            switch (msg.Type)
            {
            case MessageType.Global:
                OnGetMessage?.Invoke(msg);
                break;

            case MessageType.Private:
                PrivateChat.GetMessage((Message <int>)msg);
                break;

            case MessageType.Group:
                GroupChat.GetMessage((Message <Guid>)msg);
                break;
            }
        }
Пример #4
0
 private void MessageSender_OnRead(object sender, string e)
 {
     OnGetMessage?.Invoke(sender, e);
 }