1.0.1 • Published 2 years ago

@os1-platform/mts-mobile v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

MTS SDK

Introduction

MTS or Movement Tracking System is an android SDK written in Java & Kotlin.
It can be integrated to any native android or react native application(android only) apps.
It can be used for user/vehicle tracking.
Currently support SDK>=21 and <=29.



MTS SDK provides the following features:

1. Provides real time location updates
2. Sync location updates to server in real time**
3. Works in the background even if the app is killed
4. This library can be used in  react native as well as in native android.
5. Sync Location Trace both through REST API & MQTT (MQ Telemetry Transport)
Protocol.

Installation

npm install @os1-platform/mts-mobile

Usage

import * as MtsLib from '@os1-platform/mts-mobile';
// Add token expiry sync task in root index file (index.ts)
import { registerSyncTask } from '@os1-platform/mts-mobile';
registerSyncTask();

MTS Default Config

export class MTSDefaults {
  locationFrequency: number = 10000; // in milli seconds (no. of seconds after which location updates will happen)
  distanceAccuracyLimit: number = 250; // in metres
  speedLimit: number = 28; // in m/s
  mode: MTSMode = MTSMode.HYBRID;
  environment: MTSEnv = MTSEnv.DEV;
  batchSize: number = 25;
  isMqttCleanSession: boolean = true;
  mqttKeepAliveInterval: number = 15 * 60; //in seconds
  maxLocationAge: number = 15000; // in milliseconds
  maxTraceSession: number = 24 * 3600 * 100; //in milliseconds
  isOdometerEnabled: boolean = true;
  retriesBeforeFallback: number = 1;
  httpFailureLimit: number = 5;
  dataSendDelay: number = 30000; // in milli seconds
  alarmTime: number = 60000; // in milli seconds
  missingSeqCheckDuration: number = 5 * 60 * 1000; // in milli seconds
  odometerPushFrequency: number = 5 * 60 * 1000; // in milli seconds
  qosLevel: number = 1; // values can be 0 ,1
}

Check For Mandatory MTS Permissions

let granted = await MtsLib.requestPermissionsForMTS();
// if granted = true : all permissions granted
// granted = false : one or more permissions denied

Init MTS

import type { MTSInitRequest } from '@os1-platform/mts-mobile';

let mtsDefaults = new MtsLib.MTSDefaults();
mtsDefaults.speedLimit = 5000;
mtsDefaults.locationFrequency = 10000;
mtsDefaults.environment = MtsLib.MTSEnv.PRE_PROD;
mtsDefaults.isOdometerEnabled = false;

//Change MTS default values as per your use case

// ...Use this for Initiating MTS
let mtsInitReq: MTSInitRequest = {
  appName: 'app_name',
  appVersion: '1',
  mtsDeviceID: 'deviceId', // Use a unique device ID here
  configData: mtsDefaults,
  baseURL: 'https://{tenant}.example.io/{mtsEndpoint}',
  accessToken: 'token',
  tenantID: 'TENANTID',
};
MtsLib.initMTS(mtsInitReq, async () => {
  // fetch latest token and return the lastest access token
  return 'newToken';
});
//See Error Codes for Possible error types

Start MTS

let startReq: MTSStartRequest = {
  accessToken: 'token', // update access token
  resetSequence: false,
  dispatchID: '12345', // pass dispatch ID here
  expiryTime: Date.now() + 24 * 2600 * 1000, // expiry time after which MTS will stop automatically
};
await MtsLib.startMTS(startReq);

Publish Event

await MtsLib.publishEvent('TESTEVENT', { battery: 56, network: 100 });

Stop MTS

// To stop mts
await MtsLib.stopMTS();

Error Codes

PERMISSIONS_ERROR[2500] = 'Mandatory Android Permissions not provided';
MTS_INIT_ERROR[2501] = 'MTS INIT Not called! MTS Device ID is Empty';
PARAM_MISSING[2502] = 'Mandatory Paramater is missing in request';