Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
martinbach #1
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to react on a subscription request "subscribe"
Hi Alex,

how should my app react on a subscription request "subscribe":

eg.

<presence from='romeo@example.net'
                 id='xk3h1v69'
                 to='juliet@example.com'
                 type='subscribe'/>

I'd like to react by letting the receiving app chose to return subscribed  or unsubscribed.

My questions are:

1. How do I trigger and send the answer in MatriX:

<presence from='juliet@example.com'
                 id='xk3h1v69'
                 to='romeo@example.net'
                 type='unsubscribed'/>

or

<presence from='juliet@example.com'
                 id='xk3h1v69'
                 to='romeo@example.net'
                 type='subscribed'/>

2. Is "presenceManager.OnSubscribe" the right place to react on the request or should I
use OnPresence:

private void xmppClient_OnPresence(object sender, Matrix.Xmpp.Client.PresenceEventArgs e)
{
    if (e.Presence.Type == PresenceType.subscribe)
               {
         ...
    }
    ...
}

Thank you.

Martin
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by martinbach:
<presence from='romeo@example.net'
                 id='xk3h1v69'
                 to='juliet@example.com'
                 type='subscribe'/>

I'd like to react by letting the receiving app chose to return subscribed  or unsubscribed.

You fetch the jid from the request an then either use
ApproveSubscriptionRequest(Jid to) or DenySubscriptionRequest(Jid to) of the PresenceManager.

Quote by martinbach:
2. Is "presenceManager.OnSubscribe" the right place to react on the request or should I
use OnPresence:

private void xmppClient_OnPresence(object sender, Matrix.Xmpp.Client.PresenceEventArgs e)
{
    if (e.Presence.Type == PresenceType.subscribe)
               {
         ...
    }
    ...
}
yes, the PresenManager handles the OnPresence event and gives you the events:

  • OnAvailablePresence
  • OnUnavailablePresence
  • OnSubscribe
  • OnSubscribed
  • OnUnsubscribe
  • OnUnsubscribed
  • OnInvisiblePresence
  • OnPresenceError

The PresenceManager is a wrapper which makes it much easier for you to use Presence.

Alex
Avatar
martinbach #3
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

thank you for the very quick answer.

I will try it asap.

Thanks,

Martin
Avatar
wamra #4
Member since Apr 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Problem with the PresenceManager.OnSubscribed
I am having a problem with the OnSubscribed event in PresenceManager.

User1 tries to add User2
User2 login and accept User1
User1 receives a confirmation:

  1. RCV: Receiving..............................
  2. <iq type="result" id="642-409" from="testuser2@mktdevpc1729" to="testuser1@mktdevpc1729/Velocity" xmlns="jabber:client">
  3.  <pubsub xmlns="http://jabber.org/protocol/pubsub">
  4.     <subscription jid="testuser1@mktdevpc1729" subscription="subscribed">
  5.       <subscribe-options />
  6.     </subscription>
  7.  </pubsub>
  8. </iq>
  9. ..............................
  10. RCV: Receiving..............................
  11. <presence from="testuser2@mktdevpc1729/mktdevpc1729" to="testuser1@mktdevpc1729/Velocity" xmlns="jabber:client">
  12. <priority>5</priority>
  13. <c xmlns="http://jabber.org/protocol/caps" node="http://psi-im.org/caps" ver="caps-b75d8d2b25" ext="ca cs ep-notify html" />
  14. </presence>
  15. ..............................

User1 PresenceManager.OnSubscribed doesn't seem to get triggered :(
This post was edited 2 times, last on 2011-04-01, 19:30 by wamra.
Avatar
Alex #5
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The PresenceManager is for Presence subscriptions (roster subscriptions), not for pubsub subscriptions.

Alex
Avatar
wamra #6
Member since Apr 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
How else can you confirm a result for the Asynch operations below.

  1.             RosterManager.Add(user, nickName, groupNames.ToArray());
  2.             PresenceManager.Subscribe(user);

I need to listen for some server confirmation to add the users to a display list.
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the server sends out a roster push whenever something changes in the subscription. So you get notified with an OnRosterItem event.
You can also listen to the OnPresence event which send you a subscribed after a contact accepted your request. There is also a OnSubscribed event in the PresenceManager.

Alex
Avatar
wamra #8
Member since Apr 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Roster don't update when another user accept's subscription request
There is a problem, it is not behaving the way you describe it. I am using the latest version of Openfire
1 - The OnSubscribed function is never called on User1
2 - The Presence from User2 -> User1 is not enough, it doesn't have the display name and User2 needs to be online for User1 to detect/get the subscribed note. See the bottom of the log below, and I will attach a file as well.

