Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Page:  1  2  next
Avatar
ayyrk #1
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Subject: Auto Roster
Hi,

Is _xmppCon.AutoRoster = true; a good idea on Mobile Devices considering network utilization?

When should the roster be manually requested when not using AutoRoster? 

Thanks!

-Ayyrk
P.S. - We're up to 600 AT&T Tilts deployed, heading for about 1,000
Avatar
Alex #2
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this depends on your roster size.
But to save bandwidth and  speedup the login caching the roster and set AutoRoster to false is always a good idea.

Alex
Avatar
ayyrk #3
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Does autoroster generate roster requests other than during login?
Avatar
Alex #4
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
only on login. It requests the full roster on login.
Its not related to the roster updates which you get on changes. You will get the roster updates anyway.

Alex
Avatar
ayyrk #5
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Well, I'm writing a new app using the agsxmpp SDK. I know more this time around but just hit something I don't understand.

As soon as I connect to the server I get a series of OnPresence calls before I get the OnRosterStart/OnRosterItem/OnRosterEnd sequence.

I want to cache the information from the Roster callback and later update it with Presence information. So getting all the presence information before I build the roster cache is a problem.

Is my approach generally sound? Is it usual to get the presence information before the roster information? Is there a way to force the server to refresh all presence information?

It doesn't seem right to me to build the roster cache based on presence callback information but maybe that is the correct way to go.

Thanks for any advice,

-Ayyrk
Avatar
Alex #6
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ayyrk:
... Is it usual to get the presence information before the roster information? Is there a way to force the server to refresh all presence information?

no its not.
When AutoRoster and AutoPresence are true agsXMPP retrieves the roster first, and then sends the initial presence.
It looks like you are doing something in the wrong order in your code. You get the presences of your contacts right after you sent your own presence to the server and mark yourself as available. So I suggest to set also AutoPresence to false and send your own presence when your roster was rebuild from the cache and you are ready for incoming presences.
Let me know if this solved your problem

Alex
Avatar
ayyrk #7
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
The client I'm developing has a chat window for each Jid Resource. It lets the user chat with a specific resource. I will experiment with/without concurrent logins to see if that makes a difference. Generally I am logged in with PSI while testing my application using a different resource.

No question here. Just info.

Thanks,
-Ayyrk
Avatar
ayyrk #8
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
In reply to post #1
Woops.. You were right; I was sending my presence in the onLogin callback before requesting the Roster.. Let me work on this a bit..

-Ayyrk
Avatar
ayyrk #9
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
In reply to post #1
Hi,

Here is the OnPresence call back from the application I am working on. The example in the compact framework mini client did not have filled in "if conditions" for the subscribe / unsubscribe PresenceTypes so I am asking you if this looks at all correct.

My concern is that I have seen an XMPP protocol infinite loop where I recieve endless Unsubscribe events. I got that to stop by not always responding with XmppCon.PresenceManager.Unsubscribe(pres.From).

Am I responding correctly to the subscribe and unsubscribe events here?

Also, the mini client example has a couple of places where the RosterManager is referenced. Is that left over code from another example or does it do something in the compact framework example?

I mean these calls:
_connection.RosterManager.AddRosterItem(jid, txtNickname.Text);
XmppCon.RosterManager.RemoveRosterItem(new Jid(itm.Tag as string));


