Sending of availability information
OK. We’ve connected, authenticated, defined, and registered the
callback to handle <presence/> elements,
and requested
the roster, so mod_roster will send us any
presence subscription (or unsubscription) requests.
Now we need to make an availability announcement
in the form of a simple <presence/> element:
<presence/>
We can do this by calling the sendInitPresence()
method on the connection object:
con.sendInitPresence()
This availability information will be distributed to all the entities that are subscribed to the script’s presence and are online at that moment. It will also signify to the Jabber server that we are properly online—in which case it can forward to us any messages that had been stored up in our absence.
We’re not really expecting any <message/>
elements; indeed, we haven’t set up any subroutine to handle them, so
they’d just be thrown away by the library anyway. The real reason for
sending presence is so that the server will actively go and
probe those in a presence subscription relationship with the script and
report back on those who are available (who have themselves sent their
presence during their current session). This causes
<presence/> elements to arrive on the
stream and make their way to the presenceCB()
handler.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access