@mentra/bluetooth-sdk 3.3.0-dev.944 → 3.4.0-dev.1003

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.
Files changed (100) hide show
  1. package/MIGRATION.md +61 -0
  2. package/README.md +78 -0
  3. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +274 -0
  4. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +13 -3
  5. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +8 -1
  6. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +79 -8
  7. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
  8. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
  9. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  10. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +22 -4
  11. package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
  12. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
  14. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +832 -134
  15. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +337 -39
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +8 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +1 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
  25. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +16 -0
  26. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
  27. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
  28. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
  29. package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
  30. package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
  31. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
  32. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
  33. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
  34. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
  35. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
  36. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
  37. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +564 -1
  38. package/build/BluetoothSdk.types.d.ts +110 -2
  39. package/build/BluetoothSdk.types.d.ts.map +1 -1
  40. package/build/BluetoothSdk.types.js.map +1 -1
  41. package/build/_private/BluetoothSdkModule.d.ts +6 -2
  42. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  43. package/build/_private/BluetoothSdkModule.js +1 -0
  44. package/build/_private/BluetoothSdkModule.js.map +1 -1
  45. package/build/generated/changelogCatalog.d.ts +3 -0
  46. package/build/generated/changelogCatalog.d.ts.map +1 -1
  47. package/build/generated/changelogCatalog.js +4 -0
  48. package/build/generated/changelogCatalog.js.map +1 -1
  49. package/build/generated/releaseMetadata.js +6 -6
  50. package/build/generated/releaseMetadata.js.map +1 -1
  51. package/build/index.d.ts +1 -1
  52. package/build/index.d.ts.map +1 -1
  53. package/build/index.js +4 -0
  54. package/build/index.js.map +1 -1
  55. package/ios/BluetoothSdkModule.swift +24 -4
  56. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  57. package/ios/Source/Bridge.swift +11 -3
  58. package/ios/Source/DeviceManager.swift +103 -7
  59. package/ios/Source/DeviceStore.swift +27 -0
  60. package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
  61. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  62. package/ios/Source/MentraBluetoothSDK.swift +41 -7
  63. package/ios/Source/TouchGesture.swift +13 -0
  64. package/ios/Source/errors/BluetoothSdkError.swift +5 -1
  65. package/ios/Source/events/BluetoothEvents.swift +4 -0
  66. package/ios/Source/internal/BleTraceLogger.swift +9 -6
  67. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +181 -0
  68. package/ios/Source/sgcs/MentraLive.swift +1196 -173
  69. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
  70. package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
  71. package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
  72. package/ios/Source/sgcs/Nimo.swift +278 -38
  73. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +77 -18
  74. package/ios/Source/sgcs/NimoCanvasSession.swift +1 -0
  75. package/ios/Source/sgcs/NimoMacResourceTransport.swift +217 -0
  76. package/ios/Source/sgcs/NimoResourceFixture.swift +384 -0
  77. package/ios/Source/sgcs/NimoResourceSession.swift +406 -0
  78. package/ios/Source/sgcs/SGCManager.swift +7 -0
  79. package/ios/Source/sgcs/Simulated.swift +2 -0
  80. package/ios/Source/status/DeviceStatus.swift +35 -0
  81. package/ios/Source/types/DeviceModels.swift +8 -1
  82. package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
  83. package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
  84. package/ios/Tests/DeviceManagerReconnectTests.swift +75 -2
  85. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +191 -0
  86. package/ios/Tests/MentraLiveAudioSetupTests.swift +215 -0
  87. package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
  88. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
  89. package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
  90. package/ios/Tests/MentraLiveSessionReadinessTests.swift +328 -26
  91. package/ios/Tests/NimoCanvasTransportTests.swift +147 -0
  92. package/ios/Tests/NimoResourceSessionTests.swift +476 -0
  93. package/ios/Tests/TouchGestureCommandTests.swift +87 -0
  94. package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
  95. package/package.json +3 -2
  96. package/src/BluetoothSdk.types.ts +115 -1
  97. package/src/_private/BluetoothSdkModule.ts +7 -1
  98. package/src/generated/changelogCatalog.ts +4 -0
  99. package/src/generated/releaseMetadata.ts +6 -6
  100. package/src/index.ts +12 -0
