Converse converse.js

Class: Handler

Handler(handler, ns, name, type, idopt, fromopt, optionsopt)

Private helper class for managing stanza handlers.

A Strophe.Handler encapsulates a user provided callback function to be executed when matching stanzas are received by the connection. Handlers can be either one-off or persistant depending on their return value. Returning true will cause a Handler to remain active, and returning false will remove the Handler.

Users will not use Strophe.Handler objects directly, but instead they will use Strophe.Connection.addHandler and Strophe.Connection.deleteHandler.

Constructor

new Handler(handler, ns, name, type, idopt, fromopt, optionsopt)

Create and initialize a new Strophe.Handler.

Parameters:
Name Type Attributes Description
handler function

A function to be executed when the handler is run.

ns string

The namespace to match.

name string

The element name to match.

type string | Array.<string>

The stanza type (or types if an array) to match.

id string <optional>

The element id attribute to match.

from string <optional>

The element from attribute to match.

options HandlerOptions <optional>

Handler options

Source:

Methods

getNamespace(elem) → {string}

Returns the XML namespace attribute on an element. If ignoreNamespaceFragment was passed in for this handler, then the URL fragment will be stripped.

Parameters:
Name Type Description
elem Element

The XML element with the namespace.

Source:
Returns:
  • The namespace, with optionally the fragment stripped.
Type
string

isMatch(elem) → {boolean}

Tests if a stanza matches the Strophe.Handler.

Parameters:
Name Type Description
elem Element

The XML element to test.

Source:
Returns:
  • true if the stanza matches and false otherwise.
Type
boolean

namespaceMatch(elem) → {boolean}

Tests if a stanza matches the namespace set for this Strophe.Handler.

Parameters:
Name Type Description
elem Element

The XML element to test.

Source:
Returns:
  • true if the stanza matches and false otherwise.
Type
boolean

run(elem) → {boolean}

Run the callback on a matching stanza.

Parameters:
Name Type Description
elem Element

The DOM element that triggered the Strophe.Handler.

Source:
Returns:
  • A boolean indicating if the handler should remain active.
Type
boolean

toString() → {string}

Get a String representation of the Strophe.Handler object.

Source:
Returns:
Type
string