HTML and CSS Reference
In-Depth Information
Figure 4-9. Observing presence changes in the browser
Exchanging Chat Messages
Here, we get to the core of any IM application: chat messages. Chat messages are
represented as message stanzas with the type attribute set to chat . The Strophe.js
connection API has an addHandler() function that lets us listen for incoming message
stanzas matching that type, as shown in Listing 4-11.
Listing 4-11. Listening for Incoming “Chat” Message Stanzas
function messageHandler(message) {
var from = message.getAttribute("from");
var body = "";
Strophe.forEachChild(message, "body", function(elem) {
body = elem.textContent;
});
// Log message if body was present
if (body) {
log(from + ": " + body);
}
 
Search WWH ::




Custom Search