O'Reilly logo

XMPP: The Definitive Guide by Remko Tronçon, Kevin Smith, Peter Saint-Andre

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Directed Presence

The presence notifications we’ve looked at so far have been broadcast—that is, they are sent to everyone in your roster (you indicate that you want a presence notification to be broadcast by leaving off the to address). But what if you want to send presence to someone who is not in your roster? Perhaps you want to chat with someone for a little while but don’t want to add that person to your roster and therefore share presence on a permanent basis. In this case, you can send directed presence to the other person, i.e., presence that has a to address.

Consider what happens when Alice goes down the rabbit hole and meets the White Rabbit. Because the rabbit isn’t in her roster, she sends a message but also sends directed presence:

<message from="alice@wonderland.lit/rabbithole"
         to="whiterabbit@wonderland.lit"
         type="chat">
  <body>If you please, sir--</body>
</message>

<presence from="alice@wonderland.lit/rabbithole"
          to="whiterabbit@wonderland.lit"/>

The White Rabbit is too frightened to reply, but his IM client at least sends directed presence back to Alice:

<presence from="whiterabbit@wonderland.lit/mobile"
          to="alice@wonderland.lit/rabbithole"
          type="unavailable"/>

This kind of temporary presence sharing without a long-term subscription is a best practice for brief interactions over the network. And as we’ll see in Chapter 4, directed presence is also used to join and leave multi-user chat rooms (another form of temporary interaction).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required