Created
September 26, 2014 23:33
-
-
Save jwoertink/b174b285ac840b33e070 to your computer and use it in GitHub Desktop.
An example of using XMPP to do messaging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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