示例#1
0
 void conn_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
 {
     if (this.IsHandleCreated)
     {
         this.Invoke(new OnStanzaDelegate(OnStanza), pres);
     }
 }
示例#2
0
        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            string[]             jIDRaw  = pres.From.ToString().Split('/');
            string               jID     = jIDRaw[0];
            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByPropertyValue("JabberID", jID);

            if (objects != null)
            {
                foreach (OSAEObject oObj in objects)
                {
                    Log.Info(String.Format("Received Presence from: {0} show: {1} status: {2}", oObj.Name, pres.Show.ToString(), pres.Status));
                    if (pres.Show.ToString() == "away")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(oObj.Name, "JabberStatus", "Idle", "Jabber");
                    }
                    else if (pres.Show.ToString() == "NONE")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(oObj.Name, "JabberStatus", "Online", "Jabber");
                    }
                    break;
                }
            }
            else
            {
                Log.Info(String.Format("No object found with address of: {0}", jID, pres.Show.ToString(), pres.Status));
            }
        }
示例#3
0
        void objXmpp_ServerStatus(agsXMPP.protocol.client.Presence pres)//用户在线状态事件【3】
        {
            del_AddRecord AddRecord_del = new del_AddRecord(AddRecord);

            this.Invoke(AddRecord_del, new object[] { pres.Type.ToString(), pres.From.Bare, pres.Status });
            Thread.Sleep(50);
            //AddRecord(pres.Type.ToString(), pres.From.Bare, pres.Status);
        }
示例#4
0
 void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
 {
     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 agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence), new object[] { sender, pres });
         return;
     }
     listEvents.Items.Add(String.Format("Received Presence from:{0} show:{1} status:{2}", pres.From.ToString(), pres.Show.ToString(), pres.Status));
     listEvents.SelectedIndex = listEvents.Items.Count - 1;
 }
示例#5
0
        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            osae.AddToLog(String.Format("Received Presence from:{0} show:{1} status:{2}", pres.From.ToString(), pres.Show.ToString(), pres.Status), false);
            List <OSAEObject> objects = osae.GetObjectsByType("PERSON");

            foreach (OSAEObject oObj in objects)
            {
                OSAEObject obj = osae.GetObjectByName(oObj.Name);
                if (osae.GetObjectPropertyValue(obj.Name, "JabberID").Value == pres.From.Bare)
                {
                    if (pres.Show.ToString() == "away")
                    {
                        osae.ObjectPropertySet(obj.Name, "JabberStatus", "Idle");
                    }
                    else if (pres.Show.ToString() == "NONE")
                    {
                        osae.ObjectPropertySet(obj.Name, "JabberStatus", "Online");
                    }
                    break;
                }
            }
        }
示例#6
0
 /// <summary>
 /// Change l'�tat de son status
 /// </summary>
 public void applyStatus()
 {
     if (Jabber.xmpp.Authenticated)
     {
         agsXMPP.protocol.client.Presence p = new agsXMPP.protocol.client.Presence();
         p.From     = Jabber.xmpp.MyJID;
         p.Priority = Jabber.xmpp.Priority;
         p.Type     = Enumerations.PresenceTypeConverter(_status.type);
         if (p.Type == agsXMPP.protocol.client.PresenceType.available)
         {
             p.Show         = Enumerations.StatusTypeConverter(_status.type);
             p.Status       = _status.message;
             p.XDelay       = new agsXMPP.protocol.x.Delay();
             p.XDelay.Stamp = DateTime.Now;
             p.AddChild(Queries.getCapabilities());
             Jabber.xmpp.Show   = p.Show;
             Jabber.xmpp.Status = p.Status;
             p.Nickname         = new agsXMPP.protocol.extensions.nickname.Nickname(Jabber._identity.nickname);
         }
         Jabber.xmpp.Send(p);
     }
 }
