Skip to content

Getting Started

The JavaScript library communicates over a websocket or the accessibility service of the NIMMSTA Android / Windows App with the scanner.

Web Communication

Warning

If you are not using the websocket you have to keep in mind that the accessibility service is only able to monitor the hidden fields if the android phone is unlocked and the screen is active.

Requirements

  • NIMMSTA Android App Version 5.0 or above
  • Browser App on Android that supports ECMAScript 6

The communication with websites with this library works for all NIMMSTA Android / Windows Apps with version 5.0+. You can get the latest version in the NIMMSTA B2B Portal.

The library is compiled with ECMAScript 6 targeted. So ECMAScript 6 support is required.

Warning

The communication with the HS 50 only works if you open the website with a browser on the phone where the NIMMSTA App is installed or on a Windows PC that has the websocket application installed.

It is possible to debug the page on your phone. A tutorial on how this is done can be found on the official google page.

Integrate JavaScript Library

To get started with the NIMMSTA JavaScript Library, you have to add the script loader file to your HTML file above your JavaScript code that will use the library. If you want to build an Angular application you can get started with our Angular example project to see how it's done in an easy way.

<script type="text/javascript" src="https://cdn.nimmsta.com/latest/nimmsta.loader.js"></script>
<script type="text/javascript" src="your-index.js"></script>

TypeScript Definition

The TypeScript definition can be downloaded here: https://cdn.nimmsta.com/latest/nimmsta-ts-declarations.zip

Initialize library

The javascript file you added above is only a loader of the whole script which is embedded in the Application that is running on your machine (Android App, Windows JVM Application). If your using a non default websocket port you have to change it. After the initialization is done the callback function Nimmsta.onReady gets called. To initialize the communication between the website and the HS 50 you have to create an instance of NimmstaConnectionManager.

NIMMSTA.websocketPort = 64693;
NIMMSTA.requestSendTimeout = 1000; // 1000 ms until a request is considered 'failed'
NIMMSTA.maxCommunicationRetries = 3; // Roughly 3 * 1000 ms = 3000 ms is the time until onError will be invoked if app is missing.

// Invoked once connection to app is ready to be used.
NIMMSTA.onReady(function() {
    const connectionManager = new NimmstaConnectionManager();
    if (connectionManager.devices.length > 0) {
        const device = connectionManager.devices[0];
    } else {
        connectionManager.displayConnectActivity();
    }
});

NIMMSTA.onError(function(error) {
    // handle error, e.g. app is not installed, so no connection was established.
    // Retry connect by calling NIMMSTA.tryConnect()
});

Keeping Connection Open

The connection to the NIMMSTA Websocket is automatically closed once the focus of current tab gets lost. In certain circumstances, it makes sense ot change this behavior. You can set keepAlwaysConnected to true to keep the connection open. This is not possible when the communication is done through the AccessibilityService.

NIMMSTA.keepAlwaysConnected = true;

Debug logging

If you want to see debug logging for your development process, you can enable and disable it by calling:

// Enable debug logging
Logger.enableDebugLogging();

// Disable debug logging
Logger.disableDebugLogging();

To learn more about what you can do with the NimmstaConnectionManager or the NimmstaDevice head to the dedicated pages for them.