npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-xmpp

v2.3.1

Published

Simple High Level NodeJS XMPP Library

Downloads

9,986

Readme

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 === '[email protected]') {
		xmpp.acceptSubscription(from);
	}
});

xmpp.connect({
	jid: [email protected],
	password: password,
	host: 'talk.google.com',
	port: 5222
});

xmpp.subscribe('[email protected]');
// check for incoming subscription requests
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

/**
	@param jid - is the id of buddy (eg:- [email protected])
	@param state - state of the buddy. value will be one of the following constant can be access 
                   via require('simple-xmpp').STATUS
		AWAY - Buddy goes away
		DND - Buddy set its status as "Do Not Disturb" or "Busy",
		ONLINE - Buddy comes online or available to chat
		OFFLINE - Buddy goes offline
	@param statusText - status message of the buddy (known as "custom message" in Gmail).
                        `null` if the buddy has not specified any status text.

	@param resource - is the last parameter of JID, which tells that the user is logged in via with device. 
                      (e.g mobile , Desktop )
*/
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) {
	// data contains clientName and features
	console.log(data.features);
});

Stanza

access core stanza element when such received Fires for every incoming stanza

/**
	@param stanza - the core object
	xmpp.on('stanza', function(stanza) {
		console.log(stanza);
	});
*/

Methods

Send Chat Messages

/**
	@param to - Address to send (eg:- [email protected] - [email protected])
	@param message - message to be sent
	@param group - if true, send the message in a group chat
*/

xmpp.send(to, message, group);

Send Friend requests

/**
	@param to - Address to send (eg:- [email protected])
*/
xmpp.subscribe(to);

Accept Friend requests

/**
	@param from - Address to accept (eg:- [email protected])
*/
xmpp.acceptSubscription(from);

Unsubscribe Friend

/**
	@param to - Address to unsubscribe (eg:- [email protected])
*/
xmpp.unsubscribe(to);

Accept unsubscription requests

/**
	@param from - Address to accept (eg:- [email protected])
*/
xmpp.acceptUnsubscription(from);

Set presence

/**
	@param show - Your current presence state ['away', 'dnd', 'xa', 'chat']
	@param status - (optional) free text as your status message
*/
xmpp.setPresence('away', 'Out to lunch');

Set chatstate

/**
	@param to - The target JID (ie. person you are chatting with) to receive the chatstate
	@param state - Your current chatstate [ 'active', 'composing', 'paused', 'inactive', 'gone' ]
*/
xmpp.setChatstate('[email protected]', 'composing');

Get vCard

/*
	@param buddy - The JID to use
	@param callback - The function to call when the vCard is retreived. The returned data will be a JSON object
*/
xmpp.getVCard('[email protected]', function (vcard) {
	console.log('[email protected] vcard: ', vcard);
});

Probe the state of the buddy

/**
	@param jid - Buddy's id (eg:- [email protected])
	@param state -	State of the buddy.	 value will be one of the following constant can be access 
                    via require('simple-xmpp').STATUS
		AWAY - Buddy goes away
		DND - Buddy set its status as "Do Not Disturb" or	 "Busy",
		ONLINE - Buddy comes online or available to chat
		OFFLINE - Buddy goes offline
*/

xmpp.probe(jid, function(state) {

});

Disconnect session

/**
	no params
*/

xmpp.disconnect();

Fields

Fields provided Additional Core functionalies

xmpp.conn

The underlying connection object

var xmpp = simpleXMPP.connect({});
xmpp.conn; // the connection object

xmpp.Element

XMPP Element class (from node-xmpp)

var xmpp = simpleXMPP.connect({});
xmpp.Element; // the connection object

Guides