Esempio n. 1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         var response = _webApiClient.Account.Login(new LoginRequest()
         {
             UserID = tbUserID.Text, Password = tbPassword.Text
         });
         AppendLine($"User `{tbUserID.Text}` logged in.");
         tbSessionID.Text = response.SessionID;
         _chatClient      = new ChatClientModule($"http://{_config.ServerIP}:{_config.ChatPort}/", tbUserID.Text, response.SessionID);
         _chatClient.Hub.SubscribeOn <MessageParam>(c => c.Message, msg =>
         {
             Invoke(() =>
             {
                 ConversationForm form = StartConversation(msg.SenderUserID);
                 form.AppendMessageFromOtherUser(msg.Message);
             });
         });
         _chatClient.Hub.SubscribeOn <ClientListParam>(c => c.ClientList, msg =>
         {
             Invoke(() => FillUserList(msg.Clients));
         });
         _voipClient = new VoipClientModule(_config.ServerIP, _config.SipPort);
         _voipClient.PhoneStateChanged += VoipClientOnPhoneStateChanged;
         _voipClient.Register(tbUserID.Text, tbSessionID.Text);
         SetControlsToLoginState(true);
     }
     catch (WebApiException ex)
     {
         AppendLine($"Could not log in: {ex.ResponseCode} {ex.ResponseMessage}");
     }
 }
Esempio n. 2
0
        private ConversationForm StartConversation(string person)
        {
            ConversationForm chatForm = null;

            Invoke(() =>
            {
                chatForm = _forms.GetOrAdd(person, _ =>
                {
                    var form       = new ConversationForm(tbUserID.Text, person, tbPassword.Text, _voipClient);
                    _forms[person] = form;
                    var msgSent    = new Action <string>(msg =>
                    {
                        _chatClient.Hub.Call(c => c.SendMessage(new SendMessageParam()
                        {
                            DestinationUserID = person,
                            Message           = msg
                        }));
                    });
                    form.MessageSent += msgSent;
                    form.Closed      += (sender, args) =>
                    {
                        form.MessageSent -= msgSent;
                        ConversationForm tmp;
                        _forms.TryRemove(person, out tmp);
                    };
                    form.Show();
                    return(form);
                });
                chatForm.BringToFront();
            });
            return(chatForm);
        }