try the following:
addHandler(context.onMessage, null, 'message', 'chat')//or 'normal'
from Wrox Professional XMPP Programming with JavaScript and jQuery Book:
The addHandler () function takes one or more parameters. The first parameter is a function that is called when the corresponding stanza is received. The remaining parameters meet the criteria.
A complete list of these parameters is shown in this abbreviated definition of a function from the Strophe source code:
addHandler: function (handler, ns, name, type, id, from) { // implementation omitted }
If any of the criteria is null or undefined, any stanza will match. Otherwise, stanzas will only match if they meet the criteria for equality of strings in a certain part of the stanza.
The last four criteria - name, type, id and from - specify filters by stanzas element name and type, id and from attributes. These four criteria are checked only on the top-level element, and not on any of the elements descendants. The first criterion, ns, is slightly different, and it is checked for a top-level element as well as for its immediate children. You understand why soon. The name criterion will almost always be null to match any stanza or single message, presence, or iq. In the addHandler () example, a handler is created that will be called for any stanza received.
Type, identifier and criteria correspond to the main attributes and stanzas.
You can use the type to distinguish between regular chat messages and group chat messages or to separate stanzas of the IQ result from the lines of IQ errors. The id criterion is often used to process responses to specific requests, such as the IQ result associated with a particular IQ-get request.
source share