Skip to content

Commit

Permalink
Add worker handle support (#34)
Browse files Browse the repository at this point in the history
Add any Capacitor version to peerDependencies
  • Loading branch information
pavel-kuznetsov-hypertrack authored Jun 19, 2024
1 parent 7b35022 commit ee710d5
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 83 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.4.0] - 2024-06-13

### Added

- New `setWorkerHandle` and `getWorkerHandle` can be used to identify workers
- We observed our customers identify worker devices via `HyperTrack.metadata`, so we decided to make it a first class citizen in our API.
- If you previously used `metadata` to identify workers, we suggest using `workerHandle` for this purpose instead.

### Changed

- Updated HyperTrack SDK iOS to [5.6.0](https://github.com/hypertrack/sdk-ios/releases/tag/5.6.0)
- Updated HyperTrack SDK Android to [7.6.0](https://github.com/hypertrack/sdk-android/releases/tag/7.6.0)

## [3.3.1] - 2024-05-24

### Changed
Expand Down Expand Up @@ -215,3 +228,4 @@ We are excited to announce the release of HyperTrack Ionic Capacitor SDK 2.0.0,
[3.2.2]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.2.2
[3.3.0]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.3.0
[3.3.1]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.3.1
[3.4.0]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.4.0
2 changes: 1 addition & 1 deletion HypertrackSdkIonicCapacitor.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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','5.5.4'
s.dependency 'HyperTrack','5.6.0'
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-5.5.4-brightgreen.svg)](https://github.com/hypertrack/sdk-ios)
[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.5.5-brightgreen.svg)](https://github.com/hypertrack/sdk-android)
[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.6.0-brightgreen.svg)](https://github.com/hypertrack/sdk-ios)
[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.6.0-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.

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {

buildscript {
ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '1.9.10'
ext.hypertrack_sdk_version = "7.5.5"
ext.hypertrack_sdk_version = "7.6.0"
ext.firebase_messaging_version = "23.1.1"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class HyperTrackCapacitorPlugin : Plugin() {
invokeSdkMethod(SdkMethod.getName, call).toPluginCall(call)
}

@PluginMethod
fun getWorkerHandle(call: PluginCall) {
invokeSdkMethod(SdkMethod.getWorkerHandle, call).toPluginCall(call)
}

@PluginMethod
fun setIsAvailable(call: PluginCall) {
invokeSdkMethod(SdkMethod.setIsAvailable, call).toPluginCall(call)
Expand All @@ -82,6 +87,11 @@ class HyperTrackCapacitorPlugin : Plugin() {
invokeSdkMethod(SdkMethod.setName, call).toPluginCall(call)
}

@PluginMethod
fun setWorkerHandle(call: PluginCall) {
invokeSdkMethod(SdkMethod.setWorkerHandle, call).toPluginCall(call)
}

@PluginMethod
fun onSubscribedToErrors(call: PluginCall) {
sendErrorsEvent(HyperTrack.errors)
Expand Down Expand Up @@ -211,6 +221,10 @@ class HyperTrackCapacitorPlugin : Plugin() {
HyperTrackSdkWrapper.getName()
}

SdkMethod.getWorkerHandle -> {
HyperTrackSdkWrapper.getWorkerHandle()
}

SdkMethod.locate -> {
throw NotImplementedError("Locate is implemented in different way")
}
Expand Down Expand Up @@ -242,6 +256,12 @@ class HyperTrackCapacitorPlugin : Plugin() {
HyperTrackSdkWrapper.setName(args)
}
}

SdkMethod.setWorkerHandle -> {
withArgs<Map<String, Any?>, Unit>(argsJson) { args ->
HyperTrackSdkWrapper.setWorkerHandle(args)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.hypertrack.sdk.capacitor.common.Serialization.deserializeIsAvailable
import com.hypertrack.sdk.capacitor.common.Serialization.deserializeIsTracking
import com.hypertrack.sdk.capacitor.common.Serialization.deserializeMetadata
import com.hypertrack.sdk.capacitor.common.Serialization.deserializeName
import com.hypertrack.sdk.capacitor.common.Serialization.deserializeWorkerHandle
import com.hypertrack.sdk.capacitor.common.Serialization.serializeDeviceId
import com.hypertrack.sdk.capacitor.common.Serialization.serializeDynamicPublishableKey
import com.hypertrack.sdk.capacitor.common.Serialization.serializeErrors
Expand All @@ -20,6 +21,7 @@ import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationSucces
import com.hypertrack.sdk.capacitor.common.Serialization.serializeLocationWithDeviationSuccess
import com.hypertrack.sdk.capacitor.common.Serialization.serializeMetadata
import com.hypertrack.sdk.capacitor.common.Serialization.serializeName
import com.hypertrack.sdk.capacitor.common.Serialization.serializeWorkerHandle

typealias Serialized = Map<String, Any?>

Expand Down Expand Up @@ -137,6 +139,12 @@ internal object HyperTrackSdkWrapper {
)
}

fun getWorkerHandle(): WrapperResult<Serialized> {
return Success(
serializeWorkerHandle(HyperTrack.workerHandle),
)
}

fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> {
return deserializeDynamicPublishableKey(args)
.mapSuccess { publishableKey ->
Expand Down Expand Up @@ -174,4 +182,11 @@ internal object HyperTrackSdkWrapper {
HyperTrack.name = name
}
}

fun setWorkerHandle(args: Serialized): WrapperResult<Unit> {
return deserializeWorkerHandle(args)
.mapSuccess { workerHandle ->
HyperTrack.workerHandle = workerHandle
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ internal enum class SdkMethod {
getLocation,
getMetadata,
getName,
getWorkerHandle,
locate,
setDynamicPublishableKey,
setIsAvailable,
setIsTracking,
setMetadata,
setName,
setWorkerHandle,
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ internal object Serialization {
}
}

fun deserializeWorkerHandle(map: Map<String, Any?>): WrapperResult<String> {
return parse(map) {
it.assertValue<String>(key = KEY_TYPE, value = TYPE_WORKER_HANDLE)
it
.get<String>(KEY_VALUE)
.getOrThrow()
}
}

fun serializeDeviceId(deviceId: String): Map<String, Any?> {
return mapOf(
KEY_TYPE to TYPE_DEVICE_ID,
Expand Down Expand Up @@ -206,6 +215,13 @@ internal object Serialization {
)
}

fun serializeWorkerHandle(workerHandle: String): Map<String, Any?> {
return mapOf(
KEY_TYPE to TYPE_WORKER_HANDLE,
KEY_VALUE to workerHandle,
)
}

private fun deserializeLocation(map: Map<String, Any?>): WrapperResult<Location> {
return parse(map) {
it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
Expand Down Expand Up @@ -397,10 +413,11 @@ internal object Serialization {
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_METADATA = "metadata"
private const val TYPE_NAME = "name"
private const val TYPE_WORKER_HANDLE = "workerHandle"

private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning"
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ee710d5

Please sign in to comment.