Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
WMFGREEN #1
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: Announce presence to server
Is there a method in the MatriX library that announces presence to server ?

For example before using MatriX I was using a library called Coversant and I had something like this:

            // create the Jabber user to connect
            JabberID jabberId = new JabberID(user, SessionInfo.ServerName, ActiveResource);
            // login
            _session.Login(jabberId, password);

            // announce the user to the server
            AvailableRequest announce = new AvailableRequest();
            _session.SendAndForget(announce);

            // announce the user to the administrator user on the server
            JabberID serverJabberId = new JabberID("api2", SessionInfo.ServerName, "xmpphp");
            AvailableRequest announcePresenceToServer = new AvailableRequest(serverJabberId);
            _session.SendAndForget(announcePresenceToServer);

Is there something equivalent in MatriX?
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
When AutoPresence is true then MatriX sends the presence with the params set in the Show, Status and Priority properties automatically after login. When you want to update your presence use SendPresence.

Alex
Avatar
WMFGREEN #3
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
    How can I send my presence to an user that does not have a subscription?
Avatar
Alex #4
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The following code sends a directed presence:

  1. xmppClient.Send(new Presence
  2. {
  3.     To = "user@server.org/resource",
  4.     Show = Matrix.Xmpp.Show.away,
  5.     Status = "my status"
  6. });
Avatar
WMFGREEN #5
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
      When I send presence like this it raises the OnClose() event. Also I don't see user online. Any tips?
Avatar
Alex #6
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Are you properly connected when sending the presence?
Can you attach or post the Xml log?
Avatar
WMFGREEN #7
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
Hi,

Below is the XML exchanged between the server and the Matrix client.

  1. Send:     <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="jabber.mysora.net" version="1.0" >
  2. Receive:    <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="2170400850" from="jabber.mysora.net" version="1.0" xml:lang="en" >
  3. Receive:    <stream:features xmlns:stream="http://etherx.jabber.org/streams">  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">    <mechanism>PLAIN</mechanism>  </mechanisms>  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.process-one.net/en/ejabberd/" ver="wwrSvLFOLzC92POh074kJuEqYxE=" />  <register xmlns="http://jabber.org/features/iq-register" /></stream:features>
  4. Send:      <auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">AGU1N.....</auth>
  5. Receive:    <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
  6. Send:      <presence to="xxxx@jabber.mysora.net/resource" xmlns="jabber:client">  <show>dnd</show></presence>
  7. Send:      <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="jabber.mysora.net" version="1.0" >
  8. Receive:    <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="736943883" from="jabber.mysora.net" lang="en" >
  9. Receive:    <stream:error xmlns:stream="http://etherx.jabber.org/streams">  <invalid-namespace xmlns="urn:ietf:params:xml:ns:xmpp-streams" /></stream:error>

As far as I see i'm successfully logged when sending the presence.
Thanks in advance for your help.
Avatar
Alex #8
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by WMFGREEN:
As far as I see i'm successfully logged when sending the presence.
Thanks in advance for your help.
no, you are sending this to early. Your session is not ready yet. Make sure that AutoRoster is true and don't send this presence before you got the OnRosterEnd event.

Alex
Avatar
WMFGREEN #9
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thank you very much. It works now.
Avatar
Alex #10
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
great to hear.

Be aware that MatriX is asynchronous. When the Open() call returns this means MatriX is processing the XMPP connect, but not already connected. This is why you have to listen to events.
Avatar
WMFGREEN #11
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
Yes, I knew about the fact that the Open() method is asynchronous because I read it somewhere on your site.
By the way another problem was the Show property. When the Show property was set to something else than Show.NONE it didn't send the presence properly. ( I couldn't see user online )
Don't know why this happens but it seems to work fine when Show property is set to Show.NONE. ( I can see user online )

Thanks again.
Avatar
Alex #12
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by WMFGREEN:
By the way another problem was the Show property. When the Show property was set to something else than Show.NONE it didn't send the presence properly. ( I couldn't see user online )

this must work with all other show types as well.
Avatar
WMFGREEN #13
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
It seemed to send presence properly in the xml log even with other values of the Show property, but the problem was that I couldn't see user online. ( maybe it was a delay?!?, maybe it would have appeared online later?!? )
Even if I don't get this figured out I think my problem is solved with Show set to Show.NONE .
Avatar
Alex #14
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
it must show immediately. When it doesn't then there is still something wrong in your code.
  • Are you sending to the correct full Jid?
  • Is this Jid and resource properly connected?
Avatar
WMFGREEN #15
Member since Jan 2012 · 20 posts
Group memberships: Members
Show profile · Link to this post
Yes, the Jid and resource are correct and properly connected.
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:
Forum: MatriX RSS