npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adhesion

v0.2.3

Published

Use MQTT directly in your web pages using WebSockets

Downloads

7

Readme

Adhesion - MQTT over WebSockets

Adhesion is a light-weight solution that allows you to directly use the familiar MQTT pub/sub commands in the browser. It saves you from having to write custom code, and you do not need to expose your MQTT broker to the world.

More Information

Installing

npm install adhesion

Using Adhesion

Stand-alone

When using Adhesion as a stand-alone app, supply your MQTT and WebSocket settings in proxy_settings.json.

{
    "mqtt_host": "localhost",
    "mqtt_port": 1883,
    "websocket_port": 8090
}

| Option | Type | Default | Description | | -----------------------|--------|-----------| ----------------------------------------------------------------| | mqtt_host | String | localhost | MQTT broker host. | | mqtt_port | Int | 1883 | MQTT broker port. | | websocket_port | Int | 8090 | Port to open WebSocket on. | | topics_allow | Array | - | Which topics the client is allowed to access (optional). | | topics_deny | Array | - | Which topics the client is denied access (optional). | | deny_publish | Bool | false | Deny client publish rights for all topics (optional). | | topics_allow_subscribe | Array | - | Which topics the client is allowed subscribe rights (optional). | | topics_deny_subscribe | Array | - | Which topics the client is denied subscribe rights (optional). | | topics_allow_publish | Array | - | Which topics the client is allowed publish rights (optional). | | topics_deny_publish | Array | - | Which topics the client is denied publish rights (optional). |

You can start the proxy by issuing node proxy.js. Of course you can use a system like Forever to keep it on line.

In your own app

To use the Adhesion proxy in your own node.js application, you can use the methods exposed to you by Adhesion. A small example is as follows:

var Adhesion = require('adhesion');

var server = new Adhesion.Server({
    'mqtt_host': 'localhost',       // defaults to localhost
    'mqtt_port': 1883,              // defaults to port 1883
    'websocket_port': 9234
});
server.on('connection', function(client) {
    console.log('Connection received...');
    client.on('error', function(err) {
        console.log('An error occured');
        console.log(err);
    });
    client.on('publish', function(topic, message, flags, allow) {
        console.log('Publish request on %s: %s', topic, message);
        return allow(true);  // Allow the request (true) or not (false)
    });
    client.on('subscribe', function(topic, allow) {
        console.log('Subscribe request on %s', topic);
        return allow(true);  // Allow the request (true) or not (false)
    });
});
server.on('error', function(err) {
    console.log('An error occured');
    console.log(err);
});
server.start(function() {
    console.log('Adhesion running');
});

Client Example

Within the Adhesion package, you will find a file called client.js. This is the Adhesion client. The following code snippet shows how to connect to the proxy, subscribe to a topic and publish on a topic.

var client = Adhesion.getClient('ws://localhost:8090');
client.on('error', function(error) {
    console.log('Got an error: %s!', error);
});
client.on('open', function() {
    console.log('Connection established!');
    client.subscribe('/var/www/#');
    client.publish('/var/www/ret', 'This works!', { retain: true }); // retain is optional
    client.on('message', function(topic, message) {
        console.log('%s %s', topic, message);
        client.close(); // close the WebSocket
    });
});
client.connect();

Reconnecting

Adhesion has support for auto-reconnect when the WebSocket is closed by an error. To enable reconnecting, give reconnect to the getClient function:

// ...
var client = Adhesion.getClient('ws://localhost:8090', { 'reconnect': true, 'reconnect_tries': 3 });

reconnect_tries is optional, and defaults to 3. If all three attempts fail, the client will emit the max_reconnected event.

// ...
client.on('max_reconnected', function() {
	alert('Failed to reconnect to WebSocket!');
});

Changelog

Version 0.2.2/0.2.3 - 27h July 2014

0.2.3

  • Once again improvements to belowmentioned restriction vars
  • Reconnection support

0.2.2

  • Added 'not_allowed' and 'server_error' events to client
  • Fixed 'topics_allow', 'topics_deny' and 'deny_publish' in proxy

Version 0.2.1 - 26h July 2014

  • Improved 'topics_allow' and 'topics_deny' options in proxy
  • Added 'deny_publish' option in proxy

Version 0.2.0 - 25th July 2014

  • Rework of version 0.0.1, initial commit

Planned

  • Support for wildcards on proxy subscribe/publish allow/deny config
  • Better error handling

Licence

(The MIT License)

Copyright (C) 2014 Michiel van der Velde

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.