1.0.2 • Published 4 years ago

x-cite-tracking v1.0.2

Weekly downloads
13
License
-
Repository
-
Last release
4 years ago

This project was bootstrapped with x-cite.io project.

Available Scripts

In you project directory, run this script to install the package:

npm i x-cite-tracking
yarn add x-cite-tracking

To start using the package , import the module into your component

import {useTrackingservice} from 'x-cite-tracking'

Then use it in your app, those are the services that can be used:

const userToken = .... // you can use getCurrentUser() from firebase
const {	listDevices, GetReportStreamservice, GetListReportService, GetListLastReportService, listPersonsByThingId} = useTrackingservice(userToken);

To start using one of those services you can do a global promise like that :

export const promisifyGrpc = (fn) => (...args) => {
	let promise = new Promise((resolve, reject) => {
		fn(...args, (data) => resolve(data), (error) => reject(error));
	});
	return promise;
};

const userToken = .... // you can use getCurrentUser() from firebase
const {	listDevices, GetReportStreamservice, GetListReportService, GetListLastReportService, listPersonsByThingId} = useTrackingservice(userToken);

export const C19ListDevices = promisifyGrpc((id,...args) => listDevices(id,...args));
export const C19ReportStream = promisifyGrpc((id,...args) => GetReportStreamservice(id,...args));
export const C19ListReport = promisifyGrpc((id,...args) => GetListReportService(id,...args));
export const C19ListLastReport = promisifyGrpc((id,...args) => GetListLastReportService(id,...args));
export const C19listPersonByThingId = promisifyGrpc((id,...args) => listPersonsByThingId(id,...args));

For the stream, you have to call the service GetReportStreamservice directly into your component:

import {useTrackingservice} from 'x-cite-tracking'

const token = ""
const { GetReportStreamservice, cancel } = useTrackingservice(token)
// some code ....
  const startStream = ()=>{
    GetReportStreamservice(
      listLastReport, // list of latest report
      data => {
        console.log(data.toObject())
        ...
      },
      err => {
        console.log(err)
      }
    )
  }

you can use google map or any map tools to display reports