Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created September 26, 2014 23:33
Show Gist options
  • Select an option

  • Save jwoertink/b174b285ac840b33e070 to your computer and use it in GitHub Desktop.

Select an option

Save jwoertink/b174b285ac840b33e070 to your computer and use it in GitHub Desktop.
An example of using XMPP to do messaging
var Client = require('node-xmpp-client'),
ltx = require('node-xmpp-core').ltx;
var client = new Client({jid: 'billy@pbx.dev', password: 'password'});
client.on('online', function(data) {
console.log('Connected as ' + data.jid.user + '@' + data.jid.domain + '/' + data.jid.resource)
var presence = new ltx.Element('presence', { type: 'available' }).c('show').t('chat');
client.send(presence);
});
client.on('stanza', function(stanza) {
console.log('RECEIVED STANZA', stanza);
});
client.on('offline', function () {
console.log('Client is offline');
});
client.on('connect', function () {
console.log('Client is connected');
});
// log in
client.connect();
var message = new ltx.Element(
'message',
{to: 'jeremy@pbx.dev', type: 'chat'}
).c('body').t('sup?');
// send message
client.send(message);
var roster = new ltx.Element(
'iq',
{id: 'roster_0',type: 'get'}
).c('query', { xmlns: 'jabber:iq:roster'});
// get roster
client.send(roster);
// log out
client.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment