@sentiance-react-native/event-timeline 6.10.0-rc.5 → 6.10.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/android/src/main/java/com/sentiance/react/bridge/eventtimeline/ErrorCodes.java +2 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/SentianceEventTimelinePackage.java +12 -3
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/SentianceFeedbackModule.java +79 -0
- package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/converters/OnDeviceTypesConverter.java +19 -1
- package/lib/feedback.js +40 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +6 -2
- package/package.json +2 -2
|
@@ -2,4 +2,6 @@ package com.sentiance.react.bridge.eventtimeline;
|
|
|
2
2
|
|
|
3
3
|
public class ErrorCodes {
|
|
4
4
|
public static final String E_TRANSPORT_TAG_ERROR = "E_TRANSPORT_TAG_ERROR";
|
|
5
|
+
public static final String E_INVALID_FEEDBACK_TYPE = "E_INVALID_FEEDBACK_TYPE";
|
|
6
|
+
public static final String E_OCCUPANT_ROLE_FEEDBACK_SUBMISSION = "E_OCCUPANT_ROLE_FEEDBACK_SUBMISSION";
|
|
5
7
|
}
|
|
@@ -10,8 +10,10 @@ import com.sentiance.react.bridge.core.common.SentianceSubscriptionsManager;
|
|
|
10
10
|
import com.sentiance.react.bridge.eventtimeline.converters.OnDeviceTypesConverter;
|
|
11
11
|
import com.sentiance.sdk.Sentiance;
|
|
12
12
|
import com.sentiance.sdk.eventtimeline.api.EventTimelineApi;
|
|
13
|
+
import com.sentiance.sdk.feedback.api.FeedbackApi;
|
|
13
14
|
|
|
14
15
|
import java.util.ArrayList;
|
|
16
|
+
import java.util.Arrays;
|
|
15
17
|
import java.util.Collections;
|
|
16
18
|
import java.util.List;
|
|
17
19
|
|
|
@@ -19,7 +21,6 @@ public class SentianceEventTimelinePackage implements ReactPackage {
|
|
|
19
21
|
@NonNull
|
|
20
22
|
@Override
|
|
21
23
|
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
22
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
23
24
|
SentianceEventTimelineModule eventTimelineModule = new SentianceEventTimelineModule(
|
|
24
25
|
reactContext,
|
|
25
26
|
Sentiance.getInstance(reactContext),
|
|
@@ -28,8 +29,16 @@ public class SentianceEventTimelinePackage implements ReactPackage {
|
|
|
28
29
|
new EventTimelineEmitter(reactContext),
|
|
29
30
|
new OnDeviceTypesConverter()
|
|
30
31
|
);
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
SentianceFeedbackModule feedbackModule = new SentianceFeedbackModule(
|
|
34
|
+
reactContext,
|
|
35
|
+
Sentiance.getInstance(reactContext),
|
|
36
|
+
FeedbackApi.getInstance(),
|
|
37
|
+
new SentianceSubscriptionsManager(),
|
|
38
|
+
new OnDeviceTypesConverter()
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return Arrays.asList(eventTimelineModule, feedbackModule);
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
@NonNull
|
package/android/src/main/java/com/sentiance/react/bridge/eventtimeline/SentianceFeedbackModule.java
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.eventtimeline;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.eventtimeline.ErrorCodes.E_INVALID_FEEDBACK_TYPE;
|
|
4
|
+
import static com.sentiance.react.bridge.eventtimeline.ErrorCodes.E_OCCUPANT_ROLE_FEEDBACK_SUBMISSION;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
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.feedback.api.FeedbackApi;
|
|
15
|
+
import com.sentiance.sdk.feedback.api.OccupantRoleFeedback;
|
|
16
|
+
import com.sentiance.sdk.feedback.api.OccupantRoleFeedbackResult;
|
|
17
|
+
|
|
18
|
+
public class SentianceFeedbackModule extends AbstractSentianceModule {
|
|
19
|
+
public static final String NATIVE_MODULE_NAME = "SentianceFeedback";
|
|
20
|
+
|
|
21
|
+
private final FeedbackApi mFeedbackApi;
|
|
22
|
+
private final OnDeviceTypesConverter mOnDeviceTypesConverter;
|
|
23
|
+
|
|
24
|
+
public SentianceFeedbackModule(ReactApplicationContext reactApplicationContext,
|
|
25
|
+
Sentiance sentiance,
|
|
26
|
+
FeedbackApi feedbackApi,
|
|
27
|
+
SentianceSubscriptionsManager subscriptionsManager,
|
|
28
|
+
OnDeviceTypesConverter converter) {
|
|
29
|
+
super(reactApplicationContext, sentiance, subscriptionsManager);
|
|
30
|
+
this.mOnDeviceTypesConverter = converter;
|
|
31
|
+
this.mFeedbackApi = feedbackApi;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
protected void removeNativeListener(String eventName, int subscriptionId, Promise promise) {
|
|
36
|
+
// Implementation can be added here if needed
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
protected void addNativeListener(String eventName, int subscriptionId, Promise promise) {
|
|
41
|
+
// Implementation can be added here if needed
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
@ReactMethod
|
|
46
|
+
protected void addListener(String eventName) {
|
|
47
|
+
// Implementation can be added here if needed
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
@ReactMethod
|
|
52
|
+
protected void removeListeners(Integer count) {
|
|
53
|
+
// Implementation can be added here if needed
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@NonNull
|
|
57
|
+
@Override
|
|
58
|
+
public String getName() {
|
|
59
|
+
return NATIVE_MODULE_NAME;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@ReactMethod
|
|
63
|
+
public void submitOccupantRoleFeedback(final String transportId,
|
|
64
|
+
final String occupantFeedbackRole,
|
|
65
|
+
final Promise promise) {
|
|
66
|
+
if (rejectIfNotInitialized(promise)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
OccupantRoleFeedback occupantRoleFeedback = mOnDeviceTypesConverter.getOccupantRoleFeedbackFrom(occupantFeedbackRole);
|
|
71
|
+
if (occupantRoleFeedback == null) {
|
|
72
|
+
promise.reject(E_INVALID_FEEDBACK_TYPE, "Invalid feedback role");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
OccupantRoleFeedbackResult result = mFeedbackApi.submitOccupantRoleFeedback(transportId, occupantRoleFeedback);
|
|
77
|
+
promise.resolve(result.name());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -5,10 +5,14 @@ import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_LATITUDE
|
|
|
5
5
|
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_LONGITUDE;
|
|
6
6
|
import static com.sentiance.react.bridge.core.SentianceConverter.JS_KEY_TIMESTAMP;
|
|
7
7
|
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
|
|
8
10
|
import com.facebook.react.bridge.Arguments;
|
|
9
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
10
12
|
import com.facebook.react.bridge.WritableArray;
|
|
11
13
|
import com.facebook.react.bridge.WritableMap;
|
|
14
|
+
import com.sentiance.sdk.feedback.api.OccupantRoleFeedback;
|
|
15
|
+
import com.sentiance.sdk.feedback.api.OccupantRoleFeedbackResult;
|
|
12
16
|
import com.sentiance.sdk.ondevice.api.GeoLocation;
|
|
13
17
|
import com.sentiance.sdk.ondevice.api.Waypoint;
|
|
14
18
|
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
@@ -40,6 +44,9 @@ public class OnDeviceTypesConverter {
|
|
|
40
44
|
public static final String JS_KEY_HAS_UNLIMITED_SPEED_LIMIT = "hasUnlimitedSpeedLimit";
|
|
41
45
|
public static final String JS_KEY_IS_SPEED_LIMIT_INFO_SET = "isSpeedLimitInfoSet";
|
|
42
46
|
public static final String JS_KEY_TRANSPORT_TAGS = "transportTags";
|
|
47
|
+
public static final String JS_KEY_IS_SYNTHETIC = "isSynthetic";
|
|
48
|
+
public static final String JS_KEY_OCCUPANT_ROLE = "occupantRole";
|
|
49
|
+
|
|
43
50
|
|
|
44
51
|
private final TransportTagsConverter transportTagsConverter;
|
|
45
52
|
|
|
@@ -86,7 +93,7 @@ public class OnDeviceTypesConverter {
|
|
|
86
93
|
|
|
87
94
|
map.putString(JS_KEY_TYPE, event.getEventType().toString());
|
|
88
95
|
|
|
89
|
-
|
|
96
|
+
if (event instanceof StationaryEvent) {
|
|
90
97
|
addStationaryEventInfo(map, (StationaryEvent) event);
|
|
91
98
|
} else if (event instanceof TransportEvent) {
|
|
92
99
|
addTransportEventInfo(map, (TransportEvent) event);
|
|
@@ -117,6 +124,7 @@ public class OnDeviceTypesConverter {
|
|
|
117
124
|
private void addTransportEventInfo(WritableMap map, TransportEvent event) {
|
|
118
125
|
map.putString(JS_KEY_TRANSPORT_MODE, event.getTransportMode().toString());
|
|
119
126
|
map.putArray(JS_KEY_WAYPOINTS, convertWaypointList(event.getWaypoints()));
|
|
127
|
+
map.putString(JS_KEY_OCCUPANT_ROLE, event.getOccupantRole().name());
|
|
120
128
|
|
|
121
129
|
if (event.getDistanceInMeters() != null) {
|
|
122
130
|
map.putInt(JS_KEY_DISTANCE, event.getDistanceInMeters());
|
|
@@ -149,6 +157,7 @@ public class OnDeviceTypesConverter {
|
|
|
149
157
|
}
|
|
150
158
|
waypointMap.putBoolean(JS_KEY_IS_SPEED_LIMIT_INFO_SET, waypoint.isSpeedLimitInfoSet());
|
|
151
159
|
waypointMap.putBoolean(JS_KEY_HAS_UNLIMITED_SPEED_LIMIT, waypoint.hasUnlimitedSpeedLimit());
|
|
160
|
+
waypointMap.putBoolean(JS_KEY_IS_SYNTHETIC, waypoint.isSynthetic());
|
|
152
161
|
|
|
153
162
|
return waypointMap;
|
|
154
163
|
}
|
|
@@ -164,4 +173,13 @@ public class OnDeviceTypesConverter {
|
|
|
164
173
|
public Map<String, String> convertTransportTags(ReadableMap tags) {
|
|
165
174
|
return transportTagsConverter.convertFrom(tags);
|
|
166
175
|
}
|
|
176
|
+
|
|
177
|
+
@Nullable
|
|
178
|
+
public OccupantRoleFeedback getOccupantRoleFeedbackFrom(String value) {
|
|
179
|
+
try {
|
|
180
|
+
return OccupantRoleFeedback.valueOf(value.toUpperCase()); // Ensures case insensitivity
|
|
181
|
+
} catch (IllegalArgumentException | NullPointerException e) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
167
185
|
}
|
package/lib/feedback.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { NativeModules, Platform } = require("react-native");
|
|
2
|
+
const { varToString } = require("@sentiance-react-native/core/lib/utils");
|
|
3
|
+
|
|
4
|
+
const {SentianceFeedback, SentianceCore} = NativeModules;
|
|
5
|
+
|
|
6
|
+
const VALID_OCCUPANT_ROLE_TYPES = ["DRIVER", "PASSENGER"];
|
|
7
|
+
|
|
8
|
+
let feedbackModule = {};
|
|
9
|
+
if (Platform.OS === "android") {
|
|
10
|
+
if (!SentianceFeedback) {
|
|
11
|
+
const nativeModuleName = varToString({ SentianceFeedback });
|
|
12
|
+
console.error(`Could not locate the native ${nativeModuleName} module.
|
|
13
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`);
|
|
14
|
+
} else {
|
|
15
|
+
feedbackModule = SentianceFeedback;
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
if (!SentianceCore) {
|
|
19
|
+
const nativeModuleName = varToString({ SentianceCore });
|
|
20
|
+
console.error(`Could not locate the native ${nativeModuleName} module.
|
|
21
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`);
|
|
22
|
+
} else {
|
|
23
|
+
feedbackModule = SentianceCore;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const submitOccupantRoleFeedback = (transportId: string, occupantRoleFeedback: string) => {
|
|
28
|
+
if (!_isOccupantRoleFeedbackTypeValid(occupantRoleFeedback)) {
|
|
29
|
+
return Promise.reject(new Error("submitOccupantRoleFeedback was called with invalid feedback type: " + occupantRoleFeedback));
|
|
30
|
+
}
|
|
31
|
+
return feedbackModule.submitOccupantRoleFeedback(transportId, occupantRoleFeedback);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const _isOccupantRoleFeedbackTypeValid = (type: string): boolean => {
|
|
35
|
+
return VALID_OCCUPANT_ROLE_TYPES.includes(type);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
submitOccupantRoleFeedback
|
|
40
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare module "@sentiance-react-native/event-timeline" {
|
|
|
19
19
|
waypoints: Waypoint[];
|
|
20
20
|
distance?: number; // in meters
|
|
21
21
|
transportTags: TransportTags;
|
|
22
|
+
occupantRole: OccupantRole
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export interface GeoLocation {
|
|
@@ -86,6 +87,21 @@ declare module "@sentiance-react-native/event-timeline" {
|
|
|
86
87
|
| "BUS"
|
|
87
88
|
| "MOTORCYCLE";
|
|
88
89
|
|
|
90
|
+
export type OccupantRole =
|
|
91
|
+
| "DRIVER"
|
|
92
|
+
| "PASSENGER"
|
|
93
|
+
| "UNAVAILABLE";
|
|
94
|
+
|
|
95
|
+
export type OccupantRoleFeedback = Exclude<OccupantRole, "UNAVAILABLE">;
|
|
96
|
+
|
|
97
|
+
export type OccupantRoleFeedbackResult =
|
|
98
|
+
| "ACCEPTED"
|
|
99
|
+
| "TRANSPORT_TYPE_NOT_SUPPORTED"
|
|
100
|
+
| "TRANSPORT_NOT_FOUND"
|
|
101
|
+
| "TRANSPORT_NOT_YET_COMPLETE"
|
|
102
|
+
| "FEEDBACK_ALREADY_PROVIDED"
|
|
103
|
+
| "UNEXPECTED_ERROR";
|
|
104
|
+
|
|
89
105
|
export interface Waypoint {
|
|
90
106
|
latitude: number;
|
|
91
107
|
longitude: number;
|
|
@@ -95,10 +111,15 @@ declare module "@sentiance-react-native/event-timeline" {
|
|
|
95
111
|
speedLimitInMps?: number; // in meters per second
|
|
96
112
|
hasUnlimitedSpeedLimit: boolean;
|
|
97
113
|
isSpeedLimitInfoSet: boolean;
|
|
114
|
+
isSynthetic: boolean;
|
|
98
115
|
}
|
|
99
116
|
|
|
100
117
|
export type TransportTags = { [key: string]: string };
|
|
101
118
|
|
|
119
|
+
export interface SentianceFeedback {
|
|
120
|
+
submitOccupantRoleFeedback(transportId: string, occupantRoleFeedback: OccupantRoleFeedback): Promise<OccupantRoleFeedbackResult>;
|
|
121
|
+
}
|
|
122
|
+
|
|
102
123
|
export interface SentianceEventTimeline {
|
|
103
124
|
getTimelineUpdates(afterEpochTimeMs: number): Promise<Event[]>;
|
|
104
125
|
getTimelineEvents(fromEpochTimeMs: number, toEpochTimeMs: number): Promise<Event[]>;
|
|
@@ -139,6 +160,8 @@ declare module "@sentiance-react-native/event-timeline" {
|
|
|
139
160
|
* the 256 characters limit.
|
|
140
161
|
*/
|
|
141
162
|
setTransportTags(tags: TransportTags): Promise<void>;
|
|
163
|
+
|
|
164
|
+
sentianceFeedback: SentianceFeedback;
|
|
142
165
|
}
|
|
143
166
|
|
|
144
167
|
/**
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,9 @@ const { varToString } = require("@sentiance-react-native/core/lib/utils");
|
|
|
3
3
|
const SentianceEventEmitter = require("@sentiance-react-native/core/lib/SentianceEventEmitter");
|
|
4
4
|
const { createEventListener } = require("@sentiance-react-native/core/lib/SentianceEventListenerUtils");
|
|
5
5
|
const { TransportTaggingError, E_TRANSPORT_TAG_ERROR } = require("./errors/errors");
|
|
6
|
-
const { SentianceEventTimeline, SentianceCore
|
|
6
|
+
const { SentianceEventTimeline, SentianceCore} = NativeModules;
|
|
7
|
+
const sentianceFeedback = require("./feedback");
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
const TIMELINE_UPDATE_EVENT = "SENTIANCE_TIMELINE_UPDATE_EVENT";
|
|
9
11
|
|
|
@@ -61,8 +63,10 @@ module.exports = {
|
|
|
61
63
|
getTimelineEvents,
|
|
62
64
|
getTimelineEvent,
|
|
63
65
|
addTimelineUpdateListener,
|
|
64
|
-
setTransportTags
|
|
66
|
+
setTransportTags,
|
|
67
|
+
sentianceFeedback
|
|
65
68
|
};
|
|
69
|
+
|
|
66
70
|
module.exports.events = {
|
|
67
71
|
TIMELINE_UPDATE_EVENT
|
|
68
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentiance-react-native/event-timeline",
|
|
3
|
-
"version": "6.10.0
|
|
3
|
+
"version": "6.10.0",
|
|
4
4
|
"description": "The Sentiance Event Timeline library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"sentiance"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@sentiance-react-native/core": "6.10.0
|
|
17
|
+
"@sentiance-react-native/core": "6.10.0"
|
|
18
18
|
},
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "",
|