Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add examples.

  • Loading branch information...
commit 012f67958938f8abcde29750a17fb26406e3e188 1 parent b2759f9
@jaredhanson authored
Showing with 88 additions and 0 deletions.
  1. +79 −0 examples/info-query/app.js
  2. +9 −0 examples/info-query/package.json
View
79 examples/info-query/app.js
@@ -0,0 +1,79 @@
+var junction = require('junction');
+var disco = require('junction-disco');
+var argv = require('optimist').argv;
+
+console.log('Junction/Disco: Info#Query Example');
+console.log(' (using Junction/Disco + ' + disco.version + ')');
+
+var options = {
+ type: 'client',
+ jid: argv.I,
+ password: argv.P
+};
+
+var connection = disco.createConnection(options);
+connection.on('online', function() {
+ console.log('Connected as: ' + connection.jid);
+ connection.send(new junction.elements.Presence());
+});
+
+
+var store = new junction.pending.MemoryStore();
+//connection.use(junction.logger());
+connection.use(junction.pending({ store: store }));
+
+connection.use(junction.presence(function(handler) {
+ handler.on('available', function(stanza) {
+ console.log('Discovering info about ' + stanza.from + ' ...');
+
+ var iq = new junction.elements.IQ(stanza.from);
+ iq.id = connection.generateID();
+ iq.c(new disco.elements.InfoQuery());
+ connection.send(iq);
+ });
+}));
+
+connection.info(null, function(req, res, next) {
+ var identities = [ { category: 'client', type: 'bot', name: 'Junction/Disco Example' } ];
+ var features = [ 'http://jabber.org/protocol/disco#info' ];
+
+ var disco = res.c('query', { xmlns: 'http://jabber.org/protocol/disco#info' });
+ identities.forEach(function(identity) {
+ disco.c('identity', { category: identity.category,
+ type: identity.type,
+ name: identity.name });
+ });
+ features.forEach(function(feature) {
+ disco.c('feature', { var: feature });
+ });
+ res.send();
+})
+
+connection.use(disco.middleware.infoQueryResultParser());
+connection.use(function(stanza, next) {
+ if (!(stanza.irt && stanza.irt.xmlns === 'http://jabber.org/protocol/disco#info' && stanza.irt.query === 'info')) {
+ return next();
+ }
+
+ if (stanza.type == 'error') {
+ console.log('Failed to discovered info about ' + stanza.from);
+ return;
+ }
+
+ console.log('Discovered info about ' + stanza.from);
+ console.log(' identities:');
+ stanza.identities.forEach(function(identity) {
+ console.log(' category: ' + identity.category + ', type: ' + identity.type + ', name: ' + identity.name);
+ });
+ console.log(' features:');
+ stanza.features.forEach(function(feature) {
+ console.log(' ' + feature);
+ });
+});
+
+connection.use(junction.serviceUnavailable());
+connection.use(junction.errorHandler());
+
+
+connection.filter(disco.filters.infoQuery());
+connection.filter(junction.filters.pending({ store: store }));
View
9 examples/info-query/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "junction-disco-examples-info-query",
+ "version": "0.0.0",
+ "dependencies": {
+ "junction-disco": ">= 0.0.0",
+ "junction": ">= 0.0.0",
+ "optimist": ">= 0.0.0"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.