hypertrack-sdk-react-native 8.2.1 → 9.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/CONTRIBUTING.md +32 -110
  3. package/{LICENSE → LICENSE.md} +2 -0
  4. package/README.md +20 -40
  5. package/android/build.gradle +112 -113
  6. package/android/gradle.properties +1 -1
  7. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +209 -0
  8. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackSdkPackage.kt +2 -4
  9. package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +88 -0
  10. package/android/src/main/java/com/reactnativehypertracksdk/common/Geotag.kt +9 -0
  11. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackError.kt +27 -0
  12. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +243 -0
  13. package/android/src/main/java/com/reactnativehypertracksdk/common/LocationError.kt +9 -0
  14. package/android/src/main/java/com/reactnativehypertracksdk/common/Result.kt +48 -0
  15. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkInitParams.kt +46 -0
  16. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +20 -0
  17. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +196 -0
  18. package/hypertrack-sdk-react-native.podspec +2 -2
  19. package/ios/HyperTrackReactNativePlugin.m +54 -0
  20. package/ios/HyperTrackReactNativePlugin.swift +253 -0
  21. package/ios/HyperTrackSdk-Bridging-Header.h +2 -0
  22. package/ios/HyperTrackSdk.xcodeproj/project.pbxproj +8 -11
  23. package/ios/common/DictionaryDecoder.swift +28 -0
  24. package/ios/common/HyperTrackError.swift +20 -0
  25. package/ios/common/HyperTrackSDKWrapper.swift +118 -0
  26. package/ios/common/SDKInitParams.swift +11 -0
  27. package/ios/common/SDKMethod.swift +14 -0
  28. package/ios/common/Serialization.swift +270 -0
  29. package/lib/commonjs/HyperTrack/HyperTrack.js +141 -142
  30. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  31. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js +31 -0
  32. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js.map +1 -0
  33. package/lib/commonjs/HyperTrack/data_types/Location.js +2 -0
  34. package/lib/commonjs/HyperTrack/data_types/Location.js.map +1 -0
  35. package/lib/commonjs/HyperTrack/data_types/LocationError.js +6 -0
  36. package/lib/commonjs/HyperTrack/data_types/LocationError.js.map +1 -0
  37. package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js +2 -0
  38. package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js.map +1 -0
  39. package/lib/commonjs/HyperTrack/data_types/internal/DeviceId.js +2 -0
  40. package/lib/commonjs/HyperTrack/data_types/internal/DeviceId.js.map +1 -0
  41. package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js +2 -0
  42. package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js.map +1 -0
  43. package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js +2 -0
  44. package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js.map +1 -0
  45. package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js +2 -0
  46. package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -0
  47. package/lib/commonjs/HyperTrack/data_types/internal/IsAvailable.js +2 -0
  48. package/lib/commonjs/HyperTrack/data_types/internal/IsAvailable.js.map +1 -0
  49. package/lib/commonjs/HyperTrack/data_types/internal/IsTracking.js +2 -0
  50. package/lib/commonjs/HyperTrack/data_types/internal/IsTracking.js.map +1 -0
  51. package/lib/commonjs/HyperTrack/data_types/internal/LocationErrorInternal.js +6 -0
  52. package/lib/commonjs/HyperTrack/data_types/internal/LocationErrorInternal.js.map +1 -0
  53. package/lib/commonjs/HyperTrack/data_types/internal/LocationResponse.js +6 -0
  54. package/lib/commonjs/HyperTrack/data_types/internal/LocationResponse.js.map +1 -0
  55. package/lib/commonjs/index.js +28 -17
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/module/HyperTrack/HyperTrack.js +140 -134
  58. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  59. package/lib/module/HyperTrack/data_types/HyperTrackError.js +24 -0
  60. package/lib/module/HyperTrack/data_types/HyperTrackError.js.map +1 -0
  61. package/lib/module/HyperTrack/data_types/Location.js +2 -0
  62. package/lib/module/HyperTrack/data_types/Location.js.map +1 -0
  63. package/lib/module/HyperTrack/data_types/LocationError.js +2 -0
  64. package/lib/module/HyperTrack/data_types/LocationError.js.map +1 -0
  65. package/lib/module/HyperTrack/data_types/SdkInitParams.js +2 -0
  66. package/lib/module/HyperTrack/data_types/SdkInitParams.js.map +1 -0
  67. package/lib/module/HyperTrack/data_types/internal/DeviceId.js +2 -0
  68. package/lib/module/HyperTrack/data_types/internal/DeviceId.js.map +1 -0
  69. package/lib/module/HyperTrack/data_types/internal/DeviceName.js +2 -0
  70. package/lib/module/HyperTrack/data_types/internal/DeviceName.js.map +1 -0
  71. package/lib/module/HyperTrack/data_types/internal/Geotag.js +2 -0
  72. package/lib/module/HyperTrack/data_types/internal/Geotag.js.map +1 -0
  73. package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js +2 -0
  74. package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -0
  75. package/lib/module/HyperTrack/data_types/internal/IsAvailable.js +2 -0
  76. package/lib/module/HyperTrack/data_types/internal/IsAvailable.js.map +1 -0
  77. package/lib/module/HyperTrack/data_types/internal/IsTracking.js +2 -0
  78. package/lib/module/HyperTrack/data_types/internal/IsTracking.js.map +1 -0
  79. package/lib/module/HyperTrack/data_types/internal/LocationErrorInternal.js +2 -0
  80. package/lib/module/HyperTrack/data_types/internal/LocationErrorInternal.js.map +1 -0
  81. package/lib/module/HyperTrack/data_types/internal/LocationResponse.js +2 -0
  82. package/lib/module/HyperTrack/data_types/internal/LocationResponse.js.map +1 -0
  83. package/lib/module/index.js +4 -1
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/typescript/HyperTrack/HyperTrack.d.ts +66 -100
  86. package/lib/typescript/HyperTrack/data_types/HyperTrackError.d.ts +20 -0
  87. package/lib/typescript/HyperTrack/data_types/Location.d.ts +7 -0
  88. package/lib/typescript/HyperTrack/data_types/LocationError.d.ts +8 -0
  89. package/lib/typescript/HyperTrack/data_types/SdkInitParams.d.ts +5 -0
  90. package/lib/typescript/HyperTrack/data_types/internal/DeviceId.d.ts +4 -0
  91. package/lib/typescript/HyperTrack/data_types/internal/DeviceName.d.ts +4 -0
  92. package/lib/typescript/HyperTrack/data_types/internal/Geotag.d.ts +3 -0
  93. package/lib/typescript/HyperTrack/data_types/internal/HyperTrackErrorInternal.d.ts +4 -0
  94. package/lib/typescript/HyperTrack/data_types/internal/IsAvailable.d.ts +4 -0
  95. package/lib/typescript/HyperTrack/data_types/internal/IsTracking.d.ts +4 -0
  96. package/lib/typescript/HyperTrack/data_types/internal/LocationErrorInternal.d.ts +12 -0
  97. package/lib/typescript/HyperTrack/data_types/internal/LocationResponse.d.ts +11 -0
  98. package/lib/typescript/index.d.ts +4 -1
  99. package/package.json +156 -156
  100. package/src/HyperTrack/HyperTrack.ts +163 -163
  101. package/src/HyperTrack/data_types/HyperTrackError.ts +22 -0
  102. package/src/HyperTrack/data_types/Location.ts +7 -0
  103. package/src/HyperTrack/data_types/LocationError.ts +11 -0
  104. package/src/HyperTrack/data_types/SdkInitParams.ts +5 -0
  105. package/src/HyperTrack/data_types/internal/DeviceId.ts +4 -0
  106. package/src/HyperTrack/data_types/internal/DeviceName.ts +4 -0
  107. package/src/HyperTrack/data_types/internal/Geotag.ts +3 -0
  108. package/src/HyperTrack/data_types/internal/HyperTrackErrorInternal.ts +4 -0
  109. package/src/HyperTrack/data_types/internal/IsAvailable.ts +4 -0
  110. package/src/HyperTrack/data_types/internal/IsTracking.ts +4 -0
  111. package/src/HyperTrack/data_types/internal/LocationErrorInternal.ts +14 -0
  112. package/src/HyperTrack/data_types/internal/LocationResponse.ts +14 -0
  113. package/src/index.tsx +4 -7
  114. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackModule.kt +0 -284
  115. package/ios/HyperTrack.h +0 -7
  116. package/ios/HyperTrack.m +0 -384
