Пример #1
0
        public MessageBoxForm(String title,CSS.IM.XMPP.protocol.client.Message msg,string username,string pswd)
        {
            InitializeComponent();
            Msg = msg;
            this.username = username;
            this.pswd = pswd;
            //Msg.SetTag("subject","mq");

            this.Text = title;

            switch (msg.GetTag("subject"))
            {
                case null:
                    this.lllab.Text = Msg.Body;
                    break;
                case "window":
                    MqMessage mqMsg = MarkMessage_Mq(Msg);
                    try
                    {
                        this.lllab.Text = mqMsg.Msg;
                        this.lllab.Tag = mqMsg;
                    }
                    catch (Exception ex)
                    {
                        this.lllab.Text = "消息格式错误," + ex.Message;
                    }
                    break;
            }
            //this.Location = new System.Drawing.Point(100, 100);
            //this.Cursor = System.Windows.Forms.Cursors.Hand;
        }
Пример #2
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            //RTBRecord.Focus();
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";

            try
            {
                face = msg.GetTag("face").ToString();
            }
            catch (Exception)
            {
                face = "";
            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown == null)
                    {
                        emotionDropdown = new EmotionDropdown();
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;
                    }
                    else
                    {
                        String img_str = msg.GetTag(imageContent[1]);
                        try
                        {

                            if (msg.From.Bare == XmppConn.MyJID.Bare)
                            {
                                image = Image.FromFile(Util.sendImage + imageContent[1].ToString() + ".gif");
                            }
                            else
                            {
                                image = Image.FromFile(Util.receiveImage + imageContent[1].ToString() + ".gif");
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    this.RTBRecord.addGifControl(imageContent[1], image);
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {

                this.RTBRecord.AppendText(msgtext + "\n");
            }
            //RTBRecord.Focus();
            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
            //this.RTBRecord.Focus();
        }
Пример #3
0
        public void XmppCon_OnMessage(object sender, CSS.IM.XMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                Invoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
            {
                //Debug.WriteLine("创建聊天室发送了消息:"+msg.Body);
                return;
            }
            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }
            //if (msg.Type == MessageType.normal)
            //{
            //    filename = msg.Body;
            //    Debug.WriteLine(msg.ToString());
            //    return;
            //}

            // check for xData Message

            if (msg.HasTag(typeof(Data)))//如果是文件
            {
                Element e = msg.SelectSingleElement(typeof(Data));
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    //frmXData fXData = new frmXData(xdata);
                    //fXData.Text = "xData Form from " + msg.From.ToString();
                    //fXData.Show();
                }
            }
            else if (msg.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
            else
            {
                if (msg.Body != null)
                {
                    if (msg.GetTag("subject") == "notify")//xu
                    {
                        filename = msg.Body;
                        return;
                    }
                    if (msg.From.ToString() == msg.From.Server)
                    {
                        if (CSS.IM.UI.Util.Path.ReveiveSystemNotification)//是否接收服务器消息
                        {
                            if (CSS.IM.UI.Util.Path.SystemSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.SystemPath);

                            MessageBoxForm sBox = new MessageBoxForm("系统通知", msg);
                            try
                            {
                                sBox.TopMost = true;
                                sBox.Show();
                            }
                            catch (Exception)
                            {

                            }

                            string sqlstr = "insert into MessageLog (Belong,MessageType,MessageLog,[DateNow]) values ({0},{1},{2},{3})";
                            sqlstr = String.Format(sqlstr,
                                "'" + XmppCon.MyJID.Bare.ToString() + "'",
                                "'0'",
                                "'" + msg.ToString() + "'",
                                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                        }
                    }
                    else
                    {
                        if (!Util.ChatForms.ContainsKey(msg.From.Bare))//查看聊天窗口是否已经打开了
                        {

                            //RosterNode rn = rosterControl.GetRosterItem(msg.From);
                            //string nick = msg.From.Bare;
                            //if (rn != null)
                            //    nick = rn.Text;
                            try
                            {
                                //string sqlstr = "insert into ChatMessageLog (Jid,[MessageLog],[DateNow])values ({0},{1},{2})";
                                //sqlstr = String.Format(sqlstr,
                                //    "'" + msg.From.Bare.ToString() + "'",
                                //    "'" + msg.ToString() + "'",
                                //     "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                                //CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

                                if (msg.GetTagInt("m_type") == 0)//如果为0就是正常消息,就播放声音
                                {
                                    if (CSS.IM.UI.Util.Path.MsgSwitch)
                                        SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);
                                }
                                else//代码进入到这里,说明,聊天的窗口已经关闭,接收到属于聊天窗口里面的业务不做处理
                                {
                                    //6发图片
                                    //1接收视频

                                    if (!(msg.GetTagInt("m_type")==6||msg.GetTagInt("m_type")==1))
                                    {
                                        return;
                                    }
                                }

                                Friend flfriend = friendListView.Rosters[msg.From.User];

                                if (CSS.IM.UI.Util.Path.ChatOpen)
                                {
                                    //friendListView.flickerFriend(new Jid(msg.From.Bare));
                                    //ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                    //timer_notifyIco.Enabled = true;

                                    ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                    try
                                    {
                                        chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                        chatForm.Show();
                                        chatForm.Activate();
                                        chatForm.IncomingMessage(msg);
                                    }
                                    catch (Exception)
                                    {

                                    }

                                }
                                else
                                {
                                    if (msgBox.ContainsKey(msg.From.Bare.ToString()))
                                    {
                                        List<CSS.IM.XMPP.protocol.client.Message> msgs = msgBox[msg.From.Bare.ToString()];
                                        msgs.Add(msg);
                                        msgBox.Remove(msg.From.Bare.ToString());
                                        msgBox.Add(msg.From.Bare.ToString(), msgs);
                                        friendListView.flickerFriend(new Jid(msg.From.Bare));

                                    }
                                    else
                                    {
                                        if (friendListView.Rosters.ContainsKey(msg.From.User))
                                        {
                                            List<CSS.IM.XMPP.protocol.client.Message> msgs = new List<XMPP.protocol.client.Message>();
                                            msgs.Add(msg);
                                            msgBox.Add(msg.From.Bare.ToString(), msgs);
                                            friendListView.flickerFriend(new Jid(msg.From.Bare));
                                            ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                            timer_notifyIco.Enabled = true;
                                        }
                                        else
                                        {
                                            ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                            try
                                            {
                                                chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                                chatForm.Show();
                                                chatForm.Activate();
                                                chatForm.IncomingMessage(msg);
                                            }
                                            catch (Exception)
                                            {

                                            }

                                        }

                                        //Friend item=friendListView.Rosters[msg.From.Bare.ToString()];
                                    }
                                }

                                //ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                //chatForm.Show();
                                //chatForm.IncomingMessage(msg);
                            }
                            catch (Exception)
                            {
                                //MessageBox.Show(ex.Message);
                            }

                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            string sqlstr = "insert into ChatMessageLog (Belong,Jid,[MessageLog],[DateNow])values ({0},{1},{2},{3})";
            sqlstr = String.Format(sqlstr,
                "'" + XmppConn.MyJID.Bare.ToString() + "'",
                "'" + (isSend == true ? msg.To.Bare.ToString() : msg.From.Bare.ToString()) + "'",
                "'" + msg.ToString() + "'",
                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";
            try
            {
                if (msg.GetTag("face")!=null)
                {
                    face = msg.GetTag("face").ToString();
                }
                else
                {
                    face = "";
                }
            }
            catch (Exception)
            {

            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown==null)
                    {
                        emotionDropdown = new EmotionDropdown();
                        emotionDropdown.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = CSS.IM.UI.Util.ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;

                        this.RTBRecord.addGifControl(imageContent[1], image);
                    }
                    else
                    {
                        try
                        {
                            if (isSend)
                            {
                                image = this.rtfSend.findPic(imageContent[1]).Image;
                                this.RTBRecord.addGifControl(imageContent[1], image);

                            }
                            else
                            {
                                image = CSS.IM.UI.Util.ResClass.GetImgRes("wite");
                                this.RTBRecord.addGifControl(imageContent[1] + "_r", image);
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {
                this.RTBRecord.AppendText(msgtext + "\n");
            }

            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
        }
Пример #5
0
        public void IncomingMessage(CSS.IM.XMPP.protocol.client.Message msg)
        {
            try
            {
                if (msg.Type == MessageType.error)
                {
                    MsgBox.Show(this, "CSS&IM", "离线消息没有发送成功!", MessageBoxButtons.OK);
                    btn_close_Click(null, null);
                    //btn_close_Click(null, null);
                    //if (msg.To.Bare == _connection.MyJID.Bare && msg.From.Bare == to_Jid.Bare)
                    //{
                    //    MsgBox.Show(this, "CSS&IM", "在服务器中没有找到该用户,无法发送消息!", MessageBoxButtons.OK);
                    //    btn_close_Click(null, null);
                    //}
                }

                int m_type = msg.GetTagInt("m_type");

                switch (m_type)
                {
                    case 0://正常消息
                        //RTBRecord.AppendTextAsRtf(msg.From.User + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "\n", new Font(this.Font, FontStyle.Underline | FontStyle.Bold), CSS.IM.Library.ExtRichTextBox.RtfColor.Red, CSS.IM.Library.ExtRichTextBox.RtfColor.White);
                        CSS.IM.UI.Util.Win32.FlashWindow(this.Handle, true);//闪烁

                        #region 显示我自己发送的消息
                        CSS.IM.XMPP.protocol.client.Message top_msg = new XMPP.protocol.client.Message();
                        top_msg.SetTag("FName", this.Font.Name);//获得字体名称
                        top_msg.SetTag("FSize", this.Font.Size);//字体大小
                        top_msg.SetTag("FBold", true);//是否粗体
                        top_msg.SetTag("FItalic", this.Font.Italic);//是否斜体
                        top_msg.SetTag("FStrikeout", this.Font.Strikeout);//是否删除线
                        top_msg.SetTag("FUnderline", true);//是否下划线

                        Color top_cl = Color.Red;//获取颜色
                        byte[] top_cby = BitConverter.GetBytes(top_cl.ToArgb());
                        top_msg.SetTag("CA", top_cby[0]);
                        top_msg.SetTag("CR", top_cby[1]);
                        top_msg.SetTag("CG", top_cby[2]);
                        top_msg.SetTag("CB", top_cby[3]);
                        top_msg.Body = (_NickName != "" ? _NickName : msg.From.User) + "(" + msg.From.User + "):" + DateTime.Now.ToString("HH:mm:ss");
                        top_msg.From = TO_Jid;
                        top_msg.To = TO_Jid;
                        RTBRecord_Show(top_msg, true);
                        #endregion

                        RTBRecord_Show(msg, false);

                        if (IsPlayMsg)
                        {
                            if (CSS.IM.UI.Util.Path.MsgSwitch)
                                CSS.IM.UI.Util.SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);
                        }
                        break;
                    case 1://收到对方的请求要过行视频功能服务,初始化本地的视频
                        this.Invoke(AccepVideotInit, new object[] { msg });
                        break;
                    case 2://我发送视频请求后,对方告诉我视频初使化完成,进行自己本地的视频初使化
                        this.Invoke(ReturnAcceptVideoInit, new object[] { msg });
                        break;
                    case 3://对方给我发送视频请求,我初使化本地视频服务,告诉对方,对方也初使化视频服务了,我打开视频功能
                        this.Invoke(AcceptVideoOpen, new object[] { msg });
                        break;
                    case 4://去对方获取截图的功能
                        RemotBaseUDPPort = msg.GetTagInt("BPort");
                        RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP"));
                        bool isSend = msg.GetTagBool("isSend");

                        if (isSend)
                        {
                            CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message();
                            fmsg.SetTag("m_type", 4);
                            fmsg.Type = MessageType.chat;
                            fmsg.To = TO_Jid;
                            fmsg.SetTag("BPort", ListenBasicUDPPort);
                            fmsg.SetTag("BIP", Program.LocalHostIP.ToString());
                            fmsg.SetTag("isSend", false);
                            XmppConn.Send(fmsg);
                        }

                        sendSelfImage();
                        break;
                    case 5://视频释放
                        if (RemotVideoUDPPort != -1)
                        {
                            //avForm.isBtn_hangup = true;
                            if (avForm != null && !avForm.IsDisposed)
                            {
                                avForm.isBtn_hangup = true;
                                avForm.AVClose();
                            }
                            if (ravForm != null && !ravForm.IsDisposed)
                            {
                                ravForm.isBtn_hangup = true;
                                ravForm.AVClose();
                            }
                        }
                        break;
                    case 6://传文件
                        RemotBaseUDPPort = msg.GetTagInt("BPort");
                        RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP"));

                        CSS.IM.XMPP.protocol.client.Message lmsg = new CSS.IM.XMPP.protocol.client.Message();
                        lmsg.SetTag("m_type", 7);//告诉对方要发送文件啦
                        lmsg.Type = MessageType.chat;
                        lmsg.To = TO_Jid;
                        lmsg.SetTag("BPort", udpReceiveFile.Port);
                        lmsg.SetTag("BIP", Program.LocalHostIP.ToString());
                        lmsg.SetTag("isSend", false);
                        lmsg.SetTag("File", msg.GetTag("File").ToString());
                        XmppConn.Send(lmsg);
                        break;
                    case 7:
                        RemotBaseUDPPort = msg.GetTagInt("BPort");
                        RemotBaseUDPIP = IPAddress.Parse(msg.GetTag("BIP"));
                        this.Invoke(FileSendInitEvent, msg.GetTag("File").ToString());
                        break;
                    case 8://ftp离线文件
                        this.Invoke(GetFtpFileEvent, new object[] { msg});
                        break;
                    case 9://对方拒绝接收主线文件
                        this.AppendSystemRtf("对方"+msg.Body);
                        break;
                    case 10://对方接收离线文件
                        //DownloadImage
                        try
                        {
                            FTPClient ftpClient = new FTPClient(Util.ServerAddress, Util.ftpPath, Util.ftpUser, Util.ftpPswd, Util.ftpPort);
                            ftpClient.FtpPath=msg.GetTag("Path");
                            DownloadImage downloadImage = new DownloadImage();
                            downloadImage.ftpClient = ftpClient;
                            downloadImage.remoteImageName = msg.GetTag("FileName");
                            downloadImage.parent = this;
                            Thread getFileThread = new Thread(downloadImage.Download);
                            getFileThread.Start();
                        }
                        catch (Exception)
                        {

                        }
                        break;
                    case 11://接收到red的视频请求
                        this.Invoke(Red5AccpetEvent, new object[] { msg });
                        break;
                    case 12://接收到red的视频请求
                        this.Invoke(Red5RefuseEvent, new object[] { msg });
                        break;
                    case 13:
                        //red5MsgSend_FormClosing
                        if (red5MsgReceive != null || !red5MsgReceive.IsDisposed)
                        {
                            red5MsgReceive.Close();
                            red5MsgReceive.Dispose();
                            red5MsgReceive = null;
                        }
                        this.AppendSystemRtf("对方" + msg.From.User + "关闭了视频通话");
                        break;
                    case 14:
                        //red5MsgReceive_FormClosing
                        if (red5MsgSend != null || !red5MsgSend.IsDisposed)
                        {
                            red5MsgSend.Close();
                            red5MsgSend.Dispose();
                            red5MsgSend = null;
                        }
                        this.AppendSystemRtf("对方" + msg.From.User + "关闭了视频通话");
                        break;

                }
            }
            catch (Exception)
            {

            }
        }
Пример #6
0
        /// <summary>
        /// 同意视频信息后,进行初使化本地视频服务
        /// </summary>
        /// <param name="msg"></param>
        void AcceptVideoInitMethod(CSS.IM.XMPP.protocol.client.Message msg)
        {
            UserInfo user1;
            UserInfo user2;

            if (ravForm != null && !ravForm.IsDisposed)
            {
                try
                {
                    ravForm.Dispose();
                    ravForm = null;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                ravForm = new CSS.IM.App.Controls.AVForm(TO_Jid);
                ravForm.AVCloseEvent += new CSS.IM.App.Controls.AVForm.AVCloseDelegate(avForm_AVCloseEvent);
            }

            //保存本地视频的监听端口
            ListenVideoUDPPort = ravForm.aVcommunicationEx1.selfUDPPort;

            RemotVideoUDPPort = msg.GetTagInt("UDPPort");
            RemotVideoUDPIP = IPAddress.Parse(msg.GetTag("UDPIP"));

            user1 = new UserInfo();

            user1.LocalPort = RemotVideoUDPPort;
            user1.LocalIP = RemotVideoUDPIP;

            ravForm.SetRemoteAddress(user1, RemotVideoUDPPort);

            user2 = new UserInfo();
            user2.LocalIP = Program.LocalHostIP;
            user2.LocalPort = ListenVideoUDPPort;
            ravForm.SetLocalAddress(user2);
            ravForm.AgreeEvent += new CSS.IM.App.Controls.AVForm.AgreeDelegate(ravForm_AgreeEvent);//接收视频会话事件
            ravForm.btn_hangup.Visible = false;//挂断不可用
            ravForm.btn_agree.Visible = true;//接受可用
            ravForm.btn_refuse.Visible = true;//拒绝可用
            try
            {
                ravForm.Show();
            }
            catch (Exception)
            {

            }

            //if (ravForm.callSoundPlayer != null)
            //    ravForm.callSoundPlayer.Stop();
        }
Пример #7
0
        /// <summary>
        /// 同意视频信息后,进行初使化本地视频服务
        /// </summary>
        /// <param name="msg"></param>
        void AcceptInitMethod(CSS.IM.XMPP.protocol.client.Message msg)
        {
            UserInfo user1;
            UserInfo user2;

            if (ravForm != null && !ravForm.IsDisposed)
            {
                try
                {
                    ravForm.Dispose();
                    ravForm = null;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                ravForm = new AVForm(to_Jid);
                ravForm.AVCloseEvent += new AVForm.AVCloseDelegate(avForm_AVCloseEvent);
            }
            LocalVideoUDPPort = ravForm.aVcommunicationEx1.selfUDPPort.ToString();

            VideoRemotUDPPort = msg.GetTagInt("UDPPort");
            VideoRemotUDPIP = IPAddress.Parse(msg.GetTag("UDPIP"));
            user1 = new UserInfo();
            user1.LocalIP = VideoRemotUDPIP;
            user1.LocalPort = VideoRemotUDPPort;
            ravForm.SetRemoteAddress(user1, VideoRemotUDPPort);

            user2 = new UserInfo();
            user2.LocalIP = Program.LocalHostIP;
            user2.LocalPort = int.Parse(LocalVideoUDPPort);
            ravForm.SetLocalAddress(user2);
            ravForm.AgreeEvent += new AVForm.AgreeDelegate(ravForm_AgreeEvent);//接收视频会话事件
            ravForm.btn_hangup.Visible = false;//挂断不可用
            ravForm.btn_agree.Visible = true;//接受可用
            ravForm.btn_refuse.Visible = true;//拒绝可用
            try
            {
                ravForm.Show();
            }
            catch (Exception)
            {

            }
        }
Пример #8
0
        public void IncomingMessage(CSS.IM.XMPP.protocol.client.Message msg)
        {
            try
            {
                if (msg.Type == MessageType.error)
                {
                    MsgBox.Show(this, "CSS&IM", "离线消息没有发送成功!", MessageBoxButtons.OK);
                    btn_close_Click(null, null);
                    //btn_close_Click(null, null);
                    //if (msg.To.Bare == _connection.MyJID.Bare && msg.From.Bare == to_Jid.Bare)
                    //{
                    //    MsgBox.Show(this, "CSS&IM", "在服务器中没有找到该用户,无法发送消息!", MessageBoxButtons.OK);
                    //    btn_close_Click(null, null);
                    //}
                }

                int m_type = msg.GetTagInt("m_type");

                switch (m_type)
                {
                    case 0://正常消息
                        //RTBRecord.AppendTextAsRtf(msg.From.User + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "\n", new Font(this.Font, FontStyle.Underline | FontStyle.Bold), CSS.IM.Library.ExtRichTextBox.RtfColor.Red, CSS.IM.Library.ExtRichTextBox.RtfColor.White);
                        Win32.FlashWindow(this.Handle, true);//闪烁
                        #region 显示我自己发送的消息
                        CSS.IM.XMPP.protocol.client.Message top_msg = new XMPP.protocol.client.Message();
                        top_msg.SetTag("FName", this.Font.Name);//获得字体名称
                        top_msg.SetTag("FSize", this.Font.Size);//字体大小
                        top_msg.SetTag("FBold", true);//是否粗体
                        top_msg.SetTag("FItalic", this.Font.Italic);//是否斜体
                        top_msg.SetTag("FStrikeout", this.Font.Strikeout);//是否删除线
                        top_msg.SetTag("FUnderline", true);//是否下划线

                        Color top_cl = Color.Red;//获取颜色
                        byte[] top_cby = BitConverter.GetBytes(top_cl.ToArgb());
                        top_msg.SetTag("CA", top_cby[0]);
                        top_msg.SetTag("CR", top_cby[1]);
                        top_msg.SetTag("CG", top_cby[2]);
                        top_msg.SetTag("CB", top_cby[3]);
                        top_msg.Body = msg.From.User + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        top_msg.From = to_Jid;
                        top_msg.To = to_Jid;
                        RTBRecord_Show(top_msg, true);
                        #endregion
                        RTBRecord_Show(msg, false);
                        if (IsPlayMsg)
                        {
                            if (CSS.IM.UI.Util.Path.MsgSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);

                        }
                        break;
                    case 1://收到对方的请求要过行视频功能服务,初始化本地的视频
                        this.Invoke(AcceptInit, new object[] { msg });
                        break;
                    case 2://我发送视频请求后,对方告诉我视频初使化完成,进行自己本地的视频初使化
                        this.Invoke(ReturnAcceptInit, new object[] { msg });
                        break;
                    case 3://对方给我发送视频请求,我初使化本地视频服务,告诉对方,对方也初使化视频服务了,我打开视频功能
                        this.Invoke(AcceptOpen, new object[] { msg });
                        break;
                    case 4:
                        BaseRemotUDPPort = msg.GetTagInt("BPort");
                        BaseRemotUDPIP = IPAddress.Parse(msg.GetTag("BIP"));
                        bool isSend = msg.GetTagBool("isSend");
                        if (isSend)
                        {
                            CSS.IM.XMPP.protocol.client.Message fmsg = new CSS.IM.XMPP.protocol.client.Message();
                            fmsg.SetTag("m_type", 4);
                            fmsg.Type = MessageType.chat;
                            fmsg.To = to_Jid;
                            fmsg.SetTag("BPort", BaseLocalUDPPort);
                            fmsg.SetTag("BIP", Program.LocalHostIP.ToString());
                            fmsg.SetTag("isSend", false);
                            fmsg.Body = "falg";
                            _connection.Send(fmsg);
                        }
                        sendSelfImage();
                        break;
                    case 5://视频释放
                        if (VideoRemotUDPPort != -1)
                        {
                            //avForm.isBtn_hangup = true;

                            if (avForm != null && !avForm.IsDisposed)
                            {
                                avForm.isBtn_hangup = true;
                                avForm.AVClose();
                            }
                            if (ravForm != null && !ravForm.IsDisposed)
                            {
                                ravForm.isBtn_hangup = true;
                                ravForm.AVClose();
                            }
                        }
                        break;
                    case 6://传文件
                        BaseRemotUDPPort = msg.GetTagInt("BPort");
                        BaseRemotUDPIP = IPAddress.Parse(msg.GetTag("BIP"));

                        CSS.IM.XMPP.protocol.client.Message lmsg = new CSS.IM.XMPP.protocol.client.Message();
                        lmsg.SetTag("m_type", 7);//告诉对方要发送文件啦
                        lmsg.Type = MessageType.chat;
                        lmsg.To = to_Jid;
                        lmsg.SetTag("BPort", BaseLocalUDPPort);
                        lmsg.SetTag("BIP", Program.LocalHostIP.ToString());
                        lmsg.SetTag("isSend", false);
                        lmsg.SetTag("File", msg.GetTag("File").ToString());
                        lmsg.Body = "falg";
                        _connection.Send(lmsg);

                        break;
                    case 7:
                        BaseRemotUDPPort = msg.GetTagInt("BPort");
                        BaseRemotUDPIP = IPAddress.Parse(msg.GetTag("BIP"));
                        this.Invoke(FileSendInitEvent, msg.GetTag("File").ToString());
                        break;
                }
            }
            catch (Exception)
            {

            }
        }
Пример #9
0
        public void IncomingMessage(CSS.IM.XMPP.protocol.client.Message msg)
        {
            try
            {
                CSS.IM.XMPP.protocol.client.Message top_msg = new XMPP.protocol.client.Message();
                top_msg.SetTag("FName", this.Font.Name);//获得字体名称
                top_msg.SetTag("FSize", this.Font.Size);//字体大小
                top_msg.SetTag("FBold", true);//是否粗体
                top_msg.SetTag("FItalic", this.Font.Italic);//是否斜体
                top_msg.SetTag("FStrikeout", this.Font.Strikeout);//是否删除线
                top_msg.SetTag("FUnderline", true);//是否下划线

                Color cl;

                if (XmppConn.MyJID.User == msg.From.Resource)
                {
                    cl = Color.FromArgb(33, 119, 207);//获取颜色
                }
                else
                {
                    cl = Color.Red;//获取颜色
                }
                byte[] cby = BitConverter.GetBytes(cl.ToArgb());
                top_msg.SetTag("CA", cby[0]);
                top_msg.SetTag("CR", cby[1]);
                top_msg.SetTag("CG", cby[2]);
                top_msg.SetTag("CB", cby[3]);

                string nickname = msg.GetTag("NickName").ToString();
                if (nickname == null)
                {
                    nickname = msg.From.Resource;
                }
                if (nickname.Trim().Length == 0)
                {
                    nickname = msg.From.Resource;
                }
                nickname=nickname + "(" + msg.From.Resource + ")";
                top_msg.Body = nickname + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
                RTBRecord_Show(top_msg, false);
                //RTBRecord.AppendTextAsRtf(msg.From.User + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "\n", new Font(this.Font, FontStyle.Underline | FontStyle.Bold), CSS.IM.Library.ExtRichTextBox.RtfColor.Red, CSS.IM.Library.ExtRichTextBox.RtfColor.White);
                RTBRecord_Show(msg, false);

                if (CSS.IM.UI.Util.Path.MsgSwitch)
                    CSS.IM.UI.Util.SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);

                //new Font(this.Font, FontStyle.Underline | FontStyle.Bold),
                //CSS.IM.Library.ExtRichTextBox.RtfColor.Red,
                //CSS.IM.Library.ExtRichTextBox.RtfColor.White
            }
            catch (Exception)
            {

            }
        }