hypertrack-sdk-react-native 8.2.2 → 9.1.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 +29 -1
- package/CONTRIBUTING.md +30 -110
- package/LICENSE +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 +28 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +251 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/LocationError.kt +9 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Result.kt +50 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkInitParams.kt +44 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +21 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +203 -0
- package/hypertrack-sdk-react-native.podspec +1 -1
- 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 +120 -0
- package/ios/common/SDKInitParams.swift +13 -0
- package/ios/common/SDKMethod.swift +14 -0
- package/ios/common/Serialization.swift +268 -0
- package/lib/commonjs/HyperTrack/HyperTrack.js +142 -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 +141 -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 +25 -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 +164 -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 +28 -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,43 @@ 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
|
+
automaticallyRequestPermissions: sdkInitParams.automaticallyRequestPermissions ?? true,
|
|
60
|
+
});
|
|
126
61
|
return new HyperTrack();
|
|
127
62
|
} catch (error: any) {
|
|
128
63
|
throw new Error(error.message);
|
|
@@ -130,76 +65,118 @@ export default class HyperTrack {
|
|
|
130
65
|
}
|
|
131
66
|
|
|
132
67
|
/**
|
|
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.
|
|
68
|
+
* Returns a string that is used to uniquely identify the device
|
|
142
69
|
*/
|
|
143
|
-
|
|
144
|
-
return HyperTrackSdk.
|
|
70
|
+
getDeviceId(): Promise<string> {
|
|
71
|
+
return HyperTrackSdk.getDeviceId().then(
|
|
72
|
+
(deviceId: DeviceId) => deviceId.value
|
|
73
|
+
);
|
|
145
74
|
}
|
|
146
75
|
|
|
147
76
|
/**
|
|
148
|
-
*
|
|
77
|
+
* Reflects availability of the device for the Nearby search
|
|
149
78
|
*
|
|
150
79
|
* @returns true when is available or false when unavailable
|
|
151
80
|
*/
|
|
152
81
|
isAvailable(): Promise<boolean> {
|
|
153
|
-
return HyperTrackSdk.isAvailable()
|
|
82
|
+
return HyperTrackSdk.isAvailable().then(
|
|
83
|
+
(isAvailable: IsAvailable) => isAvailable.value
|
|
84
|
+
);
|
|
154
85
|
}
|
|
155
86
|
|
|
156
87
|
/**
|
|
157
|
-
*
|
|
88
|
+
* Sets the availability of the device for the Nearby search
|
|
158
89
|
*
|
|
159
90
|
* @param availability true when is available or false when unavailable
|
|
160
91
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
92
|
+
setAvailability(isAvailable: boolean) {
|
|
93
|
+
HyperTrackSdk.setAvailability({
|
|
94
|
+
type: 'isAvailable',
|
|
95
|
+
value: isAvailable
|
|
96
|
+
} as IsAvailable);
|
|
163
97
|
}
|
|
164
98
|
|
|
165
99
|
/**
|
|
166
|
-
*
|
|
100
|
+
* Reflects the tracking intent for the device
|
|
101
|
+
*
|
|
167
102
|
* @return {boolean} Whether the user's movement data is getting tracked or not.
|
|
168
103
|
*/
|
|
169
104
|
isTracking(): Promise<boolean> {
|
|
170
|
-
return HyperTrackSdk.isTracking()
|
|
105
|
+
return HyperTrackSdk.isTracking().then(
|
|
106
|
+
(isTracking: IsTracking) => isTracking.value
|
|
107
|
+
);
|
|
171
108
|
}
|
|
172
109
|
|
|
173
110
|
/**
|
|
174
|
-
*
|
|
111
|
+
* Syncs the device state with the HyperTrack servers
|
|
175
112
|
*/
|
|
176
|
-
|
|
177
|
-
HyperTrackSdk.
|
|
113
|
+
sync() {
|
|
114
|
+
HyperTrackSdk.sync();
|
|
178
115
|
}
|
|
179
116
|
|
|
180
117
|
/**
|
|
181
|
-
*
|
|
118
|
+
* Expresses an intent to start location tracking for the device
|
|
182
119
|
*/
|
|
183
120
|
startTracking() {
|
|
184
121
|
HyperTrackSdk.startTracking();
|
|
185
122
|
}
|
|
186
123
|
|
|
187
124
|
/**
|
|
188
|
-
* Stops
|
|
125
|
+
* Stops location tracking immediately
|
|
189
126
|
*/
|
|
190
127
|
stopTracking() {
|
|
191
128
|
HyperTrackSdk.stopTracking();
|
|
192
129
|
}
|
|
193
130
|
|
|
194
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Reflects the current location of the user or an outage reason
|
|
133
|
+
*/
|
|
195
134
|
getLocation(): Promise<LocationError | Location> {
|
|
196
|
-
return HyperTrackSdk.getLocation()
|
|
135
|
+
return HyperTrackSdk.getLocation().then(
|
|
136
|
+
(locationResponse: LocationResponse) => {
|
|
137
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
197
140
|
}
|
|
198
141
|
|
|
199
142
|
/**
|
|
200
|
-
*
|
|
143
|
+
* Sets the name for the device
|
|
144
|
+
* @param {string} name
|
|
145
|
+
*/
|
|
146
|
+
setName(name: string) {
|
|
147
|
+
HyperTrackSdk.setName({
|
|
148
|
+
type: 'deviceName',
|
|
149
|
+
value: name
|
|
150
|
+
} as DeviceName)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sets the metadata for the device
|
|
155
|
+
* @param {Object} data - Metadata JSON
|
|
156
|
+
*/
|
|
157
|
+
setMetadata(data: Object) {
|
|
158
|
+
HyperTrackSdk.setMetadata(data);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adds a new geotag
|
|
163
|
+
* @param {Object} data - Geotad data JSON
|
|
164
|
+
* @returns current location if success or LocationError if failure
|
|
165
|
+
*/
|
|
166
|
+
addGeotag(data: Object): Promise<LocationError | Location> {
|
|
167
|
+
return HyperTrackSdk.addGeotag({
|
|
168
|
+
data
|
|
169
|
+
} as Geotag).then(
|
|
170
|
+
(locationResponse: LocationResponse) => {
|
|
171
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Subscribe to tracking errors
|
|
201
178
|
*
|
|
202
|
-
* @param listener
|
|
179
|
+
* @param listener
|
|
203
180
|
* @returns EmitterSubscription
|
|
204
181
|
* @example
|
|
205
182
|
* ```js
|
|
@@ -213,14 +190,16 @@ export default class HyperTrack {
|
|
|
213
190
|
* subscription.remove()
|
|
214
191
|
* ```
|
|
215
192
|
*/
|
|
216
|
-
subscribeToErrors(listener: (errors:
|
|
217
|
-
return EventEmitter.addListener(
|
|
193
|
+
subscribeToErrors(listener: (errors: HyperTrackError[]) => void) {
|
|
194
|
+
return EventEmitter.addListener(EVENT_ERROR, (rawErrors: HyperTrackErrorInternal[]) => {
|
|
195
|
+
listener(this.deserializeHyperTrackErrors(rawErrors))
|
|
196
|
+
});
|
|
218
197
|
}
|
|
219
198
|
|
|
220
199
|
/**
|
|
221
|
-
*
|
|
200
|
+
* Subscribe to tracking intent changes
|
|
222
201
|
*
|
|
223
|
-
* @param listener
|
|
202
|
+
* @param listener
|
|
224
203
|
* @returns EmitterSubscription
|
|
225
204
|
* @example
|
|
226
205
|
* ```js
|
|
@@ -235,39 +214,61 @@ export default class HyperTrack {
|
|
|
235
214
|
* ```
|
|
236
215
|
*/
|
|
237
216
|
subscribeToTracking(listener: (isTracking: boolean) => void) {
|
|
238
|
-
return EventEmitter.addListener(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*/
|
|
245
|
-
setDeviceName(name: string) {
|
|
246
|
-
HyperTrackSdk.setDeviceName(name);
|
|
217
|
+
return EventEmitter.addListener(
|
|
218
|
+
EVENT_TRACKING,
|
|
219
|
+
(isTracking: IsTracking) => {
|
|
220
|
+
listener(isTracking.value);
|
|
221
|
+
}
|
|
222
|
+
);
|
|
247
223
|
}
|
|
248
224
|
|
|
249
225
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
226
|
+
* Subscribe to availability changes
|
|
227
|
+
*
|
|
228
|
+
* @param listener
|
|
229
|
+
* @returns EmitterSubscription
|
|
230
|
+
* @example
|
|
231
|
+
* ```js
|
|
232
|
+
* const subscription = HyperTrack.subscribeToAvailability(isAvailable => {
|
|
233
|
+
* if (isAvailable) {
|
|
234
|
+
* // ... ready to go
|
|
235
|
+
* }
|
|
236
|
+
* })
|
|
237
|
+
*
|
|
238
|
+
* // later, to stop listening
|
|
239
|
+
* subscription.remove()
|
|
240
|
+
* ```
|
|
252
241
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
242
|
+
subscribeToAvailability(listener: (isAvailable: boolean) => void) {
|
|
243
|
+
return EventEmitter.addListener(
|
|
244
|
+
EVENT_AVAILABILITY,
|
|
245
|
+
(isAvailable: IsAvailable) => {
|
|
246
|
+
listener(isAvailable.value);
|
|
247
|
+
}
|
|
248
|
+
);
|
|
255
249
|
}
|
|
256
250
|
|
|
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');
|
|
251
|
+
/** @ignore */
|
|
252
|
+
private deserializeHyperTrackErrors(errors: HyperTrackErrorInternal[]): HyperTrackError[] {
|
|
253
|
+
return errors.map((error: HyperTrackErrorInternal) => HyperTrackError[error.value as keyof typeof HyperTrackError])
|
|
264
254
|
}
|
|
265
255
|
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
/** @ignore */
|
|
257
|
+
private deserializeLocationResponse(response: LocationResponse): Location | LocationError {
|
|
258
|
+
switch(response.type) {
|
|
259
|
+
case "success":
|
|
260
|
+
return response.value
|
|
261
|
+
case "failure":
|
|
262
|
+
switch(response.value.type) {
|
|
263
|
+
case "notRunning":
|
|
264
|
+
case "starting":
|
|
265
|
+
return response.value
|
|
266
|
+
case "errors":
|
|
267
|
+
return {
|
|
268
|
+
type: "errors",
|
|
269
|
+
value: this.deserializeHyperTrackErrors(response.value.value)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
272
273
|
}
|
|
273
274
|
}
|
|
@@ -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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameters for initializing the SDK.
|
|
3
|
+
*/
|
|
4
|
+
export type SdkInitParams = {
|
|
5
|
+
/**
|
|
6
|
+
* Enable debug logging.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
loggingEnabled?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Allow mock locations to pass through and don’t send mock location outage.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
allowMockLocations?: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Require Background location permissions while requiring permissions on Android.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
requireBackgroundTrackingPermission?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Automatically request permissions on starting tracking on iOS.
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
automaticallyRequestPermissions?: boolean;
|
|
28
|
+
};
|
|
@@ -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'
|