An XMPP client is an entity that connects to an XMPP server.
@xmpp/client package includes a minimal set of features to connect and authenticate securely and reliably.
It supports Node.js, browser and React Native. See below for differences.
npm install @xmpp/client or
yarn add @xmpp/client
const client xml jid =
VERSION with the desired version number.
const client xml jid = windowXMPP
const client xml =const xmpp =xmppxmppxmppxmpp// Debugxmppxmppxmppxmppstart
See xml package
See jid package
<string>The service to connect to, accepts an URI or a domain.
<string>Optional domain of the service, if omitted will use the hostname from
service. Useful when the service domain is different than the service hostname.
<string> Optional resource for resource binding
<string>Optional username for sasl
<string>Optional password for sasl
Returns an xmpp object.
xmpp is an instance of EventEmitter.
online indicates that
xmpp is authenticated and addressable. It is emitted every time there is a successfull (re)connection.
offline indicates that
xmpp disconnected and no automatic attempt to reconnect will happen (after calling
connecting: Socket is connecting
connect: Socket is connected
opening: Stream is opening
open: Stream is open
closing: Stream is closing
close: Stream is closed
disconnecting: Socket is disconnecting
disconnect: Socket is disconnected
You can read the current status using the
const isOnline = xmppstatus === 'online'
You can listen for status change using the
Emitted when the status changes.
Emitted when an error occurs. For connection errors,
xmpp will reconnect on its own using @xmpp/reconnect however a listener MUST be attached to avoid uncaught exceptions.
Emitted when a stanza is received and parsed.
// Simple echo bot examplexmpp
Emitted when connected, authenticated and ready to receive/send stanzas.
Emitted when the connection is closed an no further attempt to reconnect will happen, after calling xmpp.stop().
Starts the connection. Attempts to reconnect will automatically happen if it cannot connect or gets disconnected.
Returns a promise that resolves if the first attempt succeed or rejects if the first attempt fails.
Stops the connection and prevent any further auto reconnect/retry.
Returns a promise that resolves once the stream closes and the socket disconnects.
Sends a stanza.
Returns a promise that resolves once the stanza is serialized and written to the socket or rejects if any of those fails.
XMPP supports multiple transports, this table list
@xmpp/client supported and unsupported transport for each environment.
Multiple authentication mechanisms are supported.
PLAIN should only be used over secure WebSocket (
wss://), direct TLS (
xmpps:) or a TCP (
xmpp:) connection upgraded to TLS via STARTTLS
- ☐ : Optional
- ✗ : Unavailable
- ✔ : Included
Unable to resolve module
If you are using an older React Native version, please require/import
@xmpp/client/reat-native instead of