HTML and CSS Reference
In-Depth Information
Listing 4-9. Handling Presence Updates
function presenceHandler(presence) {
var from = presence.getAttribute("from");
var show = "";
var status = "";
Strophe.forEachChild(presence, "show", function(elem) {
show = elem.textContent;
});
Strophe.forEachChild(presence, "status", function(elem) {
status = elem.textContent;
});
//
if (show || status){
log("[presence] " + from + ":" + status + " " + show);
}
// indicate that this handler should be called repeatedly
return true;
}
To handle presence updates with this function, we register the handler with
the connection object (see Listing 4-10). This call to addHandler() will associate the
presenceHandler() function with every presence stanza.
Listing 4-10. Registering the Presence Handler
connection.addHandler(presenceHandler, null, "presence", null);
Figure 4-9 shows that as websocketuser updates his presence status using the desktop
client to “Gone fishing - Do Not Disturb,” the browser client displays it right away.
 
Search WWH ::




Custom Search