spotny-sdk 1.0.21 → 1.0.22

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.
@@ -99,6 +99,8 @@ public class SpotnyBeaconScanner: NSObject {
99
99
  private var campaignFetchCooldown: [String: Date] = [:] // backoff after failed fetch
100
100
  // 410 from /track means backend session expired — stop sending heartbeats until next NEARBY
101
101
  private var impressionDisabled: [String: Bool] = [:]
102
+ // Last time each beacon was seen in a ranging callback — used to detect slow drift exits
103
+ private var beaconLastSeen: [String: Date] = [:]
102
104
 
103
105
  // MARK: - Init
104
106
 
@@ -757,6 +759,7 @@ public class SpotnyBeaconScanner: NSObject {
757
759
  campaignFetched.removeValue(forKey: key)
758
760
  campaignFetchCooldown.removeValue(forKey: key)
759
761
  impressionDisabled.removeValue(forKey: key)
762
+ beaconLastSeen.removeValue(forKey: key)
760
763
  print("🧹 SpotnySDK: Cleaned up \(key)")
761
764
  }
762
765
 
@@ -853,7 +856,9 @@ extension SpotnyBeaconScanner: KTKBeaconManagerDelegate {
853
856
  lastProximityDistance[key] = distance
854
857
  lastProximityEventSent[key] = now
855
858
  }
856
-
859
+
860
+ beaconLastSeen[key] = now
861
+
857
862
  // Fetch campaign when distance <= 3m
858
863
  if distance <= 3.0 && campaignFetched[key] != true {
859
864
  fetchCampaign(key: key, major: major, minor: minor)
@@ -872,13 +877,24 @@ extension SpotnyBeaconScanner: KTKBeaconManagerDelegate {
872
877
  }
873
878
  }
874
879
  }
880
+
881
+ // Slow-drift exit detection — beacon disappeared from ranging without a region exit
882
+ let beaconExitTimeout: TimeInterval = 5.0
883
+ for key in Array(lastProximityEventSent.keys) {
884
+ guard let lastSeen = beaconLastSeen[key] else {
885
+ beaconLastSeen[key] = now; continue
886
+ }
887
+ if now.timeIntervalSince(lastSeen) >= beaconExitTimeout {
888
+ cleanupBeacon(key)
889
+ }
890
+ }
875
891
  }
876
892
 
877
893
  public func beaconManager(_ manager: KTKBeaconManager, didEnter region: KTKBeaconRegion) {
878
894
  print("🎯 SpotnySDK: Entered region \(region.identifier)")
879
895
  eventCallback?("onBeaconRegionEvent", ["region": region.identifier, "event": "enter"])
880
- // FIX #1: use helper — avoids defer capturing bg by value
881
- extendBackgroundTime(duration: 3.0)
896
+ extendBackgroundTime(duration: 30.0)
897
+ beaconManager.startRangingBeacons(in: region)
882
898
  }
883
899
 
884
900
  public func beaconManager(_ manager: KTKBeaconManager, didExitRegion region: KTKBeaconRegion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spotny-sdk",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Beacon Scanner",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",