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.');
}
});
| Constant | Value | Description |
|---|
Strophe.Status.ERROR | 0 | An unrecoverable error occurred. |
Strophe.Status.CONNECTING | 1 | The connection is being established. |
Strophe.Status.CONNFAIL | 2 | The connection attempt failed at the transport level. |
Strophe.Status.AUTHENTICATING | 3 | The SASL authentication exchange is in progress. |
Strophe.Status.AUTHFAIL | 4 | Authentication failed (bad credentials or no supported mechanism). |
Strophe.Status.CONNECTED | 5 | Authentication succeeded and the session is active. |
Strophe.Status.DISCONNECTED | 6 | The connection has been cleanly closed. |
Strophe.Status.DISCONNECTING | 7 | A disconnect has been requested and is in progress. |
Strophe.Status.ATTACHED | 8 | A pre-existing BOSH session has been successfully attached. |
Strophe.Status.REDIRECT | 9 | The server has issued a redirect. |
Strophe.Status.CONNTIMEOUT | 10 | The connection timed out. |
Strophe.Status.BINDREQUIRED | 11 | Resource binding is required before the session can proceed. |
Strophe.Status.ATTACHFAIL | 12 | Attaching to an existing BOSH session failed. |
Strophe.Status.RECONNECTING | 13 | A reconnection attempt is underway after a transient failure. |
Your connection callback may be called multiple times during a session’s lifetime (e.g. CONNECTING → AUTHENTICATING → CONNECTED → DISCONNECTING → DISCONNECTED). 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');
| Constant | Value |
|---|
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);
| Constant | Value | Description |
|---|
Strophe.LOG_LEVELS.DEBUG | 0 | Verbose messages useful for tracing execution during development. |
Strophe.LOG_LEVELS.INFO | 1 | Informational messages about normal operational events (e.g. “SASL auth succeeded”). |
Strophe.LOG_LEVELS.WARN | 2 | Warnings about potentially problematic conditions (e.g. request timeouts). |
Strophe.LOG_LEVELS.ERROR | 3 | Errors that indicate a problem occurred but the connection may still be recoverable. |
Strophe.LOG_LEVELS.FATAL | 4 | Non-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
'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
'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
'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
'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
'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);
}
}
| Constant | Value | DOM Equivalent | Description |
|---|
Strophe.ElementType.NORMAL | 1 | Node.ELEMENT_NODE | A standard XML/HTML element node (e.g. <message>). |
Strophe.ElementType.TEXT | 3 | Node.TEXT_NODE | A text data node containing character content. |
Strophe.ElementType.CDATA | 4 | Node.CDATA_SECTION_NODE | A CDATA section node. |
Strophe.ElementType.FRAGMENT | 11 | Node.DOCUMENT_FRAGMENT_NODE | A 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.
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:
| Tag | Allowed Attributes |
|---|
a | href |
blockquote | style |
br | (none) |
cite | style |
em | (none) |
img | src, alt, style, height, width |
li | style |
ol | style |
p | style |
span | style |
strong | (none) |
ul | style |
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.