Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 1002c4087fe29b51e038ebc05cef0dd321fa63c6 0 parents
@jaredhanson authored
6 .gitignore
@@ -0,0 +1,6 @@
+# Mac OS X
+.DS_Store
+
+# Node.js
+node_modules
+npm-debug.log
17 .npmignore
@@ -0,0 +1,17 @@
+# Mac OS X
+.DS_Store
+
+# Node.js
+.npmignore
+node_modules/
+npm-debug.log
+
+# Git
+.git*
+
+# Project
+README.md
+Makefile
+docs/
+examples/
+test/
20 LICENSE
@@ -0,0 +1,20 @@
+(The MIT License)
+
+Copyright (c) 2011 Jared Hanson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 Makefile
@@ -0,0 +1,19 @@
+NODE = node
+TEST = ./node_modules/.bin/vows
+TESTS ?= test/*-test.js
+
+test:
+ @NODE_ENV=test NODE_PATH=lib $(TEST) $(TEST_FLAGS) $(TESTS)
+
+docs: docs/api.html
+
+docs/api.html: lib/junction/*.js
+ dox \
+ --title junction-delay \
+ --desc "Delayed Delivery middleware for Junction" \
+ $(shell find lib/junction-delay/* -type f) > $@
+
+docclean:
+ rm -f docs/*.{1,html}
+
+.PHONY: test docs docclean
27 README.md
@@ -0,0 +1,27 @@
+# junction-delay
+
+[Delayed Delivery](http://xmpp.org/extensions/xep-0203.html) middleware built on [Junction](http://github.com/jaredhanson/junction)
+and [Node](http://nodejs.org).
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Jared Hanson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 lib/delayParser.js
@@ -0,0 +1,37 @@
+/**
+ * Module dependencies.
+ */
+var JID = require('junction').JID;
+
+
+/**
+ * Parse information indicating an XMPP stanza has been delivered with a delay.
+ *
+ * This middleware parses delay information contained within message and
+ * presence stanzas. `stanza.delayedBy` indicates the Jabber ID of the entity
+ * that delayed the delivery of the stana. `stanza.originallySentAt` indicates
+ * the time the stanza was originally sent.
+ *
+ * Examples:
+ *
+ * connection.use(junction.delayParser());
+ *
+ * References:
+ * - [XEP-0203: Delayed Delivery](http://xmpp.org/extensions/xep-0203.html)
+ *
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function delayParser() {
+
+ return function delayParser(stanza, next) {
+ if (!(stanza.is('message') || stanza.is('presence'))) { return next(); }
+ var delay = stanza.getChild('delay', 'urn:xmpp:delay');
+ if (!delay) { return next(); }
+
+ stanza.delayedBy = new JID(delay.attrs.from);
+ stanza.originallySentAt = new Date(delay.attrs.stamp);
+ next();
+ }
+}
10 lib/index.js
@@ -0,0 +1,10 @@
+/**
+ * Module dependencies.
+ */
+var delayParser = require('./delayParser');
+
+/**
+ * Expose middleware.
+ */
+exports = module.exports = delayParser;
+exports.delayParser = delayParser;
29 package.json
@@ -0,0 +1,29 @@
+{
+ "name": "junction-delay",
+ "version": "0.0.0",
+ "description": "Delayed Delivery middleware for Junction.",
+ "keywords": ["junction", "xmpp", "jabber", "delay", "xep0203", "middleware"],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jaredhanson/junction-delay.git"
+ },
+ "bugs": {
+ "url": "http://github.com/jaredhanson/junction-delay/issues"
+ },
+ "author": { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" },
+ "licenses": [ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/MIT"
+ } ],
+ "main": "./lib",
+ "dependencies": {
+ "junction": "0.2.x"
+ },
+ "devDependencies": {
+ "vows": "0.6.x"
+ },
+ "scripts": {
+ "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
+ },
+ "engines": { "node": ">= 0.4.0" }
+}
133 test/delayParser-test.js
@@ -0,0 +1,133 @@
+var vows = require('vows');
+var assert = require('assert');
+var util = require('util');
+var junction = require('junction');
+var IQ = require('junction').elements.IQ;
+var delayParser = require('delayParser');
+
+
+vows.describe('delayParser').addBatch({
+
+ 'middleware': {
+ topic: function() {
+ return delayParser();
+ },
+
+ 'when handling a message stanza with delay': {
+ topic: function(delayParser) {
+ var self = this;
+ var msg = new junction.XMLElement('message', { from: 'romeo@example.net/orchard' });
+ msg.c('delay', { xmlns: 'urn:xmpp:delay',
+ from: 'capulet.com',
+ stamp: '2002-09-10T23:08:25Z' });
+
+ function next(err) {
+ self.callback(err, msg);
+ }
+ process.nextTick(function () {
+ delayParser(msg, next)
+ });
+ },
+
+ 'should set delayedBy property' : function(err, stanza) {
+ assert.instanceOf(stanza.delayedBy, junction.JID);
+ assert.equal(stanza.delayedBy, 'capulet.com');
+ },
+ 'should set originallySentAt property' : function(err, stanza) {
+ assert.instanceOf(stanza.originallySentAt, Date);
+ assert.equal(stanza.originallySentAt.toUTCString(), 'Tue, 10 Sep 2002 23:08:25 GMT');
+ },
+ },
+
+ 'when handling a message stanza without delay': {
+ topic: function(delayParser) {
+ var self = this;
+ var msg = new junction.XMLElement('message', { from: 'romeo@example.net/orchard' });
+
+ function next(err) {
+ self.callback(err, msg);
+ }
+ process.nextTick(function () {
+ delayParser(msg, next)
+ });
+ },
+
+ 'should not set delayedBy property' : function(err, stanza) {
+ assert.isUndefined(stanza.delayedBy);
+ },
+ 'should not set originallySentAt property' : function(err, stanza) {
+ assert.isUndefined(stanza.originallySentAt);
+ },
+ },
+
+ 'when handling a presence stanza with delay': {
+ topic: function(delayParser) {
+ var self = this;
+ var pres = new junction.XMLElement('presence', { from: 'romeo@example.net/orchard' });
+ pres.c('delay', { xmlns: 'urn:xmpp:delay',
+ from: 'capulet.com',
+ stamp: '2002-09-10T23:08:25Z' });
+
+ function next(err) {
+ self.callback(err, pres);
+ }
+ process.nextTick(function () {
+ delayParser(pres, next)
+ });
+ },
+
+ 'should set delayedBy property' : function(err, stanza) {
+ assert.instanceOf(stanza.delayedBy, junction.JID);
+ assert.equal(stanza.delayedBy, 'capulet.com');
+ },
+ 'should set originallySentAt property' : function(err, stanza) {
+ assert.instanceOf(stanza.originallySentAt, Date);
+ assert.equal(stanza.originallySentAt.toUTCString(), 'Tue, 10 Sep 2002 23:08:25 GMT');
+ },
+ },
+
+ 'when handling a presence stanza without delay': {
+ topic: function(delayParser) {
+ var self = this;
+ var pres = new junction.XMLElement('presence', { from: 'romeo@example.net/orchard' });
+
+ function next(err) {
+ self.callback(err, pres);
+ }
+ process.nextTick(function () {
+ delayParser(pres, next)
+ });
+ },
+
+ 'should not set delayedBy property' : function(err, stanza) {
+ assert.isUndefined(stanza.delayedBy);
+ },
+ 'should not set originallySentAt property' : function(err, stanza) {
+ assert.isUndefined(stanza.originally, Date);
+ },
+ },
+
+ 'when handling a non-message, non-presence stanza': {
+ topic: function(delayParser) {
+ var self = this;
+ var iq = new IQ('romeo@example.net', 'juliet@example.com', 'get');
+ iq = iq.toXML();
+
+ function next(err) {
+ self.callback(err, iq);
+ }
+ process.nextTick(function () {
+ delayParser(iq, next)
+ });
+ },
+
+ 'should not set delayedBy property' : function(err, stanza) {
+ assert.isUndefined(stanza.delayedBy);
+ },
+ 'should not set originallySentAt property' : function(err, stanza) {
+ assert.isUndefined(stanza.originallySentAt);
+ },
+ },
+ },
+
+}).export(module);
15 test/index-test.js
@@ -0,0 +1,15 @@
+var vows = require('vows');
+var assert = require('assert');
+var delay = require('index');
+
+
+vows.describe('junction-delay').addBatch({
+
+ 'module': {
+ 'should export middleware': function () {
+ assert.isFunction(delay);
+ assert.isFunction(delay.delayParser);
+ },
+ },
+
+}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.