@mentra/glasses-media 3.5.0-dev.1369 → 3.5.0-dev.1372

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.
@@ -5,6 +5,11 @@ import ObjectiveC
5
5
  /// Blocking public CoreWLAN calls are isolated here; the existing hotspot owner
6
6
  /// retains custody until they return, even after cancellation or a timeout.
7
7
  final class MacHotspotAssociation {
8
+ /// Rejoining the hotspot seconds after leaving it, as between an update's passes, can be refused while the
9
+ /// glasses still hold the Mac's previous association (-3912). A later attempt in the same window succeeds.
10
+ static let associationAttempts = 3
11
+ static let associationRetryDelay: TimeInterval = 2
12
+
8
13
  private let condition = NSCondition()
9
14
  private var cancelled = false
10
15
  private var interface: MacWifiInterface?
@@ -33,16 +38,26 @@ final class MacHotspotAssociation {
33
38
  try checkCurrent()
34
39
  let interface = try makeInterface()
35
40
  self.interface = interface
36
- if try readSSID(interface) != ssid {
41
+ for attempt in 1 ... Self.associationAttempts {
42
+ guard try readSSID(interface) != ssid else { break }
37
43
  let network = try discoverNetwork(ssid: ssid, interface: interface)
38
44
  try checkDiscoveryCurrent()
39
- if let network, try readSSID(interface) != ssid {
40
- try checkDiscoveryCurrent()
41
- try authorization?.requireCurrentAuthorization()
42
- // Record the intended association before this blocking call. A late
43
- // successful join still belongs to us and must be cleaned up.
44
- joinedSSID = ssid
45
+ guard let network, try readSSID(interface) != ssid else { break }
46
+ try checkDiscoveryCurrent()
47
+ try authorization?.requireCurrentAuthorization()
48
+ // Record the intended association before this blocking call. A late
49
+ // successful join still belongs to us and must be cleaned up.
50
+ joinedSSID = ssid
51
+ do {
45
52
  try interface.associate(network: network, password: password)
53
+ break
54
+ } catch {
55
+ // A refusal is retried with a fresh scan; cancellation, a lost Location
56
+ // authorization (rechecked by the next read) and the deadline end it.
57
+ if error is CancellationError || attempt == Self.associationAttempts { throw error }
58
+ try checkCurrent()
59
+ guard now() + Self.associationRetryDelay < deadline else { throw error }
60
+ wait(Self.associationRetryDelay)
46
61
  }
47
62
  }
48
63
  try checkCurrent()
@@ -98,17 +113,19 @@ final class MacHotspotAssociation {
98
113
  if try readSSID(interface) == ssid { return nil }
99
114
  if let network { return network }
100
115
  // Successful empty scans remain pending within this same join window.
101
- // Native scan errors escape immediately; association is never retried.
102
- let remaining = max(0, deadline - now())
103
- if let pause { pause(min(1, remaining)) }
104
- else {
105
- condition.lock()
106
- if !cancelled { _ = condition.wait(until: Date(timeIntervalSinceNow: min(1, remaining))) }
107
- condition.unlock()
108
- }
116
+ // Native scan errors escape immediately.
117
+ wait(min(1, max(0, deadline - now())))
109
118
  }
110
119
  }
111
120
 
121
+ /// Pause on the association worker; cancellation wakes it.
122
+ private func wait(_ seconds: TimeInterval) {
123
+ if let pause { pause(seconds); return }
124
+ condition.lock()
125
+ if !cancelled { _ = condition.wait(until: Date(timeIntervalSinceNow: seconds)) }
126
+ condition.unlock()
127
+ }
128
+
112
129
  private func checkDiscoveryCurrent() throws {
113
130
  try checkCurrent()
114
131
  guard now() < deadline else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/glasses-media",
3
- "version": "3.5.0-dev.1369",
3
+ "version": "3.5.0-dev.1372",
4
4
  "description": "Shared native glasses media receivers and local network transport",
5
5
  "license": "MIT",
6
6
  "author": "Mentra Community",
@@ -16,7 +16,7 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@mentra/bluetooth-sdk": "3.5.0-dev.1369"
19
+ "@mentra/bluetooth-sdk": "3.5.0-dev.1372"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "expo-modules-core": "~55.0.25"