Пример #1
0
//播放视频
        private void showViewRtsp(string rtspAddess)
        {
            //throw new NotImplementedException();
            this.Invoke(new Action(() =>
            {
                ViewRtsp f = new ViewRtsp(rtspAddess);
                f.Show();
                vrForm = f;
                f.startPlay();
            }));
        }
Пример #2
0
//对接收消息的处理函数
        void clientConnect_MessageReceived(TcpConnectJson.Messages msg)
        {
            messageList.Invoke(messageCallback, string.Format("{0}:{1}:{2}", tcpclient.Client.RemoteEndPoint, msg.order, msg.content));
            switch (msg.order)
            {
            case OrderBySev.loginRepeatShutdown:      //教师端重复登录
                this.BeginInvoke(new DoSomething(delegate()
                {
                    MessageBox.Show("当前教师端已有多个!您将被迫下线", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Application.Exit();
                }));
                break;

            case OrderByStu.alreadyPushVideo:    //监视学生端
                //MessageBox.Show("教师端收到命令");
                this.BeginInvoke(new DoSomething(delegate()
                {
                    ViewRtsp f = new ViewRtsp(msg.content, screenmonitor, msg.ipSend, msg.portSend);
                    //Thread th = new Thread(new ThreadStart(f.Show));
                    //th.Start();
                    vrForm = f;
                    f.Show();
                    f.startPlay();
                }));
                break;

            case OrderByStu.prepareForInteract:    //学生演示
                showViewRtsp(msg.content);
                break;

            case OrderByTec.stopStudentInteract:    //停止学生演示
                this.Invoke(new Action(() =>
                {
                    if (vrForm != null)
                    {
                        vrForm.Close();
                        vrForm = null;
                    }
                }));
                break;

            case OrderBySev.requirePlaySucceed:

                break;

            case OrderByStu.signIn:

                break;

            case OrderByStu.acceptVideoCall:
                messageList.Invoke(messageCallback, string.Format("role:{0}", "对方接受视话请求!"));
                vcForm.receiveAccpet(msg.content);
                break;

            case OrderByStu.refuseVideoCall:
                messageList.Invoke(messageCallback, string.Format("role:{0}", "对方拒绝视话请求!"));
                vcForm.requireRefused();
                break;

            case OrderBySev.studentConnect:

                //  UserInfm userOnline= JsonConvert.DeserializeObject<UserInfm>(msg.content);
                //-----------------------------------------------------------
                int    index            = msg.content.IndexOf(":");
                int    indexScreenState = msg.content.LastIndexOf(":");
                string screenState      = msg.content.Substring(indexScreenState + 1);
                string deviceType       = msg.content.Substring(index + 1, indexScreenState - index - 1);
                // MessageBox.Show(screenState);

                UserInfm newUser = new UserInfm(msg.ipSend, msg.portSend);
                newUser.deviceType = deviceType;
                newUser.role       = msg.clientStyle;
                userlist.Add(newUser);
                messageList.Invoke(messageCallback, string.Format("role:{0},deviceType:{1},ip:{2},port:{3}", msg.clientStyle, deviceType, msg.ipSend, msg.portSend));
                listView1.Invoke(userCallback, deviceType, msg.clientStyle, msg.ipSend, msg.portSend.ToString());
                if (deviceType == "COMPUTER")
                {
                    //Mre.WaitOne();

                    /*
                     * if (screenState == "1")
                     * {
                     *  Messages msgBlock = new Messages();
                     *  msgBlock.clientStyle = UserRole.teacher;
                     *  msgBlock.order = OrderByTec.forbidMouseKb;
                     *  msgBlock.time = System.DateTime.Now.ToString();
                     *  msgBlock.ipReceive = msg.ipSend;
                     *  msgBlock.portReceive = msg.portSend;
                     *  clientConnect.BeginSendMessage(msg);
                     * }
                     * */
                    this.Invoke(new createUserControl_dl(create_UserControl), new object[] { msg.ipSend, msg.portSend });
                    if (flag)
                    {
                        Thread t = new Thread(new ThreadStart(ReceiveMsg));
                        t.Start();
                        flag = false;
                    }
                }


                //userlist.Add(new UserInfm(msg.ipSend, msg.portSend));
                if (rtspAddress != null)
                {
                    Messages videoMsg = new Messages();
                    videoMsg.clientStyle = UserRole.teacher;
                    videoMsg.order       = OrderByTec.requireSomeonePlayVideo;
                    videoMsg.time        = System.DateTime.Now.ToString();
                    videoMsg.ipReceive   = msg.ipSend;   //学生端ip
                    videoMsg.portReceive = msg.portSend; //学生端port
                    videoMsg.ipSend      = _localIP;
                    videoMsg.portSend    = _localPort;
                    videoMsg.content     = rtspAddress;
                    //videoMsg.content = "123";
                    clientConnect.BeginSendMessage(videoMsg);
                }
                if (beingCallTheRoll)
                {
                    Messages signInMsg = new Messages();
                    signInMsg.clientStyle = UserRole.teacher;
                    signInMsg.order       = OrderByTec.requireSomeoneSignin;
                    signInMsg.time        = System.DateTime.Now.ToString();
                    signInMsg.ipReceive   = msg.ipSend;   //学生端ip
                    signInMsg.portReceive = msg.portSend; //学生端port
                    signInMsg.ipSend      = _localIP;
                    signInMsg.portSend    = _localPort;
                    //videoMsg.content = "123";
                    clientConnect.BeginSendMessage(signInMsg);
                }
                break;

            case OrderBySev.studentLost:
                messageList.Invoke(messageCallback, string.Format("role:{0},ip:{1},port:{2}", msg.clientStyle, msg.ipSend, msg.portSend));

                if (this.vrForm != null)
                {
                    string [] s      = msg.ipSend.Split('.');
                    string    ipPort = "";
                    foreach (string i in s)
                    {
                        ipPort += i;
                    }

                    ipPort += msg.portSend.ToString();
                    string rtspAddr = vrForm.playAddress;
                    int    index1   = rtspAddr.LastIndexOf('/');
                    int    index2   = rtspAddr.LastIndexOf('.');
                    int    len      = index2 - index1;
                    string total    = rtspAddr.Substring(index1 + 1, len);
                    string source   = " ";
                    for (int i = 0; i < total.Length; i++)
                    {
                        if (total[i] >= '0' && total[i] <= '9')
                        {
                            source += total[i];
                        }
                    }
                    if (ipPort.Equals(source.Trim()))
                    {
                        vrForm.Close();
                    }
                }
                this.Invoke(new removeUserControl_dl(remove_UserControl), new object[] { msg.ipSend, msg.portSend });
                listView1.Invoke(userOfflineCallback, msg.ipSend, msg.portSend.ToString());
                break;

            //获取用户列表
            case OrderByTec.userList:
                // userlist = new List<UserInfm>();
                userlist = JsonConvert.DeserializeObject <List <UserInfm> >(msg.content);
                messageList.Invoke(messageCallback, string.Format("userCount:{0}", userlist.Count));
                if (userlist.Count > 0)
                {
                    for (int i = 0; i < userlist.Count; i++)
                    {
                        UserInfm user = userlist[i];
                        messageList.Invoke(messageCallback, string.Format("role:{0},name:{1},device:{2},ip:   {3},port:{4}", user.role, user.name, user.deviceType, user.ip, user.port));
                        listView1.Invoke(userCallback, user.deviceType, user.role, user.ip, user.port.ToString());
                        if (user.deviceType == "COMPUTER" && user.role == "STUDENT")
                        {
                            this.Invoke(new createUserControl_dl(create_UserControl), new object[] { user.ip, user.port });
                            if (flag == true)
                            {
                                flag = false;
                                Thread t = new Thread(new ThreadStart(ReceiveMsg));
                                t.Start();
                            }
                        }
                    }
                }
                break;

            case OrderByTec.privateChat:
            {
                messageList.Invoke(messageCallback, string.Format("ipSend:{0},portSend:{1},content:{2}", msg.ipSend, msg.portSend, msg.content));
                {
                    foreach (ChatForm cf in chatFormList)
                    {
                        if ((cf._ip == msg.ipSend) && (cf._port == msg.portSend))
                        {
                            if (msg.type.Equals(MessType.picture))            //发送图片
                            {
                                cf._cform.setPicture(msg.ipSend, msg.portSend, msg.content);
                            }
                            if (msg.type.Equals(MessType.video))            //发送语音
                            {
                            }
                            if (msg.type.Equals(MessType.text))            //
                            {
                                cf._cform.RecvMess(msg.ipSend, msg.portSend, msg.content);
                            }
                        }
                    }
                }
            }
            break;

            case OrderByTec.groupChat:
            {
                messageList.Invoke(messageCallback, string.Format("ipSend:{0},portSend:{1},content:{2}", msg.ipSend, msg.portSend, msg.content));
                switch (msg.type)
                {
                case MessType.picture:
                    gcForm.setPicture(msg.ipSend, msg.portSend, msg.content);
                    break;

                case MessType.voice:
                    gcForm.setVoice(msg.ipSend, msg.portSend, msg.content);
                    break;

                default:
                    gcForm.setMessage(msg.ipSend, msg.portSend, msg.content);
                    messageList.Invoke(messageCallback, string.Format("{0}:{1}:{2}", msg.ipSend, msg.portSend, msg.content));
                    break;
                }
            }
            break;

            case OrderBySev.groupSucceed:
                this.Invoke(new Action(() =>
                {
                    MessageBox.Show("分组成功!");
                }));
                break;

            case OrderByStu.privateLetter:
                this.Invoke(new Action(() =>
                {
                    PrivateLetter f = new PrivateLetter(msg.ipSend, msg.portSend, msg.content, this.chatFormList, this);
                    f.Show();
                    messageList.Invoke(messageCallback, string.Format("{0}:{1}:{2}", msg.ipSend, msg.portSend, msg.content));
                }));
                break;
            }
        }