@@ -0,0 +1,121 @@
1
+ import Foundation
2
+
3
+ /// Process-wide owner of the `MentraLivePairingStateMachine`. It outlives each `MentraLive`
4
+ /// instance so a disconnect or SGC replacement keeps the pause and the rejection, persists the
5
+ /// record natively (never through the replayed settings), and publishes
6
+ /// `GlassesStatus.pairingState` plus `pairing_state_changed`. Mirrors Android
7
+ /// `MentraLivePairingStateStore`.
8
+ @MainActor
9
+ final class MentraLivePairingStateStore {
10
+ static let shared = MentraLivePairingStateStore()
11
+
12
+ /// The persisted record lives under one UserDefaults key; unknown inner keys are ignored.
13
+ static let defaultsKey = "mentra_live_pairing_v4"
14
+
15
+ private let defaults: UserDefaults
16
+ private let publishes: Bool
17
+ private var machine = MentraLivePairingStateMachine()
18
+ private var restored = false
19
+
20
+ /// `publishes == false` keeps tests away from DeviceStore and the bridge.
21
+ init(defaults: UserDefaults = .standard, publishes: Bool = true) {
22
+ self.defaults = defaults
23
+ self.publishes = publishes
24
+ }
25
+
26
+ var state: MentraLivePairingState { machine.state }
27
+ var allowsAutomaticReconnect: Bool { machine.allowsAutomaticReconnect }
28
+ var isPaused: Bool { machine.isPaused }
29
+ var isRejected: Bool { machine.state == .rejected }
30
+ var verificationArmed: Bool { machine.verificationArmed }
31
+ /// A window this phone paused for ended and its advertisement has not been read yet.
32
+ var awaitingTakeoverCheck: Bool { machine.awaitingTakeoverCheck }
33
+
34
+ func remainingPauseMs(nowMs: Int = MentraLivePairingStateStore.nowMs()) -> Int {
35
+ machine.remainingPauseMs(nowMs: nowMs)
36
+ }
37
+
38
+ /// Restore once per process. Later calls only republish the status field.
39
+ @discardableResult
40
+ func ensureRestored(savedDeviceId: String, nowMs: Int = MentraLivePairingStateStore.nowMs()) -> MentraLivePairingTransition? {
41
+ if restored {
42
+ publish(emitEvent: false)
43
+ return nil
44
+ }
45
+ restored = true
46
+ var values = defaults.dictionary(forKey: Self.defaultsKey) ?? [:]
47
+ for key in MentraLivePairingStateMachine.legacyKeys {
48
+ if let legacy = defaults.object(forKey: key) { values[key] = legacy }
49
+ }
50
+ let transition = machine.restore(values: values, savedDeviceId: savedDeviceId, nowMs: nowMs)
51
+ for key in MentraLivePairingStateMachine.legacyKeys {
52
+ defaults.removeObject(forKey: key)
53
+ }
54
+ persist()
55
+ publish()
56
+ Bridge.log("PAIRFLOW: pairing_state restore note=\(transition.note) state=\(describe())")
57
+ return transition
58
+ }
59
+
60
+ /// Run one machine input, persist the record, and publish when the public state changed.
61
+ @discardableResult
62
+ func update(
63
+ _ source: String,
64
+ _ input: (inout MentraLivePairingStateMachine) -> MentraLivePairingTransition
65
+ ) -> MentraLivePairingTransition {
66
+ let before = machine.state
67
+ let beforeRecord = machine.persisted() as NSDictionary
68
+ let transition = input(&machine)
69
+ // Duplicate-reporting scans feed every advertisement through here.
70
+ if !beforeRecord.isEqual(to: machine.persisted()) { persist() }
71
+ if machine.state != before { publish() }
72
+ if transition.effect != .none || machine.state != before {
73
+ Bridge.log(
74
+ "PAIRFLOW: pairing_state source=\(source) effect=\(transition.effect) note=\(transition.note) state=\(describe())"
75
+ )
76
+ }
77
+ return transition
78
+ }
79
+
80
+ func describe() -> String {
81
+ switch machine.state {
82
+ case .normal: return "normal"
83
+ case let .pairingMode(windowId, endsAtMs): return "pairing_mode(window=\(windowId), endsAtMs=\(endsAtMs))"
84
+ case .rejected: return "pairing_rejected"
85
+ }
86
+ }
87
+
88
+ /// Drops the in-memory state as a process restart would. Persisted values stay.
89
+ func resetForTest() {
90
+ machine = MentraLivePairingStateMachine()
91
+ restored = false
92
+ }
93
+
94
+ nonisolated static func nowMs() -> Int {
95
+ Int(Date().timeIntervalSince1970 * 1000)
96
+ }
97
+
98
+ private func persist() {
99
+ var stored = defaults.dictionary(forKey: Self.defaultsKey) ?? [:]
100
+ for key in MentraLivePairingStateMachine.keys {
101
+ stored.removeValue(forKey: key)
102
+ }
103
+ for (key, value) in machine.persisted() {
104
+ stored[key] = value
105
+ }
106
+ if stored.isEmpty {
107
+ defaults.removeObject(forKey: Self.defaultsKey)
108
+ } else {
109
+ defaults.set(stored, forKey: Self.defaultsKey)
110
+ }
111
+ }
112
+
113
+ private func publish(emitEvent: Bool = true) {
114
+ guard publishes else { return }
115
+ let map = machine.state.toMap()
116
+ DeviceStore.shared.apply("glasses", "pairingState", map)
117
+ if emitEvent {
118
+ Bridge.sendTypedMessage("pairing_state_changed", body: ["state": map])
119
+ }
120
+ }
121
+ }