hypertrack-sdk-react-native 10.0.3 → 11.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 +48 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +2 -2
- package/android/build.gradle +5 -1
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +80 -115
- package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +23 -3
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +87 -220
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +11 -9
- package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +216 -132
- package/android/src/main/java/com/reactnativehypertracksdk/common/{Result.kt → WrapperResult.kt} +9 -7
- package/hypertrack-sdk-react-native.podspec +1 -1
- package/ios/HyperTrackReactNativePlugin.m +13 -11
- package/ios/HyperTrackReactNativePlugin.swift +141 -114
- package/ios/common/DictionaryDecoder.swift +5 -5
- package/ios/common/HyperTrackSDKWrapper.swift +44 -80
- package/ios/common/SDKMethod.swift +13 -12
- package/ios/common/Serialization.swift +190 -245
- package/lib/commonjs/HyperTrack/HyperTrack.js +224 -124
- package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js +13 -17
- package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/internal/Metadata.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/Metadata.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/Name.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/Name.js.map +1 -0
- package/lib/commonjs/index.js +0 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/HyperTrack/HyperTrack.js +224 -124
- package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/module/HyperTrack/data_types/HyperTrackError.js +13 -17
- package/lib/module/HyperTrack/data_types/HyperTrackError.js.map +1 -1
- package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -1
- package/lib/module/HyperTrack/data_types/internal/Metadata.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/Metadata.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/Name.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/Name.js.map +1 -0
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/HyperTrack/HyperTrack.d.ts +106 -54
- package/lib/typescript/HyperTrack/data_types/HyperTrackError.d.ts +59 -17
- package/lib/typescript/HyperTrack/data_types/internal/HyperTrackErrorInternal.d.ts +1 -1
- package/lib/typescript/HyperTrack/data_types/internal/Metadata.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/Name.d.ts +7 -0
- package/lib/typescript/index.d.ts +0 -1
- package/package.json +1 -1
- package/src/HyperTrack/HyperTrack.ts +281 -161
- package/src/HyperTrack/data_types/HyperTrackError.ts +73 -18
- package/src/HyperTrack/data_types/internal/HyperTrackErrorInternal.ts +3 -3
- package/src/HyperTrack/data_types/internal/Metadata.ts +4 -0
- package/src/HyperTrack/data_types/internal/Name.ts +7 -0
- package/src/index.tsx +0 -1
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackError.kt +0 -28
- package/android/src/main/java/com/reactnativehypertracksdk/common/LocationError.kt +0 -9
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkInitParams.kt +0 -44
- package/ios/common/HyperTrackError.swift +0 -20
- package/ios/common/SDKInitParams.swift +0 -13
- package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js +0 -2
- package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js.map +0 -1
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js +0 -2
- package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js.map +0 -1
- package/lib/module/HyperTrack/data_types/SdkInitParams.js +0 -2
- package/lib/module/HyperTrack/data_types/SdkInitParams.js.map +0 -1
- package/lib/module/HyperTrack/data_types/internal/DeviceName.js +0 -2
- package/lib/module/HyperTrack/data_types/internal/DeviceName.js.map +0 -1
- package/lib/typescript/HyperTrack/data_types/SdkInitParams.d.ts +0 -25
- package/lib/typescript/HyperTrack/data_types/internal/DeviceName.d.ts +0 -4
- package/src/HyperTrack/data_types/SdkInitParams.ts +0 -28
- package/src/HyperTrack/data_types/internal/DeviceName.ts +0 -4
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
Platform,
|
|
4
|
+
NativeEventEmitter,
|
|
5
|
+
EmitterSubscription,
|
|
6
|
+
} from 'react-native';
|
|
2
7
|
import { HyperTrackError } from './data_types/HyperTrackError';
|
|
3
8
|
import type { IsAvailable } from './data_types/internal/IsAvailable';
|
|
4
9
|
import type { IsTracking } from './data_types/internal/IsTracking';
|
|
5
10
|
import type { Location } from './data_types/Location';
|
|
6
11
|
import type { LocationError } from './data_types/LocationError';
|
|
7
|
-
import type { SdkInitParams } from './data_types/SdkInitParams';
|
|
8
12
|
import type { DeviceId } from './data_types/internal/DeviceId';
|
|
9
13
|
import type { GeotagData } from './data_types/internal/GeotagData';
|
|
10
|
-
import type {
|
|
14
|
+
import type { Name } from './data_types/internal/Name';
|
|
11
15
|
import type { HyperTrackErrorInternal } from './data_types/internal/HyperTrackErrorInternal';
|
|
12
|
-
import type { Result } from './data_types/Result';
|
|
13
16
|
import type { LocationWithDeviation } from './data_types/LocationWithDeviation';
|
|
14
17
|
import type { LocationErrorInternal } from './data_types/internal/LocationErrorInternal';
|
|
18
|
+
import type { Result } from './data_types/Result';
|
|
15
19
|
import type { LocationInternal } from './data_types/internal/LocationInternal';
|
|
16
20
|
import type { LocationWithDeviationInternal } from './data_types/internal/LocationWithDeviationInternal';
|
|
21
|
+
import type { Metadata } from './data_types/internal/Metadata';
|
|
17
22
|
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
23
|
+
const EVENT_ERRORS = 'errors';
|
|
24
|
+
const EVENT_IS_AVAILABLE = 'isAvailable';
|
|
25
|
+
const EVENT_IS_TRACKING = 'isTracking';
|
|
26
|
+
const EVENT_LOCATE = 'locate';
|
|
27
|
+
const EVENT_LOCATION = 'location';
|
|
21
28
|
|
|
22
29
|
const LINKING_ERROR =
|
|
23
30
|
`The package 'hypertrack-sdk-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -39,193 +46,234 @@ const HyperTrackSdk = NativeModules.HyperTrackReactNativePlugin
|
|
|
39
46
|
const EventEmitter = new NativeEventEmitter(HyperTrackSdk);
|
|
40
47
|
|
|
41
48
|
export default class HyperTrack {
|
|
42
|
-
private
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
49
|
+
private static locateSubscription: EmitterSubscription | undefined;
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
|
-
*
|
|
52
|
+
* Adds a new geotag
|
|
48
53
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
51
|
-
* @returns HyperTrack instance
|
|
54
|
+
* @param {Object} data - Geotad data JSON
|
|
55
|
+
* @returns current location if success or LocationError if failure
|
|
52
56
|
*/
|
|
53
|
-
static async
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
static async addGeotag(
|
|
58
|
+
data: Object
|
|
59
|
+
): Promise<Result<Location, LocationError>>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Adds a new geotag with expected location
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} data - Geotad data JSON
|
|
65
|
+
* @param {Location} expectedLocation - Expected location
|
|
66
|
+
* @returns location with deviation if success or LocationError if failure
|
|
67
|
+
*/
|
|
68
|
+
static async addGeotag(
|
|
69
|
+
data: Object,
|
|
70
|
+
expectedLocation: Location
|
|
71
|
+
): Promise<Result<LocationWithDeviation, LocationError>>;
|
|
72
|
+
|
|
73
|
+
static async addGeotag(
|
|
74
|
+
...args: any[]
|
|
75
|
+
): Promise<Result<Location | LocationWithDeviation, LocationError>> {
|
|
76
|
+
if (args.length === 1 && typeof args[0] === 'object') {
|
|
77
|
+
return HyperTrackSdk.addGeotag({
|
|
78
|
+
data: args[0],
|
|
79
|
+
expectedLocation: undefined,
|
|
80
|
+
} as GeotagData).then(
|
|
81
|
+
(locationResponse: Result<LocationInternal, LocationErrorInternal>) => {
|
|
82
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
} else if (
|
|
86
|
+
args.length === 2 &&
|
|
87
|
+
typeof args[0] === 'object' &&
|
|
88
|
+
HyperTrack.isLocation(args[1])
|
|
89
|
+
) {
|
|
90
|
+
let expectedLocation = args[1] as Location;
|
|
91
|
+
return HyperTrackSdk.addGeotag({
|
|
92
|
+
data: args[0],
|
|
93
|
+
expectedLocation: {
|
|
94
|
+
type: 'location',
|
|
95
|
+
value: {
|
|
96
|
+
latitude: expectedLocation.latitude,
|
|
97
|
+
longitude: expectedLocation.longitude,
|
|
98
|
+
},
|
|
99
|
+
} as LocationInternal,
|
|
100
|
+
} as GeotagData).then(
|
|
101
|
+
(
|
|
102
|
+
locationResponse: Result<
|
|
103
|
+
LocationWithDeviationInternal,
|
|
104
|
+
LocationErrorInternal
|
|
105
|
+
>
|
|
106
|
+
) => {
|
|
107
|
+
return this.deserializeLocationWithDeviationResponse(
|
|
108
|
+
locationResponse
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
} else {
|
|
113
|
+
throw new Error('Invalid arguments');
|
|
70
114
|
}
|
|
71
115
|
}
|
|
72
116
|
|
|
73
117
|
/**
|
|
74
118
|
* Returns a string that is used to uniquely identify the device
|
|
119
|
+
*
|
|
120
|
+
* @returns {string} Device ID
|
|
75
121
|
*/
|
|
76
|
-
getDeviceId(): Promise<string> {
|
|
122
|
+
static async getDeviceId(): Promise<string> {
|
|
77
123
|
return HyperTrackSdk.getDeviceId().then(
|
|
78
124
|
(deviceId: DeviceId) => deviceId.value
|
|
79
125
|
);
|
|
80
126
|
}
|
|
81
127
|
|
|
82
128
|
/**
|
|
83
|
-
*
|
|
129
|
+
* Returns a list of errors that blocks SDK from tracking
|
|
84
130
|
*
|
|
85
|
-
* @returns
|
|
131
|
+
* @returns {HyperTrackError[]} List of errors
|
|
86
132
|
*/
|
|
87
|
-
|
|
88
|
-
return HyperTrackSdk.
|
|
89
|
-
(
|
|
133
|
+
static async getErrors(): Promise<HyperTrackError[]> {
|
|
134
|
+
return HyperTrackSdk.getErrors().then(
|
|
135
|
+
(errors: HyperTrackErrorInternal[]) => {
|
|
136
|
+
return this.deserializeHyperTrackErrors(errors);
|
|
137
|
+
}
|
|
90
138
|
);
|
|
91
139
|
}
|
|
92
140
|
|
|
93
141
|
/**
|
|
94
|
-
*
|
|
142
|
+
* Reflects availability of the device for the Nearby search
|
|
95
143
|
*
|
|
96
|
-
* @
|
|
144
|
+
* @returns true when is available or false when unavailable
|
|
97
145
|
*/
|
|
98
|
-
|
|
99
|
-
HyperTrackSdk.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
} as IsAvailable);
|
|
146
|
+
static async getIsAvailable(): Promise<boolean> {
|
|
147
|
+
return HyperTrackSdk.getIsAvailable().then(
|
|
148
|
+
(isAvailable: IsAvailable) => isAvailable.value
|
|
149
|
+
);
|
|
103
150
|
}
|
|
104
151
|
|
|
105
152
|
/**
|
|
106
153
|
* Reflects the tracking intent for the device
|
|
107
154
|
*
|
|
108
|
-
* @
|
|
155
|
+
* @returns {boolean} Whether the user's movement data is getting tracked or not.
|
|
109
156
|
*/
|
|
110
|
-
|
|
111
|
-
return HyperTrackSdk.
|
|
157
|
+
static async getIsTracking(): Promise<boolean> {
|
|
158
|
+
return HyperTrackSdk.getIsTracking().then(
|
|
112
159
|
(isTracking: IsTracking) => isTracking.value
|
|
113
160
|
);
|
|
114
161
|
}
|
|
115
162
|
|
|
116
163
|
/**
|
|
117
|
-
*
|
|
164
|
+
* Reflects the current location of the user or an outage reason
|
|
118
165
|
*/
|
|
119
|
-
|
|
120
|
-
HyperTrackSdk.
|
|
166
|
+
static async getLocation(): Promise<Result<Location, LocationError>> {
|
|
167
|
+
return HyperTrackSdk.getLocation().then(
|
|
168
|
+
(locationResponse: Result<LocationInternal, LocationErrorInternal>) => {
|
|
169
|
+
return this.deserializeLocationResponse(locationResponse);
|
|
170
|
+
}
|
|
171
|
+
);
|
|
121
172
|
}
|
|
122
173
|
|
|
123
174
|
/**
|
|
124
|
-
*
|
|
175
|
+
* Gets the metadata that is set for the device
|
|
176
|
+
*
|
|
177
|
+
* @returns {Object} Metadata JSON
|
|
125
178
|
*/
|
|
126
|
-
|
|
127
|
-
HyperTrackSdk.
|
|
179
|
+
static async getMetadata(): Promise<Object> {
|
|
180
|
+
return HyperTrackSdk.getMetadata().then((metadata: Metadata) => {
|
|
181
|
+
return this.deserializeMetadata(metadata);
|
|
182
|
+
});
|
|
128
183
|
}
|
|
129
184
|
|
|
130
185
|
/**
|
|
131
|
-
*
|
|
186
|
+
* Gets the name that is set for the device
|
|
187
|
+
*
|
|
188
|
+
* @returns {string} Device name
|
|
132
189
|
*/
|
|
133
|
-
|
|
134
|
-
HyperTrackSdk.
|
|
190
|
+
static async getName(): Promise<string> {
|
|
191
|
+
return HyperTrackSdk.getName().then((name: Name) => {
|
|
192
|
+
return this.deserializeName(name);
|
|
193
|
+
});
|
|
135
194
|
}
|
|
136
195
|
|
|
137
196
|
/**
|
|
138
|
-
*
|
|
197
|
+
* Requests one-time location update and returns the location once it is available, or error.
|
|
198
|
+
*
|
|
199
|
+
* Only one locate subscription can be active at a time. If you re-subscribe, the old EmitterSubscription
|
|
200
|
+
* will be automaticaly removed.
|
|
201
|
+
*
|
|
202
|
+
* This method will start location tracking if called, and will stop it when the location is received or
|
|
203
|
+
* the subscription is cancelled. If any other tracking intent is present (e.g. isAvailable is set to `true`),
|
|
204
|
+
* the tracking will not be stopped.
|
|
205
|
+
*
|
|
206
|
+
* @param callback
|
|
207
|
+
* @returns EmitterSubscription
|
|
208
|
+
* @example ```js
|
|
209
|
+
* const subscription = HyperTrack.locate(location => {
|
|
210
|
+
* ...
|
|
211
|
+
* })
|
|
212
|
+
*
|
|
213
|
+
* // to unsubscribe
|
|
214
|
+
* subscription.remove()
|
|
215
|
+
* ```
|
|
139
216
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
217
|
+
static locate(
|
|
218
|
+
callback: (location: Result<Location, HyperTrackError[]>) => void
|
|
219
|
+
) {
|
|
220
|
+
this.locateSubscription?.remove();
|
|
221
|
+
this.locateSubscription = EventEmitter.addListener(
|
|
222
|
+
EVENT_LOCATE,
|
|
223
|
+
(location: Result<LocationInternal, HyperTrackErrorInternal[]>) => {
|
|
224
|
+
callback(this.deserializeLocateResponse(location));
|
|
144
225
|
}
|
|
145
226
|
);
|
|
227
|
+
HyperTrackSdk.locate();
|
|
228
|
+
return this.locateSubscription;
|
|
146
229
|
}
|
|
147
230
|
|
|
148
231
|
/**
|
|
149
|
-
* Sets the
|
|
150
|
-
*
|
|
232
|
+
* Sets the availability of the device for the Nearby search
|
|
233
|
+
*
|
|
234
|
+
* @param availability true when is available or false when unavailable
|
|
151
235
|
*/
|
|
152
|
-
|
|
153
|
-
HyperTrackSdk.
|
|
154
|
-
type: '
|
|
155
|
-
value:
|
|
156
|
-
} as
|
|
236
|
+
static async setIsAvailable(isAvailable: boolean) {
|
|
237
|
+
HyperTrackSdk.setIsAvailable({
|
|
238
|
+
type: 'isAvailable',
|
|
239
|
+
value: isAvailable,
|
|
240
|
+
} as IsAvailable);
|
|
157
241
|
}
|
|
158
242
|
|
|
159
243
|
/**
|
|
160
|
-
* Sets the
|
|
161
|
-
*
|
|
244
|
+
* Sets the tracking intent for the device
|
|
245
|
+
*
|
|
246
|
+
* @param {boolean} isTracking
|
|
162
247
|
*/
|
|
163
|
-
|
|
164
|
-
HyperTrackSdk.
|
|
248
|
+
static async setIsTracking(isTracking: boolean): Promise<void> {
|
|
249
|
+
HyperTrackSdk.setIsTracking({
|
|
250
|
+
type: 'isTracking',
|
|
251
|
+
value: isTracking,
|
|
252
|
+
} as IsTracking);
|
|
165
253
|
}
|
|
166
254
|
|
|
167
255
|
/**
|
|
168
|
-
*
|
|
256
|
+
* Sets the metadata for the device
|
|
169
257
|
*
|
|
170
|
-
* @param {Object} data -
|
|
171
|
-
* @returns current location if success or LocationError if failure
|
|
258
|
+
* @param {Object} data - Metadata JSON
|
|
172
259
|
*/
|
|
173
|
-
async
|
|
260
|
+
static async setMetadata(data: Object) {
|
|
261
|
+
HyperTrackSdk.setMetadata({
|
|
262
|
+
type: 'metadata',
|
|
263
|
+
value: data,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
174
266
|
|
|
175
267
|
/**
|
|
176
|
-
*
|
|
268
|
+
* Sets the name for the device
|
|
177
269
|
*
|
|
178
|
-
* @param {
|
|
179
|
-
* @param {Location} expectedLocation - Expected location
|
|
180
|
-
* @returns location with deviation if success or LocationError if failure
|
|
270
|
+
* @param {string} name
|
|
181
271
|
*/
|
|
182
|
-
async
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
async addGeotag(
|
|
188
|
-
...args: any[]
|
|
189
|
-
): Promise<Result<Location | LocationWithDeviation, LocationError>> {
|
|
190
|
-
if (args.length === 1 && typeof args[0] === 'object') {
|
|
191
|
-
return HyperTrackSdk.addGeotag({
|
|
192
|
-
data: args[0],
|
|
193
|
-
expectedLocation: undefined,
|
|
194
|
-
} as GeotagData).then(
|
|
195
|
-
(locationResponse: Result<LocationInternal, LocationErrorInternal>) => {
|
|
196
|
-
return this.deserializeLocationResponse(locationResponse);
|
|
197
|
-
}
|
|
198
|
-
);
|
|
199
|
-
} else if (
|
|
200
|
-
args.length === 2 &&
|
|
201
|
-
typeof args[0] === 'object' &&
|
|
202
|
-
this.isLocation(args[1])
|
|
203
|
-
) {
|
|
204
|
-
let expectedLocation = args[1] as Location;
|
|
205
|
-
return HyperTrackSdk.addGeotag({
|
|
206
|
-
data: args[0],
|
|
207
|
-
expectedLocation: {
|
|
208
|
-
type: 'location',
|
|
209
|
-
value: {
|
|
210
|
-
latitude: expectedLocation.latitude,
|
|
211
|
-
longitude: expectedLocation.longitude,
|
|
212
|
-
},
|
|
213
|
-
} as LocationInternal,
|
|
214
|
-
} as GeotagData).then(
|
|
215
|
-
(
|
|
216
|
-
locationResponse: Result<
|
|
217
|
-
LocationWithDeviationInternal,
|
|
218
|
-
LocationErrorInternal
|
|
219
|
-
>
|
|
220
|
-
) => {
|
|
221
|
-
return this.deserializeLocationWithDeviationResponse(
|
|
222
|
-
locationResponse
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
} else {
|
|
227
|
-
throw new Error('Invalid arguments');
|
|
228
|
-
}
|
|
272
|
+
static async setName(name: string) {
|
|
273
|
+
HyperTrackSdk.setName({
|
|
274
|
+
type: 'name',
|
|
275
|
+
value: name,
|
|
276
|
+
} as Name);
|
|
229
277
|
}
|
|
230
278
|
|
|
231
279
|
/**
|
|
@@ -245,15 +293,45 @@ export default class HyperTrack {
|
|
|
245
293
|
* subscription.remove()
|
|
246
294
|
* ```
|
|
247
295
|
*/
|
|
248
|
-
subscribeToErrors(
|
|
296
|
+
static subscribeToErrors(
|
|
297
|
+
listener: (errors: HyperTrackError[]) => void
|
|
298
|
+
): EmitterSubscription {
|
|
249
299
|
return EventEmitter.addListener(
|
|
250
|
-
|
|
300
|
+
EVENT_ERRORS,
|
|
251
301
|
(rawErrors: HyperTrackErrorInternal[]) => {
|
|
252
302
|
listener(this.deserializeHyperTrackErrors(rawErrors));
|
|
253
303
|
}
|
|
254
304
|
);
|
|
255
305
|
}
|
|
256
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Subscribe to availability changes
|
|
309
|
+
*
|
|
310
|
+
* @param listener
|
|
311
|
+
* @returns EmitterSubscription
|
|
312
|
+
* @example
|
|
313
|
+
* ```js
|
|
314
|
+
* const subscription = HyperTrack.subscribeToIsAvailable(isAvailable => {
|
|
315
|
+
* if (isAvailable) {
|
|
316
|
+
* // ... ready to go
|
|
317
|
+
* }
|
|
318
|
+
* })
|
|
319
|
+
*
|
|
320
|
+
* // later, to stop listening
|
|
321
|
+
* subscription.remove()
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
static subscribeToIsAvailable(
|
|
325
|
+
listener: (isAvailable: boolean) => void
|
|
326
|
+
): EmitterSubscription {
|
|
327
|
+
return EventEmitter.addListener(
|
|
328
|
+
EVENT_IS_AVAILABLE,
|
|
329
|
+
(isAvailable: IsAvailable) => {
|
|
330
|
+
listener(isAvailable.value);
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
257
335
|
/**
|
|
258
336
|
* Subscribe to tracking intent changes
|
|
259
337
|
*
|
|
@@ -261,7 +339,7 @@ export default class HyperTrack {
|
|
|
261
339
|
* @returns EmitterSubscription
|
|
262
340
|
* @example
|
|
263
341
|
* ```js
|
|
264
|
-
* const subscription = HyperTrack.
|
|
342
|
+
* const subscription = HyperTrack.subscribeToIsTracking(isTracking => {
|
|
265
343
|
* if (isTracking) {
|
|
266
344
|
* // ... ready to go
|
|
267
345
|
* }
|
|
@@ -271,9 +349,11 @@ export default class HyperTrack {
|
|
|
271
349
|
* subscription.remove()
|
|
272
350
|
* ```
|
|
273
351
|
*/
|
|
274
|
-
|
|
352
|
+
static subscribeToIsTracking(
|
|
353
|
+
listener: (isTracking: boolean) => void
|
|
354
|
+
): EmitterSubscription {
|
|
275
355
|
return EventEmitter.addListener(
|
|
276
|
-
|
|
356
|
+
EVENT_IS_TRACKING,
|
|
277
357
|
(isTracking: IsTracking) => {
|
|
278
358
|
listener(isTracking.value);
|
|
279
359
|
}
|
|
@@ -281,43 +361,83 @@ export default class HyperTrack {
|
|
|
281
361
|
}
|
|
282
362
|
|
|
283
363
|
/**
|
|
284
|
-
* Subscribe to
|
|
364
|
+
* Subscribe to location changes
|
|
285
365
|
*
|
|
286
366
|
* @param listener
|
|
287
367
|
* @returns EmitterSubscription
|
|
288
368
|
* @example
|
|
289
369
|
* ```js
|
|
290
|
-
* const subscription = HyperTrack.
|
|
291
|
-
*
|
|
292
|
-
* // ... ready to go
|
|
293
|
-
* }
|
|
370
|
+
* const subscription = HyperTrack.subscribeToLocation(location => {
|
|
371
|
+
* ...
|
|
294
372
|
* })
|
|
295
373
|
*
|
|
296
374
|
* // later, to stop listening
|
|
297
375
|
* subscription.remove()
|
|
298
376
|
* ```
|
|
299
377
|
*/
|
|
300
|
-
|
|
378
|
+
static subscribeToLocation(
|
|
379
|
+
listener: (location: Result<Location, LocationError>) => void
|
|
380
|
+
) {
|
|
301
381
|
return EventEmitter.addListener(
|
|
302
|
-
|
|
303
|
-
(
|
|
304
|
-
listener(
|
|
382
|
+
EVENT_LOCATION,
|
|
383
|
+
(location: Result<LocationInternal, LocationErrorInternal>) => {
|
|
384
|
+
listener(this.deserializeLocationResponse(location));
|
|
305
385
|
}
|
|
306
386
|
);
|
|
307
387
|
}
|
|
308
388
|
|
|
309
389
|
/** @ignore */
|
|
310
|
-
private deserializeHyperTrackErrors(
|
|
390
|
+
private static deserializeHyperTrackErrors(
|
|
311
391
|
errors: HyperTrackErrorInternal[]
|
|
312
392
|
): HyperTrackError[] {
|
|
313
|
-
|
|
314
|
-
(error
|
|
315
|
-
|
|
316
|
-
|
|
393
|
+
let res = errors.map((error: HyperTrackErrorInternal) => {
|
|
394
|
+
if (error.type != 'error') {
|
|
395
|
+
throw new Error('Invalid error type');
|
|
396
|
+
}
|
|
397
|
+
return Object.keys(HyperTrackError).find(
|
|
398
|
+
(key) =>
|
|
399
|
+
HyperTrackError[key as keyof typeof HyperTrackError] === error.value
|
|
400
|
+
) as HyperTrackError;
|
|
401
|
+
});
|
|
402
|
+
return res;
|
|
317
403
|
}
|
|
318
404
|
|
|
319
405
|
/** @ignore */
|
|
320
|
-
private
|
|
406
|
+
private static deserializeLocateResponse(
|
|
407
|
+
response: Result<LocationInternal, HyperTrackErrorInternal[]>
|
|
408
|
+
): Result<Location, HyperTrackError[]> {
|
|
409
|
+
switch (response.type) {
|
|
410
|
+
case 'success':
|
|
411
|
+
return {
|
|
412
|
+
type: 'success',
|
|
413
|
+
value: response.value.value,
|
|
414
|
+
};
|
|
415
|
+
case 'failure':
|
|
416
|
+
return {
|
|
417
|
+
type: 'failure',
|
|
418
|
+
value: this.deserializeHyperTrackErrors(response.value),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** @ignore */
|
|
424
|
+
private static deserializeLocationError(
|
|
425
|
+
locationError: LocationErrorInternal
|
|
426
|
+
): LocationError {
|
|
427
|
+
switch (locationError.type) {
|
|
428
|
+
case 'notRunning':
|
|
429
|
+
case 'starting':
|
|
430
|
+
return locationError;
|
|
431
|
+
case 'errors':
|
|
432
|
+
return {
|
|
433
|
+
type: 'errors',
|
|
434
|
+
value: this.deserializeHyperTrackErrors(locationError.value),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** @ignore */
|
|
440
|
+
private static deserializeLocationResponse(
|
|
321
441
|
response: Result<LocationInternal, LocationErrorInternal>
|
|
322
442
|
): Result<Location, LocationError> {
|
|
323
443
|
switch (response.type) {
|
|
@@ -335,7 +455,7 @@ export default class HyperTrack {
|
|
|
335
455
|
}
|
|
336
456
|
|
|
337
457
|
/** @ignore */
|
|
338
|
-
private deserializeLocationWithDeviationResponse(
|
|
458
|
+
private static deserializeLocationWithDeviationResponse(
|
|
339
459
|
response: Result<LocationWithDeviationInternal, LocationErrorInternal>
|
|
340
460
|
): Result<LocationWithDeviation, LocationError> {
|
|
341
461
|
switch (response.type) {
|
|
@@ -361,23 +481,23 @@ export default class HyperTrack {
|
|
|
361
481
|
}
|
|
362
482
|
|
|
363
483
|
/** @ignore */
|
|
364
|
-
private
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
};
|
|
484
|
+
private static deserializeMetadata(metadata: Metadata): Object {
|
|
485
|
+
if (metadata.type != 'metadata') {
|
|
486
|
+
throw new Error(`Invalid metadata: ${JSON.stringify(metadata)}`);
|
|
487
|
+
}
|
|
488
|
+
return metadata.value;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** @ignore */
|
|
492
|
+
private static deserializeName(name: Name): string {
|
|
493
|
+
if (name.type != 'name') {
|
|
494
|
+
throw new Error(`Invalid name: ${JSON.stringify(name)}`);
|
|
376
495
|
}
|
|
496
|
+
return name.value;
|
|
377
497
|
}
|
|
378
498
|
|
|
379
499
|
/** @ignore */
|
|
380
|
-
private isLocation(obj: Location): obj is Location {
|
|
500
|
+
private static isLocation(obj: Location): obj is Location {
|
|
381
501
|
return (
|
|
382
502
|
'latitude' in obj &&
|
|
383
503
|
typeof obj.latitude == 'number' &&
|