hypertrack-sdk-react-native 10.0.3-psl19.1 → 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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
3
3
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
4
4
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
5
|
|
|
6
|
+
## [11.0.0] - 2023-09-08
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `locate()` to ask for one-time user location
|
|
11
|
+
- `subscribeToLocation()` to subscribe to user location updates
|
|
12
|
+
- `getErrors()`
|
|
13
|
+
- `getName()`
|
|
14
|
+
- `getMetadata()`
|
|
15
|
+
- HyperTrackError types:
|
|
16
|
+
- `noExemptionFromBackgroundStartRestrictions`
|
|
17
|
+
- `permissionsNotificationsDenied`
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Updated HyperTrack Android SDK to 7.0.1
|
|
22
|
+
- Add Android SDK plugins (`location-services-google-19-0-1` and `push-service-firebase`)
|
|
23
|
+
- Updated HyperTrack iOS SDK to 5.0.1
|
|
24
|
+
- The whole HyperTrack API is now static
|
|
25
|
+
- Changed the way to provide publishableKey (you need to add `HyperTrackPublishableKey` `meta-data` item to your `AndroidManifest.xml`)
|
|
26
|
+
- Renamed HyperTrackError types:
|
|
27
|
+
- `gpsSignalLost` to `locationSignalLost`
|
|
28
|
+
- `locationPermissionsDenied` to `permissionsLocationDenied`
|
|
29
|
+
- `locationPermissionsInsufficientForBackground` to `permissionsLocationInsufficientForBackground`
|
|
30
|
+
- `locationPermissionsNotDetermined` to `permissionsLocationNotDetermined`
|
|
31
|
+
- `locationPermissionsProvisional` to `locationPermissionsProvisional`
|
|
32
|
+
- `locationPermissionsReducedAccuracy` to `permissionsLocationReducedAccuracy`
|
|
33
|
+
- `locationPermissionsRestricted` to `permissionsLocationRestricted`
|
|
34
|
+
- Renamed `isAvailable()` to `getIsAvailable()`
|
|
35
|
+
- Renamed `isTracking()` to `getIsTracking()`
|
|
36
|
+
- Renamed `setAvailability()` to `setIsAvailable(boolean)`
|
|
37
|
+
- Changed `startTracking()` and `stopTracking()` to `setIsTracking(boolean)`
|
|
38
|
+
- Renamed `subscribeToTracking()` to `subscribeToIsTracking()`
|
|
39
|
+
- Renamed `subscribeToAvailability()` to `subscribeToIsAvailable()`
|
|
40
|
+
|
|
41
|
+
### Removed
|
|
42
|
+
|
|
43
|
+
- `initialize()` method (the API is now static)
|
|
44
|
+
- `SdkInitParams` (the config now should be done with the `AndroidManifest` metadata and `Info.plist`)
|
|
45
|
+
- Motion Activity permissions are not required for tracking anymore
|
|
46
|
+
- HyperTrackError types:
|
|
47
|
+
- `motionActivityPermissionsDenied`
|
|
48
|
+
- `motionActivityServicesDisabled`
|
|
49
|
+
- `motionActivityServicesUnavailable`
|
|
50
|
+
- `motionActivityPermissionsRestricted`
|
|
51
|
+
- `networkConnectionUnavailable`
|
|
52
|
+
- `sync()` method
|
|
53
|
+
|
|
6
54
|
## [10.0.3] - 2023-08-04
|
|
7
55
|
|
|
8
56
|
### Fixed
|
package/CONTRIBUTING.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- HyperTrackSdk_HyperTrackSDKVersion
|
|
12
12
|
- ios
|
|
13
13
|
- [hypertrack-sdk-react-native.podspec](hypertrack-sdk-react-native.podspec)
|
|
14
|
-
- s.dependency 'HyperTrack
|
|
14
|
+
- s.dependency 'HyperTrack', '**version**'
|
|
15
15
|
|
|
16
16
|
2. Increment wrapper version
|
|
17
17
|
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-

|
|
6
|
+

