Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

stanza

legastero24.4kMIT12.21.0TypeScript support: included

Modern XMPP in the browser, with a JSON API

jingle, stanza, stanza.io, xmpp

readme

StanzaJS

Modern XMPP, with a JSON API.


npm chat

What is this?

StanzaJS is a JavaScript/TypeScript library for using modern XMPP, and it does that by exposing everything as JSON. Unless you insist, you have no need to ever see or touch any XML when using StanzaJS.

Installing

npm install stanza

Echo Client Demo

import * as XMPP from 'stanza';

const client = XMPP.createClient({
    jid: 'echobot@example.com',
    password: 'hunter2',

    // If you have a .well-known/host-meta.json file for your
    // domain, the connection transport config can be skipped.
    transports: {
        websocket: 'wss://example.com:5281/xmpp-websocket',
        bosh: 'https://example.com:5281/http-bind'
    }
});

client.on('session:started', () => {
    client.getRoster();
    client.sendPresence();
});

client.on('chat', msg => {
    client.sendMessage({
        to: msg.from,
        body: 'You sent: ' + msg.body
    });
});

client.connect();

Documentation

Discussion

MUC Room: discuss@stanzajs.org / Logs

These are some additional modules that are highly recommended for use with StanzaJS:

Name Description Source
staydown Render helper that keeps an element scrolled to the bottom based on user intent. Source
webrtc-adapter Shims browsers to provide a consistent WebRTC API. Source

License

MIT

Portions of StanzaJS are derived from prior works. See NOTICE file for details.

Created By

If you like this, follow @lancestout on Twitter.

changelog

Change Log

12.10.0

  • BOSH and WebSocket transports are now based on Duplex streams.
  • Stream management state caching may now by async.
  • Expanded the set of events related to stream management. See Using Stream Management. These events are:
    • stanza:hibernated
    • message:hibernated
    • message:acked
    • message:failed
    • message:retry

12.9.0

  • The default external service discovery namespace was changed to urn:xmpp:extdisco:2. Querying using the :1 namespace can be done with client.discoverICEServers({ version: '1' }).

12.0.0

WARNING: Unlike many previous major version bumps that were almost entirely backwards compatible, v12 is not backwards compatible. Upgrading to v12 will require modifications in existing code.

  • Complete TypeScript support
  • Changed JXT implementation (old JXT definitions will not work). See JXT docs for more information.
  • Changed structure/names of JXT definitions for supported XEPs. See Supported XEP Formats for links to the type definitions of each XEP supported by StanzaJS.
  • Removed support for callbacks. All methods now support Promises only.
  • Methods using IQ stanzas now return the requested data instead of the full IQ stanza data.
  • Changed SASL implementation. Old, custom SASL mechanisms will not work.
  • Removed JID objects. JIDs are now treated as strings only. See src/JID.ts for helper functions.
  • Implemented Stringprep (not PRECIS, yet).
  • Removed WildEmitter. Now using standard EventEmitter. Event handlers using * wildcards will need to be changed.
    • The * and raw:* events are still supported.
  • Added input/display helpers for Realtime Text.
  • Configuration of transports has changed. The wsURL/boshURL/transport fields are no longer used. Configuring transports is now done by setting the transports field to an object:

    XMPP.createClient({
        transports: {
            websocket: 'wss://...',
            bosh: 'https://...'
        }
    })

    Using false instead of a URL will disable that transport type. An object can be used to pass additional configuration, such as BOSH pre-binding rid/sid:

    XMPP.createClient({
        transports: {
            websocket: false,
            bosh: {
                url: 'https://...',
                rid: 1234,
                sid: '...'
            }
        }
    })

11.1.0

  • Jingle sessions now queue local actions to allow safer handling of WebRTC peer connection objects.

11.0.0

10.0.0 -> 10.1.0

  • Renamed muc:affiliation event to muc:other

10.0.0

  • Converted to ES modules, using Typescript compiler for downleveling.
  • Moved stanza definitions back from jxt-xmpp, obsoleting both jxt-xmpp and jxt-xmpp-types.
  • Replaced use of request and xhr with cross-fetch.
  • SASL mech implementations now live inside stanza.io.
  • Moved host-meta fetching logic into stanza.io.
  • Moved xmpp-jid implementation back into stanza.io, obsoleting xmpp-jid.
  • Use ws module instead of faye-websocket.
  • Dropped support of old, pre-RFC XMPP-over-WebSocket.
  • Moved jingle implementation back into stanza.io.

9.1.0 -> 9.2.0

  • Fixed CSI namespace to use urn:xmpp:csi:0
  • Added support for XEP-0333 Chat Markers

6.0.0 -> 6.0.1

5.x.x -> 6.0.0

    ```javascript
    var localMedia = require('localmedia');

    localMedia.start();

    //...

    var sess = client.jingle.createMediaSession(peerJID);
    sess.addStream(localMedia.localStream);
    sess.start();
    ```

* `client.jingle` was updated to a `jingle.js v1.0` instance.

    The method `client.jingle.startLocalMedia()` has been removed, in favor of using the [localmedia](https://github.com/otalk/localmedia) module instead (which is not bundled in `stanza.io`).