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 is a JavaScript library for speaking XMPP via BOSH (XEP-0124 / XEP-0206) and WebSockets (RFC 7395). Originally created by Jack Moffitt for Chesspark — an online chess platform built entirely on XMPP — the library has grown into a mature, community-maintained toolkit that powers real-time chat, presence, and messaging in both browser and Node.js environments. At its core, Strophe.js manages the full XMPP connection lifecycle: opening streams, negotiating SASL authentication, dispatching incoming stanzas to your handlers, and sending outgoing stanzas with minimal boilerplate.

Key Features

Dual Transports

Connect over BOSH (HTTP long-polling, XEP-0124) or WebSocket (RFC 7395). The transport is selected automatically from the service URL — http:// / https:// use BOSH; ws:// / wss:// use WebSocket. A SharedWorker WebSocket mode is also available to share one connection across multiple browser tabs.

Comprehensive SASL

Ships with nine built-in authentication mechanisms, selected by priority at login time: 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), and EXTERNAL (10). Custom mechanisms can be registered at connection time.

TypeScript & Plugin API

Full TypeScript types are generated at dist/types/index.d.ts and resolved automatically by module-aware bundlers. The plugin system (Strophe.addConnectionPlugin) lets you extend every Connection instance with your own namespaced methods and lifecycle hooks.

BOSH and WebSocket Transports

Strophe.js selects the transport automatically based on the URL you pass to new Strophe.Connection(service):
  • BOSH — any URL beginning with http:// or https:// (or a relative path) creates a Bosh transport that implements the HTTP Binding protocol defined in XEP-0124.
  • WebSocket — any URL beginning with ws:// or wss:// creates a Websocket transport. You can also force WebSocket for a relative URL by passing { protocol: 'wss' } in the options object.
  • WorkerWebsocket — passing a worker URL in the options creates a WorkerWebsocket transport, allowing multiple browser tabs to share a single WebSocket connection via a SharedWorker.

Browser and Node.js Support

Strophe.js runs in all modern browsers (the browserslist target is >1%, maintained node versions) and in Node.js. No extra packages are needed in the browser because WebSocket and DOM APIs are natively available. In Node.js, those APIs must be supplied by peer dependencies.
React Native requires a WebCrypto polyfill. Since version 1.6.0, Strophe.js uses the Web Crypto API for all cryptographic operations (SCRAM hashing, signature verification). This API is built into modern browsers and Node.js, but it is not available in React Native. If you use Strophe.js in a React Native project you must install and configure a third-party crypto.subtle polyfill before importing Strophe.

Version History Highlights

Strophe.js follows semantic versioning. The milestones below summarise the most impactful changes in recent major releases. v3.0 (May 2024) resolved a long-standing Node.js compatibility issue and removed circular dependencies between internal modules. Deep imports such as strophe.js/src/connection no longer work — everything is now imported from the top-level strophe.js package. v3.1 (December 2024) introduced a security fix for the stx tagged template literal (values are now XML-escaped by default), replaced the xmldom parser with jsdom, and added support for passing Stanza / Builder objects directly as values inside stx templates. v4.0 (June 2026) moved jsdom and ws from optionalDependencies to peerDependencies, removed the Strophe.shims compatibility shim, and fixed SCRAM client-first-message encoding for non-ASCII usernames (e.g. accented characters). The upcoming v4.1 completes the migration from JSDoc annotations to full TypeScript source.

Getting Started

Installation

Install via npm, yarn, or pnpm; import from a CDN; or load the UMD bundle. Covers Node.js peer dependency setup and all available package entry points.

Quickstart

A complete working example: connect to an XMPP server, send initial presence, add a message handler, reply to messages, and disconnect cleanly.

Build docs developers (and LLMs) love