Beispiel #1
0
        private void BindResult(object sender, IQ iq, object data)
        {
            // Once the server has generated a resource identifier for the client or accepted the resource
            // identifier provided by the client, it MUST return an IQ stanza of type "result"
            // to the client, which MUST include a <jid/> child element that specifies the full JID for
            // the connected resource as determined by the server:

            // Server informs client of successful resource binding:
            // <iq type='result' id='bind_2'>
            //  <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
            //    <jid>[email protected]/someresource</jid>
            //  </bind>
            // </iq>
            if (iq.Type == IqType.result)
            {
                // i assume the server could assign another resource here to the client
                // so grep the resource assigned by the server now
                Element bind = iq.SelectSingleElement(typeof(Bind));
                if (bind != null)
                {
                    Jid jid = ((Bind)bind).Jid;
                    m_XmppClient.Resource = jid.Resource;
                    m_XmppClient.Username = jid.User;
                }

                m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binded);
                m_XmppClient.m_Binded = true;

                m_XmppClient.DoRaiseEventBinded();

                // success, so start the session now
                m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.StartSession);
                SessionIq sIq = new SessionIq(IqType.set, new Jid(m_XmppClient.Server));
                m_XmppClient.IqGrabber.SendIq(sIq, new IqCB(SessionResult), null);

            }
            else if (iq.Type == IqType.error)
            {
                // TODO, handle bind errors
            }
        }
Beispiel #2
0
        public void XmppCon_OnIq(object sender, IQ iq)
        {
            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
                BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq });
                return;
            }

            if (iq != null)
            {
                // No Iq with query
                if (iq.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.error)
                    {
                        CSS.IM.XMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)) as CSS.IM.XMPP.protocol.extensions.si.SI;

                        CSS.IM.XMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            // somebody wants to send a file to us
                            //if (!Util.ChatForms.ContainsKey(iq.From.Bare))//正常消息
                            //{
                            //    //RosterNode rn = rosterControl.GetRosterItem(msg.From);
                            //    //string nick = msg.From.Bare;
                            //    //if (rn != null)
                            //    //    nick = rn.Text;
                            //    ChatForm chatForm = new ChatForm(iq.From, XmppCon, iq.From.Bare);
                            //    chatForm.Show();
                            //    //chatForm.IncomingMessage(msg);
                            //    chatForm.FileTransfer(iq);
                            //}
                        }
                    }
                }
                else
                {

                }
            }
        }
Beispiel #3
0
        public void XmppCon_OnIq(object sender, IQ iq)
        {
            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
                BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq });
                return;
            }

            if (iq != null)
            {
                if (iq.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        CSS.IM.XMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)) as CSS.IM.XMPP.protocol.extensions.si.SI;

                        CSS.IM.XMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            if (!Util.ChatForms.ContainsKey(iq.From.Bare))//查看聊天窗口是否已经打开了
                            {
                                try
                                {
                                    Friend flfriend = listView_fd.Rosters[iq.From.Bare];
                                    string nickName = listView_fd.GetFriendNickName(iq.From.Bare);
                                    ChatFromMsg chatForm = new ChatFromMsg(iq.From, XmppCon, nickName);
                                    chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                    chatForm.Show();
                                    //chatForm.FileTransfer(iq);
                                    chatForm.Activate();
                                }
                                catch (Exception)
                                {

                                }
                            }
                            else
                            {

                            }

                        }
                    }
                }
                else
                {

                }
            }
        }