@@ -0,0 +1,20 @@
1
+ package com.reactnativehypertracksdk.common
2
+
3
+ /**
4
+ * The list of available methods in the SDK API.
5
+ * Enum naming convention is ignored to make datatype sync across platforms easier
6
+ */
7
+ internal enum class SdkMethod {
8
+ initialize,
9
+ getDeviceId,
10
+ getLocation,
11
+ startTracking,
12
+ stopTracking,
13
+ setAvailability,
14
+ setName,
15
+ setMetadata,
16
+ isTracking,
17
+ isAvailable,
18
+ addGeotag,
19
+ sync
20
+ }
@@ -0,0 +1,196 @@
1
+ package com.reactnativehypertracksdk.common
2
+
3
+ import android.location.Location
4
+
5
+ /**
6
+ * Platform-independent serialization code that converts HyperTrack data types
7
+ * to Map<String, T> or List<T> where T is any JSON-compatible type
8
+ */
9
+ internal object Serialization {
10
+
11
+ fun serializeErrors(errors: Set<HyperTrackError>): List<Map<String, String>> {
12
+ return errors.map {
13
+ serializeHypertrackError(it)
14
+ }
15
+ }
16
+
17
+ fun serializeSuccess(location: Location): Map<String, Any?> {
18
+ return mapOf(
19
+ KEY_TYPE to TYPE_RESULT_SUCCESS,
20
+ KEY_VALUE to serializeLocation(location)
21
+ )
22
+ }
23
+
24
+ fun serializeFailure(locationError: LocationError): Map<String, Any?> {
25
+ return mapOf(
26
+ KEY_TYPE to TYPE_RESULT_FAILURE,
27
+ KEY_VALUE to serializeLocationError(locationError)
28
+ )
29
+ }
30
+
31
+ fun serializeIsTracking(isTracking: Boolean): Map<String, Any?> {
32
+ return mapOf(
33
+ KEY_TYPE to TYPE_IS_TRACKING,
34
+ KEY_VALUE to isTracking
35
+ )
36
+ }
37
+
38
+ fun serializeIsAvailable(isAvailable: Boolean): Map<String, Any?> {
39
+ return mapOf(
40
+ KEY_TYPE to TYPE_AVAILABILITY,
41
+ KEY_VALUE to isAvailable
42
+ )
43
+ }
44
+
45
+ fun serializeLocation(location: Location): Map<String, Any?> {
46
+ return mapOf(
47
+ KEY_TYPE to TYPE_LOCATION,
48
+ KEY_VALUE to mapOf(
49
+ KEY_LATITUDE to location.latitude,
50
+ KEY_LONGITUDE to location.longitude
51
+ )
52
+ )
53
+ }
54
+
55
+ fun serializeLocationError(locationError: LocationError): Map<String, Any?> {
56
+ return when (locationError) {
57
+ NotRunning -> {
58
+ mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
59
+ }
60
+ Starting -> {
61
+ mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING)
62
+ }
63
+ is Errors -> {
64
+ mapOf(
65
+ KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS,
66
+ KEY_VALUE to locationError.errors.map { serializeHypertrackError(it) }
67
+ )
68
+ }
69
+ }
70
+ }
71
+
72
+ fun serializeHypertrackError(error: HyperTrackError): Map<String, String> {
73
+ return mapOf(
74
+ KEY_TYPE to TYPE_HYPERTRACK_ERROR,
75
+ KEY_VALUE to error.name
76
+ )
77
+ }
78
+
79
+ fun serializeDeviceId(deviceId: String): Map<String, Any?> {
80
+ return mapOf(
81
+ KEY_TYPE to TYPE_DEVICE_ID,
82
+ KEY_VALUE to deviceId
83
+ )
84
+ }
85
+
86
+ fun deserializeDeviceName(name: Map<String, Any?>): Result<String> {
87
+ return parse(name) {
88
+ it.assertValue<String>(key = KEY_TYPE, value = TYPE_DEVICE_NAME)
89
+ it.get<String>(KEY_VALUE).getOrThrow()
90
+ }
91
+ }
92
+
93
+ fun deserializeAvailability(isAvailable: Map<String, Any?>): Result<Boolean> {
94
+ return parse(isAvailable) {
95
+ it.assertValue<String>(key = KEY_TYPE, value = TYPE_AVAILABILITY)
96
+ it.get<Boolean>(KEY_VALUE).getOrThrow()
97
+ }
98
+ }
99
+
100
+ fun deserializeGeotagData(map: Map<String, Any?>): Result<Geotag> {
101
+ return parse(map) {
102
+ val data = it.get<Map<String, Any?>>(KEY_GEOTAG_DATA).getOrThrow()
103
+ Geotag(data)
104
+ }
105
+ }
106
+
107
+ fun <T> parse(
108
+ source: Map<String, Any?>,
109
+ parseFunction: (ParsingHandle) -> T
110
+ ): Result<T> {
111
+ val handle = ParsingHandle(source);
112
+ return try {
113
+ if (handle.exceptions.isEmpty()) {
114
+ Success(parseFunction.invoke(handle))
115
+ } else {
116
+ Failure(ParsingExceptions(source, handle.exceptions))
117
+ }
118
+ } catch (e: Exception) {
119
+ Failure(
120
+ if (handle.exceptions.isNotEmpty()) {
121
+ ParsingExceptions(source, handle.exceptions + e)
122
+ } else {
123
+ e
124
+ }
125
+ )
126
+ }
127
+ }
128
+
129
+ internal class ParsingHandle(
130
+ private val source: Map<String, Any?>,
131
+ ) {
132
+ private val _exceptions = mutableListOf<Exception>()
133
+ val exceptions: List<Exception> = _exceptions
134
+
135
+ inline fun <reified T> get(
136
+ key: String
137
+ ): Result<T> {
138
+ return try {
139
+ Success(source[key]!! as T)
140
+ } catch (e: Exception) {
141
+ Failure(
142
+ ParsingException(key, e)
143
+ .also {
144
+ _exceptions.add(it)
145
+ }
146
+ )
147
+ }
148
+ }
149
+
150
+ inline fun <reified T> assertValue(
151
+ key: String,
152
+ value: Any
153
+ ) {
154
+ if (source[key] != value) {
155
+ _exceptions.add(Exception("Assertion failed: $key != $value"))
156
+ }
157
+ }
158
+ }
159
+
160
+ internal data class ParsingExceptions(
161
+ val source: Any,
162
+ val exceptions: List<Exception>
163
+ ) : Throwable(exceptions.joinToString("\n").let {
164
+ "Invalid input:\n\n${source}\n\n${it}"
165
+ })
166
+
167
+ internal class ParsingException(
168
+ key: String,
169
+ exception: Exception
170
+ ) : Exception("Invalid value for '$key': $exception", exception)
171
+
172
+ private const val KEY_TYPE = "type"
173
+ private const val KEY_VALUE = "value"
174
+
175
+ private const val TYPE_RESULT_SUCCESS = "success"
176
+ private const val TYPE_RESULT_FAILURE = "failure"
177
+
178
+ private const val TYPE_LOCATION = "location"
179
+ private const val TYPE_AVAILABILITY = "isAvailable"
180
+ private const val TYPE_DEVICE_NAME = "deviceName"
181
+ private const val TYPE_DEVICE_ID = "deviceID"
182
+ private const val TYPE_HYPERTRACK_ERROR = "hyperTrackError"
183
+ private const val TYPE_IS_TRACKING = "isTracking"
184
+
185
+ private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning"
186
+ private const val TYPE_LOCATION_ERROR_STARTING = "starting"
187
+ private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
188
+
189
+ private const val KEY_LATITUDE = "latitude"
190
+ private const val KEY_LONGITUDE = "longitude"
191
+
192
+ const val KEY_GEOTAG_DATA = "data"
193
+
194
+ }
195
+
196
+
@@ -12,13 +12,13 @@ Pod::Spec.new do |s|
12
12
  s.license = package["license"]
