adhesion-server
Use MQTT directly in your web pages using WebSockets
Last updated 5 years ago by michielvdvelde .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install adhesion-server 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.0.2                                ...           latest (5 years ago)

2 Versions

  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |