Global

Members

(constant) ElementType

DOM element types.

  • ElementType.NORMAL - Normal element.
  • ElementType.TEXT - Text data element.
  • ElementType.FRAGMENT - XHTML fragment element.
Source:

(constant) XHTML

Contains allowed tags, tag attributes, and css properties. Used in the Strophe.createHtml function to filter incoming html into the allowed XHTML-IM subset. See XEP-0071 for the list of recommended allowed tags and their attributes.

Source:

_requestId

Private variable that keeps track of the request ids for connections.

Source:

_xmlGenerator :Document

Type:
  • Document
Source:

(constant) connectionPlugins :Object.<string, Object>

Private variable Used to store plugin names that need initialization during Connection construction.

Type:
  • Object.<string, Object>
Source:

manager :ConnectionManager

Type:
Source:

Methods

$build(name, attrsopt) → {Builder}

Create a Strophe.Builder This is an alias for new Strophe.Builder(name, attrs).

Parameters:
Name Type Attributes Description
name string

The root element name.

attrs Object.<string, (string|number)> <optional>

The attributes for the root element in object notation.

Source:
Returns:

A new Strophe.Builder object.

Type
Builder

$iq(attrsopt) → {Builder}

Create a Strophe.Builder with an <iq/> element as the root.

Parameters:
Name Type Attributes Description
attrs Object.<string, string> <optional>

The element attributes in object notation.

Source:
Returns:

A new Strophe.Builder object.

Type
Builder

$msg(attrsopt) → {Builder}

Create a Strophe.Builder with a <message/> element as the root.

Parameters:
Name Type Attributes Description
attrs Object.<string, string> <optional>

The element attributes in object notation.

Source:
Returns:

A new Strophe.Builder object.

Type
Builder

$pres(attrsopt) → {Builder}

Create a Strophe.Builder with a <presence/> element as the root.

Parameters:
Name Type Attributes Description
attrs Object.<string, string> <optional>

The element attributes in object notation.

Source:
Returns:

A new Strophe.Builder object.

Type
Builder

addCookies(cookies)

Parameters:
Name Type Description
cookies Cookies
Source:

arrayBufToBase64(buffer) → {string}

Parameters:
Name Type Description
buffer ArrayBufferLike
Source:
Returns:
Type
string

base64ToArrayBuf(str) → {ArrayBufferLike}

Parameters:
Name Type Description
str string
Source:
Returns:
Type
ArrayBufferLike

generate_cnonce() → {string}

Generate an ASCII nonce (not containing the ',' character)

Source:
Returns:
Type
string

getDOMParserImplementation()

DOMParser https://w3c.github.io/DOM-Parsing/#the-domparser-interface

Interface to parse XML strings into Document objects

Used implementations:

  • supported browsers: built-in in DOMParser global https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#Browser_compatibility
  • nodejs: use '@xmldom/xmldom' module https://www.npmjs.com/package/@xmldom/xmldom
Source:

getDummyXMLDOMDocument()

Creates a dummy XML DOM document to serve as an element and text node generator.

Used implementations:

  • IE < 10: avoid using createDocument() due to a memory leak, use ie-specific workaround
  • other supported browsers: use document's createDocument
  • nodejs: use '@xmldom/xmldom'
Source:

getWebSocketImplementation()

WHATWG WebSockets API https://www.w3.org/TR/websockets/

Interface to use the web socket protocol

Used implementations:

  • supported browsers: built-in in WebSocket global https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Browser_compatibility
  • nodejs: use standard-compliant 'ws' module https://www.npmjs.com/package/ws
Source:

handleError(e)

Properly logs an error to the console

Parameters:
Name Type Description
e Error
Source:

(async) scramClientProof(authMessage, clientKey, hashName)

Parameters:
Name Type Description
authMessage string
clientKey ArrayBufferLike
hashName string
Source:

(async) scramDeriveKeys(password, salt, iter, hashName, hashBits)

Derive the client and server keys given a string password, a hash name, and a bit length. Returns an object of the following form: { ck: ArrayBuffer, the client key sk: ArrayBuffer, the server key }

Parameters:
Name Type Description
password string
salt BufferSource
iter number
hashName string
hashBits number
Source:

scramParseChallenge(challenge)

This function parses the information in a SASL SCRAM challenge response, into an object of the form { nonce: String, salt: ArrayBuffer, iter: Int } Returns undefined on failure.

Parameters:
Name Type Description
challenge string
Source:

(async) scramServerSign(authMessage, sk, hashName)

Parameters:
Name Type Description
authMessage string
sk BufferSource
hashName string
Source:

stringToArrayBuf(str) → {ArrayBufferLike}

Parameters:
Name Type Description
str string
Source:
Returns:
Type
ArrayBufferLike

stx(strings, …values)

Tagged template literal function which generates Stanza objects

Parameters:
Name Type Attributes Description
strings Array.<string>
values any <repeatable>
Source:
Example
stx`<presence type="${type}" xmlns="jabber:client"><show>${show}</show></presence>`