Is there a way to enforce/request Roster updates?


other wise I will have to disconnect User1, reconnect to get the User2 RosterItem :(

  1. testuser2 -   # RCV: Receiving #################################################
  2.                     # <presence from="testuser1@devpc1729/VServer" to="testuser2@devpc1729" type="subscribe" xmlns="jabber:client" />
  3.                     # ################################################################
  4. testuser2 -   # SND: Sending #################################################
  5.                     # <presence type="subscribed" to="testuser1@devpc1729" xmlns="jabber:client" />
  6.                     # ################################################################
  7. User: testuser2@devpc1729/VServer accepted user testuser1@devpc1729/VServer for subscription.
  8. testuser2 -   # RCV: Receiving #################################################
  9.                     # <iq type="set" id="502-118" to="testuser2@devpc1729/VServer" xmlns="jabber:client">
  10.                     #   <query xmlns="jabber:iq:roster">
  11.                     #     <item jid="testuser1@devpc1729" subscription="from" />
  12.                     #   </query>
  13.                     # </iq>
  14.                     # ################################################################
  15. Retrieving Roster Item  / testuser1@devpc1729 / NONE
  16. testuser1 -   # SND: Sending #################################################
  17.                     # <presence xmlns="jabber:client">
  18.                     #   <status></status>
  19.                     #   <priority>0</priority>
  20.                     # </presence>
  21.                     # ################################################################
  22. testuser1 -   # RCV: Receiving #################################################
  23.                     # <iq type="result" id="MX_7" to="testuser1@devpc1729/VServer" xmlns="jabber:client" />
  24.                     # ################################################################
  25. testuser2 -   # SND: Sending #################################################
  26. testuser1 -   # RCV: Receiving #################################################
  27.                     # <presence from="testuser2@devpc1729/VServer" to="testuser1@devpc1729/VServer" xmlns="jabber:client">
  28.                     #   <status />
  29.                     #   <priority>0</priority>
  30.                     # </presence>
  31.                     # ################################################################
  32.                     # <iq type="result" id="502-118" xmlns="jabber:client" />
  33.                     # ################################################################
  34. testuser1 -   # RCV: Receiving #################################################
  35.                     # <message to="testuser1@devpc1729/VServer" from="testuser2@devpc1729" id="testuser2@devpc1729__testuser1@devpc1729__ryA9a" xmlns="jabber:client">
  36.                     #   <event xmlns="http://jabber.org/protocol/pubsub#event">
  37.                     #     <items node="http://jabber.org/protocol/mood">
  38.                     #       <item id="current">
  39.                     #         <mood xmlns="http://jabber.org/protocol/mood">
  40.                     # <anxious />
  41.                     # </mood>
  42.                     #       </item>
  43.                     #     </items>
  44.                     #   </event>
  45.                     #   <delay xmlns="urn:xmpp:delay" stamp="2011-03-22T17:34:55.489Z" />
  46.                     #   <addresses xmlns="http://jabber.org/protocol/address">
  47.                     #     <address type="replyto" jid="testuser2@devpc1729/devpc1729" />
  48.                     #   </addresses>
  49.                     # </message>
  50.                     # ################################################################
  51. Message recieved from testuser2@devpc1729 : ''
  52. testuser1 -   # SND: Sending #################################################
  53.                     # </stream:stream>
  54.                     # ################################################################
  55. testuser1 -   # RCV: Receiving #################################################
  56.                     # </stream:stream>
  57.                     # ################################################################
  58. Disconnected - User: testuser1 / TestUser1 / Resource:VServer @ Domain: devpc1729 / Host:
The author has attached one file to this post:
AddUser- ChatLog.txt 12.5 kBytes
You have no permission to open this file.
Avatar
Alex #9
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the problem is that you need a mutual subscription. In your log I see only 1 user asking for presence, but not the other user. In XMPP both users accept the request to get a mutual subscription. Mutual means subscription="both" in the roster item.

Both users have to ask for presence (subscribe). So When your user2 received the subscription requests and accepts it he should at the same time send a subscription request to user1 when he is not already subscribed.

You don't need to send the presence on your own, the server automatically distributes it when the subscription requests succeed.

When you send a subscription request to a user which is offline then the server delivers the request when teh user comes online the next time. When the user ignores it then the server resends the request o each login until you process it.

Alex
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: