@sentiance-react-native/event-timeline 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/android/build.gradle +42 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/EventTimelineEmitter.java +22 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/SentianceEventTimelineModule.java +126 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/SentianceEventTimelinePackage.java +40 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/converters/OnDeviceTypesConverter.java +151 -0
- package/lib/index.d.ts +108 -0
- package/lib/index.js +55 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Sentiance Event Timeline module for React Native
|
|
2
|
+
|
|
3
|
+
## Demo Application
|
|
4
|
+
|
|
5
|
+
https://github.com/sentiance/sample-apps-react-native
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
To use the Event Timeline SDK module, please visit the corresponding [API reference page.](https://docs.sentiance.com/sdk/api-reference/react-native/event-timeline)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id "com.android.library"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
def coreProj
|
|
6
|
+
if (findProject(':core')) {
|
|
7
|
+
coreProj = project(':core')
|
|
8
|
+
} else if (findProject(':sentiance-react-native_core')) {
|
|
9
|
+
// Starting from RN 0.61, the @ sign is stripped from project names
|
|
10
|
+
coreProj = project(':sentiance-react-native_core')
|
|
11
|
+
} else if (findProject(':@sentiance-react-native_core')) {
|
|
12
|
+
// On RN 0.60, the @ sign is not stripped from project names
|
|
13
|
+
coreProj = project(':@sentiance-react-native_core')
|
|
14
|
+
} else {
|
|
15
|
+
throw new GradleException('Could not find the @sentiance-react-native/core package, have you installed it?')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
compileOptions {
|
|
20
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
21
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
apply from: "$coreProj.projectDir/package-json-reader.gradle"
|
|
26
|
+
apply from: "$coreProj.projectDir/sentiance-version-finder.gradle"
|
|
27
|
+
|
|
28
|
+
def corePackageJson = PackageJson.of(coreProj)
|
|
29
|
+
applyAndroidVersionsFrom(corePackageJson)
|
|
30
|
+
def sentianceSdkVersion = getSentianceSdkVersion()
|
|
31
|
+
|
|
32
|
+
dependencies {
|
|
33
|
+
implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
|
|
34
|
+
api("com.sentiance:sdk-event-timeline") { transitive = true }
|
|
35
|
+
api coreProj
|
|
36
|
+
|
|
37
|
+
if (findProject(':test-common')) {
|
|
38
|
+
testImplementation project(':test-common')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
applyReactNativeDependency()
|
package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/EventTimelineEmitter.java
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.eventtimeline;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
|
|
5
|
+
import com.sentiance.react.bridge.core.common.base.AbstractSentianceEmitter;
|
|
6
|
+
import com.sentiance.react.bridge.eventtimeline.converters.OnDeviceTypesConverter;
|
|
7
|
+
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
8
|
+
|
|
9
|
+
public class EventTimelineEmitter extends AbstractSentianceEmitter {
|
|
10
|
+
|
|
11
|
+
public static final String TIMELINE_UPDATE_EVENT = "SENTIANCE_TIMELINE_UPDATE_EVENT";
|
|
12
|
+
private final OnDeviceTypesConverter onDeviceTypesConverter;
|
|
13
|
+
|
|
14
|
+
public EventTimelineEmitter(Context context) {
|
|
15
|
+
super(context);
|
|
16
|
+
onDeviceTypesConverter = new OnDeviceTypesConverter();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public void sendTimelineUpdateEvent(Event event) {
|
|
20
|
+
sendEvent(TIMELINE_UPDATE_EVENT, onDeviceTypesConverter.convertEvent(event));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.eventtimeline;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.eventtimeline.EventTimelineEmitter.TIMELINE_UPDATE_EVENT;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.Promise;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+
import com.sentiance.react.bridge.core.common.SentianceSubscriptionsManager;
|
|
11
|
+
import com.sentiance.react.bridge.core.common.base.AbstractSentianceModule;
|
|
12
|
+
import com.sentiance.react.bridge.eventtimeline.converters.OnDeviceTypesConverter;
|
|
13
|
+
import com.sentiance.sdk.Sentiance;
|
|
14
|
+
import com.sentiance.sdk.eventtimeline.api.EventTimelineApi;
|
|
15
|
+
import com.sentiance.sdk.eventtimeline.api.EventTimelineUpdateListener;
|
|
16
|
+
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
17
|
+
|
|
18
|
+
import java.util.Date;
|
|
19
|
+
import java.util.List;
|
|
20
|
+
|
|
21
|
+
public class SentianceEventTimelineModule extends AbstractSentianceModule {
|
|
22
|
+
public static final String NATIVE_MODULE_NAME = "SentianceEventTimeline";
|
|
23
|
+
|
|
24
|
+
private final EventTimelineApi mEventTimelineApi;
|
|
25
|
+
private final EventTimelineEmitter mEmitter;
|
|
26
|
+
private final OnDeviceTypesConverter onDeviceTypesConverter;
|
|
27
|
+
|
|
28
|
+
public SentianceEventTimelineModule(ReactApplicationContext reactApplicationContext,
|
|
29
|
+
Sentiance sentiance,
|
|
30
|
+
SentianceSubscriptionsManager subscriptionsManager,
|
|
31
|
+
EventTimelineApi eventTimelineApi,
|
|
32
|
+
EventTimelineEmitter emitter,
|
|
33
|
+
OnDeviceTypesConverter converter) {
|
|
34
|
+
super(reactApplicationContext, sentiance, subscriptionsManager);
|
|
35
|
+
mEventTimelineApi = eventTimelineApi;
|
|
36
|
+
mEmitter = emitter;
|
|
37
|
+
onDeviceTypesConverter = converter;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
protected void addSupportedEventSubscriptions(SentianceSubscriptionsManager subscriptionsManager) {
|
|
42
|
+
subscriptionsManager.addSupportedSubscription(
|
|
43
|
+
TIMELINE_UPDATE_EVENT,
|
|
44
|
+
mEventTimelineApi::setTimelineUpdateListener,
|
|
45
|
+
listener -> mEventTimelineApi.setTimelineUpdateListener(null),
|
|
46
|
+
SentianceSubscriptionsManager.SubscriptionType.SINGLE
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
@ReactMethod
|
|
52
|
+
protected void removeNativeListener(String eventName, int subscriptionId, Promise promise) {
|
|
53
|
+
if (rejectIfNotInitialized(promise)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
mSubscriptionsManager.removeSubscription(subscriptionId, eventName);
|
|
58
|
+
promise.resolve(null);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Override
|
|
62
|
+
@ReactMethod
|
|
63
|
+
protected void addNativeListener(String eventName, int subscriptionId, Promise promise) {
|
|
64
|
+
if (rejectIfNotInitialized(promise)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
switch (eventName) {
|
|
69
|
+
case TIMELINE_UPDATE_EVENT:
|
|
70
|
+
mSubscriptionsManager.addSubscription(eventName, subscriptionId, (EventTimelineUpdateListener) mEmitter::sendTimelineUpdateEvent);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
promise.resolve(null);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
@ReactMethod
|
|
78
|
+
protected void addListener(String eventName) {
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Override
|
|
83
|
+
@ReactMethod
|
|
84
|
+
protected void removeListeners(Integer count) {
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@NonNull
|
|
89
|
+
@Override
|
|
90
|
+
public String getName() {
|
|
91
|
+
return NATIVE_MODULE_NAME;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
public void getTimelineUpdates(final Double afterEpochTimeMs, final Promise promise) {
|
|
96
|
+
if (rejectIfNotInitialized(promise)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Date afterDate = new Date(afterEpochTimeMs.longValue());
|
|
101
|
+
List<Event> events = mEventTimelineApi.getTimelineUpdates(afterDate);
|
|
102
|
+
promise.resolve(onDeviceTypesConverter.convertEvents(events));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@ReactMethod
|
|
106
|
+
public void getTimelineEvents(final Double fromEpochTimeMs, final Double toEpochTimeMs, final Promise promise) {
|
|
107
|
+
if (rejectIfNotInitialized(promise)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Date fromDate = new Date(fromEpochTimeMs.longValue());
|
|
112
|
+
Date toDate = new Date(toEpochTimeMs.longValue());
|
|
113
|
+
List<Event> events = mEventTimelineApi.getTimelineEvents(fromDate, toDate);
|
|
114
|
+
promise.resolve(onDeviceTypesConverter.convertEvents(events));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@ReactMethod
|
|
118
|
+
public void getTimelineEvent(final String eventId, final Promise promise) {
|
|
119
|
+
if (rejectIfNotInitialized(promise)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Event event = mEventTimelineApi.getTimelineEvent(eventId);
|
|
124
|
+
promise.resolve(event == null ? null : onDeviceTypesConverter.convertEvent(event));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.eventtimeline;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
import com.sentiance.react.bridge.core.common.SentianceSubscriptionsManager;
|
|
10
|
+
import com.sentiance.react.bridge.eventtimeline.converters.OnDeviceTypesConverter;
|
|
11
|
+
import com.sentiance.sdk.Sentiance;
|
|
12
|
+
import com.sentiance.sdk.eventtimeline.api.EventTimelineApi;
|
|
13
|
+
|
|
14
|
+
import java.util.ArrayList;
|
|
15
|
+
import java.util.Collections;
|
|
16
|
+
import java.util.List;
|
|
17
|
+
|
|
18
|
+
public class SentianceEventTimelinePackage implements ReactPackage {
|
|
19
|
+
@NonNull
|
|
20
|
+
@Override
|
|
21
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
22
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
23
|
+
SentianceEventTimelineModule eventTimelineModule = new SentianceEventTimelineModule(
|
|
24
|
+
reactContext,
|
|
25
|
+
Sentiance.getInstance(reactContext),
|
|
26
|
+
new SentianceSubscriptionsManager(),
|
|
27
|
+
EventTimelineApi.getInstance(reactContext),
|
|
28
|
+
new EventTimelineEmitter(reactContext),
|
|
29
|
+
new OnDeviceTypesConverter()
|
|
30
|
+
);
|
|
31
|
+
modules.add(eventTimelineModule);
|
|
32
|
+
return modules;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@NonNull
|
|
36
|
+
@Override
|
|
37
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
38
|
+
return Collections.emptyList();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.eventtimeline.converters;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_ACCURACY;
|
|
4
|
+
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_LATITUDE;
|
|
5
|
+
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_LONGITUDE;
|
|
6
|
+
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_TIMESTAMP;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.WritableArray;
|
|
10
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
|
+
import com.sentiance.sdk.ondevice.api.GeoLocation;
|
|
12
|
+
import com.sentiance.sdk.ondevice.api.Waypoint;
|
|
13
|
+
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
14
|
+
import com.sentiance.sdk.ondevice.api.event.StationaryEvent;
|
|
15
|
+
import com.sentiance.sdk.ondevice.api.event.TransportEvent;
|
|
16
|
+
import com.sentiance.sdk.ondevice.api.venue.Venue;
|
|
17
|
+
|
|
18
|
+
import java.util.List;
|
|
19
|
+
|
|
20
|
+
public class OnDeviceTypesConverter {
|
|
21
|
+
public static final String JS_KEY_ID = "id";
|
|
22
|
+
public static final String JS_KEY_START_TIME = "startTime";
|
|
23
|
+
public static final String JS_KEY_START_TIME_EPOCH = "startTimeEpoch";
|
|
24
|
+
public static final String JS_KEY_END_TIME = "endTime";
|
|
25
|
+
public static final String JS_KEY_END_TIME_EPOCH = "endTimeEpoch";
|
|
26
|
+
public static final String JS_KEY_LAST_UPDATE_TIME = "lastUpdateTime";
|
|
27
|
+
public static final String JS_KEY_LAST_UPDATE_TIME_EPOCH = "lastUpdateTimeEpoch";
|
|
28
|
+
public static final String JS_KEY_DURATION_SECONDS = "durationInSeconds";
|
|
29
|
+
public static final String JS_KEY_TYPE = "type";
|
|
30
|
+
public static final String JS_KEY_LOCATION = "location";
|
|
31
|
+
public static final String JS_KEY_VENUE = "venue";
|
|
32
|
+
public static final String JS_KEY_SIGNIFICANCE = "significance";
|
|
33
|
+
public static final String JS_KEY_TRANSPORT_MODE = "transportMode";
|
|
34
|
+
public static final String JS_KEY_WAYPOINTS = "waypoints";
|
|
35
|
+
public static final String JS_KEY_DISTANCE = "distance";
|
|
36
|
+
public static final String JS_KEY_SPEED_IN_MPS = "speedInMps";
|
|
37
|
+
public static final String JS_KEY_SPEED_LIMIT_IN_MPS = "speedLimitInMps";
|
|
38
|
+
public static final String JS_KEY_HAS_UNLIMITED_SPEED_LIMIT = "hasUnlimitedSpeedLimit";
|
|
39
|
+
public static final String JS_KEY_IS_SPEED_LIMIT_INFO_SET = "isSpeedLimitInfoSet";
|
|
40
|
+
|
|
41
|
+
public WritableMap convertGeoLocation(GeoLocation location) {
|
|
42
|
+
WritableMap locationMap = Arguments.createMap();
|
|
43
|
+
|
|
44
|
+
locationMap.putDouble(JS_KEY_LATITUDE, location.getLatitude());
|
|
45
|
+
locationMap.putDouble(JS_KEY_LONGITUDE, location.getLongitude());
|
|
46
|
+
locationMap.putInt(JS_KEY_ACCURACY, location.getAccuracyInMeters());
|
|
47
|
+
|
|
48
|
+
return locationMap;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public WritableArray convertEvents(List<Event> events) {
|
|
52
|
+
WritableArray array = Arguments.createArray();
|
|
53
|
+
for (Event event : events) {
|
|
54
|
+
array.pushMap(convertEvent(event));
|
|
55
|
+
}
|
|
56
|
+
return array;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public WritableMap convertEvent(Event event) {
|
|
60
|
+
WritableMap map = Arguments.createMap();
|
|
61
|
+
|
|
62
|
+
map.putString(JS_KEY_ID, event.getId());
|
|
63
|
+
map.putString(JS_KEY_START_TIME, event.getStartTime().toString());
|
|
64
|
+
map.putDouble(JS_KEY_START_TIME_EPOCH, event.getStartTime().getEpochTime());
|
|
65
|
+
if (event.getEndTime() != null) {
|
|
66
|
+
map.putString(JS_KEY_END_TIME, event.getEndTime().toString());
|
|
67
|
+
map.putDouble(JS_KEY_END_TIME_EPOCH, event.getEndTime().getEpochTime());
|
|
68
|
+
|
|
69
|
+
Long durationInSeconds = event.getDurationInSeconds();
|
|
70
|
+
if (durationInSeconds != null) {
|
|
71
|
+
map.putDouble(JS_KEY_DURATION_SECONDS, durationInSeconds);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
map.putString(JS_KEY_LAST_UPDATE_TIME, event.getLastUpdateTime().toString());
|
|
76
|
+
map.putDouble(JS_KEY_LAST_UPDATE_TIME_EPOCH, event.getLastUpdateTime().getEpochTime());
|
|
77
|
+
|
|
78
|
+
map.putString(JS_KEY_TYPE, event.getEventType().toString());
|
|
79
|
+
|
|
80
|
+
if (event instanceof StationaryEvent) {
|
|
81
|
+
addStationaryEventInfo(map, (StationaryEvent) event);
|
|
82
|
+
} else if (event instanceof TransportEvent) {
|
|
83
|
+
addTransportEventInfo(map, (TransportEvent) event);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return map;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private void addStationaryEventInfo(WritableMap map, StationaryEvent event) {
|
|
90
|
+
if (event.getLocation() != null) {
|
|
91
|
+
map.putMap(JS_KEY_LOCATION, convertGeoLocation(event.getLocation()));
|
|
92
|
+
}
|
|
93
|
+
map.putMap(JS_KEY_VENUE, convertVenue(event.getVenue()));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public WritableMap convertVenue(Venue venue) {
|
|
97
|
+
WritableMap venueMap = Arguments.createMap();
|
|
98
|
+
|
|
99
|
+
if (venue.getLocation() != null) {
|
|
100
|
+
venueMap.putMap(JS_KEY_LOCATION, convertGeoLocation(venue.getLocation()));
|
|
101
|
+
}
|
|
102
|
+
venueMap.putString(JS_KEY_SIGNIFICANCE, venue.getSignificance().name());
|
|
103
|
+
venueMap.putString(JS_KEY_TYPE, venue.getType().name());
|
|
104
|
+
|
|
105
|
+
return venueMap;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private void addTransportEventInfo(WritableMap map, TransportEvent event) {
|
|
109
|
+
map.putString(JS_KEY_TRANSPORT_MODE, event.getTransportMode().toString());
|
|
110
|
+
map.putArray(JS_KEY_WAYPOINTS, convertWaypointList(event.getWaypoints()));
|
|
111
|
+
|
|
112
|
+
if (event.getDistanceInMeters() != null) {
|
|
113
|
+
map.putInt(JS_KEY_DISTANCE, event.getDistanceInMeters());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public WritableArray convertWaypoints(List<Waypoint> waypointList) {
|
|
118
|
+
WritableArray array = Arguments.createArray();
|
|
119
|
+
for (Waypoint waypoint : waypointList) {
|
|
120
|
+
array.pushMap(convertWaypoint(waypoint));
|
|
121
|
+
}
|
|
122
|
+
return array;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public WritableMap convertWaypoint(Waypoint waypoint) {
|
|
126
|
+
WritableMap waypointMap = Arguments.createMap();
|
|
127
|
+
|
|
128
|
+
waypointMap.putDouble(JS_KEY_LATITUDE, waypoint.getLatitude());
|
|
129
|
+
waypointMap.putDouble(JS_KEY_LONGITUDE, waypoint.getLongitude());
|
|
130
|
+
waypointMap.putInt(JS_KEY_ACCURACY, waypoint.getAccuracyInMeters());
|
|
131
|
+
waypointMap.putDouble(JS_KEY_TIMESTAMP, waypoint.getTimestamp());
|
|
132
|
+
if (waypoint.hasSpeed()) {
|
|
133
|
+
waypointMap.putDouble(JS_KEY_SPEED_IN_MPS, waypoint.getSpeedInMps());
|
|
134
|
+
}
|
|
135
|
+
if (waypoint.isSpeedLimitInfoSet() && !waypoint.hasUnlimitedSpeedLimit()) {
|
|
136
|
+
waypointMap.putDouble(JS_KEY_SPEED_LIMIT_IN_MPS, waypoint.getSpeedLimitInMps());
|
|
137
|
+
}
|
|
138
|
+
waypointMap.putBoolean(JS_KEY_IS_SPEED_LIMIT_INFO_SET, waypoint.isSpeedLimitInfoSet());
|
|
139
|
+
waypointMap.putBoolean(JS_KEY_HAS_UNLIMITED_SPEED_LIMIT, waypoint.hasUnlimitedSpeedLimit());
|
|
140
|
+
|
|
141
|
+
return waypointMap;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private WritableArray convertWaypointList(List<Waypoint> waypointList) {
|
|
145
|
+
WritableArray array = Arguments.createArray();
|
|
146
|
+
for (Waypoint waypoint : waypointList) {
|
|
147
|
+
array.pushMap(convertWaypoint(waypoint));
|
|
148
|
+
}
|
|
149
|
+
return array;
|
|
150
|
+
}
|
|
151
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
declare module "@sentiance-react-native/event-timeline" {
|
|
2
|
+
import {EmitterSubscription} from "react-native";
|
|
3
|
+
|
|
4
|
+
export interface Event {
|
|
5
|
+
id: string;
|
|
6
|
+
startTime: string;
|
|
7
|
+
startTimeEpoch: number; // in milliseconds
|
|
8
|
+
lastUpdateTime: string;
|
|
9
|
+
lastUpdateTimeEpoch: number; // in milliseconds
|
|
10
|
+
endTime: string | null;
|
|
11
|
+
endTimeEpoch: number | null; // in milliseconds
|
|
12
|
+
durationInSeconds: number | null;
|
|
13
|
+
type: EventType;
|
|
14
|
+
// stationary event fields
|
|
15
|
+
location: GeoLocation | null;
|
|
16
|
+
venue: Venue | null;
|
|
17
|
+
// transport event fields
|
|
18
|
+
transportMode: TransportMode | null;
|
|
19
|
+
waypoints: Waypoint[];
|
|
20
|
+
distance?: number; // in meters
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface GeoLocation {
|
|
24
|
+
latitude: number;
|
|
25
|
+
longitude: number;
|
|
26
|
+
accuracy: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Venue {
|
|
30
|
+
location: GeoLocation | null;
|
|
31
|
+
significance: VenueSignificance;
|
|
32
|
+
type: VenueType;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type VenueType =
|
|
36
|
+
| "UNKNOWN"
|
|
37
|
+
| "DRINK_DAY"
|
|
38
|
+
| "DRINK_EVENING"
|
|
39
|
+
| "EDUCATION_INDEPENDENT"
|
|
40
|
+
| "EDUCATION_PARENTS"
|
|
41
|
+
| "HEALTH"
|
|
42
|
+
| "INDUSTRIAL"
|
|
43
|
+
| "LEISURE_BEACH"
|
|
44
|
+
| "LEISURE_DAY"
|
|
45
|
+
| "LEISURE_EVENING"
|
|
46
|
+
| "LEISURE_MUSEUM"
|
|
47
|
+
| "LEISURE_NATURE"
|
|
48
|
+
| "LEISURE_PARK"
|
|
49
|
+
| "OFFICE"
|
|
50
|
+
| "RELIGION"
|
|
51
|
+
| "RESIDENTIAL"
|
|
52
|
+
| "RESTO_MID"
|
|
53
|
+
| "RESTO_SHORT"
|
|
54
|
+
| "SHOP_LONG"
|
|
55
|
+
| "SHOP_SHORT"
|
|
56
|
+
| "SPORT"
|
|
57
|
+
| "SPORT_ATTEND"
|
|
58
|
+
| "TRAVEL_BUS"
|
|
59
|
+
| "TRAVEL_CONFERENCE"
|
|
60
|
+
| "TRAVEL_FILL"
|
|
61
|
+
| "TRAVEL_HOTEL"
|
|
62
|
+
| "TRAVEL_LONG"
|
|
63
|
+
| "TRAVEL_SHORT"
|
|
64
|
+
|
|
65
|
+
export type VenueSignificance =
|
|
66
|
+
| "UNKNOWN"
|
|
67
|
+
| "HOME"
|
|
68
|
+
| "WORK"
|
|
69
|
+
| "POINT_OF_INTEREST";
|
|
70
|
+
|
|
71
|
+
export type EventType =
|
|
72
|
+
| "UNKNOWN"
|
|
73
|
+
| "STATIONARY"
|
|
74
|
+
| "OFF_THE_GRID"
|
|
75
|
+
| "IN_TRANSPORT";
|
|
76
|
+
|
|
77
|
+
export type TransportMode =
|
|
78
|
+
| "UNKNOWN"
|
|
79
|
+
| "BICYCLE"
|
|
80
|
+
| "WALKING"
|
|
81
|
+
| "RUNNING"
|
|
82
|
+
| "TRAM"
|
|
83
|
+
| "TRAIN"
|
|
84
|
+
| "CAR"
|
|
85
|
+
| "BUS"
|
|
86
|
+
| "MOTORCYCLE";
|
|
87
|
+
|
|
88
|
+
export interface Waypoint {
|
|
89
|
+
latitude: number;
|
|
90
|
+
longitude: number;
|
|
91
|
+
accuracy: number; // in meters
|
|
92
|
+
timestamp: number; // UTC epoch time in milliseconds
|
|
93
|
+
speedInMps?: number; // in meters per second
|
|
94
|
+
speedLimitInMps?: number; // in meters per second
|
|
95
|
+
hasUnlimitedSpeedLimit: boolean;
|
|
96
|
+
isSpeedLimitInfoSet: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface EventTimelineApi {
|
|
100
|
+
getTimelineUpdates(afterEpochTimeMs: number): Promise<Event[]>;
|
|
101
|
+
getTimelineEvents(fromEpochTimeMs: number, toEpochTimeMs: number): Promise<Event[]>;
|
|
102
|
+
getTimelineEvent(eventId: string): Promise<Event | null>;
|
|
103
|
+
addTimelineUpdateListener(onTimelineUpdated: (event: Event) => void): Promise<EmitterSubscription>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const EventTimelineApi: EventTimelineApi;
|
|
107
|
+
export default EventTimelineApi;
|
|
108
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const {NativeModules, Platform} = require("react-native");
|
|
2
|
+
const {varToString} = require("@sentiance-react-native/core/lib/utils");
|
|
3
|
+
const SentianceEventEmitter = require("@sentiance-react-native/core/lib/SentianceEventEmitter");
|
|
4
|
+
const {createEventListener} = require("@sentiance-react-native/core/lib/SentianceEventListenerUtils");
|
|
5
|
+
const {SentianceEventTimeline, SentianceCore} = NativeModules;
|
|
6
|
+
|
|
7
|
+
const TIMELINE_UPDATE_EVENT = "SENTIANCE_TIMELINE_UPDATE_EVENT";
|
|
8
|
+
|
|
9
|
+
let didLocateNativeModule = true;
|
|
10
|
+
let eventTimelineModule = {};
|
|
11
|
+
if (Platform.OS === 'android') {
|
|
12
|
+
if (!SentianceEventTimeline) {
|
|
13
|
+
didLocateNativeModule = false;
|
|
14
|
+
const nativeModuleName = varToString({SentianceEventTimeline});
|
|
15
|
+
console.error(`Could not locate the native ${nativeModuleName} module.
|
|
16
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`);
|
|
17
|
+
} else {
|
|
18
|
+
eventTimelineModule = SentianceEventTimeline;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
if (!SentianceCore) {
|
|
22
|
+
didLocateNativeModule = false;
|
|
23
|
+
const nativeModuleName = varToString({SentianceCore});
|
|
24
|
+
console.error(`Could not locate the native ${nativeModuleName} module.
|
|
25
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`);
|
|
26
|
+
} else {
|
|
27
|
+
eventTimelineModule = SentianceCore;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (didLocateNativeModule) {
|
|
32
|
+
const emitter = new SentianceEventEmitter(eventTimelineModule);
|
|
33
|
+
|
|
34
|
+
eventTimelineModule._addTimelineUpdateListener = async (onTimelineUpdated) => {
|
|
35
|
+
return createEventListener(TIMELINE_UPDATE_EVENT, emitter, onTimelineUpdated);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getTimelineUpdates = (afterEpochTimeMs) => eventTimelineModule.getTimelineUpdates(afterEpochTimeMs);
|
|
40
|
+
|
|
41
|
+
const getTimelineEvents = (fromEpochTimeMs, toEpochTimeMs) => eventTimelineModule.getTimelineEvents(fromEpochTimeMs, toEpochTimeMs);
|
|
42
|
+
|
|
43
|
+
const getTimelineEvent = (eventId) => eventTimelineModule.getTimelineEvent(eventId);
|
|
44
|
+
|
|
45
|
+
const addTimelineUpdateListener = eventTimelineModule._addTimelineUpdateListener;
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
getTimelineUpdates,
|
|
49
|
+
getTimelineEvents,
|
|
50
|
+
getTimelineEvent,
|
|
51
|
+
addTimelineUpdateListener
|
|
52
|
+
};
|
|
53
|
+
module.exports.events = {
|
|
54
|
+
TIMELINE_UPDATE_EVENT
|
|
55
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sentiance-react-native/event-timeline",
|
|
3
|
+
"version": "6.6.0",
|
|
4
|
+
"description": "The Sentiance Event Timeline library",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --verbose",
|
|
9
|
+
"lint": "npx eslint lib/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react-native",
|
|
13
|
+
"event-timeline",
|
|
14
|
+
"sentiance"
|
|
15
|
+
],
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@sentiance-react-native/core": "6.6.0"
|
|
18
|
+
},
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "",
|
|
21
|
+
"homepage": "https://github.com/sentiance/react-native-sentiance/tree/main/packages/event-timeline",
|
|
22
|
+
"repository": "github:sentiance/react-native-sentiance",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
}
|
|
26
|
+
}
|