-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Practical XMPP
By :
The component that we are building will be listening for chat messages, and it will echo those chat messages back to the client. Using the same component.on('stanza') function that we implemented before, we can delegate to a handleMessage function if the incoming stanza is of type message. Modify your component.on('stanza') to the following:
component.on('stanza', function(stanza) {
if (true === stanza.is('iq')) {
handleIq(stanza);
}
else if (true === stanza.is('message')) {
handleMessage(stanza)
}
} )
Now that you are experienced in implementing a response to a DISCO#info request, you will probably find the response to a chat message to follow a familiar structure. We want to create a new stanza, again using the to/from of the sender as the from/to of our response, and we simply want to respond with the same message that we received.
Here is the handleMessage function:
const handleMessage = function(stanza) {
if (stanza.attrs...