Beispiel #1
0
 /// <summary>
 /// 接收端口信息并处理
 /// </summary>
 /// <param name="message">信息</param>
 private void callBack(string message)
 {
     try
     {
         bool       isVoice    = false;
         UdpMessage udpMessage = UdpMessage.GetUdpMessage(message);
         string     content    = udpMessage.MessageContent;
         if (udpMessage.MessageType == MessageType.Control_Server)
         {
             if (content == "ConnectSuccess")
             {
                 setObj(connectStatusLabel, "连接成功");
                 setObj(functionPanel, true);
             }
             else if (content == "EndVoice")
             {
                 voiceForm.End();
             }
             else if (Regex.IsMatch(content, "Onliner:(.*)"))
             {
                 string name = Regex.Match(content, "Onliner:(.*)").Groups[1].Value.ToString();
                 if ((!onliner.Contains(name)) && (name != user.UserName))
                 {
                     onliner.Add(name);
                 }
                 setObj(onlineUsersComboBox, onliner);
             }
             else if (Regex.IsMatch(content, "ResponseUserInfo:(.*)"))
             {
                 string   Info        = Regex.Match(content, "ResponseUserInfo:(.*)").Groups[1].Value.ToString();
                 object[] objs        = JsonConvert.DeserializeObject <object[]>(Info);
                 string   requestName = objs[0].ToString();
                 string[] ips         = JsonConvert.DeserializeObject <string[]>(objs[1].ToString());
                 foreach (var i in ips)
                 {
                     IPEndPoint ip = new IPEndPoint(IPAddress.Parse(i.Split("|")[1]), int.Parse(i.Split("|")[3]));
                     connectIPs.Add(ip);
                 }
                 setObj(onlineUsersComboBox, false);
                 setObj(communicateButton, false);
                 setObj(communicatePanel, true);
                 if (isVoice)
                 {
                     isVoice = false;
                     if (connectIPs.Count == 4)
                     {
                         voiceForm = new VoiceForm(user, connectIPs, requestName, true);
                         voiceForm.ShowDialog();
                     }
                 }
             }
             else if (Regex.IsMatch(content, "BeReadyForCommunicate:(.*)"))
             {
                 string fromName = Regex.Match(content, "BeReadyForCommunicate:(.*)").Groups[1].Value.ToString();
                 setObj(onlineUsersComboBox, fromName);
                 setObj(onlineUsersComboBox, false);
                 setObj(communicateButton, false);
                 setObj(communicatePanel, true);
             }
             else if (Regex.IsMatch(content, "ReadyToVoiceCommunicate:(.*)"))
             {
                 string fromName = Regex.Match(content, "ReadyToVoiceCommunicate:(.*)").Groups[1].Value.ToString();
                 setObj(onlineUsersComboBox, fromName);
                 setObj(onlineUsersComboBox, false);
                 _sender.Send("RequestUserInfo:" + fromName);
                 isVoice = true;
             }
             else if (Regex.IsMatch(content, "BPlayToARec:(.*)"))
             {
                 string BName = Regex.Match(content, "BPlayToARec:(.*)").Groups[1].Value.ToString();
                 setObj(onlineUsersComboBox, BName);
                 setObj(onlineUsersComboBox, false);
                 voiceForm.ReadyToRecord(connectIPs);
             }
             else if (Regex.IsMatch(content, "APlayToBRec:(.*)"))
             {
                 string AName = Regex.Match(content, "APlayToBRec:(.*)").Groups[1].Value.ToString();
                 setObj(onlineUsersComboBox, AName);
                 setObj(onlineUsersComboBox, false);
                 voiceForm.BPlayer(connectIPs);
             }
         }
         else if (udpMessage.MessageType == MessageType.Communicate)
         {
             string showContent = udpMessage.Receiver + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + content + "\n";
             setObj(showContentRichTextBox, showContent, true);
         }
         else if (udpMessage.MessageType == MessageType.Control_Client)
         {
             if (content == "BPlayToARec")
             {
             }
         }
     }
     catch (ThreadAbortException e)
     {
         Console.WriteLine("线程终止");
         Console.WriteLine(e.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine("error!!");
         Console.WriteLine(e.Message);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 打开语音通话窗口
 /// </summary>
 private void communicateVoiceToolStripButton_Click(object sender, EventArgs e)
 {
     voiceForm = new VoiceForm(user, connectIPs, onlineUsersComboBox.Text);
     voiceForm.ShowDialog();
 }