13
13
  s.authors = package["author"]
14
14
 
15
- s.platforms = { :ios => "10.0" }
15
+ s.platforms = { :ios => "11.0" }
16
16
  s.source = { :git => "https://github.com/hypertrack/sdk-react-native.git", :tag => "#{s.version}" }
17
17
 
18
18
  s.source_files = "ios/**/*.{h,m,mm,swift}"
19
19
 
20
20
  s.dependency "React-Core"
21
- s.dependency 'HyperTrack/Objective-C', '4.13.0'
21
+ s.dependency 'HyperTrack/Objective-C', '4.14.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
@@ -0,0 +1,54 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
3
+
4
+ @interface RCT_EXTERN_MODULE(HyperTrackReactNativePlugin, RCTEventEmitter)
5
+
6
+ RCT_EXTERN_METHOD(supportedEvents)
7
+
8
+ RCT_EXTERN_METHOD(addListener)
9
+
10
+ RCT_EXTERN_METHOD(requiresMainQueueSetup)
11
+
12
+ RCT_EXTERN_METHOD(initializeSdk:(NSDictionary *)args
13
+ resolver:(RCTPromiseResolveBlock)resolve
14
+ rejecter:(RCTPromiseRejectBlock)reject)
15
+
16
+ RCT_EXTERN_METHOD(getDeviceId:(RCTPromiseResolveBlock)resolve
17
+ rejecter:(RCTPromiseRejectBlock)reject)
18
+
19
+ RCT_EXTERN_METHOD(getLocation:(RCTPromiseResolveBlock)resolve
20
+ rejecter:(RCTPromiseRejectBlock)reject)
21
+
22
+ RCT_EXTERN_METHOD(startTracking:(RCTPromiseResolveBlock)resolve
23
+ rejecter:(RCTPromiseRejectBlock)reject)
24
+
25
+ RCT_EXTERN_METHOD(stopTracking:(RCTPromiseResolveBlock)resolve
26
+ rejecter:(RCTPromiseRejectBlock)reject)
27
+
28
+ RCT_EXTERN_METHOD(isTracking:(RCTPromiseResolveBlock)resolve
29
+ rejecter:(RCTPromiseRejectBlock)reject)
30
+
31
+ RCT_EXTERN_METHOD(isAvailable:(RCTPromiseResolveBlock)resolve
32
+ rejecter:(RCTPromiseRejectBlock)reject)
33
+
34
+ RCT_EXTERN_METHOD(sync:(RCTPromiseResolveBlock)resolve
35
+ rejecter:(RCTPromiseRejectBlock)reject)
36
+
37
+ RCT_EXTERN_METHOD(setAvailability:(NSDictionary *)args
38
+ resolver:(RCTPromiseResolveBlock)resolve
39
+ rejecter:(RCTPromiseRejectBlock)reject)
40
+
41
+ RCT_EXTERN_METHOD(setName:(NSDictionary *)args
42
+ resolver:(RCTPromiseResolveBlock)resolve
43
+ rejecter:(RCTPromiseRejectBlock)reject)
44
+
45
+ RCT_EXTERN_METHOD(setMetadata:(NSDictionary *)args
46
+ resolver:(RCTPromiseResolveBlock)resolve
47
+ rejecter:(RCTPromiseRejectBlock)reject)
48
+
49
+ RCT_EXTERN_METHOD(addGeotag:(NSDictionary *)args
50
+ resolver:(RCTPromiseResolveBlock)resolve
51
+ rejecter:(RCTPromiseRejectBlock)reject)
52
+
53
+
54
+ @end
@@ -0,0 +1,253 @@
1
+ import HyperTrack
2
+
3
+ @objc(HyperTrackReactNativePlugin)
4
+ class HyperTrackReactNativePlugin: RCTEventEmitter {
5
+
6
+ private let eventTracking = "onTrackingChanged"
7
+ private let eventAvailability = "onAvailabilityChanged"
8
+ private let eventErrors = "onError"
9
+
10
+ private var isTrackingSubscription: HyperTrack.Cancellable!
11
+ private var availabilitySubscription: HyperTrack.Cancellable!
12
+ private var errorsSubscription: HyperTrack.Cancellable!
13
+
14
+ @objc override static func requiresMainQueueSetup() -> Bool {
15
+ return false
16
+ }
17
+
18
+ @objc override func supportedEvents() -> [String] {
19
+ return [
20
+ eventTracking,
21
+ eventAvailability,
22
+ eventErrors
23
+ ]
24
+ }
25
+
26
+ @objc override func addListener(_ eventName: String) {
27
+ super.addListener(eventName)
28
+ switch(eventName) {
29
+ case eventTracking:
30
+ sendEvent(withName: eventTracking, body: serializeIsTracking(sdkInstance.isTracking))
31
+ case eventAvailability:
32
+ sendEvent(withName: eventAvailability, body: serializeIsAvailable(sdkInstance.availability))
33
+ case eventErrors:
34
+ sendEvent(withName: eventErrors, body: serializeErrors(sdkInstance.errors))
35
+ default:
36
+ return
37
+ }
38
+ }
39
+
40
+ /// Method name is changed from 'initialize' because RCTEventEmitter has a method with the same name
41
+ @objc func initializeSdk(
42
+ _ args: NSDictionary,
43
+ resolver resolve: RCTPromiseResolveBlock,
44
+ rejecter reject: RCTPromiseRejectBlock
45
+ ) {
46
+ sendAsPromise(
47
+ hypertrack_sdk_react_native.initializeSDK(
48
+ args as! Dictionary<String, Any>
49
+ ).map({ (result:SuccessResult) in
50
+ initListeners()
51
+ return result
52
+ }),
53
+ method: .initialize,
54
+ resolve,
55
+ reject
56
+ )
57
+
58
+ }
59
+
60
+ @objc func getDeviceId(
61
+ _ resolve: RCTPromiseResolveBlock,
62
+ rejecter reject: RCTPromiseRejectBlock
63
+ ) {
64
+ sendAsPromise(
65
+ hypertrack_sdk_react_native.getDeviceID(),
66
+ method: .getDeviceId,
67
+ resolve,
68
+ reject
69
+ )
70
+ }
71
+
72
+ @objc func setName(
73
+ _ args: NSDictionary,
74
+ resolver resolve: RCTPromiseResolveBlock,
75
+ rejecter reject: RCTPromiseRejectBlock
76
+ ) {
77
+ sendAsPromise(
78
+ hypertrack_sdk_react_native.setName(args as! Dictionary<String, Any>),
79
+ method: .setName,
80
+ resolve,
81
+ reject
82
+ )
83
+ }
84
+
85
+ @objc func setMetadata(
86
+ _ args: NSDictionary,
87
+ resolver resolve: RCTPromiseResolveBlock,
88
+ rejecter reject: RCTPromiseRejectBlock
89
+ ) {
90
+ sendAsPromise(
91
+ hypertrack_sdk_react_native.setMetadata(
92
+ args as! Dictionary<String, Any>
93
+ ),
94
+ method: .setMetadata,
95
+ resolve,
96
+ reject
97
+ )
98
+ }
99
+
100
+ @objc func getLocation(
101
+ _ resolve: RCTPromiseResolveBlock,
102
+ rejecter reject: RCTPromiseRejectBlock
103
+ ) {
104
+ sendAsPromise(
105
+ hypertrack_sdk_react_native.getLocation(),
106
+ method: .getLocation,
107
+ resolve,
108
+ reject
109
+ )
110
+ }
111
+
112
+ @objc func startTracking(
113
+ _ resolve: RCTPromiseResolveBlock,
114
+ rejecter reject: RCTPromiseRejectBlock
115
+ ) {
116
+ sendAsPromise(
117
+ hypertrack_sdk_react_native.startTracking(),
118
+ method: .startTracking,
119
+ resolve,
120
+ reject
121
+ )
122
+ }
123
+
124
+ @objc func stopTracking(
125
+ _ resolve: RCTPromiseResolveBlock,
126
+ rejecter reject: RCTPromiseRejectBlock
127
+ ) {
128
+ sendAsPromise(
129
+ hypertrack_sdk_react_native.stopTracking(),
130
+ method: .stopTracking,
131
+ resolve,
132
+ reject
133
+ )
134
+ }
135
+
136
+ @objc func setAvailability(
137
+ _ args: NSDictionary,
138
+ resolver resolve: RCTPromiseResolveBlock,
139
+ rejecter reject: RCTPromiseRejectBlock
140
+ ) {
141
+ sendAsPromise(
142
+ hypertrack_sdk_react_native.setAvailability(
143
+ args as! Dictionary<String, Any>
144
+ ),
145
+ method: .setAvailability,
146
+ resolve,
147
+ reject
148
+ )
149
+ }
150
+
151
+ @objc func isTracking(
152
+ _ resolve: RCTPromiseResolveBlock,
153
+ rejecter reject: RCTPromiseRejectBlock
154
+ ) {
155
+ sendAsPromise(
156
+ hypertrack_sdk_react_native.isTracking(),
157
+ method: .isTracking,
158
+ resolve,
159
+ reject
160
+ )
161
+ }
162
+
163
+ @objc func isAvailable(
164
+ _ resolve: RCTPromiseResolveBlock,
165
+ rejecter reject: RCTPromiseRejectBlock
166
+ ) {
167
+ sendAsPromise(
168
+ hypertrack_sdk_react_native.isAvailable(),
169
+ method: .isAvailable,
170
+ resolve,
171
+ reject
172
+ )
173
+ }
174
+
175
+ @objc func addGeotag(
176
+ _ args: NSDictionary,
177
+ resolver resolve: RCTPromiseResolveBlock,
178
+ rejecter reject: RCTPromiseRejectBlock
179
+ ) {
180
+ sendAsPromise(
181
+ hypertrack_sdk_react_native.addGeotag(
182
+ args as! Dictionary<String, Any>
183
+ ),
184
+ method: .addGeotag,
185
+ resolve,
186
+ reject
187
+ )
188
+ }
189
+
190
+ @objc func sync(
191
+ _ resolve: RCTPromiseResolveBlock,
192
+ rejecter reject: RCTPromiseRejectBlock
193
+ ) {
194
+ sendAsPromise(
195
+ hypertrack_sdk_react_native.sync(),
196
+ method: .sync,
197
+ resolve,
198
+ reject
199
+ )
200
+ }
201
+
202
+ private func initListeners() {
203
+ isTrackingSubscription = sdkInstance.subscribeToIsTracking(callback: { isTracking in
204
+ self.sendTrackingEvent(isTracking: isTracking)
205
+ })
206
+ availabilitySubscription = sdkInstance.subscribeToAvailability(callback: { availability in
207
+ self.sendAvailabilityEvent(availability: availability)
208
+ })
209
+ errorsSubscription = sdkInstance.subscribeToErrors { errors in
210
+ self.sendErrorsEvent(errors)
211
+ }
212
+ }
213
+
214
+ private func sendTrackingEvent(isTracking: Bool) {
215
+ sendEvent(withName: eventTracking, body: serializeIsTracking(isTracking))
216
+ }
217
+ private func sendAvailabilityEvent(availability: HyperTrack.Availability) {
218
+ sendEvent(withName: eventAvailability, body: serializeIsAvailable(availability))
219
+ }
220
+
221
+ private func sendErrorsEvent(_ errors: Set<HyperTrack.HyperTrackError>) {
222
+ sendEvent(withName: eventErrors, body: serializeErrors(errors))
223
+ }
224
+
225
+ }
226
+
227
+ private func sendAsPromise(
228
+ _ result: Result<SuccessResult, FailureResult>,
229
+ method: SDKMethod,
230
+ _ resolve: RCTPromiseResolveBlock,
231
+ _ reject: RCTPromiseRejectBlock
232
+ ) {
233
+ switch result {
234
+ case .success(let success):
235
+ switch (success) {
236
+ case .void:
237
+ resolve(nil)
238
+ case .dict(let value):
239
+ resolve(value)
240
+ }
241
+ case .failure(let failure):
242
+ switch(failure) {
243
+ case .error(let message):
244
+ reject(
245
+ "method_call_error",
246
+ "\(method.rawValue): \(message)",
247
+ NSError.init(domain: "com.hypertrack.sdk.reactnative.ios", code: 0, userInfo: nil)
248
+ )
249
+ case .fatalError(let message):
250
+ preconditionFailure(message)
251
+ }
252
+ }
253
+ }
@@ -0,0 +1,2 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
@@ -6,10 +6,6 @@
6
6
  objectVersion = 46;
7
7
  objects = {
8
8
 
9
- /* Begin PBXBuildFile section */
10
- 12CFB2D62872FAE100FEE5E6 /* HyperTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 12CFB2D52872FAE100FEE5E6 /* HyperTrack.m */; };
11
- /* End PBXBuildFile section */
12
-
13
9
  /* Begin PBXCopyFilesBuildPhase section */
14
10
  58B511D91A9E6C8500147676 /* CopyFiles */ = {
15
11
  isa = PBXCopyFilesBuildPhase;
@@ -23,10 +19,11 @@
23
19
  /* End PBXCopyFilesBuildPhase section */
24
20
 
25
21
  /* Begin PBXFileReference section */
26
- 12CFB2D52872FAE100FEE5E6 /* HyperTrack.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HyperTrack.m; sourceTree = "<group>"; };
27
- 12CFB2D72872FAFE00FEE5E6 /* HyperTrack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HyperTrack.h; sourceTree = "<group>"; };
22
+ 0AAF11002923F18800A50DA1 /* HyperTrackReactNativePlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HyperTrackReactNativePlugin.m; sourceTree = "<group>"; };
23
+ 0AAF11012923F18800A50DA1 /* common */ = {isa = PBXFileReference; lastKnownFileType = folder; path = common; sourceTree = "<group>"; };
24
+ 0AAF11022923F18800A50DA1 /* HyperTrackReactNativePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperTrackReactNativePlugin.swift; sourceTree = "<group>"; };
25
+ 0AAF11062923FED200A50DA1 /* HyperTrackSdk-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HyperTrackSdk-Bridging-Header.h"; sourceTree = "<group>"; };
28
26
  134814201AA4EA6300B7C361 /* libHyperTrackSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libHyperTrackSdk.a; sourceTree = BUILT_PRODUCTS_DIR; };
29
- F4FF95D5245B92E700C19C63 /* HyperTrackSdk-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HyperTrackSdk-Bridging-Header.h"; sourceTree = "<group>"; };
30
27
  /* End PBXFileReference section */
31
28
 
32
29
  /* Begin PBXFrameworksBuildPhase section */
@@ -51,9 +48,10 @@
51
48
  58B511D21A9E6C8500147676 = {
52
49
  isa = PBXGroup;
53
50
  children = (
54
- 12CFB2D52872FAE100FEE5E6 /* HyperTrack.m */,
55
- 12CFB2D72872FAFE00FEE5E6 /* HyperTrack.h */,
56
- F4FF95D5245B92E700C19C63 /* HyperTrackSdk-Bridging-Header.h */,
51
+ 0AAF11062923FED200A50DA1 /* HyperTrackSdk-Bridging-Header.h */,
52
+ 0AAF11012923F18800A50DA1 /* common */,
53
+ 0AAF11002923F18800A50DA1 /* HyperTrackReactNativePlugin.m */,
54
+ 0AAF11022923F18800A50DA1 /* HyperTrackReactNativePlugin.swift */,
57
55
  134814211AA4EA7D00B7C361 /* Products */,
58
56
  );
59
57
  sourceTree = "<group>";
@@ -115,7 +113,6 @@
115
113
  isa = PBXSourcesBuildPhase;
116
114
  buildActionMask = 2147483647;
117
115
  files = (
118
- 12CFB2D62872FAE100FEE5E6 /* HyperTrack.m in Sources */,
119
116
  );
120
117
  runOnlyForDeploymentPostprocessing = 0;
121
118
  };
@@ -0,0 +1,28 @@
1
+ class DictionaryDecoder {
2
+ private let decoder = JSONDecoder()
3
+
4
+ var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy {
5
+ set { decoder.dateDecodingStrategy = newValue }
6
+ get { decoder.dateDecodingStrategy }
7
+ }
8
+
9
+ var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy {
10
+ set { decoder.dataDecodingStrategy = newValue }
11
+ get { decoder.dataDecodingStrategy }
12
+ }
13
+
14
+ var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy {
15
+ set { decoder.nonConformingFloatDecodingStrategy = newValue }
16
+ get { decoder.nonConformingFloatDecodingStrategy }
17
+ }
18
+
19
+ var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy {
20
+ set { decoder.keyDecodingStrategy = newValue }
21
+ get { decoder.keyDecodingStrategy }
22
+ }
23
+
24
+ func decode<T>(_ type: T.Type, from dictionary: [String: Any]) throws -> T where T: Decodable {
25
+ let data = try JSONSerialization.data(withJSONObject: dictionary, options: [])
26
+ return try decoder.decode(type, from: data)
27
+ }
28
+ }
@@ -0,0 +1,20 @@
1
+ enum HyperTrackError: String {
2
+ case gpsSignalLost
3
+ case locationMocked
4
+ case locationPermissionsDenied
5
+ case locationPermissionsInsufficientForBackground
6
+ case locationPermissionsNotDetermined
7
+ case locationPermissionsReducedAccuracy
8
+ case locationPermissionsProvisional
9
+ case locationPermissionsRestricted
10
+ case locationServicesDisabled
11
+ case locationServicesUnavailable
12
+ case motionActivityPermissionsNotDetermined
13
+ case motionActivityPermissionsDenied
14
+ case motionActivityServicesDisabled
15
+ case motionActivityServicesUnavailable
16
+ case motionActivityPermissionsRestricted
17
+ case networkConnectionUnavailable
18
+ case invalidPublishableKey
19
+ case blockedFromRunning
20
+ }