Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-native-kontaktio with all npm packages installed. Try it out:

var reactNativeKontaktio = require("react-native-kontaktio")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-native-kontaktio v2.7.0

React-native module for detecting [Kontakt.io](http://kontakt.io/) beacons. You have to own some Kontakt.io beacons, configure them via their managment console and have your api-key handy.

react-native-kontaktio npm version

Cross-platform React Native module for detecting beacons with Android and iOS devices.

Kontakt.io SDK Versions of newest release:

OSSDK Version
Android4.0.1 (Documentation points to 4.0.2)
iOS1.5.1

The documentation points to 4.0.2 because there is none specifically for 4.0.1. The Android SDK Version 4.0.2 could not be installed.

Advantages

  • Works with any beacon (becquse the Kontakt.io SDK wraps the native beacon libraries (while adding more) - no Kontakt.io SDK API key is necessary.
  • Especially useful with Kontakt.io beacons because additional information like the unique id (on the back of each beacon), the battery power level and others are available and get synchronized with your Kontakt.io online panel.
  • Highly customizable configurations (e.g. for setting arbitrary monitoring intervals on Android)

Setup

API Documentation

Examples

Extensive Example

Minimal Example

A minimal example with the default configuration and no specifically set regions. Thus, the default region everywhere (i.e. all beacons) is automatically used.

Android

Example/src/MinimalExample.android.js:

import React, { Component } from 'react';
import { View, DeviceEventEmitter } from 'react-native';

import Kontakt from 'react-native-kontaktio';
const { connect, startScanning } = Kontakt;

export default class MinimalExample extends Component {
  componentDidMount() {
    connect()
      .then(() => startScanning())
      .catch(error => console.log('error', error));

    DeviceEventEmitter.addListener(
      'beaconsDidUpdate',
      ({ beacons, region }) => {
        console.log('beaconsDidUpdate', beacons, region);
      },
    );
  }

  render() {
    return <View />;
  }
}

iOS

Example/src/MinimalExample.ios.js:

import React, { Component } from 'react';
import { View, NativeEventEmitter } from 'react-native';

import Kontakt, { KontaktModule } from 'react-native-kontaktio';
const { init, startDiscovery } = Kontakt;

const kontaktEmitter = new NativeEventEmitter(KontaktModule);

/**
 * Minimal example of react-native-kontaktio
 */
export default class MinimalExample extends Component {
  componentDidMount() {
    init()
      .then(() => startDiscovery())
      .catch(error => alert('error', error));

    // Add beacon listener
    kontaktEmitter.addListener('didDiscoverDevices', ({ beacons }) => {
      console.log('didDiscoverDevices', beacons);
    });
  }

  render() {
    return <View />;
  }
}

Run Example to test the module

  1. Clone this repository, connect an Android and/or Apple device to your computer and have some (Kontakt.io) beacons handy

  2. Open a terminal window, bash to the Example/ folder, run npm install and start the react-native server

    $ cd react-native-kontaktio/Example
    $ npm install
    $ npm start
    
  3. Build the example and run it on your device. The app will appear under the name KontaktIoSimpleTest:

    • Android:

          $ react-native run-android
      
    • iOS

          $ react-native run-ios
      

Further notes

  • Beacons support is part of Android versions 4.3 and up. * So far the lowest Android version this library was tested on was a device with Android 4.4.2.
  • A physical device must be used for testing, at best some Kontakt.io beacons.

ToDo:

  • Update Android Eddystone feature:

    • Add multiple Eddystone namespaces, i.e. add function setEddystoneNamespaces
    • Add Eddystone Frames Selection configuration option
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free