Modern XMPP in the browser, with a JSON API
Modern XMPP in the browser, with a JSON API.
Stanza.io is a library for using modern XMPP in the browser, 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 stanza.io.
v4.0.0, stanza.io is using the protocol specified in RFC 7395 by default, which contains backwards incompatible changes.
Servers have started switching to using the RFC version of the WebSocket binding; notably, Prosody's WebSocket module for
prosody-0.10. If your server has not yet been upgraded, you can set
['old-websocket'] in the config:
var oldws = XMPPcreateClienttransports: 'old-websocket';
$ npm install stanza.io
The bundled and minified files will be in the generated
- Find or install a server which supports XMPP over WebSocket (Prosody recommended).
npm installin the
demo.htmlin your browser.
- Enter your connection info, click connect.
- Use the JS console to play with the XMPP client (
var XMPP = require'stanza.io'; // if using browserifyvar client = XMPPcreateClientjid: 'email@example.com'password: 'hunter2'// If you have a .well-known/host-meta.json file for your// domain, the connection transport config can be skipped.transport: 'websocket'wsURL: 'wss://example.com:5281/xmpp-websocket'// (or `boshURL` if using 'bosh' as the transport);clienton'session:started'clientgetRoster;clientsendPresence;;clienton'chat'clientsendMessageto: msgfrombody: 'You sent: ' + msgbody;;clientconnect;
If you like this, follow @lancestout on twitter.