toStanza(string, throwErrorIfInvalidNSopt) → {Element}

Parameters:
Name Type Attributes Description
string string
throwErrorIfInvalidNS boolean <optional>
Source:
Returns:
Type
Element

utf16to8(str) → {string}

Parameters:
Name Type Description
str string
Source:
Returns:
Type
string

xmlElement(name, attrsopt, textopt) → {Element}

Create an XML DOM element.

This function creates an XML DOM element correctly across all implementations. Note that these are not HTML DOM elements, which aren't appropriate for XMPP stanzas.

Parameters:
Name Type Attributes Description
name string

The name for the element.

attrs Array.<Array.<string>> | Object.<string, (string|number)> | string | number <optional>

An optional array or object containing key/value pairs to use as element attributes. The object should be in the format {'key': 'value'}. The array should have the format [['key1', 'value1'], ['key2', 'value2']].

text string | number <optional>

The text child data for the element.

Source:
Returns:

A new XML DOM element.

Type
Element

xmlGenerator() → {Document}

Get the DOM document to generate elements.

Source:
Returns:
  • The currently used DOM document.
Type
Document

xmlHtmlNode(html) → {XMLDocument}

Creates an XML DOM node.

Parameters:
Name Type Description
html string

The content of the html node.

Source:
Returns:
Type
XMLDocument

xmlTextNode(text) → {Text}

Creates an XML DOM text node. Provides a cross implementation version of document.createTextNode.

Parameters:
Name Type Description
text string

The content of the text node.

Source:
Returns:
  • A new XML DOM text node.
Type
Text

xorArrayBuffers(x, y)

Parameters:
Name Type Description
x ArrayBufferLike
y ArrayBufferLike
Source:

Type Definitions

ConnectionOptions

Type:
  • Object
Properties:
Name Type Attributes Description
cookies Cookies <optional>

Allows you to pass in cookies that will be included in HTTP requests. Relevant to both the BOSH and Websocket transports.

The passed in value must be a map of cookie names and string values.

{ "myCookie": { "value": "1234", "domain": ".example.org", "path": "/", "expires": expirationDate } }

Note that cookies can't be set in this way for domains other than the one that's hosting Strophe (i.e. cross-domain). Those cookies need to be set under those domains, for example they can be set server-side by making a XHR call to that domain to ask it to set any necessary cookies.

mechanisms Array.<SASLMechanism> <optional>

Allows you to specify the SASL authentication mechanisms that this instance of Connection (and therefore your XMPP client) will support.

The value must be an array of objects with SASLMechanism prototypes.

If nothing is specified, then the following mechanisms (and their priorities) are registered:

 Mechanism       Priority
 ------------------------
 SCRAM-SHA-512   72
 SCRAM-SHA-384   71
 SCRAM-SHA-256   70
 SCRAM-SHA-1     60
 PLAIN           50
 OAUTHBEARER     40
 X-OAUTH2        30
 ANONYMOUS       20
 EXTERNAL        10
explicitResourceBinding boolean <optional>

If explicitResourceBinding is set to true, then the XMPP client needs to explicitly call Connection.bind once the XMPP server has advertised the urn:ietf:propertys:xml:ns:xmpp-bind feature.

Making this step explicit allows client authors to first finish other stream related tasks, such as setting up an XEP-0198 Stream Management session, before binding the JID resource for this session.

protocol 'ws' | 'wss' <optional>

Note: This option is only relevant to Websocket connections, and not BOSH

If you want to connect to the current host with a WebSocket connection you can tell Strophe to use WebSockets through the "protocol" option. Valid values are ws for WebSocket and wss for Secure WebSocket. So to connect to "wss://CURRENT_HOSTNAME/xmpp-websocket" you would call

 const conn = new Strophe.Connection(
     "/xmpp-websocket/",
     {protocol: "wss"}
 );

Note that relative URLs NOT starting with a "/" will also include the path of the current site.

Also because downgrading security is not permitted by browsers, when using relative URLs both BOSH and WebSocket connections will use their secure variants if the current connection to the site is also secure (https).

worker string <optional>

Note: This option is only relevant to Websocket connections, and not BOSH

Set this option to URL from where the shared worker script should be loaded.

To run the websocket connection inside a shared worker. This allows you to share a single websocket-based connection between multiple Connection instances, for example one per browser tab.

The script to use is the one in src/shared-connection-worker.js.

sync boolean <optional>

Used to control whether BOSH HTTP requests will be made synchronously or not. The default behaviour is asynchronous. If you want to make requests synchronous, make "sync" evaluate to true.

const conn = new Strophe.Connection("/http-bind/", {sync: true});

You can also toggle this on an already established connection.

conn.options.sync = true;

customHeaders Array.<string> <optional>

Used to provide custom HTTP headers to be included in the BOSH HTTP requests.

keepalive boolean <optional>

Used to instruct Strophe to maintain the current BOSH session across interruptions such as webpage reloads.

It will do this by caching the sessions tokens in sessionStorage, and when "restore" is called it will check whether there are cached tokens with which it can resume an existing session.

