Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/strophe/strophejs/llms.txt

Use this file to discover all available pages before exploring further.

Strophe.js exposes a set of constant objects on the Strophe namespace to help you write readable, maintainable code without magic numbers or hard-coded strings. These constants cover connection lifecycle states, XMPP namespace URIs, log severity levels, error condition identifiers, DOM node types, and the XHTML-IM content filtering profile. All values are defined in src/constants.ts and are frozen at runtime — they cannot be modified.

Strophe.Status

Connection status constants are passed as the first argument to the callback function you supply to connection.connect(). Check against these values instead of raw integers to make your connection handler self-documenting.
conn.connect(jid, password, (status: number) => {
  if (status === Strophe.Status.CONNECTED) {
    console.log('Connected!');
  } else if (status === Strophe.Status.AUTHFAIL) {
    console.error('Authentication failed.');
  } else if (status === Strophe.Status.DISCONNECTED) {
    console.log('Disconnected.');
  }
});
ConstantValueDescription
Strophe.Status.ERROR0An unrecoverable error occurred.
Strophe.Status.CONNECTING1The connection is being established.
Strophe.Status.CONNFAIL2The connection attempt failed at the transport level.
Strophe.Status.AUTHENTICATING3The SASL authentication exchange is in progress.
Strophe.Status.AUTHFAIL4Authentication failed (bad credentials or no supported mechanism).
Strophe.Status.CONNECTED5Authentication succeeded and the session is active.
Strophe.Status.DISCONNECTED6The connection has been cleanly closed.
Strophe.Status.DISCONNECTING7A disconnect has been requested and is in progress.
Strophe.Status.ATTACHED8A pre-existing BOSH session has been successfully attached.
Strophe.Status.REDIRECT9The server has issued a redirect.
Strophe.Status.CONNTIMEOUT10The connection timed out.
Strophe.Status.BINDREQUIRED11Resource binding is required before the session can proceed.
Strophe.Status.ATTACHFAIL12Attaching to an existing BOSH session failed.
Strophe.Status.RECONNECTING13A reconnection attempt is underway after a transient failure.
Your connection callback may be called multiple times during a session’s lifetime (e.g. CONNECTINGAUTHENTICATINGCONNECTEDDISCONNECTINGDISCONNECTED). Always handle every relevant status, especially CONNFAIL and AUTHFAIL, to give users meaningful feedback.

Strophe.NS

Namespace URI constants for standard XMPP extensions and core protocol elements. Pass these to $iq, $msg, $pres builders or to handler filters to avoid typos in long URN strings.
// Using NS constants in a stanza builder
const iq = $iq({ type: 'get' })
  .c('query', { xmlns: Strophe.NS.ROSTER });

// Using NS constants in a handler
conn.addHandler(handleDiscoInfo, Strophe.NS.DISCO_INFO, 'iq', 'result');
ConstantValue
Strophe.NS.HTTPBIND'http://jabber.org/protocol/httpbind'
Strophe.NS.BOSH'urn:xmpp:xbosh'
Strophe.NS.CLIENT'jabber:client'
Strophe.NS.SERVER'jabber:server'
Strophe.NS.AUTH'jabber:iq:auth'
Strophe.NS.ROSTER'jabber:iq:roster'
Strophe.NS.PROFILE'jabber:iq:profile'
Strophe.NS.DISCO_INFO'http://jabber.org/protocol/disco#info'
Strophe.NS.DISCO_ITEMS'http://jabber.org/protocol/disco#items'
Strophe.NS.MUC'http://jabber.org/protocol/muc'
Strophe.NS.SASL'urn:ietf:params:xml:ns:xmpp-sasl'
Strophe.NS.STREAM'http://etherx.jabber.org/streams'
Strophe.NS.FRAMING'urn:ietf:params:xml:ns:xmpp-framing'
Strophe.NS.BIND'urn:ietf:params:xml:ns:xmpp-bind'
Strophe.NS.SESSION'urn:ietf:params:xml:ns:xmpp-session'
Strophe.NS.VERSION'jabber:iq:version'
Strophe.NS.STANZAS'urn:ietf:params:xml:ns:xmpp-stanzas'
Strophe.NS.XHTML_IM'http://jabber.org/protocol/xhtml-im'
Strophe.NS.XHTML'http://www.w3.org/1999/xhtml'
You can extend the namespace map at runtime using Strophe.addNamespace():
// Add a custom or non-standard namespace
Strophe.addNamespace('PING', 'urn:ietf:params:xml:ns:xmpp-ping');

// Now available as:
console.log(Strophe.NS.PING); // 'urn:ietf:params:xml:ns:xmpp-ping'

Strophe.LOG_LEVELS

Numeric severity levels used with Strophe.setLogLevel() and Strophe.log(). Strophe.js suppresses all log messages below the current log level.
// Only show warnings and above in production
Strophe.setLogLevel(Strophe.LOG_LEVELS.WARN);

// Enable full debug logging during development
Strophe.setLogLevel(Strophe.LOG_LEVELS.DEBUG);
ConstantValueDescription
Strophe.LOG_LEVELS.DEBUG0Verbose messages useful for tracing execution during development.
Strophe.LOG_LEVELS.INFO1Informational messages about normal operational events (e.g. “SASL auth succeeded”).
Strophe.LOG_LEVELS.WARN2Warnings about potentially problematic conditions (e.g. request timeouts).
Strophe.LOG_LEVELS.ERROR3Errors that indicate a problem occurred but the connection may still be recoverable.
Strophe.LOG_LEVELS.FATAL4Non-recoverable fatal errors. The connection will not continue after a FATAL log.
The default log level is DEBUG (0), meaning all messages are emitted. Set it to WARN or higher in production to reduce console noise.

Strophe.ErrorCondition

String identifiers for specific error conditions that Strophe.js passes to connection callbacks or throws in exceptions. Comparing against these constants is more robust than comparing against raw strings.
conn.connect(jid, password, (status, condition) => {
  if (status === Strophe.Status.CONNFAIL) {
    if (condition === Strophe.ErrorCondition.NO_AUTH_MECH) {
      console.error('Server does not support any authentication mechanism we can use.');
    }
  }
});
Strophe.ErrorCondition.BAD_FORMAT
string
'bad-format' — The server sent a stanza or response that could not be parsed or did not conform to the expected format.
Strophe.ErrorCondition.CONFLICT
string
'conflict' — A resource conflict occurred (e.g. another client connected with the same resource, causing the current session to be terminated).
Strophe.ErrorCondition.MISSING_JID_NODE
string
'x-strophe-bad-non-anon-jid' — A non-anonymous authentication was attempted but the JID provided has no node (local) part.
Strophe.ErrorCondition.NO_AUTH_MECH
string
'no-auth-mech' — The server did not advertise any SASL mechanism that Strophe.js supports (or all available mechanisms were disabled via test()).
Strophe.ErrorCondition.UNKNOWN_REASON
string
'unknown' — The connection failed for an unspecified or unrecognised reason.

Strophe.ElementType

DOM nodeType constants used internally by Strophe.js when traversing and constructing XML trees. These mirror the standard DOM Node type constants and are used in utility functions like copyElement(), createHtml(), and forEachChild().
// Checking a node type while traversing child nodes
for (const child of elem.childNodes) {
  if (child.nodeType === Strophe.ElementType.TEXT) {
    console.log('Text node:', child.nodeValue);
  } else if (child.nodeType === Strophe.ElementType.NORMAL) {
    console.log('Element node:', (child as Element).tagName);
  }
}
ConstantValueDOM EquivalentDescription
Strophe.ElementType.NORMAL1Node.ELEMENT_NODEA standard XML/HTML element node (e.g. <message>).
Strophe.ElementType.TEXT3Node.TEXT_NODEA text data node containing character content.
Strophe.ElementType.CDATA4Node.CDATA_SECTION_NODEA CDATA section node.
Strophe.ElementType.FRAGMENT11Node.DOCUMENT_FRAGMENT_NODEA document fragment node, used for grouping nodes without a parent element.

XHTML Allowed Values

The XHTML constant defines the safe subset of HTML permitted in XMPP message bodies under XEP-0071 (XHTML-IM). It is used by Strophe.createHtml() to sanitize incoming HTML before embedding it in an XMPP stanza.

Allowed Tags

The following tag names are permitted. All others are stripped (their text content is preserved in a document fragment):
Strophe.XHTML.tags = [
  'a', 'blockquote', 'br', 'cite', 'em',
  'img', 'li', 'ol', 'p', 'span',
  'strong', 'ul', 'body'
]

Allowed Attributes per Tag

Only these attributes are copied to the sanitized output. Any attribute not listed for the corresponding tag is dropped:
TagAllowed Attributes
ahref
blockquotestyle
br(none)
citestyle
em(none)
imgsrc, alt, style, height, width
listyle
olstyle
pstyle
spanstyle
strong(none)
ulstyle
body(none)

Allowed CSS Properties

When processing style attributes, only these CSS property names are preserved. Other declarations are silently dropped:
Strophe.XHTML.css = [
  'background-color',
  'color',
  'font-family',
  'font-size',
  'font-style',
  'font-weight',
  'margin-left',
  'margin-right',
  'text-align',
  'text-decoration',
]
Use Strophe.validTag(), Strophe.validAttribute(), and Strophe.validCSS() to check individual values programmatically. See the Utils reference for their signatures.
Always sanitize HTML through Strophe.createHtml() before embedding it in an XMPP stanza. Never pass raw user-supplied HTML directly — it may contain disallowed tags, scripts, or attributes that violate the XHTML-IM profile and could cause parsing errors on the receiving client.

Build docs developers (and LLMs) love