EVRYTHNG-HUB.JS (plugin for EVT.js)
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).
bower install evrythng-hub --save
See Usage below for more details.
Load from CDN
Add the script tag into your HTML page:
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>
npm install evrythng-hub --save
var EVT =hub = ;EVT;...
// The plugin is attached as EVT.HubEVT;...
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;// Setup global settingsHub;// Authenticate a user (app.login()), or create any other scope (TrustedApp, Operator)var user = 'USER_API_KEY';user;
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-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.
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.
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
bower_components folder when you install the plugin via
The plugin will use the encryption defined in the THNGHUB startup settings.
Check the THNGHUB REST API documentation on the EVRYTHNG THNGHUB documentation.
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.
evrythng.js is the core version of evrythng.js intended to be used in
public applications and/or devices.
evrythng-extended.js is an extended version of evrythng.js which
includes Operator access to the API.
Apache 2.0 License, check
Copyright (c) EVRYTHNG Ltd.