withCredentials boolean <optional>

Used to indicate wether cookies should be included in HTTP requests (by default they're not). Set this value to true if you are connecting to a BOSH service and for some reason need to send cookies to it. In order for this to work cross-domain, the server must also enable credentials by setting the Access-Control-Allow-Credentials response header to "true". For most usecases however this setting should be false (which is the default). Additionally, when using Access-Control-Allow-Credentials, the Access-Control-Allow-Origin header can't be set to the wildcard "*", but instead must be restricted to actual domains.

contentType string <optional>

Used to change the default Content-Type, which is "text/xml; charset=utf-8". Can be useful to reduce the amount of CORS preflight requests that are sent to the server.

Source:

Cookies

Type:
  • Object.<string, string>
Source:

Cookies

A map of cookie names to string values or to maps of cookie values.

Type:
  • Object.<string, string>
Source:

HandlerOptions

Type:
  • Object
Properties:
Name Type Attributes Description
HandlerOptions.matchBareFromJid boolean <optional>
HandlerOptions.ignoreNamespaceFragment boolean <optional>
Source:

HandlerOptions

Type:
  • Object
Properties:
Name Type Attributes Description
HandlerOptions.matchBareFromJid boolean <optional>
HandlerOptions.ignoreNamespaceFragment boolean <optional>
Source:

LogLevels

Logging level indicators.

Type:
  • 0 | 1 | 2 | 3 | 4
Source:

NS

Common namespace constants from the XMPP RFCs and XEPs.

Type:
  • Object
Properties:
Name Type Description
NS.HTTPBIND string

HTTP BIND namespace from XEP 124.

NS.BOSH string

BOSH namespace from XEP 206.

NS.CLIENT string

Main XMPP client namespace.

NS.AUTH string

Legacy authentication namespace.

NS.ROSTER string

Roster operations namespace.

NS.PROFILE string

Profile namespace.

NS.DISCO_INFO string

Service discovery info namespace from XEP 30.

NS.DISCO_ITEMS string

Service discovery items namespace from XEP 30.

NS.MUC string

Multi-User Chat namespace from XEP 45.

NS.SASL string

XMPP SASL namespace from RFC 3920.

NS.STREAM string

XMPP Streams namespace from RFC 3920.

NS.BIND string

XMPP Binding namespace from RFC 3920 and RFC 6120.

NS.SESSION string

XMPP Session namespace from RFC 3920.

NS.XHTML_IM string

XHTML-IM namespace from XEP 71.

NS.XHTML string

XHTML body namespace from XEP 71.

NS.STANZAS string
NS.FRAMING string
Source:

Password

Type:
  • Object
Properties:
Name Type Description
Password.name string
Password.ck string
Password.sk string
Password.iter number
Password.salt string
Source:

Password

Type:
  • Object
Properties:
Name Type Description
Password.name string
Password.ck string
Password.sk string
Password.iter number
salt string
Source:

SASLData

Type:
  • Object.<string, any>
Properties:
Name Type Attributes Description
SASLData.keys Object <optional>
Source:

SASLXOAuth2

SASL X-OAuth2 authentication.

Source:

StanzaAttrs

Type:
  • Object.<string, (string|number)>
Properties:
Name Type Attributes Description
StanzaAttrs.xmlns string <optional>
Source:

Status

Connection status constants for use by the connection handler callback.

Type:
  • Object
Properties:
Name Type Description
Status.ERROR connstatus

An error has occurred

Status.CONNECTING connstatus

The connection is currently being made

Status.CONNFAIL connstatus

The connection attempt failed

Status.AUTHENTICATING connstatus

The connection is authenticating

Status.AUTHFAIL connstatus

The authentication attempt failed

Status.CONNECTED connstatus

The connection has succeeded

Status.DISCONNECTED connstatus

The connection has been terminated

Status.DISCONNECTING connstatus

The connection is currently being terminated

Status.ATTACHED connstatus

The connection has been attached

Status.REDIRECT connstatus

The connection has been redirected

Status.CONNTIMEOUT connstatus

The connection has timed out

Status.BINDREQUIRED connstatus

The JID resource needs to be bound for this session

Status.ATTACHFAIL connstatus

Failed to attach to a pre-existing session

Status.RECONNECTING connstatus

Not used by Strophe, but added for integrators

Source:

WebsocketLike

Type:
  • Object
Properties:
Name Type Description
WebsocketLike.close function
WebsocketLike.onopen function
WebsocketLike.readyState string
Source:

XHTMLAttrs

Type:
  • 'a' | 'blockquote' | 'br' | 'cite' | 'em' | 'img' | 'li' | 'ol' | 'p' | 'span' | 'strong' | 'ul' | 'body'
Source:

connectionCallback(connection)

Parameters:
Name Type Description
connection Connection
Source:

connectionCallback(connection)

Parameters:
Name Type Description
connection Connection
Source:

connectionCallback(connection)

Parameters:
Name Type Description
connection Connection
Source:

connstatus

Type:
  • number
Source: