Strophe.js provides a lightweight plugin system that lets you attach reusable objects to everyDocumentation 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.
Connection instance. A plugin can register stanza handlers, listen to connection lifecycle events, and expose helper methods — all under a namespace of your choosing. Once registered, a plugin is automatically instantiated for every new connection, including those created before the plugin was loaded.
How Plugins Work
When you callStrophe.addConnectionPlugin(name, ptype), Strophe.js stores the prototype object in an internal connectionPlugins registry. The Connection constructor iterates over that registry and, for each plugin, creates a new object that inherits from the registered prototype and calls its init(connection) method. The resulting instance is attached to the connection as connection[name].
statusChanged(status, condition) method. This happens in _changeConnectStatus() before the user’s own callback is invoked.
Plugin Shape
A plugin prototype needs at most two methods:| Method | Signature | When it is called |
|---|---|---|
init | (conn: Connection) => void | Once, immediately after the Connection is created |
statusChanged | (status: number, condition?: string | null) => void | Every time the connection status changes |
Registering a Plugin
addConnectionPlugin must be called before creating any Connection that should have the plugin. Plugins registered after a connection is constructed are not retroactively initialised on that connection.Using a Plugin After Connecting
AfteraddConnectionPlugin has been called, every new Connection instance exposes the plugin under the registered name:
Connection type to get full type safety:
A Complete Plugin Example
The following plugin sends a directed presence to a conference room every time the connection status becomesCONNECTED, and cleans up when it becomes DISCONNECTED.
Plugin Initialisation Order
Plugins are initialised in the order in which their keys appear in theconnectionPlugins object, which follows JavaScript’s property insertion order. If plugin B depends on plugin A being fully initialised, register plugin A first:
init(), you can access other plugins on the same connection through the conn argument:
Community Plugins
The Strophe.js organisation maintains a collection of ready-made XMPP extension plugins at: https://github.com/strophe/strophejs-plugins Available plugins include implementations of common XEPs such as MUC (XEP-0045), PubSub (XEP-0060), vCards (XEP-0054), and many more. Each plugin follows the sameinit / statusChanged pattern described on this page.