@mentra/bluetooth-sdk 3.5.0-dev.1505 → 3.5.0-dev.1506

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 (42) hide show
  1. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +14 -0
  2. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +14 -0
  3. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +1 -0
  4. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  5. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +51 -1
  6. package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +24 -0
  7. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +85 -5
  8. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +7 -0
  9. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +16 -0
  10. package/build/BluetoothSdk.types.d.ts +34 -0
  11. package/build/BluetoothSdk.types.d.ts.map +1 -1
  12. package/build/BluetoothSdk.types.js.map +1 -1
  13. package/build/_private/BluetoothSdkModule.d.ts +3 -1
  14. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  15. package/build/_private/BluetoothSdkModule.js +14 -0
  16. package/build/_private/BluetoothSdkModule.js.map +1 -1
  17. package/build/_private/photoRequestPayload.d.ts.map +1 -1
  18. package/build/_private/photoRequestPayload.js +3 -0
  19. package/build/_private/photoRequestPayload.js.map +1 -1
  20. package/build/generated/releaseMetadata.js +5 -5
  21. package/build/generated/releaseMetadata.js.map +1 -1
  22. package/build/index.d.ts +1 -1
  23. package/build/index.d.ts.map +1 -1
  24. package/build/index.js +2 -0
  25. package/build/index.js.map +1 -1
  26. package/ios/BluetoothSdkModule.swift +15 -0
  27. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  28. package/ios/Source/DeviceManager.swift +10 -0
  29. package/ios/Source/DeviceStore.swift +1 -0
  30. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  31. package/ios/Source/MentraBluetoothSDK.swift +53 -2
  32. package/ios/Source/camera/CameraModels.swift +44 -8
  33. package/ios/Source/sgcs/MentraLive.swift +83 -6
  34. package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +5 -0
  35. package/ios/Source/status/DeviceStatus.swift +9 -0
  36. package/ios/Tests/PhotoRequestRoutingTests.swift +31 -0
  37. package/package.json +2 -2
  38. package/src/BluetoothSdk.types.ts +35 -0
  39. package/src/_private/BluetoothSdkModule.ts +22 -0
  40. package/src/_private/photoRequestPayload.ts +3 -0
  41. package/src/generated/releaseMetadata.ts +5 -5
  42. package/src/index.ts +3 -0
