O'Reilly logo

Practical XMPP by David Koelle, Lloyd Watkin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Responding to a chat message

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required