expo-beacon 0.7.22 → 0.7.24

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.
@@ -10,8 +10,10 @@ interface BeaconEventPlugin {
10
10
  // iBeacon
11
11
  fun onBeaconEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
12
12
  fun onBeaconExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
13
+ fun onBeaconTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
13
14
 
14
15
  // Eddystone
15
16
  fun onEddystoneEnter(identifier: String, namespace: String, instance: String, distance: Double)
16
17
  fun onEddystoneExit(identifier: String, namespace: String, instance: String, distance: Double)
18
+ fun onEddystoneTimeout(identifier: String, namespace: String, instance: String, distance: Double)
17
19
  }
@@ -628,18 +628,18 @@ class BeaconForegroundService : Service(), BeaconConsumer {
628
628
  // Forward all produced events to remote API
629
629
  apiForwarder?.forwardEvent(params)
630
630
 
631
- // Dispatch enter/exit to registered plugins (e.g. to start/stop BGLocation)
632
- if (eventType == "enter" || eventType == "exit") {
631
+ // Dispatch enter/exit/timeout to registered plugins (e.g. to start/stop BGLocation)
632
+ if (eventType == "enter" || eventType == "exit" || eventType == "timeout") {
633
633
  val identifier = region.uniqueId
634
634
  val uuid = if (!isEddystone) id1Str else ""
635
635
  val major = if (!isEddystone) region.id2?.toInt() ?: 0 else 0
636
636
  val minor = if (!isEddystone) region.id3?.toInt() ?: 0 else 0
637
637
  val namespace = if (isEddystone) id1Str.removePrefix("0x") else ""
638
638
  val instance = if (isEddystone) region.id2?.toString()?.removePrefix("0x") ?: "" else ""
639
- if (eventType == "enter") {
640
- BeaconPluginRegistry.dispatchEnter(isEddystone, identifier, uuid, major, minor, namespace, instance, distance)
641
- } else {
642
- BeaconPluginRegistry.dispatchExit(isEddystone, identifier, uuid, major, minor, namespace, instance, distance)
639
+ when (eventType) {
640
+ "enter" -> BeaconPluginRegistry.dispatchEnter(isEddystone, identifier, uuid, major, minor, namespace, instance, distance)
641
+ "exit" -> BeaconPluginRegistry.dispatchExit(isEddystone, identifier, uuid, major, minor, namespace, instance, distance)
642
+ "timeout" -> BeaconPluginRegistry.dispatchTimeout(isEddystone, identifier, uuid, major, minor, namespace, instance, distance)
643
643
  }
644
644
  }
645
645
 
@@ -58,4 +58,23 @@ object BeaconPluginRegistry {
58
58
  }
59
59
  }
60
60
  }
61
+
62
+ internal fun dispatchTimeout(
63
+ isEddystone: Boolean,
64
+ identifier: String,
65
+ uuid: String,
66
+ major: Int,
67
+ minor: Int,
68
+ namespace: String,
69
+ instance: String,
70
+ distance: Double,
71
+ ) {
72
+ plugins.forEach { plugin ->
73
+ if (isEddystone) {
74
+ plugin.onEddystoneTimeout(identifier, namespace, instance, distance)
75
+ } else {
76
+ plugin.onBeaconTimeout(identifier, uuid, major, minor, distance)
77
+ }
78
+ }
79
+ }
61
80
  }
@@ -9,10 +9,12 @@ public protocol BeaconLifecycleDelegate: AnyObject {
9
9
  // MARK: iBeacon
10
10
  func beaconDidEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
11
11
  func beaconDidExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
12
+ func beaconDidTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double)
12
13
 
13
14
  // MARK: Eddystone
14
15
  func eddystoneDidEnter(identifier: String, namespace: String, instance: String, distance: Double)
15
16
  func eddystoneDidExit(identifier: String, namespace: String, instance: String, distance: Double)
17
+ func eddystoneDidTimeout(identifier: String, namespace: String, instance: String, distance: Double)
16
18
  }
17
19
 
18
20
  /// Thread-safe registry for [BeaconLifecycleDelegate] plugins.
@@ -46,6 +48,12 @@ public final class BeaconLifecycleRegistry {
46
48
  internal func dispatchEddystoneExit(identifier: String, namespace: String, instance: String, distance: Double) {
47
49
  snapshot().forEach { $0.eddystoneDidExit(identifier: identifier, namespace: namespace, instance: instance, distance: distance) }
48
50
  }
51
+ internal func dispatchBeaconTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
52
+ snapshot().forEach { $0.beaconDidTimeout(identifier: identifier, uuid: uuid, major: major, minor: minor, distance: distance) }
53
+ }
54
+ internal func dispatchEddystoneTimeout(identifier: String, namespace: String, instance: String, distance: Double) {
55
+ snapshot().forEach { $0.eddystoneDidTimeout(identifier: identifier, namespace: namespace, instance: instance, distance: distance) }
56
+ }
49
57
 
