hypertrack-sdk-react-native 13.3.5 → 13.5.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/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +48 -6
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +22 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +3 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +97 -44
- package/hypertrack-sdk-react-native.podspec +1 -1
- package/ios/HyperTrackReactNativePlugin.m +10 -0
- package/ios/HyperTrackReactNativePlugin.swift +51 -4
- package/ios/common/HyperTrackSDKWrapper.swift +22 -8
- package/ios/common/SDKMethod.swift +3 -0
- package/ios/common/Serialization.swift +52 -4
- package/lib/commonjs/HyperTrack/HyperTrack.js +95 -1
- package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/Order.js +6 -0
- package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +6 -0
- package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/WorkerHandle.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/WorkerHandle.js.map +1 -0
- package/lib/commonjs/index.js +0 -66
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/HyperTrack/HyperTrack.js +95 -1
- package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/module/HyperTrack/data_types/Order.js +2 -0
- package/lib/module/HyperTrack/data_types/Order.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/WorkerHandle.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/WorkerHandle.js.map +1 -0
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/HyperTrack/HyperTrack.d.ts +48 -2
- package/lib/typescript/HyperTrack/data_types/Order.d.ts +6 -0
- package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +7 -0
- package/lib/typescript/HyperTrack/data_types/internal/OrdersInternal.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/WorkerHandle.d.ts +4 -0
- package/lib/typescript/index.d.ts +7 -6
- package/package.json +2 -2
- package/src/HyperTrack/HyperTrack.ts +114 -2
- package/src/HyperTrack/data_types/Order.ts +7 -0
- package/src/HyperTrack/data_types/internal/OrderInternal.ts +8 -0
- package/src/HyperTrack/data_types/internal/OrdersInternal.ts +4 -0
- package/src/HyperTrack/data_types/internal/WorkerHandle.ts +4 -0
- package/src/index.tsx +10 -7
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
package com.reactnativehypertracksdk
|
|
2
2
|
|
|
3
|
-
import com.facebook.react.bridge
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.bridge.WritableArray
|
|
9
|
+
import com.facebook.react.bridge.WritableMap
|
|
4
10
|
import com.facebook.react.module.annotations.ReactModule
|
|
5
11
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
6
|
-
import com.hypertrack.sdk.*
|
|
7
12
|
import com.hypertrack.sdk.android.HyperTrack
|
|
8
|
-
import com.reactnativehypertracksdk.common
|
|
13
|
+
import com.reactnativehypertracksdk.common.HyperTrackSdkWrapper
|
|
9
14
|
import com.reactnativehypertracksdk.common.Serialization.serializeErrors
|
|
10
15
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
|
|
11
16
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
|
|
12
17
|
import com.reactnativehypertracksdk.common.Serialization.serializeLocateResult
|
|
13
18
|
import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult
|
|
19
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeOrders
|
|
20
|
+
import com.reactnativehypertracksdk.common.Success
|
|
14
21
|
|
|
15
22
|
@ReactModule(name = HyperTrackReactNativePlugin.NAME)
|
|
16
23
|
class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
@@ -40,15 +47,28 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
40
47
|
EVENT_ERRORS -> {
|
|
41
48
|
emitEvent(EVENT_ERRORS, serializeErrors(HyperTrack.errors).toWriteableArray())
|
|
42
49
|
}
|
|
50
|
+
|
|
43
51
|
EVENT_IS_AVAILABLE -> {
|
|
44
|
-
emitEvent(
|
|
52
|
+
emitEvent(
|
|
53
|
+
EVENT_IS_AVAILABLE,
|
|
54
|
+
serializeIsAvailable(HyperTrack.isAvailable).toWritableMap(),
|
|
55
|
+
)
|
|
45
56
|
}
|
|
57
|
+
|
|
46
58
|
EVENT_IS_TRACKING -> {
|
|
47
|
-
emitEvent(
|
|
59
|
+
emitEvent(
|
|
60
|
+
EVENT_IS_TRACKING,
|
|
61
|
+
serializeIsTracking(HyperTrack.isTracking).toWritableMap(),
|
|
62
|
+
)
|
|
48
63
|
}
|
|
64
|
+
|
|
49
65
|
EVENT_LOCATION -> {
|
|
50
|
-
emitEvent(
|
|
66
|
+
emitEvent(
|
|
67
|
+
EVENT_LOCATION,
|
|
68
|
+
serializeLocationResult(HyperTrack.location).toWritableMap(),
|
|
69
|
+
)
|
|
51
70
|
}
|
|
71
|
+
|
|
52
72
|
else -> Unit
|
|
53
73
|
}
|
|
54
74
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
@@ -111,6 +131,16 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
111
131
|
HyperTrackSdkWrapper.getName().toPromise(promise)
|
|
112
132
|
}
|
|
113
133
|
|
|
134
|
+
@ReactMethod
|
|
135
|
+
fun getOrders(promise: Promise) {
|
|
136
|
+
HyperTrackSdkWrapper.getOrders().toPromise(promise)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@ReactMethod
|
|
140
|
+
fun getWorkerHandle(promise: Promise) {
|
|
141
|
+
HyperTrackSdkWrapper.getWorkerHandle().toPromise(promise)
|
|
142
|
+
}
|
|
143
|
+
|
|
114
144
|
@ReactMethod
|
|
115
145
|
fun locate(promise: Promise) {
|
|
116
146
|
locateSubscription?.cancel()
|
|
@@ -146,6 +176,11 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
146
176
|
HyperTrackSdkWrapper.setName(args.toHashMap())
|
|
147
177
|
}
|
|
148
178
|
|
|
179
|
+
@ReactMethod
|
|
180
|
+
fun setWorkerHandle(args: ReadableMap) {
|
|
181
|
+
HyperTrackSdkWrapper.setWorkerHandle(args.toHashMap())
|
|
182
|
+
}
|
|
183
|
+
|
|
149
184
|
private fun initListeners(): List<HyperTrack.Cancellable> {
|
|
150
185
|
return mutableListOf<HyperTrack.Cancellable>().also { result ->
|
|
151
186
|
HyperTrack.subscribeToErrors {
|
|
@@ -171,6 +206,12 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
171
206
|
}.also {
|
|
172
207
|
result.add(it)
|
|
173
208
|
}
|
|
209
|
+
|
|
210
|
+
HyperTrack.subscribeToOrders {
|
|
211
|
+
emitEvent(EVENT_ORDERS, serializeOrders(it.values).toWritableMap())
|
|
212
|
+
}.also {
|
|
213
|
+
result.add(it)
|
|
214
|
+
}
|
|
174
215
|
}
|
|
175
216
|
}
|
|
176
217
|
|
|
@@ -199,6 +240,7 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
199
240
|
private const val EVENT_IS_TRACKING = "isTracking"
|
|
200
241
|
private const val EVENT_LOCATE = "locate"
|
|
201
242
|
private const val EVENT_LOCATION = "location"
|
|
243
|
+
private const val EVENT_ORDERS = "orders"
|
|
202
244
|
|
|
203
245
|
const val NAME = "HyperTrackReactNativePlugin"
|
|
204
246
|
}
|
|
@@ -9,6 +9,7 @@ import com.reactnativehypertracksdk.common.Serialization.deserializeIsAvailable
|
|
|
9
9
|
import com.reactnativehypertracksdk.common.Serialization.deserializeIsTracking
|
|
10
10
|
import com.reactnativehypertracksdk.common.Serialization.deserializeMetadata
|
|
11
11
|
import com.reactnativehypertracksdk.common.Serialization.deserializeName
|
|
12
|
+
import com.reactnativehypertracksdk.common.Serialization.deserializeWorkerHandle
|
|
12
13
|
import com.reactnativehypertracksdk.common.Serialization.serializeDeviceId
|
|
13
14
|
import com.reactnativehypertracksdk.common.Serialization.serializeDynamicPublishableKey
|
|
14
15
|
import com.reactnativehypertracksdk.common.Serialization.serializeErrors
|
|
@@ -20,6 +21,8 @@ import com.reactnativehypertracksdk.common.Serialization.serializeLocationSucces
|
|
|
20
21
|
import com.reactnativehypertracksdk.common.Serialization.serializeLocationWithDeviationSuccess
|
|
21
22
|
import com.reactnativehypertracksdk.common.Serialization.serializeMetadata
|
|
22
23
|
import com.reactnativehypertracksdk.common.Serialization.serializeName
|
|
24
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeOrders
|
|
25
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeWorkerHandle
|
|
23
26
|
|
|
24
27
|
typealias Serialized = Map<String, Any?>
|
|
25
28
|
|
|
@@ -137,6 +140,18 @@ internal object HyperTrackSdkWrapper {
|
|
|
137
140
|
)
|
|
138
141
|
}
|
|
139
142
|
|
|
143
|
+
fun getOrders(): WrapperResult<Serialized> {
|
|
144
|
+
return Success(
|
|
145
|
+
serializeOrders(HyperTrack.orders.values),
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fun getWorkerHandle(): WrapperResult<Serialized> {
|
|
150
|
+
return Success(
|
|
151
|
+
serializeWorkerHandle(HyperTrack.workerHandle),
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
140
155
|
fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> {
|
|
141
156
|
return deserializeDynamicPublishableKey(args)
|
|
142
157
|
.mapSuccess { publishableKey ->
|
|
@@ -174,4 +189,11 @@ internal object HyperTrackSdkWrapper {
|
|
|
174
189
|
HyperTrack.name = name
|
|
175
190
|
}
|
|
176
191
|
}
|
|
192
|
+
|
|
193
|
+
fun setWorkerHandle(args: Serialized): WrapperResult<Unit> {
|
|
194
|
+
return deserializeWorkerHandle(args)
|
|
195
|
+
.mapSuccess { workerHandle ->
|
|
196
|
+
HyperTrack.workerHandle = workerHandle
|
|
197
|
+
}
|
|
198
|
+
}
|
|
177
199
|
}
|
|
@@ -18,15 +18,15 @@ internal object Serialization {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
fun deserializeGeotagData(map:
|
|
21
|
+
fun deserializeGeotagData(map: Serialized): WrapperResult<GeotagData> {
|
|
22
22
|
return parse(map) {
|
|
23
23
|
val data =
|
|
24
24
|
it
|
|
25
|
-
.get<
|
|
25
|
+
.get<Serialized>(KEY_GEOTAG_DATA)
|
|
26
26
|
.getOrThrow()
|
|
27
27
|
val expectedLocationData =
|
|
28
28
|
it
|
|
29
|
-
.getOptional<
|
|
29
|
+
.getOptional<Serialized>(KEY_GEOTAG_EXPECTED_LOCATION)
|
|
30
30
|
.getOrThrow()
|
|
31
31
|
val expectedLocation =
|
|
32
32
|
expectedLocationData?.let {
|
|
@@ -34,12 +34,12 @@ internal object Serialization {
|
|
|
34
34
|
}
|
|
35
35
|
val orderHandleData =
|
|
36
36
|
it
|
|
37
|
-
.getOptional<
|
|
37
|
+
.getOptional<Serialized>(KEY_GEOTAG_ORDER_HANDLE)
|
|
38
38
|
.getOrThrow()
|
|
39
39
|
val orderHandle = orderHandleData?.let { deserializeOrderHandle(it).getOrThrow() }
|
|
40
40
|
val orderStatusData =
|
|
41
41
|
it
|
|
42
|
-
.getOptional<
|
|
42
|
+
.getOptional<Serialized>(KEY_GEOTAG_ORDER_STATUS)
|
|
43
43
|
.getOrThrow()
|
|
44
44
|
val orderStatus = orderStatusData?.let { deserializeOrderStatus(it).getOrThrow() }
|
|
45
45
|
GeotagData(
|
|
@@ -51,7 +51,7 @@ internal object Serialization {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
fun deserializeIsAvailable(isAvailable:
|
|
54
|
+
fun deserializeIsAvailable(isAvailable: Serialized): WrapperResult<Boolean> {
|
|
55
55
|
return parse(isAvailable) {
|
|
56
56
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_AVAILABLE)
|
|
57
57
|
it
|
|
@@ -60,7 +60,7 @@ internal object Serialization {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
fun deserializeIsTracking(isTracking:
|
|
63
|
+
fun deserializeIsTracking(isTracking: Serialized): WrapperResult<Boolean> {
|
|
64
64
|
return parse(isTracking) {
|
|
65
65
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_TRACKING)
|
|
66
66
|
it
|
|
@@ -69,16 +69,16 @@ internal object Serialization {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
fun deserializeMetadata(metadata:
|
|
72
|
+
fun deserializeMetadata(metadata: Serialized): WrapperResult<Serialized> {
|
|
73
73
|
return parse(metadata) {
|
|
74
74
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_METADATA)
|
|
75
75
|
it
|
|
76
|
-
.get<
|
|
76
|
+
.get<Serialized>(KEY_VALUE)
|
|
77
77
|
.getOrThrow()
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
fun deserializeName(name:
|
|
81
|
+
fun deserializeName(name: Serialized): WrapperResult<String> {
|
|
82
82
|
return parse(name) {
|
|
83
83
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_NAME)
|
|
84
84
|
it
|
|
@@ -87,7 +87,16 @@ internal object Serialization {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
fun
|
|
90
|
+
fun deserializeWorkerHandle(map: Serialized): WrapperResult<String> {
|
|
91
|
+
return parse(map) {
|
|
92
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_WORKER_HANDLE)
|
|
93
|
+
it
|
|
94
|
+
.get<String>(KEY_VALUE)
|
|
95
|
+
.getOrThrow()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fun serializeDeviceId(deviceId: String): Serialized {
|
|
91
100
|
return mapOf(
|
|
92
101
|
KEY_TYPE to TYPE_DEVICE_ID,
|
|
93
102
|
KEY_VALUE to deviceId,
|
|
@@ -127,21 +136,21 @@ internal object Serialization {
|
|
|
127
136
|
}
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
fun serializeIsAvailable(isAvailable: Boolean):
|
|
139
|
+
fun serializeIsAvailable(isAvailable: Boolean): Serialized {
|
|
131
140
|
return mapOf(
|
|
132
141
|
KEY_TYPE to TYPE_IS_AVAILABLE,
|
|
133
142
|
KEY_VALUE to isAvailable,
|
|
134
143
|
)
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
fun serializeIsTracking(isTracking: Boolean):
|
|
146
|
+
fun serializeIsTracking(isTracking: Boolean): Serialized {
|
|
138
147
|
return mapOf(
|
|
139
148
|
KEY_TYPE to TYPE_IS_TRACKING,
|
|
140
149
|
KEY_VALUE to isTracking,
|
|
141
150
|
)
|
|
142
151
|
}
|
|
143
152
|
|
|
144
|
-
fun serializeLocateResult(locationResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>):
|
|
153
|
+
fun serializeLocateResult(locationResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>): Serialized {
|
|
145
154
|
return when (locationResult) {
|
|
146
155
|
is Result.Failure -> {
|
|
147
156
|
serializeFailure(serializeErrors(locationResult.failure))
|
|
@@ -153,7 +162,7 @@ internal object Serialization {
|
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
164
|
|
|
156
|
-
fun serializeLocationResult(locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>):
|
|
165
|
+
fun serializeLocationResult(locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>): Serialized {
|
|
157
166
|
return when (locationResult) {
|
|
158
167
|
is Result.Failure -> {
|
|
159
168
|
serializeLocationErrorFailure(locationResult.failure)
|
|
@@ -165,15 +174,15 @@ internal object Serialization {
|
|
|
165
174
|
}
|
|
166
175
|
}
|
|
167
176
|
|
|
168
|
-
fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError):
|
|
177
|
+
fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError): Serialized {
|
|
169
178
|
return serializeFailure(serializeLocationError(locationError))
|
|
170
179
|
}
|
|
171
180
|
|
|
172
|
-
fun serializeLocationSuccess(location: HyperTrack.Location):
|
|
181
|
+
fun serializeLocationSuccess(location: HyperTrack.Location): Serialized {
|
|
173
182
|
return serializeSuccess(serializeLocation(location))
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
fun serializeLocationWithDeviationSuccess(locationWithDeviation: HyperTrack.LocationWithDeviation):
|
|
185
|
+
fun serializeLocationWithDeviationSuccess(locationWithDeviation: HyperTrack.LocationWithDeviation): Serialized {
|
|
177
186
|
return serializeSuccess(
|
|
178
187
|
serializeLocationWithDeviation(
|
|
179
188
|
locationWithDeviation,
|
|
@@ -181,37 +190,47 @@ internal object Serialization {
|
|
|
181
190
|
)
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
fun
|
|
185
|
-
return mapOf(
|
|
186
|
-
KEY_TYPE to TYPE_LOCATION,
|
|
187
|
-
KEY_VALUE to
|
|
188
|
-
mapOf(
|
|
189
|
-
KEY_LATITUDE to location.latitude,
|
|
190
|
-
KEY_LONGITUDE to location.longitude,
|
|
191
|
-
),
|
|
192
|
-
)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
fun serializeMetadata(metadata: Map<String, Any?>): Map<String, Any?> {
|
|
193
|
+
fun serializeMetadata(metadata: Serialized): Serialized {
|
|
196
194
|
return mapOf(
|
|
197
195
|
KEY_TYPE to TYPE_METADATA,
|
|
198
196
|
KEY_VALUE to metadata,
|
|
199
197
|
)
|
|
200
198
|
}
|
|
201
199
|
|
|
202
|
-
fun serializeName(name: String):
|
|
200
|
+
fun serializeName(name: String): Serialized {
|
|
203
201
|
return mapOf(
|
|
204
202
|
KEY_TYPE to TYPE_NAME,
|
|
205
203
|
KEY_VALUE to name,
|
|
206
204
|
)
|
|
207
205
|
}
|
|
208
206
|
|
|
209
|
-
|
|
207
|
+
fun serializeOrders(orders: Collection<HyperTrack.Order>): Serialized {
|
|
208
|
+
return mapOf(
|
|
209
|
+
KEY_TYPE to TYPE_ORDERS,
|
|
210
|
+
KEY_VALUE to
|
|
211
|
+
orders.mapIndexed { index, order ->
|
|
212
|
+
mapOf(
|
|
213
|
+
KEY_ORDER_HANDLE to order.orderHandle,
|
|
214
|
+
KEY_ORDER_INDEX to index,
|
|
215
|
+
KEY_ORDER_IS_INSIDE_GEOFENCE to serializeIsInsideGeofence(order.isInsideGeofence),
|
|
216
|
+
)
|
|
217
|
+
},
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fun serializeWorkerHandle(workerHandle: String): Serialized {
|
|
222
|
+
return mapOf(
|
|
223
|
+
KEY_TYPE to TYPE_WORKER_HANDLE,
|
|
224
|
+
KEY_VALUE to workerHandle,
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private fun deserializeLocation(map: Serialized): WrapperResult<Location> {
|
|
210
229
|
return parse(map) {
|
|
211
230
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
|
|
212
231
|
val value =
|
|
213
232
|
it
|
|
214
|
-
.get<
|
|
233
|
+
.get<Serialized>(KEY_VALUE)
|
|
215
234
|
.getOrThrow()
|
|
216
235
|
parse(value) { parser ->
|
|
217
236
|
val latitude =
|
|
@@ -230,7 +249,7 @@ internal object Serialization {
|
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
251
|
|
|
233
|
-
private fun deserializeOrderHandle(map:
|
|
252
|
+
private fun deserializeOrderHandle(map: Serialized): WrapperResult<String> {
|
|
234
253
|
return parse(map) {
|
|
235
254
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_ORDER_HANDLE)
|
|
236
255
|
it
|
|
@@ -239,7 +258,7 @@ internal object Serialization {
|
|
|
239
258
|
}
|
|
240
259
|
}
|
|
241
260
|
|
|
242
|
-
private fun deserializeOrderStatus(map:
|
|
261
|
+
private fun deserializeOrderStatus(map: Serialized): WrapperResult<HyperTrack.OrderStatus> {
|
|
243
262
|
return parse(map) {
|
|
244
263
|
when (it.get<String>(KEY_TYPE).getOrThrow()) {
|
|
245
264
|
TYPE_GEOTAG_ORDER_STATUS_CLOCK_IN -> HyperTrack.OrderStatus.ClockIn
|
|
@@ -254,7 +273,35 @@ internal object Serialization {
|
|
|
254
273
|
}
|
|
255
274
|
}
|
|
256
275
|
|
|
257
|
-
private fun
|
|
276
|
+
private fun serializeIsInsideGeofence(isInsideGeofence: Result<Boolean, HyperTrack.LocationError>): Serialized {
|
|
277
|
+
return when (isInsideGeofence) {
|
|
278
|
+
is Result.Failure -> {
|
|
279
|
+
serializeFailure(serializeLocationError(isInsideGeofence.failure))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
is Result.Success -> {
|
|
283
|
+
serializeSuccess(
|
|
284
|
+
mapOf(
|
|
285
|
+
KEY_TYPE to TYPE_IS_INSIDE_GEOFENCE,
|
|
286
|
+
KEY_VALUE to isInsideGeofence.success,
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private fun serializeLocation(location: HyperTrack.Location): Serialized {
|
|
294
|
+
return mapOf(
|
|
295
|
+
KEY_TYPE to TYPE_LOCATION,
|
|
296
|
+
KEY_VALUE to
|
|
297
|
+
mapOf(
|
|
298
|
+
KEY_LATITUDE to location.latitude,
|
|
299
|
+
KEY_LONGITUDE to location.longitude,
|
|
300
|
+
),
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private fun serializeLocationWithDeviation(locationWithDeviation: HyperTrack.LocationWithDeviation): Serialized {
|
|
258
305
|
return mapOf(
|
|
259
306
|
KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION,
|
|
260
307
|
KEY_VALUE to
|
|
@@ -265,28 +312,28 @@ internal object Serialization {
|
|
|
265
312
|
)
|
|
266
313
|
}
|
|
267
314
|
|
|
268
|
-
private fun serializeFailure(failure: List<
|
|
315
|
+
private fun serializeFailure(failure: List<Serialized>): Serialized {
|
|
269
316
|
return mapOf(
|
|
270
317
|
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
271
318
|
KEY_VALUE to failure,
|
|
272
319
|
)
|
|
273
320
|
}
|
|
274
321
|
|
|
275
|
-
private fun serializeFailure(failure:
|
|
322
|
+
private fun serializeFailure(failure: Serialized): Serialized {
|
|
276
323
|
return mapOf(
|
|
277
324
|
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
278
325
|
KEY_VALUE to failure,
|
|
279
326
|
)
|
|
280
327
|
}
|
|
281
328
|
|
|
282
|
-
private fun serializeSuccess(success:
|
|
329
|
+
private fun serializeSuccess(success: Serialized): Serialized {
|
|
283
330
|
return mapOf(
|
|
284
331
|
KEY_TYPE to TYPE_RESULT_SUCCESS,
|
|
285
332
|
KEY_VALUE to success,
|
|
286
333
|
)
|
|
287
334
|
}
|
|
288
335
|
|
|
289
|
-
private fun serializeLocationError(locationError: HyperTrack.LocationError):
|
|
336
|
+
private fun serializeLocationError(locationError: HyperTrack.LocationError): Serialized {
|
|
290
337
|
return when (locationError) {
|
|
291
338
|
HyperTrack.LocationError.NotRunning -> {
|
|
292
339
|
mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
|
|
@@ -308,7 +355,7 @@ internal object Serialization {
|
|
|
308
355
|
}
|
|
309
356
|
|
|
310
357
|
fun <T> parse(
|
|
311
|
-
source:
|
|
358
|
+
source: Serialized,
|
|
312
359
|
parseFunction: (Parser) -> T,
|
|
313
360
|
): WrapperResult<T> {
|
|
314
361
|
val parser = Parser(source)
|
|
@@ -330,7 +377,7 @@ internal object Serialization {
|
|
|
330
377
|
}
|
|
331
378
|
|
|
332
379
|
internal class Parser(
|
|
333
|
-
private val source:
|
|
380
|
+
private val source: Serialized,
|
|
334
381
|
) {
|
|
335
382
|
private val _exceptions = mutableListOf<Exception>()
|
|
336
383
|
val exceptions: List<Exception> = _exceptions
|
|
@@ -396,11 +443,14 @@ internal object Serialization {
|
|
|
396
443
|
private const val TYPE_DYNAMIC_PUBLISHABLE_KEY = "dynamicPublishableKey"
|
|
397
444
|
private const val TYPE_ERROR = "error"
|
|
398
445
|
private const val TYPE_IS_AVAILABLE = "isAvailable"
|
|
446
|
+
private const val TYPE_IS_INSIDE_GEOFENCE = "isInsideGeofence"
|
|
399
447
|
private const val TYPE_IS_TRACKING = "isTracking"
|
|
400
|
-
private const val TYPE_METADATA = "metadata"
|
|
401
|
-
private const val TYPE_NAME = "name"
|
|
402
448
|
private const val TYPE_LOCATION = "location"
|
|
403
449
|
private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation"
|
|
450
|
+
private const val TYPE_METADATA = "metadata"
|
|
451
|
+
private const val TYPE_NAME = "name"
|
|
452
|
+
private const val TYPE_ORDERS = "orders"
|
|
453
|
+
private const val TYPE_WORKER_HANDLE = "workerHandle"
|
|
404
454
|
|
|
405
455
|
private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
|
|
406
456
|
private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning"
|
|
@@ -419,5 +469,8 @@ internal object Serialization {
|
|
|
419
469
|
private const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation"
|
|
420
470
|
private const val KEY_GEOTAG_ORDER_HANDLE = "orderHandle"
|
|
421
471
|
private const val KEY_GEOTAG_ORDER_STATUS = "orderStatus"
|
|
472
|
+
private const val KEY_ORDER_IS_INSIDE_GEOFENCE = "isInsideGeofence"
|
|
422
473
|
private const val KEY_LOCATION = "location"
|
|
474
|
+
private const val KEY_ORDER_HANDLE = "orderHandle"
|
|
475
|
+
private const val KEY_ORDER_INDEX = "orderIndex"
|
|
423
476
|
}
|
|
@@ -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', '5.
|
|
21
|
+
s.dependency 'HyperTrack', '5.7.0'
|
|
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
|
|
@@ -37,6 +37,12 @@ RCT_EXTERN_METHOD(getMetadata:(RCTPromiseResolveBlock)resolve
|
|
|
37
37
|
RCT_EXTERN_METHOD(getName:(RCTPromiseResolveBlock)resolve
|
|
38
38
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
39
39
|
|
|
40
|
+
RCT_EXTERN_METHOD(getOrders:(RCTPromiseResolveBlock)resolve
|
|
41
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
42
|
+
|
|
43
|
+
RCT_EXTERN_METHOD(getWorkerHandle:(RCTPromiseResolveBlock)resolve
|
|
44
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
45
|
+
|
|
40
46
|
RCT_EXTERN_METHOD(locate:(RCTPromiseResolveBlock)resolve
|
|
41
47
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
42
48
|
|
|
@@ -60,4 +66,8 @@ RCT_EXTERN_METHOD(setName:(NSDictionary *)args
|
|
|
60
66
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
61
67
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
62
68
|
|
|
69
|
+
RCT_EXTERN_METHOD(setWorkerHandle:(NSDictionary *)args
|
|
70
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
71
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
72
|
+
|
|
63
73
|
@end
|
|
@@ -5,6 +5,7 @@ struct Subscriptions {
|
|
|
5
5
|
let isAvailableSubscription: HyperTrack.Cancellable
|
|
6
6
|
let isTrackingSubscription: HyperTrack.Cancellable
|
|
7
7
|
let errorsSubscription: HyperTrack.Cancellable
|
|
8
|
+
let ordersSubscription: HyperTrack.Cancellable
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
@objc(HyperTrackReactNativePlugin)
|
|
@@ -14,6 +15,7 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
14
15
|
private let eventIsTracking = "isTracking"
|
|
15
16
|
private let eventLocate = "locate"
|
|
16
17
|
private let eventLocation = "location"
|
|
18
|
+
private let eventOrders = "orders"
|
|
17
19
|
|
|
18
20
|
private var subscriptions: Subscriptions? = nil
|
|
19
21
|
private var locateSubscription: HyperTrack.Cancellable? = nil
|
|
@@ -29,6 +31,7 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
29
31
|
eventIsTracking,
|
|
30
32
|
eventLocate,
|
|
31
33
|
eventLocation,
|
|
34
|
+
eventOrders,
|
|
32
35
|
]
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -52,6 +55,8 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
52
55
|
sendEvent(withName: eventErrors, body: serializeErrors(HyperTrack.errors))
|
|
53
56
|
case eventLocation:
|
|
54
57
|
sendEvent(withName: eventLocation, body: serializeLocationResult(HyperTrack.location))
|
|
58
|
+
case eventOrders:
|
|
59
|
+
sendEvent(withName: eventOrders, body: serializeOrders(Array(HyperTrack.orders)))
|
|
55
60
|
default:
|
|
56
61
|
return
|
|
57
62
|
}
|
|
@@ -168,6 +173,30 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
168
173
|
)
|
|
169
174
|
}
|
|
170
175
|
|
|
176
|
+
@objc func getOrders(
|
|
177
|
+
_ resolve: RCTPromiseResolveBlock,
|
|
178
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
179
|
+
) {
|
|
180
|
+
sendAsPromise(
|
|
181
|
+
hypertrack_sdk_react_native.getOrders(),
|
|
182
|
+
method: .getOrders,
|
|
183
|
+
resolve,
|
|
184
|
+
reject
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@objc func getWorkerHandle(
|
|
189
|
+
_ resolve: RCTPromiseResolveBlock,
|
|
190
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
191
|
+
) {
|
|
192
|
+
sendAsPromise(
|
|
193
|
+
hypertrack_sdk_react_native.getWorkerHandle(),
|
|
194
|
+
method: .getWorkerHandle,
|
|
195
|
+
resolve,
|
|
196
|
+
reject
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
171
200
|
@objc func locate(
|
|
172
201
|
_ resolve: RCTPromiseResolveBlock,
|
|
173
202
|
rejecter reject: RCTPromiseRejectBlock
|
|
@@ -216,6 +245,21 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
216
245
|
)
|
|
217
246
|
}
|
|
218
247
|
|
|
248
|
+
@objc func setIsTracking(
|
|
249
|
+
_ args: NSDictionary,
|
|
250
|
+
resolver resolve: RCTPromiseResolveBlock,
|
|
251
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
252
|
+
) {
|
|
253
|
+
sendAsPromise(
|
|
254
|
+
hypertrack_sdk_react_native.setIsTracking(
|
|
255
|
+
args as! [String: Any]
|
|
256
|
+
),
|
|
257
|
+
method: .setIsTracking,
|
|
258
|
+
resolve,
|
|
259
|
+
reject
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
|
|
219
263
|
@objc func setMetadata(
|
|
220
264
|
_ args: NSDictionary,
|
|
221
265
|
resolver resolve: RCTPromiseResolveBlock,
|
|
@@ -244,16 +288,16 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
244
288
|
)
|
|
245
289
|
}
|
|
246
290
|
|
|
247
|
-
@objc func
|
|
291
|
+
@objc func setWorkerHandle(
|
|
248
292
|
_ args: NSDictionary,
|
|
249
293
|
resolver resolve: RCTPromiseResolveBlock,
|
|
250
294
|
rejecter reject: RCTPromiseRejectBlock
|
|
251
295
|
) {
|
|
252
296
|
sendAsPromise(
|
|
253
|
-
hypertrack_sdk_react_native.
|
|
297
|
+
hypertrack_sdk_react_native.setWorkerHandle(
|
|
254
298
|
args as! [String: Any]
|
|
255
299
|
),
|
|
256
|
-
method: .
|
|
300
|
+
method: .setWorkerHandle,
|
|
257
301
|
resolve,
|
|
258
302
|
reject
|
|
259
303
|
)
|
|
@@ -272,7 +316,10 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
272
316
|
let locationSubscription = HyperTrack.subscribeToLocation { locationResult in
|
|
273
317
|
self.sendEvent(withName: self.eventLocation, body: serializeLocationResult(locationResult))
|
|
274
318
|
}
|
|
275
|
-
|
|
319
|
+
let ordersSubscription = HyperTrack.subscribeToOrders { orders in
|
|
320
|
+
self.sendEvent(withName: self.eventOrders, body: serializeOrders(Array(orders)))
|
|
321
|
+
}
|
|
322
|
+
return Subscriptions(locationSubscription: locationSubscription, isAvailableSubscription: isAvailableSubscription, isTrackingSubscription: isTrackingSubscription, errorsSubscription: errorsSubscription, ordersSubscription: ordersSubscription)
|
|
276
323
|
}
|
|
277
324
|
}
|
|
278
325
|
|