Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add hello example.

  • Loading branch information...
commit 8ca78fbd1a157ea9bea903c1c9c6c7c9a56fcba6 1 parent c2812fd
@jaredhanson authored
View
37 examples/hello/app.js
@@ -0,0 +1,37 @@
+var junction = require('junction')
+ , Message = junction.elements.Message
+ , argv = require('optimist').argv;
+
+var options = {
+ type: 'client',
+ jid: argv.i,
+ password: argv.P
+};
+
+var app = junction.create();
+
+app.use(junction.presence(function(handler) {
+ handler.on('available', function(stanza) {
+ console.log(stanza.from + ' is available');
+ });
+ handler.on('unavailable', function(stanza) {
+ console.log(stanza.from + ' is unavailable');
+ });
+}));
+
+app.use(junction.messageParser());
+app.use(junction.message(function(handler) {
+ handler.on('chat', function(stanza) {
+ var msg = new Message(stanza.from);
+ msg.c('body', {}).t('Hello ' + stanza.from + '!\n\n' + 'You said: ' + stanza.body);
+ stanza.connection.send(msg);
+ });
+}));
+
+app.use(junction.serviceUnavailable());
+app.use(junction.errorHandler());
+
+app.connect(options).on('online', function() {
+ console.log('Connected as: ' + this.jid);
+ this.send(new junction.elements.Presence());
+});
View
8 examples/hello/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "junction-examples-hello",
+ "version": "0.0.0",
+ "dependencies": {
+ "junction": ">= 0.0.0",
+ "optimist": ">= 0.0.0"
+ }
+}
View
2  examples/presence/app.js
@@ -6,7 +6,7 @@ console.log(' (using Junction + ' + junction.version + ')');
var options = {
type: 'client',
- jid: argv.I,
+ jid: argv.i,
password: argv.P
};
Please sign in to comment.
Something went wrong with that request. Please try again.