From e3f63c6b74de99b1ef9cf4f91e74077980a71968 Mon Sep 17 00:00:00 2001 From: pavel-kuznetsov-hypertrack <78730314+pavel-kuznetsov-hypertrack@users.noreply.github.com> Date: Fri, 27 Oct 2023 16:48:20 +0300 Subject: [PATCH] Use SDK v5/7 (#15) Implement static API --- CHANGELOG.md | 56 ++ HypertrackSdkIonicCapacitor.podspec | 2 +- README.md | 5 +- android/build.gradle | 8 +- .../sdk/capacitor/CapacitorSerialization.kt | 15 +- .../capacitor/HyperTrackCapacitorPlugin.kt | 266 ++++++---- .../hypertrack/sdk/capacitor/common/Geotag.kt | 9 - .../sdk/capacitor/common/GeotagData.kt | 13 + .../sdk/capacitor/common/HyperTrackError.kt | 28 - .../capacitor/common/HyperTrackSdkWrapper.kt | 293 ++++------- .../sdk/capacitor/common/LocationError.kt | 9 - .../sdk/capacitor/common/SdkInitParams.kt | 44 -- .../sdk/capacitor/common/SdkMethod.kt | 20 +- .../sdk/capacitor/common/Serialization.kt | 285 +++++++--- .../common/{Result.kt => WrapperResult.kt} | 16 +- docs/assets/highlight.css | 49 ++ docs/assets/search.js | 2 +- docs/classes/HyperTrack.html | 368 ++++++++----- docs/enums/HyperTrackError.html | 176 ++++--- docs/index.html | 28 +- docs/interfaces/Subscription.html | 14 +- docs/types/Errors.html | 15 +- docs/types/Failure.html | 67 +++ docs/types/Location.html | 24 +- docs/types/LocationError.html | 15 +- ...Params.html => LocationWithDeviation.html} | 27 +- docs/types/NotRunning.html | 15 +- docs/types/Result.html | 62 +++ docs/types/Starting.html | 15 +- docs/types/Success.html | 67 +++ ios/Plugin/HyperTrackCapacitorPlugin.m | 22 +- ios/Plugin/HyperTrackCapacitorPlugin.swift | 243 +++++---- ios/Plugin/common/DictionaryDecoder.swift | 10 +- ios/Plugin/common/GeotagData.swift | 11 + ios/Plugin/common/HyperTrackError.swift | 20 - ios/Plugin/common/HyperTrackSDKWrapper.swift | 124 ++--- ios/Plugin/common/SDKInitParams.swift | 11 - ios/Plugin/common/SDKMethod.swift | 25 +- ios/Plugin/common/Serialization.swift | 430 ++++++++------- package.json | 2 +- src/HyperTrack.ts | 492 +++++++++++++----- src/HyperTrackCapacitorPlugin.ts | 74 +++ src/Subscription.ts | 4 + src/data_types/HyperTrackError.ts | 91 +++- src/data_types/Location.ts | 7 +- src/data_types/LocationError.ts | 2 - src/data_types/LocationWithDeviation.ts | 6 + src/data_types/Result.ts | 11 + src/data_types/SdkInitParams.ts | 5 - src/data_types/internal/DeviceName.ts | 4 - src/data_types/internal/Geotag.ts | 3 - src/data_types/internal/GeotagData.ts | 6 + .../internal/HyperTrackErrorInternal.ts | 6 +- src/data_types/internal/LocationInternal.ts | 7 + src/data_types/internal/LocationResponse.ts | 14 - .../internal/LocationWithDeviationInternal.ts | 9 + src/data_types/internal/Metadata.ts | 4 + src/data_types/internal/Name.ts | 7 + src/definitions.ts | 34 -- src/index.ts | 13 +- 60 files changed, 2273 insertions(+), 1437 deletions(-) delete mode 100644 android/src/main/java/com/hypertrack/sdk/capacitor/common/Geotag.kt create mode 100644 android/src/main/java/com/hypertrack/sdk/capacitor/common/GeotagData.kt delete mode 100644 android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackError.kt delete mode 100644 android/src/main/java/com/hypertrack/sdk/capacitor/common/LocationError.kt delete mode 100644 android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkInitParams.kt rename android/src/main/java/com/hypertrack/sdk/capacitor/common/{Result.kt => WrapperResult.kt} (80%) create mode 100644 docs/types/Failure.html rename docs/types/{SdkInitParams.html => LocationWithDeviation.html} (79%) create mode 100644 docs/types/Result.html create mode 100644 docs/types/Success.html create mode 100644 ios/Plugin/common/GeotagData.swift delete mode 100644 ios/Plugin/common/HyperTrackError.swift delete mode 100644 ios/Plugin/common/SDKInitParams.swift create mode 100644 src/HyperTrackCapacitorPlugin.ts create mode 100644 src/Subscription.ts create mode 100644 src/data_types/LocationWithDeviation.ts create mode 100644 src/data_types/Result.ts delete mode 100644 src/data_types/SdkInitParams.ts delete mode 100644 src/data_types/internal/DeviceName.ts delete mode 100644 src/data_types/internal/Geotag.ts create mode 100644 src/data_types/internal/GeotagData.ts create mode 100644 src/data_types/internal/LocationInternal.ts delete mode 100644 src/data_types/internal/LocationResponse.ts create mode 100644 src/data_types/internal/LocationWithDeviationInternal.ts create mode 100644 src/data_types/internal/Metadata.ts create mode 100644 src/data_types/internal/Name.ts delete mode 100644 src/definitions.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b809940..657c8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,57 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.0] - 2023-10-27 + +We are excited to announce the release of HyperTrack Ionic Capacitor SDK 2.0.0, a major update to our location tracking SDK. This release ensures highest tracking performance, reduces deployed app sizes and comes with an improved API to simplify the integrations. We highly recommend upgrading, but please note that there are a few breaking changes. + +### Changed + +- Updated HyperTrack Android SDK to [7.0.6](https://github.com/hypertrack/sdk-android/releases/tag/7.0.1) +- Added Android SDK plugins (`location-services-google` and `push-service-firebase`) +- Updated HyperTrack iOS SDK to [5.0.4](https://github.com/hypertrack/sdk-ios/releases/tag/5.0.4) +- The whole HyperTrack API is now static +- Changed the way to provide publishableKey (you need to add `HyperTrackPublishableKey` `meta-data` item to your `AndroidManifest.xml`) +- Renamed HyperTrackError types: + - `gpsSignalLost` to `locationSignalLost` + - `locationPermissionsDenied` to `permissionsLocationDenied` + - `locationPermissionsInsufficientForBackground` to `permissionsLocationInsufficientForBackground` + - `locationPermissionsNotDetermined` to `permissionsLocationNotDetermined` + - `locationPermissionsProvisional` to `locationPermissionsProvisional` + - `locationPermissionsReducedAccuracy` to `permissionsLocationReducedAccuracy` + - `locationPermissionsRestricted` to `permissionsLocationRestricted` +- Renamed `isAvailable()` to `getIsAvailable()` +- Renamed `isTracking()` to `getIsTracking()` +- Renamed `setAvailability()` to `setIsAvailable(boolean)` +- Changed `startTracking()` and `stopTracking()` to `setIsTracking(boolean)` +- Renamed `subscribeToTracking()` to `subscribeToIsTracking()` +- Renamed `subscribeToAvailability()` to `subscribeToIsAvailable()` +- Changed `getLocation()` response to `Result` + +### Added + +- `locate()` to ask for one-time user location +- `subscribeToLocation()` to subscribe to user location updates +- `getErrors()` +- `getName()` +- `getMetadata()` +- HyperTrackError types: + - `noExemptionFromBackgroundStartRestrictions` + - `permissionsNotificationsDenied` + +### Removed + +- `initialize()` method (the API is now static) +- `SdkInitParams` (the config now should be done with the `AndroidManifest` metadata and `Info.plist`) +- Motion Activity permissions are not required for tracking anymore +- HyperTrackError types: + - `motionActivityPermissionsDenied` + - `motionActivityServicesDisabled` + - `motionActivityServicesUnavailable` + - `motionActivityPermissionsRestricted` + - `networkConnectionUnavailable` +- `sync()` method + ## [1.0.3] - 2023-06-16 ### Changed @@ -12,18 +63,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.0.2] - 2023-06-15 ### Changed + - HyperTrack SDK Android updated to 6.4.2 ## [1.0.1] - 2023-06-01 ### Changed + - HyperTrack SDK iOS updated to 4.16.0 ## [1.0.0] - 2023-02-10 ### Added + - Initial release +[2.0.0] https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/2.0.0 +[1.0.3] https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/1.0.3 [1.0.2] https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/1.0.2 [1.0.1] https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/1.0.1 [1.0.0] https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/1.0.0 diff --git a/HypertrackSdkIonicCapacitor.podspec b/HypertrackSdkIonicCapacitor.podspec index 0a433e2..e8d39d2 100644 --- a/HypertrackSdkIonicCapacitor.podspec +++ b/HypertrackSdkIonicCapacitor.podspec @@ -14,5 +14,5 @@ Pod::Spec.new do |s| s.ios.deployment_target = '12.0' s.dependency 'Capacitor' s.swift_version = '5.1' - s.dependency 'HyperTrack','4.16.1' + s.dependency 'HyperTrack','5.0.4' end diff --git a/README.md b/README.md index 5e92794..f863938 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![GitHub](https://img.shields.io/github/license/hypertrack/sdk-ionic-capacitor.svg?color=orange)](./LICENSE) [![npm](https://img.shields.io/npm/v/hypertrack-sdk-ionic-capacitor.svg)](https://www.npmjs.com/package/hypertrack-sdk-ionic-capacitor) -[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-4.16.1-brightgreen.svg)](https://github.com/hypertrack/sdk-ios) -[![Android SDK](https://img.shields.io/badge/Android%20SDK-6.4.2-brightgreen.svg)](https://github.com/hypertrack/sdk-android) +[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.0.4-brightgreen.svg)](https://github.com/hypertrack/sdk-ios) +[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.0.6-brightgreen.svg)](https://github.com/hypertrack/sdk-android) [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. @@ -16,6 +16,7 @@ For information about how to get started with Ionic Capacitor HyperTrack SDK, pl `npm install hypertrack-sdk-ionic-capacitor` ### Android + In order to use this plugin, please add HyperTrack repository in `android/build.gradle`: ``` diff --git a/android/build.gradle b/android/build.gradle index 6ef15c5..0388998 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,7 @@ ext { buildscript { ext.kotlin_version = "1.7.21" - ext.hypertrack_sdk_version = "6.4.2" + ext.hypertrack_sdk_version = "7.0.6" ext.firebase_messaging_version = "23.1.1" repositories { @@ -64,6 +64,10 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':capacitor-android') implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" - implementation "com.hypertrack:hypertrack:$hypertrack_sdk_version" + + implementation "com.hypertrack:sdk-android:$hypertrack_sdk_version" + implementation "com.hypertrack:location-services-google:$hypertrack_sdk_version" + implementation "com.hypertrack:push-service-firebase:$hypertrack_sdk_version" + implementation "com.google.firebase:firebase-messaging:$firebase_messaging_version" } diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/CapacitorSerialization.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/CapacitorSerialization.kt index c91a075..b5f17c6 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/CapacitorSerialization.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/CapacitorSerialization.kt @@ -4,13 +4,22 @@ import com.getcapacitor.JSArray import com.getcapacitor.JSObject import com.getcapacitor.PluginCall import com.hypertrack.sdk.capacitor.common.Failure -import com.hypertrack.sdk.capacitor.common.Result +import com.hypertrack.sdk.capacitor.common.Serialized +import com.hypertrack.sdk.capacitor.common.WrapperResult import com.hypertrack.sdk.capacitor.common.Success import org.json.JSONArray import org.json.JSONObject +private const val KEY_ERRORS = "errors" + +fun serializeErrorsForCapacitor(errors: List): Serialized { + return mapOf( + KEY_ERRORS to errors + ) +} + @Suppress("UNCHECKED_CAST") -internal fun Result.toPluginCall(call: PluginCall) { +internal fun WrapperResult.toPluginCall(call: PluginCall) { when (this) { is Success -> { when (this.success) { @@ -65,7 +74,7 @@ internal fun Map.toJSObject(): JSObject { is Boolean -> { put(key, value) } - is Double -> { + is Double, is Float -> { put(key, value) } is Int -> { diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/HyperTrackCapacitorPlugin.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/HyperTrackCapacitorPlugin.kt index 0abfa0a..a47859b 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/HyperTrackCapacitorPlugin.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/HyperTrackCapacitorPlugin.kt @@ -7,138 +7,216 @@ import com.getcapacitor.PluginCall import com.getcapacitor.PluginMethod import com.getcapacitor.annotation.CapacitorPlugin import com.hypertrack.sdk.* +import com.hypertrack.sdk.android.HyperTrack +import com.hypertrack.sdk.android.Result import com.hypertrack.sdk.capacitor.common.* -import com.hypertrack.sdk.capacitor.common.Result +import com.hypertrack.sdk.capacitor.common.Serialization.serializeErrors +import com.hypertrack.sdk.capacitor.common.WrapperResult @CapacitorPlugin(name = "HyperTrackCapacitorPlugin") -public class HyperTrackCapacitorPlugin : Plugin() { +class HyperTrackCapacitorPlugin : Plugin() { + + private var locateSubscription: HyperTrack.Cancellable? = null + + init { + initListeners() + } @PluginMethod - public fun initialize(call: PluginCall) { - invokeSdkMethod(SdkMethod.initialize, call).toPluginCall(call) + fun addGeotag(call: PluginCall) { + invokeSdkMethod(SdkMethod.addGeotag, call).toPluginCall(call) } @PluginMethod - public fun getDeviceId(call: PluginCall) { + fun getDeviceId(call: PluginCall) { invokeSdkMethod(SdkMethod.getDeviceID, call).toPluginCall(call) } @PluginMethod - public fun getLocation(call: PluginCall) { + fun getErrors(call: PluginCall) { + invokeSdkMethod(SdkMethod.getErrors, call).toPluginCall(call) + } + + @PluginMethod + fun getIsAvailable(call: PluginCall) { + invokeSdkMethod(SdkMethod.getIsAvailable, call).toPluginCall(call) + } + + @PluginMethod + fun getIsTracking(call: PluginCall) { + invokeSdkMethod(SdkMethod.getIsTracking, call).toPluginCall(call) + } + + @PluginMethod + fun getLocation(call: PluginCall) { invokeSdkMethod(SdkMethod.getLocation, call).toPluginCall(call) } @PluginMethod - public fun startTracking(call: PluginCall) { - invokeSdkMethod(SdkMethod.startTracking, call).toPluginCall(call) + fun getMetadata(call: PluginCall) { + invokeSdkMethod(SdkMethod.getMetadata, call).toPluginCall(call) + } + + @PluginMethod + fun getName(call: PluginCall) { + invokeSdkMethod(SdkMethod.getName, call).toPluginCall(call) } @PluginMethod - public fun stopTracking(call: PluginCall) { - invokeSdkMethod(SdkMethod.stopTracking, call).toPluginCall(call) + fun setIsAvailable(call: PluginCall) { + invokeSdkMethod(SdkMethod.setIsAvailable, call).toPluginCall(call) } @PluginMethod - public fun setAvailability(call: PluginCall) { - invokeSdkMethod(SdkMethod.setAvailability, call).toPluginCall(call) + fun setIsTracking(call: PluginCall) { + invokeSdkMethod(SdkMethod.setIsTracking, call).toPluginCall(call) } @PluginMethod - public fun setMetadata(call: PluginCall) { + fun setMetadata(call: PluginCall) { invokeSdkMethod(SdkMethod.setMetadata, call).toPluginCall(call) } @PluginMethod - public fun setName(call: PluginCall) { + fun setName(call: PluginCall) { invokeSdkMethod(SdkMethod.setName, call).toPluginCall(call) } @PluginMethod - public fun isTracking(call: PluginCall) { - invokeSdkMethod(SdkMethod.isTracking, call).toPluginCall(call) + fun onSubscribedToErrors(call: PluginCall) { + sendErrorsEvent(HyperTrack.errors) } @PluginMethod - public fun isAvailable(call: PluginCall) { - invokeSdkMethod(SdkMethod.isAvailable, call).toPluginCall(call) + fun onSubscribedToIsAvailable(call: PluginCall) { + sendIsAvailableEvent(HyperTrack.isAvailable) } @PluginMethod - public fun addGeotag(call: PluginCall) { - invokeSdkMethod(SdkMethod.addGeotag, call).toPluginCall(call) + fun onSubscribedToIsTracking(call: PluginCall) { + sendIsTrackingEvent(HyperTrack.isTracking) } @PluginMethod - public fun sync(call: PluginCall) { - invokeSdkMethod(SdkMethod.sync, call).toPluginCall(call) + fun onSubscribedToLocate(call: PluginCall) { + locateSubscription?.cancel() + locateSubscription = HyperTrack.locate { result -> + sendLocateEvent(result) + } } @PluginMethod - public fun onSubscribedToTracking(call: PluginCall) { - Log.v("ht_listener", "onSubscribedToTracking") - sendIsTrackingEvent( - Serialization.serializeIsTracking(HyperTrackSdkWrapper.sdkInstance.isTracking) + fun onSubscribedToLocation(call: PluginCall) { + sendLocationEvent(HyperTrack.location) + } + + private fun sendErrorsEvent(errors: Set) { + sendEvent( + EVENT_ERRORS, + serializeErrorsForCapacitor(serializeErrors(errors)).toJSObject() ) } - @PluginMethod - public fun onSubscribedToAvailability(call: PluginCall) { - sendAvailabilityEvent( - Serialization.serializeIsAvailable( - HyperTrackSdkWrapper.sdkInstance.availability == Availability.AVAILABLE - ) + private fun sendIsAvailableEvent(isAvailable: Boolean) { + sendEvent( + EVENT_IS_AVAILABLE, + Serialization.serializeIsAvailable(isAvailable).toJSObject() ) } - @PluginMethod - public fun onSubscribedToErrors(call: PluginCall) { - sendErrorsEvent(HyperTrackSdkWrapper.getInitialErrors()) + private fun sendIsTrackingEvent(isTracking: Boolean) { + sendEvent( + EVENT_IS_TRACKING, + Serialization.serializeIsTracking(isTracking).toJSObject() + ) + } + + private fun sendLocationEvent(locationResult: Result) { + sendEvent( + EVENT_LOCATION, + Serialization.serializeLocationResult(locationResult).toJSObject() + ) + } + + private fun sendLocateEvent(locateResult: Result>) { + sendEvent( + EVENT_LOCATE, + Serialization.serializeLocateResult(locateResult).toJSObject() + ) + } + + private fun initListeners() { + HyperTrack.subscribeToErrors { + sendErrorsEvent(it) + } + + HyperTrack.subscribeToIsAvailable { + sendIsAvailableEvent(it) + } + + HyperTrack.subscribeToIsTracking { + sendIsTrackingEvent(it) + } + + HyperTrack.subscribeToLocation { + sendLocationEvent(it) + } } private fun invokeSdkMethod( method: SdkMethod, call: PluginCall - ): Result<*> { + ): WrapperResult<*> { val argsJson = call.data return when (method) { - SdkMethod.initialize -> { - withArgs, Unit>(argsJson) { args -> - HyperTrackSdkWrapper.initializeSdk(args).mapSuccess { - initListeners(it) - } + SdkMethod.addGeotag -> { + withArgs, Map>(argsJson) { args -> + HyperTrackSdkWrapper.addGeotag(args) } } + SdkMethod.getDeviceID -> { HyperTrackSdkWrapper.getDeviceId() } - SdkMethod.isTracking -> { - HyperTrackSdkWrapper.isTracking() + + SdkMethod.getErrors -> { + HyperTrackSdkWrapper + .getErrors() + .mapSuccess { + serializeErrorsForCapacitor(it) + } } - SdkMethod.isAvailable -> { - HyperTrackSdkWrapper.isAvailable() + + SdkMethod.getIsAvailable -> { + HyperTrackSdkWrapper.getIsAvailable() } - SdkMethod.setAvailability -> { - withArgs, Unit>(argsJson) { args -> - HyperTrackSdkWrapper.setAvailability(args) - } + + SdkMethod.getIsTracking -> { + HyperTrackSdkWrapper.getIsTracking() } + SdkMethod.getLocation -> { HyperTrackSdkWrapper.getLocation() } - SdkMethod.startTracking -> { - HyperTrackSdkWrapper.startTracking() + + SdkMethod.getMetadata -> { + HyperTrackSdkWrapper.getMetadata() } - SdkMethod.stopTracking -> { - HyperTrackSdkWrapper.stopTracking() + + SdkMethod.getName -> { + HyperTrackSdkWrapper.getName() } - SdkMethod.addGeotag -> { - withArgs, Map>(argsJson) { args -> - HyperTrackSdkWrapper.addGeotag(args) + SdkMethod.locate -> { + throw NotImplementedError("Locate is implemented in different way") + } + SdkMethod.setIsAvailable -> { + withArgs, Unit>(argsJson) { args -> + HyperTrackSdkWrapper.setIsAvailable(args) } } - SdkMethod.setName -> { + SdkMethod.setIsTracking -> { withArgs, Unit>(argsJson) { args -> - HyperTrackSdkWrapper.setName(args) + HyperTrackSdkWrapper.setIsTracking(args) } } SdkMethod.setMetadata -> { @@ -146,71 +224,28 @@ public class HyperTrackCapacitorPlugin : Plugin() { HyperTrackSdkWrapper.setMetadata(args) } } - SdkMethod.sync -> { - HyperTrackSdkWrapper.sync() - } - } - } - private fun initListeners(sdk: HyperTrack) { - sdk.addTrackingListener(object : TrackingStateObserver.OnTrackingStateChangeListener { - override fun onTrackingStart() { - Log.v("ht_listener", "onTrackingStart") - sendIsTrackingEvent(Serialization.serializeIsTracking(true)) - } - - override fun onTrackingStop() { - Log.v("ht_listener", "onTrackingStop") - sendIsTrackingEvent(Serialization.serializeIsTracking(false)) - } - - override fun onError(error: TrackingError) { - sendErrorsEvent(HyperTrackSdkWrapper.getErrors(error)) - } - }) - - sdk.addAvailabilityListener(object : - AvailabilityStateObserver.OnAvailabilityStateChangeListener { - override fun onAvailable() { - sendAvailabilityEvent(Serialization.serializeIsAvailable(true)) - } - - override fun onUnavailable() { - sendAvailabilityEvent(Serialization.serializeIsAvailable(false)) - } - - override fun onError(error: AvailabilityError) { - // ignored, errors are handled by errorEventChannel + SdkMethod.setName -> { + withArgs, Unit>(argsJson) { args -> + HyperTrackSdkWrapper.setName(args) + } } - }) - } - - private fun sendIsTrackingEvent(data: Map, retainUntilConsumed: Boolean = false) { - notifyListeners(EVENT_TRACKING, data.toJSObject(), retainUntilConsumed) - } - - private fun sendAvailabilityEvent( - data: Map, - retainUntilConsumed: Boolean = false - ) { - notifyListeners(EVENT_AVAILABILITY, data.toJSObject(), retainUntilConsumed) + } } - private fun sendErrorsEvent( - data: List>, - retainUntilConsumed: Boolean = false - ) { - notifyListeners(EVENT_ERRORS, mapOf(KEY_ERRORS to data).toJSObject(), retainUntilConsumed) + private fun sendEvent(eventName: String, data: JSObject, retainUntilConsumed: Boolean = false) { + notifyListeners(eventName, data, retainUntilConsumed) } private inline fun withArgs( args: JSObject, - crossinline sdkMethodCall: (T) -> Result - ): Result { + crossinline sdkMethodCall: (T) -> WrapperResult + ): WrapperResult { return when (T::class) { Map::class -> { sdkMethodCall.invoke(args.toMap() as T) } + else -> { Failure(IllegalArgumentException(args.toString())) } @@ -218,9 +253,10 @@ public class HyperTrackCapacitorPlugin : Plugin() { } companion object { - private const val EVENT_TRACKING = "onTrackingChanged" - private const val EVENT_AVAILABILITY = "onAvailabilityChanged" - private const val EVENT_ERRORS = "onError" - private const val KEY_ERRORS = "errors" + private const val EVENT_ERRORS = "errors" + private const val EVENT_IS_TRACKING = "isTracking" + private const val EVENT_IS_AVAILABLE = "isAvailable" + private const val EVENT_LOCATE = "locate" + private const val EVENT_LOCATION = "location" } } diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Geotag.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/Geotag.kt deleted file mode 100644 index f21a269..0000000 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Geotag.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.hypertrack.sdk.capacitor.common - -/** - * The data that represents geotag to create. Now it contains only payload data but - * can have other params like expectedLocation in future - * - * @param data Geotag payload - */ -internal data class Geotag(val data: Map) diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/GeotagData.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/GeotagData.kt new file mode 100644 index 0000000..4aca40f --- /dev/null +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/common/GeotagData.kt @@ -0,0 +1,13 @@ +package com.hypertrack.sdk.capacitor.common + +import android.location.Location + +/** + * The data that represents geotag to create + * + * @param data Geotag payload + */ +internal data class GeotagData( + val data: Map, + val expectedLocation: Location? +) diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackError.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackError.kt deleted file mode 100644 index 22961d3..0000000 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackError.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.hypertrack.sdk.capacitor.common - -/** - * Check HyperTrack SDK docs for HyperTrackError. - * Enum naming convention is ignored to make datatype sync across platforms easier. - * Using Swift naming convention. - */ -@Suppress("EnumEntryName") -internal enum class HyperTrackError { - gpsSignalLost, - locationMocked, - locationPermissionsDenied, - locationPermissionsInsufficientForBackground, - locationPermissionsNotDetermined, - locationPermissionsReducedAccuracy, - locationPermissionsProvisional, - locationPermissionsRestricted, - locationServicesDisabled, - locationServicesUnavailable, - motionActivityPermissionsNotDetermined, - motionActivityPermissionsDenied, - motionActivityServicesDisabled, - motionActivityServicesUnavailable, - motionActivityPermissionsRestricted, - networkConnectionUnavailable, - invalidPublishableKey, - blockedFromRunning -} diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackSdkWrapper.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackSdkWrapper.kt index a07dc18..2a9dd88 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackSdkWrapper.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/common/HyperTrackSdkWrapper.kt @@ -1,17 +1,27 @@ package com.hypertrack.sdk.capacitor.common import com.hypertrack.sdk.* -import com.hypertrack.sdk.capacitor.common.Serialization.deserializeAvailability -import com.hypertrack.sdk.capacitor.common.Serialization.deserializeDeviceName +import com.hypertrack.sdk.android.HyperTrack +import com.hypertrack.sdk.android.HyperTrack.metadata +import com.hypertrack.sdk.android.Json +import com.hypertrack.sdk.android.Result +import com.hypertrack.sdk.capacitor.common.Serialization.deserializeIsAvailable +import com.hypertrack.sdk.capacitor.common.Serialization.deserializeName import com.hypertrack.sdk.capacitor.common.Serialization.deserializeGeotagData +import com.hypertrack.sdk.capacitor.common.Serialization.deserializeIsTracking +import com.hypertrack.sdk.capacitor.common.Serialization.deserializeMetadata import com.hypertrack.sdk.capacitor.common.Serialization.serializeDeviceId import com.hypertrack.sdk.capacitor.common.Serialization.serializeErrors -import com.hypertrack.sdk.capacitor.common.Serialization.serializeFailure import com.hypertrack.sdk.capacitor.common.Serialization.serializeIsAvailable import com.hypertrack.sdk.capacitor.common.Serialization.serializeIsTracking -import com.hypertrack.sdk.capacitor.common.Serialization.serializeSuccess -import java.lang.IllegalStateException -import java.lang.RuntimeException +import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationErrorFailure +import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationResult +import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationSuccess +import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationWithDeviationSuccess +import com.hypertrack.sdk.capacitor.common.Serialization.serializeMetadata +import com.hypertrack.sdk.capacitor.common.Serialization.serializeName + +typealias Serialized = Map /** * This class stores SDK instance, calls HyperTrack SDK methods and serializes responses. @@ -19,233 +29,116 @@ import java.lang.RuntimeException */ internal object HyperTrackSdkWrapper { - // initialize method is guaranteed to be called (by non-native side) - // prior to any access to the SDK instance - private lateinit var _sdkInstance: HyperTrack - val sdkInstance: HyperTrack - get() = _sdkInstance - - // method is named to align with 'initializeSDK' in iOS - fun initializeSdk( - args: Map - ): Result { - return try { - SdkInitParams - .fromMap(args) - .flatMapSuccess { initParams -> - _sdkInstance = HyperTrack.getInstance(initParams.publishableKey) - if (initParams.loggingEnabled) { - HyperTrack.enableDebugLogging() - } - if (initParams.allowMockLocations) { - sdkInstance.allowMockLocations() - } - this.sdkInstance.backgroundTrackingRequirement( - initParams.requireBackgroundTrackingPermission - ) - Success(sdkInstance) - } - } catch (exception: Exception) { - Failure(Exception("Hypertrack SDK initialization failed.", exception)) - } - } - - fun getDeviceId(): Result> { - return Success(serializeDeviceId(sdkInstance.deviceID)) - } - - fun startTracking(): Result { - sdkInstance.start() - return Success(Unit) - } - - fun stopTracking(): Result { - sdkInstance.stop() - return Success(Unit) - } - - fun sync(): Result { - sdkInstance.syncDeviceSettings() - return Success(Unit) - } - - fun addGeotag(args: Map): Result> { + fun addGeotag(args: Serialized): WrapperResult { return deserializeGeotagData(args) .flatMapSuccess { geotag -> - sdkInstance - .addGeotag(geotag.data) - .let { result -> - when (result) { - is GeotagResult.SuccessWithDeviation -> { - serializeSuccess(result.deviceLocation) - } - is GeotagResult.Success -> { - serializeSuccess(result.deviceLocation) - } - is GeotagResult.Error -> { - serializeFailure(getLocationError(result.reason)) - } - else -> { - throw IllegalArgumentException() + // TODO: return proper error if JSON is wrong + val geotagMetadata = Json.fromMap(geotag.data)!! + val expectedLocation = geotag + .expectedLocation + ?.let { + HyperTrack.Location( + latitude = it.latitude, + longitude = it.longitude + ) + } + if (expectedLocation != null) { + HyperTrack + .addGeotag(geotagMetadata, expectedLocation) + .let { + when (it) { + is Result.Failure -> { + serializeLocationErrorFailure(it.failure) + } + + is Result.Success -> { + serializeLocationWithDeviationSuccess(it.success) + } } } - } - .let { - Success(it) - } + } else { + HyperTrack + .addGeotag(geotagMetadata) + .let { serializeLocationResult(it) } + }.let { + Success(it) + } } } - fun isTracking(): Result> { - return Success(serializeIsTracking(sdkInstance.isTracking)) + fun getDeviceId(): WrapperResult { + return Success(serializeDeviceId(HyperTrack.deviceID)) } - fun isAvailable(): Result> { - return Success( - serializeIsAvailable(sdkInstance.availability.equals(Availability.AVAILABLE)) - ) + fun getErrors(): WrapperResult> { + return Success(serializeErrors(HyperTrack.errors)) } - fun setAvailability(args: Map): Result { - return deserializeAvailability(args) - .mapSuccess { isAvailable -> - if (isAvailable) { - sdkInstance.availability = Availability.AVAILABLE - } else { - sdkInstance.availability = Availability.UNAVAILABLE - } - } - } - - fun setName(args: Map): Result { - return deserializeDeviceName(args) - .mapSuccess { name -> - sdkInstance.setDeviceName(name) - } + fun getIsAvailable(): WrapperResult { + return Success( + serializeIsAvailable(HyperTrack.isAvailable) + ) } - fun setMetadata(metadata: Map): Result { - return Result.tryAsResult { - sdkInstance.setDeviceMetadata(metadata) - Unit - } + fun getIsTracking(): WrapperResult { + return Success( + serializeIsTracking(HyperTrack.isTracking) + ) } - fun getLocation(): Result> { - return sdkInstance.latestLocation - .let { result -> - if (result.isSuccess) { - serializeSuccess(result.value) - } else { - serializeFailure(getLocationError(result.error)) + fun getLocation(): WrapperResult { + return HyperTrack + .location + .let { + when (it) { + is Result.Failure -> serializeLocationErrorFailure(it.failure) + is Result.Success -> serializeLocationSuccess(it.success) } } .let { Success(it) } } - fun getInitialErrors(): List> { - return serializeErrors(getHyperTrackErrorsFromBlockers()) + fun getMetadata(): WrapperResult { + return Success( + serializeMetadata(HyperTrack.metadata.toMap()) + ) } - fun getErrors(error: TrackingError): List> { - return serializeErrors(getTrackingErrors((error))) + fun getName(): WrapperResult { + return Success( + serializeName(HyperTrack.name) + ) } - private fun getTrackingErrors(error: TrackingError): Set { - return when (error.code) { - TrackingError.INVALID_PUBLISHABLE_KEY_ERROR -> { - HyperTrackError.invalidPublishableKey - } - TrackingError.PERMISSION_DENIED_ERROR -> { - null - } - TrackingError.AUTHORIZATION_ERROR -> { - HyperTrackError.blockedFromRunning - } - TrackingError.GPS_PROVIDER_DISABLED_ERROR -> { - HyperTrackError.locationServicesDisabled - } - TrackingError.UNKNOWN_NETWORK_ERROR -> { - HyperTrackError.blockedFromRunning - } - else -> { - throw RuntimeException("Unknown tracking error") - } - } - .let { hyperTrackError -> - (hyperTrackError?.let { setOf(it) } ?: setOf()) + getHyperTrackErrorsFromBlockers() + fun setIsAvailable(args: Serialized): WrapperResult { + return deserializeIsAvailable(args) + .mapSuccess { isAvailable -> + HyperTrack.isAvailable = isAvailable } } - private fun getLocationError(error: OutageReason): LocationError { - val blockersErrors = getHyperTrackErrorsFromBlockers() - return when (error) { - OutageReason.NO_GPS_SIGNAL -> { - Errors(setOf(HyperTrackError.gpsSignalLost) + blockersErrors) - } - OutageReason.MISSING_LOCATION_PERMISSION -> { - Errors(setOf(HyperTrackError.locationPermissionsDenied) + blockersErrors) - } - OutageReason.LOCATION_SERVICE_DISABLED -> { - Errors(setOf(HyperTrackError.locationServicesDisabled) + blockersErrors) - } - OutageReason.MISSING_ACTIVITY_PERMISSION -> { - Errors(setOf(HyperTrackError.motionActivityPermissionsDenied) + blockersErrors) + fun setIsTracking(args: Serialized): WrapperResult { + return deserializeIsTracking(args) + .mapSuccess { isTracking -> + HyperTrack.isTracking = isTracking } - OutageReason.NOT_TRACKING -> { - NotRunning - } - OutageReason.START_HAS_NOT_FINISHED -> { - Starting - } - OutageReason.RESTART_REQUIRED -> { - throw IllegalStateException("RESTART_REQUIRED must not be returned") - } - } } - private fun getLocationError(error: GeotagResult.Error.Reason): LocationError { - val blockersErrors = getHyperTrackErrorsFromBlockers() - return when (error) { - GeotagResult.Error.Reason.NO_GPS_SIGNAL -> { - Errors(setOf(HyperTrackError.gpsSignalLost) + blockersErrors) - } - GeotagResult.Error.Reason.MISSING_LOCATION_PERMISSION -> { - Errors(setOf(HyperTrackError.locationPermissionsDenied) + blockersErrors) - } - GeotagResult.Error.Reason.LOCATION_SERVICE_DISABLED -> { - Errors(setOf(HyperTrackError.locationServicesDisabled) + blockersErrors) - } - GeotagResult.Error.Reason.MISSING_ACTIVITY_PERMISSION -> { - Errors(setOf(HyperTrackError.motionActivityPermissionsDenied) + blockersErrors) - } - GeotagResult.Error.Reason.NOT_TRACKING -> { - NotRunning - } - GeotagResult.Error.Reason.START_HAS_NOT_FINISHED -> { - Starting + fun setMetadata(args: Serialized): WrapperResult { + return deserializeMetadata(args) + .flatMapSuccess { metadata -> + WrapperResult.tryAsResult { + // TODO: return proper error if JSON is wrong + HyperTrack.metadata = Json.fromMap(metadata)!! + } } - } } - private fun getHyperTrackErrorsFromBlockers(): Set { - return HyperTrack.getBlockers() - .map { - when (it) { - Blocker.LOCATION_PERMISSION_DENIED -> { - HyperTrackError.locationPermissionsDenied - } - Blocker.LOCATION_SERVICE_DISABLED -> { - HyperTrackError.locationServicesDisabled - } - Blocker.ACTIVITY_PERMISSION_DENIED -> { - HyperTrackError.motionActivityPermissionsDenied - } - Blocker.BACKGROUND_LOCATION_DENIED -> { - HyperTrackError.locationPermissionsInsufficientForBackground - } - } + fun setName(args: Serialized): WrapperResult { + return deserializeName(args) + .mapSuccess { name -> + HyperTrack.name = name } - .toSet() } + } diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/LocationError.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/LocationError.kt deleted file mode 100644 index fb6e245..0000000 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/LocationError.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.hypertrack.sdk.capacitor.common - -/** - * Check HyperTrack SDK docs for LocationError - */ -internal sealed class LocationError -internal object NotRunning : LocationError() -internal object Starting : LocationError() -internal data class Errors(val errors: Set) : LocationError() diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkInitParams.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkInitParams.kt deleted file mode 100644 index ee9e5a9..0000000 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkInitParams.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.hypertrack.sdk.capacitor.common - -import com.hypertrack.sdk.capacitor.common.Serialization.parse - -/** - * SDK config params - */ -internal data class SdkInitParams( - val publishableKey: String, - val requireBackgroundTrackingPermission: Boolean, - val loggingEnabled: Boolean, - val allowMockLocations: Boolean -) { - - companion object { - fun fromMap(map: Map): Result { - return parse(map) { - SdkInitParams( - publishableKey = it - .get(KEY_PUBLISHABLE_KEY) - .getOrThrow(), - requireBackgroundTrackingPermission = it - .get(KEY_REQUIRE_BACKGROUND_TRACKING_PERMISSION) - .getOrThrow(), - loggingEnabled = it - .get(KEY_LOGGING_ENABLED) - .getOrThrow(), - allowMockLocations = it - .get(KEY_ALLOW_MOCK_LOCATIONS) - .getOrThrow() - ) - } - } - - private const val KEY_PUBLISHABLE_KEY = - "publishableKey" - private const val KEY_REQUIRE_BACKGROUND_TRACKING_PERMISSION = - "requireBackgroundTrackingPermission" - private const val KEY_LOGGING_ENABLED = - "loggingEnabled" - private const val KEY_ALLOW_MOCK_LOCATIONS = - "allowMockLocations" - } -} diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkMethod.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkMethod.kt index 3cb657b..f0088cc 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkMethod.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/common/SdkMethod.kt @@ -2,20 +2,22 @@ package com.hypertrack.sdk.capacitor.common /** * The list of available methods in the SDK API. + * It is used to match method calls in some wrappers (like Flutter) * Enum naming convention is ignored to make datatype sync across platforms easier. * Using Swift naming convention. */ internal enum class SdkMethod { - initialize, + addGeotag, getDeviceID, + getErrors, + getIsAvailable, + getIsTracking, getLocation, - startTracking, - stopTracking, - setAvailability, - setName, + getMetadata, + getName, + locate, + setIsAvailable, + setIsTracking, setMetadata, - isTracking, - isAvailable, - addGeotag, - sync + setName, } diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Serialization.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/Serialization.kt index d99e629..3a36f7c 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Serialization.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/common/Serialization.kt @@ -1,6 +1,8 @@ package com.hypertrack.sdk.capacitor.common import android.location.Location +import com.hypertrack.sdk.android.HyperTrack +import com.hypertrack.sdk.android.Result /** * Platform-independent serialization code that converts HyperTrack data types @@ -8,23 +10,91 @@ import android.location.Location */ internal object Serialization { - fun serializeErrors(errors: Set): List> { - return errors.map { - serializeHypertrackError(it) + fun deserializeIsAvailable(isAvailable: Map): WrapperResult { + return parse(isAvailable) { + it.assertValue(key = KEY_TYPE, value = TYPE_IS_AVAILABLE) + it + .get(KEY_VALUE) + .getOrThrow() } } - fun serializeSuccess(location: Location): Map { + fun deserializeIsTracking(isTracking: Map): WrapperResult { + return parse(isTracking) { + it.assertValue(key = KEY_TYPE, value = TYPE_IS_TRACKING) + it + .get(KEY_VALUE) + .getOrThrow() + } + } + + fun deserializeMetadata(metadata: Map): WrapperResult> { + return parse(metadata) { + it.assertValue(key = KEY_TYPE, value = TYPE_METADATA) + it + .get>(KEY_VALUE) + .getOrThrow() + } + } + + fun deserializeName(name: Map): WrapperResult { + return parse(name) { + it.assertValue(key = KEY_TYPE, value = TYPE_NAME) + it + .get(KEY_VALUE) + .getOrThrow() + } + } + + fun deserializeGeotagData(map: Map): WrapperResult { + return parse(map) { + val data = it + .get>(KEY_GEOTAG_DATA) + .getOrThrow() + val locationData = it + .getOptional>(KEY_GEOTAG_EXPECTED_LOCATION) + .getOrThrow() + val location = locationData?.let { deserializeLocation(it).getOrThrow() } + GeotagData(data, location) + } + } + + fun serializeDeviceId(deviceId: String): Map { return mapOf( - KEY_TYPE to TYPE_RESULT_SUCCESS, - KEY_VALUE to serializeLocation(location) + KEY_TYPE to TYPE_DEVICE_ID, + KEY_VALUE to deviceId ) } - fun serializeFailure(locationError: LocationError): Map { + fun serializeError(error: HyperTrack.Error): Map { return mapOf( - KEY_TYPE to TYPE_RESULT_FAILURE, - KEY_VALUE to serializeLocationError(locationError) + KEY_TYPE to TYPE_ERROR, + KEY_VALUE to when (error) { + HyperTrack.Error.BlockedFromRunning -> "blockedFromRunning" + HyperTrack.Error.InvalidPublishableKey -> "invalidPublishableKey" + HyperTrack.Error.Location.Mocked -> "location.mocked" + HyperTrack.Error.Location.ServicesDisabled -> "location.servicesDisabled" + HyperTrack.Error.Location.ServicesUnavailable -> "location.servicesUnavailable" + HyperTrack.Error.Location.SignalLost -> "location.signalLost" + HyperTrack.Error.NoExemptionFromBackgroundStartRestrictions -> "noExemptionFromBackgroundStartRestrictions" + HyperTrack.Error.Permissions.Location.Denied -> "permissions.location.denied" + HyperTrack.Error.Permissions.Location.InsufficientForBackground -> "permissions.location.insufficientForBackground" + HyperTrack.Error.Permissions.Location.ReducedAccuracy -> "permissions.location.reducedAccuracy" + HyperTrack.Error.Permissions.Notifications.Denied -> "permissions.notifications.denied" + } + ) + } + + fun serializeErrors(errors: Set): List> { + return errors.map { + serializeError(it) + } + } + + fun serializeIsAvailable(isAvailable: Boolean): Map { + return mapOf( + KEY_TYPE to TYPE_IS_AVAILABLE, + KEY_VALUE to isAvailable ) } @@ -35,86 +105,155 @@ internal object Serialization { ) } - fun serializeIsAvailable(isAvailable: Boolean): Map { + fun serializeMetadata(metadata: Map): Map { return mapOf( - KEY_TYPE to TYPE_AVAILABILITY, - KEY_VALUE to isAvailable + KEY_TYPE to TYPE_METADATA, + KEY_VALUE to metadata ) } - fun serializeLocation(location: Location): Map { + fun serializeName(name: String): Map { return mapOf( - KEY_TYPE to TYPE_LOCATION, - KEY_VALUE to mapOf( - KEY_LATITUDE to location.latitude, - KEY_LONGITUDE to location.longitude - ) + KEY_TYPE to TYPE_NAME, + KEY_VALUE to name ) } - fun serializeLocationError(locationError: LocationError): Map { - return when (locationError) { - NotRunning -> { - mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING) + fun serializeLocateResult( + locationResult: Result> + ): Map { + return when (locationResult) { + is Result.Failure -> { + serializeFailure(serializeErrors(locationResult.failure)) } - Starting -> { - mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING) + + is Result.Success -> { + serializeLocationSuccess(locationResult.success) } - is Errors -> { - mapOf( - KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS, - KEY_VALUE to locationError.errors - .map { serializeHypertrackError(it) } - ) + } + } + + fun serializeLocationResult( + locationResult: Result + ): Map { + return when (locationResult) { + is Result.Failure -> { + serializeLocationErrorFailure(locationResult.failure) + } + + is Result.Success -> { + serializeLocationSuccess(locationResult.success) } } } - fun serializeHypertrackError(error: HyperTrackError): Map { - return mapOf( - KEY_TYPE to TYPE_HYPERTRACK_ERROR, - KEY_VALUE to error.name + fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError): Map { + return serializeFailure(serializeLocationError(locationError)) + } + + fun serializeLocationSuccess(location: HyperTrack.Location): Map { + return serializeSuccess(serializeLocation(location)) + } + + fun serializeLocationWithDeviationSuccess( + locationWithDeviation: HyperTrack.LocationWithDeviation, + ): Map { + return serializeSuccess( + serializeLocationWithDeviation( + locationWithDeviation + ) ) } - fun serializeDeviceId(deviceId: String): Map { + private fun serializeLocationWithDeviation( + locationWithDeviation: HyperTrack.LocationWithDeviation, + ): Map { return mapOf( - KEY_TYPE to TYPE_DEVICE_ID, - KEY_VALUE to deviceId + KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION, + KEY_VALUE to mapOf( + KEY_LOCATION to serializeLocation(locationWithDeviation.location), + KEY_DEVIATION to locationWithDeviation.deviation + ) ) } - fun deserializeDeviceName(name: Map): Result { - return parse(name) { - it.assertValue(key = KEY_TYPE, value = TYPE_DEVICE_NAME) - it - .get(KEY_VALUE) + private fun deserializeLocation(map: Map): WrapperResult { + return parse(map) { + it.assertValue(key = KEY_TYPE, value = TYPE_LOCATION) + val value = it + .get>(KEY_VALUE) .getOrThrow() + parse(value) { parser -> + val latitude = parser + .get(KEY_LATITUDE) + .getOrThrow() + val longitude = parser + .get(KEY_LONGITUDE) + .getOrThrow() + Location("api").also { + it.latitude = latitude + it.longitude = longitude + } + }.getOrThrow() } } - fun deserializeAvailability(isAvailable: Map): Result { - return parse(isAvailable) { - it.assertValue(key = KEY_TYPE, value = TYPE_AVAILABILITY) - it - .get(KEY_VALUE) - .getOrThrow() - } + private fun serializeFailure(failure: List>): Map { + return mapOf( + KEY_TYPE to TYPE_RESULT_FAILURE, + KEY_VALUE to failure + ) } - fun deserializeGeotagData(map: Map): Result { - return parse(map) { - val data = it - .get>(KEY_GEOTAG_DATA) - .getOrThrow() - Geotag(data) + private fun serializeFailure(failure: Map): Map { + return mapOf( + KEY_TYPE to TYPE_RESULT_FAILURE, + KEY_VALUE to failure + ) + } + + private fun serializeSuccess(success: Map): Map { + return mapOf( + KEY_TYPE to TYPE_RESULT_SUCCESS, + KEY_VALUE to success + ) + } + + fun serializeLocation(location: HyperTrack.Location): Map { + return mapOf( + KEY_TYPE to TYPE_LOCATION, + KEY_VALUE to mapOf( + KEY_LATITUDE to location.latitude, + KEY_LONGITUDE to location.longitude + ) + ) + } + + + private fun serializeLocationError(locationError: HyperTrack.LocationError): Map { + return when (locationError) { + HyperTrack.LocationError.NotRunning -> { + mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING) + } + + HyperTrack.LocationError.Starting -> { + mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING) + } + + is HyperTrack.LocationError.Errors -> { + mapOf( + KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS, + KEY_VALUE to locationError.errors + .map { serializeError(it) } + ) + } } } fun parse( source: Map, parseFunction: (Parser) -> T - ): Result { + ): WrapperResult { val parser = Parser(source) return try { if (parser.exceptions.isEmpty()) { @@ -141,7 +280,7 @@ internal object Serialization { inline fun get( key: String - ): Result { + ): WrapperResult { return try { Success(source[key]!! as T) } catch (e: Exception) { @@ -154,6 +293,21 @@ internal object Serialization { } } + inline fun getOptional( + key: String + ): WrapperResult { + return try { + Success(source[key] as T?) + } catch (e: Exception) { + Failure( + ParsingException(key, e) + .also { + _exceptions.add(it) + } + ) + } + } + inline fun assertValue( key: String, value: Any @@ -182,22 +336,27 @@ internal object Serialization { private const val KEY_TYPE = "type" private const val KEY_VALUE = "value" - private const val TYPE_RESULT_SUCCESS = "success" private const val TYPE_RESULT_FAILURE = "failure" + private const val TYPE_RESULT_SUCCESS = "success" - private const val TYPE_LOCATION = "location" - private const val TYPE_AVAILABILITY = "isAvailable" - private const val TYPE_DEVICE_NAME = "deviceName" private const val TYPE_DEVICE_ID = "deviceID" - private const val TYPE_HYPERTRACK_ERROR = "hyperTrackError" + private const val TYPE_ERROR = "error" + private const val TYPE_IS_AVAILABLE = "isAvailable" private const val TYPE_IS_TRACKING = "isTracking" + private const val TYPE_METADATA = "metadata" + private const val TYPE_NAME = "name" + private const val TYPE_LOCATION = "location" + private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation" + private const val TYPE_LOCATION_ERROR_ERRORS = "errors" private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning" private const val TYPE_LOCATION_ERROR_STARTING = "starting" - private const val TYPE_LOCATION_ERROR_ERRORS = "errors" private const val KEY_LATITUDE = "latitude" private const val KEY_LONGITUDE = "longitude" + const val KEY_DEVIATION = "deviation" const val KEY_GEOTAG_DATA = "data" + const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation" + const val KEY_LOCATION = "location" } diff --git a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Result.kt b/android/src/main/java/com/hypertrack/sdk/capacitor/common/WrapperResult.kt similarity index 80% rename from android/src/main/java/com/hypertrack/sdk/capacitor/common/Result.kt rename to android/src/main/java/com/hypertrack/sdk/capacitor/common/WrapperResult.kt index 4808af2..4219828 100644 --- a/android/src/main/java/com/hypertrack/sdk/capacitor/common/Result.kt +++ b/android/src/main/java/com/hypertrack/sdk/capacitor/common/WrapperResult.kt @@ -1,24 +1,26 @@ package com.hypertrack.sdk.capacitor.common -internal sealed class Result { +internal sealed class WrapperResult { fun flatMapSuccess( - onSuccess: (SuccessType) -> Result - ): Result { + onSuccess: (SuccessType) -> WrapperResult + ): WrapperResult { return when (this) { is Success -> { onSuccess.invoke(this.success) } + is Failure -> { Failure(this.failure) } } } - fun mapSuccess(onSuccess: (SuccessType) -> MappedSuccess): Result { + fun mapSuccess(onSuccess: (SuccessType) -> MappedSuccess): WrapperResult { return when (this) { is Success -> { Success(onSuccess.invoke(this.success)) } + is Failure -> { Failure(this.failure) } @@ -36,7 +38,7 @@ internal sealed class Result { } companion object { - fun tryAsResult(block: () -> SuccessType): Result { + fun tryAsResult(block: () -> SuccessType): WrapperResult { return try { Success(block.invoke()) } catch (e: Exception) { @@ -46,5 +48,5 @@ internal sealed class Result { } } -internal data class Success(val success: SuccessType) : Result() -internal data class Failure(val failure: Throwable) : Result() +internal data class Success(val success: SuccessType) : WrapperResult() +internal data class Failure(val failure: Throwable) : WrapperResult() diff --git a/docs/assets/highlight.css b/docs/assets/highlight.css index 5674cf3..13409c3 100644 --- a/docs/assets/highlight.css +++ b/docs/assets/highlight.css @@ -1,22 +1,71 @@ :root { + --light-hl-0: #0000FF; + --dark-hl-0: #569CD6; + --light-hl-1: #000000; + --dark-hl-1: #D4D4D4; + --light-hl-2: #0070C1; + --dark-hl-2: #4FC1FF; + --light-hl-3: #001080; + --dark-hl-3: #9CDCFE; + --light-hl-4: #795E26; + --dark-hl-4: #DCDCAA; + --light-hl-5: #008000; + --dark-hl-5: #6A9955; + --light-hl-6: #AF00DB; + --dark-hl-6: #C586C0; --light-code-background: #FFFFFF; --dark-code-background: #1E1E1E; } @media (prefers-color-scheme: light) { :root { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); --code-background: var(--light-code-background); } } @media (prefers-color-scheme: dark) { :root { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); --code-background: var(--dark-code-background); } } :root[data-theme='light'] { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); --code-background: var(--light-code-background); } :root[data-theme='dark'] { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); --code-background: var(--dark-code-background); } +.hl-0 { color: var(--hl-0); } +.hl-1 { color: var(--hl-1); } +.hl-2 { color: var(--hl-2); } +.hl-3 { color: var(--hl-3); } +.hl-4 { color: var(--hl-4); } +.hl-5 { color: var(--hl-5); } +.hl-6 { color: var(--hl-6); } pre, code { background: var(--code-background); } diff --git a/docs/assets/search.js b/docs/assets/search.js index 0d39ba6..2ad0643 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = JSON.parse("{\"kinds\":{\"8\":\"Enumeration\",\"16\":\"Enumeration Member\",\"128\":\"Class\",\"256\":\"Interface\",\"512\":\"Constructor\",\"1024\":\"Property\",\"2048\":\"Method\",\"65536\":\"Type literal\",\"4194304\":\"Type alias\",\"8388608\":\"Reference\"},\"rows\":[{\"kind\":128,\"name\":\"HyperTrack\",\"url\":\"classes/HyperTrack.html\",\"classes\":\"tsd-kind-class\"},{\"kind\":2048,\"name\":\"initialize\",\"url\":\"classes/HyperTrack.html#initialize\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/HyperTrack.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getDeviceId\",\"url\":\"classes/HyperTrack.html#getDeviceId\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"isAvailable\",\"url\":\"classes/HyperTrack.html#isAvailable\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setAvailability\",\"url\":\"classes/HyperTrack.html#setAvailability\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"isTracking\",\"url\":\"classes/HyperTrack.html#isTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"sync\",\"url\":\"classes/HyperTrack.html#sync\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"startTracking\",\"url\":\"classes/HyperTrack.html#startTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"stopTracking\",\"url\":\"classes/HyperTrack.html#stopTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getLocation\",\"url\":\"classes/HyperTrack.html#getLocation\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setName\",\"url\":\"classes/HyperTrack.html#setName\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setMetadata\",\"url\":\"classes/HyperTrack.html#setMetadata\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"addGeotag\",\"url\":\"classes/HyperTrack.html#addGeotag\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToTracking\",\"url\":\"classes/HyperTrack.html#subscribeToTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToAvailability\",\"url\":\"classes/HyperTrack.html#subscribeToAvailability\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToErrors\",\"url\":\"classes/HyperTrack.html#subscribeToErrors\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":4194304,\"name\":\"SdkInitParams\",\"url\":\"types/SdkInitParams.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/SdkInitParams.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"SdkInitParams\"},{\"kind\":1024,\"name\":\"loggingEnabled\",\"url\":\"types/SdkInitParams.html#__type.loggingEnabled\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"SdkInitParams.__type\"},{\"kind\":1024,\"name\":\"allowMockLocations\",\"url\":\"types/SdkInitParams.html#__type.allowMockLocations\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"SdkInitParams.__type\"},{\"kind\":1024,\"name\":\"requireBackgroundTrackingPermission\",\"url\":\"types/SdkInitParams.html#__type.requireBackgroundTrackingPermission\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"SdkInitParams.__type\"},{\"kind\":8,\"name\":\"HyperTrackError\",\"url\":\"enums/HyperTrackError.html\",\"classes\":\"tsd-kind-enum\"},{\"kind\":16,\"name\":\"gpsSignalLost\",\"url\":\"enums/HyperTrackError.html#gpsSignalLost\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationMocked\",\"url\":\"enums/HyperTrackError.html#locationMocked\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsDenied\",\"url\":\"enums/HyperTrackError.html#locationPermissionsDenied\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsInsufficientForBackground\",\"url\":\"enums/HyperTrackError.html#locationPermissionsInsufficientForBackground\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsNotDetermined\",\"url\":\"enums/HyperTrackError.html#locationPermissionsNotDetermined\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsReducedAccuracy\",\"url\":\"enums/HyperTrackError.html#locationPermissionsReducedAccuracy\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsProvisional\",\"url\":\"enums/HyperTrackError.html#locationPermissionsProvisional\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationPermissionsRestricted\",\"url\":\"enums/HyperTrackError.html#locationPermissionsRestricted\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationServicesDisabled\",\"url\":\"enums/HyperTrackError.html#locationServicesDisabled\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationServicesUnavailable\",\"url\":\"enums/HyperTrackError.html#locationServicesUnavailable\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"motionActivityPermissionsNotDetermined\",\"url\":\"enums/HyperTrackError.html#motionActivityPermissionsNotDetermined\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"motionActivityPermissionsDenied\",\"url\":\"enums/HyperTrackError.html#motionActivityPermissionsDenied\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"motionActivityServicesDisabled\",\"url\":\"enums/HyperTrackError.html#motionActivityServicesDisabled\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"motionActivityServicesUnavailable\",\"url\":\"enums/HyperTrackError.html#motionActivityServicesUnavailable\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"motionActivityPermissionsRestricted\",\"url\":\"enums/HyperTrackError.html#motionActivityPermissionsRestricted\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"networkConnectionUnavailable\",\"url\":\"enums/HyperTrackError.html#networkConnectionUnavailable\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"invalidPublishableKey\",\"url\":\"enums/HyperTrackError.html#invalidPublishableKey\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"blockedFromRunning\",\"url\":\"enums/HyperTrackError.html#blockedFromRunning\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":4194304,\"name\":\"LocationError\",\"url\":\"types/LocationError.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":4194304,\"name\":\"NotRunning\",\"url\":\"types/NotRunning.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/NotRunning.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"NotRunning\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/NotRunning.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"NotRunning.__type\"},{\"kind\":4194304,\"name\":\"Starting\",\"url\":\"types/Starting.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Starting.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Starting\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Starting.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Starting.__type\"},{\"kind\":4194304,\"name\":\"Errors\",\"url\":\"types/Errors.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Errors.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Errors\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Errors.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Errors.__type\"},{\"kind\":1024,\"name\":\"value\",\"url\":\"types/Errors.html#__type.value\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Errors.__type\"},{\"kind\":4194304,\"name\":\"Location\",\"url\":\"types/Location.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Location.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Location\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Location.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type\"},{\"kind\":1024,\"name\":\"value\",\"url\":\"types/Location.html#__type.value\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Location.html#__type.value.__type-1\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-property\",\"parent\":\"Location.__type.value\"},{\"kind\":1024,\"name\":\"latitude\",\"url\":\"types/Location.html#__type.value.__type-1.latitude\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type.value.__type\"},{\"kind\":1024,\"name\":\"longitude\",\"url\":\"types/Location.html#__type.value.__type-1.longitude\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type.value.__type\"},{\"kind\":256,\"name\":\"Subscription\",\"url\":\"interfaces/Subscription.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"remove\",\"url\":\"interfaces/Subscription.html#remove\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Subscription\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/Subscription.html#remove.__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-property\",\"parent\":\"Subscription.remove\"},{\"kind\":8388608,\"name\":\"default\",\"url\":\"index.html#default\",\"classes\":\"tsd-kind-reference\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,37.534]],[\"comment/0\",[]],[\"name/1\",[1,37.534]],[\"comment/1\",[]],[\"name/2\",[2,37.534]],[\"comment/2\",[]],[\"name/3\",[3,37.534]],[\"comment/3\",[]],[\"name/4\",[4,37.534]],[\"comment/4\",[]],[\"name/5\",[5,37.534]],[\"comment/5\",[]],[\"name/6\",[6,37.534]],[\"comment/6\",[]],[\"name/7\",[7,37.534]],[\"comment/7\",[]],[\"name/8\",[8,37.534]],[\"comment/8\",[]],[\"name/9\",[9,37.534]],[\"comment/9\",[]],[\"name/10\",[10,37.534]],[\"comment/10\",[]],[\"name/11\",[11,37.534]],[\"comment/11\",[]],[\"name/12\",[12,37.534]],[\"comment/12\",[]],[\"name/13\",[13,37.534]],[\"comment/13\",[]],[\"name/14\",[14,37.534]],[\"comment/14\",[]],[\"name/15\",[15,37.534]],[\"comment/15\",[]],[\"name/16\",[16,37.534]],[\"comment/16\",[]],[\"name/17\",[17,37.534]],[\"comment/17\",[]],[\"name/18\",[18,21.44]],[\"comment/18\",[]],[\"name/19\",[19,37.534]],[\"comment/19\",[]],[\"name/20\",[20,37.534]],[\"comment/20\",[]],[\"name/21\",[21,37.534]],[\"comment/21\",[]],[\"name/22\",[22,37.534]],[\"comment/22\",[]],[\"name/23\",[23,37.534]],[\"comment/23\",[]],[\"name/24\",[24,37.534]],[\"comment/24\",[]],[\"name/25\",[25,37.534]],[\"comment/25\",[]],[\"name/26\",[26,37.534]],[\"comment/26\",[]],[\"name/27\",[27,37.534]],[\"comment/27\",[]],[\"name/28\",[28,37.534]],[\"comment/28\",[]],[\"name/29\",[29,37.534]],[\"comment/29\",[]],[\"name/30\",[30,37.534]],[\"comment/30\",[]],[\"name/31\",[31,37.534]],[\"comment/31\",[]],[\"name/32\",[32,37.534]],[\"comment/32\",[]],[\"name/33\",[33,37.534]],[\"comment/33\",[]],[\"name/34\",[34,37.534]],[\"comment/34\",[]],[\"name/35\",[35,37.534]],[\"comment/35\",[]],[\"name/36\",[36,37.534]],[\"comment/36\",[]],[\"name/37\",[37,37.534]],[\"comment/37\",[]],[\"name/38\",[38,37.534]],[\"comment/38\",[]],[\"name/39\",[39,37.534]],[\"comment/39\",[]],[\"name/40\",[40,37.534]],[\"comment/40\",[]],[\"name/41\",[41,37.534]],[\"comment/41\",[]],[\"name/42\",[42,37.534]],[\"comment/42\",[]],[\"name/43\",[18,21.44]],[\"comment/43\",[]],[\"name/44\",[43,26.548]],[\"comment/44\",[]],[\"name/45\",[44,37.534]],[\"comment/45\",[]],[\"name/46\",[18,21.44]],[\"comment/46\",[]],[\"name/47\",[43,26.548]],[\"comment/47\",[]],[\"name/48\",[45,37.534]],[\"comment/48\",[]],[\"name/49\",[18,21.44]],[\"comment/49\",[]],[\"name/50\",[43,26.548]],[\"comment/50\",[]],[\"name/51\",[46,32.426]],[\"comment/51\",[]],[\"name/52\",[47,37.534]],[\"comment/52\",[]],[\"name/53\",[18,21.44]],[\"comment/53\",[]],[\"name/54\",[43,26.548]],[\"comment/54\",[]],[\"name/55\",[46,32.426]],[\"comment/55\",[]],[\"name/56\",[18,21.44]],[\"comment/56\",[]],[\"name/57\",[48,37.534]],[\"comment/57\",[]],[\"name/58\",[49,37.534]],[\"comment/58\",[]],[\"name/59\",[50,37.534]],[\"comment/59\",[]],[\"name/60\",[51,37.534]],[\"comment/60\",[]],[\"name/61\",[18,21.44]],[\"comment/61\",[]],[\"name/62\",[52,37.534]],[\"comment/62\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":18,\"name\":{\"18\":{},\"43\":{},\"46\":{},\"49\":{},\"53\":{},\"56\":{},\"61\":{}},\"comment\":{}}],[\"addgeotag\",{\"_index\":13,\"name\":{\"13\":{}},\"comment\":{}}],[\"allowmocklocations\",{\"_index\":20,\"name\":{\"20\":{}},\"comment\":{}}],[\"blockedfromrunning\",{\"_index\":40,\"name\":{\"40\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"default\",{\"_index\":52,\"name\":{\"62\":{}},\"comment\":{}}],[\"errors\",{\"_index\":45,\"name\":{\"48\":{}},\"comment\":{}}],[\"getdeviceid\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}],[\"getlocation\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"gpssignallost\",{\"_index\":23,\"name\":{\"23\":{}},\"comment\":{}}],[\"hypertrack\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"hypertrackerror\",{\"_index\":22,\"name\":{\"22\":{}},\"comment\":{}}],[\"initialize\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"invalidpublishablekey\",{\"_index\":39,\"name\":{\"39\":{}},\"comment\":{}}],[\"isavailable\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"istracking\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"latitude\",{\"_index\":48,\"name\":{\"57\":{}},\"comment\":{}}],[\"location\",{\"_index\":47,\"name\":{\"52\":{}},\"comment\":{}}],[\"locationerror\",{\"_index\":41,\"name\":{\"41\":{}},\"comment\":{}}],[\"locationmocked\",{\"_index\":24,\"name\":{\"24\":{}},\"comment\":{}}],[\"locationpermissionsdenied\",{\"_index\":25,\"name\":{\"25\":{}},\"comment\":{}}],[\"locationpermissionsinsufficientforbackground\",{\"_index\":26,\"name\":{\"26\":{}},\"comment\":{}}],[\"locationpermissionsnotdetermined\",{\"_index\":27,\"name\":{\"27\":{}},\"comment\":{}}],[\"locationpermissionsprovisional\",{\"_index\":29,\"name\":{\"29\":{}},\"comment\":{}}],[\"locationpermissionsreducedaccuracy\",{\"_index\":28,\"name\":{\"28\":{}},\"comment\":{}}],[\"locationpermissionsrestricted\",{\"_index\":30,\"name\":{\"30\":{}},\"comment\":{}}],[\"locationservicesdisabled\",{\"_index\":31,\"name\":{\"31\":{}},\"comment\":{}}],[\"locationservicesunavailable\",{\"_index\":32,\"name\":{\"32\":{}},\"comment\":{}}],[\"loggingenabled\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"longitude\",{\"_index\":49,\"name\":{\"58\":{}},\"comment\":{}}],[\"motionactivitypermissionsdenied\",{\"_index\":34,\"name\":{\"34\":{}},\"comment\":{}}],[\"motionactivitypermissionsnotdetermined\",{\"_index\":33,\"name\":{\"33\":{}},\"comment\":{}}],[\"motionactivitypermissionsrestricted\",{\"_index\":37,\"name\":{\"37\":{}},\"comment\":{}}],[\"motionactivityservicesdisabled\",{\"_index\":35,\"name\":{\"35\":{}},\"comment\":{}}],[\"motionactivityservicesunavailable\",{\"_index\":36,\"name\":{\"36\":{}},\"comment\":{}}],[\"networkconnectionunavailable\",{\"_index\":38,\"name\":{\"38\":{}},\"comment\":{}}],[\"notrunning\",{\"_index\":42,\"name\":{\"42\":{}},\"comment\":{}}],[\"remove\",{\"_index\":51,\"name\":{\"60\":{}},\"comment\":{}}],[\"requirebackgroundtrackingpermission\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"sdkinitparams\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"setavailability\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"setmetadata\",{\"_index\":12,\"name\":{\"12\":{}},\"comment\":{}}],[\"setname\",{\"_index\":11,\"name\":{\"11\":{}},\"comment\":{}}],[\"starting\",{\"_index\":44,\"name\":{\"45\":{}},\"comment\":{}}],[\"starttracking\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"stoptracking\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"subscribetoavailability\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"subscribetoerrors\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"subscribetotracking\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"subscription\",{\"_index\":50,\"name\":{\"59\":{}},\"comment\":{}}],[\"sync\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"type\",{\"_index\":43,\"name\":{\"44\":{},\"47\":{},\"50\":{},\"54\":{}},\"comment\":{}}],[\"value\",{\"_index\":46,\"name\":{\"51\":{},\"55\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file +window.searchData = JSON.parse("{\"kinds\":{\"8\":\"Enumeration\",\"16\":\"Enumeration Member\",\"128\":\"Class\",\"256\":\"Interface\",\"512\":\"Constructor\",\"1024\":\"Property\",\"2048\":\"Method\",\"65536\":\"Type literal\",\"4194304\":\"Type alias\",\"8388608\":\"Reference\"},\"rows\":[{\"kind\":128,\"name\":\"HyperTrack\",\"url\":\"classes/HyperTrack.html\",\"classes\":\"tsd-kind-class\"},{\"kind\":1024,\"name\":\"locateSubscription\",\"url\":\"classes/HyperTrack.html#locateSubscription\",\"classes\":\"tsd-kind-property tsd-parent-kind-class tsd-is-private\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"addGeotag\",\"url\":\"classes/HyperTrack.html#addGeotag\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getDeviceId\",\"url\":\"classes/HyperTrack.html#getDeviceId\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getErrors\",\"url\":\"classes/HyperTrack.html#getErrors\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getIsAvailable\",\"url\":\"classes/HyperTrack.html#getIsAvailable\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getIsTracking\",\"url\":\"classes/HyperTrack.html#getIsTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getLocation\",\"url\":\"classes/HyperTrack.html#getLocation\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getMetadata\",\"url\":\"classes/HyperTrack.html#getMetadata\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"getName\",\"url\":\"classes/HyperTrack.html#getName\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"locate\",\"url\":\"classes/HyperTrack.html#locate\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setIsAvailable\",\"url\":\"classes/HyperTrack.html#setIsAvailable\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setIsTracking\",\"url\":\"classes/HyperTrack.html#setIsTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setMetadata\",\"url\":\"classes/HyperTrack.html#setMetadata\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"setName\",\"url\":\"classes/HyperTrack.html#setName\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToErrors\",\"url\":\"classes/HyperTrack.html#subscribeToErrors\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToIsAvailable\",\"url\":\"classes/HyperTrack.html#subscribeToIsAvailable\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToIsTracking\",\"url\":\"classes/HyperTrack.html#subscribeToIsTracking\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":2048,\"name\":\"subscribeToLocation\",\"url\":\"classes/HyperTrack.html#subscribeToLocation\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/HyperTrack.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"HyperTrack\"},{\"kind\":8,\"name\":\"HyperTrackError\",\"url\":\"enums/HyperTrackError.html\",\"classes\":\"tsd-kind-enum\"},{\"kind\":16,\"name\":\"blockedFromRunning\",\"url\":\"enums/HyperTrackError.html#blockedFromRunning\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"invalidPublishableKey\",\"url\":\"enums/HyperTrackError.html#invalidPublishableKey\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationMocked\",\"url\":\"enums/HyperTrackError.html#locationMocked\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationServicesDisabled\",\"url\":\"enums/HyperTrackError.html#locationServicesDisabled\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationServicesUnavailable\",\"url\":\"enums/HyperTrackError.html#locationServicesUnavailable\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"locationSignalLost\",\"url\":\"enums/HyperTrackError.html#locationSignalLost\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"noExemptionFromBackgroundStartRestrictions\",\"url\":\"enums/HyperTrackError.html#noExemptionFromBackgroundStartRestrictions\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationDenied\",\"url\":\"enums/HyperTrackError.html#permissionsLocationDenied\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationInsufficientForBackground\",\"url\":\"enums/HyperTrackError.html#permissionsLocationInsufficientForBackground\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationNotDetermined\",\"url\":\"enums/HyperTrackError.html#permissionsLocationNotDetermined\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationProvisional\",\"url\":\"enums/HyperTrackError.html#permissionsLocationProvisional\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationReducedAccuracy\",\"url\":\"enums/HyperTrackError.html#permissionsLocationReducedAccuracy\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsLocationRestricted\",\"url\":\"enums/HyperTrackError.html#permissionsLocationRestricted\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":16,\"name\":\"permissionsNotificationsDenied\",\"url\":\"enums/HyperTrackError.html#permissionsNotificationsDenied\",\"classes\":\"tsd-kind-enum-member tsd-parent-kind-enum\",\"parent\":\"HyperTrackError\"},{\"kind\":4194304,\"name\":\"NotRunning\",\"url\":\"types/NotRunning.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/NotRunning.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"NotRunning\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/NotRunning.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"NotRunning.__type\"},{\"kind\":4194304,\"name\":\"Starting\",\"url\":\"types/Starting.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Starting.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Starting\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Starting.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Starting.__type\"},{\"kind\":4194304,\"name\":\"LocationError\",\"url\":\"types/LocationError.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":4194304,\"name\":\"Errors\",\"url\":\"types/Errors.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Errors.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Errors\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Errors.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Errors.__type\"},{\"kind\":1024,\"name\":\"value\",\"url\":\"types/Errors.html#__type.value\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Errors.__type\"},{\"kind\":4194304,\"name\":\"LocationWithDeviation\",\"url\":\"types/LocationWithDeviation.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/LocationWithDeviation.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"LocationWithDeviation\"},{\"kind\":1024,\"name\":\"location\",\"url\":\"types/LocationWithDeviation.html#__type.location\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"LocationWithDeviation.__type\"},{\"kind\":1024,\"name\":\"deviation\",\"url\":\"types/LocationWithDeviation.html#__type.deviation\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"LocationWithDeviation.__type\"},{\"kind\":4194304,\"name\":\"Location\",\"url\":\"types/Location.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Location.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Location\"},{\"kind\":1024,\"name\":\"latitude\",\"url\":\"types/Location.html#__type.latitude\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type\"},{\"kind\":1024,\"name\":\"longitude\",\"url\":\"types/Location.html#__type.longitude\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Location.__type\"},{\"kind\":4194304,\"name\":\"Result\",\"url\":\"types/Result.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":4194304,\"name\":\"Success\",\"url\":\"types/Success.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Success.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Success\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Success.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Success.__type\"},{\"kind\":1024,\"name\":\"value\",\"url\":\"types/Success.html#__type.value\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Success.__type\"},{\"kind\":4194304,\"name\":\"Failure\",\"url\":\"types/Failure.html\",\"classes\":\"tsd-kind-type-alias\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/Failure.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"Failure\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"types/Failure.html#__type.type\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Failure.__type\"},{\"kind\":1024,\"name\":\"value\",\"url\":\"types/Failure.html#__type.value\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"Failure.__type\"},{\"kind\":256,\"name\":\"Subscription\",\"url\":\"interfaces/Subscription.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"remove\",\"url\":\"interfaces/Subscription.html#remove\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Subscription\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/Subscription.html#remove.__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-property\",\"parent\":\"Subscription.remove\"},{\"kind\":8388608,\"name\":\"default\",\"url\":\"index.html#default\",\"classes\":\"tsd-kind-reference\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,38.14]],[\"comment/0\",[]],[\"name/1\",[1,38.14]],[\"comment/1\",[]],[\"name/2\",[2,38.14]],[\"comment/2\",[]],[\"name/3\",[3,38.14]],[\"comment/3\",[]],[\"name/4\",[4,38.14]],[\"comment/4\",[]],[\"name/5\",[5,38.14]],[\"comment/5\",[]],[\"name/6\",[6,38.14]],[\"comment/6\",[]],[\"name/7\",[7,38.14]],[\"comment/7\",[]],[\"name/8\",[8,38.14]],[\"comment/8\",[]],[\"name/9\",[9,38.14]],[\"comment/9\",[]],[\"name/10\",[10,38.14]],[\"comment/10\",[]],[\"name/11\",[11,38.14]],[\"comment/11\",[]],[\"name/12\",[12,38.14]],[\"comment/12\",[]],[\"name/13\",[13,38.14]],[\"comment/13\",[]],[\"name/14\",[14,38.14]],[\"comment/14\",[]],[\"name/15\",[15,38.14]],[\"comment/15\",[]],[\"name/16\",[16,38.14]],[\"comment/16\",[]],[\"name/17\",[17,38.14]],[\"comment/17\",[]],[\"name/18\",[18,38.14]],[\"comment/18\",[]],[\"name/19\",[19,38.14]],[\"comment/19\",[]],[\"name/20\",[20,38.14]],[\"comment/20\",[]],[\"name/21\",[21,38.14]],[\"comment/21\",[]],[\"name/22\",[22,38.14]],[\"comment/22\",[]],[\"name/23\",[23,38.14]],[\"comment/23\",[]],[\"name/24\",[24,38.14]],[\"comment/24\",[]],[\"name/25\",[25,38.14]],[\"comment/25\",[]],[\"name/26\",[26,38.14]],[\"comment/26\",[]],[\"name/27\",[27,38.14]],[\"comment/27\",[]],[\"name/28\",[28,38.14]],[\"comment/28\",[]],[\"name/29\",[29,38.14]],[\"comment/29\",[]],[\"name/30\",[30,38.14]],[\"comment/30\",[]],[\"name/31\",[31,38.14]],[\"comment/31\",[]],[\"name/32\",[32,38.14]],[\"comment/32\",[]],[\"name/33\",[33,38.14]],[\"comment/33\",[]],[\"name/34\",[34,38.14]],[\"comment/34\",[]],[\"name/35\",[35,38.14]],[\"comment/35\",[]],[\"name/36\",[36,20.794]],[\"comment/36\",[]],[\"name/37\",[37,25.148]],[\"comment/37\",[]],[\"name/38\",[38,38.14]],[\"comment/38\",[]],[\"name/39\",[36,20.794]],[\"comment/39\",[]],[\"name/40\",[37,25.148]],[\"comment/40\",[]],[\"name/41\",[39,38.14]],[\"comment/41\",[]],[\"name/42\",[40,38.14]],[\"comment/42\",[]],[\"name/43\",[36,20.794]],[\"comment/43\",[]],[\"name/44\",[37,25.148]],[\"comment/44\",[]],[\"name/45\",[41,29.667]],[\"comment/45\",[]],[\"name/46\",[42,38.14]],[\"comment/46\",[]],[\"name/47\",[36,20.794]],[\"comment/47\",[]],[\"name/48\",[43,33.032]],[\"comment/48\",[]],[\"name/49\",[44,38.14]],[\"comment/49\",[]],[\"name/50\",[43,33.032]],[\"comment/50\",[]],[\"name/51\",[36,20.794]],[\"comment/51\",[]],[\"name/52\",[45,38.14]],[\"comment/52\",[]],[\"name/53\",[46,38.14]],[\"comment/53\",[]],[\"name/54\",[47,38.14]],[\"comment/54\",[]],[\"name/55\",[48,38.14]],[\"comment/55\",[]],[\"name/56\",[36,20.794]],[\"comment/56\",[]],[\"name/57\",[37,25.148]],[\"comment/57\",[]],[\"name/58\",[41,29.667]],[\"comment/58\",[]],[\"name/59\",[49,38.14]],[\"comment/59\",[]],[\"name/60\",[36,20.794]],[\"comment/60\",[]],[\"name/61\",[37,25.148]],[\"comment/61\",[]],[\"name/62\",[41,29.667]],[\"comment/62\",[]],[\"name/63\",[50,38.14]],[\"comment/63\",[]],[\"name/64\",[51,38.14]],[\"comment/64\",[]],[\"name/65\",[36,20.794]],[\"comment/65\",[]],[\"name/66\",[52,38.14]],[\"comment/66\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":36,\"name\":{\"36\":{},\"39\":{},\"43\":{},\"47\":{},\"51\":{},\"56\":{},\"60\":{},\"65\":{}},\"comment\":{}}],[\"addgeotag\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"blockedfromrunning\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"default\",{\"_index\":52,\"name\":{\"66\":{}},\"comment\":{}}],[\"deviation\",{\"_index\":44,\"name\":{\"49\":{}},\"comment\":{}}],[\"errors\",{\"_index\":40,\"name\":{\"42\":{}},\"comment\":{}}],[\"failure\",{\"_index\":49,\"name\":{\"59\":{}},\"comment\":{}}],[\"getdeviceid\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}],[\"geterrors\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"getisavailable\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"getistracking\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"getlocation\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"getmetadata\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"getname\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"hypertrack\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"hypertrackerror\",{\"_index\":20,\"name\":{\"20\":{}},\"comment\":{}}],[\"invalidpublishablekey\",{\"_index\":22,\"name\":{\"22\":{}},\"comment\":{}}],[\"latitude\",{\"_index\":45,\"name\":{\"52\":{}},\"comment\":{}}],[\"locate\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"locatesubscription\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"location\",{\"_index\":43,\"name\":{\"48\":{},\"50\":{}},\"comment\":{}}],[\"locationerror\",{\"_index\":39,\"name\":{\"41\":{}},\"comment\":{}}],[\"locationmocked\",{\"_index\":23,\"name\":{\"23\":{}},\"comment\":{}}],[\"locationservicesdisabled\",{\"_index\":24,\"name\":{\"24\":{}},\"comment\":{}}],[\"locationservicesunavailable\",{\"_index\":25,\"name\":{\"25\":{}},\"comment\":{}}],[\"locationsignallost\",{\"_index\":26,\"name\":{\"26\":{}},\"comment\":{}}],[\"locationwithdeviation\",{\"_index\":42,\"name\":{\"46\":{}},\"comment\":{}}],[\"longitude\",{\"_index\":46,\"name\":{\"53\":{}},\"comment\":{}}],[\"noexemptionfrombackgroundstartrestrictions\",{\"_index\":27,\"name\":{\"27\":{}},\"comment\":{}}],[\"notrunning\",{\"_index\":35,\"name\":{\"35\":{}},\"comment\":{}}],[\"permissionslocationdenied\",{\"_index\":28,\"name\":{\"28\":{}},\"comment\":{}}],[\"permissionslocationinsufficientforbackground\",{\"_index\":29,\"name\":{\"29\":{}},\"comment\":{}}],[\"permissionslocationnotdetermined\",{\"_index\":30,\"name\":{\"30\":{}},\"comment\":{}}],[\"permissionslocationprovisional\",{\"_index\":31,\"name\":{\"31\":{}},\"comment\":{}}],[\"permissionslocationreducedaccuracy\",{\"_index\":32,\"name\":{\"32\":{}},\"comment\":{}}],[\"permissionslocationrestricted\",{\"_index\":33,\"name\":{\"33\":{}},\"comment\":{}}],[\"permissionsnotificationsdenied\",{\"_index\":34,\"name\":{\"34\":{}},\"comment\":{}}],[\"remove\",{\"_index\":51,\"name\":{\"64\":{}},\"comment\":{}}],[\"result\",{\"_index\":47,\"name\":{\"54\":{}},\"comment\":{}}],[\"setisavailable\",{\"_index\":11,\"name\":{\"11\":{}},\"comment\":{}}],[\"setistracking\",{\"_index\":12,\"name\":{\"12\":{}},\"comment\":{}}],[\"setmetadata\",{\"_index\":13,\"name\":{\"13\":{}},\"comment\":{}}],[\"setname\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"starting\",{\"_index\":38,\"name\":{\"38\":{}},\"comment\":{}}],[\"subscribetoerrors\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"subscribetoisavailable\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"subscribetoistracking\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"subscribetolocation\",{\"_index\":18,\"name\":{\"18\":{}},\"comment\":{}}],[\"subscription\",{\"_index\":50,\"name\":{\"63\":{}},\"comment\":{}}],[\"success\",{\"_index\":48,\"name\":{\"55\":{}},\"comment\":{}}],[\"type\",{\"_index\":37,\"name\":{\"37\":{},\"40\":{},\"44\":{},\"57\":{},\"61\":{}},\"comment\":{}}],[\"value\",{\"_index\":41,\"name\":{\"45\":{},\"58\":{},\"62\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file diff --git a/docs/classes/HyperTrack.html b/docs/classes/HyperTrack.html index 55e52f1..6bf07aa 100644 --- a/docs/classes/HyperTrack.html +++ b/docs/classes/HyperTrack.html @@ -1,4 +1,4 @@ -HyperTrack | HyperTrack Ionic Capacitor SDK API - v1.0.3
+HyperTrack | HyperTrack Ionic Capacitor SDK API - v2.0.0
  • Preparing search index...
  • -
  • The search index is not available
HyperTrack Ionic Capacitor SDK API - v1.0.3
+
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    @@ -25,146 +25,207 @@

    Hierarchy

    -

    Constructors

    -
    - -
    +

    Properties

    +
    + +
    locateSubscription: undefined | Subscription

    Methods

    -
    - +
    +
      - + +
    • +

      Adds a new geotag

      + +

      Returns

      current location if success or LocationError if failure

      +
      +
      +

      Parameters

      +
        +
      • +
        data: Object
        +

        Geotad data JSON

        +
      +

      Returns Promise<Result<Location, LocationError>>

    • +
    • -

      Creates an SDK instance

      +

      Adds a new geotag with expected location

      -

      Returns

      HyperTrack instance

      +

      Returns

      location with deviation if success or LocationError if failure

      Parameters

      • -
        publishableKey: string
        -

        publishable key provided in HyperTrack’s dashboard setup page

        +
        data: Object
        +

        Geotad data JSON

      • -
        sdkInitParams: SdkInitParams = {}
      -

      Returns Promise<HyperTrack>

    +
    expectedLocation: Location
    +

    Expected location

    +
    +

    Returns Promise<Result<LocationWithDeviation, LocationError>>

    - +
    • Returns a string that is used to uniquely identify the device

      + +

      Returns

      Device ID

      Returns Promise<string>

    -
    - +
    +
      - +
    • -

      Reflects availability of the device for the Nearby search

      +

      Returns a list of errors that blocks SDK from tracking

      -

      Returns

      true when is available or false when unavailable

      +

      Returns

      List of errors

      -

      Returns Promise<boolean>

    -
    - +

    Returns Promise<HyperTrackError[]>

    +
    +
      - +
    • -

      Sets the availability of the device for the Nearby search

      +

      Reflects availability of the device for the Nearby search

      + +

      Returns

      true when is available or false when unavailable

      -
      -

      Parameters

      -
        -
      • -
        isAvailable: boolean
      -

      Returns void

    -
    - +

    Returns Promise<boolean>

    +
    +
      - +
    • Reflects the tracking intent for the device

      Returns

      Whether the user's movement data is getting tracked or not.

      Returns Promise<boolean>

    -
    - +
    +
      - +
    • -

      Syncs the device state with the HyperTrack servers

      +

      Reflects the current location of the user or an outage reason

      -

      Returns void

    -
    - +

    Returns Promise<Result<Location, LocationError>>

    +
    +
      - +
    • -

      Expresses an intent to start location tracking for the device

      +

      Gets the metadata that is set for the device

      + +

      Returns

      Metadata JSON

      -

      Returns void

    -
    - +

    Returns Promise<Object>

    +
    +
      - +
    • -

      Stops location tracking immediately

      +

      Gets the name that is set for the device

      + +

      Returns

      Device name

      -

      Returns void

    -
    - +

    Returns Promise<string>

    +
    +
      - +
    • -

      Reflects the current location of the user or an outage reason

      +

      Requests one-time location update and returns the location once it is available, or error.

      +

      Only one locate subscription can be active at a time. If you re-subscribe, the old Subscription +will be automaticaly removed.

      +

      This method will start location tracking if called, and will stop it when the location is received or +the subscription is cancelled. If any other tracking intent is present (e.g. isAvailable is set to true), +the tracking will not be stopped.

      + +

      Returns

      Subscription

      + +

      Example

      const subscription = HyperTrack.locate(location => {
      ...
      })

      // to unsubscribe
      subscription.remove() +
      -

      Returns Promise<Location | LocationError>

    -
    - +
    +

    Parameters

    +
    +

    Returns Subscription

    +
    +
      - +
    • -

      Sets the name for the device

      +

      Sets the availability of the device for the Nearby search

      Parameters

      • -
        name: string
      -

      Returns void

    +
    isAvailable: boolean
    +

    Returns Promise<void>

    +
    + +
      + +
    • +

      Sets the tracking intent for the device

      +
      +
      +

      Parameters

      +
        +
      • +
        isTracking: boolean
      +

      Returns Promise<void>

    - +
      - +
    • Sets the metadata for the device

      @@ -175,68 +236,66 @@

      Parameters

      data: Object

      Metadata JSON

    -

    Returns void

    -
    - +

    Returns Promise<void>

    +
    +
      - +
    • -

      Adds a new geotag

      - -

      Returns

      current location if success or LocationError if failure

      +

      Sets the name for the device

      Parameters

      • -
        data: Object
        -

        Geotad data JSON

        -
      -

      Returns Promise<Location | LocationError>

    -
    - +
    name: string
    +

    Returns Promise<void>

    +
    +
      - +
    • -

      Subscribe to tracking intent changes

      +

      Subscribe to tracking errors

      -

      Returns

      Promise

      +

      Returns

      Subscription

      + +

      Example

      const subscription = HyperTrack.subscribeToErrors(errors => {
      errors.forEach(error => {
      // ... error
      })
      })

      // later, to stop listening
      subscription.remove() +

      Parameters

      • -
        subscriptionFunction: ((isTracking: boolean) => void)
        -

        (isTracking: boolean) => void

        -
        +
        listener: ((errors: HyperTrackError[]) => void)

      Returns void

    -

    Returns Promise<Subscription>

    -
    - +

    Returns Subscription

    +
    +
      - +
    • Subscribe to availability changes

      -

      Returns

      Promise

      +

      Returns

      Subscription

      + +

      Example

      const subscription = HyperTrack.subscribeToIsAvailable(isAvailable => {
      if (isAvailable) {
      // ... ready to go
      }
      })

      // later, to stop listening
      subscription.remove() +

      Parameters

      • -
        subscriptionFunction: ((isAvailable: boolean) => void)
        -

        (isAvailable: boolean) => void

        -
        +
        listener: ((isAvailable: boolean) => void)
          • @@ -248,35 +307,73 @@

            Parameters

          • isAvailable: boolean

      Returns void

    -

    Returns Promise<Subscription>

    -
    - +

    Returns Subscription

    +
    +
      - +
    • -

      Subscribe to tracking errors

      +

      Subscribe to tracking intent changes

      + +

      Returns

      Subscription

      -

      Returns

      Promise

      +

      Example

      const subscription = HyperTrack.subscribeToIsTracking(isTracking => {
      if (isTracking) {
      // ... ready to go
      }
      })

      // later, to stop listening
      subscription.remove() +

      Parameters

      • -
        subscriptionFunction: ((errors: HyperTrackError[]) => void)
        -

        (errors: HyperTrackError[]) => void

        +
        listener: ((isTracking: boolean) => void)
        +
          +
        • +
            +
          • (isTracking: boolean): void
          • +
          • +
            +

            Parameters

            +
              +
            • +
              isTracking: boolean
            +

            Returns void

      +

      Returns Subscription

    +
    + + -

    Returns Promise<Subscription>

    +

    Returns Subscription

    +
    +

    Constructors

    +
    + +
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0

    Enumeration Members

    -
    - -
    gpsSignalLost: "gpsSignalLost"
    +
    + +
    blockedFromRunning: "blockedFromRunning"
    +

    The SDK was remotely blocked from running.

    +
    +
    + +
    invalidPublishableKey: "invalidPublishableKey"
    +

    The publishable key is invalid.

    +
    -
    locationMocked: "locationMocked"
    -
    - -
    locationPermissionsDenied: "locationPermissionsDenied"
    -
    - -
    locationPermissionsInsufficientForBackground: "locationPermissionsInsufficientForBackground"
    -
    - -
    locationPermissionsNotDetermined: "locationPermissionsNotDetermined"
    -
    - -
    locationPermissionsReducedAccuracy: "locationPermissionsReducedAccuracy"
    -
    - -
    locationPermissionsProvisional: "locationPermissionsProvisional"
    -
    - -
    locationPermissionsRestricted: "locationPermissionsRestricted"
    +
    locationMocked: "location.mocked"
    +

    The user enabled mock location app while mocking locations is prohibited.

    +
    -
    locationServicesDisabled: "locationServicesDisabled"
    +
    locationServicesDisabled: "location.servicesDisabled"
    +

    The user disabled location services systemwide.

    +
    -
    locationServicesUnavailable: "locationServicesUnavailable"
    -
    - -
    motionActivityPermissionsNotDetermined: "motionActivityPermissionsNotDetermined"
    -
    - -
    motionActivityPermissionsDenied: "motionActivityPermissionsDenied"
    -
    - -
    motionActivityServicesDisabled: "motionActivityServicesDisabled"
    -
    - -
    motionActivityServicesUnavailable: "motionActivityServicesUnavailable"
    -
    - -
    motionActivityPermissionsRestricted: "motionActivityPermissionsRestricted"
    -
    - -
    networkConnectionUnavailable: "networkConnectionUnavailable"
    -
    - -
    invalidPublishableKey: "invalidPublishableKey"
    -
    - -
    blockedFromRunning: "blockedFromRunning"
    +
    locationServicesUnavailable: "location.servicesUnavailable"
    +

    [Android only] The device doesn't have location services.

    +
    +
    + +
    locationSignalLost: "location.signalLost"
    +

    GPS satellites are not in view.

    +
    +
    + +
    noExemptionFromBackgroundStartRestrictions: "noExemptionFromBackgroundStartRestrictions"
    +

    [Android only] The SDK wasn't able to start tracking because of the limitations imposed by the OS. +The exempt from background execution conditions weren't met. +https://developer.android.com/guide/components/foreground-services#background-start-restriction-exemptions

    +
    +
    + +
    permissionsLocationDenied: "permissions.location.denied"
    +

    The user denied location permissions.

    +
    +
    + +
    permissionsLocationInsufficientForBackground: "permissions.location.insufficientForBackground"
    +

    Can’t start tracking in background with When In Use location permissions. +SDK will automatically start tracking when app will return to foreground.

    +
    +
    + +
    permissionsLocationNotDetermined: "permissions.location.notDetermined"
    +

    [iOS only] The user has not chosen whether the app can use location services.

    +
    +
    + +
    permissionsLocationProvisional: "permissions.location.provisional"
    +

    [iOS only] The app is in Provisional Always authorization state, which stops sending locations when app is in background.

    +
    +
    + +
    permissionsLocationReducedAccuracy: "permissions.location.reducedAccuracy"
    +

    The user didn't grant precise location permissions or downgraded permissions to imprecise.

    +
    +
    + +
    permissionsLocationRestricted: "permissions.location.restricted"
    +

    [iOS only] The app is not authorized to use location services.

    +
    +
    + +
    permissionsNotificationsDenied: "permissions.notifications.denied"
    +

    [Android only] The user denied notification permissions needed to display a persistent notification +needed for foreground location tracking.

    +
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    -

    HyperTrack Ionic Capacitor SDK API - v1.0.3

    +

    HyperTrack Ionic Capacitor SDK API - v2.0.0

    @@ -22,6 +22,10 @@

    Classes

    +

    Interfaces

    +
    +

    Enumerations

    @@ -30,15 +34,14 @@

    Type Aliases

    -

    Interfaces

    -
    -

    References

    @@ -65,18 +68,21 @@

    Theme

    @@ -6,13 +6,13 @@
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    @@ -32,15 +32,15 @@

    Properties

    Properties

    -
    remove: (() => Promise<void>)
    +
    remove: (() => Promise<Object>)

    Type declaration

      • -
      • (): Promise<void>
      • +
      • (): Promise<Object>
      • -

        Returns Promise<void>

    +

    Returns Promise<Object>

    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    Errors: {
        type: "errors";
        value: HyperTrackError[];
    }
    @@ -42,18 +42,21 @@

    Theme

    +
    +
    +
      +
    • Preparing search index...
    • +
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v2.0.0
    +
    +
    +
    + +
    Failure<F>: {
        type: "failure";
        value: F;
    }
    +
    +

    Type Parameters

    +
      +
    • +

      F

    +
    +

    Type declaration

    +
      +
    • +
      type: "failure"
    • +
    • +
      value: F
    +
    +
    \ No newline at end of file diff --git a/docs/types/Location.html b/docs/types/Location.html index 65da154..7657e55 100644 --- a/docs/types/Location.html +++ b/docs/types/Location.html @@ -1,4 +1,4 @@ -Location | HyperTrack Ionic Capacitor SDK API - v1.0.3
    +Location | HyperTrack Ionic Capacitor SDK API - v2.0.0
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3
    +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    -
    Location: {
        type: "location";
        value: {
            latitude: number;
            longitude: number;
        };
    }
    +
    Location: {
        latitude: number;
        longitude: number;
    }

    Type declaration

    • -
      type: "location"
    • -
    • -
      value: {
          latitude: number;
          longitude: number;
      }
      -
        -
      • latitude: number
      • -
        longitude: number
    +
    longitude: number
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    @@ -35,18 +35,21 @@

    Theme

    @@ -6,25 +6,23 @@
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    -
    SdkInitParams: {
        loggingEnabled?: boolean;
        allowMockLocations?: boolean;
        requireBackgroundTrackingPermission?: boolean;
    }
    +
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
  • +
  • LocationWithDeviation
  • +

    Type alias LocationWithDeviation

    +
    LocationWithDeviation: {
        location: Location;
        deviation: number;
    }

    Type declaration

    • -
      Optional loggingEnabled?: boolean
    • +
      location: Location
    • -
      Optional allowMockLocations?: boolean
    • -
    • -
      Optional requireBackgroundTrackingPermission?: boolean
    +
    deviation: number
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3 +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    NotRunning: {
        type: "notRunning";
    }
    @@ -40,18 +40,21 @@

    Theme

    +
    +
    +
      +
    • Preparing search index...
    • +
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v2.0.0
    +
    +
    +
    + +
    Result<S, F>: Success<S> | Failure<F>
    +
    +

    Type Parameters

    +
      +
    • +

      S

    • +
    • +

      F

    +
    +
    \ No newline at end of file diff --git a/docs/types/Starting.html b/docs/types/Starting.html index f3e8183..f092b44 100644 --- a/docs/types/Starting.html +++ b/docs/types/Starting.html @@ -1,4 +1,4 @@ -Starting | HyperTrack Ionic Capacitor SDK API - v1.0.3
    +Starting | HyperTrack Ionic Capacitor SDK API - v2.0.0
    • Preparing search index...
    • -
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v1.0.3
    +
  • The search index is not available
  • HyperTrack Ionic Capacitor SDK API - v2.0.0
    Starting: {
        type: "starting";
    }
    @@ -40,18 +40,21 @@

    Theme

    +
    +
    +
      +
    • Preparing search index...
    • +
    • The search index is not available
    HyperTrack Ionic Capacitor SDK API - v2.0.0
    +
    +
    +
    + +
    Success<S>: {
        type: "success";
        value: S;
    }
    +
    +

    Type Parameters

    +
      +
    • +

      S

    +
    +

    Type declaration

    +
      +
    • +
      type: "success"
    • +
    • +
      value: S
    +
    +
    \ No newline at end of file diff --git a/ios/Plugin/HyperTrackCapacitorPlugin.m b/ios/Plugin/HyperTrackCapacitorPlugin.m index b19b632..9a134fd 100644 --- a/ios/Plugin/HyperTrackCapacitorPlugin.m +++ b/ios/Plugin/HyperTrackCapacitorPlugin.m @@ -4,19 +4,21 @@ // Define the plugin using the CAP_PLUGIN Macro, and // each method the plugin supports using the CAP_PLUGIN_METHOD macro. CAP_PLUGIN(HyperTrackCapacitorPlugin, "HyperTrackCapacitorPlugin", - CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(addGeotag, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getDeviceId, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getErrors, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getIsAvailable, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getIsTracking, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getLocation, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(startTracking, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(stopTracking, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setAvailability, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getMetadata, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getName, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(setIsAvailable, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(setIsTracking, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(setMetadata, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(setName, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(isTracking, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(isAvailable, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(addGeotag, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(sync, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(onSubscribedToTracking, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(onSubscribedToAvailability, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(onSubscribedToErrors, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(onSubscribedToIsAvailable, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(onSubscribedToIsTracking, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(onSubscribedToLocate, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(onSubscribedToLocation, CAPPluginReturnPromise); ) diff --git a/ios/Plugin/HyperTrackCapacitorPlugin.swift b/ios/Plugin/HyperTrackCapacitorPlugin.swift index eebcb4c..c7c36e5 100644 --- a/ios/Plugin/HyperTrackCapacitorPlugin.swift +++ b/ios/Plugin/HyperTrackCapacitorPlugin.swift @@ -1,31 +1,41 @@ -import Foundation import Capacitor +import Foundation import HyperTrack +/// HyperTrack Capacitor Plugin +/// +/// The HypertrackSdkIonicCapacitor is a Swift module name to access HyperTrackSDKWrapper +/// methods. @objc(HyperTrackCapacitorPlugin) public class HyperTrackCapacitorPlugin: CAPPlugin { - - private let eventTracking = "onTrackingChanged" - private let eventAvailability = "onAvailabilityChanged" - private let eventErrors = "onError" - - private var isTrackingSubscription: HyperTrack.Cancellable! - private var availabilitySubscription: HyperTrack.Cancellable! + private let eventErrors = "errors" + private let eventIsTracking = "isTracking" + private let eventIsAvailable = "isAvailable" + private let eventLocate = "locate" + private let eventLocation = "location" + private var errorsSubscription: HyperTrack.Cancellable! - - @objc func initialize(_ call: CAPPluginCall) { + private var isTrackingSubscription: HyperTrack.Cancellable! + private var isAvailableSubscription: HyperTrack.Cancellable! + private var locationSubscription: HyperTrack.Cancellable! + + private var locateSubscription: HyperTrack.Cancellable? = nil + + override required init(bridge: CAPBridgeProtocol, pluginId: String, pluginName: String) { + super.init(bridge: bridge, pluginId: pluginId, pluginName: pluginName) + initListeners() + } + + @objc func addGeotag(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.initializeSDK( - call.options as! Dictionary - ).map({ (result:SuccessResult) in - initListeners() - return result - }), - method: .initialize, + HypertrackSdkIonicCapacitor.addGeotag( + call.options as! [String: Any] + ), + method: .addGeotag, call ) } - + @objc func getDeviceId(_ call: CAPPluginCall) { sendAsPromise( HypertrackSdkIonicCapacitor.getDeviceID(), @@ -33,134 +43,165 @@ public class HyperTrackCapacitorPlugin: CAPPlugin { call ) } - - @objc func getLocation(_ call: CAPPluginCall) { + + @objc func getErrors(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.getLocation(), - method: .getLocation, + HypertrackSdkIonicCapacitor.getErrors().map { errors in + switch errors { + case .void: + preconditionFailure("Unexpected void result") + case let .dict(value): + preconditionFailure("Unexpected dict result: \(value)") + case let .array(errors): + return .dict(serializeErrorsForPlugin(errors as! [[String: Any]])) + } + }, + method: .getErrors, call ) } - - @objc func startTracking(_ call: CAPPluginCall) { + + @objc func getIsAvailable(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.startTracking(), - method: .startTracking, + HypertrackSdkIonicCapacitor.getIsAvailable(), + method: .getIsAvailable, call ) } - - @objc func stopTracking(_ call: CAPPluginCall) { + + @objc func getIsTracking(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.stopTracking(), - method: .stopTracking, + HypertrackSdkIonicCapacitor.getIsTracking(), + method: .getIsTracking, call ) } - - @objc func setAvailability(_ call: CAPPluginCall) { + + @objc func getLocation(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.setAvailability( - call.options as! Dictionary - ), - method: .setAvailability, + HypertrackSdkIonicCapacitor.getLocation(), + method: .getLocation, call ) } - - @objc func setName(_ call: CAPPluginCall) { + + @objc func getMetadata(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.setName( - call.options as! Dictionary - ), - method: .setName, + HypertrackSdkIonicCapacitor.getMetadata(), + method: .getMetadata, call ) } - - @objc func setMetadata(_ call: CAPPluginCall) { + + @objc func getName(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.setMetadata( - call.options as! Dictionary - ), - method: .setMetadata, + HypertrackSdkIonicCapacitor.getName(), + method: .getName, call ) } - - @objc func isTracking(_ call: CAPPluginCall) { + + @objc func setIsAvailable(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.isTracking(), - method: .isTracking, + HypertrackSdkIonicCapacitor.setIsAvailable( + call.options as! [String: Any] + ), + method: .setIsAvailable, call ) } - - @objc func isAvailable(_ call: CAPPluginCall) { + + @objc func setIsTracking(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.isAvailable(), - method: .isAvailable, + HypertrackSdkIonicCapacitor.setIsTracking( + call.options as! [String: Any] + ), + method: .setIsTracking, call ) } - - @objc func addGeotag(_ call: CAPPluginCall) { + + @objc func setMetadata(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.addGeotag( - call.options as! Dictionary + HypertrackSdkIonicCapacitor.setMetadata( + call.options as! [String: Any] ), - method: .addGeotag, + method: .setMetadata, call ) } - - @objc func sync(_ call: CAPPluginCall) { + + @objc func setName(_ call: CAPPluginCall) { sendAsPromise( - HypertrackSdkIonicCapacitor.sync(), - method: .sync, + HypertrackSdkIonicCapacitor.setName( + call.options as! [String: Any] + ), + method: .setName, call ) } - - @objc func onSubscribedToTracking(_ call: CAPPluginCall) { - sendTrackingEvent(isTracking: sdkInstance.isTracking) + + @objc func onSubscribedToErrors(_: CAPPluginCall) { + sendErrorsEvent(HyperTrack.errors) + } + + @objc func onSubscribedToIsTracking(_: CAPPluginCall) { + sendIsTrackingEvent(isTracking: HyperTrack.isTracking) + } + + @objc func onSubscribedToIsAvailable(_: CAPPluginCall) { + sendIsAvailableEvent(isAvailable: HyperTrack.isAvailable) } - - @objc func onSubscribedToAvailability(_ call: CAPPluginCall) { - sendAvailabilityEvent(availability: sdkInstance.availability) + + @objc func onSubscribedToLocate(_: CAPPluginCall) { + locateSubscription?.cancel() + locateSubscription = HyperTrack.locate { locateResult in + self.sendLocateEvent(locateResult) + } } - - @objc func onSubscribedToErrors(_ call: CAPPluginCall) { - sendErrorsEvent(sdkInstance.errors) + + @objc func onSubscribedToLocation(_: CAPPluginCall) { + sendLocationEvent(HyperTrack.location) } - + private func initListeners() { - isTrackingSubscription = sdkInstance.subscribeToIsTracking(callback: { isTracking in - self.sendTrackingEvent(isTracking: isTracking) - }) - availabilitySubscription = sdkInstance.subscribeToAvailability(callback: { availability in - self.sendAvailabilityEvent(availability: availability) - }) - errorsSubscription = sdkInstance.subscribeToErrors { errors in + errorsSubscription = HyperTrack.subscribeToErrors { errors in self.sendErrorsEvent(errors) } + isAvailableSubscription = HyperTrack.subscribeToIsAvailable { isAvailable in + self.sendIsAvailableEvent(isAvailable: isAvailable) + } + isTrackingSubscription = HyperTrack.subscribeToIsTracking { isTracking in + self.sendIsTrackingEvent(isTracking: isTracking) + } + locationSubscription = HyperTrack.subscribeToLocation { location in + self.sendLocationEvent(location) + } + } + + private func sendErrorsEvent(_ errors: Set) { + notifyListeners(eventErrors, data: serializeErrorsForPlugin(serializeErrors(errors))) } - - private func sendTrackingEvent(isTracking: Bool) { - notifyListeners(eventTracking, data: serializeIsTracking(isTracking)) + + private func sendIsAvailableEvent(isAvailable: Bool) { + notifyListeners(eventIsAvailable, data: serializeIsAvailable(isAvailable)) } - private func sendAvailabilityEvent(availability: HyperTrack.Availability) { - notifyListeners(eventAvailability, data: serializeIsAvailable(availability)) + + private func sendIsTrackingEvent(isTracking: Bool) { + notifyListeners(eventIsTracking, data: serializeIsTracking(isTracking)) } - - private func sendErrorsEvent(_ errors: Set) { - notifyListeners(eventErrors, data: serializeErrorsForPlugin(serializeErrors(errors))) + + private func sendLocateEvent(_ locateResult: Result>) { + notifyListeners(eventLocate, data: serializeLocateResult(locateResult)) + } + + private func sendLocationEvent(_ locationResult: Result) { + notifyListeners(eventLocation, data: serializeLocationResult(locationResult)) } - - private func serializeErrorsForPlugin(_ errors: Array>) -> Dictionary { + + private func serializeErrorsForPlugin(_ errors: [[String: Any]]) -> [String: Any] { return ["errors": errors] } - } private func sendAsPromise( @@ -169,22 +210,24 @@ private func sendAsPromise( _ call: CAPPluginCall ) { switch result { - case .success(let success): - switch (success) { + case let .success(success): + switch success { case .void: call.resolve([:]) - case .dict(let value): + case let .dict(value): call.resolve(value) + case .array: + preconditionFailure("Arrays params are not supported in Capacitor") } - case .failure(let failure): - switch(failure) { - case .error(let message): + case let .failure(failure): + switch failure { + case let .error(message): call.reject( "\(method.rawValue): \(message)", nil, nil ) - case .fatalError(let message): + case let .fatalError(message): preconditionFailure(message) } } diff --git a/ios/Plugin/common/DictionaryDecoder.swift b/ios/Plugin/common/DictionaryDecoder.swift index 542b61c..a9245a2 100644 --- a/ios/Plugin/common/DictionaryDecoder.swift +++ b/ios/Plugin/common/DictionaryDecoder.swift @@ -1,26 +1,26 @@ class DictionaryDecoder { private let decoder = JSONDecoder() - + var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy { set { decoder.dateDecodingStrategy = newValue } get { decoder.dateDecodingStrategy } } - + var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy { set { decoder.dataDecodingStrategy = newValue } get { decoder.dataDecodingStrategy } } - + var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy { set { decoder.nonConformingFloatDecodingStrategy = newValue } get { decoder.nonConformingFloatDecodingStrategy } } - + var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy { set { decoder.keyDecodingStrategy = newValue } get { decoder.keyDecodingStrategy } } - + func decode(_ type: T.Type, from dictionary: [String: Any]) throws -> T where T: Decodable { let data = try JSONSerialization.data(withJSONObject: dictionary, options: []) return try decoder.decode(type, from: data) diff --git a/ios/Plugin/common/GeotagData.swift b/ios/Plugin/common/GeotagData.swift new file mode 100644 index 0000000..04dbe9f --- /dev/null +++ b/ios/Plugin/common/GeotagData.swift @@ -0,0 +1,11 @@ +import HyperTrack + +struct GeotagData { + let data: [String: Any] + let expectedLocation: HyperTrack.Location? + + init(data: [String: Any], expectedLocation: HyperTrack.Location?) { + self.data = data + self.expectedLocation = expectedLocation + } +} diff --git a/ios/Plugin/common/HyperTrackError.swift b/ios/Plugin/common/HyperTrackError.swift deleted file mode 100644 index 4392042..0000000 --- a/ios/Plugin/common/HyperTrackError.swift +++ /dev/null @@ -1,20 +0,0 @@ -enum HyperTrackError: String { - case gpsSignalLost - case locationMocked - case locationPermissionsDenied - case locationPermissionsInsufficientForBackground - case locationPermissionsNotDetermined - case locationPermissionsReducedAccuracy - case locationPermissionsProvisional - case locationPermissionsRestricted - case locationServicesDisabled - case locationServicesUnavailable - case motionActivityPermissionsNotDetermined - case motionActivityPermissionsDenied - case motionActivityServicesDisabled - case motionActivityServicesUnavailable - case motionActivityPermissionsRestricted - case networkConnectionUnavailable - case invalidPublishableKey - case blockedFromRunning -} diff --git a/ios/Plugin/common/HyperTrackSDKWrapper.swift b/ios/Plugin/common/HyperTrackSDKWrapper.swift index a40b929..edde36a 100644 --- a/ios/Plugin/common/HyperTrackSDKWrapper.swift +++ b/ios/Plugin/common/HyperTrackSDKWrapper.swift @@ -2,7 +2,8 @@ import HyperTrack enum SuccessResult { case void - case dict(Dictionary) + case dict([String: Any]) + case array([Any]) } enum FailureResult: Error { @@ -10,110 +11,81 @@ enum FailureResult: Error { case error(_ message: String) } -var sdkInstance: HyperTrack! // initialize method is guaranteed to be called (by non-native side) prior to any access to the SDK instance - -// method is named 'initializeSDK' to avoid conflict with React Native plugin 'initialize' method -func initializeSDK( - _ params: Dictionary -) -> Result { - if let sdkInitParams = SDKInitParams(params) { - let publishableKey = HyperTrack.PublishableKey(params["publishableKey"] as! String) - if let publishableKey = publishableKey { - switch HyperTrack.makeSDK( - publishableKey: publishableKey, - mockLocationsAllowed: sdkInitParams.allowMockLocations - ) { - case let .success(hyperTrack): - sdkInstance = hyperTrack - HyperTrack.isLoggingEnabled = sdkInitParams.loggingEnabled - return .success(.void) - case let .failure(fatalError): - return .failure(mapFatalError(fatalError: fatalError)) +func addGeotag(_ args: [String: Any]) -> Result { + return deserializeGeotagData(args).flatMap { geotagData in + if let metadata: HyperTrack.JSON.Object = toJSON(geotagData.data) { + if let expectedLocation = geotagData.expectedLocation { + let result = HyperTrack.addGeotag(metadata, expectedLocation: expectedLocation) + return .success(.dict(serializeLocationWithDeviationResult(result))) + } else { + let result = HyperTrack.addGeotag(metadata) + return .success(.dict(serializeLocationResult(result))) } } else { - return .failure(.fatalError("Invalid publishable key")) + return .failure(.error("Failed to deserialize geotag metadata")) } - } else { - return .failure(.error("Invalid SDK init parameters \(params)")) } } func getDeviceID() -> Result { - .success(.dict(serializeDeviceID(sdkInstance.deviceID))) + .success(.dict(serializeDeviceID(HyperTrack.deviceID))) } -func getLocation() -> Result { - .success(.dict(serializeLocationResult(sdkInstance.location))) +func getErrors() -> Result { + .success(.array(serializeErrors(HyperTrack.errors))) } -func startTracking() -> Result { - .success(asVoid(sdkInstance.start())) +func getMetadata() -> Result { + .success(.dict(serializeMetadata(HyperTrack.metadata))) } -func stopTracking() -> Result { - .success(asVoid(sdkInstance.stop())) +func getName() -> Result { + .success(.dict(serializeName(HyperTrack.name))) } -func setAvailability( - _ availability: Dictionary -) -> Result { - deserializeAvailability(availability).flatMap { (isAvailable:Bool) in - if(isAvailable) { - sdkInstance.availability = .available - } else { - sdkInstance.availability = .unavailable - } - return .success(.void) - } +func getLocation() -> Result { + .success(.dict(serializeLocationResult(HyperTrack.location))) } -func setName(_ args: Dictionary) -> Result { - deserializeDeviceName(args).flatMap({ (name: String) in - .success(asVoid(sdkInstance.setDeviceName(name))) - }) +func getIsAvailable() -> Result { + .success(.dict(serializeIsAvailable(HyperTrack.isAvailable))) } -func setMetadata(_ map: Dictionary) -> Result { - sdkInstance.metadata = getJSON(map) - return .success(.void) +func setIsAvailable(_ args: [String: Any]) -> Result { + deserializeIsAvailable(args).flatMap { (isAvailable: Bool) in + HyperTrack.isAvailable = isAvailable + return .success(.void) + } } -func isTracking() -> Result { - .success(.dict(serializeIsTracking(sdkInstance.isTracking))) +func getIsTracking() -> Result { + .success(.dict(serializeIsTracking(HyperTrack.isTracking))) } -func isAvailable() -> Result { - .success(.dict(serializeIsAvailable(sdkInstance.availability))) +func setIsTracking(_ args: [String: Any]) -> Result { + deserializeIsTracking(args).flatMap { (isTracking: Bool) in + HyperTrack.isTracking = isTracking + return .success(.void) + } } -func addGeotag(_ args: Dictionary) -> Result { - return deserializeGeotagData(args).flatMap { data in - let metadata: HyperTrack.JSON.Object = getJSON(data) - let result = sdkInstance.addGeotag(metadata) - return .success(.dict(serializeLocationResult(result))) +func setMetadata(_ args: [String: Any]) -> Result { + deserializeMetadata(args).flatMap { map in + if let metadata = toJSON(map) { + HyperTrack.metadata = metadata + return .success(.void) + } else { + return .failure(.error("Failed to deserialize metadata")) + } } } -func sync() -> Result { - .success(asVoid(sdkInstance.syncDeviceSettings())) +func setName(_ args: [String: Any]) -> Result { + deserializeName(args).flatMap { name in + .success(asVoid(HyperTrack.name = name)) + } } -func asVoid(_ void: Void) -> SuccessResult { +func asVoid(_: Void) -> SuccessResult { .void } - -private func mapFatalError(fatalError: HyperTrack.FatalError) -> FailureResult { - switch fatalError { - case .developmentError(.missingLocationUpdatesBackgroundModeCapability): - return .fatalError("missingLocationUpdatesBackgroundModeCapability") - case .developmentError(.runningOnSimulatorUnsupported): - return .fatalError("runningOnSimulatorUnsupported") - // typo is in the HyperTrack SDK itself, no need to fix (it will be deleted in the next major update) - case .productionError(.locationServicesUnavalible): - return .error("locationServicesUnavalible") - case .productionError(.motionActivityServicesUnavalible): - return .error("motionActivityServicesUnavalible") - case .productionError(.motionActivityPermissionsDenied): - return .fatalError("motionActivityPermissionsDenied") - } -} diff --git a/ios/Plugin/common/SDKInitParams.swift b/ios/Plugin/common/SDKInitParams.swift deleted file mode 100644 index 4eb4b01..0000000 --- a/ios/Plugin/common/SDKInitParams.swift +++ /dev/null @@ -1,11 +0,0 @@ -public struct SDKInitParams { - let publishableKey: String - let loggingEnabled: Bool - let allowMockLocations: Bool - - init?(_ map: Dictionary) { - self.publishableKey = (map["publishableKey"] as! String) - self.loggingEnabled = (map["loggingEnabled"] as! Bool) - self.allowMockLocations = (map["allowMockLocations"] as! Bool) - } -} diff --git a/ios/Plugin/common/SDKMethod.swift b/ios/Plugin/common/SDKMethod.swift index 5f0e602..a8b3c41 100644 --- a/ios/Plugin/common/SDKMethod.swift +++ b/ios/Plugin/common/SDKMethod.swift @@ -1,14 +1,15 @@ enum SDKMethod: String { - case initialize = "initialize" - case getDeviceID = "getDeviceID" - case getLocation = "getLocation" - case startTracking = "startTracking" - case stopTracking = "stopTracking" - case setAvailability = "setAvailability" - case setName = "setName" - case setMetadata = "setMetadata" - case isTracking = "isTracking" - case isAvailable = "isAvailable" - case addGeotag = "addGeotag" - case sync = "sync" + case addGeotag + case getDeviceID + case getErrors + case getIsAvailable + case getIsTracking + case getLocation + case getMetadata + case getName + case locate + case setIsAvailable + case setIsTracking + case setMetadata + case setName } diff --git a/ios/Plugin/common/Serialization.swift b/ios/Plugin/common/Serialization.swift index 8ed558a..aa81d0a 100644 --- a/ios/Plugin/common/Serialization.swift +++ b/ios/Plugin/common/Serialization.swift @@ -1,268 +1,302 @@ import HyperTrack +private let keyExpectedLocation = "expectedLocation" +private let keyGeotagData = "data" private let keyType = "type" private let keyValue = "value" -private let typeSuccess = "success" +private let typeError = "error" private let typeFailure = "failure" -private let typeHyperTrackError = "hyperTrackError" -private let typeIsTracking = "isTracking" private let typeIsAvailable = "isAvailable" +private let typeIsTracking = "isTracking" +private let typeLocation = "location" +private let typeMetadata = "metadata" +private let typeName = "name" +private let typeSuccess = "success" -let keyGeotagData = "data" +func deserializeGeotagData( + _ args: [String: Any] +) -> Result { + guard let data = args[keyGeotagData] as? [String: Any] else { + return .failure(.fatalError(getParseError(args, key: keyGeotagData))) + } + if let expectedLocationData = args[keyExpectedLocation] as? [String: Any] { + let expectedLocation = deserializeLocation(expectedLocationData) + switch expectedLocation { + case let .failure(failure): + return .failure(failure) + case let .success(expectedLocation): + return .success(.init(data: data, expectedLocation: expectedLocation)) + } + } else { + return .success(.init(data: data, expectedLocation: nil)) + } +} -func getJSON(_ dictionary: Dictionary) -> HyperTrack.JSON.Object { - return try! DictionaryDecoder().decode(HyperTrack.JSON.Object.self, from: dictionary) +func deserializeIsAvailable(_ data: [String: Any]) -> Result { + if data[keyType] as? String != typeIsAvailable { + return .failure(.fatalError(getParseError(data, key: keyType))) + } + guard let value = data[keyValue] as? Bool else { + return .failure(.fatalError(getParseError(data, key: keyValue))) + } + return .success(value) } -func getHyperTrackError(_ error: HyperTrack.UnrestorableError) -> HyperTrackError { - switch(error) { - case .invalidPublishableKey: - return HyperTrackError.invalidPublishableKey - case .motionActivityPermissionsDenied: - return HyperTrackError.locationPermissionsDenied +func deserializeIsTracking(_ data: [String: Any]) -> Result { + if data[keyType] as? String != typeIsTracking { + return .failure(.fatalError(getParseError(data, key: keyType))) + } + guard let value = data[keyValue] as? Bool else { + return .failure(.fatalError(getParseError(data, key: keyValue))) } + return .success(value) } -func getHyperTrackError(_ error: HyperTrack.RestorableError) -> HyperTrackError { - switch(error) { - case .locationPermissionsNotDetermined: - return HyperTrackError.locationPermissionsNotDetermined - case .motionActivityPermissionsNotDetermined: - return HyperTrackError.motionActivityPermissionsNotDetermined - case .locationPermissionsCantBeAskedInBackground: - return HyperTrackError.locationPermissionsNotDetermined - case .motionActivityPermissionsCantBeAskedInBackground: - return HyperTrackError.motionActivityPermissionsNotDetermined - case .locationPermissionsRestricted: - return HyperTrackError.locationPermissionsRestricted - case .motionActivityPermissionsRestricted: - return HyperTrackError.motionActivityPermissionsRestricted - case .locationPermissionsDenied: - return HyperTrackError.locationPermissionsDenied - case .locationPermissionsInsufficientForBackground: - return HyperTrackError.locationPermissionsInsufficientForBackground - case .locationServicesDisabled: - return HyperTrackError.locationServicesDisabled - case .motionActivityServicesDisabled: - return HyperTrackError.motionActivityServicesDisabled - case .networkConnectionUnavailable: - return HyperTrackError.networkConnectionUnavailable - case .trialEnded: - return HyperTrackError.blockedFromRunning - case .paymentDefault: - return HyperTrackError.blockedFromRunning +func deserializeLocation(_ data: [String: Any]) -> Result { + if data[keyType] as? String != typeLocation { + return .failure(.fatalError(getParseError(data, key: keyType))) + } + guard let value = data[keyValue] as? [String: Any] else { + return .failure(.fatalError(getParseError(data, key: keyValue))) + } + guard let latitude = value["latitude"] as? Double else { + return .failure(.fatalError(getParseError(value, key: "latitude"))) + } + guard let longitude = value["longitude"] as? Double else { + return .failure(.fatalError(getParseError(value, key: "longitude"))) } + return .success(.init(latitude: latitude, longitude: longitude)) } -func getHyperTrackError(_ error: HyperTrack.HyperTrackError) -> HyperTrackError { - switch(error) { - case .locationPermissionsNotDetermined: - return .locationPermissionsNotDetermined - case .locationPermissionsInsufficientForBackground: - return .locationPermissionsInsufficientForBackground - case .locationPermissionsRestricted: - return .locationPermissionsRestricted - case .locationPermissionsReducedAccuracy: - return .locationPermissionsReducedAccuracy - case .locationPermissionsProvisional: - return .locationPermissionsProvisional - case .locationPermissionsDenied: - return .locationPermissionsDenied - case .locationServicesDisabled: - return .locationServicesDisabled - case .motionActivityPermissionsNotDetermined: - return .motionActivityPermissionsNotDetermined - case .motionActivityPermissionsDenied: - return .motionActivityPermissionsDenied - case .motionActivityServicesDisabled: - return .motionActivityServicesDisabled - case .motionActivityServicesUnavailable: - return .motionActivityServicesUnavailable - case .gpsSignalLost: - return .gpsSignalLost - case .locationMocked: - return .locationMocked - case .invalidPublishableKey: - return .invalidPublishableKey - case .blockedFromRunning: - return .blockedFromRunning - default: - preconditionFailure("Unknown error \(error)") +func deserializeMetadata(_ data: [String: Any]) -> Result<[String: Any], FailureResult> { + if data[keyType] as? String != typeMetadata { + return .failure(.fatalError(getParseError(data, key: keyType))) } + guard let value = data[keyValue] as? [String: Any] else { + return .failure(.fatalError(getParseError(data, key: keyValue))) + } + return .success(value) } -func serializeErrors(_ errors: Set) -> Array> { - return errors.map({ error in - serializeHyperTrackError(getHyperTrackError(error)) - }) +func deserializeName(_ data: [String: Any]) -> Result { + if data[keyType] as? String != typeName { + return .failure(.fatalError(getParseError(data, key: keyType))) + } + guard let value = data[keyValue] as? String else { + return .failure(.fatalError(getParseError(data, key: keyValue))) + } + return .success(value) } -func serializeDeviceID(_ deviceID: String) -> Dictionary { +func serializeDeviceID(_ deviceID: String) -> [String: Any] { return [ keyType: "deviceID", - keyValue: deviceID + keyValue: deviceID, + ] +} + +func serializeError(_ error: HyperTrack.Error) -> [String: Any] { + let value: String + switch error { + case .blockedFromRunning: + value = "blockedFromRunning" + case .invalidPublishableKey: + value = "invalidPublishableKey" + case let .location(location): + switch location { + case .mocked: + value = "location.mocked" + case .servicesDisabled: + value = "location.servicesDisabled" + case .signalLost: + value = "location.signalLost" + } + case let .permissions(permissionType): + switch permissionType { + case let .location(permission): + switch permission { + case .denied: + value = "permissions.location.denied" + case .insufficientForBackground: + value = "permissions.location.insufficientForBackground" + case .notDetermined: + value = "permissions.location.notDetermined" + case .provisional: + value = "permissions.location.provisional" + case .reducedAccuracy: + value = "permissions.location.reducedAccuracy" + case .restricted: + value = "permissions.location.restricted" + } + } + } + + return [ + keyType: typeError, + keyValue: value, + ] +} + +func serializeIsAvailable(_ isAvailable: Bool) -> [String: Any] { + return [ + keyType: typeIsAvailable, + keyValue: isAvailable, ] } -func serializeLocationResult(_ result: Result) -> Dictionary { - switch (result) { - case .success(let success): +func serializeIsTracking(_ isTracking: Bool) -> [String: Any] { + return [ + keyType: typeIsTracking, + keyValue: isTracking, + ] +} + +func serializeLocateResult(_ locateResult: Result>) -> [String: Any] { + switch locateResult { + case let .success(success): return [ keyType: typeSuccess, - keyValue: [ - keyType: "location", - keyValue: [ - "latitude": success.latitude, - "longitude": success.longitude - ] - ] + keyValue: serializeLocation(success), ] - case .failure(let failure): - var locationError: Dictionary - switch(failure) { - case .locationPermissionsNotDetermined: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsNotDetermined) - case .locationPermissionsCantBeAskedInBackground: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsNotDetermined) - case .locationPermissionsInsufficientForBackground: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsInsufficientForBackground) - case .locationPermissionsRestricted: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsRestricted) - case .locationPermissionsReducedAccuracy: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsReducedAccuracy) - case .locationPermissionsDenied: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationPermissionsDenied) - case .locationServicesDisabled: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationServicesDisabled) - case .motionActivityPermissionsNotDetermined: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.motionActivityPermissionsNotDetermined) - case .motionActivityPermissionsCantBeAskedInBackground: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.motionActivityPermissionsNotDetermined) - case .motionActivityPermissionsDenied: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.motionActivityPermissionsDenied) - case .motionActivityServicesDisabled: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.motionActivityServicesDisabled) - case .gpsSignalLost: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.gpsSignalLost) - case .locationMocked: - locationError = serializeHyperTrackErrorAsLocationError(HyperTrackError.locationMocked) - case .starting: - locationError = [ - keyType: "starting" - ] - case .notRunning: - locationError = [ - keyType: "notRunning" - ] - } + case let .failure(failure): return [ keyType: typeFailure, - keyValue: locationError + keyValue: serializeErrors(failure), + ] + } +} + +func serializeLocation(_ location: HyperTrack.Location) -> [String: Any] { + return [ + keyType: typeLocation, + keyValue: [ + "latitude": location.latitude, + "longitude": location.longitude, + ], + ] +} + +func serializeLocationError(_ error: HyperTrack.Location.Error) -> [String: Any] { + switch error { + case .starting: + return [ + keyType: "starting", + ] + case .notRunning: + return [ + keyType: "notRunning", + ] + case let .errors(errors): + return [ + keyType: "errors", + keyValue: serializeErrors(errors), ] } } -func serializeLocationResult(_ result: Result) -> Dictionary { - switch (result) { - case .success(let success): +func serializeLocationResult(_ result: Result) -> [String: Any] { + switch result { + case let .success(success): return [ keyType: typeSuccess, - keyValue: [ - keyType: "location", - keyValue: [ - "latitude": success.latitude, - "longitude": success.longitude - ] - ] + keyValue: serializeLocation(success), ] - case .failure(let failure): - var locationError: Dictionary - switch(failure) { - case .starting: - locationError = [ - keyType: "starting" - ] - case .notRunning: - locationError = [ - keyType: "notRunning" - ] - case .errors(let errors): - locationError = [ - keyType: "errors", - keyValue: serializeErrors(errors) - ] - } - + case let .failure(failure): return [ keyType: typeFailure, - keyValue: locationError + keyValue: serializeLocationError(failure), ] } } -func serializeHyperTrackErrorAsLocationError(_ error: HyperTrackError) -> Dictionary { +func serializeLocationWithDeviation( + _ locationWithDeviation: HyperTrack.LocationWithDeviation +) -> [String: Any] { return [ - keyType: "errors", - keyValue: [ - [ - keyType: typeHyperTrackError, - keyValue: error.rawValue - ] - ] + "location": serializeLocation(locationWithDeviation.location), + "deviation": locationWithDeviation.deviation, ] } -func serializeHyperTrackError(_ error: HyperTrackError) -> Dictionary { - return [ - keyType: typeHyperTrackError, - keyValue: error.rawValue - ] +func serializeLocationWithDeviationResult( + _ result: Result +) -> [String: Any] { + switch result { + case let .success(success): + return [ + keyType: typeSuccess, + keyValue: [ + keyType: "locationWithDeviation", + keyValue: serializeLocationWithDeviation(success), + ], + ] + case let .failure(failure): + return [ + keyType: typeFailure, + keyValue: serializeLocationError(failure), + ] + } } -func serializeIsTracking(_ isTracking: Bool) -> Dictionary { +func serializeMetadata(_ metadata: HyperTrack.JSON.Object) -> [String: Any] { return [ - keyType: typeIsTracking, - keyValue: isTracking + keyType: typeMetadata, + keyValue: toMap(metadata), ] } -func serializeIsAvailable(_ isAvailable: HyperTrack.Availability) -> Dictionary { +func serializeName(_ name: String) -> [String: Any] { return [ - keyType: typeIsAvailable, - keyValue: isAvailable == .available + keyType: typeName, + keyValue: name, ] } -func deserializeDeviceName(_ data: Dictionary) -> Result { - if (data[keyType] as? String != "deviceName") { - return .failure(.fatalError(getParseError(data, key: keyType))) - } - guard let value = data[keyValue] as? String else { - return .failure(.fatalError(getParseError(data, key: keyValue))) +func serializeErrors(_ errors: Set) -> [[String: Any]] { + return errors.map { error in + serializeError(error) } - return .success(value) } -func deserializeAvailability(_ data: Dictionary) -> Result { - if (data[keyType] as? String != typeIsAvailable) { - return .failure(.fatalError(getParseError(data, key: keyType))) - } - guard let value = data[keyValue] as? Bool else { - return .failure(.fatalError(getParseError(data, key: keyValue))) +private func toMap(_ object: HyperTrack.JSON.Object) -> [String: Any] { + return object.mapValues { value in + switch value { + case let .object(objectValue): + return toMap(objectValue) as Any + case let .array(arr): + return toArray(arr) + case let .bool(bool): + return bool + case let .number(number): + return number + case let .string(string): + return string + case .null: + return NSNull() + } } - return .success(value) } -func deserializeGeotagData( - _ geotag: Dictionary -) -> Result, FailureResult> { - guard let data = geotag[keyGeotagData] as? Dictionary else { - return .failure(.fatalError(getParseError(geotag, key: keyGeotagData))) +private func toArray(_ array: [HyperTrack.JSON]) -> [Any] { + return array.map { (json: HyperTrack.JSON) -> Any in + switch json { + case let .object(objectValue): + return toMap(objectValue) + case let .array(arr): + return toArray(arr) + case let .bool(bool): + return bool + case let .number(number): + return number + case let .string(string): + return string + case .null: + return NSNull() + } } - return .success(data) } -func getParseError(_ data: Any, key: String) -> String { +private func getParseError(_ data: Any, key: String) -> String { return "Invalid input for key \(key): \(data)" } diff --git a/package.json b/package.json index 83b0d9b..850c44c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hypertrack-sdk-ionic-capacitor", - "version": "1.0.3", + "version": "2.0.0", "description": "Capacitor plugin for HyperTrack generation SDKs", "main": "dist/plugin.cjs.js", "module": "dist/esm/index.js", diff --git a/src/HyperTrack.ts b/src/HyperTrack.ts index 7fdec62..6efc82a 100644 --- a/src/HyperTrack.ts +++ b/src/HyperTrack.ts @@ -1,225 +1,447 @@ +import { HyperTrackError } from './data_types/HyperTrackError'; import type { IsAvailable } from './data_types/internal/IsAvailable'; import type { IsTracking } from './data_types/internal/IsTracking'; -import type { LocationResponse } from './data_types/internal/LocationResponse'; import type { Location } from './data_types/Location'; import type { LocationError } from './data_types/LocationError'; -import type { SdkInitParams } from './data_types/SdkInitParams'; import type { DeviceId } from './data_types/internal/DeviceId'; -import type { Geotag } from './data_types/internal/Geotag'; -import type { DeviceName } from './data_types/internal/DeviceName'; - +import type { GeotagData } from './data_types/internal/GeotagData'; +import type { Name } from './data_types/internal/Name'; +import type { HyperTrackErrorInternal } from './data_types/internal/HyperTrackErrorInternal'; +import type { LocationWithDeviation } from './data_types/LocationWithDeviation'; +import type { LocationErrorInternal } from './data_types/internal/LocationErrorInternal'; +import type { Result } from './data_types/Result'; +import type { LocationInternal } from './data_types/internal/LocationInternal'; +import type { LocationWithDeviationInternal } from './data_types/internal/LocationWithDeviationInternal'; +import type { Metadata } from './data_types/internal/Metadata'; import { registerPlugin } from '@capacitor/core'; -import { HyperTrackCapacitorPlugin, Subscription } from './definitions'; -import { HyperTrackError } from './data_types/HyperTrackError'; -import { HyperTrackErrorInternal } from './data_types/internal/HyperTrackErrorInternal'; +import { Subscription } from './Subscription'; +import { Errors, HyperTrackCapacitorPlugin } from './HyperTrackCapacitorPlugin'; + +export const EVENT_ERRORS = 'errors'; +export const EVENT_IS_AVAILABLE = 'isAvailable'; +export const EVENT_IS_TRACKING = 'isTracking'; +export const EVENT_LOCATE = 'locate'; +export const EVENT_LOCATION = 'location'; const hyperTrackPlugin = registerPlugin('HyperTrackCapacitorPlugin', { // web: () => import('./web').then(m => new m.HyperTrackSdkWeb()), }); export default class HyperTrack { - constructor() { - return this; - } - - /** - * Creates an SDK instance - * - * @param publishableKey publishable key provided in HyperTrack’s dashboard setup page - * @param sdkInitParams - * @returns HyperTrack instance - */ - static async initialize( - publishableKey: string, - sdkInitParams: SdkInitParams = {} - ) { - try { - await hyperTrackPlugin.initialize({ - publishableKey, - loggingEnabled: sdkInitParams.loggingEnabled ?? false, - allowMockLocations: sdkInitParams.allowMockLocations ?? false, - requireBackgroundTrackingPermission: sdkInitParams.requireBackgroundTrackingPermission ?? false, - }); - return new HyperTrack(); - } catch (error: any) { - throw new Error(error.message); + private static locateSubscription: Subscription | undefined; + + /** + * Adds a new geotag + * + * @param {Object} data - Geotad data JSON + * @returns current location if success or LocationError if failure + */ + static async addGeotag(data: Object): Promise>; + + /** + * Adds a new geotag with expected location + * + * @param {Object} data - Geotad data JSON + * @param {Location} expectedLocation - Expected location + * @returns location with deviation if success or LocationError if failure + */ + static async addGeotag( + data: Object, + expectedLocation: Location + ): Promise>; + + static async addGeotag(...args: any[]): Promise> { + if (args.length === 1 && typeof args[0] === 'object') { + return hyperTrackPlugin + .addGeotag({ + data: args[0], + expectedLocation: undefined, + } as GeotagData) + .then((locationResponse: Result) => { + return this.deserializeLocationResponse(locationResponse); + }); + } else if (args.length === 2 && typeof args[0] === 'object' && HyperTrack.isLocation(args[1])) { + let expectedLocation = args[1] as Location; + return hyperTrackPlugin + .addGeotag({ + data: args[0], + expectedLocation: { + type: 'location', + value: { + latitude: expectedLocation.latitude, + longitude: expectedLocation.longitude, + }, + } as LocationInternal, + } as GeotagData) + .then((locationResponse: Result) => { + return this.deserializeLocationWithDeviationResponse(locationResponse); + }); + } else { + throw new Error('Invalid arguments'); } } /** * Returns a string that is used to uniquely identify the device + * + * @returns {string} Device ID */ - getDeviceId(): Promise { - return hyperTrackPlugin.getDeviceId().then( - (deviceId: DeviceId) => deviceId.value - ); + static async getDeviceId(): Promise { + return hyperTrackPlugin.getDeviceId().then((deviceId: DeviceId) => deviceId.value); } /** - * Reflects availability of the device for the Nearby search + * Returns a list of errors that blocks SDK from tracking * - * @returns true when is available or false when unavailable + * @returns {HyperTrackError[]} List of errors */ - isAvailable(): Promise { - return hyperTrackPlugin.isAvailable().then( - (isAvailable: IsAvailable) => isAvailable.value - ); + static async getErrors(): Promise { + return hyperTrackPlugin.getErrors().then((errors: Errors) => { + return this.deserializeHyperTrackErrors(errors.errors); + }); } /** - * Sets the availability of the device for the Nearby search + * Reflects availability of the device for the Nearby search * - * @param availability true when is available or false when unavailable + * @returns true when is available or false when unavailable */ - setAvailability(isAvailable: boolean) { - hyperTrackPlugin.setAvailability({ - type: 'isAvailable', - value: isAvailable - } as IsAvailable); + static async getIsAvailable(): Promise { + return hyperTrackPlugin.getIsAvailable().then((isAvailable: IsAvailable) => isAvailable.value); } /** * Reflects the tracking intent for the device - * - * @return {boolean} Whether the user's movement data is getting tracked or not. + * + * @returns {boolean} Whether the user's movement data is getting tracked or not. */ - isTracking(): Promise { - return hyperTrackPlugin.isTracking().then( - (isTracking: IsTracking) => isTracking.value - ); + static async getIsTracking(): Promise { + return hyperTrackPlugin.getIsTracking().then((isTracking: IsTracking) => isTracking.value); } /** - * Syncs the device state with the HyperTrack servers + * Reflects the current location of the user or an outage reason */ - sync() { - hyperTrackPlugin.sync(); + static async getLocation(): Promise> { + return hyperTrackPlugin.getLocation().then((locationResponse: Result) => { + return this.deserializeLocationResponse(locationResponse); + }); } /** - * Expresses an intent to start location tracking for the device + * Gets the metadata that is set for the device + * + * @returns {Object} Metadata JSON */ - startTracking() { - hyperTrackPlugin.startTracking(); + static async getMetadata(): Promise { + return hyperTrackPlugin.getMetadata().then((metadata: Metadata) => { + return this.deserializeMetadata(metadata); + }); } /** - * Stops location tracking immediately + * Gets the name that is set for the device + * + * @returns {string} Device name */ - stopTracking() { - hyperTrackPlugin.stopTracking(); + static async getName(): Promise { + return hyperTrackPlugin.getName().then((name: Name) => { + return this.deserializeName(name); + }); } /** - * Reflects the current location of the user or an outage reason + * Requests one-time location update and returns the location once it is available, or error. + * + * Only one locate subscription can be active at a time. If you re-subscribe, the old Subscription + * will be automaticaly removed. + * + * This method will start location tracking if called, and will stop it when the location is received or + * the subscription is cancelled. If any other tracking intent is present (e.g. isAvailable is set to `true`), + * the tracking will not be stopped. + * + * @param callback + * @returns Subscription + * @example ```js + * const subscription = HyperTrack.locate(location => { + * ... + * }) + * + * // to unsubscribe + * subscription.remove() + * ``` */ - getLocation(): Promise { - return hyperTrackPlugin.getLocation().then( - (locationResponse: LocationResponse) => { - return this.deserializeLocationResponse(locationResponse); + static locate(callback: (locateResult: Result) => void) { + // this call doesn't work on iOS for some reason + this.locateSubscription?.remove(); + this.locateSubscription = hyperTrackPlugin.addListener( + EVENT_LOCATE, + (location: Result) => { + callback(this.deserializeLocateResponse(location)); + // so we remove the subscription here (locate should return only one event) + this.locateSubscription?.remove(); } ); + hyperTrackPlugin.onSubscribedToLocate(); + return this.locateSubscription; } /** - * Sets the name for the device - * @param {string} name + * Sets the availability of the device for the Nearby search + * + * @param availability true when is available or false when unavailable */ - setName(name: string) { - hyperTrackPlugin.setName({ - type: 'deviceName', - value: name - } as DeviceName) + static async setIsAvailable(isAvailable: boolean) { + hyperTrackPlugin.setIsAvailable({ + type: 'isAvailable', + value: isAvailable, + } as IsAvailable); + } + + /** + * Sets the tracking intent for the device + * + * @param {boolean} isTracking + */ + static async setIsTracking(isTracking: boolean): Promise { + hyperTrackPlugin.setIsTracking({ + type: 'isTracking', + value: isTracking, + } as IsTracking); } /** * Sets the metadata for the device + * * @param {Object} data - Metadata JSON */ - setMetadata(data: Object) { - hyperTrackPlugin.setMetadata(data); + static async setMetadata(data: Object) { + hyperTrackPlugin.setMetadata({ + type: 'metadata', + value: data, + }); } /** - * Adds a new geotag - * @param {Object} data - Geotad data JSON - * @returns current location if success or LocationError if failure + * Sets the name for the device + * + * @param {string} name */ - addGeotag(data: Object): Promise { - return hyperTrackPlugin.addGeotag({ - data - } as Geotag).then( - (locationResponse: LocationResponse) => { - return this.deserializeLocationResponse(locationResponse); - } - ); + static async setName(name: string) { + hyperTrackPlugin.setName({ + type: 'name', + value: name, + } as Name); } /** - * Subscribe to tracking intent changes + * Subscribe to tracking errors * - * @param subscriptionFunction (isTracking: boolean) => void - * @returns Promise + * @param listener + * @returns Subscription + * @example + * ```js + * const subscription = HyperTrack.subscribeToErrors(errors => { + * errors.forEach(error => { + * // ... error + * }) + * }) + * + * // later, to stop listening + * subscription.remove() + * ``` */ - subscribeToTracking(subscriptionFunction: (isTracking: boolean) => void): Promise { - const result = hyperTrackPlugin.addListener("onTrackingChanged", (info: IsTracking) => subscriptionFunction(info.value)) - hyperTrackPlugin.onSubscribedToTracking(); - console.log("onSubscribedToTracking") - return result + static subscribeToErrors(listener: (errors: HyperTrackError[]) => void): Subscription { + const result = hyperTrackPlugin.addListener(EVENT_ERRORS, (info: Errors) => { + listener(this.deserializeHyperTrackErrors(info.errors)); + }); + hyperTrackPlugin.onSubscribedToErrors(); + return result; } /** * Subscribe to availability changes * - * @param subscriptionFunction (isAvailable: boolean) => void - * @returns Promise + * @param listener + * @returns Subscription + * @example + * ```js + * const subscription = HyperTrack.subscribeToIsAvailable(isAvailable => { + * if (isAvailable) { + * // ... ready to go + * } + * }) + * + * // later, to stop listening + * subscription.remove() + * ``` */ - subscribeToAvailability(subscriptionFunction: (isAvailable: boolean) => void): Promise { - const result = hyperTrackPlugin.addListener("onAvailabilityChanged", (info: IsAvailable) => subscriptionFunction(info.value)) - hyperTrackPlugin.onSubscribedToAvailability(); - console.log("onSubscribedToAvailability") - return result + static subscribeToIsAvailable(listener: (isAvailable: boolean) => void): Subscription { + const result = hyperTrackPlugin.addListener(EVENT_IS_AVAILABLE, (isAvailable: IsAvailable) => { + listener(isAvailable.value); + }); + hyperTrackPlugin.onSubscribedToIsAvailable(); + return result; } /** - * Subscribe to tracking errors + * Subscribe to tracking intent changes * - * @param subscriptionFunction (errors: HyperTrackError[]) => void - * @returns Promise + * @param listener + * @returns Subscription + * @example + * ```js + * const subscription = HyperTrack.subscribeToIsTracking(isTracking => { + * if (isTracking) { + * // ... ready to go + * } + * }) + * + * // later, to stop listening + * subscription.remove() + * ``` */ - subscribeToErrors(subscriptionFunction: (errors: HyperTrackError[]) => void): Promise { - const result = hyperTrackPlugin.addListener("onError", (info: Errors) => { - subscriptionFunction(this.deserializeHyperTrackErrors(info.errors)); - }) - hyperTrackPlugin.onSubscribedToErrors(); - return result + static subscribeToIsTracking(listener: (isTracking: boolean) => void): Subscription { + const result = hyperTrackPlugin.addListener(EVENT_IS_TRACKING, (isTracking: IsTracking) => { + listener(isTracking.value); + }); + hyperTrackPlugin.onSubscribedToIsTracking(); + return result; + } + + /** + * Subscribe to location changes + * + * @param listener + * @returns Subscription + * @example + * ```js + * const subscription = HyperTrack.subscribeToLocation(location => { + * ... + * }) + * + * // later, to stop listening + * subscription.remove() + * ``` + */ + static subscribeToLocation(listener: (location: Result) => void) { + const result = hyperTrackPlugin.addListener( + EVENT_LOCATION, + (location: Result) => { + listener(this.deserializeLocationResponse(location)); + } + ); + hyperTrackPlugin.onSubscribedToLocation(); + return result; + } + + /** @ignore */ + private static deserializeHyperTrackErrors(errors: HyperTrackErrorInternal[]): HyperTrackError[] { + let res = errors.map((error: HyperTrackErrorInternal) => { + if (error.type != 'error') { + throw new Error('Invalid error type'); + } + return Object.keys(HyperTrackError).find( + (key) => HyperTrackError[key as keyof typeof HyperTrackError] === error.value + ) as HyperTrackError; + }); + return res; } /** @ignore */ - private deserializeHyperTrackErrors(errors: HyperTrackErrorInternal[]): HyperTrackError[] { - return errors.map((error: HyperTrackErrorInternal) => HyperTrackError[error.value as keyof typeof HyperTrackError]) + private static deserializeLocateResponse( + response: Result + ): Result { + switch (response.type) { + case 'success': + return { + type: 'success', + value: response.value.value, + }; + case 'failure': + return { + type: 'failure', + value: this.deserializeHyperTrackErrors(response.value), + }; + } } /** @ignore */ - private deserializeLocationResponse(response: LocationResponse): Location | LocationError { - switch(response.type) { - case "success": - return response.value - case "failure": - switch(response.value.type) { - case "notRunning": - case "starting": - return response.value - case "errors": - return { - type: "errors", - value: this.deserializeHyperTrackErrors(response.value.value) - } - } - }; + private static deserializeLocationError(locationError: LocationErrorInternal): LocationError { + switch (locationError.type) { + case 'notRunning': + case 'starting': + return locationError; + case 'errors': + return { + type: 'errors', + value: this.deserializeHyperTrackErrors(locationError.value), + }; + } + } + + /** @ignore */ + private static deserializeLocationResponse( + response: Result + ): Result { + switch (response.type) { + case 'success': + return { + type: 'success', + value: response.value.value, + }; + case 'failure': + return { + type: 'failure', + value: this.deserializeLocationError(response.value), + }; + } + } + + /** @ignore */ + private static deserializeLocationWithDeviationResponse( + response: Result + ): Result { + switch (response.type) { + case 'success': + const locationWithDeviationInternal: LocationWithDeviationInternal = response.value; + const locationInternal: LocationInternal = locationWithDeviationInternal.value.location; + + return { + type: 'success', + value: { + location: locationInternal.value, + deviation: locationWithDeviationInternal.value.deviation, + } as LocationWithDeviation, + }; + case 'failure': + return { + type: 'failure', + value: this.deserializeLocationError(response.value), + }; + } } -} -type Errors = { - "errors": HyperTrackErrorInternal[] + /** @ignore */ + private static deserializeMetadata(metadata: Metadata): Object { + if (metadata.type != 'metadata') { + throw new Error(`Invalid metadata: ${JSON.stringify(metadata)}`); + } + return metadata.value; + } + + /** @ignore */ + private static deserializeName(name: Name): string { + if (name.type != 'name') { + throw new Error(`Invalid name: ${JSON.stringify(name)}`); + } + return name.value; + } + + /** @ignore */ + private static isLocation(obj: Location): obj is Location { + return ( + 'latitude' in obj && typeof obj.latitude == 'number' && 'longitude' in obj && typeof obj.longitude == 'number' + ); + } } diff --git a/src/HyperTrackCapacitorPlugin.ts b/src/HyperTrackCapacitorPlugin.ts new file mode 100644 index 0000000..7cfc3ee --- /dev/null +++ b/src/HyperTrackCapacitorPlugin.ts @@ -0,0 +1,74 @@ +import { EVENT_ERRORS, EVENT_IS_AVAILABLE, EVENT_IS_TRACKING, EVENT_LOCATE, EVENT_LOCATION } from "./HyperTrack"; +import { Subscription } from "./Subscription"; +import { Result } from "./data_types/Result"; +import { DeviceId } from "./data_types/internal/DeviceId"; +import { HyperTrackErrorInternal } from "./data_types/internal/HyperTrackErrorInternal"; +import { IsAvailable } from "./data_types/internal/IsAvailable"; +import { IsTracking } from "./data_types/internal/IsTracking"; +import { LocationErrorInternal } from "./data_types/internal/LocationErrorInternal"; +import { LocationInternal } from "./data_types/internal/LocationInternal"; +import { Metadata } from "./data_types/internal/Metadata"; +import { Name } from "./data_types/internal/Name"; + +export type Errors = { + "errors": HyperTrackErrorInternal[] +} + +export interface HyperTrackCapacitorPlugin { + addGeotag( + ...args: any[] + ): Promise; + + getDeviceId(): Promise; + + getErrors(): Promise; + + getIsAvailable(): Promise; + + getIsTracking(): Promise; + + getLocation(): Promise>; + + getMetadata(): Promise; + + getName(): Promise; + + setIsAvailable(isAvailable: IsAvailable): Promise; + + setIsTracking(isTracking: IsTracking): Promise; + + setMetadata(data: Metadata): Promise; + + setName(name: Name): Promise; + + onSubscribedToErrors(): Promise; + onSubscribedToIsAvailable(): Promise; + onSubscribedToIsTracking(): Promise; + onSubscribedToLocate(): Promise; + onSubscribedToLocation(): Promise; + + addListener( + eventName: typeof EVENT_ERRORS, + listenerFunc: (error: any) => void + ): Subscription; + + addListener( + eventName: typeof EVENT_IS_AVAILABLE, + listenerFunc: (isAvailable: IsAvailable) => void + ): Subscription; + + addListener( + eventName: typeof EVENT_IS_TRACKING, + listenerFunc: (isTracking: IsTracking) => void + ): Subscription; + + addListener( + eventName: typeof EVENT_LOCATE, + listenerFunc: (locateResult: Result) => void + ): Subscription; + + addListener( + eventName: typeof EVENT_LOCATION, + listenerFunc: (location: Result) => void + ): Subscription; +} diff --git a/src/Subscription.ts b/src/Subscription.ts new file mode 100644 index 0000000..45a1208 --- /dev/null +++ b/src/Subscription.ts @@ -0,0 +1,4 @@ + +export interface Subscription { + remove: () => Promise; +} diff --git a/src/data_types/HyperTrackError.ts b/src/data_types/HyperTrackError.ts index 2b1c703..b616224 100644 --- a/src/data_types/HyperTrackError.ts +++ b/src/data_types/HyperTrackError.ts @@ -1,22 +1,77 @@ // enum naming convention is ignored to make datatype sync // across platforms easier export enum HyperTrackError { - gpsSignalLost = "gpsSignalLost", - locationMocked = "locationMocked", - locationPermissionsDenied = "locationPermissionsDenied", - locationPermissionsInsufficientForBackground = "locationPermissionsInsufficientForBackground", - locationPermissionsNotDetermined = "locationPermissionsNotDetermined", - locationPermissionsReducedAccuracy = "locationPermissionsReducedAccuracy", - locationPermissionsProvisional = "locationPermissionsProvisional", - locationPermissionsRestricted = "locationPermissionsRestricted", - locationServicesDisabled = "locationServicesDisabled", - locationServicesUnavailable = "locationServicesUnavailable", - motionActivityPermissionsNotDetermined = "motionActivityPermissionsNotDetermined", - motionActivityPermissionsDenied = "motionActivityPermissionsDenied", - motionActivityServicesDisabled = "motionActivityServicesDisabled", - motionActivityServicesUnavailable = "motionActivityServicesUnavailable", - motionActivityPermissionsRestricted = "motionActivityPermissionsRestricted", - networkConnectionUnavailable = "networkConnectionUnavailable", - invalidPublishableKey = "invalidPublishableKey", - blockedFromRunning = "blockedFromRunning" + /** + * The SDK was remotely blocked from running. + */ + blockedFromRunning = 'blockedFromRunning', + + /** + * The publishable key is invalid. + */ + invalidPublishableKey = 'invalidPublishableKey', + + /** + * The user enabled mock location app while mocking locations is prohibited. + */ + locationMocked = 'location.mocked', + + /** + * The user disabled location services systemwide. + */ + locationServicesDisabled = 'location.servicesDisabled', + + /** + * [Android only] The device doesn't have location services. + */ + locationServicesUnavailable = 'location.servicesUnavailable', + + /** + * GPS satellites are not in view. + */ + locationSignalLost = 'location.signalLost', + + /** + * [Android only] The SDK wasn't able to start tracking because of the limitations imposed by the OS. + * The exempt from background execution conditions weren't met. + * {@link https://developer.android.com/guide/components/foreground-services#background-start-restriction-exemptions} + */ + noExemptionFromBackgroundStartRestrictions = 'noExemptionFromBackgroundStartRestrictions', + + /** + * The user denied location permissions. + */ + permissionsLocationDenied = 'permissions.location.denied', + + /** + * Can’t start tracking in background with When In Use location permissions. + * SDK will automatically start tracking when app will return to foreground. + */ + permissionsLocationInsufficientForBackground = 'permissions.location.insufficientForBackground', + + /** + * [iOS only] The user has not chosen whether the app can use location services. + */ + permissionsLocationNotDetermined = 'permissions.location.notDetermined', + + /** + * [iOS only] The app is in Provisional Always authorization state, which stops sending locations when app is in background. + */ + permissionsLocationProvisional = 'permissions.location.provisional', + + /** + * The user didn't grant precise location permissions or downgraded permissions to imprecise. + */ + permissionsLocationReducedAccuracy = 'permissions.location.reducedAccuracy', + + /** + * [iOS only] The app is not authorized to use location services. + */ + permissionsLocationRestricted = 'permissions.location.restricted', + + /** + * [Android only] The user denied notification permissions needed to display a persistent notification + * needed for foreground location tracking. + */ + permissionsNotificationsDenied = 'permissions.notifications.denied', } diff --git a/src/data_types/Location.ts b/src/data_types/Location.ts index 03335cf..8fb2331 100644 --- a/src/data_types/Location.ts +++ b/src/data_types/Location.ts @@ -1,7 +1,4 @@ export type Location = { - type: 'location'; - value: { - latitude: number; - longitude: number; - }; + latitude: number; + longitude: number; }; diff --git a/src/data_types/LocationError.ts b/src/data_types/LocationError.ts index f7156c8..6917407 100644 --- a/src/data_types/LocationError.ts +++ b/src/data_types/LocationError.ts @@ -1,8 +1,6 @@ import type { HyperTrackError } from './HyperTrackError'; import type { NotRunning, Starting } from './internal/LocationErrorInternal'; -export { NotRunning, Starting } - export type Errors = { type: 'errors'; value: HyperTrackError[]; diff --git a/src/data_types/LocationWithDeviation.ts b/src/data_types/LocationWithDeviation.ts new file mode 100644 index 0000000..ad0278b --- /dev/null +++ b/src/data_types/LocationWithDeviation.ts @@ -0,0 +1,6 @@ +import type { Location } from './Location'; + +export type LocationWithDeviation = { + location: Location; + deviation: number; +}; diff --git a/src/data_types/Result.ts b/src/data_types/Result.ts new file mode 100644 index 0000000..a43e7df --- /dev/null +++ b/src/data_types/Result.ts @@ -0,0 +1,11 @@ +export type Success = { + type: 'success'; + value: S; +}; + +export type Failure = { + type: 'failure'; + value: F; +}; + +export type Result = Success | Failure; diff --git a/src/data_types/SdkInitParams.ts b/src/data_types/SdkInitParams.ts deleted file mode 100644 index 8455d28..0000000 --- a/src/data_types/SdkInitParams.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type SdkInitParams = { - loggingEnabled?: boolean; - allowMockLocations?: boolean; - requireBackgroundTrackingPermission?: boolean; -}; diff --git a/src/data_types/internal/DeviceName.ts b/src/data_types/internal/DeviceName.ts deleted file mode 100644 index 0ba3179..0000000 --- a/src/data_types/internal/DeviceName.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type DeviceName = { - type: 'deviceName'; - value: string; -}; diff --git a/src/data_types/internal/Geotag.ts b/src/data_types/internal/Geotag.ts deleted file mode 100644 index 7f2bab2..0000000 --- a/src/data_types/internal/Geotag.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Geotag = { - data: Object -} diff --git a/src/data_types/internal/GeotagData.ts b/src/data_types/internal/GeotagData.ts new file mode 100644 index 0000000..e20e6fc --- /dev/null +++ b/src/data_types/internal/GeotagData.ts @@ -0,0 +1,6 @@ +import type { LocationInternal } from './LocationInternal'; + +export type GeotagData = { + data: Object; + expectedLocation?: LocationInternal; +}; diff --git a/src/data_types/internal/HyperTrackErrorInternal.ts b/src/data_types/internal/HyperTrackErrorInternal.ts index 26f8769..0d5c3e5 100644 --- a/src/data_types/internal/HyperTrackErrorInternal.ts +++ b/src/data_types/internal/HyperTrackErrorInternal.ts @@ -1,4 +1,4 @@ export type HyperTrackErrorInternal = { - type: "hyperTrackError", - value: string -} + type: 'error'; + value: string; +}; diff --git a/src/data_types/internal/LocationInternal.ts b/src/data_types/internal/LocationInternal.ts new file mode 100644 index 0000000..77e54a1 --- /dev/null +++ b/src/data_types/internal/LocationInternal.ts @@ -0,0 +1,7 @@ +export type LocationInternal = { + type: 'location'; + value: { + latitude: number; + longitude: number; + }; +}; diff --git a/src/data_types/internal/LocationResponse.ts b/src/data_types/internal/LocationResponse.ts deleted file mode 100644 index da063e2..0000000 --- a/src/data_types/internal/LocationResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { Location } from '../Location'; -import type { LocationErrorInternal } from './LocationErrorInternal'; - -export type LocationSuccess = { - type: 'success'; - value: Location; -}; - -export type LocationFailure = { - type: 'failure'; - value: LocationErrorInternal; -}; - -export type LocationResponse = LocationSuccess | LocationFailure; diff --git a/src/data_types/internal/LocationWithDeviationInternal.ts b/src/data_types/internal/LocationWithDeviationInternal.ts new file mode 100644 index 0000000..fb9c9ef --- /dev/null +++ b/src/data_types/internal/LocationWithDeviationInternal.ts @@ -0,0 +1,9 @@ +import type { LocationInternal } from './LocationInternal'; + +export type LocationWithDeviationInternal = { + type: 'locationWithDeviation'; + value: { + location: LocationInternal; + deviation: number; + }; +}; diff --git a/src/data_types/internal/Metadata.ts b/src/data_types/internal/Metadata.ts new file mode 100644 index 0000000..db4f044 --- /dev/null +++ b/src/data_types/internal/Metadata.ts @@ -0,0 +1,4 @@ +export type Metadata = { + type: 'metadata'; + value: Object; +}; diff --git a/src/data_types/internal/Name.ts b/src/data_types/internal/Name.ts new file mode 100644 index 0000000..95232a5 --- /dev/null +++ b/src/data_types/internal/Name.ts @@ -0,0 +1,7 @@ +/** + * Device name + */ +export type Name = { + type: 'name'; + value: string; +}; diff --git a/src/definitions.ts b/src/definitions.ts deleted file mode 100644 index 4c57de9..0000000 --- a/src/definitions.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { DeviceId } from "./data_types/internal/DeviceId"; -import { DeviceName } from "./data_types/internal/DeviceName"; -import { IsAvailable } from "./data_types/internal/IsAvailable"; -import { IsTracking } from "./data_types/internal/IsTracking"; -import { LocationResponse } from "./data_types/internal/LocationResponse"; - -export interface HyperTrackCapacitorPlugin { - initialize(sdkInitParams: {}): Promise; - startTracking(): Promise; - stopTracking(): Promise; - getDeviceId(): Promise; - /** Sets device's availability for nearby search. */ - setAvailability(isAvailable: IsAvailable): Promise; - /** Reflects tracking intent. */ - isTracking(): Promise; - isAvailable(): Promise; - setName(name: DeviceName): Promise; - setMetadata(data: Object): Promise; - sync(): Promise; - getLocation(): Promise; - addGeotag(data: Object): Promise; - - onSubscribedToTracking(): Promise - onSubscribedToAvailability(): Promise - onSubscribedToErrors(): Promise - - addListener(eventName: 'onTrackingChanged', listenerFunc: (info: any) => void): Promise & Subscription; - addListener(eventName: 'onAvailabilityChanged', listenerFunc: (info: any) => void): Promise & Subscription; - addListener(eventName: 'onError', listenerFunc: (info: any) => void): Promise & Subscription; -} - -export interface Subscription { - remove: () => Promise; -} diff --git a/src/index.ts b/src/index.ts index 4e4a577..60e3550 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,14 @@ -import { SdkInitParams } from './data_types/SdkInitParams'; import HyperTrack from './HyperTrack'; export default HyperTrack; export { HyperTrack }; -export { SdkInitParams }; + export { HyperTrackError } from './data_types/HyperTrackError'; -export { LocationError, NotRunning, Starting, Errors } from './data_types/LocationError'; +export { + NotRunning, + Starting, +} from './data_types/internal/LocationErrorInternal'; +export { LocationError, Errors } from './data_types/LocationError'; +export { LocationWithDeviation } from './data_types/LocationWithDeviation'; export { Location } from './data_types/Location'; -export { Subscription } from './definitions' +export { Result, Success, Failure } from './data_types/Result'; +export { Subscription } from './Subscription';