react-native-polar-bridge 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
17
17
  s.private_header_files = "ios/**/*.h"
18
18
 
19
- s.dependency 'PolarBleSdk', '~> 6.4.0'
19
+ s.dependency 'PolarBleSdk', '~> 6.14.0'
20
20
 
21
21
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
22
22
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
@@ -93,7 +93,7 @@ dependencies {
93
93
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
94
94
  implementation 'io.reactivex.rxjava3:rxjava:3.1.11'
95
95
  implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
96
- implementation 'com.github.polarofficial:polar-ble-sdk:6.4.0'
96
+ implementation 'com.github.polarofficial:polar-ble-sdk:6.14.0'
97
97
  }
98
98
 
99
99
  react {
@@ -1,5 +1,5 @@
1
1
  PolarBridge_kotlinVersion=2.0.21
2
- PolarBridge_minSdkVersion=24
2
+ PolarBridge_minSdkVersion=26
3
3
  PolarBridge_targetSdkVersion=34
4
4
  PolarBridge_compileSdkVersion=35
5
5
  PolarBridge_ndkVersion=27.1.12297006
@@ -18,7 +18,7 @@ import io.reactivex.rxjava3.core.Single
18
18
  import java.util.*
19
19
  import java.util.concurrent.atomic.AtomicInteger
20
20
  import java.util.concurrent.TimeUnit
21
- import java.time.Instant
21
+ import java.time.*
22
22
 
23
23
  @ReactModule(name = PolarBridgeModule.NAME)
24
24
  class PolarBridgeModule(reactContext: ReactApplicationContext) :
@@ -65,13 +65,13 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
65
65
 
66
66
  override fun connectToDevice(deviceId: String, promise: Promise) {
67
67
  val map: WritableMap = Arguments.createMap()
68
- var deviceConnected = false
69
- var batteryReceived = false
68
+ var connectedId: String? = null
69
+ var battery: Int? = null
70
+ var isResolved = false // Guard to ensure we only resolve once
70
71
  api.setApiCallback(object : PolarBleApiCallback() {
71
72
  override fun deviceConnected(polarDeviceInfo: PolarDeviceInfo) {
72
73
  Log.d("Polar", "Connected: ${polarDeviceInfo.deviceId}")
73
- map.putString("connectedDeviceId", polarDeviceInfo.deviceId)
74
- deviceConnected = true
74
+ connectedId = polarDeviceInfo.deviceId
75
75
  runResolve()
76
76
  }
77
77
 
@@ -88,13 +88,14 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
88
88
 
89
89
  override fun batteryLevelReceived(identifier: String, level: Int) {
90
90
  Log.d("Polar", "Battery for $identifier: $level%")
91
- map.putInt("batteryLevel", level)
92
- batteryReceived = true
91
+ battery = level
93
92
  runResolve()
94
93
  }
95
94
 
96
95
  private fun runResolve() {
97
- if (deviceConnected && batteryReceived) {
96
+ if (connectedId != null && battery != null && !isResolved) {
97
+ map.putString("connectedDeviceId", connectedId)
98
+ map.putInt("batteryLevel", battery)
98
99
  promise.resolve(map)
99
100
  }
100
101
  }
@@ -210,7 +211,9 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
210
211
  )
211
212
 
212
213
  val map: WritableMap = Arguments.createMap()
213
- map.putDouble("recTimestamp", polarOfflineRecordingEntry.date.time.toDouble())
214
+ map.putDouble("recTimestamp", polarOfflineRecordingEntry.date
215
+ .toInstant(ZoneOffset.UTC)
216
+ .toEpochMilli().toDouble())
214
217
  map.putString("path", polarOfflineRecordingEntry.path)
215
218
  map.putDouble("size", polarOfflineRecordingEntry.size.toDouble())
216
219
  array.pushMap(map)
@@ -373,10 +376,14 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
373
376
  Log.d(TAG, "Recording ${polarOfflineRecordingEntry.path} downloaded. Size: ${polarOfflineRecordingEntry.size}")
374
377
  when (it) {
375
378
  is PolarOfflineRecordingData.HrOfflineRecording -> {
376
- Log.d(TAG, "HR Offline Recording started at ${it.startTime.time}")
379
+ Log.d(TAG, "HR Offline Recording started at ${it.startTime
380
+ .toInstant(ZoneOffset.UTC)
381
+ .toEpochMilli()}")
377
382
  var index = 0;
378
383
  val intervalInMs = 1000; // 1Hz
379
- val firstSampleDateUTC = it.startTime.timeInMillis + intervalInMs
384
+ val firstSampleDateUTC = it.startTime
385
+ .toInstant(ZoneOffset.UTC)
386
+ .toEpochMilli() + intervalInMs
380
387
  for (sample in it.data.samples) {
381
388
  val unixTimestamp = firstSampleDateUTC + intervalInMs * index++;
382
389
  val timestamp = Instant.ofEpochMilli(unixTimestamp)
@@ -393,7 +400,8 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
393
400
  }
394
401
  }
395
402
  is PolarOfflineRecordingData.AccOfflineRecording -> {
396
- Log.d(TAG, "ACC Offline Recording started at ${it.startTime.time}")
403
+ Log.d(TAG, "ACC Offline Recording started at ${it.startTime.toInstant(ZoneOffset.UTC)
404
+ .toEpochMilli()}")
397
405
  var index = 0;
398
406
  for (sample in it.data.samples) {
399
407
  Log.d(TAG, "ACC data: time: ${sample.timeStamp} X: ${sample.x} Y: ${sample.y} Z: ${sample.z} entry ${++index} of ${it.data.samples.size}")
@@ -409,7 +417,8 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
409
417
  }
410
418
  }
411
419
  is PolarOfflineRecordingData.GyroOfflineRecording -> {
412
- Log.d(TAG, "GYRO Offline Recording started at ${it.startTime.time}")
420
+ Log.d(TAG, "GYRO Offline Recording started at ${it.startTime.toInstant(ZoneOffset.UTC)
421
+ .toEpochMilli()}")
413
422
  var index = 0;
414
423
  for (sample in it.data.samples) {
415
424
  Log.d(TAG, "GYRO data: ${sample.timeStamp} X: ${sample.x} Y: ${sample.y} Z: ${sample.z} entry ${++index} of ${it.data.samples.size}")
@@ -425,7 +434,8 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
425
434
  }
426
435
  }
427
436
  is PolarOfflineRecordingData.PpgOfflineRecording -> {
428
- Log.d(TAG, "PPG Offline Recording started at ${it.startTime.time}")
437
+ Log.d(TAG, "PPG Offline Recording started at ${it.startTime.toInstant(ZoneOffset.UTC)
438
+ .toEpochMilli()}")
429
439
  var index = 0;
430
440
  for (sample in it.data.samples) {
431
441
  Log.d(TAG, "PPG data: ${sample.timeStamp} ppg0 ${sample.channelSamples[0]} ppg1 ${sample.channelSamples[1]} ppg2 ${sample.channelSamples[2]} ambient ${sample.channelSamples[3]} entry ${++index} of ${it.data.samples.size}")
@@ -505,15 +515,14 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
505
515
 
506
516
  // Sets the date time on the Polar device
507
517
  override fun setDeviceTime(deviceId: String) {
508
- val calendar = Calendar.getInstance()
509
- calendar.time = Date()
510
- Log.e(TAG, "Set device: $deviceId time to ${calendar.time}")
518
+ val now = LocalDateTime.now(ZoneOffset.UTC)
519
+ Log.e(TAG, "Set device: $deviceId time to ${now}")
511
520
  try {
512
- api.setLocalTime(deviceId, calendar)
521
+ api.setLocalTime(deviceId, now)
513
522
  .observeOn(AndroidSchedulers.mainThread())
514
523
  .subscribe(
515
524
  {
516
- val timeSetString = "time ${calendar.time} set to device"
525
+ val timeSetString = "time ${now} set to device"
517
526
  Log.d(TAG, timeSetString)
518
527
  },
519
528
  { error: Throwable -> Log.e(TAG, "set time failed: $error") }
@@ -529,13 +538,14 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
529
538
  .observeOn(AndroidSchedulers.mainThread())
530
539
  .subscribe(
531
540
  { calendar ->
532
- val timeGetString = "${calendar.time} read from the device"
541
+ val timeGetString = "${calendar} read from the device"
533
542
 
534
543
  val map: WritableMap = Arguments.createMap()
535
- map.putString("time", "${calendar.time}")
544
+ map.putString("time", "${calendar.toInstant(ZoneOffset.UTC)}")
536
545
  // Long not supported, use double as workaround
537
546
  // See: https://github.com/facebook/react-native/issues/9685
538
- map.putDouble("timeMs", calendar.timeInMillis.toDouble())
547
+ map.putDouble("timeMs", calendar.toInstant(ZoneOffset.UTC)
548
+ .toEpochMilli().toDouble())
539
549
  promise.resolve(map)
540
550
  },
541
551
  { error: Throwable ->
@@ -567,9 +577,6 @@ class PolarBridgeModule(reactContext: ReactApplicationContext) :
567
577
  }
568
578
 
569
579
  override fun doFactoryReset(deviceId: String) {
570
- val calendar = Calendar.getInstance()
571
- calendar.time = Date()
572
- Log.e(TAG, "Set device: $deviceId time to ${calendar.time}")
573
580
  try {
574
581
  api.doFactoryReset(deviceId, preservePairingInformation = true)
575
582
  .observeOn(AndroidSchedulers.mainThread())
@@ -132,7 +132,7 @@ class PolarBridge: RCTEventEmitter, ObservableObject
132
132
  let allSettings = api.requestFullStreamSettings(identifier, feature: feature)
133
133
  .catch { error in
134
134
  NSLog("Full stream settings NOT available for \(feature). Reason: \(error.localizedDescription)")
135
- return Single.just(PolarSensorSetting([:]))
135
+ return Single.just(try PolarSensorSetting([:]))
136
136
  }
137
137
 
138
138
  return Single.zip(availableSettings, allSettings)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-polar-bridge",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Polar SDK for React Native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",