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

evrythng-hub

v2.0.0

Published

Evrythng.js Hub plugin for transparent local Thng-Hub requests

Downloads

10

Readme

EVRYTHNG-HUB.JS (plugin for EVT.js)

evrythng-hub.js is an extension plugin to be used with evrythng.js or evrythng-extended.js JS libraries.

It adds the support for local requests within a THNGHUB environment. This means that, if the application makes a request to any of the endpoints supported by THNGHUB (see EVRYTHNG THNGHUB documentation), it will try locally by default and then the remote host, if the Hub is unavailable.

evrythng-hub.js is UMD compatible, meaning it just loads and works nicely in all contexts (Browser AMD, Node.js, Browser globals).

Installation

Browser

With Bower
bower install evrythng-hub --save

The Bower package is AMD-compatible. This means you can load it asynchronously using tools like Require.js or simply dropping the script tag into your HTML page:

<script src="bower_components/evrythng-hub/dist/evrythng-hub.js"></script>

See Usage below for more details.

Load from CDN

Add the script tag into your HTML page:

<script src="//cdn.evrythng.net/toolkit/evrythng-js-sdk/evrythng-hub-2.0.0.min.js"></script>

Or always get the last release:

<script src="//cdn.evrythng.net/toolkit/evrythng-js-sdk/evrythng-hub.js"></script>
<script src="//cdn.evrythng.net/toolkit/evrythng-js-sdk/evrythng-hub.min.js"></script>

For HTTPS you need to use:

<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-hub-2.0.0.min.js"></script>
<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-hub.js"></script>
<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-hub.min.js"></script>

Node.js

npm install evrythng-hub --save

Usage

RequireJS (AMD)

requirejs.config({
    paths: {
        'evrythng': '../bower_components/evrythng/dist/evrythng',
        'evrythng-hub': '../bower_components/evrythng-hub/dist/evrythng-hub'
    }
});
    
require(['evrythng', 'evrythng-hub'], function (EVT, Hub) {

  EVT.use(Hub);
  ...
  
});

Node.js

var EVT = require('evrythng'),
  hub = require('evrythng-hub');
  
EVT.use(hub);
...

Globals

// The plugin is attached as EVT.Hub
EVT.use(EVT.Hub);
...

Examples

General

After loading the plugin, using any of the methods above, and before starting to communicate with a THNGHUB, you need to setup the targetHub setting hub Thng that you want to talk to. Usually there will be a single THNGHUB in the environment, though. The plugin provides an easy way to fetch the list of the available hubs in the current project/context:

EVT.use(Hub);

// Setup global settings
Hub.setup({
  timeout: 1000,        // local request timeout before switching to remote host
  remote: false         // make local requests by default (only to THNGHUB endpoints)
});

// Authenticate a user (app.login()), or create any other scope (TrustedApp, Operator)
var user = new EVT.User('USER_API_KEY');

user.getAvailableHubs().then(function(hubs) {

  EVT.Hub.setup({
    targetHub: hubs[0]
  });

  // Fetch local things via hubs[0]
  user.thng().read().then(function(localThngs) {
    console.log(localThngs);
  });
  
  // Read remote thngs explicitly
  user.thng().read({ remote: true }).then(function(remoteThngs){
    console.log(remoteThngs);
  });

});

The targetHub property contains all the necessary configuration (IP address, Port numbers and Security settings) used by that particular hub, so the client does not need to know the HTTP, MQTT or WebSockets URLs or handle the encryption required by different hubs.

View all the supported endpoints on the hub here.

Usage with MQTT/WS plugins

Note: In order to connect to THNGHUB over MQTT/WebSockets you will need to add and install evrythng-mqtt.js or evrythng-ws.js together with evrythng-hub. Refer to these dependencies READMEs for installation and usage instructions.

When using the MQTT or WS plugin, the Hub plugin will first try to connect to the specified local hub URL (configured in the settings) and falls back to the remote cloud URL if it fails, making it transparent for the developer and application user if they are talking to the local Hub or the cloud API.

Install both plugins. Hub plugin should come after MQTT/WS.

EVT.use(mqtt).use(hub);

hub.setup({
  targetHub: <hub thng> // see above
});

As before, by setting the targetHub the SDK will know the correct MQTT/WS urls to establish the connections.

Make requests and subscriptions as if you were talking to the cloud.

user.thng('{thndId}').property('temperature').subscribe(function(tempUpdate){
  // Update coming from THNGHUB or directly from the cloud.
  console.log(tempUpdate);
});

Secure Mode

In order to talk to hubs that require encryption you need to have node-jose (node-jose-browserified for browsers) and jsrsasign installed. These dependencies are automatically loaded into node_modules or bower_components folder when you install the plugin via npm/bower.

The plugin will use the encryption defined in the THNGHUB startup settings.


Documentation

Check the THNGHUB REST API documentation on the EVRYTHNG THNGHUB documentation.

Source Maps

Source Maps are available, which means that when using the minified version, if you open Developer Tools (Chrome, Safari, Firefox), .map files will be downloaded to help you debug code using the original uncompressed version of the library.

Related tools

evrythng.js

evrythng.js is the core version of evrythng.js intended to be used in public applications and/or devices.

evrythng-extended.js

evrythng-extended.js is an extended version of evrythng.js which includes Operator access to the API.

License

Apache 2.0 License, check LICENSE.txt

Copyright (c) EVRYTHNG Ltd.