@mentra/bluetooth-sdk 3.3.0-dev.943 → 3.3.0
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/README.md +31 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +4 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +8 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +77 -2
- package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +137 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +6 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +2 -1
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +1 -1
- package/build/generated/changelogCatalog.js +1 -1
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +8 -0
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +4 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +1 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +11 -0
- package/ios/Source/TouchGesture.swift +13 -0
- package/ios/Source/events/BluetoothEvents.swift +4 -0
- package/ios/Source/sgcs/MentraLive.swift +96 -23
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +129 -0
- package/ios/Tests/TouchGestureCommandTests.swift +87 -0
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +15 -0
- package/src/_private/BluetoothSdkModule.ts +2 -0
- package/src/generated/changelogCatalog.ts +1 -1
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +2 -0
|
@@ -1345,6 +1345,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1345
1345
|
if state == ConnTypes.DISCONNECTED {
|
|
1346
1346
|
resetPendingAckState(reason: "BLE session ended")
|
|
1347
1347
|
resetWireNegotiationState()
|
|
1348
|
+
resetReadinessExchange()
|
|
1348
1349
|
resetAncsRelayState()
|
|
1349
1350
|
// Queued writes are session-bound: transmitting them into the NEXT session
|
|
1350
1351
|
// (e.g. a stale handshake whose reply activates v2 before the new session
|
|
@@ -1603,6 +1604,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1603
1604
|
// the physical connection — so a first-seen sid after an upgrade OTA cannot be
|
|
1604
1605
|
// mistaken for a fresh pairing just because a not-ready heartbeat slipped in first.
|
|
1605
1606
|
private var readinessCompletedThisBleSession = false
|
|
1607
|
+
/// Readiness exchange the phone is waiting on. Every phone_ready carries it until the
|
|
1608
|
+
/// matching glasses_ready arrives, so retries and the copies the BES buffers while the
|
|
1609
|
+
/// glasses boot are one exchange: the glasses reset their transport once for it and answer
|
|
1610
|
+
/// later copies without resetting. Both exchange fields are scoped to the BLE session.
|
|
1611
|
+
private var pendingReadyId: String?
|
|
1612
|
+
/// `sid` of the glasses process whose glasses_ready this BLE session last handled.
|
|
1613
|
+
private var readyGlassesSessionId: String?
|
|
1606
1614
|
private var globalMessageId = 0
|
|
1607
1615
|
private var lastReceivedMessageId = 0
|
|
1608
1616
|
private var bleWriteTraceSequence = 0
|
|
@@ -2193,6 +2201,17 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2193
2201
|
return commands.removeFirst()
|
|
2194
2202
|
}
|
|
2195
2203
|
|
|
2204
|
+
/// Discards the run of writes from earlier wire-session generations at the head of
|
|
2205
|
+
/// the queue in one pass and dequeues the first current one. Stale writes are never
|
|
2206
|
+
/// sent, so they must not each cost a drain tick: a burst of epoch resets would
|
|
2207
|
+
/// otherwise park every current write behind seconds of dead entries.
|
|
2208
|
+
func dequeue(currentGeneration: Int) -> (command: PendingMessage?, staleIds: [String]) {
|
|
2209
|
+
let firstCurrent = commands.firstIndex { $0.generation == currentGeneration } ?? commands.endIndex
|
|
2210
|
+
let staleIds = commands[..<firstCurrent].map(\.id)
|
|
2211
|
+
commands.removeSubrange(..<firstCurrent)
|
|
2212
|
+
return (commands.isEmpty ? nil : commands.removeFirst(), staleIds)
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2196
2215
|
func removeAll() {
|
|
2197
2216
|
commands.removeAll()
|
|
2198
2217
|
}
|
|
@@ -2203,21 +2222,25 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2203
2222
|
guard let self else { return }
|
|
2204
2223
|
while true {
|
|
2205
2224
|
let pendingIsNil = await MainActor.run { self.pending == nil }
|
|
2206
|
-
if pendingIsNil {
|
|
2207
|
-
|
|
2208
|
-
let currentGeneration = await MainActor.run { self.wireSessionGeneration }
|
|
2209
|
-
if command.generation != currentGeneration {
|
|
2210
|
-
Bridge.log("LIVE: Dropping stale queued write from a previous session epoch (id: \(command.id))")
|
|
2211
|
-
} else {
|
|
2212
|
-
await self.processSendQueue(command)
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2225
|
+
if pendingIsNil, let command = await self.dequeueCurrentGenerationWrite() {
|
|
2226
|
+
await self.processSendQueue(command)
|
|
2215
2227
|
}
|
|
2216
2228
|
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
|
|
2217
2229
|
}
|
|
2218
2230
|
}
|
|
2219
2231
|
}
|
|
2220
2232
|
|
|
2233
|
+
private func dequeueCurrentGenerationWrite() -> PendingMessage? {
|
|
2234
|
+
let next = commandQueue.dequeue(currentGeneration: wireSessionGeneration)
|
|
2235
|
+
if !next.staleIds.isEmpty {
|
|
2236
|
+
Bridge.log(
|
|
2237
|
+
"LIVE: Dropping \(next.staleIds.count) stale queued write(s) from a previous session epoch " +
|
|
2238
|
+
"(ids: \(next.staleIds.joined(separator: ", ")))"
|
|
2239
|
+
)
|
|
2240
|
+
}
|
|
2241
|
+
return next.command
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2221
2244
|
private func processSendQueue(_ message: PendingMessage) async {
|
|
2222
2245
|
guard let peripheral = connectedPeripheral,
|
|
2223
2246
|
let txChar = txCharacteristic
|
|
@@ -2802,6 +2825,16 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2802
2825
|
Bridge.log("LIVE: Ignoring stale glasses_ready during pairing yield")
|
|
2803
2826
|
return
|
|
2804
2827
|
}
|
|
2828
|
+
let sid = (json["sid"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
2829
|
+
let readyId = (json["readyId"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
2830
|
+
if let readyId, isRepeatedGlassesReady(readyId: readyId, sid: sid) {
|
|
2831
|
+
Bridge.log("LIVE: Ignoring repeated glasses_ready for readiness exchange \(readyId) - the glasses did not reset for it")
|
|
2832
|
+
return
|
|
2833
|
+
}
|
|
2834
|
+
if readyId != nil, readyId == pendingReadyId {
|
|
2835
|
+
pendingReadyId = nil
|
|
2836
|
+
}
|
|
2837
|
+
readyGlassesSessionId = sid
|
|
2805
2838
|
// glasses_ready is a REMOTE wire-session reset: the glasses ran
|
|
2806
2839
|
// onTransportReset() before sending it, so their side is back on legacy
|
|
2807
2840
|
// framing regardless of what this side negotiated earlier. Start a fresh
|
|
@@ -2817,7 +2850,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2817
2850
|
// Record the session id BEFORE marking ready: an unsolicited glasses_ready
|
|
2818
2851
|
// already runs this full remote-reset flow, so recording (not re-triggering)
|
|
2819
2852
|
// is correct here; version_info detection covers the restart case.
|
|
2820
|
-
glassesSessionId =
|
|
2853
|
+
glassesSessionId = sid
|
|
2821
2854
|
streamControlVersion = json["streamControlVersion"] as? Int ?? 0
|
|
2822
2855
|
Bridge.sendTypedMessage(
|
|
2823
2856
|
"wifi_protocol_session_ready",
|
|
@@ -3341,6 +3374,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3341
3374
|
processAncsRelay(body)
|
|
3342
3375
|
}
|
|
3343
3376
|
|
|
3377
|
+
case "sr_tpdef":
|
|
3378
|
+
if let body = k900ParseBody(json["B"]), body["setting"] as? String == "touch_gesture_default" {
|
|
3379
|
+
emitSettingsAck(body)
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3344
3382
|
case "sr_hrt":
|
|
3345
3383
|
if let bodyObj = json["B"] as? [String: Any] {
|
|
3346
3384
|
let readyResponse = bodyObj["ready"] as? Int ?? 0
|
|
@@ -3383,12 +3421,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3383
3421
|
// This prevents re-initialization on every heartbeat after initial connection
|
|
3384
3422
|
// The ready flag is reset on disconnect/reconnect, so this won't prevent proper reconnection
|
|
3385
3423
|
if !fullyBooted {
|
|
3386
|
-
|
|
3387
|
-
"type": "phone_ready",
|
|
3388
|
-
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
3389
|
-
]
|
|
3390
|
-
// Send it through our data channel
|
|
3391
|
-
sendJson(readyMsg, wakeUp: true)
|
|
3424
|
+
sendPhoneReady(reason: "SOC ready")
|
|
3392
3425
|
}
|
|
3393
3426
|
}
|
|
3394
3427
|
}
|
|
@@ -3850,6 +3883,25 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3850
3883
|
sendJson(json, wakeUp: true)
|
|
3851
3884
|
}
|
|
3852
3885
|
|
|
3886
|
+
func sendTouchGestureDefaultBehaviorEnabled(requestId: String, gesture: TouchGesture, enabled: Bool) throws {
|
|
3887
|
+
guard connectedPeripheral != nil, txCharacteristic != nil else {
|
|
3888
|
+
throw BluetoothSdkError(code: "not_connected", message: "Mentra Live glasses are not connected.")
|
|
3889
|
+
}
|
|
3890
|
+
try sendTouchGestureDefaultCommand(requestId: requestId, gesture: gesture, enabled: enabled)
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
/// Kept separate from readiness admission so tests can replay the real K900 wire exchange.
|
|
3894
|
+
func sendTouchGestureDefaultCommand(requestId: String, gesture: TouchGesture, enabled: Bool) throws {
|
|
3895
|
+
let body = try JSONSerialization.data(withJSONObject: [
|
|
3896
|
+
"request_id": requestId, "gesture": gesture.rawValue, "enabled": enabled,
|
|
3897
|
+
])
|
|
3898
|
+
guard let bodyString = String(data: body, encoding: .utf8),
|
|
3899
|
+
sendRawK900Command(["C": "cs_tpdef", "V": 1, "B": bodyString])
|
|
3900
|
+
else {
|
|
3901
|
+
throw BluetoothSdkError(code: "command_send_failed", message: "Could not encode the touch gesture setting.")
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3853
3905
|
func sendGalleryServerEnabled(requestId: String, enabled: Bool) {
|
|
3854
3906
|
sendJson([
|
|
3855
3907
|
"type": "set_gallery_server_enabled",
|
|
@@ -3920,6 +3972,20 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3920
3972
|
|
|
3921
3973
|
// MARK: - Message Handlers
|
|
3922
3974
|
|
|
3975
|
+
/// A glasses_ready that echoes a readyId answers a phone_ready exchange. The answer to the
|
|
3976
|
+
/// exchange the phone is waiting on, and any answer from a glasses process other than the
|
|
3977
|
+
/// one this link last handled (an asg restart resets for every exchange it first sees),
|
|
3978
|
+
/// followed a transport reset. Any other answer repeats an exchange that process already
|
|
3979
|
+
/// reset for, or one superseded by the pending exchange, whose answer is still to come.
|
|
3980
|
+
private func isRepeatedGlassesReady(readyId: String, sid: String?) -> Bool {
|
|
3981
|
+
readyId != pendingReadyId && sid == readyGlassesSessionId
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
private func resetReadinessExchange() {
|
|
3985
|
+
pendingReadyId = nil
|
|
3986
|
+
readyGlassesSessionId = nil
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3923
3989
|
private func handleGlassesReady() {
|
|
3924
3990
|
Bridge.log("LIVE: 🎉 Received glasses_ready message - SOC is booted and ready!")
|
|
3925
3991
|
|
|
@@ -5772,12 +5838,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5772
5838
|
)
|
|
5773
5839
|
// requestReadyK900()
|
|
5774
5840
|
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
]
|
|
5779
|
-
|
|
5780
|
-
|
|
5841
|
+
// The timer fires on bluetoothQueue; the pending readiness exchange is main-actor state.
|
|
5842
|
+
// A tick queued just before glasses_ready stopped the loop must not start a new exchange.
|
|
5843
|
+
let check = self.readinessCheckCounter
|
|
5844
|
+
DispatchQueue.main.async { [weak self] in
|
|
5845
|
+
guard let self, self.readinessCheckDispatchTimer != nil else { return }
|
|
5846
|
+
self.sendPhoneReady(reason: "readiness check #\(check)")
|
|
5847
|
+
}
|
|
5781
5848
|
}
|
|
5782
5849
|
|
|
5783
5850
|
readinessCheckDispatchTimer!.resume()
|
|
@@ -6023,6 +6090,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6023
6090
|
// Stop all timers
|
|
6024
6091
|
stopAllTimers()
|
|
6025
6092
|
resetWireNegotiationState()
|
|
6093
|
+
resetReadinessExchange()
|
|
6026
6094
|
commandQueue.removeAll() // stale writes die with the session
|
|
6027
6095
|
closeL2capFileChannel()
|
|
6028
6096
|
|
|
@@ -6152,10 +6220,15 @@ extension MentraLive {
|
|
|
6152
6220
|
|
|
6153
6221
|
/// Sends phone_ready to (re)start the glasses-driven readiness flow.
|
|
6154
6222
|
private func sendPhoneReady(reason: String) {
|
|
6155
|
-
|
|
6223
|
+
let readyId = pendingReadyId ?? UUID().uuidString
|
|
6224
|
+
pendingReadyId = readyId
|
|
6225
|
+
Bridge.log(
|
|
6226
|
+
"LIVE: 📱 Sending phone_ready to glasses (\(reason), exchange \(readyId)) - waiting for glasses_ready response"
|
|
6227
|
+
)
|
|
6156
6228
|
let readyMsg: [String: Any] = [
|
|
6157
6229
|
"type": "phone_ready",
|
|
6158
6230
|
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
6231
|
+
"readyId": readyId,
|
|
6159
6232
|
]
|
|
6160
6233
|
sendJson(readyMsg, wakeUp: true)
|
|
6161
6234
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
final class MentraLiveCommandQueueTests: XCTestCase {
|
|
6
|
+
func testStaleGenerationRunIsDiscardedInOnePassAheadOfTheCurrentWrite() {
|
|
7
|
+
let queue = MentraLive.CommandQueue()
|
|
8
|
+
for (id, generation) in [("1", 1), ("2", 1), ("3", 2), ("4", 3), ("5", 3)] {
|
|
9
|
+
_ = queue.enqueue(write(id, generation: generation))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let next = queue.dequeue(currentGeneration: 3)
|
|
13
|
+
XCTAssertEqual(next.command?.id, "4")
|
|
14
|
+
XCTAssertEqual(next.staleIds, ["1", "2", "3"])
|
|
15
|
+
|
|
16
|
+
let following = queue.dequeue(currentGeneration: 3)
|
|
17
|
+
XCTAssertEqual(following.command?.id, "5")
|
|
18
|
+
XCTAssertEqual(following.staleIds, [])
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func testQueueOfOnlyStaleWritesDrainsToEmpty() {
|
|
22
|
+
let queue = MentraLive.CommandQueue()
|
|
23
|
+
_ = queue.enqueue(write("1", generation: 1))
|
|
24
|
+
_ = queue.enqueue(write("2", generation: 2))
|
|
25
|
+
|
|
26
|
+
let next = queue.dequeue(currentGeneration: 3)
|
|
27
|
+
XCTAssertNil(next.command)
|
|
28
|
+
XCTAssertEqual(next.staleIds, ["1", "2"])
|
|
29
|
+
XCTAssertNil(queue.dequeue())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private func write(_ id: String, generation: Int) -> MentraLive.PendingMessage {
|
|
33
|
+
MentraLive.PendingMessage(data: Data([1]), id: id, retries: 0, generation: generation)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -8,6 +8,10 @@ private final class SessionReadinessTransport: MentraLive {
|
|
|
8
8
|
override func sendJson(_ jsonOriginal: [String: Any], wakeUp: Bool, requireAck: Bool) {
|
|
9
9
|
commands.append(jsonOriginal)
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
func phoneReadyIds() -> [String] {
|
|
13
|
+
commands.filter { $0["type"] as? String == "phone_ready" }.compactMap { $0["readyId"] as? String }
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
@MainActor
|
|
@@ -143,6 +147,131 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
143
147
|
XCTAssertTrue(sdk.glassesStatus.fullyBooted)
|
|
144
148
|
}
|
|
145
149
|
|
|
150
|
+
func testBufferedPhoneReadyCopiesAreOneExchangeWithOneInit() throws {
|
|
151
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
152
|
+
// Two SOC-ready heartbeats while the glasses boot: one exchange, sent twice.
|
|
153
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
154
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
155
|
+
let readyIds = transport.phoneReadyIds()
|
|
156
|
+
XCTAssertEqual(readyIds.count, 2)
|
|
157
|
+
XCTAssertEqual(Set(readyIds).count, 1)
|
|
158
|
+
let readyId = try XCTUnwrap(readyIds.first)
|
|
159
|
+
|
|
160
|
+
// The glasses answer every buffered copy; only the first followed a reset.
|
|
161
|
+
for _ in 0 ..< 7 {
|
|
162
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": readyId])
|
|
163
|
+
}
|
|
164
|
+
XCTAssertEqual(versionRequests(), 1)
|
|
165
|
+
XCTAssertEqual(DeviceStore.shared.store.get("glasses", "fullyBooted") as? Bool, true)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
func testRestartedGlassesProcessStartsANewExchangeAndIgnoresStaleAnswers() throws {
|
|
170
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
171
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
172
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
173
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
174
|
+
|
|
175
|
+
// asg restarted under the live link: a new exchange, and the old one's answers no
|
|
176
|
+
// longer count even though the new process will reset for its own.
|
|
177
|
+
try receive(["type": "version_info_1", "sid": "restarted", "build_number": "302010073"])
|
|
178
|
+
let second = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
179
|
+
XCTAssertNotEqual(second, first)
|
|
180
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
181
|
+
XCTAssertEqual(versionRequests(), 1)
|
|
182
|
+
|
|
183
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
184
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
func testAnswerFromAnotherGlassesProcessIsHandledWithNoExchangePending() throws {
|
|
189
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
190
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
191
|
+
let readyId = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
192
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": readyId])
|
|
193
|
+
|
|
194
|
+
// A different process reset its transport for this copy, so it is not a repeat.
|
|
195
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": readyId])
|
|
196
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
func testRestartedProcessAnsweringAnOlderCopyIsHandledAndThePendingExchangeStillCounts() throws {
|
|
201
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
202
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
203
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
204
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
205
|
+
try receive(["type": "version_info_1", "sid": "restarted", "build_number": "302010073"])
|
|
206
|
+
let second = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
207
|
+
|
|
208
|
+
// The restarted process reset for a buffered copy of the old exchange, then resets
|
|
209
|
+
// again for the pending one: both answers follow a reset.
|
|
210
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": first])
|
|
211
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
212
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
213
|
+
XCTAssertEqual(versionRequests(), 3)
|
|
214
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
215
|
+
XCTAssertEqual(versionRequests(), 3)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
func testReadinessExchangeEndsWithTheBleSession() throws {
|
|
220
|
+
try withReadinessTransport { transport, receive, _ in
|
|
221
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
222
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
223
|
+
transport.cleanup()
|
|
224
|
+
DeviceStore.shared.store.set("glasses", "fullyBooted", false)
|
|
225
|
+
|
|
226
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
227
|
+
XCTAssertNotEqual(try XCTUnwrap(transport.phoneReadyIds().last), first)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
func testGlassesWithoutReadyIdKeepInitializingOnEveryAnswer() throws {
|
|
232
|
+
try withReadinessTransport { _, receive, versionRequests in
|
|
233
|
+
try receive(["type": "glasses_ready", "sid": "legacy"])
|
|
234
|
+
try receive(["type": "glasses_ready", "sid": "legacy"])
|
|
235
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// Runs `body` on a fresh transport whose glasses have not reported readiness yet.
|
|
240
|
+
private func withReadinessTransport(
|
|
241
|
+
_ body: (
|
|
242
|
+
SessionReadinessTransport,
|
|
243
|
+
([String: Any]) throws -> Void,
|
|
244
|
+
() -> Int
|
|
245
|
+
) throws -> Void
|
|
246
|
+
) throws {
|
|
247
|
+
let store = DeviceStore.shared.store
|
|
248
|
+
let saved = ["bluetooth", "glasses"].map { ($0, store.getCategory($0)) }
|
|
249
|
+
let previous = DeviceManager.shared.sgc
|
|
250
|
+
let transport = SessionReadinessTransport()
|
|
251
|
+
DeviceManager.shared.sgc = transport
|
|
252
|
+
defer {
|
|
253
|
+
transport.cleanup()
|
|
254
|
+
DeviceManager.shared.sgc = previous
|
|
255
|
+
for (category, values) in saved {
|
|
256
|
+
for key in store.getCategory(category).keys where values[key] == nil {
|
|
257
|
+
store.remove(category, key)
|
|
258
|
+
}
|
|
259
|
+
for (key, value) in values {
|
|
260
|
+
store.set(category, key, value)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
store.set("glasses", "fullyBooted", false)
|
|
265
|
+
|
|
266
|
+
func receive(_ value: [String: Any]) throws {
|
|
267
|
+
try transport.processReceivedData(JSONSerialization.data(withJSONObject: value))
|
|
268
|
+
}
|
|
269
|
+
func versionRequests() -> Int {
|
|
270
|
+
transport.commands.filter { $0["type"] as? String == "request_version" }.count
|
|
271
|
+
}
|
|
272
|
+
try body(transport, receive, versionRequests)
|
|
273
|
+
}
|
|
274
|
+
|
|
146
275
|
func testInitialVersionChunkDoesNotStartAnExtraReadinessExchange() throws {
|
|
147
276
|
let store = DeviceStore.shared.store
|
|
148
277
|
let saved = store.getCategory("glasses")
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
private final class TouchGestureTransport: MentraLive {
|
|
6
|
+
var respond: (([String: Any]) -> [[String: Any]])?
|
|
7
|
+
var requestIds: [String] = []
|
|
8
|
+
|
|
9
|
+
override func sendTouchGestureDefaultBehaviorEnabled(requestId: String, gesture: TouchGesture, enabled: Bool) throws {
|
|
10
|
+
try sendTouchGestureDefaultCommand(requestId: requestId, gesture: gesture, enabled: enabled)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override func queueSend(_ data: Data, id _: String) {
|
|
14
|
+
do {
|
|
15
|
+
// K900: ##, type, two-byte length, JSON payload, $$.
|
|
16
|
+
let payload = data.subdata(in: 5 ..< data.count - 2)
|
|
17
|
+
let envelope = try XCTUnwrap(JSONSerialization.jsonObject(with: payload) as? [String: Any])
|
|
18
|
+
XCTAssertEqual(envelope["C"] as? String, "cs_tpdef")
|
|
19
|
+
let body = try XCTUnwrap((envelope["B"] as? String)?.data(using: .utf8))
|
|
20
|
+
let command = try XCTUnwrap(JSONSerialization.jsonObject(with: body) as? [String: Any])
|
|
21
|
+
try requestIds.append(XCTUnwrap(command["request_id"] as? String))
|
|
22
|
+
for response in respond?(command) ?? [] {
|
|
23
|
+
try processReceivedData(JSONSerialization.data(withJSONObject: response))
|
|
24
|
+
}
|
|
25
|
+
} catch { XCTFail("K900 round trip failed: \(error)") }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@MainActor
|
|
30
|
+
final class TouchGestureCommandTests: XCTestCase {
|
|
31
|
+
func testEveryGestureRoundTripsBothStates() async throws {
|
|
32
|
+
let previous = DeviceManager.shared.sgc
|
|
33
|
+
let transport = TouchGestureTransport()
|
|
34
|
+
DeviceManager.shared.sgc = transport
|
|
35
|
+
let sdk = MentraBluetoothSDK()
|
|
36
|
+
defer { sdk.invalidate(); DeviceManager.shared.sgc = previous }
|
|
37
|
+
for gesture in TouchGesture.allCases {
|
|
38
|
+
for enabled in [false, true] {
|
|
39
|
+
transport.respond = { command in
|
|
40
|
+
XCTAssertEqual(command["gesture"] as? String, gesture.rawValue)
|
|
41
|
+
XCTAssertEqual(command["enabled"] as? Bool, enabled)
|
|
42
|
+
let body: [String: Any] = ["type": "settings_ack", "setting": "touch_gesture_default", "status": "applied",
|
|
43
|
+
"request_id": command["request_id"]!, "gesture": gesture.rawValue, "enabled": enabled]
|
|
44
|
+
var unrelated = body
|
|
45
|
+
unrelated["request_id"] = "another-request"
|
|
46
|
+
return [["C": "sr_tpdef", "B": unrelated], ["C": "sr_tpdef", "B": body]]
|
|
47
|
+
}
|
|
48
|
+
let ack = try await sdk.setTouchGestureDefaultBehaviorEnabled(gesture, enabled: enabled)
|
|
49
|
+
XCTAssertEqual(ack.gesture, gesture)
|
|
50
|
+
XCTAssertEqual(ack.enabled, enabled)
|
|
51
|
+
XCTAssertEqual(ack.requestId, transport.requestIds.last)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
XCTAssertEqual(Set(transport.requestIds).count, 16)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func testFirmwareRejectionPropagatesThroughStringBody() async {
|
|
58
|
+
let previous = DeviceManager.shared.sgc
|
|
59
|
+
let transport = TouchGestureTransport()
|
|
60
|
+
DeviceManager.shared.sgc = transport
|
|
61
|
+
let sdk = MentraBluetoothSDK()
|
|
62
|
+
defer { sdk.invalidate(); DeviceManager.shared.sgc = previous }
|
|
63
|
+
transport.respond = { command in
|
|
64
|
+
let body: [String: Any] = ["type": "settings_ack", "setting": "touch_gesture_default", "status": "error",
|
|
65
|
+
"request_id": command["request_id"]!, "error_code": "invalid_touch_gesture_setting"]
|
|
66
|
+
let encoded = try! JSONSerialization.data(withJSONObject: body)
|
|
67
|
+
return [["C": "sr_tpdef", "B": String(data: encoded, encoding: .utf8)!]]
|
|
68
|
+
}
|
|
69
|
+
do {
|
|
70
|
+
_ = try await sdk.setTouchGestureDefaultBehaviorEnabled(.doubleTap, enabled: false)
|
|
71
|
+
XCTFail("Rejected firmware setting must throw")
|
|
72
|
+
} catch let error as BluetoothSdkError { XCTAssertEqual(error.code, "invalid_touch_gesture_setting") }
|
|
73
|
+
catch { XCTFail("Unexpected error: \(error)") }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func testUnsupportedDeviceRejects() async {
|
|
77
|
+
let previous = DeviceManager.shared.sgc
|
|
78
|
+
DeviceManager.shared.sgc = nil
|
|
79
|
+
let sdk = MentraBluetoothSDK()
|
|
80
|
+
defer { sdk.invalidate(); DeviceManager.shared.sgc = previous }
|
|
81
|
+
do {
|
|
82
|
+
_ = try await sdk.setTouchGestureDefaultBehaviorEnabled(.doubleTap, enabled: false)
|
|
83
|
+
XCTFail("Unsupported device must throw")
|
|
84
|
+
} catch let error as BluetoothSdkError { XCTAssertEqual(error.code, "unsupported_device") }
|
|
85
|
+
catch { XCTFail("Unexpected error: \(error)") }
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/bluetooth-sdk",
|
|
3
|
-
"version": "3.3.0
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "SDK for communicating with smart glasses",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"registry": "https://registry.npmjs.org/"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@mentra/cloud-protocol": "3.3.0
|
|
117
|
+
"@mentra/cloud-protocol": "3.3.0"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
120
|
"@types/node": "^25.9.3",
|
|
@@ -584,9 +584,20 @@ export type RgbLedControlResponseEvent =
|
|
|
584
584
|
|
|
585
585
|
export type RgbLedControlSuccessResponseEvent = Extract<RgbLedControlResponseEvent, {state: "success"}>
|
|
586
586
|
|
|
587
|
+
export type TouchGesture =
|
|
588
|
+
| "single_tap"
|
|
589
|
+
| "double_tap"
|
|
590
|
+
| "triple_tap"
|
|
591
|
+
| "long_press"
|
|
592
|
+
| "forward_swipe"
|
|
593
|
+
| "backward_swipe"
|
|
594
|
+
| "up_swipe"
|
|
595
|
+
| "down_swipe"
|
|
596
|
+
|
|
587
597
|
export type SettingsAckStatus = "applied" | "ready" | "error" | "failed" | "failure" | "rejected"
|
|
588
598
|
|
|
589
599
|
export type SettingsAckSetting =
|
|
600
|
+
| "touch_gesture_default"
|
|
590
601
|
| "gallery_server"
|
|
591
602
|
| "gallery_mode"
|
|
592
603
|
| "button_photo"
|
|
@@ -600,6 +611,8 @@ export type SettingsAckEvent = {
|
|
|
600
611
|
type: "settings_ack"
|
|
601
612
|
requestId: string
|
|
602
613
|
setting: SettingsAckSetting
|
|
614
|
+
/** Gesture whose stock behavior was changed; present for touch_gesture_default. */
|
|
615
|
+
gesture?: TouchGesture
|
|
603
616
|
status: SettingsAckStatus
|
|
604
617
|
timestamp: number
|
|
605
618
|
fov?: number
|
|
@@ -1425,6 +1438,8 @@ export interface BluetoothSdkPublicModule {
|
|
|
1425
1438
|
* Returns saved enabled state plus current listening/url. No Wi-Fi means listening=false.
|
|
1426
1439
|
*/
|
|
1427
1440
|
setGalleryServerEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
1441
|
+
/** Mentra Live only. Keep gesture events; reset stock actions on BLE disconnect. Requires compatible BES firmware. */
|
|
1442
|
+
setTouchGestureDefaultBehaviorEnabled(gesture: TouchGesture, enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
1428
1443
|
setGalleryModeEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
1429
1444
|
setVoiceActivityDetectionEnabled(enabled: boolean): Promise<void>
|
|
1430
1445
|
setLoudnessGateEnabled(enabled: boolean): Promise<void>
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
SettingsAckSuccessEvent,
|
|
50
50
|
StreamStartRequest,
|
|
51
51
|
StreamStatusEvent,
|
|
52
|
+
TouchGesture,
|
|
52
53
|
VideoRecordingStartedStatusEvent,
|
|
53
54
|
VideoRecordingSettings,
|
|
54
55
|
VideoRecordingStoppedStatusEvent,
|
|
@@ -143,6 +144,7 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
|
|
|
143
144
|
|
|
144
145
|
// Gallery Commands
|
|
145
146
|
setGalleryServerEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
147
|
+
setTouchGestureDefaultBehaviorEnabled(gesture: TouchGesture, enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
146
148
|
setGalleryModeEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent>
|
|
147
149
|
setVoiceActivityDetectionEnabled(enabled: boolean): Promise<void>
|
|
148
150
|
/** Mentra Live center-mic loudness / Barrier gate (cs_swit type 10). */
|
|
@@ -3,7 +3,7 @@ export const GENERATED_RELEASE_CHANGELOGS = Object.freeze(
|
|
|
3
3
|
[
|
|
4
4
|
{
|
|
5
5
|
"version": "3.3.0",
|
|
6
|
-
"markdown": "
|
|
6
|
+
"markdown": "- **Mentra Call:** Now available on iPhone, with a redesigned call screen and photo sharing during calls.\n- **Microphone:** Improved glasses microphone reliability, including after phone calls.\n- **Photos and gallery:** More reliable photo capture and gallery syncing.\n- **Glasses updates:** More reliable glasses updates, with clearer progress.\n- **Miniapps:** Miniapps now update automatically. Fixed miniapps getting stuck on loading screens.\n- **Mentra AI:** Reliability improvements and bug fixes.\n- **Notes:** Take photos with the glasses camera button, and add meeting and location details to your notes.\n- **Pairing and connections:** Improved glasses audio reconnection on Android.\n- **G1 and NIMO:** Improved text display, including accented letters.\n- **Android tablets:** The Mentra App now rotates to landscape."
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
9
|
"version": "3.2.1",
|
|
@@ -12,9 +12,9 @@ export interface BluetoothSdkReleaseMetadata {
|
|
|
12
12
|
export const BLUETOOTH_SDK_RELEASE_METADATA: Readonly<BluetoothSdkReleaseMetadata> = Object.freeze({
|
|
13
13
|
"schemaVersion": 1,
|
|
14
14
|
"familyBaseVersion": "3.3.0",
|
|
15
|
-
"releaseIdentity": "3.3.0
|
|
16
|
-
"releaseSetId": "mentra-3.3.0
|
|
17
|
-
"sourceCommit": "
|
|
18
|
-
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-
|
|
19
|
-
"otaManifestSha256": "
|
|
15
|
+
"releaseIdentity": "3.3.0",
|
|
16
|
+
"releaseSetId": "mentra-3.3.0",
|
|
17
|
+
"sourceCommit": "5bd50400b076b758691429755b6e1bd7b77268fb",
|
|
18
|
+
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-beta.1188.json",
|
|
19
|
+
"otaManifestSha256": "66070872d18ee11303347e1be71b7385af96aab30adc3d226ceb4a82c2c4848f"
|
|
20
20
|
})
|
package/src/index.ts
CHANGED
|
@@ -128,6 +128,7 @@ export const BluetoothSdk: BluetoothSdkPublicModule = Object.freeze({
|
|
|
128
128
|
setSystemTime: bindPublicMethod("setSystemTime"),
|
|
129
129
|
setWifiAdbState: bindPublicMethod("setWifiAdbState"),
|
|
130
130
|
setGalleryServerEnabled: bindPublicMethod("setGalleryServerEnabled"),
|
|
131
|
+
setTouchGestureDefaultBehaviorEnabled: bindPublicMethod("setTouchGestureDefaultBehaviorEnabled"),
|
|
131
132
|
setGalleryModeEnabled: bindPublicMethod("setGalleryModeEnabled"),
|
|
132
133
|
setVoiceActivityDetectionEnabled: bindPublicMethod("setVoiceActivityDetectionEnabled"),
|
|
133
134
|
setLoudnessGateEnabled: bindPublicMethod("setLoudnessGateEnabled"),
|
|
@@ -311,6 +312,7 @@ export type {
|
|
|
311
312
|
SwipeVolumeStatusEvent,
|
|
312
313
|
SwitchStatusEvent,
|
|
313
314
|
TouchEvent,
|
|
315
|
+
TouchGesture,
|
|
314
316
|
VideoRecordingDefaults,
|
|
315
317
|
VideoRecordingStartedStatusEvent,
|
|
316
318
|
VideoRecordingStatusEvent,
|