|
|
7
7
|
|
|
8
8
|
[HyperTrack](https://www.hypertrack.com) lets you add live location tracking to your mobile app. Live location is made available along with ongoing activity, tracking controls and tracking outage with reasons.
|
|
9
9
|
|
package/android/build.gradle
CHANGED
|
@@ -144,8 +144,12 @@ def hyperTrackSdk_version = getExtOrDefault('HyperTrackSDKVersion')
|
|
|
144
144
|
dependencies {
|
|
145
145
|
//noinspection GradleDynamicVersion
|
|
146
146
|
implementation "com.facebook.react:react-native:+"
|
|
147
|
+
|
|
147
148
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
148
|
-
|
|
149
|
+
|
|
150
|
+
implementation "com.hypertrack:sdk-android:$hyperTrackSdk_version"
|
|
151
|
+
implementation "com.hypertrack:location-services-google-19-0-1:$hyperTrackSdk_version"
|
|
152
|
+
implementation "com.hypertrack:push-service-firebase:$hyperTrackSdk_version"
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
if (isNewArchitectureEnabled()) {
|
|
@@ -4,120 +4,67 @@ import com.facebook.react.bridge.*
|
|
|
4
4
|
import com.facebook.react.module.annotations.ReactModule
|
|
5
5
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
6
6
|
import com.hypertrack.sdk.*
|
|
7
|
-
import com.hypertrack.sdk.
|
|
8
|
-
import com.hypertrack.sdk.TrackingStateObserver.OnTrackingStateChangeListener
|
|
7
|
+
import com.hypertrack.sdk.android.HyperTrack
|
|
9
8
|
import com.reactnativehypertracksdk.common.*
|
|
9
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeErrors
|
|
10
10
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
|
|
11
11
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
|
|
12
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeLocateResult
|
|
13
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeLocation
|
|
14
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult
|
|
12
15
|
|
|
13
|
-
@Suppress("ComplexRedundantLet")
|
|
14
16
|
@ReactModule(name = HyperTrackReactNativePlugin.NAME)
|
|
15
17
|
class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
16
18
|
ReactContextBaseJavaModule(reactContext) {
|
|
17
19
|
|
|
18
|
-
var
|
|
19
|
-
var availabilityListener: OnAvailabilityStateChangeListener? = null
|
|
20
|
+
private var locateSubscription: HyperTrack.Cancellable? = null
|
|
20
21
|
|
|
21
22
|
override fun getName(): String {
|
|
22
23
|
return NAME
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* ReactNative built-in methods
|
|
28
|
+
*/
|
|
29
|
+
|
|
25
30
|
@ReactMethod
|
|
26
|
-
fun addListener(
|
|
27
|
-
when
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
is Success -> {
|
|
32
|
-
emitIsTracking(it.success)
|
|
33
|
-
}
|
|
34
|
-
is Failure -> {
|
|
35
|
-
throw Exception("isTracking failed: ${it.failure}", it.failure)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
31
|
+
fun addListener(eventName: String?) {
|
|
32
|
+
// called when RN app subscribes to an event
|
|
33
|
+
when (eventName) {
|
|
34
|
+
EVENT_ERRORS -> {
|
|
35
|
+
emitEvent(EVENT_ERRORS, serializeErrors(HyperTrack.errors).toWriteableArray())
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
when (it) {
|
|
43
|
-
is Success -> {
|
|
44
|
-
emitIsAvailable(it.success)
|
|
45
|
-
}
|
|
46
|
-
is Failure -> {
|
|
47
|
-
throw Exception("isAvailable failed: ${it.failure}", it.failure)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
37
|
+
EVENT_IS_AVAILABLE -> {
|
|
38
|
+
emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(HyperTrack.isAvailable).toWritableMap())
|
|
51
39
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
EVENT_IS_TRACKING -> {
|
|
41
|
+
emitEvent(EVENT_IS_TRACKING, serializeIsTracking(HyperTrack.isTracking).toWritableMap())
|
|
42
|
+
}
|
|
43
|
+
EVENT_LOCATION -> {
|
|
44
|
+
emitEvent(EVENT_LOCATION, serializeLocationResult(HyperTrack.location).toWritableMap())
|
|
56
45
|
}
|
|
57
46
|
else -> Unit
|
|
58
47
|
}
|
|
59
48
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
60
49
|
}
|
|
61
50
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
override fun initialize() {
|
|
52
|
+
super.initialize()
|
|
53
|
+
initListeners()
|
|
65
54
|
}
|
|
66
55
|
|
|
67
56
|
@ReactMethod
|
|
68
|
-
fun
|
|
69
|
-
|
|
70
|
-
promise: Promise
|
|
71
|
-
) {
|
|
72
|
-
HyperTrackSdkWrapper
|
|
73
|
-
.initializeSdk(initParams.toHashMap())
|
|
74
|
-
.mapSuccess { sdk ->
|
|
75
|
-
initListeners(sdk)
|
|
76
|
-
}
|
|
77
|
-
.toPromise(promise)
|
|
57
|
+
fun removeListeners(type: Int?) {
|
|
58
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
78
59
|
}
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
trackingStateListener = null
|
|
84
|
-
}
|
|
85
|
-
trackingStateListener = object : OnTrackingStateChangeListener {
|
|
86
|
-
override fun onError(trackingError: TrackingError) {
|
|
87
|
-
emitErrors(HyperTrackSdkWrapper.getErrors(trackingError))
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
override fun onTrackingStart() {
|
|
91
|
-
emitIsTracking(serializeIsTracking(true))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
override fun onTrackingStop() {
|
|
95
|
-
emitIsTracking(serializeIsTracking(false))
|
|
96
|
-
}
|
|
97
|
-
}.also {
|
|
98
|
-
sdkInstance.addTrackingListener(it)
|
|
99
|
-
}
|
|
61
|
+
/**
|
|
62
|
+
* SDK methods
|
|
63
|
+
*/
|
|
100
64
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
availabilityListener =
|
|
106
|
-
object : AvailabilityStateObserver.OnAvailabilityStateChangeListener {
|
|
107
|
-
override fun onError(p0: AvailabilityError) {
|
|
108
|
-
// ignored, errors are handled by trackingStateListener
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
override fun onAvailable() {
|
|
112
|
-
emitIsAvailable(serializeIsAvailable(true))
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
override fun onUnavailable() {
|
|
116
|
-
emitIsAvailable(serializeIsAvailable(false))
|
|
117
|
-
}
|
|
118
|
-
}.also {
|
|
119
|
-
sdkInstance.addAvailabilityListener(it)
|
|
120
|
-
}
|
|
65
|
+
@ReactMethod
|
|
66
|
+
fun addGeotag(args: ReadableMap, promise: Promise) {
|
|
67
|
+
HyperTrackSdkWrapper.addGeotag(args.toHashMap()).toPromise(promise)
|
|
121
68
|
}
|
|
122
69
|
|
|
123
70
|
@ReactMethod
|
|
@@ -126,43 +73,52 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
126
73
|
}
|
|
127
74
|
|
|
128
75
|
@ReactMethod
|
|
129
|
-
fun
|
|
130
|
-
HyperTrackSdkWrapper.
|
|
76
|
+
fun getErrors(promise: Promise) {
|
|
77
|
+
HyperTrackSdkWrapper.getErrors().toPromise(promise)
|
|
131
78
|
}
|
|
132
79
|
|
|
133
80
|
@ReactMethod
|
|
134
|
-
fun
|
|
135
|
-
HyperTrackSdkWrapper.
|
|
81
|
+
fun getIsAvailable(promise: Promise) {
|
|
82
|
+
HyperTrackSdkWrapper.getIsAvailable().toPromise(promise)
|
|
136
83
|
}
|
|
137
84
|
|
|
138
85
|
@ReactMethod
|
|
139
|
-
fun
|
|
140
|
-
HyperTrackSdkWrapper.
|
|
86
|
+
fun getIsTracking(promise: Promise) {
|
|
87
|
+
HyperTrackSdkWrapper.getIsTracking().toPromise(promise)
|
|
141
88
|
}
|
|
142
89
|
|
|
143
90
|
@ReactMethod
|
|
144
|
-
fun
|
|
145
|
-
HyperTrackSdkWrapper.
|
|
91
|
+
fun getLocation(promise: Promise) {
|
|
92
|
+
HyperTrackSdkWrapper.getLocation().toPromise(promise)
|
|
146
93
|
}
|
|
147
94
|
|
|
148
95
|
@ReactMethod
|
|
149
|
-
fun
|
|
150
|
-
HyperTrackSdkWrapper.
|
|
96
|
+
fun getMetadata(promise: Promise) {
|
|
97
|
+
HyperTrackSdkWrapper.getMetadata().toPromise(promise)
|
|
151
98
|
}
|
|
152
99
|
|
|
153
100
|
@ReactMethod
|
|
154
|
-
fun
|
|
155
|
-
HyperTrackSdkWrapper.
|
|
101
|
+
fun getName(promise: Promise) {
|
|
102
|
+
HyperTrackSdkWrapper.getName().toPromise(promise)
|
|
156
103
|
}
|
|
157
104
|
|
|
158
105
|
@ReactMethod
|
|
159
|
-
fun
|
|
160
|
-
|
|
106
|
+
fun locate(promise: Promise) {
|
|
107
|
+
locateSubscription?.cancel()
|
|
108
|
+
locateSubscription = HyperTrack.locate {
|
|
109
|
+
emitEvent(EVENT_LOCATE, serializeLocateResult(it).toWritableMap())
|
|
110
|
+
}
|
|
111
|
+
Success(Unit).toPromise(promise)
|
|
161
112
|
}
|
|
162
113
|
|
|
163
114
|
@ReactMethod
|
|
164
|
-
fun
|
|
165
|
-
HyperTrackSdkWrapper.
|
|
115
|
+
fun setIsAvailable(args: ReadableMap) {
|
|
116
|
+
HyperTrackSdkWrapper.setIsAvailable(args.toHashMap())
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@ReactMethod
|
|
120
|
+
fun setIsTracking(args: ReadableMap) {
|
|
121
|
+
HyperTrackSdkWrapper.setIsTracking(args.toHashMap())
|
|
166
122
|
}
|
|
167
123
|
|
|
168
124
|
@ReactMethod
|
|
@@ -171,20 +127,26 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
171
127
|
}
|
|
172
128
|
|
|
173
129
|
@ReactMethod
|
|
174
|
-
fun
|
|
175
|
-
HyperTrackSdkWrapper.
|
|
130
|
+
fun setName(args: ReadableMap) {
|
|
131
|
+
HyperTrackSdkWrapper.setName(args.toHashMap())
|
|
176
132
|
}
|
|
177
133
|
|
|
178
|
-
private fun
|
|
179
|
-
|
|
180
|
-
|
|
134
|
+
private fun initListeners() {
|
|
135
|
+
HyperTrack.subscribeToErrors {
|
|
136
|
+
emitEvent(EVENT_ERRORS, serializeErrors(it).toWriteableArray())
|
|
137
|
+
}
|
|
181
138
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
139
|
+
HyperTrack.subscribeToIsAvailable {
|
|
140
|
+
emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(it).toWritableMap())
|
|
141
|
+
}
|
|
185
142
|
|
|
186
|
-
|
|
187
|
-
|
|
143
|
+
HyperTrack.subscribeToIsTracking {
|
|
144
|
+
emitEvent(EVENT_IS_TRACKING, serializeIsTracking(it).toWritableMap())
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
HyperTrack.subscribeToLocation {
|
|
148
|
+
emitEvent(EVENT_LOCATION, serializeLocationResult(it).toWritableMap())
|
|
149
|
+
}
|
|
188
150
|
}
|
|
189
151
|
|
|
190
152
|
private fun emitEvent(event: String, data: WritableMap) {
|
|
@@ -193,6 +155,7 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
193
155
|
.emit(event, data)
|
|
194
156
|
}
|
|
195
157
|
|
|
158
|
+
@Suppress("SameParameterValue")
|
|
196
159
|
private fun emitEvent(event: String, data: WritableArray) {
|
|
197
160
|
reactApplicationContext
|
|
198
161
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
@@ -200,9 +163,11 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
|
|
|
200
163
|
}
|
|
201
164
|
|
|
202
165
|
companion object {
|
|
203
|
-
private const val
|
|
204
|
-
private const val
|
|
205
|
-
private const val
|
|
166
|
+
private const val EVENT_ERRORS = "errors"
|
|
167
|
+
private const val EVENT_IS_AVAILABLE = "isAvailable"
|
|
168
|
+
private const val EVENT_IS_TRACKING = "isTracking"
|
|
169
|
+
private const val EVENT_LOCATE = "locate"
|
|
170
|
+
private const val EVENT_LOCATION = "location"
|
|
206
171
|
|
|
207
172
|
const val NAME = "HyperTrackReactNativePlugin"
|
|
208
173
|
}
|
|
@@ -5,26 +5,33 @@ import com.facebook.react.bridge.Promise
|
|
|
5
5
|
import com.facebook.react.bridge.WritableArray
|
|
6
6
|
import com.facebook.react.bridge.WritableMap
|
|
7
7
|
import com.reactnativehypertracksdk.common.Failure
|
|
8
|
-
import com.reactnativehypertracksdk.common.
|
|
8
|
+
import com.reactnativehypertracksdk.common.WrapperResult
|
|
9
9
|
import com.reactnativehypertracksdk.common.Success
|
|
10
10
|
|
|
11
11
|
@Suppress("UNCHECKED_CAST")
|
|
12
|
-
internal fun <T>
|
|
12
|
+
internal fun <T> WrapperResult<T>.toPromise(promise: Promise) {
|
|
13
13
|
when (this) {
|
|
14
14
|
is Success -> {
|
|
15
15
|
when (this.success) {
|
|
16
16
|
is Map<*, *> -> {
|
|
17
17
|
promise.resolve((this.success as Map<String, Any>).toWritableMap())
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
is List<*> -> {
|
|
21
|
+
promise.resolve((this.success as List<Any>).toWriteableArray())
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
is Unit -> {
|
|
20
25
|
promise.resolve(null)
|
|
21
26
|
}
|
|
27
|
+
|
|
22
28
|
else -> {
|
|
23
29
|
// using nested exception to correctly display error in RN logs
|
|
24
30
|
promise.reject(Exception(IllegalArgumentException(this.success.toString())))
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
|
|
28
35
|
is Failure -> {
|
|
29
36
|
/**
|
|
30
37
|
* ReactNative NativeBridge converts the Exception to JS Error
|
|
@@ -42,7 +49,7 @@ internal fun <T> Result<T>.toPromise(promise: Promise) {
|
|
|
42
49
|
*
|
|
43
50
|
* Default ReactNative logger skips the Exception class name in logs, so we build a
|
|
44
51
|
* custom Exception to include the class name in the message.
|
|
45
|
-
*
|
|
52
|
+
*
|
|
46
53
|
* Default Exception.toString() will print both the class name and the message
|
|
47
54
|
*/
|
|
48
55
|
val exception = Exception(this.failure.toString())
|
|
@@ -60,9 +67,11 @@ internal fun List<Any>.toWriteableArray(): WritableArray {
|
|
|
60
67
|
is String -> {
|
|
61
68
|
writableArray.pushString(it)
|
|
62
69
|
}
|
|
70
|
+
|
|
63
71
|
is Map<*, *> -> {
|
|
64
72
|
writableArray.pushMap((it as Map<String, Any>).toWritableMap())
|
|
65
73
|
}
|
|
74
|
+
|
|
66
75
|
else -> {
|
|
67
76
|
throw Exception(IllegalArgumentException(it.javaClass.toString()))
|
|
68
77
|
}
|
|
@@ -81,24 +90,35 @@ internal fun Map<String, Any?>.toWritableMap(): WritableMap {
|
|
|
81
90
|
is String -> {
|
|
82
91
|
putString(key, value)
|
|
83
92
|
}
|
|
93
|
+
|
|
84
94
|
is Int -> {
|
|
85
95
|
putInt(key, value)
|
|
86
96
|
}
|
|
97
|
+
|
|
87
98
|
is Double -> {
|
|
88
99
|
putDouble(key, value)
|
|
89
100
|
}
|
|
101
|
+
|
|
102
|
+
is Float -> {
|
|
103
|
+
putDouble(key, value.toDouble())
|
|
104
|
+
}
|
|
105
|
+
|
|
90
106
|
is Boolean -> {
|
|
91
107
|
putBoolean(key, value)
|
|
92
108
|
}
|
|
109
|
+
|
|
93
110
|
is List<*> -> {
|
|
94
111
|
putArray(key, (value as List<String>).toWriteableArray())
|
|
95
112
|
}
|
|
113
|
+
|
|
96
114
|
is Map<*, *> -> {
|
|
97
115
|
putMap(key, (value as Map<String, Any>).toWritableMap())
|
|
98
116
|
}
|
|
117
|
+
|
|
99
118
|
null -> {
|
|
100
119
|
putNull(key)
|
|
101
120
|
}
|
|
121
|
+
|
|
102
122
|
else -> {
|
|
103
123
|
throw Exception(IllegalArgumentException(entry.value?.javaClass.toString()))
|
|
104
124
|
}
|