hypertrack-sdk-react-native 8.2.1 → 9.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/CHANGELOG.md +28 -1
- package/CONTRIBUTING.md +32 -110
- package/{LICENSE → LICENSE.md} +2 -0
- package/README.md +20 -40
- package/android/build.gradle +112 -113
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +209 -0
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackSdkPackage.kt +2 -4
- package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +88 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Geotag.kt +9 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackError.kt +27 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +243 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/LocationError.kt +9 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Result.kt +48 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkInitParams.kt +46 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +20 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +196 -0
- package/hypertrack-sdk-react-native.podspec +2 -2
- package/ios/HyperTrackReactNativePlugin.m +54 -0
- package/ios/HyperTrackReactNativePlugin.swift +253 -0
- package/ios/HyperTrackSdk-Bridging-Header.h +2 -0
- package/ios/HyperTrackSdk.xcodeproj/project.pbxproj +8 -11
- package/ios/common/DictionaryDecoder.swift +28 -0
- package/ios/common/HyperTrackError.swift +20 -0
- package/ios/common/HyperTrackSDKWrapper.swift +118 -0
- package/ios/common/SDKInitParams.swift +11 -0
- package/ios/common/SDKMethod.swift +14 -0
- package/ios/common/Serialization.swift +270 -0
- package/lib/commonjs/HyperTrack/HyperTrack.js +141 -142
- package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js +31 -0
- package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/Location.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/Location.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/LocationError.js +6 -0
- package/lib/commonjs/HyperTrack/data_types/LocationError.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceId.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceId.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/IsAvailable.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/IsAvailable.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/IsTracking.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/IsTracking.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/LocationErrorInternal.js +6 -0
- package/lib/commonjs/HyperTrack/data_types/internal/LocationErrorInternal.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/LocationResponse.js +6 -0
- package/lib/commonjs/HyperTrack/data_types/internal/LocationResponse.js.map +1 -0
- package/lib/commonjs/index.js +28 -17
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/HyperTrack/HyperTrack.js +140 -134
- package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/module/HyperTrack/data_types/HyperTrackError.js +24 -0
- package/lib/module/HyperTrack/data_types/HyperTrackError.js.map +1 -0
- package/lib/module/HyperTrack/data_types/Location.js +2 -0
- package/lib/module/HyperTrack/data_types/Location.js.map +1 -0
- package/lib/module/HyperTrack/data_types/LocationError.js +2 -0
- package/lib/module/HyperTrack/data_types/LocationError.js.map +1 -0
- package/lib/module/HyperTrack/data_types/SdkInitParams.js +2 -0
- package/lib/module/HyperTrack/data_types/SdkInitParams.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/DeviceId.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/DeviceId.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/DeviceName.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/DeviceName.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/Geotag.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/Geotag.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/IsAvailable.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/IsAvailable.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/IsTracking.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/IsTracking.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/LocationErrorInternal.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/LocationErrorInternal.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/LocationResponse.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/LocationResponse.js.map +1 -0
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/HyperTrack/HyperTrack.d.ts +66 -100
- package/lib/typescript/HyperTrack/data_types/HyperTrackError.d.ts +20 -0
- package/lib/typescript/HyperTrack/data_types/Location.d.ts +7 -0
- package/lib/typescript/HyperTrack/data_types/LocationError.d.ts +8 -0
- package/lib/typescript/HyperTrack/data_types/SdkInitParams.d.ts +5 -0
- package/lib/typescript/HyperTrack/data_types/internal/DeviceId.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/DeviceName.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/Geotag.d.ts +3 -0
- package/lib/typescript/HyperTrack/data_types/internal/HyperTrackErrorInternal.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/IsAvailable.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/IsTracking.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/LocationErrorInternal.d.ts +12 -0
- package/lib/typescript/HyperTrack/data_types/internal/LocationResponse.d.ts +11 -0
- package/lib/typescript/index.d.ts +4 -1
- package/package.json +156 -156
- package/src/HyperTrack/HyperTrack.ts +163 -163
- package/src/HyperTrack/data_types/HyperTrackError.ts +22 -0
- package/src/HyperTrack/data_types/Location.ts +7 -0
- package/src/HyperTrack/data_types/LocationError.ts +11 -0
- package/src/HyperTrack/data_types/SdkInitParams.ts +5 -0
- package/src/HyperTrack/data_types/internal/DeviceId.ts +4 -0
- package/src/HyperTrack/data_types/internal/DeviceName.ts +4 -0
- package/src/HyperTrack/data_types/internal/Geotag.ts +3 -0
- package/src/HyperTrack/data_types/internal/HyperTrackErrorInternal.ts +4 -0
- package/src/HyperTrack/data_types/internal/IsAvailable.ts +4 -0
- package/src/HyperTrack/data_types/internal/IsTracking.ts +4 -0
- package/src/HyperTrack/data_types/internal/LocationErrorInternal.ts +14 -0
- package/src/HyperTrack/data_types/internal/LocationResponse.ts +14 -0
- package/src/index.tsx +4 -7
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackModule.kt +0 -284
- package/ios/HyperTrack.h +0 -7
- package/ios/HyperTrack.m +0 -384
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
|
|
2
|
+
import { HyperTrackError } from './data_types/HyperTrackError';
|
|
3
|
+
import type { IsAvailable } from './data_types/internal/IsAvailable';
|
|
4
|
+
import type { IsTracking } from './data_types/internal/IsTracking';
|
|
5
|
+
import type { LocationResponse } from './data_types/internal/LocationResponse';
|
|
6
|
+
import type { Location } from './data_types/Location';
|
|
7
|
+
import type { LocationError } from './data_types/LocationError';
|
|
8
|
+
import type { SdkInitParams } from './data_types/SdkInitParams';
|
|
9
|
+
import type { DeviceId } from './data_types/internal/DeviceId';
|
|
10
|
+
import type { Geotag } from './data_types/internal/Geotag';
|
|
11
|
+
import type { DeviceName } from './data_types/internal/DeviceName';
|
|
12
|
+
import type { HyperTrackErrorInternal } from './data_types/internal/HyperTrackErrorInternal';
|
|
13
|
+
|
|
14
|
+
const EVENT_TRACKING = 'onTrackingChanged';
|
|
15
|
+
const EVENT_AVAILABILITY = 'onAvailabilityChanged';
|
|
16
|
+
const EVENT_ERROR = 'onError';
|
|
2
17
|
|
|
3
18
|
const LINKING_ERROR =
|
|
4
19
|
`The package 'hypertrack-sdk-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -6,123 +21,42 @@ const LINKING_ERROR =
|
|
|
6
21
|
'- You rebuilt the app after installing the package\n' +
|
|
7
22
|
'- You are not using Expo managed workflow\n';
|
|
8
23
|
|
|
9
|
-
const HyperTrackSdk = NativeModules.
|
|
10
|
-
? NativeModules.
|
|
24
|
+
const HyperTrackSdk = NativeModules.HyperTrackReactNativePlugin
|
|
25
|
+
? NativeModules.HyperTrackReactNativePlugin
|
|
11
26
|
: new Proxy(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
{},
|
|
28
|
+
{
|
|
29
|
+
get() {
|
|
30
|
+
throw new Error(LINKING_ERROR);
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
);
|
|
19
34
|
|
|
20
35
|
const EventEmitter = new NativeEventEmitter(HyperTrackSdk);
|
|
21
36
|
|
|
22
|
-
export enum SDKError {
|
|
23
|
-
/**
|
|
24
|
-
* An error that we couldn't recognize.
|
|
25
|
-
*/
|
|
26
|
-
GENERAL = 0,
|
|
27
|
-
/**
|
|
28
|
-
* Publishable key is invalid. Check your key on hypertrack dashboard setup.
|
|
29
|
-
*/
|
|
30
|
-
INVALID_PUBLISHABLE_KEY = 1,
|
|
31
|
-
/**
|
|
32
|
-
* Your free trial ended or account was not renewed. Check your account on hypertrack dashboard.
|
|
33
|
-
*/
|
|
34
|
-
AUTHORIZATION_FAILED = 2,
|
|
35
|
-
/**
|
|
36
|
-
* Tracking won't start due to denied (or absent) permission.
|
|
37
|
-
*/
|
|
38
|
-
PERMISSION_DENIED = 3,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* A base interface for errors in SDK.
|
|
43
|
-
*/
|
|
44
|
-
export type Error = {
|
|
45
|
-
code: SDKError;
|
|
46
|
-
message?: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Interface for accessing adding geotag result.
|
|
51
|
-
*/
|
|
52
|
-
export enum GeotagError {
|
|
53
|
-
/** Expected location is not supported on this platform */
|
|
54
|
-
PLATFORM_NOT_SUPPORTED = 0,
|
|
55
|
-
/** Expected vs actual location difference is greater then required */
|
|
56
|
-
LOCATION_MISMATCH = 1,
|
|
57
|
-
/** SDK can't get actual location from OS sensors */
|
|
58
|
-
LOCATION_NOT_AVAILABLE = 2,
|
|
59
|
-
/** Invalid arguments */
|
|
60
|
-
INVALID_ARGUMENTS = 3,
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface Location {
|
|
64
|
-
location: {
|
|
65
|
-
latitude: number;
|
|
66
|
-
longitude: number;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export enum LocationError {
|
|
71
|
-
// The user has not chosen whether the app can use location services.
|
|
72
|
-
// SDK automatically asked for permissions.
|
|
73
|
-
LOCATION_PERMISSIONS_NOT_DETERMINED = 'location_permissions_not_determined',
|
|
74
|
-
// The user has not chosen whether the app can use location services.
|
|
75
|
-
// SDK can't ask for permissions in background.
|
|
76
|
-
LOCATION_PERMISSIONS_CANT_BE_ASKED_IN_BACKGROUND = 'location_permissions_cant_be_asked_in_background',
|
|
77
|
-
// Can't start tracking in background with When In Use location
|
|
78
|
-
// permissions. SDK will automatically start tracking when app will return
|
|
79
|
-
// to foreground.
|
|
80
|
-
LOCATION_PERMISSIONS_INSUFFICIENT_FOR_BACKGROUND = 'location_permissions_insufficient_for_background',
|
|
81
|
-
// The app is not authorized to use location services.
|
|
82
|
-
LOCATION_PERMISSIONS_RESTRICTED = 'location_permissions_restricted',
|
|
83
|
-
// The user didn't grant precise location permissions or downgraded permissions to imprecise.
|
|
84
|
-
LOCATION_PERMISSIONS_REDUCED_ACCURACY = 'location_permissions_reduced_accuracy',
|
|
85
|
-
// The user denied location permissions.
|
|
86
|
-
LOCATION_PERMISSIONS_DENIED = 'location_permissions_denied',
|
|
87
|
-
// The user disabled location services systemwide.
|
|
88
|
-
LOCATION_SERVICES_DISABLED = 'location_services_disabled',
|
|
89
|
-
// The user has not chosen whether the app can use motion activity
|
|
90
|
-
// services. SDK automatically asked for permissions.
|
|
91
|
-
MOTION_ACTIVITY_PERMISSIONS_NOT_DETERMINED = 'motion_activity_permissions_not_determined',
|
|
92
|
-
// The user has not chosen whether the app can use motion activity
|
|
93
|
-
// services. SDK can't ask for permissions in background.
|
|
94
|
-
MOTION_ACTIVITY_PERMISSIONS_CANT_BE_ASKED_IN_BACKGROUND = 'motion_activity_permissions_cant_be_asked_in_background',
|
|
95
|
-
// Motion activity permissions denied after SDK's initialization. Granting
|
|
96
|
-
// them will restart the app, so in effect, they are denied during this app's
|
|
97
|
-
// session.
|
|
98
|
-
MOTION_ACTIVITY_PERMISSIONS_DENIED = 'motion_activity_permissions_denied',
|
|
99
|
-
// The user disabled motion services systemwide.
|
|
100
|
-
MOTION_ACTIVITY_SERVICES_DISABLED = 'motion_activity_services_disabled',
|
|
101
|
-
// The SDK is not collecting locations because it's either not tracking or is unavailable.
|
|
102
|
-
NOT_RUNNING = 'not_running',
|
|
103
|
-
// GPS satellites are not in view.
|
|
104
|
-
GPS_SIGNAL_LOST = 'gps_signal_lost',
|
|
105
|
-
// The SDK started collecting locations and is waiting for OS location services to respond.
|
|
106
|
-
STARTING = 'starting',
|
|
107
|
-
// The user enabled mock location app while mocking locations is prohibited.
|
|
108
|
-
LOCATION_MOCKED = 'location_mocked',
|
|
109
|
-
}
|
|
110
|
-
|
|
111
37
|
export default class HyperTrack {
|
|
112
|
-
constructor() {
|
|
38
|
+
private constructor() {
|
|
113
39
|
return this;
|
|
114
40
|
}
|
|
115
41
|
|
|
116
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Creates an SDK instance
|
|
44
|
+
*
|
|
45
|
+
* @param publishableKey publishable key provided in HyperTrack’s dashboard setup page
|
|
46
|
+
* @param sdkInitParams
|
|
47
|
+
* @returns HyperTrack instance
|
|
48
|
+
*/
|
|
49
|
+
static async initialize(
|
|
117
50
|
publishableKey: string,
|
|
118
|
-
|
|
119
|
-
) {
|
|
51
|
+
sdkInitParams: SdkInitParams = {}
|
|
52
|
+
): Promise<HyperTrack> {
|
|
120
53
|
try {
|
|
121
|
-
await HyperTrackSdk.
|
|
54
|
+
await HyperTrackSdk.initializeSdk({
|
|
122
55
|
publishableKey,
|
|
123
|
-
false,
|
|
124
|
-
|
|
125
|
-
|
|
56
|
+
loggingEnabled: sdkInitParams.loggingEnabled ?? false,
|
|
57
|
+
allowMockLocations: sdkInitParams.allowMockLocations ?? false,
|
|
58
|
+
requireBackgroundTrackingPermission: sdkInitParams.requireBackgroundTrackingPermission ?? false,
|
|
59
|
+
});
|
|
126
60
|
return new HyperTrack();
|
|
127
61
|
} catch (error: any) {
|
|
128
62
|
throw new Error(error.message);
|
|
@@ -130,76 +64,118 @@ export default class HyperTrack {
|
|
|
130
64
|
}
|
|
131
65
|
|
|
132
66
|
/**
|
|
133
|
-
*
|
|
134
|
-
* production build.
|
|
135
|
-
*/
|
|
136
|
-
static enableDebugLogging(enable: boolean) {
|
|
137
|
-
HyperTrackSdk.enableDebugLogging(enable);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Returns a string which is used by HyperTrack to uniquely identify the user.
|
|
67
|
+
* Returns a string that is used to uniquely identify the device
|
|
142
68
|
*/
|
|
143
|
-
|
|
144
|
-
return HyperTrackSdk.
|
|
69
|
+
getDeviceId(): Promise<string> {
|
|
70
|
+
return HyperTrackSdk.getDeviceId().then(
|
|
71
|
+
(deviceId: DeviceId) => deviceId.value
|
|
72
|
+
);
|
|
145
73
|
}
|
|
146
74
|
|
|
147
75
|
/**
|
|
148
|
-
*
|
|
76
|
+
* Reflects availability of the device for the Nearby search
|
|
149
77
|
*
|
|
150
78
|
* @returns true when is available or false when unavailable
|
|
151
79
|
*/
|
|
152
80
|
isAvailable(): Promise<boolean> {
|
|
153
|
-
return HyperTrackSdk.isAvailable()
|
|
81
|
+
return HyperTrackSdk.isAvailable().then(
|
|
82
|
+
(isAvailable: IsAvailable) => isAvailable.value
|
|
83
|
+
);
|
|
154
84
|
}
|
|
155
85
|
|
|
156
86
|
/**
|
|
157
|
-
*
|
|
87
|
+
* Sets the availability of the device for the Nearby search
|
|
158
88
|
*
|
|
159
89
|
* @param availability true when is available or false when unavailable
|
|
160
90
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
91
|
+
setAvailability(isAvailable: boolean) {
|
|
92
|
+
HyperTrackSdk.setAvailability({
|
|
93
|
+
type: 'isAvailable',
|
|
94
|
+
value: isAvailable
|
|
95
|
+
} as IsAvailable);
|
|
163
96
|
}
|
|
164
97
|
|
|
165
98
|
/**
|
|
166
|
-
*
|
|
99
|
+
* Reflects the tracking intent for the device
|
|
100
|
+
*
|
|
167
101
|
* @return {boolean} Whether the user's movement data is getting tracked or not.
|
|
168
102
|
*/
|
|
169
103
|
isTracking(): Promise<boolean> {
|
|
170
|
-
return HyperTrackSdk.isTracking()
|
|
104
|
+
return HyperTrackSdk.isTracking().then(
|
|
105
|
+
(isTracking: IsTracking) => isTracking.value
|
|
106
|
+
);
|
|
171
107
|
}
|
|
172
108
|
|
|
173
109
|
/**
|
|
174
|
-
*
|
|
110
|
+
* Syncs the device state with the HyperTrack servers
|
|
175
111
|
*/
|
|
176
|
-
|
|
177
|
-
HyperTrackSdk.
|
|
112
|
+
sync() {
|
|
113
|
+
HyperTrackSdk.sync();
|
|
178
114
|
}
|
|
179
115
|
|
|
180
116
|
/**
|
|
181
|
-
*
|
|
117
|
+
* Expresses an intent to start location tracking for the device
|
|
182
118
|
*/
|
|
183
119
|
startTracking() {
|
|
184
120
|
HyperTrackSdk.startTracking();
|
|
185
121
|
}
|
|
186
122
|
|
|
187
123
|
/**
|
|
188
|
-
* Stops
|
|
124
|
+
* Stops location tracking immediately
|
|
189
125
|
*/
|
|
190
126
|
stopTracking() {
|
|
191
127
|
HyperTrackSdk.stopTracking();
|
|
192
128
|
}
|
|
193
129
|
|
|
194
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Reflects the current location of the user or an outage reason
|
|
132
|
+
*/
|
|
195
133
|
getLocation(): Promise<LocationError | Location> {
|
|
196
|
-
return HyperTrackSdk.getLocation()
|
|
134
|
+
return HyperTrackSdk.getLocation().then(
|
|
135
|
+
(locationResponse: LocationResponse) => {
|
|
136
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
197
139
|
}
|
|
198
140
|
|
|
199
141
|
/**
|
|
200
|
-
*
|
|
142
|
+
* Sets the name for the device
|
|
143
|
+
* @param {string} name
|
|
144
|
+
*/
|
|
145
|
+
setName(name: string) {
|
|
146
|
+
HyperTrackSdk.setName({
|
|
147
|
+
type: 'deviceName',
|
|
148
|
+
value: name
|
|
149
|
+
} as DeviceName)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Sets the metadata for the device
|
|
154
|
+
* @param {Object} data - Metadata JSON
|
|
155
|
+
*/
|
|
156
|
+
setMetadata(data: Object) {
|
|
157
|
+
HyperTrackSdk.setMetadata(data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Adds a new geotag
|
|
162
|
+
* @param {Object} data - Geotad data JSON
|
|
163
|
+
* @returns current location if success or LocationError if failure
|
|
164
|
+
*/
|
|
165
|
+
addGeotag(data: Object): Promise<LocationError | Location> {
|
|
166
|
+
return HyperTrackSdk.addGeotag({
|
|
167
|
+
data
|
|
168
|
+
} as Geotag).then(
|
|
169
|
+
(locationResponse: LocationResponse) => {
|
|
170
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Subscribe to tracking errors
|
|
201
177
|
*
|
|
202
|
-
* @param listener
|
|
178
|
+
* @param listener
|
|
203
179
|
* @returns EmitterSubscription
|
|
204
180
|
* @example
|
|
205
181
|
* ```js
|
|
@@ -213,14 +189,16 @@ export default class HyperTrack {
|
|
|
213
189
|
* subscription.remove()
|
|
214
190
|
* ```
|
|
215
191
|
*/
|
|
216
|
-
subscribeToErrors(listener: (errors:
|
|
217
|
-
return EventEmitter.addListener(
|
|
192
|
+
subscribeToErrors(listener: (errors: HyperTrackError[]) => void) {
|
|
193
|
+
return EventEmitter.addListener(EVENT_ERROR, (rawErrors: HyperTrackErrorInternal[]) => {
|
|
194
|
+
listener(this.deserializeHyperTrackErrors(rawErrors))
|
|
195
|
+
});
|
|
218
196
|
}
|
|
219
197
|
|
|
220
198
|
/**
|
|
221
|
-
*
|
|
199
|
+
* Subscribe to tracking intent changes
|
|
222
200
|
*
|
|
223
|
-
* @param listener
|
|
201
|
+
* @param listener
|
|
224
202
|
* @returns EmitterSubscription
|
|
225
203
|
* @example
|
|
226
204
|
* ```js
|
|
@@ -235,39 +213,61 @@ export default class HyperTrack {
|
|
|
235
213
|
* ```
|
|
236
214
|
*/
|
|
237
215
|
subscribeToTracking(listener: (isTracking: boolean) => void) {
|
|
238
|
-
return EventEmitter.addListener(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*/
|
|
245
|
-
setDeviceName(name: string) {
|
|
246
|
-
HyperTrackSdk.setDeviceName(name);
|
|
216
|
+
return EventEmitter.addListener(
|
|
217
|
+
EVENT_TRACKING,
|
|
218
|
+
(isTracking: IsTracking) => {
|
|
219
|
+
listener(isTracking.value);
|
|
220
|
+
}
|
|
221
|
+
);
|
|
247
222
|
}
|
|
248
223
|
|
|
249
224
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
225
|
+
* Subscribe to availability changes
|
|
226
|
+
*
|
|
227
|
+
* @param listener
|
|
228
|
+
* @returns EmitterSubscription
|
|
229
|
+
* @example
|
|
230
|
+
* ```js
|
|
231
|
+
* const subscription = HyperTrack.subscribeToAvailability(isAvailable => {
|
|
232
|
+
* if (isAvailable) {
|
|
233
|
+
* // ... ready to go
|
|
234
|
+
* }
|
|
235
|
+
* })
|
|
236
|
+
*
|
|
237
|
+
* // later, to stop listening
|
|
238
|
+
* subscription.remove()
|
|
239
|
+
* ```
|
|
252
240
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
241
|
+
subscribeToAvailability(listener: (isAvailable: boolean) => void) {
|
|
242
|
+
return EventEmitter.addListener(
|
|
243
|
+
EVENT_AVAILABILITY,
|
|
244
|
+
(isAvailable: IsAvailable) => {
|
|
245
|
+
listener(isAvailable.value);
|
|
246
|
+
}
|
|
247
|
+
);
|
|
255
248
|
}
|
|
256
249
|
|
|
257
|
-
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
* @param {Object} _data - Include anything that can be parsed into JSON.
|
|
261
|
-
*/
|
|
262
|
-
setTripMarker(_data: Object) {
|
|
263
|
-
throw new Error('Deprecated');
|
|
250
|
+
/** @ignore */
|
|
251
|
+
private deserializeHyperTrackErrors(errors: HyperTrackErrorInternal[]): HyperTrackError[] {
|
|
252
|
+
return errors.map((error: HyperTrackErrorInternal) => HyperTrackError[error.value as keyof typeof HyperTrackError])
|
|
264
253
|
}
|
|
265
254
|
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
255
|
+
/** @ignore */
|
|
256
|
+
private deserializeLocationResponse(response: LocationResponse): Location | LocationError {
|
|
257
|
+
switch(response.type) {
|
|
258
|
+
case "success":
|
|
259
|
+
return response.value
|
|
260
|
+
case "failure":
|
|
261
|
+
switch(response.value.type) {
|
|
262
|
+
case "notRunning":
|
|
263
|
+
case "starting":
|
|
264
|
+
return response.value
|
|
265
|
+
case "errors":
|
|
266
|
+
return {
|
|
267
|
+
type: "errors",
|
|
268
|
+
value: this.deserializeHyperTrackErrors(response.value.value)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// enum naming convention is ignored to make datatype sync
|
|
2
|
+
// across platforms easier
|
|
3
|
+
export enum HyperTrackError {
|
|
4
|
+
gpsSignalLost = "gpsSignalLost",
|
|
5
|
+
locationMocked = "locationMocked",
|
|
6
|
+
locationPermissionsDenied = "locationPermissionsDenied",
|
|
7
|
+
locationPermissionsInsufficientForBackground = "locationPermissionsInsufficientForBackground",
|
|
8
|
+
locationPermissionsNotDetermined = "locationPermissionsNotDetermined",
|
|
9
|
+
locationPermissionsReducedAccuracy = "locationPermissionsReducedAccuracy",
|
|
10
|
+
locationPermissionsProvisional = "locationPermissionsProvisional",
|
|
11
|
+
locationPermissionsRestricted = "locationPermissionsRestricted",
|
|
12
|
+
locationServicesDisabled = "locationServicesDisabled",
|
|
13
|
+
locationServicesUnavailable = "locationServicesUnavailable",
|
|
14
|
+
motionActivityPermissionsNotDetermined = "motionActivityPermissionsNotDetermined",
|
|
15
|
+
motionActivityPermissionsDenied = "motionActivityPermissionsDenied",
|
|
16
|
+
motionActivityServicesDisabled = "motionActivityServicesDisabled",
|
|
17
|
+
motionActivityServicesUnavailable = "motionActivityServicesUnavailable",
|
|
18
|
+
motionActivityPermissionsRestricted = "motionActivityPermissionsRestricted",
|
|
19
|
+
networkConnectionUnavailable = "networkConnectionUnavailable",
|
|
20
|
+
invalidPublishableKey = "invalidPublishableKey",
|
|
21
|
+
blockedFromRunning = "blockedFromRunning"
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HyperTrackError } from './HyperTrackError';
|
|
2
|
+
import type { NotRunning, Starting } from './internal/LocationErrorInternal';
|
|
3
|
+
|
|
4
|
+
export { NotRunning, Starting }
|
|
5
|
+
|
|
6
|
+
export type Errors = {
|
|
7
|
+
type: 'errors';
|
|
8
|
+
value: HyperTrackError[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type LocationError = NotRunning | Starting | Errors;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HyperTrackErrorInternal } from './HyperTrackErrorInternal';
|
|
2
|
+
|
|
3
|
+
export type NotRunning = {
|
|
4
|
+
type: 'notRunning';
|
|
5
|
+
};
|
|
6
|
+
export type Starting = {
|
|
7
|
+
type: 'starting';
|
|
8
|
+
};
|
|
9
|
+
export type ErrorsInternal = {
|
|
10
|
+
type: 'errors';
|
|
11
|
+
value: HyperTrackErrorInternal[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type LocationErrorInternal = NotRunning | Starting | ErrorsInternal;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Location } from '../Location';
|
|
2
|
+
import type { LocationErrorInternal } from './LocationErrorInternal';
|
|
3
|
+
|
|
4
|
+
export type LocationSuccess = {
|
|
5
|
+
type: 'success';
|
|
6
|
+
value: Location;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type LocationFailure = {
|
|
10
|
+
type: 'failure';
|
|
11
|
+
value: LocationErrorInternal;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type LocationResponse = LocationSuccess | LocationFailure;
|
package/src/index.tsx
CHANGED
|
@@ -2,10 +2,7 @@ import HyperTrack from './HyperTrack/HyperTrack';
|
|
|
2
2
|
export default HyperTrack;
|
|
3
3
|
export { HyperTrack };
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
GeotagError,
|
|
10
|
-
LocationError,
|
|
11
|
-
} from './HyperTrack/HyperTrack';
|
|
5
|
+
export { HyperTrackError } from './HyperTrack/data_types/HyperTrackError';
|
|
6
|
+
export { LocationError, NotRunning, Starting, Errors } from './HyperTrack/data_types/LocationError';
|
|
7
|
+
export { Location } from './HyperTrack/data_types/Location';
|
|
8
|
+
export { SdkInitParams } from './HyperTrack/data_types/SdkInitParams'
|