@mentra/bluetooth-sdk 3.5.0-dev.1513 → 3.5.0-dev.1515

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 (74) hide show
  1. package/README.md +14 -30
  2. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +28 -3
  3. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +27 -16
  4. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +1 -0
  5. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  6. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +69 -17
  7. package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +12 -12
  8. package/android/src/main/java/com/mentra/bluetoothsdk/camera/PhotoCapture.kt +115 -0
  9. package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +1 -1
  10. package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +1 -1
  11. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Ar99.java +2 -2
  12. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.kt +1 -1
  13. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +2 -2
  14. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.kt +1 -1
  15. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +83 -27
  16. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +2 -2
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +2 -2
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +1 -1
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +2 -2
  20. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +7 -0
  21. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerSceneHandoffTest.kt +1 -1
  22. package/android/src/test/java/com/mentra/bluetoothsdk/camera/PhotoCaptureTest.kt +53 -0
  23. package/android/src/test/java/com/mentra/bluetoothsdk/camera/PhotoRequestTest.kt +0 -19
  24. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +16 -0
  25. package/build/BluetoothSdk.types.d.ts +56 -25
  26. package/build/BluetoothSdk.types.d.ts.map +1 -1
  27. package/build/BluetoothSdk.types.js.map +1 -1
  28. package/build/_private/BluetoothSdkModule.d.ts +5 -3
  29. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  30. package/build/_private/BluetoothSdkModule.js +50 -4
  31. package/build/_private/BluetoothSdkModule.js.map +1 -1
  32. package/build/_private/photoRequestPayload.d.ts +4 -2
  33. package/build/_private/photoRequestPayload.d.ts.map +1 -1
  34. package/build/_private/photoRequestPayload.js +11 -12
  35. package/build/_private/photoRequestPayload.js.map +1 -1
  36. package/build/generated/releaseMetadata.js +5 -5
  37. package/build/generated/releaseMetadata.js.map +1 -1
  38. package/build/index.d.ts +1 -1
  39. package/build/index.d.ts.map +1 -1
  40. package/build/index.js +4 -2
  41. package/build/index.js.map +1 -1
  42. package/ios/BluetoothSdkModule.swift +35 -3
  43. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  44. package/ios/Source/DeviceManager.swift +15 -3
  45. package/ios/Source/DeviceStore.swift +1 -0
  46. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  47. package/ios/Source/MentraBluetoothSDK.swift +60 -17
  48. package/ios/Source/camera/CameraModels.swift +17 -16
  49. package/ios/Source/camera/PhotoCapture.swift +118 -0
  50. package/ios/Source/controllers/ControllerManager.swift +1 -1
  51. package/ios/Source/controllers/R1.swift +1 -1
  52. package/ios/Source/sgcs/Ar99.swift +2 -2
  53. package/ios/Source/sgcs/Frame.swift +1 -1
  54. package/ios/Source/sgcs/G1.swift +1 -1
  55. package/ios/Source/sgcs/G2.swift +1 -1
  56. package/ios/Source/sgcs/Mach1.swift +1 -1
  57. package/ios/Source/sgcs/MentraLive.swift +84 -34
  58. package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +5 -0
  59. package/ios/Source/sgcs/MentraNex.swift +1 -1
  60. package/ios/Source/sgcs/Nimo.swift +4 -4
  61. package/ios/Source/sgcs/SGCManager.swift +1 -1
  62. package/ios/Source/sgcs/Simulated.swift +2 -2
  63. package/ios/Source/status/DeviceStatus.swift +9 -0
  64. package/ios/Tests/DashboardRenderingTests.swift +1 -1
  65. package/ios/Tests/DeviceManagerReconnectTests.swift +1 -1
  66. package/ios/Tests/PhotoCaptureTests.swift +39 -0
  67. package/ios/Tests/PhotoLocalFileTests.swift +0 -7
  68. package/ios/Tests/PhotoRequestRoutingTests.swift +0 -14
  69. package/package.json +2 -2
  70. package/src/BluetoothSdk.types.ts +50 -25
  71. package/src/_private/BluetoothSdkModule.ts +68 -7
  72. package/src/_private/photoRequestPayload.ts +13 -13
  73. package/src/generated/releaseMetadata.ts +5 -5
  74. package/src/index.ts +9 -3
@@ -710,7 +710,10 @@ enum K900ProtocolUtils {
710
710
  }
711
711
 