@@ -1217,12 +1217,15 @@ public final class MentraBluetoothSDK {
1217
1217
  Bridge.log(
1218
1218
  "NATIVE: PHOTO PIPELINE [3b/6] MentraBluetoothSdk.requestPhoto requestId=\(routedRequest.requestId)"
1219
1219
  )
1220
+ if routedRequest.holdsPhoto { try requireHeldPhotos() }
1220
1221
  let pending = PendingResponse<PhotoResponseEvent>(operation: "photo request \(routedRequest.requestId)", telemetryOperation: "photo request", onTimeout: requestTimeoutReporter)
1221
1222
  pendingPhotoRequests[routedRequest.requestId] = pending
1222
1223
  do {
1223
1224
  let event = try await withUsageOutcome(record: { (latencyMs, errorCode, event: PhotoResponseEvent?) in
1224
1225
  var fileSizeBytes: Int64?
1225
- if case let .success(_, _, _, _, _, size?, _) = event?.response { fileSizeBytes = Int64(size) }
1226
+ if case let .success(_, _, _, _, _, size?, _, _, _, _) = event?.response {
1227
+ fileSizeBytes = Int64(size)
1228
+ }
1226
1229
  analytics.recordUsage {
1227
1230
  $0.photoSettled(
1228
1231
  size: routedRequest.size.rawValue,
@@ -1237,7 +1240,7 @@ public final class MentraBluetoothSDK {
1237
1240
  }
1238
1241
  }) {
1239
1242
  DeviceManager.shared.requestPhoto(routedRequest)
1240
- return try await pending.wait(timeoutMs: routedRequest.presendThumbnail
1243
+ return try await pending.wait(timeoutMs: routedRequest.presendThumbnail || routedRequest.holdsPhoto
1241
1244
  ? MentraBluetoothSDK.photoThumbnailRequestTimeoutMs
1242
1245
  : MentraBluetoothSDK.photoRequestTimeoutMs)
1243
1246
  }
@@ -1249,6 +1252,54 @@ public final class MentraBluetoothSDK {
1249
1252
  }
1250
1253
  }
1251
1254
 
1255
+ private func requireHeldPhotos() throws {
1256
+ if glassesStatus.heldPhotosVersion <= 0 {
1257
+ throw BluetoothSdkError(
1258
+ code: "held_photos_unsupported",
1259
+ message: "These glasses can't hold photos. Update the glasses software, or request whole photos."
1260
+ )
1261
+ }
1262
+ }
1263
+
1264
+ /// Fetch the full size of a photo the glasses hold (a request with `deliver = "thumbnail"`),
1265
+ /// over Bluetooth. Resolves like `requestPhoto`: with the file's URI as `photoUrl` when
1266
+ /// `localFile`, else once it is uploaded to `webhookUrl`. The glasses keep the photo until
1267
+ /// `releaseHeldPhotos` or 30 minutes after capture, so a failed fetch can be retried.
1268
+ public func fetchHeldPhoto(
1269
+ requestId: String,
1270
+ localFile: Bool = true,
1271
+ webhookUrl: String? = nil,
1272
+ authToken: String? = nil
1273
+ ) async throws -> PhotoResponseEvent {
1274
+ guard let id = nonBlankRequestId(requestId) else {
1275
+ throw BluetoothSdkError(code: "invalid_request", message: "A photo request ID is required.")
1276
+ }
1277
+ if !localFile, webhookUrl?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ?? true {
1278
+ throw BluetoothSdkError(code: "invalid_request", message: "Fetch to a file, or give a webhookUrl.")
1279
+ }
1280
+ try requireHeldPhotos()
1281
+ if pendingPhotoRequests[id] != nil {
1282
+ throw BluetoothSdkError(code: "request_in_flight", message: "This photo is already being fetched.")
1283
+ }
1284
+ let pending = PendingResponse<PhotoResponseEvent>(operation: "held photo fetch \(id)", telemetryOperation: "held photo fetch", onTimeout: requestTimeoutReporter)
1285
+ pendingPhotoRequests[id] = pending
1286
+ defer {
1287
+ if pendingPhotoRequests[id] === pending {
1288
+ pendingPhotoRequests.removeValue(forKey: id)
1289
+ }
1290
+ }
1291
+ try DeviceManager.shared.fetchHeldPhoto(
1292
+ requestId: id, localFile: localFile, webhookUrl: webhookUrl, authToken: authToken
1293
+ )
1294
+ return try await pending.wait(timeoutMs: MentraBluetoothSDK.photoThumbnailRequestTimeoutMs)
1295
+ }
1296
+
1297
+ /// Delete held photos on the glasses: these request IDs, or every held photo when nil.
1298
+ public func releaseHeldPhotos(requestIds: [String]? = nil) throws {
1299
+ try requireHeldPhotos()
1300
+ try DeviceManager.shared.releaseHeldPhotos(requestIds: requestIds)
1301
+ }
1302
+
1252
1303
  public func warmUpCamera(
1253
1304
  requestId: String? = nil,
1254
1305
  size: PhotoSize,
@@ -278,6 +278,17 @@ public struct PhotoRequest {
278
278
  /// success response carries that file's URL as `photoUrl`. Nothing is uploaded, and
279
279
  /// `webhookUrl` and `transferMethod` are ignored.
280
280
  public let localFile: Bool
281
+ /// `"thumbnail"`: the glasses hold the full photo and send only its preview; the response
282
+ /// comes once the preview arrived, with `held` and `thumbnailUrl`. Fetch the full photo later
283
+ /// with `fetchHeldPhoto`, and release the rest with `releaseHeldPhotos`. Needs glasses whose
284
+ /// status has `heldPhotosVersion` > 0. `webhookUrl` and `transferMethod` are ignored.
285
+ public let deliver: String?
286
+
287
+ public static let deliverThumbnail = "thumbnail"
288
+
289
+ public var holdsPhoto: Bool {
290
+ deliver == PhotoRequest.deliverThumbnail
291
+ }
281
292
 
282
293
  public init(
283
294
  requestId: String? = nil,
@@ -300,7 +311,8 @@ public struct PhotoRequest {
300
311
  mode: PhotoMode = .photo,
301
312
  transferMethod: String = "auto",
302
313
  presendThumbnail: Bool = false,
303
- localFile: Bool = false
314
+ localFile: Bool = false,
315
+ deliver: String? = nil
304
316
  ) {
305
317
  self.requestId = nonBlankRequestId(requestId) ?? generatedCameraRequestId("photo")
306
318
  self.size = size
@@ -323,6 +335,7 @@ public struct PhotoRequest {
323
335
  self.transferMethod = transferMethod
324
336
  self.presendThumbnail = presendThumbnail
325
337
  self.localFile = localFile
338
+ self.deliver = deliver
326
339
  }
327
340
 
328
341
  public static func from(params: [String: Any]) throws -> PhotoRequest {
@@ -407,7 +420,8 @@ public struct PhotoRequest {
407
420
  mode: PhotoMode(normalizedRawValue: params["mode"] as? String),
408
421
  transferMethod: transferMethod,
409
422
  presendThumbnail: params["presend_thumbnail"] as? Bool ?? false,
410
- localFile: params["localFile"] as? Bool ?? false
423
+ localFile: params["localFile"] as? Bool ?? false,
424
+ deliver: (params["deliver"] as? String).flatMap { $0 == deliverThumbnail ? $0 : nil }
411
425
  )
412
426
  }
413
427
 
@@ -473,7 +487,8 @@ public struct PhotoRequest {
473
487
  mode: mode,
474
488
  transferMethod: transferMethod,
475
489
  presendThumbnail: presendThumbnail,
476
- localFile: localFile
490
+ localFile: localFile,
491
+ deliver: deliver
477
492
  )
478
493
  }
479
494
  }
@@ -645,7 +660,13 @@ public enum PhotoResponse: CustomStringConvertible, Equatable {
645
660
  statusUrl: String?,
646
661
  contentType: String?,
647
662
  fileSizeBytes: Int?,
648
- timestamp: Int
663
+ timestamp: Int,
664
+ // The glasses hold the full photo (a `deliver = "thumbnail"` request).
665
+ held: Bool = false,
666
+ // The held photo's preview, as a `data:image/jpeg;base64,` URI.
667
+ thumbnailUrl: String? = nil,
668
+ // When the glasses captured the held photo (ms since the epoch).
669
+ capturedAt: Int? = nil
649
670
  )
650
671
  case error(requestId: String, errorCode: String?, errorMessage: String, timestamp: Int)
651
672
 
@@ -663,7 +684,10 @@ public enum PhotoResponse: CustomStringConvertible, Equatable {
663
684
  contentType: stringValue(values, "contentType") ?? stringValue(values, "mimeType"),
664
685
  fileSizeBytes: intValue(values["fileSizeBytes"]) ?? intValue(values["bytes"])
665
686
  ?? intValue(values["size"]),
666
- timestamp: timestamp
687
+ timestamp: timestamp,
688
+ held: boolValue(values, "held") == true,
689
+ thumbnailUrl: stringValue(values, "thumbnailUrl"),
690
+ capturedAt: intValue(values["capturedAt"])
667
691
  )
668
692
  } else {
669
693
  self = .error(
@@ -687,21 +711,24 @@ public enum PhotoResponse: CustomStringConvertible, Equatable {
687
711
 
688
712
  public var requestId: String {
689
713
  switch self {
690
- case let .success(requestId, _, _, _, _, _, _), let .error(requestId, _, _, _):
714
+ case let .success(requestId, _, _, _, _, _, _, _, _, _), let .error(requestId, _, _, _):
691
715
  requestId
692
716
  }
693
717
  }
694
718
 
695
719
  public var timestamp: Int {
696
720
  switch self {
697
- case let .success(_, _, _, _, _, _, timestamp), let .error(_, _, _, timestamp):
721
+ case let .success(_, _, _, _, _, _, timestamp, _, _, _), let .error(_, _, _, timestamp):
698
722
  timestamp
699
723
  }
700
724
  }
701
725
 
702
726
  public var values: [String: Any] {
703
727
  switch self {
704
- case let .success(requestId, uploadUrl, photoUrl, statusUrl, contentType, fileSizeBytes, timestamp):
728
+ case let .success(
729
+ requestId, uploadUrl, photoUrl, statusUrl, contentType, fileSizeBytes, timestamp, held, thumbnailUrl,
730
+ capturedAt
731
+ ):
705
732
  var values: [String: Any] = [
706
733
  "state": State.success.rawValue,
707
734
  "requestId": requestId,
@@ -720,6 +747,15 @@ public enum PhotoResponse: CustomStringConvertible, Equatable {
720
747
  if let fileSizeBytes {
721
748
  values["fileSizeBytes"] = fileSizeBytes
722
749
  }
750
+ if held {
751
+ values["held"] = true
752
+ }
753
+ if let thumbnailUrl, !thumbnailUrl.isEmpty {
754
+ values["thumbnailUrl"] = thumbnailUrl
755
+ }
756
+ if let capturedAt {
757
+ values["capturedAt"] = capturedAt
758
+ }
723
759
  return values
724
760
  case let .error(requestId, errorCode, errorMessage, timestamp):
725
761
  var values: [String: Any] = [
@@ -711,6 +711,8 @@ enum K900ProtocolUtils {
711
711
 
712
712
  private struct BlePhotoTransfer {
713
713
  var isThumbnail = false
714
+ /// A held-photo request (deliver "thumbnail"): no full photo follows its preview.
715
+ var held = false
714
716
  /// The photo stays on the phone as a file instead of being uploaded.
715
717
  var localFile = false
716
718
  let bleImgId: String
@@ -1535,6 +1537,8 @@ class MentraLive: NSObject, SGCManager {
1535
1537
  DeviceStore.shared.apply("glasses", "bluetoothMacAddress", "")
1536
1538
  DeviceStore.shared.apply("glasses", "wifiMacAddress", "")
1537
1539
  DeviceStore.shared.apply("glasses", "hotspotOtaVersion", 0)
1540
+ DeviceStore.shared.apply("glasses", "heldPhotosVersion", 0)
1541
+ heldPreviews.removeAll()
1538
1542
  }
1539
1543
  connectionState = state
1540
1544
  pairFlow(
@@ -1690,6 +1694,19 @@ 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
+ /// Held photos' previews (data URIs) by requestId, until the request's terminal response.
1698
+ private var heldPreviews = [String: String]()
1699
+ private var lastBleImgNumber = 0
1700
+ private let bleImgIdLock = NSLock()
1701
+
1702
+ /// A Bluetooth image ID no other transfer of this process has: the clock's milliseconds, or one
1703
+ /// past the last ID when two requests fall in the same millisecond (a burst, concurrent fetches).
1704
+ private func nextBleImgId() -> String {
1705
+ bleImgIdLock.lock()
1706
+ defer { bleImgIdLock.unlock() }
1707
+ lastBleImgNumber = max(Int(Date().timeIntervalSince1970 * 1000), lastBleImgNumber + 1)
1708
+ return "I" + String(format: "%09d", lastBleImgNumber % 100_000_000)
1709
+ }
1693
1710
  private(set) var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
1694
1711
  /// BES bytes kept on the phone until the MTK log for the same report has been uploaded.
1695
1712
  private var heldBesLogs = [String: HeldBesLog]()
@@ -2619,13 +2636,25 @@ class MentraLive: NSObject, SGCManager {
2619
2636
  ]
2620
2637
 
2621
2638
  // Always generate BLE ID for potential fallback
2622
- let bleImgId =
2623
- "I" + String(format: "%09d", Int(Date().timeIntervalSince1970 * 1000) % 100_000_000)
2639
+ let bleImgId = nextBleImgId()
2624
2640
  json["bleImgId"] = bleImgId
2625
2641
  json["transferMethod"] = request.localFile ? "ble" : request.transferMethod
2626
2642
  if request.presendThumbnail { json["presend_thumbnail"] = true }
2643
+ if request.holdsPhoto {
2644
+ json["deliver"] = PhotoRequest.deliverThumbnail
2645
+ }
2627
2646
 
2628
- if request.localFile {
2647
+ if request.holdsPhoto {
2648
+ // Only the preview crosses now; it finds this request by its "T" ID.
2649
+ var transfer = BlePhotoTransfer(
2650
+ bleImgId: bleImgId, requestId: request.requestId, webhookUrl: ""
2651
+ )
2652
+ transfer.held = true
2653
+ blePhotoTransfers[bleImgId] = transfer
2654
+ if let webhookUrl = request.webhookUrl, !webhookUrl.isEmpty {
2655
+ json["webhookUrl"] = webhookUrl
2656
+ }
2657
+ } else if request.localFile {
2629
2658
  var transfer = BlePhotoTransfer(
2630
2659
  bleImgId: bleImgId, requestId: request.requestId, webhookUrl: ""
2631
2660
  )
@@ -2683,6 +2712,35 @@ class MentraLive: NSObject, SGCManager {
2683
2712
  sendJson(json, wakeUp: true)
2684
2713
  }
2685
2714
 
2715
+ /// Send a held photo's full size over Bluetooth, through the ordinary BLE photo transfer for
2716
+ /// its request: saved on the phone (`localFile`) or uploaded to `webhookUrl`, then the usual
2717
+ /// terminal `photo_response` for `requestId`.
2718
+ func fetchHeldPhoto(requestId: String, localFile: Bool, webhookUrl: String?, authToken: String?) {
2719
+ let bleImgId = nextBleImgId()
2720
+ var transfer = BlePhotoTransfer(
2721
+ bleImgId: bleImgId, requestId: requestId, webhookUrl: localFile ? "" : webhookUrl ?? ""
2722
+ )
2723
+ transfer.localFile = localFile
2724
+ transfer.authToken = authToken
2725
+ blePhotoTransfers[bleImgId] = transfer
2726
+ Bridge.log("LIVE: Fetching held photo \(requestId) as \(bleImgId)")
2727
+ sendJson(
2728
+ ["type": "fetch_photo", "requestId": requestId, "bleImgId": bleImgId],
2729
+ wakeUp: true
2730
+ )
2731
+ }
2732
+
2733
+ /// Delete held photos on the glasses: these, or all of them when `requestIds` is nil.
2734
+ func releaseHeldPhotos(requestIds: [String]?) {
2735
+ var json: [String: Any] = ["type": "release_photos"]
2736
+ if let requestIds {
2737
+ json["requestIds"] = requestIds
2738
+ } else {
2739
+ json["all"] = true
2740
+ }
2741
+ sendJson(json, wakeUp: true)
2742
+ }
2743
+
2686
2744
  func warmUpCamera(
2687
2745
  requestId: String,
2688
2746
  size: PhotoSize,
@@ -3630,6 +3688,15 @@ class MentraLive: NSObject, SGCManager {
3630
3688
  emitCameraStatus(json)
3631
3689
 
3632
3690
  case "photo_response":
3691
+ var json = json
3692
+ if json["fetch"] as? Bool != true {
3693
+ // A held photo's request ended (or failed): no full photo follows its preview.
3694
+ let requestId = json["requestId"] as? String ?? ""
3695
+ blePhotoTransfers = blePhotoTransfers.filter { !($0.value.held && $0.value.requestId == requestId) }
3696
+ let preview = heldPreviews.removeValue(forKey: requestId)
3697
+ let photoSuccess = json["state"] as? String == "success" || json["success"] as? Bool == true
3698
+ if photoSuccess, let preview { json["thumbnailUrl"] = preview }
3699
+ }
3633
3700
  emitPhotoResponse(json)
3634
3701
 
3635
3702
  case "gallery_status":
@@ -3997,6 +4064,9 @@ class MentraLive: NSObject, SGCManager {
3997
4064
  if let systemTimeMs = fields["system_time_ms"] as? NSNumber {
3998
4065
  DeviceStore.shared.apply("glasses", "systemTimeMs", systemTimeMs.int64Value)
3999
4066
  }
4067
+ if let heldPhotosVersion = fields["held_photos"] as? NSNumber {
4068
+ DeviceStore.shared.apply("glasses", "heldPhotosVersion", heldPhotosVersion.intValue)
4069
+ }
4000
4070
  if let hotspotOtaVersion = fields["hotspot_ota_version"] as? NSNumber {
4001
4071
  DeviceStore.shared.apply(
4002
4072
  "glasses",
@@ -5183,9 +5253,12 @@ class MentraLive: NSObject, SGCManager {
5183
5253
  let requestId = json["requestId"] as? String ?? ""
5184
5254
  let compressionDurationMs = json["compressionDurationMs"] as? Int64 ?? 0
5185
5255
  if json["thumbnail"] as? Bool == true, !bleImgId.isEmpty, !requestId.isEmpty {
5186
- guard blePhotoTransfers.values.contains(where: {
5256
+ let parent = blePhotoTransfers.values.first(where: {
5187
5257
  !$0.isThumbnail && $0.requestId == requestId && bleImgId == "T" + $0.bleImgId.dropFirst()
5188
- }) else {
5258
+ })
5259
+ // A held preview names itself: after a reconnect this connection has no parent.
5260
+ let held = json["held"] as? Bool == true || parent?.held == true
5261
+ if parent == nil && !held {
5189
5262
  Bridge.log("LIVE: Ignoring thumbnail for an unknown photo request")
5190
5263
  return
5191
5264
  }
@@ -5193,6 +5266,7 @@ class MentraLive: NSObject, SGCManager {
5193
5266
  if blePhotoTransfers[bleImgId] == nil {
5194
5267
  var transfer = BlePhotoTransfer(bleImgId: bleImgId, requestId: requestId, webhookUrl: "")
5195
5268
  transfer.isThumbnail = true
5269
+ transfer.held = held
5196
5270
  blePhotoTransfers[bleImgId] = transfer
5197
5271
  }
5198
5272
  }
@@ -5931,12 +6005,15 @@ class MentraLive: NSObject, SGCManager {
5931
6005
 
5932
6006
  private func processAndUploadBlePhoto(_ transfer: BlePhotoTransfer, imageData: Data) {
5933
6007
  if transfer.isThumbnail {
6008
+ let thumbnailUrl = "data:image/jpeg;base64," + imageData.base64EncodedString()
6009
+ // The held request's terminal response follows this preview's acknowledgement.
6010
+ if transfer.held { heldPreviews[transfer.requestId] = thumbnailUrl }
5934
6011
  Bridge.sendPhotoStatus([
5935
6012
  "type": "photo_status",
5936
6013
  "requestId": transfer.requestId,
5937
6014
  "status": "thumbnail_received",
5938
6015
  "timestamp": Int64(Date().timeIntervalSince1970 * 1000),
5939
- "thumbnailUrl": "data:image/jpeg;base64," + imageData.base64EncodedString(),
6016
+ "thumbnailUrl": thumbnailUrl,
5940
6017
  "fileSizeBytes": imageData.count,
5941
6018
  ])
5942
6019
  return
@@ -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 {
@@ -231,6 +231,11 @@ struct GlassesStatus: CustomStringConvertible {
231
231
  intValue(values["hotspotOtaVersion"]) ?? 0
232
232
  }
233
233
 
234
+ /// Held photos (take_photo deliver "thumbnail"): the glasses' version, 0 without.
235
+ var heldPhotosVersion: Int {
236
+ intValue(values["heldPhotosVersion"]) ?? 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 heldPhotosVersion: Int? {
795
+ optionalIntValue(values, "heldPhotosVersion")
796
+ }
797
+
789
798
  var bluetoothName: String? {
790
799
  optionalStringValue(values, "bluetoothName")
791
800
  }
@@ -24,6 +24,7 @@ final class PhotoRequestRoutingTests: XCTestCase {
24
24
  "ispAnalogGain": "4x",
25
25
  "presend_thumbnail": true,
26
26
  "localFile": true,
27
+ "deliver": "thumbnail",
27
28
  ]
28
29
 
29
30
  private func assertSameCapture(_ routed: PhotoRequest, _ request: PhotoRequest, line: UInt = #line) {
@@ -45,6 +46,7 @@ final class PhotoRequestRoutingTests: XCTestCase {
45
46
  XCTAssertEqual(routed.ispAnalogGain, request.ispAnalogGain, line: line)
46
47
  XCTAssertEqual(routed.presendThumbnail, request.presendThumbnail, line: line)
47
48
  XCTAssertEqual(routed.localFile, request.localFile, line: line)
49
+ XCTAssertEqual(routed.deliver, request.deliver, line: line)
48
50
  }
49
51
 
50
52
  /// The glasses were never asked for a thumbnail on iOS: routing rebuilt the request without the flag.
@@ -87,4 +89,33 @@ final class PhotoRequestRoutingTests: XCTestCase {
87
89
  XCTAssertEqual(manual.exposureTimeNs, 8_000_000)
88
90
  XCTAssertNil(manual.iso)
89
91
  }
92
+
93
+ func testHeldPhotoOptionsAreParsedAndOnlyKnownValuesKept() throws {
94
+ let held = try PhotoRequest.from(params: ["deliver": "thumbnail"])
95
+ XCTAssertTrue(held.holdsPhoto)
96
+
97
+ let whole = try PhotoRequest.from(params: ["deliver": "full"])
98
+ XCTAssertNil(whole.deliver)
99
+ XCTAssertFalse(whole.holdsPhoto)
100
+ }
101
+
102
+ func testHeldPhotoResponseKeepsItsMetadata() {
103
+ let event = PhotoResponseEvent(values: [
104
+ "requestId": "photo-1",
105
+ "success": true,
106
+ "held": true,
107
+ "thumbnailUrl": "data:image/jpeg;base64,AA==",
108
+ "capturedAt": 1_700_000_000_000,
109
+ "bytes": 1234,
110
+ ])
111
+ XCTAssertEqual(event.values["held"] as? Bool, true)
112
+ XCTAssertEqual(event.values["thumbnailUrl"] as? String, "data:image/jpeg;base64,AA==")
113
+ XCTAssertEqual(event.values["capturedAt"] as? Int, 1_700_000_000_000)
114
+ XCTAssertEqual(event.values["fileSizeBytes"] as? Int, 1234)
115
+
116
+ let whole = PhotoResponseEvent(values: ["requestId": "photo-2", "success": true])
117
+ XCTAssertNil(whole.values["held"])
118
+ XCTAssertNil(whole.values["thumbnailUrl"])
119
+ XCTAssertNil(whole.values["capturedAt"])
120
+ }
90
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "3.5.0-dev.1505",
3
+ "version": "3.5.0-dev.1506",
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.1505"
118
+ "@mentra/cloud-protocol": "3.5.0-dev.1506"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@types/node": "^25.9.3",
@@ -331,6 +331,12 @@ export type PhotoResponseEvent =
331
331
  transferMs?: number
332
332
  /** From the phone's request to the saved file. */
333
333
  totalMs?: number
334
+ /** The glasses hold the full photo: a `deliver: "thumbnail"` request. */
335
+ held?: boolean
336
+ /** A held photo's preview (≤500 px JPEG), as a `data:image/jpeg;base64,` URI. */
337
+ thumbnailUrl?: string
338
+ /** When the glasses captured the held photo, in ms since the epoch. */
339
+ capturedAt?: number
334
340
  }
335
341
  | {
336
342
  type: "photo_response"
@@ -831,7 +837,26 @@ type NativeCameraFovSetting = {
831
837
  export type MicPreference = "auto" | "phone" | "glasses" | "bluetooth"
832
838
  export type MicMode = "phone" | "glasses" | "bluetoothClassic" | "bluetooth"
833
839
 
840
+ /** Fetch a held photo's full size: see {@link BluetoothSdkPublicModule.fetchHeldPhoto}. */
841
+ export type FetchHeldPhotoParams = {
842
+ /** The `requestId` of the `deliver: "thumbnail"` request that took it. */
843
+ requestId: string
844
+ /** Save it as a file on the phone (default true); otherwise upload it to `webhookUrl`. */
845
+ localFile?: boolean
846
+ webhookUrl?: string
847
+ authToken?: string
848
+ }
849
+
834
850
  export type PhotoRequestParams = {
851
+ /**
852
+ * `"thumbnail"`: the glasses hold the full photo and send only its preview, and the request
853
+ * resolves once the preview arrived, with `held: true` and `thumbnailUrl`. The camera is free
854
+ * for the next request as soon as the capture is written. Fetch the full photo with
855
+ * `fetchHeldPhoto` and delete the rest with `releaseHeldPhotos`; the glasses delete held photos
856
+ * 30 minutes after capture. Needs `heldPhotosVersion > 0` in the glasses status. A preview that
857
+ * fails rejects with `PREVIEW_FAILED`, and the photo is still held.
858
+ */
859
+ deliver?: "thumbnail"
835
860
  /**
836
861
  * Send an oriented <=500px, quality-50 JPEG preview before the full photo. Default false.
837
862
  * Enables a 110-second end-to-end native deadline (ordinary requests: 30 seconds).
@@ -1698,6 +1723,14 @@ export interface BluetoothSdkPublicModule {
1698
1723
  setCameraTuningConfig(anrOn: boolean, gainOn: boolean): Promise<SettingsAckSuccessEvent>
1699
1724
  queryGalleryStatus(): Promise<GalleryStatusEvent>
1700
1725
  requestPhoto(params: PhotoRequestParams): Promise<PhotoSuccessResponseEvent>
1726
+ /**
1727
+ * Fetch the full size of a photo the glasses hold (`deliver: "thumbnail"`), over Bluetooth.
1728
+ * Resolves like `requestPhoto`: with the file's `file://` URI as `photoUrl`, or once uploaded.
1729
+ * The glasses keep the photo, so a failed fetch can be retried.
1730
+ */
1731
+ fetchHeldPhoto(params: FetchHeldPhotoParams): Promise<PhotoSuccessResponseEvent>
1732
+ /** Delete held photos on the glasses: these request IDs, or all of them when omitted. */
1733
+ releaseHeldPhotos(requestIds?: string[] | null): Promise<void>
1701
1734
  warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>
1702
1735
  /** Release one request-owned warm-up. Opening requests reject with camera_warm_up_cancelled. */
1703
1736
  stopCameraWarmUp(requestId: string): Promise<void>
@@ -1920,6 +1953,8 @@ export interface GlassesStatus {
1920
1953
  packageName: string
1921
1954
  /** Phone-served hotspot OTA protocol version; 0 means unsupported/legacy glasses. */
1922
1955
  hotspotOtaVersion: number
1956
+ /** Held photos (`requestPhoto` with `deliver: "thumbnail"`); 0 means the glasses can't hold photos. */
1957
+ heldPhotosVersion?: number
1923
1958
  bluetoothName: string
1924
1959
  serialNumber: string
1925
1960
  style: string
@@ -37,6 +37,7 @@ import {
37
37
  ObservableStoreCategory,
38
38
  OtaQueryResult,
39
39
  OtaStartAckEvent,
40
+ FetchHeldPhotoParams,
40
41
  PhotoRequestParams,
41
42
  PhotoSuccessResponseEvent,
42
43
  PublicBluetoothStatus,
@@ -211,6 +212,8 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
211
212
  setCameraTuningConfig(anrOn: boolean, gainOn: boolean): Promise<SettingsAckSuccessEvent>
212
213
  queryGalleryStatus(): Promise<GalleryStatusEvent>
213
214
  requestPhoto(params: PhotoRequestParams): Promise<PhotoSuccessResponseEvent>
215
+ fetchHeldPhoto(params: FetchHeldPhotoParams): Promise<PhotoSuccessResponseEvent>
216
+ releaseHeldPhotos(requestIds?: string[] | null): Promise<void>
214
217
  warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>
215
218
  stopCameraWarmUp(requestId: string): Promise<void>
216
219
 
@@ -763,6 +766,25 @@ NativeBluetoothSdkModule.requestPhoto = function (params: PhotoRequestParams) {
763
766
  return nativeRequestPhoto(photoRequestParamsForNative(params) as unknown as PhotoRequestParams)
764
767
  }
765
768
 
769
+ const nativeFetchHeldPhoto = bindNativeMethod<(params: Record<string, string | boolean>) => Promise<PhotoSuccessResponseEvent>>(
770
+ NativeBluetoothSdkModule as unknown as Record<string, unknown>,
771
+ "fetchHeldPhoto",
772
+ )
773
+ NativeBluetoothSdkModule.fetchHeldPhoto = function (params: FetchHeldPhotoParams) {
774
+ // Expo's Android bridge rejects nulls in a map: send only what is set.
775
+ const payload: Record<string, string | boolean> = {requestId: params.requestId, localFile: params.localFile ?? true}
776
+ if (params.webhookUrl) payload.webhookUrl = params.webhookUrl
777
+ if (params.authToken) payload.authToken = params.authToken
778
+ return nativeFetchHeldPhoto(payload)
779
+ }
780
+ const nativeReleaseHeldPhotos = bindNativeMethod<(requestIds: string[] | null) => Promise<void>>(
781
+ NativeBluetoothSdkModule as unknown as Record<string, unknown>,
782
+ "releaseHeldPhotos",
783
+ )
784
+ NativeBluetoothSdkModule.releaseHeldPhotos = function (requestIds?: string[] | null) {
785
+ return nativeReleaseHeldPhotos(requestIds ?? null)
786
+ }
787
+
766
788
  const nativeWarmUpCamera = NativeBluetoothSdkModule.warmUpCamera.bind(NativeBluetoothSdkModule)
767
789
  NativeBluetoothSdkModule.warmUpCamera = function (params: WarmUpCameraParams) {
768
790
  return nativeWarmUpCamera(warmUpCameraParamsForNative(params) as unknown as WarmUpCameraParams)
@@ -52,6 +52,9 @@ export function photoRequestParamsForNative(params: PhotoRequestParams): Record<
52
52
  if (params.localFile === true) {
53
53
  payload.localFile = true
54
54
  }
55
+ if (params.deliver === "thumbnail") {
56
+ payload.deliver = "thumbnail"
57
+ }
55
58
  if (requestId != null) {
56
59
  payload.requestId = requestId
57
60
  }
@@ -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.5.0",
15
- "releaseIdentity": "3.5.0-dev.1505",
16
- "releaseSetId": "mentra-3.5.0-dev.1505",
17
- "sourceCommit": "01d8beea33cfb777a24014e8855bba6504e04a7a",
18
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1505.json",
19
- "otaManifestSha256": "bf1279d0c7fd5e4939f19581580334d090b5dea5c226506b60fd977c8178ea99"
15
+ "releaseIdentity": "3.5.0-dev.1506",
16
+ "releaseSetId": "mentra-3.5.0-dev.1506",
17
+ "sourceCommit": "f4fe4865c5938c216ffaf1d6291e6c924b6aacca",
18
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1506.json",
19
+ "otaManifestSha256": "05db21c8a7e9c5ce6b7a4c1e7a1c4b23b675f4886f4d6291fc1a0e55c5d48e99"
20
20
  })
package/src/index.ts CHANGED
@@ -184,6 +184,8 @@ export const BluetoothSdk: BluetoothSdkPublicModule = Object.freeze({
184
184
  setCameraTuningConfig: bindPublicMethod("setCameraTuningConfig"),
185
185
  queryGalleryStatus: bindPublicMethod("queryGalleryStatus"),
186
186
  requestPhoto: bindPublicMethod("requestPhoto"),
187
+ fetchHeldPhoto: bindPublicMethod("fetchHeldPhoto"),
188
+ releaseHeldPhotos: bindPublicMethod("releaseHeldPhotos"),
187
189
  warmUpCamera: bindPublicMethod("warmUpCamera"),
188
190
  stopCameraWarmUp: bindPublicMethod("stopCameraWarmUp"),
189
191
  startVideoRecording: bindPublicMethod("startVideoRecording"),
@@ -326,6 +328,7 @@ export type {
326
328
  PhotoTransferMethod,
327
329
  PhotoResponseEvent,
328
330
  PhotoRequestedCaptureConfig,
331
+ FetchHeldPhotoParams,
329
332
  PhotoRequestParams,
330
333
  PhotoSize,
331
334
  PhotoStatusEvent,