@sentiance-react-native/core 6.0.0-beta.9 → 6.0.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 +5 -20
- package/android/build.gradle +7 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceConverter.java +64 -75
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceEmitter.java +0 -5
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceHelper.java +0 -1
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceModule.java +10 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/SentianceUtils.java +18 -6
- package/ios/RNSentianceCore+Converter.h +6 -2
- package/ios/RNSentianceCore+Converter.m +49 -22
- package/ios/RNSentianceCore.m +2 -4
- package/ios/RNSentianceErrorCodes.h +2 -2
- package/ios/RNSentianceErrorCodes.m +2 -2
- package/ios/RNSentianceHelper.h +4 -2
- package/ios/RNSentianceHelper.m +9 -3
- package/lib/core.js +45 -51
- package/lib/index.d.ts +16 -8
- package/lib/index.js +36 -12
- package/lib/utils.js +3 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# Sentiance Core module for React Native
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
npm i @sentiance-react-native/core
|
|
5
|
-
```
|
|
3
|
+
## Demo Application
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Importing the package
|
|
10
|
-
|
|
11
|
-
You can import the entire contents of the package for use under a namespace of your choosing:
|
|
5
|
+
https://github.com/sentiance/sample-apps-react-native
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
import * as SentianceCore from "@sentiance-react-native/core";
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
or you can require specific functionality using named imports:
|
|
7
|
+
## Usage
|
|
18
8
|
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
enableDetections,
|
|
22
|
-
createUser
|
|
23
|
-
} from "@sentiance-react-native/core";
|
|
24
|
-
```
|
|
9
|
+
To use the core SDK module, please visit the corresponding [API reference page.](https://docs.sentiance.com/sdk/api-reference/react-native/core)
|
package/android/build.gradle
CHANGED
|
@@ -2,6 +2,13 @@ plugins {
|
|
|
2
2
|
id "com.android.library"
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
android {
|
|
6
|
+
compileOptions {
|
|
7
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
8
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
apply from: "$project.projectDir/package-json-reader.gradle"
|
|
6
13
|
apply from: "$project.projectDir/sentiance-version-finder.gradle"
|
|
7
14
|
|
|
@@ -6,6 +6,7 @@ import com.facebook.react.bridge.Arguments;
|
|
|
6
6
|
import com.facebook.react.bridge.ReadableMap;
|
|
7
7
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
8
8
|
import com.facebook.react.bridge.WritableMap;
|
|
9
|
+
import com.sentiance.react.bridge.core.utils.SentianceUtils;
|
|
9
10
|
import com.sentiance.sdk.DetectionStatus;
|
|
10
11
|
import com.sentiance.sdk.DisableDetectionsResult;
|
|
11
12
|
import com.sentiance.sdk.EnableDetectionsError;
|
|
@@ -42,7 +43,7 @@ public class SentianceConverter {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
public static Map<String, String> convertReadableMapToMap(ReadableMap inputMap) {
|
|
45
|
-
Map<String, String> map = new HashMap
|
|
46
|
+
Map<String, String> map = new HashMap<>();
|
|
46
47
|
ReadableMapKeySetIterator iterator = inputMap.keySetIterator();
|
|
47
48
|
while (iterator.hasNextKey()) {
|
|
48
49
|
String key = iterator.nextKey();
|
|
@@ -111,7 +112,7 @@ public class SentianceConverter {
|
|
|
111
112
|
WritableMap map = Arguments.createMap();
|
|
112
113
|
try {
|
|
113
114
|
map.putString("tokenId", token.getTokenId());
|
|
114
|
-
map.putString("expiryDate",
|
|
115
|
+
map.putString("expiryDate", SentianceUtils.toDateString(token.getExpiryDate()));
|
|
115
116
|
} catch (Exception ignored) {
|
|
116
117
|
}
|
|
117
118
|
|
|
@@ -119,98 +120,88 @@ public class SentianceConverter {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
public static WritableMap convertUserCreationResult(UserCreationResult result) {
|
|
122
|
-
WritableMap map = Arguments.createMap();
|
|
123
123
|
UserInfo userInfo = result.getUserInfo();
|
|
124
|
-
|
|
125
|
-
Token token = userInfo.getToken();
|
|
126
|
-
map.putString("userId", userInfo.getUserId());
|
|
127
|
-
map.putString("tokenId", token.getTokenId());
|
|
128
|
-
map.putString("tokenExpiryDate", token.getExpiryDate().toString());
|
|
129
|
-
map.putBoolean("isTokenExpired", token.isExpired());
|
|
130
|
-
} catch (Exception ignored) {
|
|
131
|
-
}
|
|
124
|
+
Token token = userInfo.getToken();
|
|
132
125
|
|
|
133
|
-
|
|
126
|
+
WritableMap userInfoMap = Arguments.createMap();
|
|
127
|
+
userInfoMap.putString("userId", userInfo.getUserId());
|
|
128
|
+
userInfoMap.putString("tokenId", token.getTokenId());
|
|
129
|
+
userInfoMap.putString("tokenExpiryDate", SentianceUtils.toDateString(token.getExpiryDate()));
|
|
130
|
+
userInfoMap.putBoolean("isTokenExpired", token.isExpired());
|
|
131
|
+
|
|
132
|
+
WritableMap userCreationResult = Arguments.createMap();
|
|
133
|
+
userCreationResult.putMap("userInfo", userInfoMap);
|
|
134
|
+
return userCreationResult;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
public static WritableMap convertUserLinkingResult(UserLinkingResult result) {
|
|
137
|
-
WritableMap map = Arguments.createMap();
|
|
138
138
|
UserInfo userInfo = result.getUserInfo();
|
|
139
|
-
|
|
140
|
-
Token token = userInfo.getToken();
|
|
141
|
-
map.putString("userId", userInfo.getUserId());
|
|
142
|
-
map.putString("tokenId", token.getTokenId());
|
|
143
|
-
map.putString("tokenExpiryDate", token.getExpiryDate().toString());
|
|
144
|
-
map.putBoolean("isTokenExpired", token.isExpired());
|
|
145
|
-
} catch (Exception ignored) {
|
|
146
|
-
}
|
|
139
|
+
Token token = userInfo.getToken();
|
|
147
140
|
|
|
148
|
-
|
|
141
|
+
WritableMap userInfoMap = Arguments.createMap();
|
|
142
|
+
userInfoMap.putString("userId", userInfo.getUserId());
|
|
143
|
+
userInfoMap.putString("tokenId", token.getTokenId());
|
|
144
|
+
userInfoMap.putString("tokenExpiryDate", SentianceUtils.toDateString(token.getExpiryDate()));
|
|
145
|
+
userInfoMap.putBoolean("isTokenExpired", token.isExpired());
|
|
146
|
+
|
|
147
|
+
WritableMap userLinkingResult = Arguments.createMap();
|
|
148
|
+
userLinkingResult.putMap("userInfo", userInfoMap);
|
|
149
|
+
return userLinkingResult;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
public static WritableMap convertInstallId(String installId) {
|
|
152
153
|
WritableMap map = Arguments.createMap();
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} catch (Exception ignored) {
|
|
156
|
-
}
|
|
154
|
+
map.putString("installId", installId);
|
|
155
|
+
|
|
157
156
|
return map;
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
public static WritableMap convertSdkStatus(SdkStatus status) {
|
|
161
160
|
WritableMap map = Arguments.createMap();
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} catch (Exception ignored) {
|
|
185
|
-
}
|
|
161
|
+
map.putString("startStatus", status.startStatus.name());
|
|
162
|
+
map.putString("detectionStatus", status.detectionStatus.name());
|
|
163
|
+
map.putBoolean("canDetect", status.canDetect);
|
|
164
|
+
map.putBoolean("isRemoteEnabled", status.isRemoteEnabled);
|
|
165
|
+
map.putString("locationPermission", status.locationPermission.toString());
|
|
166
|
+
map.putBoolean("isActivityRecognitionPermGranted", status.isActivityRecognitionPermGranted);
|
|
167
|
+
map.putString("locationSetting", status.locationSetting.name());
|
|
168
|
+
map.putBoolean("isAirplaneModeEnabled", status.isAirplaneModeEnabled);
|
|
169
|
+
map.putBoolean("isLocationAvailable", status.isLocationAvailable);
|
|
170
|
+
map.putBoolean("isAccelPresent", status.isAccelPresent);
|
|
171
|
+
map.putBoolean("isGyroPresent", status.isGyroPresent);
|
|
172
|
+
map.putBoolean("isGpsPresent", status.isGpsPresent);
|
|
173
|
+
map.putBoolean("isGooglePlayServicesMissing", status.isGooglePlayServicesMissing);
|
|
174
|
+
map.putBoolean("isBatteryOptimizationEnabled", status.isBatteryOptimizationEnabled);
|
|
175
|
+
map.putBoolean("isBatterySavingEnabled", status.isBatterySavingEnabled);
|
|
176
|
+
map.putBoolean("isBackgroundProcessingRestricted", status.isBackgroundProcessingRestricted);
|
|
177
|
+
map.putBoolean("isPreciseLocationAuthorizationGranted", status.isPreciseLocationPermGranted);
|
|
178
|
+
map.putBoolean("isSchedulingExactAlarmsPermitted", status.isSchedulingExactAlarmsPermitted);
|
|
179
|
+
map.putString("wifiQuotaStatus", status.wifiQuotaStatus.toString());
|
|
180
|
+
map.putString("mobileQuotaStatus", status.mobileQuotaStatus.toString());
|
|
181
|
+
map.putString("diskQuotaStatus", status.diskQuotaStatus.toString());
|
|
182
|
+
map.putBoolean("userExists", status.userExists);
|
|
186
183
|
|
|
187
184
|
return map;
|
|
188
185
|
}
|
|
189
186
|
|
|
190
187
|
public static WritableMap convertUserActivity(UserActivity activity) {
|
|
191
188
|
WritableMap map = Arguments.createMap();
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
//Stationary Info
|
|
204
|
-
if (activity.getStationaryInfo() != null) {
|
|
205
|
-
WritableMap stationaryInfoMap = Arguments.createMap();
|
|
206
|
-
if (activity.getStationaryInfo().getLocation() != null) {
|
|
207
|
-
WritableMap locationMap = convertLocation(activity.getStationaryInfo().getLocation());
|
|
208
|
-
stationaryInfoMap.putMap("location", locationMap);
|
|
209
|
-
}
|
|
210
|
-
map.putMap("stationaryInfo", stationaryInfoMap);
|
|
211
|
-
}
|
|
189
|
+
map.putString("type", convertUserActivityType(activity.getActivityType()));
|
|
190
|
+
|
|
191
|
+
//Trip Info
|
|
192
|
+
if (activity.getTripInfo() != null) {
|
|
193
|
+
WritableMap tripInfoMap = Arguments.createMap();
|
|
194
|
+
String tripType = convertTripType(activity.getTripInfo().getTripType());
|
|
195
|
+
tripInfoMap.putString("type", tripType);
|
|
196
|
+
map.putMap("tripInfo", tripInfoMap);
|
|
197
|
+
}
|
|
212
198
|
|
|
213
|
-
|
|
199
|
+
//Stationary Info
|
|
200
|
+
if (activity.getStationaryInfo() != null) {
|
|
201
|
+
WritableMap stationaryInfoMap = Arguments.createMap();
|
|
202
|
+
WritableMap locationMap = convertLocation(activity.getStationaryInfo().getLocation());
|
|
203
|
+
stationaryInfoMap.putMap("location", locationMap);
|
|
204
|
+
map.putMap("stationaryInfo", stationaryInfoMap);
|
|
214
205
|
}
|
|
215
206
|
|
|
216
207
|
return map;
|
|
@@ -336,10 +327,8 @@ public class SentianceConverter {
|
|
|
336
327
|
public static String stringifyStopTripError(StopTripError error) {
|
|
337
328
|
StopTripFailureReason reason = error.getReason();
|
|
338
329
|
String details = "";
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
details = "There is no ongoing external trip.";
|
|
342
|
-
break;
|
|
330
|
+
if (reason == StopTripFailureReason.NO_ONGOING_TRIP) {
|
|
331
|
+
details = "There is no ongoing external trip.";
|
|
343
332
|
}
|
|
344
333
|
return String.format("Reason: %s - %s", reason.name(), details);
|
|
345
334
|
}
|
|
@@ -15,7 +15,6 @@ public class SentianceEmitter extends AbstractSentianceEmitter {
|
|
|
15
15
|
private static final String USER_LINK = "SENTIANCE_USER_LINK_EVENT";
|
|
16
16
|
private static final String STATUS_UPDATE = "SENTIANCE_STATUS_UPDATE_EVENT";
|
|
17
17
|
private static final String USER_ACTIVITY_UPDATE = "SENTIANCE_USER_ACTIVITY_UPDATE_EVENT";
|
|
18
|
-
private static final String ON_DETECTIONS_ENABLED = "SENTIANCE_ON_DETECTIONS_ENABLED_EVENT";
|
|
19
18
|
private static final String ON_TRIP_TIMED_OUT = "SENTIANCE_ON_TRIP_TIMED_OUT_EVENT";
|
|
20
19
|
|
|
21
20
|
public SentianceEmitter(Context context) {
|
|
@@ -34,10 +33,6 @@ public class SentianceEmitter extends AbstractSentianceEmitter {
|
|
|
34
33
|
sendEvent(USER_ACTIVITY_UPDATE, convertUserActivity(userActivity));
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
void sendOnDetectionsEnabledEvent(SdkStatus status) {
|
|
38
|
-
sendEvent(ON_DETECTIONS_ENABLED, convertSdkStatus(status));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
36
|
void sendOnTripTimedOutEvent() {
|
|
42
37
|
sendEvent(ON_TRIP_TIMED_OUT, Arguments.createMap());
|
|
43
38
|
}
|
|
@@ -142,7 +142,6 @@ public class SentianceHelper {
|
|
|
142
142
|
.addOnCompleteListener(pendingOperation -> {
|
|
143
143
|
if (pendingOperation.isSuccessful()) {
|
|
144
144
|
EnableDetectionsResult result = pendingOperation.getResult();
|
|
145
|
-
emitter.sendOnDetectionsEnabledEvent(result.getSdkStatus());
|
|
146
145
|
if (promise != null) {
|
|
147
146
|
promise.resolve(SentianceConverter.convertEnableDetectionsResult(result));
|
|
148
147
|
}
|
|
@@ -525,5 +525,15 @@ public class SentianceModule extends AbstractSentianceModule {
|
|
|
525
525
|
.setTripTimeoutListener(emitter::sendOnTripTimedOutEvent);
|
|
526
526
|
promise.resolve(null);
|
|
527
527
|
}
|
|
528
|
+
|
|
529
|
+
@ReactMethod
|
|
530
|
+
public void addListener(String eventName) {
|
|
531
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
@ReactMethod
|
|
535
|
+
public void removeListeners(Integer count) {
|
|
536
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
537
|
+
}
|
|
528
538
|
}
|
|
529
539
|
|
|
@@ -10,9 +10,13 @@ import android.content.pm.ApplicationInfo;
|
|
|
10
10
|
import android.content.pm.PackageManager;
|
|
11
11
|
import android.os.Build;
|
|
12
12
|
|
|
13
|
+
import androidx.annotation.NonNull;
|
|
13
14
|
import androidx.core.app.NotificationCompat;
|
|
14
15
|
|
|
15
16
|
import java.lang.ref.WeakReference;
|
|
17
|
+
import java.text.SimpleDateFormat;
|
|
18
|
+
import java.util.Date;
|
|
19
|
+
import java.util.Locale;
|
|
16
20
|
|
|
17
21
|
public class SentianceUtils {
|
|
18
22
|
|
|
@@ -20,12 +24,14 @@ public class SentianceUtils {
|
|
|
20
24
|
public static final String SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_NAME = "Sentiance";
|
|
21
25
|
public static final String SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_ID = "Sentiance";
|
|
22
26
|
|
|
23
|
-
public static final String SENTIANCE_NOTIFICATION_ID = "com.sentiance.react.bridge.notification_id";
|
|
24
|
-
public static final String SENTIANCE_NOTIFICATION_TITLE = "com.sentiance.react.bridge.notification_title";
|
|
25
|
-
public static final String SENTIANCE_NOTIFICATION_ICON = "com.sentiance.react.bridge.notification_icon";
|
|
26
|
-
public static final String SENTIANCE_NOTIFICATION_CHANNEL_ID = "com.sentiance.react.bridge.channel_id";
|
|
27
|
-
public static final String SENTIANCE_NOTIFICATION_CHANNEL_NAME = "com.sentiance.react.bridge.notification_channel_name";
|
|
28
|
-
public static final String SENTIANCE_NOTIFICATION_NOTIFICATION_TEXT = "com.sentiance.react.bridge.notification_text";
|
|
27
|
+
public static final String SENTIANCE_NOTIFICATION_ID = "com.sentiance.react.bridge.core.notification_id";
|
|
28
|
+
public static final String SENTIANCE_NOTIFICATION_TITLE = "com.sentiance.react.bridge.core.notification_title";
|
|
29
|
+
public static final String SENTIANCE_NOTIFICATION_ICON = "com.sentiance.react.bridge.core.notification_icon";
|
|
30
|
+
public static final String SENTIANCE_NOTIFICATION_CHANNEL_ID = "com.sentiance.react.bridge.core.channel_id";
|
|
31
|
+
public static final String SENTIANCE_NOTIFICATION_CHANNEL_NAME = "com.sentiance.react.bridge.core.notification_channel_name";
|
|
32
|
+
public static final String SENTIANCE_NOTIFICATION_NOTIFICATION_TEXT = "com.sentiance.react.bridge.core.notification_text";
|
|
33
|
+
|
|
34
|
+
private static final String DATE_TIME_PATTERN_M = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; // ISO_8601
|
|
29
35
|
|
|
30
36
|
public static Notification createNotificationFromManifestData(WeakReference<Context> weakContext,
|
|
31
37
|
String title, String message) {
|
|
@@ -100,6 +106,12 @@ public class SentianceUtils {
|
|
|
100
106
|
return SENTIANCE_FALLBACK_NOTIFICATION_ID;
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
@NonNull
|
|
110
|
+
public static String toDateString(Date date) {
|
|
111
|
+
SimpleDateFormat formatter = new SimpleDateFormat(DATE_TIME_PATTERN_M, Locale.ENGLISH);
|
|
112
|
+
return formatter.format(date.getTime());
|
|
113
|
+
}
|
|
114
|
+
|
|
103
115
|
private static Notification createNotification(WeakReference<Context> weakContext, PendingIntent pendingIntent,
|
|
104
116
|
String title, String message, String channelName, String channelId,
|
|
105
117
|
Integer icon) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// RNSentianceCore+Converter.h
|
|
3
|
+
// RNSentianceCore
|
|
4
4
|
//
|
|
5
5
|
// Created by Sebouh Aguehian on 10/10/2021.
|
|
6
6
|
// Copyright © 2021 Facebook. All rights reserved.
|
|
7
7
|
//
|
|
8
8
|
#import "RNSentianceCore.h"
|
|
9
9
|
|
|
10
|
+
typedef NS_ENUM(NSInteger, UIBackgroundRefreshStatus);
|
|
11
|
+
|
|
10
12
|
@interface RNSentianceCore (Converter)
|
|
11
13
|
|
|
12
14
|
- (NSDictionary*) convertUserContextToDict:(SENTUserContext*) userContext;
|
|
@@ -43,4 +45,6 @@
|
|
|
43
45
|
- (NSDictionary *)convertDisableDetectionsResult:(SENTDisableDetectionsResult *)disableDetectionsResult;
|
|
44
46
|
- (NSString *)stringifyDisableDetectionsError:(SENTDisableDetectionsError *)disableDetectionsError;
|
|
45
47
|
- (NSString *)stringifyUserContextError:(SENTRequestUserContextError *)userContextError;
|
|
48
|
+
- (NSString*)convertBackgroundRefreshStatus:(UIBackgroundRefreshStatus)backgroundRefreshStatus;
|
|
49
|
+
|
|
46
50
|
@end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// RNSentianceCore+Converter.m
|
|
3
|
+
// RNSentianceCore
|
|
4
4
|
//
|
|
5
5
|
// Created by Sebouh Aguehian on 10/10/2021.
|
|
6
6
|
// Copyright © 2021 Facebook. All rights reserved.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
#import "RNSentianceCore+Converter.h"
|
|
10
|
+
@import UIKit.UIApplication;
|
|
10
11
|
|
|
11
12
|
@interface RNSentianceCore (Private)
|
|
12
13
|
|
|
@@ -25,6 +26,8 @@
|
|
|
25
26
|
- (nullable NSString*)convertSegmentTypeToString:(SENTSegmentType)type;
|
|
26
27
|
- (NSMutableDictionary*)convertSegmentAttributesToDict:(NSArray<SENTAttribute *>*)attributes;
|
|
27
28
|
- (nullable NSDictionary*)convertSegment:(SENTSegment*)segment;
|
|
29
|
+
- (NSString*)convertBackgroundRefreshStatus:(UIBackgroundRefreshStatus)backgroundRefreshStatus;
|
|
30
|
+
|
|
28
31
|
@end
|
|
29
32
|
|
|
30
33
|
@implementation RNSentianceCore (Converter)
|
|
@@ -561,7 +564,9 @@
|
|
|
561
564
|
@"isGpsPresent":@(status.isGpsPresent),
|
|
562
565
|
@"wifiQuotaStatus":[self convertQuotaStatusToString:status.wifiQuotaStatus],
|
|
563
566
|
@"mobileQuotaStatus":[self convertQuotaStatusToString:status.mobileQuotaStatus],
|
|
564
|
-
@"diskQuotaStatus":[self convertQuotaStatusToString:status.diskQuotaStatus]
|
|
567
|
+
@"diskQuotaStatus":[self convertQuotaStatusToString:status.diskQuotaStatus],
|
|
568
|
+
@"userExists":@(status.userExists),
|
|
569
|
+
@"backgroundRefreshStatus":[self convertBackgroundRefreshStatus:status.backgroundRefreshStatus]
|
|
565
570
|
};
|
|
566
571
|
|
|
567
572
|
return dict;
|
|
@@ -621,13 +626,13 @@
|
|
|
621
626
|
|
|
622
627
|
- (NSString*)convertInitStateToString:(SENTSDKInitState) state {
|
|
623
628
|
switch (state) {
|
|
624
|
-
case
|
|
629
|
+
case SENTSDKInitStateNotInitialized:
|
|
625
630
|
return @"NOT_INITIALIZED";
|
|
626
|
-
case
|
|
631
|
+
case SENTSDKInitStateInProgress:
|
|
627
632
|
return @"INIT_IN_PROGRESS";
|
|
628
|
-
case
|
|
633
|
+
case SENTSDKInitStateInitialized:
|
|
629
634
|
return @"INITIALIZED";
|
|
630
|
-
case
|
|
635
|
+
case SENTSDKInitStateResetting:
|
|
631
636
|
return @"RESETTING";
|
|
632
637
|
default:
|
|
633
638
|
return @"UNRECOGNIZED_STATE";
|
|
@@ -680,14 +685,18 @@
|
|
|
680
685
|
}
|
|
681
686
|
|
|
682
687
|
- (NSDictionary *)convertUserCreationResult:(SENTUserCreationResult *)userCreationResult {
|
|
683
|
-
NSMutableDictionary *
|
|
688
|
+
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
|
|
684
689
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
dict[@"tokenExpiryDate"] = userCreationResult.userInfo.token.expiryDate;
|
|
688
|
-
dict[@"isTokenExpired"] = @(NO);
|
|
690
|
+
userInfo[@"userId"] = userCreationResult.userInfo.userId;
|
|
691
|
+
userInfo[@"tokenId"] = userCreationResult.userInfo.token.tokenId;
|
|
689
692
|
|
|
690
|
-
|
|
693
|
+
NSString *tokenExpiryDate = [[SENTDate alloc]initWithNSDate: userCreationResult.userInfo.token.expiryDate].description;
|
|
694
|
+
userInfo[@"tokenExpiryDate"] = tokenExpiryDate;
|
|
695
|
+
userInfo[@"isTokenExpired"] = @(userCreationResult.userInfo.token.isExpired);
|
|
696
|
+
|
|
697
|
+
NSMutableDictionary *userCreationResultDict = [[NSMutableDictionary alloc] init];
|
|
698
|
+
userCreationResultDict[@"userInfo"] = userInfo;
|
|
699
|
+
return userCreationResultDict;
|
|
691
700
|
}
|
|
692
701
|
|
|
693
702
|
- (NSString *)stringifyUserCreationError:(SENTUserCreationError *)userCreationError {
|
|
@@ -747,14 +756,18 @@
|
|
|
747
756
|
}
|
|
748
757
|
|
|
749
758
|
- (NSDictionary *)convertUserLinkingResult:(SENTUserLinkingResult *)userLinkingResult {
|
|
750
|
-
NSMutableDictionary *
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
759
|
+
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
|
|
760
|
+
|
|
761
|
+
userInfo[@"userId"] = userLinkingResult.userInfo.userId;
|
|
762
|
+
userInfo[@"tokenId"] = userLinkingResult.userInfo.token.tokenId;
|
|
763
|
+
|
|
764
|
+
NSString *tokenExpiryDate = [[SENTDate alloc]initWithNSDate: userLinkingResult.userInfo.token.expiryDate].description;
|
|
765
|
+
userInfo[@"tokenExpiryDate"] = tokenExpiryDate;
|
|
766
|
+
userInfo[@"isTokenExpired"] = @(userLinkingResult.userInfo.token.isExpired);
|
|
756
767
|
|
|
757
|
-
|
|
768
|
+
NSMutableDictionary *userLinkingResultDict = [[NSMutableDictionary alloc] init];
|
|
769
|
+
userLinkingResultDict[@"userInfo"] = userInfo;
|
|
770
|
+
return userLinkingResultDict;
|
|
758
771
|
}
|
|
759
772
|
|
|
760
773
|
- (NSString *)stringifyUserLinkingError:(SENTUserLinkingError *)userLinkingError {
|
|
@@ -867,8 +880,10 @@
|
|
|
867
880
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
868
881
|
|
|
869
882
|
dict[@"tokenId"] = userAccessTokenResult.token.tokenId;
|
|
870
|
-
|
|
871
|
-
|
|
883
|
+
|
|
884
|
+
NSString *tokenExpiryDate = [[SENTDate alloc]initWithNSDate: userAccessTokenResult.token.expiryDate].description;
|
|
885
|
+
dict[@"expiryDate"] = tokenExpiryDate;
|
|
886
|
+
|
|
872
887
|
return dict;
|
|
873
888
|
}
|
|
874
889
|
|
|
@@ -983,4 +998,16 @@
|
|
|
983
998
|
}
|
|
984
999
|
return [NSString stringWithFormat:@"Reason: %@ - %@", reason, details];
|
|
985
1000
|
}
|
|
1001
|
+
|
|
1002
|
+
- (NSString *)convertBackgroundRefreshStatus:(UIBackgroundRefreshStatus)backgroundRefreshStatus {
|
|
1003
|
+
if (backgroundRefreshStatus == UIBackgroundRefreshStatusAvailable) {
|
|
1004
|
+
return @"AVAILABLE";
|
|
1005
|
+
} else if(backgroundRefreshStatus == UIBackgroundRefreshStatusDenied) {
|
|
1006
|
+
return @"DENIED";
|
|
1007
|
+
} else if(backgroundRefreshStatus == UIBackgroundRefreshStatusRestricted) {
|
|
1008
|
+
return @"RESTRICTED";
|
|
1009
|
+
}
|
|
1010
|
+
return @"";
|
|
1011
|
+
}
|
|
1012
|
+
|
|
986
1013
|
@end
|
package/ios/RNSentianceCore.m
CHANGED
|
@@ -33,7 +33,7 @@ RCT_EXPORT_MODULE(SentianceCore)
|
|
|
33
33
|
|
|
34
34
|
- (NSArray<NSString *> *)supportedEvents
|
|
35
35
|
{
|
|
36
|
-
return @[SdkStatusUpdateEvent, TripTimeoutEvent, UserLinkEvent, UserActivityUpdateEvent, VehicleCrashEvent, UserLinkEvent, UserContextUpdateEvent
|
|
36
|
+
return @[SdkStatusUpdateEvent, TripTimeoutEvent, UserLinkEvent, UserActivityUpdateEvent, VehicleCrashEvent, UserLinkEvent, UserContextUpdateEvent];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Will be called when this module's first listener is added.
|
|
@@ -313,8 +313,6 @@ RCT_EXPORT_METHOD(disableDetections:(RCTPromiseResolveBlock)resolve rejecter:(RC
|
|
|
313
313
|
|
|
314
314
|
RCT_EXPORT_METHOD(getInitState:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
315
315
|
{
|
|
316
|
-
REJECT_IF_SDK_NOT_INITIALIZED(reject);
|
|
317
|
-
|
|
318
316
|
@try {
|
|
319
317
|
SENTSDKInitState initState = [[Sentiance sharedInstance] getInitState];
|
|
320
318
|
resolve([self convertInitStateToString:initState]);
|
|
@@ -1030,7 +1028,7 @@ RCT_EXPORT_METHOD(listenTripTimeout:(RCTPromiseResolveBlock)resolve rejecter:(RC
|
|
|
1030
1028
|
}
|
|
1031
1029
|
|
|
1032
1030
|
- (BOOL)isSdkNotInitialized {
|
|
1033
|
-
return [Sentiance sharedInstance].initState !=
|
|
1031
|
+
return [Sentiance sharedInstance].initState != SENTSDKInitStateInitialized;
|
|
1034
1032
|
}
|
|
1035
1033
|
|
|
1036
1034
|
@end
|
package/ios/RNSentianceHelper.h
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// RNSentianceHelper.h
|
|
3
|
+
// RNSentianceCore
|
|
4
4
|
//
|
|
5
5
|
// Created by Hassan Shakeel on 10/05/2022.
|
|
6
6
|
//
|
|
@@ -27,5 +27,7 @@
|
|
|
27
27
|
launchOptions:(nullable NSDictionary *)launchOptions
|
|
28
28
|
NS_SWIFT_NAME(initializeSDK(platformUrl:isAppSessionDataCollectionAllowed:launchOptions:));
|
|
29
29
|
|
|
30
|
+
- (void)enableDetectionsIfUserExists;
|
|
31
|
+
|
|
30
32
|
@end
|
|
31
33
|
|
package/ios/RNSentianceHelper.m
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// RNSentianceHelper.m
|
|
3
|
+
// RNSentianceCore
|
|
4
4
|
//
|
|
5
5
|
// Created by Hassan Shakeel on 10/05/2022.
|
|
6
6
|
//
|
|
@@ -28,11 +28,17 @@
|
|
|
28
28
|
- (SENTInitializationResult *)initializeSDKWithPlatformUrl:(NSString *)platformUrl
|
|
29
29
|
isAppSessionDataCollectionAllowed:(BOOL *)isAppSessionDataCollectionAllowed
|
|
30
30
|
launchOptions:(nullable NSDictionary *)launchOptions {
|
|
31
|
-
SENTOptions *options = [[SENTOptions alloc]
|
|
31
|
+
SENTOptions *options = [[SENTOptions alloc] initFor:SENTOptionsInitPurposeAppLaunch];
|
|
32
32
|
options.platformUrl = platformUrl;
|
|
33
33
|
options.isAppSessionDataCollectionAllowed = isAppSessionDataCollectionAllowed;
|
|
34
34
|
return [[Sentiance sharedInstance] initializeWithOptions:options launchOptions:launchOptions];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
- (void)enableDetectionsIfUserExists {
|
|
38
|
+
if ([Sentiance sharedInstance].userExists) {
|
|
39
|
+
[[Sentiance sharedInstance] enableDetectionsWithCompletionHandler:nil];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
@end
|
|
38
44
|
|
package/lib/core.js
CHANGED
|
@@ -4,61 +4,55 @@ const {SentianceCore} = NativeModules;
|
|
|
4
4
|
|
|
5
5
|
const SDK_STATUS_UPDATE_EVENT = "SENTIANCE_STATUS_UPDATE_EVENT";
|
|
6
6
|
const SDK_USER_LINK_EVENT = "SENTIANCE_USER_LINK_EVENT";
|
|
7
|
-
const SDK_ON_DETECTIONS_ENABLED_EVENT = "SENTIANCE_ON_DETECTIONS_ENABLED_EVENT";
|
|
8
7
|
const SDK_USER_ACTIVITY_UPDATE_EVENT = "SENTIANCE_USER_ACTIVITY_UPDATE_EVENT";
|
|
9
8
|
const SDK_ON_TRIP_TIMED_OUT_EVENT = "SENTIANCE_ON_TRIP_TIMED_OUT_EVENT";
|
|
10
9
|
|
|
10
|
+
let coreModule = {};
|
|
11
11
|
if (!SentianceCore) {
|
|
12
12
|
const nativeModuleName = varToString({SentianceCore});
|
|
13
|
-
|
|
14
|
-
Make sure that your native code is properly linked, and that the module name you specified is correct
|
|
13
|
+
console.error(`Could not locate the native ${nativeModuleName} module.
|
|
14
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`);
|
|
15
|
+
} else {
|
|
16
|
+
const SENTIANCE_EMITTER = new NativeEventEmitter(SentianceCore);
|
|
17
|
+
|
|
18
|
+
const _addSdkStatusUpdateListener = async (onSdkStatusUpdated) => {
|
|
19
|
+
await SentianceCore.listenSdkStatusUpdates();
|
|
20
|
+
return SENTIANCE_EMITTER.addListener(SDK_STATUS_UPDATE_EVENT, (sdkStatus) => {
|
|
21
|
+
onSdkStatusUpdated(sdkStatus);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const _addUserLinkListener = async (linker) => {
|
|
26
|
+
const subscription = SENTIANCE_EMITTER.addListener(SDK_USER_LINK_EVENT, async (data) => {
|
|
27
|
+
const {installId} = data;
|
|
28
|
+
const linkingResult = await linker(installId);
|
|
29
|
+
if (typeof linkingResult != "boolean") {
|
|
30
|
+
console.error('Expected linker result of type boolean, got: ' + typeof linkingResult);
|
|
31
|
+
SentianceCore.userLinkCallback(false);
|
|
32
|
+
} else {
|
|
33
|
+
SentianceCore.userLinkCallback(linkingResult);
|
|
34
|
+
}
|
|
35
|
+
subscription.remove();
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const _addSdkUserActivityUpdateListener = async (onUserActivityUpdated) => {
|
|
40
|
+
await SentianceCore.listenUserActivityUpdates();
|
|
41
|
+
return SENTIANCE_EMITTER.addListener(SDK_USER_ACTIVITY_UPDATE_EVENT, (data) => {
|
|
42
|
+
onUserActivityUpdated(data);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const _addTripTimeoutListener = async (onTripTimedOut) => {
|
|
47
|
+
await SentianceCore.listenTripTimeout();
|
|
48
|
+
return SENTIANCE_EMITTER.addListener(SDK_ON_TRIP_TIMED_OUT_EVENT, onTripTimedOut);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
SentianceCore._addSdkStatusUpdateListener = _addSdkStatusUpdateListener;
|
|
52
|
+
SentianceCore._addUserLinkListener = _addUserLinkListener;
|
|
53
|
+
SentianceCore._addSdkUserActivityUpdateListener = _addSdkUserActivityUpdateListener;
|
|
54
|
+
SentianceCore._addTripTimeoutListener = _addTripTimeoutListener;
|
|
55
|
+
coreModule = SentianceCore;
|
|
15
56
|
}
|
|
16
57
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const _addSdkStatusUpdateListener = async (onSdkStatusUpdated) => {
|
|
20
|
-
await SentianceCore.listenSdkStatusUpdates();
|
|
21
|
-
return SENTIANCE_EMITTER.addListener(SDK_STATUS_UPDATE_EVENT, (sdkStatus) => {
|
|
22
|
-
onSdkStatusUpdated(sdkStatus);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const _addUserLinkListener = async (linker) => {
|
|
27
|
-
const subscription = SENTIANCE_EMITTER.addListener(SDK_USER_LINK_EVENT, async (data) => {
|
|
28
|
-
const {installId} = data;
|
|
29
|
-
const linkingResult = await linker(installId);
|
|
30
|
-
if (typeof linkingResult != "boolean") {
|
|
31
|
-
console.error('Expected linker result of type boolean, got: ' + typeof linkingResult);
|
|
32
|
-
SentianceCore.userLinkCallback(false);
|
|
33
|
-
} else {
|
|
34
|
-
SentianceCore.userLinkCallback(linkingResult);
|
|
35
|
-
}
|
|
36
|
-
subscription.remove();
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const _addOnDetectionsEnabledListener = async (onDetectionsEnabled) => {
|
|
41
|
-
return SENTIANCE_EMITTER.addListener(SDK_ON_DETECTIONS_ENABLED_EVENT, (data) => {
|
|
42
|
-
onDetectionsEnabled(data);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const _addSdkUserActivityUpdateListener = async (onUserActivityUpdated) => {
|
|
47
|
-
await SentianceCore.listenUserActivityUpdates();
|
|
48
|
-
return SENTIANCE_EMITTER.addListener(SDK_USER_ACTIVITY_UPDATE_EVENT, (data) => {
|
|
49
|
-
onUserActivityUpdated(data);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const _addTripTimeoutListener = async (onTripTimedOut) => {
|
|
54
|
-
await SentianceCore.listenTripTimeout();
|
|
55
|
-
return SENTIANCE_EMITTER.addListener(SDK_ON_TRIP_TIMED_OUT_EVENT, onTripTimedOut);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
SentianceCore._addSdkStatusUpdateListener = _addSdkStatusUpdateListener;
|
|
59
|
-
SentianceCore._addUserLinkListener = _addUserLinkListener;
|
|
60
|
-
SentianceCore._addOnDetectionsEnabledListener = _addOnDetectionsEnabledListener;
|
|
61
|
-
SentianceCore._addSdkUserActivityUpdateListener = _addSdkUserActivityUpdateListener;
|
|
62
|
-
SentianceCore._addTripTimeoutListener = _addTripTimeoutListener;
|
|
63
|
-
|
|
64
|
-
export default SentianceCore;
|
|
58
|
+
module.exports = coreModule;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
declare module "sentiance-react-native-core" {
|
|
2
2
|
import {EmitterSubscription} from "react-native";
|
|
3
3
|
|
|
4
|
+
export type DetectionStatus = "DISABLED" | "EXPIRED" | "ENABLED_BUT_BLOCKED" | "ENABLED_AND_DETECTING";
|
|
4
5
|
export type LocationPermission = "ALWAYS" | "ONLY_WHILE_IN_USE" | "NEVER";
|
|
6
|
+
export type BackgroundRefreshStatus = "AVAILABLE" | "DENIED" | "RESTRICTED";
|
|
5
7
|
export type SdkInitState =
|
|
6
8
|
"NOT_INITIALIZED"
|
|
7
9
|
| "INIT_IN_PROGRESS"
|
|
@@ -84,6 +86,7 @@ declare module "sentiance-react-native-core" {
|
|
|
84
86
|
|
|
85
87
|
export interface SdkStatus {
|
|
86
88
|
startStatus: string;
|
|
89
|
+
detectionStatus: DetectionStatus;
|
|
87
90
|
canDetect: boolean;
|
|
88
91
|
isRemoteEnabled: boolean;
|
|
89
92
|
isAccelPresent: boolean;
|
|
@@ -93,6 +96,7 @@ declare module "sentiance-react-native-core" {
|
|
|
93
96
|
mobileQuotaStatus: string;
|
|
94
97
|
diskQuotaStatus: string;
|
|
95
98
|
locationPermission: LocationPermission;
|
|
99
|
+
userExists: boolean;
|
|
96
100
|
isBgAccessPermGranted?: boolean; // iOS only
|
|
97
101
|
isActivityRecognitionPermGranted?: boolean; // Android only
|
|
98
102
|
locationSetting?: string; // Android only
|
|
@@ -104,11 +108,17 @@ declare module "sentiance-react-native-core" {
|
|
|
104
108
|
isBackgroundProcessingRestricted?: boolean; // Android only
|
|
105
109
|
isPreciseLocationAuthorizationGranted: boolean;
|
|
106
110
|
isSchedulingExactAlarmsPermitted?: boolean; // Android only
|
|
111
|
+
backgroundRefreshStatus: BackgroundRefreshStatus; // iOS only
|
|
107
112
|
}
|
|
108
113
|
|
|
109
|
-
export interface
|
|
114
|
+
export interface EnableDetectionsResult {
|
|
110
115
|
sdkStatus: SdkStatus,
|
|
111
|
-
detectionStatus:
|
|
116
|
+
detectionStatus: DetectionStatus
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface DisableDetectionsResult {
|
|
120
|
+
sdkStatus: SdkStatus,
|
|
121
|
+
detectionStatus: DetectionStatus
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
export interface SentianceCore {
|
|
@@ -116,11 +126,11 @@ declare module "sentiance-react-native-core" {
|
|
|
116
126
|
|
|
117
127
|
userExists(): Promise<boolean>;
|
|
118
128
|
|
|
119
|
-
enableDetections(): Promise<
|
|
129
|
+
enableDetections(): Promise<EnableDetectionsResult>;
|
|
120
130
|
|
|
121
|
-
enableDetectionsWithExpiryDate(expiryEpochTimeMs: number | null): Promise<
|
|
131
|
+
enableDetectionsWithExpiryDate(expiryEpochTimeMs: number | null): Promise<EnableDetectionsResult>;
|
|
122
132
|
|
|
123
|
-
disableDetections(): Promise<
|
|
133
|
+
disableDetections(): Promise<DisableDetectionsResult>;
|
|
124
134
|
|
|
125
135
|
reset(): Promise<ResetResult>;
|
|
126
136
|
|
|
@@ -180,7 +190,7 @@ declare module "sentiance-react-native-core" {
|
|
|
180
190
|
|
|
181
191
|
createUser(options: UserCreationOptions): Promise<CreateUserResult>;
|
|
182
192
|
|
|
183
|
-
linkUser(): Promise<UserLinkingResult>;
|
|
193
|
+
linkUser(linker: (installId) => boolean): Promise<UserLinkingResult>;
|
|
184
194
|
|
|
185
195
|
linkUserWithAuthCode(authCode: string): Promise<UserLinkingResult>;
|
|
186
196
|
|
|
@@ -188,8 +198,6 @@ declare module "sentiance-react-native-core" {
|
|
|
188
198
|
|
|
189
199
|
addTripTimeoutListener(onTripTimedOut: () => void): Promise<EmitterSubscription>;
|
|
190
200
|
|
|
191
|
-
addOnDetectionsEnabledListener(onDetectionsEnabled: (sdkStatus: SdkStatus) => void): Promise<EmitterSubscription>;
|
|
192
|
-
|
|
193
201
|
addSdkUserActivityUpdateListener(onUserActivityUpdated: (userActivity: UserActivity) => void): Promise<EmitterSubscription>;
|
|
194
202
|
}
|
|
195
203
|
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const core = require('./core');
|
|
2
|
+
const {Platform} = require('react-native');
|
|
3
3
|
|
|
4
4
|
const enableDetections = () => core.enableDetections();
|
|
5
5
|
const enableDetectionsWithExpiryDate = (expiryTime) => core.enableDetectionsWithExpiryDate(expiryTime);
|
|
@@ -31,6 +31,7 @@ const getMobileQuotaUsage = () => core.getMobileQuotaUsage();
|
|
|
31
31
|
const getWiFiQuotaLimit = () => core.getWiFiQuotaLimit();
|
|
32
32
|
const getWiFiQuotaUsage = () => core.getWiFiQuotaUsage();
|
|
33
33
|
const linkUserWithAuthCode = (authCode) => core.linkUserWithAuthCode(authCode);
|
|
34
|
+
const NO_OP_LINKER = {}
|
|
34
35
|
|
|
35
36
|
var startTrip
|
|
36
37
|
var stopTrip
|
|
@@ -42,8 +43,7 @@ if (Platform.OS === 'ios') {
|
|
|
42
43
|
stopTrip = () => core.stopTripNewApi();
|
|
43
44
|
submitDetections = () => core.submitDetectionsNewApi();
|
|
44
45
|
reset = () => core.resetNewApi();
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
46
|
+
} else {
|
|
47
47
|
startTrip = (metadata, hint) => core.startTrip(metadata, hint);
|
|
48
48
|
stopTrip = () => core.stopTrip();
|
|
49
49
|
submitDetections = () => core.submitDetections();
|
|
@@ -80,6 +80,16 @@ const linkUser = async (linker) => {
|
|
|
80
80
|
* }
|
|
81
81
|
*
|
|
82
82
|
* createUser(userCreationOptions);
|
|
83
|
+
*
|
|
84
|
+
* Or unlinked user with appId / appSecret (Not recommended)
|
|
85
|
+
*
|
|
86
|
+
* const userCreationOptions = {
|
|
87
|
+
* linker : NO_OP_LINKER,
|
|
88
|
+
* appId : "<APP_ID>",
|
|
89
|
+
* appSecret: "<APP_SECRET>"
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* createUser(userCreationOptions);
|
|
83
93
|
*/
|
|
84
94
|
|
|
85
95
|
|
|
@@ -106,9 +116,20 @@ const linkUser = async (linker) => {
|
|
|
106
116
|
* appSecret: "<APP_SECRET>"
|
|
107
117
|
* }
|
|
108
118
|
*
|
|
109
|
-
*
|
|
119
|
+
* createUser(userCreationOptions);
|
|
120
|
+
*
|
|
121
|
+
* Or unlinked user with appId / appSecret (Not recommended)
|
|
122
|
+
*
|
|
123
|
+
* const userCreationOptions = {
|
|
124
|
+
* linker : NO_OP_LINKER,
|
|
125
|
+
* appId : "<APP_ID>",
|
|
126
|
+
* appSecret: "<APP_SECRET>"
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* createUser(userCreationOptions);
|
|
110
130
|
*/
|
|
111
131
|
const createUser = async (userCreationOptions) => {
|
|
132
|
+
|
|
112
133
|
const appId = userCreationOptions.appId;
|
|
113
134
|
const appSecret = userCreationOptions.appSecret;
|
|
114
135
|
const authCode = userCreationOptions.authCode;
|
|
@@ -116,21 +137,24 @@ const createUser = async (userCreationOptions) => {
|
|
|
116
137
|
const linker = userCreationOptions.linker;
|
|
117
138
|
|
|
118
139
|
if (!appId && !appSecret && !authCode) {
|
|
119
|
-
return Promise.reject('Invalid userCreationOptions passed, please set authCode or
|
|
140
|
+
return Promise.reject('Invalid userCreationOptions passed, please set authCode or appId/appSecret with a linker to create user');
|
|
120
141
|
}
|
|
121
142
|
|
|
122
143
|
if (authCode) {
|
|
123
144
|
return core.createLinkedUserWithAuthCode(authCode, platformUrl);
|
|
124
145
|
} else if (linker) {
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
if (linker === NO_OP_LINKER) {
|
|
147
|
+
return core.createUnlinkedUser(appId, appSecret, platformUrl);
|
|
148
|
+
} else {
|
|
149
|
+
await core._addUserLinkListener(linker);
|
|
150
|
+
return core.createLinkedUser(appId, appSecret, platformUrl);
|
|
151
|
+
}
|
|
127
152
|
} else {
|
|
128
|
-
return
|
|
153
|
+
return Promise.reject('Invalid userCreationOptions passed, no authcode or linker specified.');
|
|
129
154
|
}
|
|
130
155
|
}
|
|
131
156
|
|
|
132
157
|
const addSdkStatusUpdateListener = core._addSdkStatusUpdateListener;
|
|
133
|
-
const addOnDetectionsEnabledListener = core._addOnDetectionsEnabledListener;
|
|
134
158
|
const addSdkUserActivityUpdateListener = core._addSdkUserActivityUpdateListener;
|
|
135
159
|
const addTripTimeoutListener = core._addTripTimeoutListener;
|
|
136
160
|
|
|
@@ -186,9 +210,9 @@ module.exports = {
|
|
|
186
210
|
linkUser,
|
|
187
211
|
linkUserWithAuthCode,
|
|
188
212
|
addSdkStatusUpdateListener,
|
|
189
|
-
addOnDetectionsEnabledListener,
|
|
190
213
|
addSdkUserActivityUpdateListener,
|
|
191
214
|
addTripTimeoutListener,
|
|
192
215
|
listenTripTimeout,
|
|
193
|
-
transportModes
|
|
216
|
+
transportModes,
|
|
217
|
+
NO_OP_LINKER
|
|
194
218
|
};
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentiance-react-native/core",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "React Native Sentiance core library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"targetSdk": 31,
|
|
30
30
|
"compileSdk": 31,
|
|
31
31
|
"buildTools": "30.0.3",
|
|
32
|
-
"sentiance": "6.0.0
|
|
32
|
+
"sentiance": "6.0.0"
|
|
33
33
|
},
|
|
34
34
|
"ios": {
|
|
35
|
-
"sentiance": "6.0.0
|
|
35
|
+
"sentiance": "6.0.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|