Fetch user placeline

ht-client can be used to fetch and poll for latest user placeline data (and other primitives). The library makes the api calls to HyperTrack backend, and continuously polls for the data to emit the latest value on regular interval.

Complete code for this tutorial is available here

Steps

1. Setting up client

ht-client and their dependencies need to be installed. Follow this tutorial to set that up.

import {HtClient} from "ht-client"

var token = "sk_xxxxxxxxxxxxxxxxxxxx";
var client = new HtClient(token);

2. Setting user_id for the placeline

client initialized in the above setup code exposes user client.

...
var users = client.users;

users contains all users related endpoints which can be used to fetch relevant data. For this tutorial we'll use placeline endpoint.

var userId = "<USER_ID>";
users.placeline.setId(userId);

3. Subscribe to placeline data

placeline property of users client has a property data$ which is an observable<IUser>. Observables when subscribed to emits updated values after each poll.

...
var placelineData$ = users.placeline.data$;

var placelineSub = placelineData$.subscribe((users) => {
  //users placeline data emitted at regular interval
});

4 Stop subscription (optional)

To stop polling and cleanup the subscription, set id as null and unsubscribe to the Subscriptions

users.setId(null);
placelineSub.unsubscribe()

Customizations

1. Query parameters

The placeline data fetched by the api can be configured using different query parameters.

parameter example usage
date {date: "2017-11-06"} fetch placeline of any particular data. Date format should be YYYY-MM-DD
action_id {action_id: "ACTION_ID"} fetch placeline of any action
action_lookup_id {action_lookup_id: "ACTION_LOOKUP_ID"} fetch placeline of any action lookup id
action_collection_id {action_collection_id: "ACTION_COLLECTION_ID"} fetch placeline of any action collection id

Usage

...
let query = {date: "2017-11-06"};
users.placeline.setQuery(query);
...

2. Update Strategy

By default the client is configured to poll for updated data on regular interval. It can be configured to fetch the data only once. UsersClient has property updateStrategy which can take values of live and once. Default update strategy is set to live.

Usage

...

users.placeline.updateStrategy = 'once'; //default is 'live'
...

3. Polling interval

By default the poll interval is set to 10 seconds/10000 msec. This can be configured by changing pollDuration property in UsersClient

...
users.placeline.pollDuration = 5000; //5 secs, default to 10secs
...

results matching ""

    No results matching ""