npm package: @mistsys/react-native-mistsdk
Description: Mist Indoor Location sdk package
Author: Rajesh Vishwakarma
Latest version: 0.1.5

# React Native Mist SDK
iOS and Android wrapper for [Mist Location SDK iOS](https://github.com/mistsys/mist-vble-ios-sdk) and [Mist Location SDK Android](https://github.com/mistsys/mist-vble-android-sdk)

# Requirements
1. Minimum Android SDK: API 26.
2. iOS deployment Target: 14.0 or later.
3. Access to the [Mist Account](https://manage.mist.com/)
4. Mobile SDK secret

# Installation
1.  To install the package, inside your project directory, run:
    ```
    $npm install @mistsys/react-native-mistsdk
    ```
2.  For ```android``` User need to ask Bluetooth and location permissions from the react-native app side.
3.  For ```iOS``` follow the below steps:
4.  To provide bluetooth and motion sensor permission, add NSBluetoothAlwaysUsageDescription and NSMotionUsageDescription key with a string value in the info.plist file inside the ios folder.
    ```
    <key>NSBluetoothAlwaysUsageDescription</key>
    <String> Mist wants to access the Bluetooth in background </String>
    <key>NSMotionUsageDescription</key>
    <String> Motion sensor data is used to provide a more accurate indoor location estimate. </String>
    ```
5.  For Setup Podfile inside ios folder according to [react native documentation](https://reactnative.dev/docs/integration-with-existing-apps#configuring-cocoapods-dependencies), so the Podfile will look like this:
    ```
    target 'YourTargetName' do
    ....
    ....
        pod 'react-native-mistsdk', path: '../node_modules/@mistsys/react-native-mistsdk'   # add this line
    end
    ```
6. Change the directory to your ```ios``` folder and run the below command.
   ```
   $pod install
   ```

# Integration Guide
1. Import the libraries from react-native.

   _TypeScript:_
   ```
   import {NativeEventEmitter, NativeModules} from 'react-native';
   ```
2. Create an object for NativeModules to access the Mist SDK callbacks.

   _TypeScript:_
   ```
   const MistSDK = NativeModules.RNMistsdk ;
   const MistSDKEvents = new NativeEventEmitter(MistSDK);
   ```
3. Start the Mist SDK with the Mobile SDK token. 

   _TypeScript:_
   ```
   MistSDK.startWithToken(MIST_SDK_TOKEN);
   ```
4. Once we have taken all the above steps, we will be able to get all the required information in the respective callbacks.
5. <P>Let's go through all of the callbacks in detail.<P><br>

**<ins>onMapUpdate</ins>**

It will be called once the map gets updated – which means that, if the device moves from one floor to another floor, there will be a change in the floor map. In such a scenario this callback will be triggered with an updated floor map.

| Attribute     | Datatype   |  Description                                    |
| ------------- | -----------|-------------------------------------------------|
| mapId         | String     |Unique identifier of the map.                    |
| name          | String     |It is the name of the map (Floor plan)           |
| ppm           | double     |The number of pixels per meter.                  |
| url           | String     |This is the url which contains the actual map.   |

_TypeScript:_
```
MistSDKEvents.addListener('onMapUpdate', (map) => {
      console.log(map);
});
```

<ins>**onRelativeLocationUpdate**</ins>

The main purpose of this method is to provide a relativeLocation, which provides detailed information about the current location of the device.

| Attribute     | Datatype   |  Description                                    |
| ------------- | -----------|-------------------------------------------------|
| mapId         | String     |It provides id of the MistMap.                   |
| x             | double     |It is a spatial coordinate x (in px).            |
| y             | double     |It is a spatial coordinate y (in px).            |
| lat           | double     | It mentions the current latitude of the device. |
| lan           | double     | It mentions the current longitude of the device.|

_TypeScript:_
```
MistSDKEvents.addListener('onRelativeLocationUpdate', (relativeLocation) => {
      console.log(relativeLocation);
});
```

**<ins>onRecievedAllMaps</ins>**

This method will give us maps for all sites in the entire organization. It gives us the array of maps which is supposed to be of MistMap type. (Properties were explained in detail **onMapUpdate** method explanation). 

_TypeScript:_
```
MistSDKEvents.addListener('onReceivedAllMaps', (maps) => {
      console.log(maps);
});
```

**<ins>onEnterZone</ins>**

This method will be triggered when the app enters our monitoring region (the area we marked as a zone in our MistMap).

| Attribute     | Datatype   |  Description                                      |
| ------------- | -----------|---------------------------------------------------|
| zoneId        | String     |Unique identifier of the zone.                     |
| name          | String     |Name of the zone.                                  |
| mapId         | String     |The map ID associated with the zone event.         |
| userId        | String     |The user ID associated with the zone event.        |
| orgId         | String     |The organisation ID associated with the zone event.|
| siteId        | String     |The site ID associated with the zone event.        |
| recipient     | String     |The recipient of the zone event.                   |
| type          | String     |The trigger associated with the zone event.        |

_TypeScript:_
```
MistSDKEvents.addListener('onEnterZone', (zone) => {
      console.log(zone);
});
```

**<ins>onExitZone</ins>**

This method will be triggered when the app exits our monitoring region (the area we marked as a zone in our MistMap). 

| Attribute     | Datatype   |  Description                                      |
| ------------- | -----------|---------------------------------------------------|
| zoneId        | String     |Unique identifier of the zone.                     |
| name          | String     |Name of the zone.                                  |
| mapId         | String     |The map ID associated with the zone event.         |
| userId        | String     |The user ID associated with the zone event.        |
| orgId         | String     |The organisation ID associated with the zone event.|
| siteId        | String     |The site ID associated with the zone event.        |
| recipient     | String     |The recipient of the zone event.                   |
| type          | String     |The trigger associated with the zone event.        |

_TypeScript:_
```
MistSDKEvents.addListener('onExitZone', (zone) => {
      console.log(zone);
});
```

**<ins>onRangeVirtualBeacon</ins>**

Using this method, we can get the current ranging beacon, which is near to us.

| Attribute     | Datatype   |  Description                                          |
| ------------- | -----------|-------------------------------------------------------|
| name          | String     |Name of the Virtual Beacon.                            |
| orgId         | String     |Organization identifier.                               |
| siteId        | String     |Site Id.                                               |
| vbId          | String     |Unique Identifier of the Virtual beacon on Mist portal.|
| vbUUId        | String     |UUID of the Virtual Beacon.                            |
| message       | String     |Message associated with the virtual beacon.            |

_TypeScript:_
```
MistSDKEvents.addListener('onRangeVirtualBeacon', (virtualBeacon) => {
      console.log(virtualBeacon);
});
```

**<ins>onUpdateVirtualBeaconList</ins>**

It will return all the available virtual beacons placed on the floorplan whenever its position and other details are changed from the Mist portal. (Properties were explained in detail **onRangeVirtualBeacon** method explanation).

_TypeScript:_
```
MistSDKEvents.addListener('onUpdateVirtualBeaconList', (virtualBeacons) => {
      console.log(virtualBeacons);
});
```

**<ins>Note:</ins>** This plugin is not supported for Expo projects.