expo-beacon 0.10.6 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-beacon",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "description": "Expo module for scanning, pairing, and monitoring iBeacons on Android and iOS",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1 +1 @@
1
- {"version":3,"file":"withBeaconAndroid.d.ts","sourceRoot":"","sources":["../src/withBeaconAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE;QACZ;2EACmE;QACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;qCAC6B;QAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;KAChC,CAAC;CACH,CAAC;AAIF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAsDlE;AAoMD,QAAA,MAAM,iBAAiB,EAAE,YAAY,CAAC,wBAAwB,GAAG,IAAI,CA0BpE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"withBeaconAndroid.d.ts","sourceRoot":"","sources":["../src/withBeaconAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAGZ,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG;IACtC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE;QACb;2EACmE;QACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;qCAC6B;QAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;KAC/B,CAAC;CACF,CAAC;AAIF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAmFlE;AAoMD,QAAA,MAAM,iBAAiB,EAAE,YAAY,CAAC,wBAAwB,GAAG,IAAI,CA0BpE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -10,6 +10,8 @@ function getAndroidPluginKotlin(packageName) {
10
10
  package ${packageName}
11
11
 
12
12
  import android.content.Context
13
+ import android.os.Handler
14
+ import android.os.Looper
13
15
  import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation
14
16
  import com.transistorsoft.locationmanager.adapter.callback.TSCallback
15
17
  import com.transistorsoft.locationmanager.adapter.callback.TSSyncCallback
@@ -27,6 +29,12 @@ class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
27
29
  override fun onFailure(error: String) {}
28
30
  }
29
31
 
32
+ // CarPlay disconnect uses a grace period: flush immediately, but defer the
33
+ // actual stop() so a quick reconnect (brief dropout) keeps tracking alive.
34
+ private val mainHandler = Handler(Looper.getMainLooper())
35
+ private var pendingCarPlayStop: Runnable? = null
36
+ private val carPlayStopDelayMs = 30_000L
37
+
30
38
  private fun startTracking() {
31
39
  bgGeo.start(noOp)
32
40
  bgGeo.changePace(true, noOp)
@@ -38,6 +46,25 @@ class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
38
46
  bgGeo.stop(noOp)
39
47
  }
40
48
 
49
+ // Flush queued locations right away, then stop tracking after a grace
50
+ // period. Cancelled by cancelPendingCarPlayStop() if CarPlay reconnects.
51
+ private fun stopTrackingForCarPlay() {
52
+ bgGeo.sync(noOpSync)
53
+ bgGeo.changePace(false, noOp)
54
+ cancelPendingCarPlayStop()
55
+ val stop = Runnable {
56
+ pendingCarPlayStop = null
57
+ bgGeo.stop(noOp)
58
+ }
59
+ pendingCarPlayStop = stop
60
+ mainHandler.postDelayed(stop, carPlayStopDelayMs)
61
+ }
62
+
63
+ private fun cancelPendingCarPlayStop() {
64
+ pendingCarPlayStop?.let { mainHandler.removeCallbacks(it) }
65
+ pendingCarPlayStop = null
66
+ }
67
+
41
68
  override fun onBeaconEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
42
69
  startTracking()
43
70
  override fun onBeaconExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
@@ -50,12 +77,14 @@ class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
50
77
  stopTracking()
51
78
  override fun onEddystoneTimeout(identifier: String, namespace: String, instance: String, distance: Double) =
52
79
  stopTracking()
53
- // Start tracking when the device connects to Android Auto, stop when it disconnects.
80
+ // Start tracking when the device connects to Android Auto; stop (after a
81
+ // grace period) when it disconnects.
54
82
  override fun onCarPlayConnected(transport: String) {
83
+ cancelPendingCarPlayStop()
55
84
  startTracking()
56
85
  }
57
86
  override fun onCarPlayDisconnected() {
58
- stopTracking()
87
+ stopTrackingForCarPlay()
59
88
  }
60
89
  }
61
90
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,CA6C1C;AA2KD,QAAA,MAAM,aAAa,EAAE,YAAY,CAAC,oBAAoB,GAAG,IAAI,CAgC5D,CAAC;AA6CF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EAKZ,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IAClC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,CAsE1C;AA2KD,QAAA,MAAM,aAAa,EAAE,YAAY,CAAC,oBAAoB,GAAG,IAAI,CAgC5D,CAAC;AA6CF,eAAe,aAAa,CAAC"}
@@ -11,6 +11,11 @@ import ExpoBeacon
11
11
  import TSLocationManager
12
12
 
13
13
  final class BeaconGeoPlugin: BeaconLifecycleDelegate {
14
+ // CarPlay disconnect uses a grace period: flush immediately, but defer the
15
+ // actual stop() so a quick reconnect (brief dropout) keeps tracking alive.
16
+ private var pendingCarPlayStop: DispatchWorkItem?
17
+ private let carPlayStopDelay: TimeInterval = 30
18
+
14
19
  private func startTracking() {
15
20
  BackgroundGeolocation.sharedInstance().start()
16
21
  BackgroundGeolocation.sharedInstance().changePace(true)
@@ -22,6 +27,25 @@ final class BeaconGeoPlugin: BeaconLifecycleDelegate {
22
27
  BackgroundGeolocation.sharedInstance().stop()
23
28
  }
24
29
 
30
+ // Flush queued locations right away, then stop tracking after a grace
31
+ // period. Cancelled by cancelPendingCarPlayStop() if CarPlay reconnects.
32
+ private func stopTrackingForCarPlay() {
33
+ BackgroundGeolocation.sharedInstance().sync({ _ in }, failure: { _ in })
34
+ BackgroundGeolocation.sharedInstance().changePace(false)
35
+ cancelPendingCarPlayStop()
36
+ let work = DispatchWorkItem { [weak self] in
37
+ self?.pendingCarPlayStop = nil
38
+ BackgroundGeolocation.sharedInstance().stop()
39
+ }
40
+ pendingCarPlayStop = work
41
+ DispatchQueue.main.asyncAfter(deadline: .now() + carPlayStopDelay, execute: work)
42
+ }
43
+
44
+ private func cancelPendingCarPlayStop() {
45
+ pendingCarPlayStop?.cancel()
46
+ pendingCarPlayStop = nil
47
+ }
48
+
25
49
  func beaconDidEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
26
50
  startTracking()
27
51
  }
@@ -40,13 +64,14 @@ final class BeaconGeoPlugin: BeaconLifecycleDelegate {
40
64
  func eddystoneDidTimeout(identifier: String, namespace: String, instance: String, distance: Double) {
41
65
  stopTracking()
42
66
  }
43
- // Start tracking when the device connects to CarPlay (wired or wireless),
44
- // stop when it disconnects.
67
+ // Start tracking when the device connects to CarPlay (wired or wireless);
68
+ // stop (after a grace period) when it disconnects.
45
69
  func carPlayDidConnect(transport: String) {
70
+ cancelPendingCarPlayStop()
46
71
  startTracking()
47
72
  }
48
73
  func carPlayDidDisconnect() {
49
- stopTracking()
74
+ stopTrackingForCarPlay()
50
75
  }
51
76
  }
52
77
  `;