示例#7
0
文件: Presence.cs 项目: don59/agsXmpp
        internal Presence()
        {
            agsXMPP.protocol.client.Presence pres = new agsXMPP.protocol.client.Presence();
            pres.Show = agsXMPP.protocol.client.ShowType.xa;
            pres.Status = "Away from the computer.";
            pres.Priority = 5;

            Capabilities caps = new Capabilities();
            caps.Node = "http://www.ag-software.de/caps";
            caps.Version = "1.1.0";
            // don't use the follwing anymore, its deprecated
            caps.Extensions = new string[] { "rtf", "html-im", "crypt"};

            Avatar avatar = new Avatar();
            avatar.Hash = "1bb12134f2528c4617fcc393180ddcfcc8462311";

            pres.AddChild(caps);
            pres.AddChild(avatar);
                        
            Console.WriteLine("Custom Presence Packet:");
            Program.Print(pres);           
        }
        public override void Send(string data)
        {
            base.Send(data);

            // This are hacks because we send no stream headers and footer in Bosh
            if (data.StartsWith("<stream:stream"))
            {
                if (!streamStarted && !restart)
                {
                    streamStarted = true;
                }
                else
                {
                    byte[] bin = Encoding.UTF8.GetBytes(DummyStreamHeader);
                    base.FireOnReceive(bin, bin.Length);
                }
                return;
            }

            if (data.EndsWith("</stream:stream>"))
            {
                agsXMPP.protocol.client.Presence pres = new agsXMPP.protocol.client.Presence();
                pres.Type = agsXMPP.protocol.client.PresenceType.unavailable;
                data      = pres.ToString(); //= "<presence type='unavailable' xmlns='jabber:client'/>";
                terminate = true;
            }
            //    return;

            lock (m_SendQueue)
            {
                m_SendQueue.Enqueue(data);
            }

            if (waitingRequests <= 1)
            {
                StartWebRequest();
            }
        }
示例#9
0
        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            Log.Info(String.Format("Received Presence from: {0} show: {1} status: {2}", pres.From.ToString(), pres.Show.ToString(), pres.Status));

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("PERSON");

            foreach (OSAEObject oObj in objects)
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(oObj.Name);

                if (OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "JabberID").Value == pres.From.Bare)
                {
                    if (pres.Show.ToString() == "away")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "JabberStatus", "Idle", "Jabber");
                    }
                    else if (pres.Show.ToString() == "NONE")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "JabberStatus", "Online", "Jabber");
                    }
                    break;
                }
            }
        }
示例#10
0
        internal Presence()
        {
            agsXMPP.protocol.client.Presence pres = new agsXMPP.protocol.client.Presence();
            pres.Show     = agsXMPP.protocol.client.ShowType.xa;
            pres.Status   = "Away from the computer.";
            pres.Priority = 5;

            Capabilities caps = new Capabilities();

            caps.Node    = "http://www.ag-software.de/caps";
            caps.Version = "1.1.0";
            // don't use the follwing anymore, its deprecated
            caps.Extensions = new string[] { "rtf", "html-im", "crypt" };

            Avatar avatar = new Avatar();

            avatar.Hash = "1bb12134f2528c4617fcc393180ddcfcc8462311";

            pres.AddChild(caps);
            pres.AddChild(avatar);

            Console.WriteLine("Custom Presence Packet:");
            Program.Print(pres);
        }
示例#11
0
        public override void Send(string data)
        {
            base.Send(data);

            // This are hacks because we send no stream headers and footer in Bosh
            if (data.StartsWith("<stream:stream"))
            {
                if (!streamStarted && !restart)
                    streamStarted = true;
                else
                {
                    byte[] bin = Encoding.UTF8.GetBytes(DummyStreamHeader);
                    base.FireOnReceive(bin, bin.Length);
                }
                return;
            }

            if (data.EndsWith("</stream:stream>"))
            {
                agsXMPP.protocol.client.Presence pres = new agsXMPP.protocol.client.Presence();
                pres.Type = agsXMPP.protocol.client.PresenceType.unavailable;
                data = pres.ToString(); //= "<presence type='unavailable' xmlns='jabber:client'/>";
                terminate = true;
            }
            //    return;

            lock (m_SendQueue)
            {
                m_SendQueue.Enqueue(data);
            }

            if (waitingRequests <= 1)
            {
                StartWebRequest();
            }
        }
