node-simple-xmpp
Simple High Level NodeJS XMPP Library
Install
$ npm install simple-xmpp
Example
var xmpp = require('simple-xmpp');
xmpp.on('online', function(data) {
console.log('Connected with JID: ' + data.jid.user);
console.log('Yes, I\'m connected!');
});
xmpp.on('chat', function(from, message) {
xmpp.send(from, 'echo: ' + message);
});
xmpp.on('error', function(err) {
console.error(err);
});
xmpp.on('subscribe', function(from) {
if (from === 'a.friend@gmail.com') {
xmpp.acceptSubscription(from);
}
});
xmpp.connect({
jid: username@gmail.com,
password: password,
host: 'talk.google.com',
port: 5222
});
xmpp.subscribe('your.friend@gmail.com');
xmpp.getRoster();
Documentation
Events
Online
Event emitted when successfully connected. Callback is passed an object containing information about the newly connected user.
xmpp.on('online', function(data) {
console.log('Yes, I\'m online');
});
Close
event where the connection has been closed
xmpp.on('close', function() {
console.log('connection has been closed!');
});
Chat
Event emitted when somebody sends a chat message to you (either a direct message or a private message from a MUC)
xmpp.on('chat', function(from, message) {
console.log('%s says %s', from, message);
});
Chat State
event emitted when a buddys chatstate changes [ 'active', 'composing', 'paused', 'inactive', 'gone' ]
xmpp.on('chatstate', function(from, state) {
console.log('% is currently %s', from, state);
});
Group Chat
event where emits when somebody sends a group chat message to you
xmpp.on('groupchat', function(conference, from, message, stamp) {
console.log('%s says %s on %s on %s at %s',
from, message, conference, stamp.substr(0,9), stamp.substr(10));
});
Buddy
Event emitted when state of the buddy on your chat list changes
xmpp.on('buddy', function(jid, state, statusText, resource) {
console.log('%s is in %s state - %s -%s', jid, state, statusText, resource);
});
Group Buddy
Event emitted when state of the buddy on group chat you recently joined changes
xmpp.on('groupbuddy', function(conference, from, state, statusText) {
console.log('%s: %s is in %s state - %s',conference, from, state, statusText);
});
Buddy capabilities
Event emitted when a buddy's client capabilities are retrieved. Capabilities specify which additional
features supported by the buddy's XMPP client (such as audio and video chat). See
XEP-0115: Entity Capabilities for more information.
xmpp.on('buddyCapabilities', function(jid, data) {
console.log(data.features);
});
Stanza
access core stanza element when such received
Fires for every incoming stanza
Methods
Send Chat Messages
xmpp.send(to, message, group);
Send Friend requests
xmpp.subscribe(to);
Accept Friend requests
xmpp.acceptSubscription(from);
Unsubscribe Friend
xmpp.unsubscribe(to);
Accept unsubscription requests
xmpp.acceptUnsubscription(from);
Set presence
xmpp.setPresence('away', 'Out to lunch');
Set chatstate
xmpp.setChatstate('user@host.com', 'composing');
Get vCard
xmpp.getVCard('user@host.com', function (vcard) {
console.log('user@host.com vcard: ', vcard);
});
Probe the state of the buddy
xmpp.probe(jid, function(state) {
});
Disconnect session
xmpp.disconnect();
Fields
Fields provided Additional Core functionalies
xmpp.conn
The underlying connection object
var xmpp = simpleXMPP.connect({});
xmpp.conn;
xmpp.Element
XMPP Element class (from node-xmpp)
var xmpp = simpleXMPP.connect({});
xmpp.Element;
Guides