adhesion-server

0.0.2 • Public • Published

Adhesion Server

Note: The previous version of Adhesion is still available on this addess but will not longer be actively maintained. Use this version instead.

Adhesion is a simple module to provide a bridge between your MQTT broker and a WebSockets. This way you can use MQTT in your browser apps without having to expose your broker to the world. A powerful but simple feature is the ability to allow or deny a subscribe or publish request based on your own logic.

For a version you can use right away, try adhesion-proxy.

Install

npm install adhesion-server --save

Usage example

 
var Adhesion = require('./Server');
 
/*
 Options to feed the server
*/
var options = {
    'mqtt': {
        'url': 'mqtt://localhost'
    },
    'ws': {
        'port': 7897
    }
};
 
var server = Adhesion.createServer(options);
// Optionally: var server = Adhesion.createServer(options, connectionListener);
 
/*
 A new WS client connected
*/
server.on('connection', function(client) {
 
    /*
     The client requested a subscription to a topic
    */
    client.on('subscribe', function(topic, allow) {
 
        // You can do any checks you want here.
        // Just call allow() with true or false when you're done
        return allow(true);
 
        // In >0.0.2 you can also do this:
        return allow(false, 'You don\'t have sufficient access!');
 
    });
 
    /*
     The client requested a publication on a topic
    */
    client.on('publish', function(topic, message, flags, allow) {
 
        // You can do any checks you want here.
        // Just call allow() with true or false when you're done
        return allow(true);
 
    });
 
});
 

That's all there is to it!

Version history

  • 0.0.2 - 21 July 2015
    • Added optional reason to allow callback
  • 0.0.1 - 20 July 2015
    • First commit

License

Copyright 2015 Michiel van der Velde.

This software is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i adhesion-server

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • michielvdvelde