712
712
  private struct BlePhotoTransfer {
713
- var isThumbnail = false
713
+ /// A deferred photo's preview, of this size.
714
+ var preview = false
715
+ var previewWidth: Int?
716
+ var previewHeight: Int?
714
717
  /// The photo stays on the phone as a file instead of being uploaded.
715
718
  var localFile = false
716
719
  let bleImgId: String
@@ -1535,6 +1538,7 @@ class MentraLive: NSObject, SGCManager {
1535
1538
  DeviceStore.shared.apply("glasses", "bluetoothMacAddress", "")
1536
1539
  DeviceStore.shared.apply("glasses", "wifiMacAddress", "")
1537
1540
  DeviceStore.shared.apply("glasses", "hotspotOtaVersion", 0)
1541
+ DeviceStore.shared.apply("glasses", "deferredPhotosVersion", 0)
1538
1542
  }
1539
1543
  connectionState = state
1540
1544
  pairFlow(
@@ -1690,6 +1694,17 @@ class MentraLive: NSObject, SGCManager {
1690
1694
  private var fileWriteCharacteristic: CBCharacteristic?
1691
1695
  private var activeFileTransfers = [String: MentraLiveFileTransferSession]()
1692
1696
  private var blePhotoTransfers = [String: BlePhotoTransfer]()
1697
+ private var lastBleImgNumber = 0
1698
+ private let bleImgIdLock = NSLock()
1699
+
1700
+ /// A Bluetooth image ID no other transfer of this process has: the clock's milliseconds, or one
1701
+ /// past the last ID when two requests fall in the same millisecond (a burst, concurrent fetches).
1702
+ private func nextBleImgId() -> String {
1703
+ bleImgIdLock.lock()
1704
+ defer { bleImgIdLock.unlock() }
1705
+ lastBleImgNumber = max(Int(Date().timeIntervalSince1970 * 1000), lastBleImgNumber + 1)
1706
+ return "I" + String(format: "%09d", lastBleImgNumber % 100_000_000)
1707
+ }
1693
1708
  private(set) var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
1694
1709
  /// BES bytes kept on the phone until the MTK log for the same report has been uploaded.
1695
1710
  private var heldBesLogs = [String: HeldBesLog]()
@@ -2608,9 +2623,32 @@ class MentraLive: NSObject, SGCManager {
2608
2623
  }
2609
2624
  }
2610
2625
 
2611
- func requestPhoto(_ request: PhotoRequest) {
2626
+ func uploadPhoto(_ request: PhotoRequest) {
2627
+ sendTakePhoto(request, localFile: false, deferred: false)
2628
+ }
2629
+
2630
+ /// A photo kept on the phone. On glasses with deferred photos (`deferred`) the glasses keep it
2631
+ /// and send only its preview, then the full photo on `fetchPhoto`; on older glasses it comes
2632
+ /// whole now, as a file.
2633
+ func capturePhoto(_ request: PhotoRequest, deferred: Bool) {
2634
+ sendTakePhoto(request, localFile: !deferred, deferred: deferred)
2635
+ }
2636
+
2637
+ /// Ask the glasses for a deferred photo's full size, or (`preview`) its preview again.
2638
+ func fetchPhoto(_ request: PhotoRequest, preview: Bool) {
2639
+ var json: [String: Any] = [
2640
+ "type": "fetch_photo",
2641
+ "requestId": request.requestId,
2642
+ "size": request.size.rawValue,
2643
+ "compress": request.compress.rawValue,
2644
+ ]
2645
+ if preview { json["preview"] = true }
2646
+ sendJson(json, wakeUp: true)
2647
+ }
2648
+
2649
+ private func sendTakePhoto(_ request: PhotoRequest, localFile: Bool, deferred: Bool) {
2612
2650
  Bridge.log(
2613
- "LIVE: PHOTO PIPELINE [5/6] requestPhoto() entry requestId=\(request.requestId) mode=\(request.mode.rawValue) save=\(request.save) sound=\(request.sound) iso=\(request.iso.map { String($0) } ?? "auto") aeDivisor=\(request.aeExposureDivisor.map { String($0) } ?? "nil")"
2651
+ "LIVE: PHOTO PIPELINE [5/6] uploadPhoto() entry requestId=\(request.requestId) mode=\(request.mode.rawValue) save=\(request.save) sound=\(request.sound) iso=\(request.iso.map { String($0) } ?? "auto") aeDivisor=\(request.aeExposureDivisor.map { String($0) } ?? "nil")"
2614
2652
  )
2615
2653
 
2616
2654
  var json: [String: Any] = [
@@ -2618,14 +2656,16 @@ class MentraLive: NSObject, SGCManager {
2618
2656
  "requestId": request.requestId,
2619
2657
  ]
2620
2658
 
2621
- // Always generate BLE ID for potential fallback
2622
- let bleImgId =
2623
- "I" + String(format: "%09d", Int(Date().timeIntervalSince1970 * 1000) % 100_000_000)
2624
- json["bleImgId"] = bleImgId
2625
- json["transferMethod"] = request.localFile ? "ble" : request.transferMethod
2626
- if request.presendThumbnail { json["presend_thumbnail"] = true }
2659
+ // The glasses keep a deferred photo and name the files they send (preview, then full photo).
2660
+ let bleImgId = deferred ? "" : nextBleImgId()
2661
+ if !deferred {
2662
+ json["bleImgId"] = bleImgId
2663
+ json["transferMethod"] = localFile ? "ble" : request.transferMethod
2664
+ }
2627
2665
 
2628
- if request.localFile {
2666
+ if deferred {
2667
+ // Nothing to prepare: the glasses' files name their request.
2668
+ } else if localFile {
2629
2669
  var transfer = BlePhotoTransfer(
2630
2670
  bleImgId: bleImgId, requestId: request.requestId, webhookUrl: ""
2631
2671
  )
@@ -2652,7 +2692,7 @@ class MentraLive: NSObject, SGCManager {
2652
2692
  }
2653
2693
 
2654
2694
  // Add authToken to JSON if provided
2655
- if !request.localFile, let authToken = request.authToken, !authToken.isEmpty {
2695
+ if !localFile, !deferred, let authToken = request.authToken, !authToken.isEmpty {
2656
2696
  json["authToken"] = authToken
2657
2697
  }
2658
2698
 
@@ -2676,13 +2716,24 @@ class MentraLive: NSObject, SGCManager {
2676
2716
  request.appendScanFields(to: &json)
2677
2717
 
2678
2718
  Bridge.log(
2679
- "LIVE: PHOTO PIPELINE [5b/6] take_photo JSON ready bleImgId=\(bleImgId) transferMethod=\(request.localFile ? "ble (local file)" : request.transferMethod)"
2719
+ "LIVE: PHOTO PIPELINE [5b/6] take_photo JSON ready bleImgId=\(bleImgId) transferMethod=\(deferred ? "deferred" : localFile ? "ble (local file)" : request.transferMethod)"
2680
2720
  )
2681
2721
  Bridge.log("LIVE: PHOTO PIPELINE [6/6] Dispatching take_photo to sendJson()")
2682
2722
 
2683
2723
  sendJson(json, wakeUp: true)
2684
2724
  }
2685
2725
 
2726
+ /// Delete deferred photos on the glasses: these, or all of them when `requestIds` is nil.
2727
+ func releasePhotos(requestIds: [String]?) {
2728
+ var json: [String: Any] = ["type": "release_photos"]
2729
+ if let requestIds {
2730
+ json["requestIds"] = requestIds
2731
+ } else {
2732
+ json["all"] = true
2733
+ }
2734
+ sendJson(json, wakeUp: true)
2735
+ }
2736
+
2686
2737
  func warmUpCamera(
2687
2738
  requestId: String,
2688
2739
  size: PhotoSize,
@@ -3997,6 +4048,9 @@ class MentraLive: NSObject, SGCManager {
3997
4048
  if let systemTimeMs = fields["system_time_ms"] as? NSNumber {
3998
4049
  DeviceStore.shared.apply("glasses", "systemTimeMs", systemTimeMs.int64Value)
3999
4050
  }
4051
+ if let deferredPhotosVersion = fields["deferred_photos"] as? NSNumber {
4052
+ DeviceStore.shared.apply("glasses", "deferredPhotosVersion", deferredPhotosVersion.intValue)
4053
+ }
4000
4054
  if let hotspotOtaVersion = fields["hotspot_ota_version"] as? NSNumber {
4001
4055
  DeviceStore.shared.apply(
4002
4056
  "glasses",
@@ -4875,6 +4929,8 @@ class MentraLive: NSObject, SGCManager {
4875
4929
  advertiseFilePayloadCapabilityToBes()
4876
4930
  openL2capFileChannel()
4877
4931
  sendBleMtuConfig()
4932
+ // Deferred photos still waited for are asked again: a restart loses what was queued.
4933
+ Bridge.sendTypedMessage("glasses_ready", body: [:])
4878
4934
 
4879
4935
  // Invalidate any version fields from a prior link session so the next version_info
4880
4936
  // cannot leave a stale build number in RN (ASG is source of truth for PackageInfo).
@@ -5182,19 +5238,15 @@ class MentraLive: NSObject, SGCManager {
5182
5238
  let bleImgId = json["bleImgId"] as? String ?? ""
5183
5239
  let requestId = json["requestId"] as? String ?? ""
5184
5240
  let compressionDurationMs = json["compressionDurationMs"] as? Int64 ?? 0
5185
- if json["thumbnail"] as? Bool == true, !bleImgId.isEmpty, !requestId.isEmpty {
5186
- guard blePhotoTransfers.values.contains(where: {
5187
- !$0.isThumbnail && $0.requestId == requestId && bleImgId == "T" + $0.bleImgId.dropFirst()
5188
- }) else {
5189
- Bridge.log("LIVE: Ignoring thumbnail for an unknown photo request")
5190
- return
5191
- }
5192
- // Preserve any packets already received when the ready message is repeated.
5193
- if blePhotoTransfers[bleImgId] == nil {
5194
- var transfer = BlePhotoTransfer(bleImgId: bleImgId, requestId: requestId, webhookUrl: "")
5195
- transfer.isThumbnail = true
5196
- blePhotoTransfers[bleImgId] = transfer
5197
- }
5241
+ if json["deferred"] as? Bool == true, !bleImgId.isEmpty, !requestId.isEmpty, blePhotoTransfers[bleImgId] == nil {
5242
+ // A deferred photo's preview or full photo: the glasses name the file, and a restart or
5243
+ // reconnect since the request doesn't matter. A repeated ready message keeps the packets.
5244
+ var transfer = BlePhotoTransfer(bleImgId: bleImgId, requestId: requestId, webhookUrl: "")
5245
+ transfer.preview = json["preview"] as? Bool == true
5246
+ transfer.localFile = !transfer.preview
5247
+ transfer.previewWidth = (json["width"] as? NSNumber)?.intValue
5248
+ transfer.previewHeight = (json["height"] as? NSNumber)?.intValue
5249
+ blePhotoTransfers[bleImgId] = transfer
5198
5250
  }
5199
5251
 
5200
5252
  Bridge.log(
@@ -5930,15 +5982,13 @@ class MentraLive: NSObject, SGCManager {
5930
5982
  }
5931
5983
 
5932
5984
  private func processAndUploadBlePhoto(_ transfer: BlePhotoTransfer, imageData: Data) {
5933
- if transfer.isThumbnail {
5934
- Bridge.sendPhotoStatus([
5935
- "type": "photo_status",
5936
- "requestId": transfer.requestId,
5937
- "status": "thumbnail_received",
5938
- "timestamp": Int64(Date().timeIntervalSince1970 * 1000),
5939
- "thumbnailUrl": "data:image/jpeg;base64," + imageData.base64EncodedString(),
5940
- "fileSizeBytes": imageData.count,
5941
- ])
5985
+ if transfer.preview {
5986
+ let preview = PhotoPreview(
5987
+ url: "data:image/jpeg;base64," + imageData.base64EncodedString(),
5988
+ width: transfer.previewWidth,
5989
+ height: transfer.previewHeight
5990
+ )
5991
+ Bridge.sendTypedMessage("photo_preview", body: preview.values.merging(["requestId": transfer.requestId]) { $1 })
5942
5992
  return
5943
5993
  }
5944
5994
  if transfer.localFile {
@@ -81,6 +81,11 @@ struct MentraLiveFileTransferSession {
81
81
  if receivedPackets.isEmpty && actualPackSize == 0 && !data.isEmpty {
82
82
  recalculateTotalPackets(actualPackSize: data.count)
83
83
  }
84
+ // The first packet seen can be the file's short last one (the ones before it lost on a
85
+ // link still settling after a reconnect): a larger packet gives the real pack size.
86
+ if actualPackSize > 0 && data.count > actualPackSize {
87
+ recalculateTotalPackets(actualPackSize: data.count)
88
+ }
84
89
 
85
90
  guard index < totalPackets else { return false }
86
91
  if dynamicPayload {
@@ -51,7 +51,7 @@ class MentraNexSGC: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate, SG
51
51
  }
52
52
  }
53
53
 
54
- func requestPhoto(_: PhotoRequest) {}
54
+ func uploadPhoto(_: PhotoRequest) {}
55
55
 
56
56
  func startStream(_: [String: Any]) {}
57
57
 
@@ -1074,16 +1074,16 @@ class Nimo: NSObject, SGCManager {
1074
1074
 
1075
1075
  // MARK: - SGCManager: Camera & Media (no camera)
1076
1076
 
1077
- func requestPhoto(
1077
+ func uploadPhoto(
1078
1078
  _: String, appId _: String, size _: String?, webhookUrl _: String?, authToken _: String?,
1079
1079
  compress _: String?, flash _: Bool, save _: Bool, sound _: Bool, exposureTimeNs _: Double?,
1080
1080
  iso _: Int?
1081
1081
  ) {
1082
- Bridge.log("NIMO: requestPhoto - not supported (no camera)")
1082
+ Bridge.log("NIMO: uploadPhoto - not supported (no camera)")
1083
1083
  }
1084
1084
 
1085
- func requestPhoto(_: PhotoRequest) {
1086
- Bridge.log("NIMO: requestPhoto(PhotoRequest) - not supported (no camera)")
1085
+ func uploadPhoto(_: PhotoRequest) {
1086
+ Bridge.log("NIMO: uploadPhoto(PhotoRequest) - not supported (no camera)")
1087
1087
  }
1088
1088
 
1089
1089
  func startStream(_: [String: Any]) {
@@ -66,7 +66,7 @@ protocol SGCManager {
66
66
 
67
67
  // MARK: - Camera & Media
68
68
 
69
- func requestPhoto(_ request: PhotoRequest)
69
+ func uploadPhoto(_ request: PhotoRequest)
70
70
  func startStream(_ message: [String: Any])
71
71
  func stopStream()
72
72
  /// Re-advertise glasses-owned stream control after the phone SDK remounts.
@@ -81,8 +81,8 @@ class Simulated: SGCManager {
81
81
 
82
82
  // MARK: - Camera & Media
83
83
 
84
- func requestPhoto(_ request: PhotoRequest) {
85
- Bridge.log("requestPhoto save=\(request.save) sound=\(request.sound)")
84
+ func uploadPhoto(_ request: PhotoRequest) {
85
+ Bridge.log("uploadPhoto save=\(request.save) sound=\(request.sound)")
86
86
  }
87
87
 
88
88
  func startStream(_: [String: Any]) {
@@ -231,6 +231,11 @@ struct GlassesStatus: CustomStringConvertible {
231
231
  intValue(values["hotspotOtaVersion"]) ?? 0
232
232
  }
233
233
 
234
+ /// Deferred photos (`capturePhoto`): the glasses' version, 0 without.
235
+ var deferredPhotosVersion: Int {
236
+ intValue(values["deferredPhotosVersion"]) ?? 0
237
+ }
238
+
234
239
  var bluetoothName: String {
235
240
  stringValue(values, "bluetoothName") ?? ""
236
241
  }
@@ -786,6 +791,10 @@ struct GlassesStatusUpdate: CustomStringConvertible {
786
791
  optionalIntValue(values, "hotspotOtaVersion")
787
792
  }
788
793
 
794
+ var deferredPhotosVersion: Int? {
795
+ optionalIntValue(values, "deferredPhotosVersion")
796
+ }
797
+
789
798
  var bluetoothName: String? {
790
799
  optionalStringValue(values, "bluetoothName")
791
800
  }
@@ -144,7 +144,7 @@ private final class PausedDisplay: SGCManager {
144
144
  }
145
145
 
146
146
  func sendJson(_: [String: Any], wakeUp _: Bool, requireAck _: Bool) {}
147
- func requestPhoto(_: PhotoRequest) {}
147
+ func uploadPhoto(_: PhotoRequest) {}
148
148
  func startStream(_: [String: Any]) {}
149
149
  func stopStream() {}
150
150
  func sendStreamKeepAlive(_: [String: Any]) {}
@@ -305,7 +305,7 @@ private final class ReconnectRecordingDevice: SGCManager {
305
305
  }
306
306
 
307
307
  func sendJson(_: [String: Any], wakeUp _: Bool, requireAck _: Bool) {}
308
- func requestPhoto(_: PhotoRequest) {}
308
+ func uploadPhoto(_: PhotoRequest) {}
309
309
  func startStream(_: [String: Any]) {}
310
310
  func stopStream() {}
311
311
  func sendStreamKeepAlive(_: [String: Any]) {}
@@ -0,0 +1,39 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ @MainActor
5
+ final class PhotoCaptureTests: XCTestCase {
6
+ private var calls: [String] = []
7
+
8
+ private func capture() -> PhotoCapture {
9
+ PhotoCapture(
10
+ request: PhotoRequest(requestId: "p1", size: .medium, sound: true),
11
+ deferred: true,
12
+ glasses: PhotoCapture.Glasses(
13
+ fetch: { [unowned self] _, preview in calls.append(preview ? "preview" : "fetch") },
14
+ release: { [unowned self] _ in calls.append("release") },
15
+ forget: { [unowned self] _ in calls.append("forget") }
16
+ )
17
+ )
18
+ }
19
+
20
+ func testAFetchedPhotoIsStillDeletedFromTheGlassesOnRelease() async throws {
21
+ let capture = capture()
22
+ capture.onStatus(PhotoStatusEvent(values: ["requestId": "p1", "status": "captured"]))
23
+ capture.onResponse(PhotoResponseEvent(values: [
24
+ "requestId": "p1", "state": "success", "photoUrl": "file:///cache/photo.jpg", "timestamp": 1,
25
+ ]))
26
+ _ = try await capture.photo()
27
+ capture.release()
28
+ XCTAssertEqual(calls, ["fetch", "forget", "release"])
29
+ }
30
+
31
+ func testAfterAReconnectOnlyWhatIsStillAwaitedIsAskedAgain() {
32
+ let capture = capture()
33
+ capture.onStatus(PhotoStatusEvent(values: ["requestId": "p1", "status": "captured"]))
34
+ capture.resume()
35
+ capture.onPreview(PhotoPreview(url: "data:image/jpeg;base64,AA==", width: 500, height: 375))
36
+ capture.resume()
37
+ XCTAssertEqual(calls, ["preview"])
38
+ }
39
+ }
@@ -2,13 +2,6 @@
2
2
  import XCTest
3
3
 
4
4
  final class PhotoLocalFileTests: XCTestCase {
5
- func testLocalFileIsOptInAndSurvivesRequestRouting() throws {
6
- XCTAssertFalse(try PhotoRequest.from(params: ["size": "low"]).localFile)
7
- let request = try PhotoRequest.from(params: ["size": "low", "localFile": true])
8
- XCTAssertTrue(request.localFile)
9
- XCTAssertTrue(request.withRequestId("routed").localFile)
10
- }
11
-
12
5
  func testSavingKeepsAJpegOnThePhoneUnchanged() throws {
13
6
  let jpeg = Data([0xFF, 0xD8, 1, 2, 3, 0xFF, 0xD9])
14
7
  let directory = FileManager.default.temporaryDirectory
@@ -22,8 +22,6 @@ final class PhotoRequestRoutingTests: XCTestCase {
22
22
  "zsl": false,
23
23
  "ispDigitalGain": 2,
24
24
  "ispAnalogGain": "4x",
25
- "presend_thumbnail": true,
26
- "localFile": true,
27
25
  ]
28
26
 
29
27
  private func assertSameCapture(_ routed: PhotoRequest, _ request: PhotoRequest, line: UInt = #line) {
@@ -43,22 +41,10 @@ final class PhotoRequestRoutingTests: XCTestCase {
43
41
  XCTAssertEqual(routed.zsl, request.zsl, line: line)
44
42
  XCTAssertEqual(routed.ispDigitalGain, request.ispDigitalGain, line: line)
45
43
  XCTAssertEqual(routed.ispAnalogGain, request.ispAnalogGain, line: line)
46
- XCTAssertEqual(routed.presendThumbnail, request.presendThumbnail, line: line)
47
- XCTAssertEqual(routed.localFile, request.localFile, line: line)
48
- }
49
-
50
- /// The glasses were never asked for a thumbnail on iOS: routing rebuilt the request without the flag.
51
- func testThumbnailFlagReachesTheGlasses() throws {
52
- let request = try PhotoRequest.from(params: ["size": "medium", "presend_thumbnail": true])
53
- XCTAssertTrue(request.presendThumbnail)
54
- XCTAssertTrue(request.routedForCapture().presendThumbnail)
55
- XCTAssertFalse(try PhotoRequest.from(params: ["size": "medium"]).routedForCapture().presendThumbnail)
56
44
  }
57
45
 
58
46
  func testRoutingKeepsEveryField() throws {
59
47
  let request = try PhotoRequest.from(params: everyField)
60
- XCTAssertTrue(request.presendThumbnail)
61
- XCTAssertTrue(request.localFile)
62
48
  XCTAssertEqual(request.aeExposureDivisor, 4)
63
49
 
64
50
  let routed = request.routedForCapture()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "3.5.0-dev.1513",
3
+ "version": "3.5.0-dev.1515",
4
4
  "description": "SDK for communicating with smart glasses",
5
5
  "main": "build/index.js",
6
6
  "react-native": "src/index.ts",
@@ -115,7 +115,7 @@
115
115
  "registry": "https://registry.npmjs.org/"
116
116
  },
117
117
  "dependencies": {
118
- "@mentra/cloud-protocol": "3.5.0-dev.1513"
118
+ "@mentra/cloud-protocol": "3.5.0-dev.1515"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@types/node": "^25.9.3",
@@ -289,9 +289,9 @@ export type PhotoResponseEvent =
289
289
  type: "photo_response"
290
290
  state: "success"
291
291
  requestId: string
292
- /** Where the photo was uploaded; empty for a `localFile` request. */
292
+ /** Where the photo was uploaded. */
293
293
  uploadUrl: string
294
- /** The upload target's own URL for the photo, or the saved file's `file://` URI for a `localFile` request. */
294
+ /** The upload target's own URL for the photo. */
295
295
  photoUrl?: string
296
296
  statusUrl?: string
297
297
  contentType?: string
@@ -321,7 +321,6 @@ export type PhotoStatusState =
321
321
  | "uploaded"
322
322
  | "ready_for_transfer"
323
323
  | "transferring"
324
- | "thumbnail_received"
325
324
  | "failed"
326
325
 
327
326
  export type PhotoResolvedConfig = {
@@ -398,8 +397,6 @@ export type PhotoStatusEvent = {
398
397
  captureMetadata?: PhotoCaptureMetadata
399
398
  errorCode?: string
400
399
  errorMessage?: string
401
- /** Present on thumbnail_received: a JPEG data URI, not the final photo. */
402
- thumbnailUrl?: string
403
400
  fileSizeBytes?: number
404
401
  }
405
402
 
@@ -686,7 +683,7 @@ export type ButtonPhotoSize = "low" | "medium" | "high" | "max"
686
683
 
687
684
  /**
688
685
  * @deprecated Sticky action-button photo presets via {@link BluetoothSdkPublicModule.setPhotoCaptureDefaults}
689
- * are deprecated. Prefer per-request {@link BluetoothSdkPublicModule.requestPhoto} options
686
+ * are deprecated. Prefer per-request {@link BluetoothSdkPublicModule.uploadPhoto} options
690
687
  * (e.g. `mode: "text"` for text sensor size/crop, or explicit `aeExposureDivisor`) instead of
691
688
  * persisting button-photo tuning on the glasses.
692
689
  */
@@ -797,27 +794,12 @@ type NativeCameraFovSetting = {
797
794
  export type MicPreference = "auto" | "phone" | "glasses" | "bluetooth"
798
795
  export type MicMode = "phone" | "glasses" | "bluetoothClassic" | "bluetooth"
799
796
 
800
- export type PhotoRequestParams = {
801
- /**
802
- * Send an oriented <=500px, quality-50 JPEG preview before the full photo. Default false.
803
- * Enables a 110-second end-to-end native deadline (ordinary requests: 30 seconds).
804
- */
805
- presend_thumbnail?: boolean
797
+ /** The settings of one capture, shared by `capturePhoto` and `uploadPhoto`. */
798
+ export type PhotoCaptureParams = {
806
799
  requestId?: string
807
800
  appId?: string
808
801
  size: PhotoSize
809
802
  mode?: PhotoMode
810
- /** `direct` disables BLE fallback; `ble` skips direct upload and forces phone-relayed transfer. */
811
- transferMethod?: PhotoTransferMethod
812
- webhookUrl: string | null
813
- authToken: string | null
814
- /**
815
- * Keep the photo on the phone: it comes over BLE, is saved as a JPEG file, and the success
816
- * response carries that file's `file://` URI as `photoUrl`, with `fileSizeBytes`. Nothing is
817
- * uploaded, and `webhookUrl`, `authToken` and `transferMethod` are ignored. The file is in the
818
- * app's cache folder and is the caller's to move or delete. Default false.
819
- */
820
- localFile?: boolean
821
803
  compress?: PhotoCompression
822
804
  save?: boolean
823
805
  sound: boolean
@@ -839,6 +821,39 @@ export type PhotoRequestParams = {
839
821
  ispAnalogGain?: string
840
822
  }
841
823
 
824
+ /** A photo uploaded where `webhookUrl` says, by the glasses over Wi-Fi or by the phone over Bluetooth. */
825
+ export type PhotoUploadParams = PhotoCaptureParams & {
826
+ /** `direct` disables BLE fallback; `ble` skips direct upload and forces phone-relayed transfer. */
827
+ transferMethod?: PhotoTransferMethod
828
+ webhookUrl: string | null
829
+ authToken: string | null
830
+ }
831
+
832
+ /** A photo's preview: the glasses' at most 500 px JPEG, as a `data:image/jpeg;base64,` URL. */
833
+ export type PhotoPreview = {url: string; width?: number; height?: number}
834
+
835
+ /** A full photo kept on the phone: a JPEG in the app's cache folder, the caller's to move or delete. */
836
+ export type PhotoTaken = {requestId: string; fileUri: string; mimeType: string; size: number}
837
+
838
+ /**
839
+ * One photo kept on the phone, in stages. Any number can be in flight: the glasses refuse a capture
840
+ * only while another one is being taken (`CAMERA_BUSY`), never because photos are being sent.
841
+ */
842
+ export interface PhotoCapture {
843
+ readonly requestId: string
844
+ /** Resolves once the glasses wrote the photo: the camera takes the next one. */
845
+ readonly captured: Promise<void>
846
+ /** The glasses' preview, which comes for every photo before its full size. */
847
+ readonly preview: Promise<PhotoPreview>
848
+ /**
849
+ * The full photo. The first call asks the glasses to send it; until then it waits on the
850
+ * glasses (deferred delivery), for 30 minutes at most. Later calls return the same photo.
851
+ */
852
+ photo(): Promise<PhotoTaken>
853
+ /** The full photo isn't needed: the glasses delete it. Stages not reached yet reject. */
854
+ release(): Promise<void>
855
+ }
856
+
842
857
  export type WarmUpCameraParams = {
843
858
  /** Supply this when the owner needs to call stopCameraWarmUp during teardown. */
844
859
  requestId?: string
@@ -1626,7 +1641,7 @@ export interface BluetoothSdkPublicModule {
1626
1641
  setAutoPowerOffEnabled(enabled: boolean): Promise<void>
1627
1642
  /**
1628
1643
  * @deprecated Sticky action-button photo presets are deprecated. Prefer per-request
1629
- * `requestPhoto(...)` options (e.g. `mode: "text"` for text sensor size/crop, or explicit per-shot
1644
+ * `uploadPhoto(...)` options (e.g. `mode: "text"` for text sensor size/crop, or explicit per-shot
1630
1645
  * fields). Still functional until removed in a future release.
1631
1646
  */
1632
1647
  setPhotoCaptureDefaults(settings: PhotoCaptureDefaults): Promise<SettingsAckSuccessEvent>
@@ -1652,7 +1667,15 @@ export interface BluetoothSdkPublicModule {
1652
1667
  */
1653
1668
  setCameraTuningConfig(anrOn: boolean, gainOn: boolean): Promise<SettingsAckSuccessEvent>
1654
1669
  queryGalleryStatus(): Promise<GalleryStatusEvent>
1655
- requestPhoto(params: PhotoRequestParams): Promise<PhotoSuccessResponseEvent>
1670
+ /**
1671
+ * A photo sent to `webhookUrl`: uploaded by the glasses over their own Wi-Fi, or relayed by the
1672
+ * phone over Bluetooth. Resolves once it is there. A photo kept on the phone is `takePhoto`.
1673
+ */
1674
+ uploadPhoto(params: PhotoUploadParams): Promise<PhotoSuccessResponseEvent>
1675
+ /** A photo kept on the phone, in stages: see {@link PhotoCapture}. */
1676
+ capturePhoto(params: PhotoCaptureParams): PhotoCapture
1677
+ /** A photo kept on the phone, whole: `capturePhoto(params).photo()`, then its release. */
1678
+ takePhoto(params: PhotoCaptureParams): Promise<PhotoTaken>
1656
1679
  warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>
1657
1680
  /** Release one request-owned warm-up. Opening requests reject with camera_warm_up_cancelled. */
1658
1681
  stopCameraWarmUp(requestId: string): Promise<void>
@@ -1875,6 +1898,8 @@ export interface GlassesStatus {
1875
1898
  packageName: string
1876
1899
  /** Phone-served hotspot OTA protocol version; 0 means unsupported/legacy glasses. */
1877
1900
  hotspotOtaVersion: number
1901
+ /** Deferred photos (`capturePhoto` keeps the full photo on the glasses until asked); 0 without. */
1902
+ deferredPhotosVersion?: number
1878
1903
  bluetoothName: string
1879
1904
  serialNumber: string
1880
1905
  style: string