forked from moscajs/aedes
-
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 5d5e57b
Showing
4 changed files
with
140 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,28 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript |
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,39 @@ | ||
|
||
var mqemitter = require('mqemitter') | ||
, mqtt = require('mqtt-connection') | ||
, parseStream = mqtt.parseStream | ||
, generateStream = mqtt.generateStream | ||
, through = require('through2') | ||
, EE = require('events').EventEmitter | ||
|
||
module.exports = aedes | ||
|
||
function aedes() { | ||
|
||
var broker = mqemitter() | ||
, ee = new EE() | ||
|
||
ee.broker = broker | ||
ee.handle = handle | ||
|
||
return ee | ||
|
||
function handle(conn) { | ||
var inStream = conn.pipe(parseStream()) | ||
, outStream = generateStream() | ||
, client = through.obj(process) | ||
|
||
client.out = outStream | ||
|
||
outStream.pipe(conn) | ||
|
||
inStream.pipe(client) | ||
} | ||
|
||
function process(packet, enc, done) { | ||
this.out.write({ | ||
cmd: 'connack' | ||
, returnCode: 0 | ||
}, done) | ||
} | ||
} |
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,35 @@ | ||
{ | ||
"name": "aedes", | ||
"version": "0.0.1", | ||
"description": "Stream-based MQTT broker", | ||
"main": "aedes.js", | ||
"scripts": { | ||
"test": "tape test.js | faucet" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:mcollina/aedes.git" | ||
}, | ||
"keywords": [ | ||
"mqtt", | ||
"broker", | ||
"stream", | ||
"internet", | ||
"of", | ||
"things" | ||
], | ||
"author": "Matteo Collina <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"faucet": "0.0.1", | ||
"tape": "^3.0.3", | ||
"through2": "^0.6.3", | ||
"reduplexer": "^1.1.0" | ||
}, | ||
"dependencies": { | ||
"mqemitter": "^0.2.1", | ||
"mqstreams": "^0.1.0", | ||
"mqtt": "^1.0.0-pre.6", | ||
"mqtt-connection": "^2.1.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,38 @@ | ||
|
||
var test = require('tape').test | ||
, mqtt = require('mqtt-connection') | ||
, parseStream = mqtt.parseStream | ||
, generateStream = mqtt.generateStream | ||
, through = require('through2') | ||
, reduplexer = require('reduplexer') | ||
, aedes = require('./') | ||
|
||
test('connect and connack (minimal)', function(t) { | ||
var broker = aedes() | ||
, inStream = generateStream() | ||
, outStream = parseStream() | ||
, conn = reduplexer(outStream, inStream) | ||
|
||
inStream.write({ | ||
cmd: 'connect' | ||
, protocolId: 'MQTT' | ||
, protocolVersion: 4 | ||
, clean: true | ||
, clientId: 'my-client' | ||
, keepalive: 0 | ||
}) | ||
|
||
outStream.on('data', function(packet) { | ||
t.deepEqual(packet, { | ||
cmd: 'connack' | ||
, returnCode: 0 | ||
, length: 2 | ||
, qos: 0 | ||
, retain: false | ||
, dup: false | ||
}, 'successful connack') | ||
t.end() | ||
}) | ||
|
||
broker.handle(conn) | ||
}) |