@sentiance-react-native/legacy 6.0.0-beta.9
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 +34 -0
- package/android/build.gradle +40 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +2 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sentiance/react/bridge/legacy/LegacySentianceModule.java +316 -0
- package/android/src/main/java/com/sentiance/react/bridge/legacy/LegacySentiancePackage.java +29 -0
- package/android/src/main/java/com/sentiance/react/bridge/legacy/RNSentianceHelper.java +251 -0
- package/android/src/main/java/com/sentiance/react/bridge/legacy/StartFinishedHandlerCreator.java +41 -0
- package/lib/index.d.ts +243 -0
- package/lib/index.js +125 -0
- package/lib/legacy/index.js +23 -0
- package/package.json +26 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.legacy;
|
|
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
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class LegacySentiancePackage implements ReactPackage {
|
|
15
|
+
|
|
16
|
+
@NonNull
|
|
17
|
+
@Override
|
|
18
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
19
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
20
|
+
LegacySentianceModule legacySentianceModule = new LegacySentianceModule(reactContext);
|
|
21
|
+
modules.add(legacySentianceModule);
|
|
22
|
+
return modules;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
27
|
+
return Collections.emptyList();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.legacy;
|
|
2
|
+
|
|
3
|
+
import android.app.Notification;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.SharedPreferences;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
|
|
10
|
+
import com.sentiance.react.bridge.core.SentianceEmitter;
|
|
11
|
+
import com.sentiance.react.bridge.core.UserLinker;
|
|
12
|
+
import com.sentiance.react.bridge.core.utils.SentianceUtils;
|
|
13
|
+
import com.sentiance.sdk.OnInitCallback;
|
|
14
|
+
import com.sentiance.sdk.OnStartFinishedHandler;
|
|
15
|
+
import com.sentiance.sdk.SdkConfig;
|
|
16
|
+
import com.sentiance.sdk.SdkStatus;
|
|
17
|
+
import com.sentiance.sdk.Sentiance;
|
|
18
|
+
|
|
19
|
+
import java.lang.ref.WeakReference;
|
|
20
|
+
import java.util.Date;
|
|
21
|
+
|
|
22
|
+
public class RNSentianceHelper {
|
|
23
|
+
|
|
24
|
+
private static final String SDK_NATIVE_INIT_FLAG = "SDK_NATIVE_INIT_FLAG";
|
|
25
|
+
private static final String MY_PREFS_NAME = "RNSentianceHelper";
|
|
26
|
+
private static final String TAG = "RNSentianceHelper";
|
|
27
|
+
private static RNSentianceHelper rnSentianceHelper;
|
|
28
|
+
|
|
29
|
+
private final SentianceEmitter sentianceEmitter;
|
|
30
|
+
private final WeakReference<Context> weakContext;
|
|
31
|
+
|
|
32
|
+
public static RNSentianceHelper getInstance(Context context) {
|
|
33
|
+
if (rnSentianceHelper == null) {
|
|
34
|
+
synchronized (RNSentianceHelper.class) {
|
|
35
|
+
rnSentianceHelper = new RNSentianceHelper(context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return rnSentianceHelper;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
private RNSentianceHelper(Context context) {
|
|
43
|
+
weakContext = new WeakReference<>(context);
|
|
44
|
+
sentianceEmitter = new SentianceEmitter(weakContext.get());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* ========================================
|
|
49
|
+
* Temporary wrapper methods to ease the
|
|
50
|
+
* integration of the SDK
|
|
51
|
+
* ========================================
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The wrapper method handle SDK initialization without needing to pass the
|
|
56
|
+
* crendentials. This method is meant to be called in the "MainActivity.onCreate". While
|
|
57
|
+
* the credentials are passed during the "createUser" method exposed.
|
|
58
|
+
* <p>
|
|
59
|
+
* This method basically rallies around the state vairables.
|
|
60
|
+
* - SENTIANCE_SDK_IS_READY_FOR_BACKGROUND
|
|
61
|
+
* - SENTIANCE_SDK_APP_ID
|
|
62
|
+
* - SENTIANCE_SDK_APP_SECRET
|
|
63
|
+
* <p>
|
|
64
|
+
* The above variables are set in the "createUser" method
|
|
65
|
+
*
|
|
66
|
+
* @param callback
|
|
67
|
+
*/
|
|
68
|
+
public void initialize(@Nullable final InitCallback callback) {
|
|
69
|
+
String isReadyForBackground = this.getValueForKey("SENTIANCE_SDK_IS_READY_FOR_BACKGROUND", "");
|
|
70
|
+
|
|
71
|
+
if (!isReadyForBackground.equals("YES")) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
String appId = this.getValueForKey("SENTIANCE_SDK_APP_ID", "");
|
|
76
|
+
String appSecret = this.getValueForKey("SENTIANCE_SDK_APP_SECRET", "");
|
|
77
|
+
String baseUrl = this.getValueForKey("SENTIANCE_SDK_APP_BASE_URL", "");
|
|
78
|
+
final String isDisabled = this.getValueForKey("SENTIANCE_SDK_IS_DISABLED", "");
|
|
79
|
+
|
|
80
|
+
if (appId.equals("") || appSecret.equals("")) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.initializeSentianceSDK(appId, appSecret, false, baseUrl, new OnInitCallback() {
|
|
85
|
+
@Override
|
|
86
|
+
public void onInitSuccess() {
|
|
87
|
+
if (!isDisabled.equals("YES")) {
|
|
88
|
+
startSentianceSDK(
|
|
89
|
+
new OnStartFinishedHandler() {
|
|
90
|
+
@Override
|
|
91
|
+
public void onStartFinished(SdkStatus sdkStatus) {
|
|
92
|
+
if (callback != null) callback.onSuccess();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Override
|
|
100
|
+
public void onInitFailure(InitIssue issue, @Nullable Throwable throwable) {
|
|
101
|
+
if (callback != null) callback.onFailure(issue);
|
|
102
|
+
}
|
|
103
|
+
}, null);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public void initializeAndStartSentianceSDK(String appId, String appSecret,
|
|
107
|
+
final boolean shouldStart, @Nullable String baseUrl,
|
|
108
|
+
boolean userLinkingEnabled,
|
|
109
|
+
final @Nullable OnInitCallback initCallback,
|
|
110
|
+
final @Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
111
|
+
Context context = weakContext.get();
|
|
112
|
+
if (context == null) return;
|
|
113
|
+
|
|
114
|
+
Notification notification = SentianceUtils.createNotificationFromManifestData(weakContext);
|
|
115
|
+
|
|
116
|
+
// Create the config.
|
|
117
|
+
SdkConfig.Builder builder = new SdkConfig.Builder(appId, appSecret, notification)
|
|
118
|
+
.setOnSdkStatusUpdateHandler(sentianceEmitter::sendStatusUpdateEvent);
|
|
119
|
+
if (userLinkingEnabled)
|
|
120
|
+
builder.setUserLinker(new UserLinker(sentianceEmitter));
|
|
121
|
+
if (baseUrl != null)
|
|
122
|
+
builder.baseURL(baseUrl);
|
|
123
|
+
|
|
124
|
+
SdkConfig config = builder.build();
|
|
125
|
+
|
|
126
|
+
// Initialize and start Sentiance SDK.
|
|
127
|
+
Sentiance.getInstance(context).init(config, new OnInitCallback() {
|
|
128
|
+
@Override
|
|
129
|
+
public void onInitSuccess() {
|
|
130
|
+
if (initCallback != null)
|
|
131
|
+
initCallback.onInitSuccess();
|
|
132
|
+
if (shouldStart)
|
|
133
|
+
startSentianceSDK(startFinishedHandler);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
public void onInitFailure(InitIssue issue, @Nullable Throwable throwable) {
|
|
138
|
+
if (initCallback != null)
|
|
139
|
+
initCallback.onInitFailure(issue, throwable);
|
|
140
|
+
Log.e(TAG, issue.toString());
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
146
|
+
public void startSentianceSDK(@Nullable final OnStartFinishedHandler callback) {
|
|
147
|
+
startSentianceSDK(null, callback);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
151
|
+
public void startSentianceSDK(@Nullable final Long stopEpochTimeMs,
|
|
152
|
+
@Nullable final OnStartFinishedHandler callback) {
|
|
153
|
+
Context context = weakContext.get();
|
|
154
|
+
if (context == null) return;
|
|
155
|
+
|
|
156
|
+
if (stopEpochTimeMs != null) {
|
|
157
|
+
Sentiance.getInstance(context).start(new Date(stopEpochTimeMs), callback);
|
|
158
|
+
} else {
|
|
159
|
+
Sentiance.getInstance(context).start(callback);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
164
|
+
public void initializeSentianceSDK(String appId, String appSecret, boolean shouldStart,
|
|
165
|
+
@Nullable OnInitCallback initCallback,
|
|
166
|
+
@Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
167
|
+
initializeAndStartSentianceSDK(appId, appSecret, shouldStart, null, false, initCallback,
|
|
168
|
+
startFinishedHandler);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
172
|
+
public void initializeSentianceSDK(String appId, String appSecret, boolean shouldStart,
|
|
173
|
+
@Nullable String baseUrl, @Nullable OnInitCallback initCallback,
|
|
174
|
+
@Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
175
|
+
initializeAndStartSentianceSDK(appId, appSecret, shouldStart, baseUrl, false, initCallback,
|
|
176
|
+
startFinishedHandler);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
180
|
+
public void initializeSentianceSDKWithUserLinking(String appId, String appSecret, boolean shouldStart,
|
|
181
|
+
@Nullable OnInitCallback initCallback,
|
|
182
|
+
@Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
183
|
+
initializeAndStartSentianceSDK(appId, appSecret, shouldStart, null, true, initCallback,
|
|
184
|
+
startFinishedHandler);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
188
|
+
public void initializeSentianceSDKWithUserLinking(String appId, String appSecret, boolean shouldStart,
|
|
189
|
+
@Nullable String baseUrl, @Nullable OnInitCallback initCallback,
|
|
190
|
+
@Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
191
|
+
initializeAndStartSentianceSDK(appId, appSecret, shouldStart, baseUrl, true, initCallback,
|
|
192
|
+
startFinishedHandler);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public Boolean initializeSentianceSDKIfUserLinkingCompleted(String appId, String appSecret, boolean shouldStart,
|
|
196
|
+
@Nullable String baseUrl,
|
|
197
|
+
@Nullable OnInitCallback initCallback,
|
|
198
|
+
@Nullable OnStartFinishedHandler startFinishedHandler) {
|
|
199
|
+
if (isThirdPartyLinked()) {
|
|
200
|
+
initializeAndStartSentianceSDK(appId, appSecret, shouldStart, baseUrl, true, initCallback,
|
|
201
|
+
startFinishedHandler);
|
|
202
|
+
return true;
|
|
203
|
+
} else {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public Boolean isThirdPartyLinked() {
|
|
209
|
+
Context context = weakContext.get();
|
|
210
|
+
if (context == null) return false;
|
|
211
|
+
return Sentiance.getInstance(context).isUserLinked();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
215
|
+
public void setValueForKey(String key, String value) {
|
|
216
|
+
Context context = weakContext.get();
|
|
217
|
+
if (context == null) return;
|
|
218
|
+
SharedPreferences prefs = context.getSharedPreferences(MY_PREFS_NAME, Context.MODE_PRIVATE);
|
|
219
|
+
prefs.edit().putString(key, value).apply();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
223
|
+
public String getValueForKey(String key, String defaultValue) {
|
|
224
|
+
Context context = weakContext.get();
|
|
225
|
+
if (context == null) return defaultValue;
|
|
226
|
+
SharedPreferences prefs = context.getSharedPreferences(MY_PREFS_NAME, Context.MODE_PRIVATE);
|
|
227
|
+
return prefs.getString(key, defaultValue);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
231
|
+
public Boolean isNativeInitializationEnabled() {
|
|
232
|
+
String nativeInitFlag = rnSentianceHelper.getValueForKey(SDK_NATIVE_INIT_FLAG, "");
|
|
233
|
+
return nativeInitFlag.equals("enabled");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
237
|
+
public void enableNativeInitialization() {
|
|
238
|
+
setValueForKey(SDK_NATIVE_INIT_FLAG, "enabled");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
242
|
+
public void disableNativeInitialization() {
|
|
243
|
+
setValueForKey(SDK_NATIVE_INIT_FLAG, "");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public interface InitCallback {
|
|
247
|
+
void onSuccess();
|
|
248
|
+
|
|
249
|
+
void onFailure(OnInitCallback.InitIssue issue);
|
|
250
|
+
}
|
|
251
|
+
}
|
package/android/src/main/java/com/sentiance/react/bridge/legacy/StartFinishedHandlerCreator.java
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.legacy;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Promise;
|
|
6
|
+
import com.sentiance.react.bridge.core.SentianceConverter;
|
|
7
|
+
import com.sentiance.sdk.OnStartFinishedHandler;
|
|
8
|
+
import com.sentiance.sdk.SdkStatus;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
public class StartFinishedHandlerCreator {
|
|
14
|
+
|
|
15
|
+
private final List<OnStartFinishedHandler> startFinishedHandlers;
|
|
16
|
+
|
|
17
|
+
StartFinishedHandlerCreator() {
|
|
18
|
+
this.startFinishedHandlers = new ArrayList<>();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
OnStartFinishedHandler createNewStartFinishedHandler(final Promise promise) {
|
|
22
|
+
final OnStartFinishedHandler startFinishedHandler = new OnStartFinishedHandler() {
|
|
23
|
+
@Override
|
|
24
|
+
public void onStartFinished(@NonNull SdkStatus sdkStatus) {
|
|
25
|
+
promise.resolve(SentianceConverter.convertSdkStatus(sdkStatus));
|
|
26
|
+
removeStartFinishHandler(this);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// hold strong reference
|
|
30
|
+
addStartFinishHandler(startFinishedHandler);
|
|
31
|
+
return startFinishedHandler;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private synchronized void addStartFinishHandler(OnStartFinishedHandler handler) {
|
|
35
|
+
startFinishedHandlers.add(handler);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private synchronized void removeStartFinishHandler(OnStartFinishedHandler handler) {
|
|
39
|
+
startFinishedHandlers.remove(handler);
|
|
40
|
+
}
|
|
41
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
declare module "react-native-sentiance" {
|
|
2
|
+
import {EmitterSubscription, EventSubscriptionVendor, NativeEventEmitter,} from "react-native";
|
|
3
|
+
|
|
4
|
+
export type LocationPermission = "ALWAYS" | "ONLY_WHILE_IN_USE" | "NEVER";
|
|
5
|
+
export type SdkInitState =
|
|
6
|
+
| "NOT_INITIALIZED"
|
|
7
|
+
| "INIT_IN_PROGRESS"
|
|
8
|
+
| "INITIALIZED"
|
|
9
|
+
| "RESETTING"
|
|
10
|
+
| "UNRECOGNIZED_STATE";
|
|
11
|
+
|
|
12
|
+
export type SdkResetFailureReason =
|
|
13
|
+
| "SDK_INIT_IN_PROGRESS"
|
|
14
|
+
| "SDK_RESET_IN_PROGRESS"
|
|
15
|
+
| "SDK_RESET_UNKNOWN_ERROR";
|
|
16
|
+
|
|
17
|
+
export type InitIssue =
|
|
18
|
+
| "INVALID_CREDENTIALS"
|
|
19
|
+
| "CHANGED_CREDENTIALS"
|
|
20
|
+
| "SERVICE_UNREACHABLE"
|
|
21
|
+
| "LINK_FAILED"
|
|
22
|
+
| "SDK_RESET_IN_PROGRESS"
|
|
23
|
+
| "INITIALIZATION_ERROR";
|
|
24
|
+
|
|
25
|
+
export type TripType = "TRIP_TYPE_SDK" | "TRIP_TYPE_EXTERNAL";
|
|
26
|
+
export type SdkEvent =
|
|
27
|
+
"SENTIANCE_STATUS_UPDATE_EVENT"
|
|
28
|
+
| "SENTIANCE_USER_LINK_EVENT"
|
|
29
|
+
| "SENTIANCE_USER_ACTIVITY_UPDATE_EVENT"
|
|
30
|
+
| "SENTIANCE_ON_TRIP_TIMED_OUT_EVENT"
|
|
31
|
+
| "SENTIANCE_VEHICLE_CRASH_EVENT";
|
|
32
|
+
|
|
33
|
+
export type SDKStatusUpdateListener = (sdkStatus: SdkStatus) => void;
|
|
34
|
+
|
|
35
|
+
export type SDKUserLinkListener = (param: { installId: string }) => void;
|
|
36
|
+
|
|
37
|
+
export type SDKUserActivityUpdateListener = (userActivity: UserActivity) => void;
|
|
38
|
+
|
|
39
|
+
export type SDKCrashEventListener = (crashEvent: CrashEvent) => void;
|
|
40
|
+
|
|
41
|
+
export type SdkEventListener =
|
|
42
|
+
SDKStatusUpdateListener |
|
|
43
|
+
SDKUserLinkListener |
|
|
44
|
+
SDKUserActivityUpdateListener |
|
|
45
|
+
SDKCrashEventListener;
|
|
46
|
+
|
|
47
|
+
export enum TransportMode {
|
|
48
|
+
UNKNOWN = 1,
|
|
49
|
+
CAR,
|
|
50
|
+
BICYCLE,
|
|
51
|
+
ON_FOOT,
|
|
52
|
+
TRAIN,
|
|
53
|
+
TRAM,
|
|
54
|
+
BUS,
|
|
55
|
+
PLANE,
|
|
56
|
+
BOAT,
|
|
57
|
+
METRO,
|
|
58
|
+
RUNNING,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface VehicleCrashEvent {
|
|
62
|
+
time: number;
|
|
63
|
+
location?: Location;
|
|
64
|
+
magnitude?: number;
|
|
65
|
+
speedAtImpact?: number;
|
|
66
|
+
deltaV?: number;
|
|
67
|
+
confidence?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CrashEvent {
|
|
71
|
+
time: number;
|
|
72
|
+
lastKnownLocation?: Location;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface Location {
|
|
76
|
+
latitude: string;
|
|
77
|
+
longitude: string;
|
|
78
|
+
accuracy?: string; // Android only
|
|
79
|
+
altitude?: string; // Android only
|
|
80
|
+
provider?: string; // Android only
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface StationaryInfo {
|
|
84
|
+
location?: Location;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface TripInfo {
|
|
88
|
+
type: "TRIP_TYPE_SDK" | "TRIP_TYPE_EXTERNAL" | "TRIP_TYPE_UNRECOGNIZED" | "ANY";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface UserActivity {
|
|
92
|
+
type: "USER_ACTIVITY_TYPE_TRIP" | "USER_ACTIVITY_TYPE_STATIONARY" | "USER_ACTIVITY_TYPE_UNKNOWN" | "USER_ACTIVITY_TYPE_UNRECOGNIZED";
|
|
93
|
+
tripInfo?: TripInfo;
|
|
94
|
+
stationaryInfo?: StationaryInfo;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface MetadataObject {
|
|
98
|
+
[key: string]: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface UserAccessToken {
|
|
102
|
+
tokenId: string;
|
|
103
|
+
expiryDate?: string; // Android only
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface SdkStatus {
|
|
107
|
+
startStatus: string;
|
|
108
|
+
canDetect: boolean;
|
|
109
|
+
isRemoteEnabled: boolean;
|
|
110
|
+
isAccelPresent: boolean;
|
|
111
|
+
isGyroPresent: boolean;
|
|
112
|
+
isGpsPresent: boolean;
|
|
113
|
+
wifiQuotaStatus: string;
|
|
114
|
+
mobileQuotaStatus: string;
|
|
115
|
+
diskQuotaStatus: string;
|
|
116
|
+
locationPermission: LocationPermission;
|
|
117
|
+
isBgAccessPermGranted?: boolean; // iOS only
|
|
118
|
+
isActivityRecognitionPermGranted?: boolean; // Android only
|
|
119
|
+
locationSetting?: string; // Android only
|
|
120
|
+
isAirplaneModeEnabled?: boolean; // Android only
|
|
121
|
+
isLocationAvailable?: boolean; // Android only
|
|
122
|
+
isGooglePlayServicesMissing?: boolean; // Android only
|
|
123
|
+
isBatteryOptimizationEnabled?: boolean; // Android only
|
|
124
|
+
isBatterySavingEnabled?: boolean; // Android only
|
|
125
|
+
isBackgroundProcessingRestricted?: boolean; // Android only
|
|
126
|
+
isPreciseLocationAuthorizationGranted: boolean;
|
|
127
|
+
isSchedulingExactAlarmsPermitted?: boolean; // Android only
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface RNSentianceConstructor extends EventSubscriptionVendor {
|
|
131
|
+
init(
|
|
132
|
+
appId: string,
|
|
133
|
+
secret: string,
|
|
134
|
+
baseURL: string | null,
|
|
135
|
+
shouldStart: boolean
|
|
136
|
+
): Promise<boolean | SdkStatus>;
|
|
137
|
+
|
|
138
|
+
initWithUserLinkingEnabled(
|
|
139
|
+
appId: string,
|
|
140
|
+
secret: string,
|
|
141
|
+
baseURL: string | null,
|
|
142
|
+
shouldStart: boolean
|
|
143
|
+
): Promise<boolean | SdkStatus>;
|
|
144
|
+
|
|
145
|
+
start(): Promise<SdkStatus>;
|
|
146
|
+
|
|
147
|
+
startWithStopDate(stopEpochTimeMs: number | null): Promise<SdkStatus>;
|
|
148
|
+
|
|
149
|
+
stop(): Promise<boolean>;
|
|
150
|
+
|
|
151
|
+
reset(): Promise<boolean>;
|
|
152
|
+
|
|
153
|
+
getInitState(): Promise<SdkInitState>;
|
|
154
|
+
|
|
155
|
+
getSdkStatus(): Promise<SdkStatus>;
|
|
156
|
+
|
|
157
|
+
getVersion(): Promise<string>;
|
|
158
|
+
|
|
159
|
+
getUserId(): Promise<string>;
|
|
160
|
+
|
|
161
|
+
getUserAccessToken(): Promise<UserAccessToken>;
|
|
162
|
+
|
|
163
|
+
addUserMetadataField(label: string, value: string): Promise<boolean>;
|
|
164
|
+
|
|
165
|
+
addUserMetadataFields(metadata: MetadataObject): Promise<boolean>;
|
|
166
|
+
|
|
167
|
+
removeUserMetadataField(label: string): Promise<boolean>;
|
|
168
|
+
|
|
169
|
+
getWiFiQuotaLimit(): Promise<string>;
|
|
170
|
+
|
|
171
|
+
getWiFiQuotaUsage(): Promise<string>;
|
|
172
|
+
|
|
173
|
+
getMobileQuotaLimit(): Promise<string>;
|
|
174
|
+
|
|
175
|
+
getMobileQuotaUsage(): Promise<string>;
|
|
176
|
+
|
|
177
|
+
getDiskQuotaLimit(): Promise<string>;
|
|
178
|
+
|
|
179
|
+
getDiskQuotaUsage(): Promise<string>;
|
|
180
|
+
|
|
181
|
+
disableBatteryOptimization(): Promise<boolean>;
|
|
182
|
+
|
|
183
|
+
getUserActivity(): Promise<UserActivity>;
|
|
184
|
+
|
|
185
|
+
listenUserActivityUpdates(): Promise<boolean>;
|
|
186
|
+
|
|
187
|
+
listenTripTimeout(): Promise<void>;
|
|
188
|
+
|
|
189
|
+
userLinkCallback(success: boolean): void;
|
|
190
|
+
|
|
191
|
+
getValueForKey(key: string, defaultValue: string): Promise<string>;
|
|
192
|
+
|
|
193
|
+
setValueForKey(key: string, value: string): void;
|
|
194
|
+
|
|
195
|
+
startTrip(
|
|
196
|
+
metadata: MetadataObject | null,
|
|
197
|
+
hint: TransportMode
|
|
198
|
+
): Promise<boolean>;
|
|
199
|
+
|
|
200
|
+
stopTrip(): Promise<boolean>;
|
|
201
|
+
|
|
202
|
+
isTripOngoing(type: TripType): Promise<boolean>;
|
|
203
|
+
|
|
204
|
+
submitDetections(): Promise<boolean>;
|
|
205
|
+
|
|
206
|
+
updateSdkNotification(title: string, message: string): Promise<boolean>;
|
|
207
|
+
|
|
208
|
+
addTripMetadata(metadata: MetadataObject): Promise<boolean>;
|
|
209
|
+
|
|
210
|
+
isThirdPartyLinked(): Promise<boolean>;
|
|
211
|
+
|
|
212
|
+
isNativeInitializationEnabled(): Promise<boolean>;
|
|
213
|
+
|
|
214
|
+
enableNativeInitialization(): Promise<boolean>;
|
|
215
|
+
|
|
216
|
+
disableNativeInitialization(): Promise<boolean>;
|
|
217
|
+
|
|
218
|
+
listenVehicleCrashEvents(): Promise<boolean>;
|
|
219
|
+
|
|
220
|
+
invokeDummyVehicleCrash(): Promise<boolean>;
|
|
221
|
+
|
|
222
|
+
isVehicleCrashDetectionSupported(): Promise<boolean>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface RNSentianceEventEmitter extends NativeEventEmitter {
|
|
226
|
+
addListener(
|
|
227
|
+
eventType: SdkEvent,
|
|
228
|
+
listener: SdkEventListener,
|
|
229
|
+
context?: any
|
|
230
|
+
): EmitterSubscription;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface RNSentianceEventSubscriptions {
|
|
234
|
+
sdkStatusSubscription?: EmitterSubscription;
|
|
235
|
+
sdkUserLinkSubscription?: EmitterSubscription;
|
|
236
|
+
sdkUserActivityUpdateSubscription?: EmitterSubscription;
|
|
237
|
+
sdkCrashEventSubscription?: EmitterSubscription;
|
|
238
|
+
sdkTripProfileListener?: EmitterSubscription;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const RNSentiance: RNSentianceConstructor;
|
|
242
|
+
export default RNSentiance;
|
|
243
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import legacy from './legacy';
|
|
2
|
+
import core from '@sentiance-react-native/core';
|
|
3
|
+
import crashDetection from '@sentiance-react-native/crash-detection';
|
|
4
|
+
|
|
5
|
+
var RNSentiance = {};
|
|
6
|
+
RNSentiance.TransportMode = core.transportModes;
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
userLinkCallback,
|
|
10
|
+
getVersion,
|
|
11
|
+
getUserId,
|
|
12
|
+
addUserMetadataField,
|
|
13
|
+
addUserMetadataFields,
|
|
14
|
+
removeUserMetadataField,
|
|
15
|
+
getUserActivity,
|
|
16
|
+
listenUserActivityUpdates,
|
|
17
|
+
isTripOngoing,
|
|
18
|
+
updateSdkNotification,
|
|
19
|
+
addTripMetadata,
|
|
20
|
+
getInitState,
|
|
21
|
+
getSdkStatus,
|
|
22
|
+
getDiskQuotaLimit,
|
|
23
|
+
getDiskQuotaUsage,
|
|
24
|
+
disableBatteryOptimization,
|
|
25
|
+
getMobileQuotaLimit,
|
|
26
|
+
getMobileQuotaUsage,
|
|
27
|
+
getWiFiQuotaLimit,
|
|
28
|
+
getWiFiQuotaUsage,
|
|
29
|
+
listenTripTimeout
|
|
30
|
+
} = core;
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
listenVehicleCrashEvents,
|
|
34
|
+
invokeDummyVehicleCrash,
|
|
35
|
+
isVehicleCrashDetectionSupported
|
|
36
|
+
} = crashDetection;
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
init,
|
|
40
|
+
initWithUserLinkingEnabled,
|
|
41
|
+
reset,
|
|
42
|
+
start,
|
|
43
|
+
startWithStopDate,
|
|
44
|
+
stop,
|
|
45
|
+
startTrip,
|
|
46
|
+
stopTrip,
|
|
47
|
+
setValueForKey,
|
|
48
|
+
getValueForKey,
|
|
49
|
+
isThirdPartyLinked,
|
|
50
|
+
isNativeInitializationEnabled,
|
|
51
|
+
enableNativeInitialization,
|
|
52
|
+
disableNativeInitialization,
|
|
53
|
+
submitDetections,
|
|
54
|
+
getUserAccessToken,
|
|
55
|
+
addListener,
|
|
56
|
+
removeListeners
|
|
57
|
+
} = legacy;
|
|
58
|
+
|
|
59
|
+
// Core bindings
|
|
60
|
+
RNSentiance.userLinkCallback = userLinkCallback;
|
|
61
|
+
RNSentiance.getUserId = getUserId;
|
|
62
|
+
RNSentiance.getVersion = getVersion;
|
|
63
|
+
RNSentiance.getUserActivity = getUserActivity;
|
|
64
|
+
RNSentiance.isTripOngoing = isTripOngoing;
|
|
65
|
+
RNSentiance.addTripMetadata = addTripMetadata;
|
|
66
|
+
RNSentiance.getInitState = getInitState;
|
|
67
|
+
RNSentiance.getSdkStatus = getSdkStatus;
|
|
68
|
+
RNSentiance.getDiskQuotaLimit = getDiskQuotaLimit;
|
|
69
|
+
RNSentiance.getDiskQuotaUsage = getDiskQuotaUsage;
|
|
70
|
+
RNSentiance.getMobileQuotaLimit = getMobileQuotaLimit;
|
|
71
|
+
RNSentiance.getMobileQuotaUsage = getMobileQuotaUsage;
|
|
72
|
+
RNSentiance.getWiFiQuotaLimit = getWiFiQuotaLimit;
|
|
73
|
+
RNSentiance.getWiFiQuotaUsage = getWiFiQuotaUsage;
|
|
74
|
+
RNSentiance.listenTripTimeout = listenTripTimeout;
|
|
75
|
+
RNSentiance.addUserMetadataField = async (label, value) => {
|
|
76
|
+
await addUserMetadataField(label, value);
|
|
77
|
+
return Promise.resolve(true);
|
|
78
|
+
};
|
|
79
|
+
RNSentiance.addUserMetadataFields = async (metadata) => {
|
|
80
|
+
await addUserMetadataFields(metadata);
|
|
81
|
+
return Promise.resolve(true);
|
|
82
|
+
};
|
|
83
|
+
RNSentiance.removeUserMetadataField = async (label) => {
|
|
84
|
+
await removeUserMetadataField(label);
|
|
85
|
+
return Promise.resolve(true);
|
|
86
|
+
};
|
|
87
|
+
RNSentiance.listenUserActivityUpdates = async () => {
|
|
88
|
+
await listenUserActivityUpdates();
|
|
89
|
+
return Promise.resolve(true);
|
|
90
|
+
};
|
|
91
|
+
RNSentiance.updateSdkNotification = async (title, message) => {
|
|
92
|
+
await updateSdkNotification(title, message);
|
|
93
|
+
return Promise.resolve(true);
|
|
94
|
+
};
|
|
95
|
+
RNSentiance.disableBatteryOptimization = async () => {
|
|
96
|
+
await disableBatteryOptimization();
|
|
97
|
+
return Promise.resolve(true);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Crash detection bindings
|
|
101
|
+
RNSentiance.listenVehicleCrashEvents = listenVehicleCrashEvents;
|
|
102
|
+
RNSentiance.invokeDummyVehicleCrash = invokeDummyVehicleCrash;
|
|
103
|
+
RNSentiance.isVehicleCrashDetectionSupported = isVehicleCrashDetectionSupported;
|
|
104
|
+
|
|
105
|
+
// Legacy bindings
|
|
106
|
+
RNSentiance.init = init;
|
|
107
|
+
RNSentiance.initWithUserLinkingEnabled = initWithUserLinkingEnabled;
|
|
108
|
+
RNSentiance.reset = reset;
|
|
109
|
+
RNSentiance.start = start;
|
|
110
|
+
RNSentiance.startWithStopDate = startWithStopDate;
|
|
111
|
+
RNSentiance.stop = stop;
|
|
112
|
+
RNSentiance.startTrip = startTrip;
|
|
113
|
+
RNSentiance.stopTrip = stopTrip;
|
|
114
|
+
RNSentiance.setValueForKey = setValueForKey;
|
|
115
|
+
RNSentiance.getValueForKey = getValueForKey;
|
|
116
|
+
RNSentiance.isThirdPartyLinked = isThirdPartyLinked;
|
|
117
|
+
RNSentiance.submitDetections = submitDetections;
|
|
118
|
+
RNSentiance.getUserAccessToken = getUserAccessToken;
|
|
119
|
+
RNSentiance.isNativeInitializationEnabled = isNativeInitializationEnabled;
|
|
120
|
+
RNSentiance.enableNativeInitialization = enableNativeInitialization;
|
|
121
|
+
RNSentiance.disableNativeInitialization = disableNativeInitialization;
|
|
122
|
+
RNSentiance.addListener = addListener
|
|
123
|
+
RNSentiance.removeListeners = removeListeners
|
|
124
|
+
|
|
125
|
+
export default RNSentiance;
|