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 battle-tested JavaScript library that lets you build real-time XMPP applications. It supports both BOSH (HTTP-based long-polling) and WebSocket transports, runs in browsers and Node.js, and ships with full TypeScript type definitions. Whether you’re building a chat client, a presence system, or any other XMPP-powered application, Strophe.js handles the protocol details so you can focus on your application logic.

Installation

Install Strophe.js via npm, CDN, or as an ES module in any environment

Quickstart

Connect to an XMPP server and send your first stanza in minutes

Core Concepts

Understand connections, stanzas, handlers, and authentication

API Reference

Full reference for every class, method, and constant in Strophe.js

Why Strophe.js?

Strophe.js has powered XMPP applications in production for over a decade. It provides a clean, callback-driven API that maps closely to the XMPP protocol while abstracting away the complexity of transport management, SASL authentication, and stanza handling.

Dual Transport

Connect over BOSH (XEP-0124) or WebSocket (RFC 7395) with the same API

SASL Auth

Supports SCRAM-SHA-512/384/256/1, PLAIN, ANONYMOUS, EXTERNAL, OAuth Bearer

Stanza Builder

Fluent $msg(), $iq(), $pres() helpers and the stx template literal

Event Handlers

Filter and respond to incoming stanzas by namespace, element name, or JID

TypeScript

Written in TypeScript with bundled type declarations for full IDE support

Plugin System

Extend the Connection class with custom plugins via addConnectionPlugin

Get Started

1

Install the library

npm install strophe.js
For Node.js, also install the peer dependencies: npm install jsdom ws
2

Create a connection

import { Strophe, $pres } from 'strophe.js';

const connection = new Strophe.Connection('wss://xmpp.example.com/websocket');
3

Connect and handle status

connection.connect('user@example.com', 'password', (status) => {
  if (status === Strophe.Status.CONNECTED) {
    console.log('Connected!');
    connection.send($pres().tree());
  }
});
4

Add stanza handlers

connection.addHandler((msg) => {
  const body = msg.getElementsByTagName('body')[0];
  if (body) console.log('Message:', Strophe.getText(body));
  return true; // keep handler alive
}, null, 'message', 'chat');
Running in Node.js requires installing jsdom and ws as peer dependencies. See the Installation guide for details.

Build docs developers (and LLMs) love