Exemplo n.º 1
0
        private void AudioIcon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string srcId    = App.user.userName;
            string destId   = chatViewModel.selectedChatRoom.id;
            string targetIP = chatViewModel.selectedChatRoom.addressInfo.IPAddress;

            byte[] data = AppProtocol.PackControl(AppProtocol.ControlType.QAUDIO, srcId, destId);

            P2PSender.getInstance().SendData(data, targetIP, P2PListener.GENERALLISTENPORT);
            var audio = new Audio(targetIP);

            audioWindow = new audioWindow(audio);
            audioWindow.Show();
        }
Exemplo n.º 2
0
        // 控制报文的发送散落于音视频会话,群聊创建等有需要的过程中
        // --------------------------- 收到控制报文 -------------------------

        private void RecvControl(byte[] newData)
        {
            string srcId    = null;
            string destId   = null;
            string optional = null;
            var    ctype    = AppProtocol.UnPackControl(newData, ref srcId, ref destId, ref optional);

            if (ctype == AppProtocol.ControlType.NEWGROUP)
            {
                App.addressBook.items.Add(new Model.AddressBook.Item()
                {
                    UserName = srcId, GroupUserName = optional.Split(';'), Alias = srcId, isGroup = true
                });
                return;
            }

            string targetIP = null;

            foreach (var item in chatViewModel.chatRoomViewModels)
            {
                if (item.addressInfo.UserName == srcId)
                {
                    targetIP = item.addressInfo.IPAddress;
                }
            }
            targetIP = chatViewModel.chatRoomViewModels[0].addressInfo.IPAddress; // debugTemp
            if (targetIP == null)                                                 // 收到非好友视频邀请不处理
            {
                return;
            }

            switch (ctype)
            {
            case AppProtocol.ControlType.QAUDIO:
                var result = MessageBox.Show($"{srcId}邀请您进行音频聊天,是否接受?", "新音频邀请", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    P2PSender.getInstance().SendData(AppProtocol.PackControl(AppProtocol.ControlType.RAUDIO, destId, srcId), targetIP, P2PListener.GENERALLISTENPORT);
                }
                else
                {
                    P2PSender.getInstance().SendData(AppProtocol.PackControl(AppProtocol.ControlType.AAUDIO, destId, srcId), targetIP, P2PListener.GENERALLISTENPORT);
                    var audio = new Audio(targetIP);
                    audioWindow = new audioWindow(audio);
                    audioWindow.Show();
                }
                break;

            case AppProtocol.ControlType.AAUDIO:

                break;

            case AppProtocol.ControlType.RAUDIO:
                audioWindow.audio.isChatting = false;
                audioWindow.Close();
                break;

            case AppProtocol.ControlType.QVIDEO:
                result = MessageBox.Show($"{srcId}邀请您进行视频聊天,是否接受?", "新视频邀请", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    P2PSender.getInstance().SendData(AppProtocol.PackControl(AppProtocol.ControlType.RVIDEO, destId, srcId), targetIP, P2PListener.GENERALLISTENPORT);
                }
                else
                {
                    P2PSender.getInstance().SendData(AppProtocol.PackControl(AppProtocol.ControlType.AVIDEO, destId, srcId), targetIP, P2PListener.GENERALLISTENPORT);
                    var video       = new Video(targetIP);
                    var videoWindow = new videoWindow(video);
                    videoWindow.Show();
                }
                break;

            case AppProtocol.ControlType.AVIDEO:

                break;

            case AppProtocol.ControlType.RVIDEO:
                videoWindow.video.isReject = true;
                videoWindow.Close();
                MessageBox.Show("对方拒绝了你的视频邀请");
                break;

            default:
                break;
            }
        }