-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5cd0fcd
Showing
12 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Mac OS X | ||
.DS_Store | ||
|
||
# Node.js | ||
node_modules | ||
npm-debug.log |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
NODE = node | ||
TEST = ./node_modules/.bin/vows | ||
TESTS ?= test/*-test.js 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-lastactivity \ | ||
--desc "Last Activity middleware for Junction" \ | ||
$(shell find lib/junction-lastactivity/* -type f) > $@ | ||
|
||
docclean: | ||
rm -f docs/*.{1,html} | ||
|
||
.PHONY: test docs docclean |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# junction-lastactivity | ||
|
||
[Last Activity](http://xmpp.org/extensions/xep-0012.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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var lastActivity = require('./middleware/lastActivity') | ||
, lastActivityResultParser = require('./middleware/lastActivityResultParser'); | ||
|
||
/** | ||
* Expose middleware. | ||
*/ | ||
exports = module.exports = lastActivity; | ||
exports.lastActivity = lastActivity; | ||
exports.lastActivityResultParser = lastActivityResultParser; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var StanzaError = require('junction').StanzaError; | ||
|
||
|
||
/** | ||
* Handle requests for the last activity associated with an XMPP entity. | ||
* | ||
* This middleware handles IQ-get requests within the _jabber:iq:last_ XML | ||
* namespace. By default, the middleware responds with the uptime of the | ||
* entity, measured in seconds. | ||
* | ||
* Examples: | ||
* | ||
* connection.use(junction.lastActivity()); | ||
* | ||
* connection.use( | ||
* junction.lastActivity(function() { | ||
* return 31556926; | ||
* }) | ||
* ); | ||
* | ||
* References: | ||
* - [XEP-0012: Last Activity](http://xmpp.org/extensions/xep-0012.html) | ||
* | ||
* @param {Function} callback | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
module.exports = function lastActivity(callback) { | ||
callback = callback || uptime; | ||
|
||
var start = Date.now(); | ||
function uptime() { | ||
return Math.round((Date.now() - start) / 1000); | ||
} | ||
|
||
return function lastActivity(req, res, next) { | ||
if (!req.is('iq')) { return next(); } | ||
if (req.type == 'result' || req.type == 'error') { return next(); } | ||
var query = req.getChild('query', 'jabber:iq:last'); | ||
if (!query) { return next(); } | ||
|
||
if (req.type != 'get') { | ||
return next(new StanzaError("last query must be sent in an IQ-get stanza", 'modify', 'bad-request')); | ||
} | ||
|
||
var q = res.c('query', { xmlns: 'jabber:iq:last', seconds: callback() }); | ||
res.send(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Parse information about the last activity associated with an XMPP entity. | ||
* | ||
* This middleware parses last activity information contained within IQ-result | ||
* stanzas. `stanza.lastActivity` indicates the time of last activity of the | ||
* entity, in seconds. `stanza.lastStatus` indicates last status of the entity. | ||
* | ||
* Examples: | ||
* | ||
* connection.use(junction.lastActivityResultParser()); | ||
* | ||
* References: | ||
* - [XEP-0012: Last Activity](http://xmpp.org/extensions/xep-0012.html) | ||
* | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
module.exports = function lastActivityResultParser() { | ||
|
||
return function lastActivityResultParser(stanza, next) { | ||
if (!stanza.is('iq')) { return next(); } | ||
if (stanza.type != 'result') { return next(); } | ||
var query = stanza.getChild('query', 'jabber:iq:last'); | ||
if (!query) { return next(); } | ||
|
||
stanza.lastActivity = query.attrs.seconds; | ||
stanza.lastStatus = query.getText(); | ||
next(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "junction-lastactivity", | ||
"version": "0.0.0", | ||
"description": "Last Activity middleware for Junction.", | ||
"keywords": ["junction", "xmpp", "jabber", "last", "lastactivity", "xep0012", "middleware"], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jaredhanson/junction-lastactivity.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/jaredhanson/junction-lastactivity/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 test/**/*-test.js" | ||
}, | ||
"engines": { "node": ">= 0.4.0" } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var vows = require('vows'); | ||
var assert = require('assert'); | ||
var lastactivity = require('index'); | ||
|
||
|
||
vows.describe('junction-lastactivity').addBatch({ | ||
|
||
'module': { | ||
'should export middleware': function () { | ||
assert.isFunction(lastactivity); | ||
assert.isFunction(lastactivity.lastActivity); | ||
assert.isFunction(lastactivity.lastActivityResultParser); | ||
}, | ||
}, | ||
|
||
}).export(module); |
Oops, something went wrong.