hypertrack-sdk-react-native 10.0.3 → 11.0.1
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 +54 -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 +46 -80
- package/ios/common/SDKMethod.swift +13 -12
- package/ios/common/Serialization.swift +200 -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,6 +1,8 @@
|
|
|
1
1
|
package com.reactnativehypertracksdk.common
|
|
2
2
|
|
|
3
3
|
import android.location.Location
|
|
4
|
+
import com.hypertrack.sdk.android.HyperTrack
|
|
5
|
+
import com.hypertrack.sdk.android.Result
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Platform-independent serialization code that converts HyperTrack data types
|
|
@@ -8,93 +10,250 @@ import android.location.Location
|
|
|
8
10
|
*/
|
|
9
11
|
internal object Serialization {
|
|
10
12
|
|
|
11
|
-
fun
|
|
12
|
-
return
|
|
13
|
-
|
|
13
|
+
fun deserializeIsAvailable(isAvailable: Map<String, Any?>): WrapperResult<Boolean> {
|
|
14
|
+
return parse(isAvailable) {
|
|
15
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_AVAILABLE)
|
|
16
|
+
it
|
|
17
|
+
.get<Boolean>(KEY_VALUE)
|
|
18
|
+
.getOrThrow()
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
fun
|
|
18
|
-
return
|
|
22
|
+
fun deserializeIsTracking(isTracking: Map<String, Any?>): WrapperResult<Boolean> {
|
|
23
|
+
return parse(isTracking) {
|
|
24
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_TRACKING)
|
|
25
|
+
it
|
|
26
|
+
.get<Boolean>(KEY_VALUE)
|
|
27
|
+
.getOrThrow()
|
|
28
|
+
}
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
fun
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
))
|
|
31
|
+
fun deserializeMetadata(metadata: Map<String, Any?>): WrapperResult<Map<String, Any?>> {
|
|
32
|
+
return parse(metadata) {
|
|
33
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_METADATA)
|
|
34
|
+
it
|
|
35
|
+
.get<Map<String, Any?>>(KEY_VALUE)
|
|
36
|
+
.getOrThrow()
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
fun
|
|
32
|
-
return
|
|
40
|
+
fun deserializeName(name: Map<String, Any?>): WrapperResult<String> {
|
|
41
|
+
return parse(name) {
|
|
42
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_NAME)
|
|
43
|
+
it
|
|
44
|
+
.get<String>(KEY_VALUE)
|
|
45
|
+
.getOrThrow()
|
|
46
|
+
}
|
|
33
47
|
}
|
|
34
48
|
|
|
35
|
-
fun
|
|
49
|
+
fun deserializeGeotagData(map: Map<String, Any?>): WrapperResult<GeotagData> {
|
|
50
|
+
return parse(map) {
|
|
51
|
+
val data = it
|
|
52
|
+
.get<Map<String, Any?>>(KEY_GEOTAG_DATA)
|
|
53
|
+
.getOrThrow()
|
|
54
|
+
val locationData = it
|
|
55
|
+
.getOptional<Map<String, Any?>>(KEY_GEOTAG_EXPECTED_LOCATION)
|
|
56
|
+
.getOrThrow()
|
|
57
|
+
val location = locationData?.let { deserializeLocation(it).getOrThrow() }
|
|
58
|
+
GeotagData(data, location)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun serializeDeviceId(deviceId: String): Map<String, Any?> {
|
|
36
63
|
return mapOf(
|
|
37
|
-
KEY_TYPE to
|
|
38
|
-
KEY_VALUE to
|
|
64
|
+
KEY_TYPE to TYPE_DEVICE_ID,
|
|
65
|
+
KEY_VALUE to deviceId
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fun serializeError(error: HyperTrack.Error): Map<String, String> {
|
|
70
|
+
return mapOf(
|
|
71
|
+
KEY_TYPE to TYPE_ERROR,
|
|
72
|
+
KEY_VALUE to when (error) {
|
|
73
|
+
HyperTrack.Error.BlockedFromRunning -> "blockedFromRunning"
|
|
74
|
+
HyperTrack.Error.InvalidPublishableKey -> "invalidPublishableKey"
|
|
75
|
+
HyperTrack.Error.Location.Mocked -> "location.mocked"
|
|
76
|
+
HyperTrack.Error.Location.ServicesDisabled -> "location.servicesDisabled"
|
|
77
|
+
HyperTrack.Error.Location.ServicesUnavailable -> "location.servicesUnavailable"
|
|
78
|
+
HyperTrack.Error.Location.SignalLost -> "location.signalLost"
|
|
79
|
+
HyperTrack.Error.NoExemptionFromBackgroundStartRestrictions -> "noExemptionFromBackgroundStartRestrictions"
|
|
80
|
+
HyperTrack.Error.Permissions.Location.Denied -> "permissions.location.denied"
|
|
81
|
+
HyperTrack.Error.Permissions.Location.InsufficientForBackground -> "permissions.location.insufficientForBackground"
|
|
82
|
+
HyperTrack.Error.Permissions.Location.ReducedAccuracy -> "permissions.location.reducedAccuracy"
|
|
83
|
+
HyperTrack.Error.Permissions.Notifications.Denied -> "permissions.notifications.denied"
|
|
84
|
+
}
|
|
39
85
|
)
|
|
40
86
|
}
|
|
41
87
|
|
|
88
|
+
fun serializeErrors(errors: Set<HyperTrack.Error>): List<Map<String, String>> {
|
|
89
|
+
return errors.map {
|
|
90
|
+
serializeError(it)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
42
94
|
fun serializeIsAvailable(isAvailable: Boolean): Map<String, Any?> {
|
|
43
95
|
return mapOf(
|
|
44
|
-
KEY_TYPE to
|
|
96
|
+
KEY_TYPE to TYPE_IS_AVAILABLE,
|
|
45
97
|
KEY_VALUE to isAvailable
|
|
46
98
|
)
|
|
47
99
|
}
|
|
48
100
|
|
|
49
|
-
fun
|
|
101
|
+
fun serializeIsTracking(isTracking: Boolean): Map<String, Any?> {
|
|
50
102
|
return mapOf(
|
|
51
|
-
KEY_TYPE to
|
|
52
|
-
KEY_VALUE to
|
|
103
|
+
KEY_TYPE to TYPE_IS_TRACKING,
|
|
104
|
+
KEY_VALUE to isTracking
|
|
53
105
|
)
|
|
54
106
|
}
|
|
55
107
|
|
|
56
|
-
fun
|
|
108
|
+
fun serializeMetadata(metadata: Map<String, Any?>): Map<String, Any?> {
|
|
57
109
|
return mapOf(
|
|
58
|
-
KEY_TYPE to
|
|
59
|
-
KEY_VALUE to
|
|
110
|
+
KEY_TYPE to TYPE_METADATA,
|
|
111
|
+
KEY_VALUE to metadata
|
|
60
112
|
)
|
|
61
113
|
}
|
|
62
114
|
|
|
63
|
-
fun
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
115
|
+
fun serializeName(name: String): Map<String, Any?> {
|
|
116
|
+
return mapOf(
|
|
117
|
+
KEY_TYPE to TYPE_NAME,
|
|
118
|
+
KEY_VALUE to name
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fun serializeLocateResult(
|
|
123
|
+
locationResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>
|
|
124
|
+
): Map<String, Any?> {
|
|
125
|
+
return when (locationResult) {
|
|
126
|
+
is Result.Failure -> {
|
|
127
|
+
serializeFailure(serializeErrors(locationResult.failure))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
is Result.Success -> {
|
|
131
|
+
serializeLocationSuccess(locationResult.success)
|
|
132
|
+
}
|
|
69
133
|
}
|
|
70
134
|
}
|
|
71
135
|
|
|
72
|
-
fun
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
.
|
|
136
|
+
fun serializeLocationResult(
|
|
137
|
+
locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>
|
|
138
|
+
): Map<String, Any?> {
|
|
139
|
+
return when (locationResult) {
|
|
140
|
+
is Result.Failure -> {
|
|
141
|
+
serializeLocationErrorFailure(locationResult.failure)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
is Result.Success -> {
|
|
145
|
+
serializeLocationSuccess(locationResult.success)
|
|
146
|
+
}
|
|
78
147
|
}
|
|
79
148
|
}
|
|
80
149
|
|
|
81
|
-
fun
|
|
150
|
+
fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError): Map<String, Any?> {
|
|
151
|
+
return serializeFailure(serializeLocationError(locationError))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fun serializeLocationSuccess(location: HyperTrack.Location): Map<String, Any?> {
|
|
155
|
+
return serializeSuccess(serializeLocation(location))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fun serializeLocationWithDeviationSuccess(
|
|
159
|
+
locationWithDeviation: HyperTrack.LocationWithDeviation,
|
|
160
|
+
): Map<String, Any?> {
|
|
161
|
+
return serializeSuccess(
|
|
162
|
+
serializeLocationWithDeviation(
|
|
163
|
+
locationWithDeviation
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private fun serializeLocationWithDeviation(
|
|
169
|
+
locationWithDeviation: HyperTrack.LocationWithDeviation,
|
|
170
|
+
): Map<String, Any?> {
|
|
171
|
+
return mapOf(
|
|
172
|
+
KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION,
|
|
173
|
+
KEY_VALUE to mapOf(
|
|
174
|
+
KEY_LOCATION to serializeLocation(locationWithDeviation.location),
|
|
175
|
+
KEY_DEVIATION to locationWithDeviation.deviation
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private fun deserializeLocation(map: Map<String, Any?>): WrapperResult<Location> {
|
|
82
181
|
return parse(map) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.
|
|
86
|
-
val locationData = it
|
|
87
|
-
.getOptional<Map<String, Any?>>(KEY_GEOTAG_EXPECTED_LOCATION)
|
|
182
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
|
|
183
|
+
val value = it
|
|
184
|
+
.get<Map<String, Any?>>(KEY_VALUE)
|
|
88
185
|
.getOrThrow()
|
|
89
|
-
|
|
90
|
-
|
|
186
|
+
parse(value) { parser ->
|
|
187
|
+
val latitude = parser
|
|
188
|
+
.get<Double>(KEY_LATITUDE)
|
|
189
|
+
.getOrThrow()
|
|
190
|
+
val longitude = parser
|
|
191
|
+
.get<Double>(KEY_LONGITUDE)
|
|
192
|
+
.getOrThrow()
|
|
193
|
+
Location("api").also {
|
|
194
|
+
it.latitude = latitude
|
|
195
|
+
it.longitude = longitude
|
|
196
|
+
}
|
|
197
|
+
}.getOrThrow()
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private fun serializeFailure(failure: List<Map<String, Any?>>): Map<String, Any?> {
|
|
202
|
+
return mapOf(
|
|
203
|
+
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
204
|
+
KEY_VALUE to failure
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private fun serializeFailure(failure: Map<String, Any?>): Map<String, Any?> {
|
|
209
|
+
return mapOf(
|
|
210
|
+
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
211
|
+
KEY_VALUE to failure
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private fun serializeSuccess(success: Map<String, Any?>): Map<String, Any?> {
|
|
216
|
+
return mapOf(
|
|
217
|
+
KEY_TYPE to TYPE_RESULT_SUCCESS,
|
|
218
|
+
KEY_VALUE to success
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fun serializeLocation(location: HyperTrack.Location): Map<String, Any?> {
|
|
223
|
+
return mapOf(
|
|
224
|
+
KEY_TYPE to TYPE_LOCATION,
|
|
225
|
+
KEY_VALUE to mapOf(
|
|
226
|
+
KEY_LATITUDE to location.latitude,
|
|
227
|
+
KEY_LONGITUDE to location.longitude
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
private fun serializeLocationError(locationError: HyperTrack.LocationError): Map<String, Any?> {
|
|
234
|
+
return when (locationError) {
|
|
235
|
+
HyperTrack.LocationError.NotRunning -> {
|
|
236
|
+
mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
HyperTrack.LocationError.Starting -> {
|
|
240
|
+
mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
is HyperTrack.LocationError.Errors -> {
|
|
244
|
+
mapOf(
|
|
245
|
+
KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS,
|
|
246
|
+
KEY_VALUE to locationError.errors
|
|
247
|
+
.map { serializeError(it) }
|
|
248
|
+
)
|
|
249
|
+
}
|
|
91
250
|
}
|
|
92
251
|
}
|
|
93
252
|
|
|
94
253
|
fun <T> parse(
|
|
95
254
|
source: Map<String, Any?>,
|
|
96
255
|
parseFunction: (Parser) -> T
|
|
97
|
-
):
|
|
256
|
+
): WrapperResult<T> {
|
|
98
257
|
val parser = Parser(source)
|
|
99
258
|
return try {
|
|
100
259
|
if (parser.exceptions.isEmpty()) {
|
|
@@ -121,7 +280,7 @@ internal object Serialization {
|
|
|
121
280
|
|
|
122
281
|
inline fun <reified T> get(
|
|
123
282
|
key: String
|
|
124
|
-
):
|
|
283
|
+
): WrapperResult<T> {
|
|
125
284
|
return try {
|
|
126
285
|
Success(source[key]!! as T)
|
|
127
286
|
} catch (e: Exception) {
|
|
@@ -136,7 +295,7 @@ internal object Serialization {
|
|
|
136
295
|
|
|
137
296
|
inline fun <reified T> getOptional(
|
|
138
297
|
key: String
|
|
139
|
-
):
|
|
298
|
+
): WrapperResult<T?> {
|
|
140
299
|
return try {
|
|
141
300
|
Success(source[key] as T?)
|
|
142
301
|
} catch (e: Exception) {
|
|
@@ -174,105 +333,30 @@ internal object Serialization {
|
|
|
174
333
|
exception: Exception
|
|
175
334
|
) : Exception("Invalid value for '$key': $exception", exception)
|
|
176
335
|
|
|
177
|
-
private fun deserializeLocation(map: Map<String, Any?>): Result<Location> {
|
|
178
|
-
return parse(map) {
|
|
179
|
-
it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
|
|
180
|
-
val value = it
|
|
181
|
-
.get<Map<String, Any?>>(KEY_VALUE)
|
|
182
|
-
.getOrThrow()
|
|
183
|
-
parse(value) { parser ->
|
|
184
|
-
val latitude = parser
|
|
185
|
-
.get<Double>(KEY_LATITUDE)
|
|
186
|
-
.getOrThrow()
|
|
187
|
-
val longitude = parser
|
|
188
|
-
.get<Double>(KEY_LONGITUDE)
|
|
189
|
-
.getOrThrow()
|
|
190
|
-
Location("api").also {
|
|
191
|
-
it.latitude = latitude
|
|
192
|
-
it.longitude = longitude
|
|
193
|
-
}
|
|
194
|
-
}.getOrThrow()
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private fun serializeLocationWithDeviation(
|
|
199
|
-
location: Location,
|
|
200
|
-
deviation: Double
|
|
201
|
-
): Map<String, Any?> {
|
|
202
|
-
return mapOf(
|
|
203
|
-
KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION,
|
|
204
|
-
KEY_VALUE to mapOf(
|
|
205
|
-
KEY_LOCATION to serializeLocation(location),
|
|
206
|
-
KEY_DEVIATION to deviation
|
|
207
|
-
)
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
private fun serializeFailure(failure: Map<String, Any?>): Map<String, Any?> {
|
|
212
|
-
return mapOf(
|
|
213
|
-
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
214
|
-
KEY_VALUE to failure
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
private fun serializeSuccess(success: Map<String, Any?>): Map<String, Any?> {
|
|
219
|
-
return mapOf(
|
|
220
|
-
KEY_TYPE to TYPE_RESULT_SUCCESS,
|
|
221
|
-
KEY_VALUE to success
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private fun serializeLocation(location: Location): Map<String, Any?> {
|
|
226
|
-
return mapOf(
|
|
227
|
-
KEY_TYPE to TYPE_LOCATION,
|
|
228
|
-
KEY_VALUE to mapOf(
|
|
229
|
-
KEY_LATITUDE to location.latitude,
|
|
230
|
-
KEY_LONGITUDE to location.longitude
|
|
231
|
-
)
|
|
232
|
-
)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private fun serializeLocationError(locationError: LocationError): Map<String, Any?> {
|
|
236
|
-
return when (locationError) {
|
|
237
|
-
NotRunning -> {
|
|
238
|
-
mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
|
|
239
|
-
}
|
|
240
|
-
Starting -> {
|
|
241
|
-
mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING)
|
|
242
|
-
}
|
|
243
|
-
is Errors -> {
|
|
244
|
-
mapOf(
|
|
245
|
-
KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS,
|
|
246
|
-
KEY_VALUE to locationError.errors
|
|
247
|
-
.map { serializeHypertrackError(it) }
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
336
|
private const val KEY_TYPE = "type"
|
|
254
337
|
private const val KEY_VALUE = "value"
|
|
255
338
|
|
|
256
|
-
private const val TYPE_RESULT_SUCCESS = "success"
|
|
257
339
|
private const val TYPE_RESULT_FAILURE = "failure"
|
|
340
|
+
private const val TYPE_RESULT_SUCCESS = "success"
|
|
258
341
|
|
|
259
|
-
private const val TYPE_LOCATION = "location"
|
|
260
|
-
private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation"
|
|
261
|
-
private const val TYPE_AVAILABILITY = "isAvailable"
|
|
262
|
-
private const val TYPE_DEVICE_NAME = "deviceName"
|
|
263
342
|
private const val TYPE_DEVICE_ID = "deviceID"
|
|
264
|
-
private const val
|
|
343
|
+
private const val TYPE_ERROR = "error"
|
|
344
|
+
private const val TYPE_IS_AVAILABLE = "isAvailable"
|
|
265
345
|
private const val TYPE_IS_TRACKING = "isTracking"
|
|
346
|
+
private const val TYPE_METADATA = "metadata"
|
|
347
|
+
private const val TYPE_NAME = "name"
|
|
348
|
+
private const val TYPE_LOCATION = "location"
|
|
349
|
+
private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation"
|
|
266
350
|
|
|
351
|
+
private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
|
|
267
352
|
private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning"
|
|
268
353
|
private const val TYPE_LOCATION_ERROR_STARTING = "starting"
|
|
269
|
-
private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
|
|
270
354
|
|
|
271
355
|
private const val KEY_LATITUDE = "latitude"
|
|
272
356
|
private const val KEY_LONGITUDE = "longitude"
|
|
273
357
|
|
|
358
|
+
const val KEY_DEVIATION = "deviation"
|
|
274
359
|
const val KEY_GEOTAG_DATA = "data"
|
|
275
360
|
const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation"
|
|
276
|
-
const val KEY_DEVIATION = "deviation"
|
|
277
361
|
const val KEY_LOCATION = "location"
|
|
278
362
|
}
|
package/android/src/main/java/com/reactnativehypertracksdk/common/{Result.kt → WrapperResult.kt}
RENAMED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
package com.reactnativehypertracksdk.common
|
|
2
2
|
|
|
3
|
-
internal sealed class
|
|
3
|
+
internal sealed class WrapperResult<SuccessType> {
|
|
4
4
|
fun <MappedSuccess> flatMapSuccess(
|
|
5
|
-
onSuccess: (SuccessType) ->
|
|
6
|
-
):
|
|
5
|
+
onSuccess: (SuccessType) -> WrapperResult<MappedSuccess>
|
|
6
|
+
): WrapperResult<MappedSuccess> {
|
|
7
7
|
return when (this) {
|
|
8
8
|
is Success -> {
|
|
9
9
|
onSuccess.invoke(this.success)
|
|
10
10
|
}
|
|
11
|
+
|
|
11
12
|
is Failure -> {
|
|
12
13
|
Failure<MappedSuccess>(this.failure)
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
fun <MappedSuccess> mapSuccess(onSuccess: (SuccessType) -> MappedSuccess):
|
|
18
|
+
fun <MappedSuccess> mapSuccess(onSuccess: (SuccessType) -> MappedSuccess): WrapperResult<MappedSuccess> {
|
|
18
19
|
return when (this) {
|
|
19
20
|
is Success -> {
|
|
20
21
|
Success(onSuccess.invoke(this.success))
|
|
21
22
|
}
|
|
23
|
+
|
|
22
24
|
is Failure -> {
|
|
23
25
|
Failure<MappedSuccess>(this.failure)
|
|
24
26
|
}
|
|
@@ -36,7 +38,7 @@ internal sealed class Result<SuccessType> {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
companion object {
|
|
39
|
-
fun <SuccessType> tryAsResult(block: () -> SuccessType):
|
|
41
|
+
fun <SuccessType> tryAsResult(block: () -> SuccessType): WrapperResult<SuccessType> {
|
|
40
42
|
return try {
|
|
41
43
|
Success(block.invoke())
|
|
42
44
|
} catch (e: Exception) {
|
|
@@ -46,5 +48,5 @@ internal sealed class Result<SuccessType> {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
internal data class Success<SuccessType>(val success: SuccessType) :
|
|
50
|
-
internal data class Failure<SuccessType>(val failure: Throwable) :
|
|
51
|
+
internal data class Success<SuccessType>(val success: SuccessType) : WrapperResult<SuccessType>()
|
|
52
|
+
internal data class Failure<SuccessType>(val failure: Throwable) : WrapperResult<SuccessType>()
|
|
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
19
19
|
|
|
20
20
|
s.dependency "React-Core"
|
|
21
|
-
s.dependency 'HyperTrack
|
|
21
|
+
s.dependency 'HyperTrack', '5.0.1'
|
|
22
22
|
|
|
23
23
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
24
24
|
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
@@ -9,36 +9,39 @@ RCT_EXTERN_METHOD(addListener)
|
|
|
9
9
|
|
|
10
10
|
RCT_EXTERN_METHOD(requiresMainQueueSetup)
|
|
11
11
|
|
|
12
|
-
RCT_EXTERN_METHOD(
|
|
12
|
+
RCT_EXTERN_METHOD(addGeotag:(NSDictionary *)args
|
|
13
13
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
14
14
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
15
15
|
|
|
16
16
|
RCT_EXTERN_METHOD(getDeviceId:(RCTPromiseResolveBlock)resolve
|
|
17
17
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
18
18
|
|
|
19
|
-
RCT_EXTERN_METHOD(
|
|
19
|
+
RCT_EXTERN_METHOD(getErrors:(RCTPromiseResolveBlock)resolve
|
|
20
20
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
21
|
|
|
22
|
-
RCT_EXTERN_METHOD(
|
|
22
|
+
RCT_EXTERN_METHOD(getIsAvailable:(RCTPromiseResolveBlock)resolve
|
|
23
23
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
24
24
|
|
|
25
|
-
RCT_EXTERN_METHOD(
|
|
25
|
+
RCT_EXTERN_METHOD(getIsTracking:(RCTPromiseResolveBlock)resolve
|
|
26
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
27
|
+
|
|
28
|
+
RCT_EXTERN_METHOD(getLocation:(RCTPromiseResolveBlock)resolve
|
|
26
29
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
27
30
|
|
|
28
|
-
RCT_EXTERN_METHOD(
|
|
31
|
+
RCT_EXTERN_METHOD(getMetadata:(RCTPromiseResolveBlock)resolve
|
|
29
32
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
30
33
|
|
|
31
|
-
RCT_EXTERN_METHOD(
|
|
34
|
+
RCT_EXTERN_METHOD(getName:(RCTPromiseResolveBlock)resolve
|
|
32
35
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
33
36
|
|
|
34
|
-
RCT_EXTERN_METHOD(
|
|
37
|
+
RCT_EXTERN_METHOD(locate:(RCTPromiseResolveBlock)resolve
|
|
35
38
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
36
39
|
|
|
37
|
-
RCT_EXTERN_METHOD(
|
|
40
|
+
RCT_EXTERN_METHOD(setIsAvailable:(NSDictionary *)args
|
|
38
41
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
39
42
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
40
43
|
|
|
41
|
-
RCT_EXTERN_METHOD(
|
|
44
|
+
RCT_EXTERN_METHOD(setIsTracking:(NSDictionary *)args
|
|
42
45
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
43
46
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
44
47
|
|
|
@@ -46,9 +49,8 @@ RCT_EXTERN_METHOD(setMetadata:(NSDictionary *)args
|
|
|
46
49
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
47
50
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
48
51
|
|
|
49
|
-
RCT_EXTERN_METHOD(
|
|
52
|
+
RCT_EXTERN_METHOD(setName:(NSDictionary *)args
|
|
50
53
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
51
54
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
52
55
|
|
|
53
|
-
|
|
54
56
|
@end
|