Thanks,
-Ayyrk

  private void XmppCon_OnPresence(object sender, Presence pres)
        {

            Boolean isRosterChanged = false;

            Jid fromJid;
            String fromUser;
            String fromResource;

            fromJid = pres.From;
            fromUser = fromJid.User;
            fromResource = fromJid.Resource;

            try
            {
                if (_allBuddies.ContainsKey(fromUser)
        && fromResource != null
        && fromResource.Trim().Length > 0)
                {
                    if (!_allBuddies[fromUser].Resources.ContainsKey(fromResource))
                    {
                        JournalMessage.Instance.DebugLog("OP: Adding a resource: "
            + fromJid.User + "/" + fromJid.Resource);
                        _allBuddies[fromUser].addResource(fromJid);
                        isRosterChanged = true;
                    }
                }
            }
            catch (Exception)
            {
                JournalMessage.Instance.RuntimeLog("OP: Error 2");
                return;
            }

            try
            {
                // Check Presence Type
                if (pres.Type == PresenceType.subscribe)
                {
                     //subscribe       ask the recipient to subscribe you
                    JournalMessage.Instance.RuntimeLog("OP: " + fromUser + " asks \"subscribe me please\"");
                    XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid);
                    XmppCon.PresenceManager.Subscribe(fromJid);
                }
                else if (pres.Type == PresenceType.subscribed)
                {
                    //subscribed      tell the sender they are subscribed
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + ": \"You are subscribed\"");
                }
                else if (pres.Type == PresenceType.unsubscribe)
                {
                    if (AutoReplyEvent != null)
                    {
                        AutoReplyEvent(this, new StringEventArgs("Roster: " + fromUser));
                    }

                    //unsubscribe     ask the recipient to unsubscribe you
                    JournalMessage.Instance.RuntimeLog("OP: "
        + pres.From.User + ": \"Unsubscribe me please\"");
                   
                    // call Unsubscribe just ONCE
                    if (_allBuddies.ContainsKey(pres.From.User))
                    {
                        _allBuddies.Remove(pres.From.User);

                        isRosterChanged = true;

                        XmppCon.PresenceManager.Unsubscribe(pres.From);
                    }

                }
                else if (pres.Type == PresenceType.unsubscribed)
                {

                    //unsubscribed    tell the sender they are unsubscribed
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + ": \"You are unsubscribed\"");

                }
                else if (pres.Type == PresenceType.unavailable)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " PresenceType unavailable");

                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setAvailable(fromResource, false);
                        isRosterChanged = true;
                    }
                }
                else if (pres.Type == PresenceType.available)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " PresenceType available");

                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setAvailable(fromResource, true);
                        isRosterChanged = true;
                    }
                }
                else if (pres.Type == PresenceType.error)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " PresenceType error");
                }
                else if (pres.Type == PresenceType.invisible)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " PresenceType invisible");
                }
                else if (pres.Type == PresenceType.probe)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " PresenceType probe");
                }
                else
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " Unknown PresenceType " +             pres.Type);
                }
            }
            catch (Exception)
            {
                JournalMessage.Instance.RuntimeLog("OP: Error 3");
                return;
            }

            try
            {
                // check Presence Show
                if (pres.Show == ShowType.NONE)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType none");
                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setPresence(fromResource, true, "None");
                        isRosterChanged = true;
                    }
                }
                else if (pres.Show == ShowType.away)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType away");
                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setPresence(fromResource, false, "Away");
                        isRosterChanged = true;
                    }
                }
                else if (pres.Show == ShowType.chat)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType chat");
                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setPresence(fromResource, true, "Chat");
                        isRosterChanged = true;
                    }
                }
                else if (pres.Show == ShowType.dnd)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType DND");
                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setPresence(fromResource, false, "DND");
                        isRosterChanged = true;
                    }
                }
                else if (pres.Show == ShowType.xa)
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType extended away");
                    if (_allBuddies.ContainsKey(fromUser))
                    {
                        _allBuddies[fromUser].setPresence(fromResource, false, "Extended Away");
                        isRosterChanged = true;
                    }
                }
                else
                {
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + " ShowType unknown");
                }

                if (isRosterChanged && RosterChangedEvent != null)
                {
                    RosterChangedEvent();
                }
            }
            catch (Exception)
            {
                JournalMessage.Instance.RuntimeLog("OP: Error 4");
                return;
            }


        }
Avatar
Alex #10
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ayyrk:
  1. // Check Presence Type
  2. if (pres.Type == PresenceType.subscribe)
  3. {
  4.      //subscribe       ask the recipient to subscribe you
  5.     JournalMessage.Instance.RuntimeLog("OP: " + fromUser + " asks \"subscribe me please\"");
  6.     XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid);
  7.     XmppCon.PresenceManager.Subscribe(fromJid);
  8. }

this is not correct. If you get a subscription request you should check whether this contact is already on your roster. If not then approve the subscription request, add the contact and subscribe to it.
If the contact is already on the roster and subscribed then you only approve the subscription request.

            
Quote by ayyrk:
  1. else if (pres.Type == PresenceType.unsubscribe)
  2. {
  3.     if (AutoReplyEvent != null)
  4.     {
  5.         AutoReplyEvent(this, new StringEventArgs("Roster: " + fromUser));
  6.     }
  7.  
  8.     //unsubscribe     ask the recipient to unsubscribe you
  9.     JournalMessage.Instance.RuntimeLog("OP: "
  10. + pres.From.User + ": \"Unsubscribe me please\"");
  11.    
  12.     // call Unsubscribe just ONCE
  13.     if (_allBuddies.ContainsKey(pres.From.User))
  14.     {
  15.         _allBuddies.Remove(pres.From.User);
  16.  
  17.         isRosterChanged = true;
  18.  
  19.         XmppCon.PresenceManager.Unsubscribe(pres.From);
  20.     }
  21. }

