Presence callback
Having dealt with the incoming <message/>
elements, we turn to the
<presence/> elements. Most of those we
receive in this conference room will be notifications from people
entering and leaving the room, as shown in
Example 9-2. We want to perform housekeeping on
our keywords dictionary so the entries don’t become
stale. We also want to deal with the potential problem of conflicting nicknames.
Let’s look at that first.
We want to check for the possibility of nickname conflict
problems that may occur when we enter the room, and the chosen
nickname (flash) is already taken.
Remembering that a conflict notification will look something like this:
<presence to='qmacro@jabber.com/jarltk'
from='cellar@conf.merlix.dyndns.org/flash'
type='error'>
<error code='409'>Conflict</error>
</presence>
we test for the receipt of a <presence/>
element with the following:
def presenceCB(con, prs):
# Deal with nickname conflict in room
if str(prs.getFrom()) == roomjid and prs.getType() == 'error':
prsnode = prs.asNode()
error = prsnode.getTag('error')
if error:
if (error.getAttr('code') == '409'):
print "Cannot join room - conflicting nickname"
con.disconnect()
sys.exit(0)
The <presence/> element will appear to
be sent from the JID that we constructed for the initial room entry
negotiation (in the roomjid variable further down
in the script); for example:
jdev@conference.jabber.org/kassist
We compare this value to the value of the incoming
<presence/>’s from attribute, and also ...
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