50
58
  private func snapshot() -> [any BeaconLifecycleDelegate] {
51
59
  lock.lock(); defer { lock.unlock() }
@@ -1066,6 +1066,14 @@ public class ExpoBeaconModule: Module {
1066
1066
  minor: params["minor"] as? Int ?? 0,
1067
1067
  distance: distance
1068
1068
  )
1069
+ case "onBeaconTimeout":
1070
+ r.dispatchBeaconTimeout(
1071
+ identifier: identifier,
1072
+ uuid: params["uuid"] as? String ?? "",
1073
+ major: params["major"] as? Int ?? 0,
1074
+ minor: params["minor"] as? Int ?? 0,
1075
+ distance: distance
1076
+ )
1069
1077
  case "onEddystoneEnter":
1070
1078
  r.dispatchEddystoneEnter(
1071
1079
  identifier: identifier,
@@ -1080,6 +1088,13 @@ public class ExpoBeaconModule: Module {
1080
1088
  instance: params["instance"] as? String ?? "",
1081
1089
  distance: distance
1082
1090
  )
1091
+ case "onEddystoneTimeout":
1092
+ r.dispatchEddystoneTimeout(
1093
+ identifier: identifier,
1094
+ namespace: params["namespace"] as? String ?? "",
1095
+ instance: params["instance"] as? String ?? "",
1096
+ distance: distance
1097
+ )
1083
1098
  default:
1084
1099
  break
1085
1100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-beacon",
3
- "version": "0.7.22",
3
+ "version": "0.7.24",
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,EAAE,YAAY,EAAoB,MAAM,sBAAsB,CAAC;AAMtE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA0BlE;AAqCD,QAAA,MAAM,iBAAiB,EAAE,YA0DxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"withBeaconAndroid.d.ts","sourceRoot":"","sources":["../src/withBeaconAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,sBAAsB,CAAC;AAMtE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA8BlE;AAqCD,QAAA,MAAM,iBAAiB,EAAE,YA0DxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -25,10 +25,14 @@ class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
25
25
  bgGeo.start(noOp)
26
26
  override fun onBeaconExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
27
27
  bgGeo.stop(noOp)
28
+ override fun onBeaconTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
29
+ bgGeo.stop(noOp)
28
30
  override fun onEddystoneEnter(identifier: String, namespace: String, instance: String, distance: Double) =
29
31
  bgGeo.start(noOp)
30
32
  override fun onEddystoneExit(identifier: String, namespace: String, instance: String, distance: Double) =
31
33
  bgGeo.stop(noOp)
34
+ override fun onEddystoneTimeout(identifier: String, namespace: String, instance: String, distance: Double) =
35
+ bgGeo.stop(noOp)
32
36
  }
33
37
  `;
34
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsC,MAAM,sBAAsB,CAAC;AAMxF,wBAAgB,iBAAiB,IAAI,MAAM,CAoB1C;AA+ED,QAAA,MAAM,aAAa,EAAE,YAmEpB,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsC,MAAM,sBAAsB,CAAC;AAMxF,wBAAgB,iBAAiB,IAAI,MAAM,CA0B1C;AA+ED,QAAA,MAAM,aAAa,EAAE,YAmEpB,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -12,16 +12,22 @@ import TSLocationManager
12
12
 
13
13
  final class BeaconGeoPlugin: BeaconLifecycleDelegate {
14
14
  func beaconDidEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
15
- BackgroundGeolocation.sharedInstance().start({ _ in }, failure: { _ in })
15
+ BackgroundGeolocation.sharedInstance().start()
16
16
  }
17
17
  func beaconDidExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
18
- BackgroundGeolocation.sharedInstance().stop({ _ in }, failure: { _ in })
18
+ BackgroundGeolocation.sharedInstance().stop()
19
+ }
20
+ func beaconDidTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
21
+ BackgroundGeolocation.sharedInstance().stop()
19
22
  }
20
23
  func eddystoneDidEnter(identifier: String, namespace: String, instance: String, distance: Double) {
21
- BackgroundGeolocation.sharedInstance().start({ _ in }, failure: { _ in })
24
+ BackgroundGeolocation.sharedInstance().start()
22
25
  }
23
26
  func eddystoneDidExit(identifier: String, namespace: String, instance: String, distance: Double) {
24
- BackgroundGeolocation.sharedInstance().stop({ _ in }, failure: { _ in })
27
+ BackgroundGeolocation.sharedInstance().stop()
28
+ }
29
+ func eddystoneDidTimeout(identifier: String, namespace: String, instance: String, distance: Double) {
30
+ BackgroundGeolocation.sharedInstance().stop()
25
31
  }
26
32
  }
27
33
  `;