Overview

The Netrunr JavaScript SDK provides a programmatic interface to the Netrunr Gateway API (GAPI) from JavaScript. GAPI implements a messaging layer to communicate with Netrunr gateways and its operating environment.

The SDK may be used from nearly any JavaScript environment, including web browsers, Node.js, and mobile apps using HTML-Native bridges such as Cordova or Ionic.

Network Transports:

The SDK can target either HTTP or MQTT protocols(*), although MQTT (the default) is the preferred mode of operation.

Eclipse Paho JavaScript Client is used to provide MQTT for web browsers. It uses WebSockets to communicate with an MQTT server that supports WebSockets.

MQTT is used for Node.js programs.

*: when "HTTP" is used, it means "HTTPS" and when "MQTT" is used, it means "MQTT-S" throughout this document.

Installation

Node.js applications

The Netrunr JavaScript SDK for Node.js can be installed directly with npm by running:

npm install netrunr-gapi

To use the SDK, add the following to Node.js programs:

var appc = require("netrunr-gapi");

The Netrunr JavaScript SDK may also be downloaded and installed from GitHub as:

git clone https://github.com/axiomware/netrunr-gapi-js
cd netrunr-gapi-js
npm install
cd ..

To use the SDK installed from GitHub, add the following to Node.js programs:

var appc = require("./netrunr-gapi-js");

Web applications

Compressed and uncompressed versions of the Netrunr JavaScript SDK are available. The uncompressed version is best used during development or debugging. The compressed version saves bandwidth and improves performance in production. A sourcemap file is also available for debugging with a compressed version.

Download compressed, production version of the Netrunr JavaScript SDK

Download uncompressed, development version of the Netrunr JavaScript SDK

Download map for the compressed version of the Netrunr JavaScript SDK

To use the SDK in web applications, add these script tags:

<script src="./appc.gapi.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" type="text/javascript"></script>

The additional script files are:

Quickstart

The easiest way to get started is to install and run the Netrunr Basic Example app for Node.js.

Note: the Netrunr JavaScript SDK for Node.js is automatically installed by this app, so SDK Installation can be skipped.

Example Apps

For a list of example apps, see: Netrunr Example Apps.

Debugging

In addition to the normal debugging tools for web browsers and Node.js, certain console information is also available.

The this.debug flag may be set to 1 to print basic messages to the JavaScript console.

The this.verbose flag may be set to 1 to print more messages to the JavaScript console.

JSON.stringify(object, null, 2) is useful for formatting objects for logging or display.