this code is not needed, and there is no action required. Only the server handles unsubscribe requests and removes the subscription flags from the roster
             
Alex
Avatar
ayyrk #11
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Here's the code with the corrections.  How's it look? Thanks very much.
-Ayyrk


                if (pres.Type == PresenceType.subscribe)
                {
                   

                    //subscribe       ask the recipient to subscribe you
                    JournalMessage.Instance.RuntimeLog("OP: " + fromUser + " asks \"subscribe me please\"");

                    if (!_allBuddies.ContainsKey(fromUser)) // not already in roster
                    {
                        //If you get a subscription request you should check whether this contact
                        //is already on your roster. If not then approve the subscription request,
                        //add the contact and subscribe to it.

                        JournalMessage.Instance.RuntimeLogLog("OP: Adding a Buddy: " + fromUser);
                        XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid); // approve the contact
                        _allBuddies.Add(fromUser, new Buddy(fromJid)); // add to roster
                        XmppCon.PresenceManager.Subscribe(fromJid); // subscribe
                    }
                    else // already in roster
                    {
                        //If the contact is already on the roster and subscribed then you
                        //only approve the subscription request.
                        if (_allBuddies[fromUser].SubType == SubscriptionType.both) // already subscribed
                        {
                            XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid); // approve the contact
                        }
                    }
                }
                else if (pres.Type == PresenceType.subscribed)
                {
                    //subscribed      tell the sender they are subscribed
                    // do nothing on client
                    JournalMessage.Instance.DebugLog("OP: " + fromUser + ": \"You are subscribed\"");
                }
                else if (pres.Type == PresenceType.unsubscribe)
                {

                    //unsubscribe     ask the recipient to unsubscribe you
                    // do nothing on client
                    JournalMessage.Instance.RuntimeLog("OP: " + pres.From.User + ": \"Unsubscribe me please\"");
                }
Avatar
Alex #12
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ayyrk:
  1. else // already in roster
  2. {
  3.     //If the contact is already on the roster and subscribed then you
  4.     //only approve the subscription request.
  5.     if (_allBuddies[fromUser].SubType == SubscriptionType.both) // already subscribed
  6.     {
  7.         XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid); // approve the contact
  8.     }
  9. }

when the subscription is already both you will get no requests routed. The server approves the request on your behalf then.
I think SubscriptionTypes none and from is what you are looking for here.
Avatar
ayyrk #13
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Two more small changes and now testing - looks better.  Here's the two additional changes:

1) When a "Subscribe Me" presence event is received and the contact is already in the roster:
if (_allBuddies[fromUser].SubType == SubscriptionType.to
  || _allBuddies[fromUser].SubType == SubscriptionType.from
  || _allBuddies[fromUser].SubType == SubscriptionType.none) //already subscribed but not SubscriptionType.both
  {
       XmppCon.PresenceManager.ApproveSubscriptionRequest(fromJid); // approve the contact
       JournalMessage.Instance.RuntimeLog("OP: Approving " + fromUser);
  }


2) When an "Unsubscribe Me" presence event is received:
if (_allBuddies.ContainsKey(pres.From.User))
      _allBuddies.Remove(pres.From.User); // remove from roster
Avatar
Alex #14
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I think you aim is a mutual subscription (both). If subscription is none or from you have no subscription to the contact, so you should also subscribe to the contact, not only approve the subscription request.
Avatar
ayyrk #15
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Also should I be using XmppCon.RosterManager.AddRosterItem(fromJid) andXmppCon.RosterManager.RemoveRosterItem(fromJid) instead of updating my roster like this:

_allBuddies.Remove(pres.From.User);

I am adding and removing contacts from my buddy list in response to Presence callbacks. Question: Should I instead use the RosterManager add/remove calls inside the Presence callbacks? Would this cause the server to send me RosterItem changes?

Question: If I call RosterManager add/remove inside the Presence callback will that cause the server to send me RosterItem updates?

If that's the case then I can update my roster just in the RosterItem callback.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next
Forum: agsXMPP RSS