示例#12
0
 /// <summary>
 /// Change l'�tat de son status
 /// </summary>
 public void applyStatus()
 {
     if (Jabber.xmpp.Authenticated)
     {
         agsXMPP.protocol.client.Presence p = new agsXMPP.protocol.client.Presence();
         p.From = Jabber.xmpp.MyJID;
         p.Priority = Jabber.xmpp.Priority;
         p.Type = Enumerations.PresenceTypeConverter(_status.type);
         if (p.Type == agsXMPP.protocol.client.PresenceType.available)
         {
             p.Show = Enumerations.StatusTypeConverter(_status.type);
             p.Status = _status.message;
             p.XDelay = new agsXMPP.protocol.x.Delay();
             p.XDelay.Stamp = DateTime.Now;
             p.AddChild(Queries.getCapabilities());
             Jabber.xmpp.Show = p.Show;
             Jabber.xmpp.Status = p.Status;
             p.Nickname = new agsXMPP.protocol.extensions.nickname.Nickname(Jabber._identity.nickname);
         }
         Jabber.xmpp.Send(p);
     }
 }
示例#13
0
 void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
 {
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        public void ClientConnection_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            // 等待好友加载完毕
            //wei=>if (!XmppRosterManager.Instance.RosterLoadedFlag.WaitOne(10000, true))
            //wei=>{
            //wei=>     XmppLogger.Error(String.Format("{0}{1}", LockWatcher.TAG, "MyRosterControl.ClientConnection_OnPresence"));
            //wei=>    return;
            //wei=>}

            waitcall.Run();

            //wei=> this.TA_Execute(delegate
            //wei=>{
            //wei=>   LockWatcher lkw = LockWatcher.New();
            lock (NavLock)
            {
                //wei=>lkw.Stop();
                String jid = pres.From.Bare;

                //String resource = pres.From.Resource;
                //if (!String.IsNullOrEmpty(resource))
                //{
                //    if (resource.StartsWith("android"))
                //    {
                //        // 安卓手机
                //    }
                //    else if (resource.StartsWith("JM"))
                //    {
                //        // JM
                //    }
                //}

                List <NavBarItem> nbList = FindNavBarItem(jid);

                int    imageIndex   = -1;
                int    mobileStatus = -1;
                int    status       = -1;
                string mobileRes    = "";
                //wei=> PresenceManager.Instance.GetUserStatus(jid, out mobileStatus, out mobileRes, out status);
                if (mobileStatus >= 0)
                {
                    //wei=> imageIndex = ResManager.STATUS_MOBILE;
                }
                else
                {
                    imageIndex = status;
                }
                if (imageIndex >= 0)
                {
                    foreach (NavBarItem item in nbList)
                    {
                        item.SmallImageIndex = imageIndex;
                    }
                    //return;
                }

                /*
                 * 出席信息节的'type'属性是可选的(OPTIONAL).
                 * 一个不拥有任何'type'属性的出席信息节用来通知服务器发送者已经在线并且可以进行通信了,
                 * 'type' 属性表示缺乏可用性, 请求管理对其他实体的出席信息的订阅, 请求其他实体的当前出席信息,
                 * 或发生了和上次发出的出席信息节有关的错误. 如果包含了它, 'type'属性必须(MUST)拥有以下值之一:
                 * •	unavailable -- 通知实体将不可通信.
                 * •	subscribe -- 发送者希望订阅接收者的出席信息.
                 * •	subscribed -- 发送者允许接收者接收他们的出席信息.
                 * •	unsubscribe -- 发送者取消订阅另一个实体的出席信息.
                 * •	unsubscribed -- 订阅者的请求被拒绝或以前的订阅被取消.
                 * •	probe -- 对一个实体当前的出席信息的请求; 只应(SHOULD)由服务器代替一个用户生成.
                 * •	error -- 处理或递送之前发送的出席信息节的时候发生了错误.
                 */
                switch (pres.Type)
                {
                // available -- 通知实体可以通信.
                case agsXMPP.protocol.client.PresenceType.available:

                    //wei=> imageIndex = ResManager.STATUS_ONLINE;

                    switch (pres.Show)
                    {
                    case agsXMPP.protocol.client.ShowType.NONE:
                        break;

                    // 离开一会
                    case agsXMPP.protocol.client.ShowType.away:
                        //wei=> imageIndex = ResManager.STATUS_AWAY;
                        break;

                    // 可以聊天
                    case agsXMPP.protocol.client.ShowType.chat:
                        break;

                    // 请勿打扰
                    case agsXMPP.protocol.client.ShowType.dnd:
                        //wei=>imageIndex = ResManager.STATUS_DND;
                        break;

                    // 长时间离开
                    case agsXMPP.protocol.client.ShowType.xa:
                        //wei=>imageIndex = ResManager.STATUS_XA;
                        break;

                    default:
                        break;
                    }
                    if (mobileStatus >= 0)
                    {
                        //wei=> imageIndex = ResManager.STATUS_MOBILE;
                    }
                    foreach (NavBarItem item in nbList)
                    {
                        item.SmallImageIndex = imageIndex;
                    }

                    break;

                // unsubscribed -- 订阅者的请求被拒绝或以前的订阅被取消.
                case agsXMPP.protocol.client.PresenceType.unsubscribed:
                    foreach (NavBarItem item in nbList)
                    {
                        // 移除好友
                        //item.SmallImageIndex = ResManager.STATUS_UNSUBSCRIBED;
                        item.NavBar.ActiveGroup.ItemLinks.Remove(item);
                    }

                    //wei=>XmppRosterManager.Instance.Remove(pres.From);
                    break;

                // subscribe -- 发送者希望订阅接收者的出席信息.
                case agsXMPP.protocol.client.PresenceType.subscribe:
                    // 对方请求添加为好友
                    //wei=>SubscriptionRequestForm form = new SubscriptionRequestForm(pres.From);
                    //wei=>form.Show();
                    break;

                // subscribed -- 发送者允许接收者接收他们的出席信息.
                case agsXMPP.protocol.client.PresenceType.subscribed:

                    // XmppRosterManager.Instance.Add(item)
                    foreach (NavBarItem item in nbList)
                    {
                        RosterItem roster = item.Tag as RosterItem;
                        roster.Subscription = SubscriptionType.to;
                    }
                    break;

                // unsubscribe -- 发送者取消订阅另一个实体的出席信息.
                case agsXMPP.protocol.client.PresenceType.unsubscribe:
                    // 对方拒绝添加好友
                    //wei=>xmppClient.ClientConnection.RosterManager.RemoveRosterItem(pres.From);
                    //wei=> XmppRosterManager.Instance.Remove(pres.From);
                    break;

                // probe -- 对一个实体当前的出席信息的请求; 只应(SHOULD)由服务器代替一个用户生成.
                case agsXMPP.protocol.client.PresenceType.probe:
                    break;

                // error -- 处理或递送之前发送的出席信息节的时候发生了错误.
                case agsXMPP.protocol.client.PresenceType.error:
                // invisible -- 隐身
                case agsXMPP.protocol.client.PresenceType.invisible:
                // unavailable -- 通知实体将不可通信.
                case agsXMPP.protocol.client.PresenceType.unavailable:
                default:
                    //foreach (NavBarItem item in nbList)
                    //    item.SmallImageIndex =  imageIndex;
                    break;
                }
            }
            //wei=>});
        }