@mentra/bluetooth-sdk 3.5.0-dev.1363 → 3.5.0-dev.1367

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 (26) hide show
  1. package/README.md +9 -0
  2. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  3. package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +7 -0
  4. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +68 -5
  5. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +38 -0
  6. package/android/src/test/java/com/mentra/bluetoothsdk/camera/PhotoRequestTest.kt +10 -0
  7. package/android/src/test/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +32 -0
  8. package/build/BluetoothSdk.types.d.ts +9 -0
  9. package/build/BluetoothSdk.types.d.ts.map +1 -1
  10. package/build/BluetoothSdk.types.js.map +1 -1
  11. package/build/_private/photoRequestPayload.d.ts.map +1 -1
  12. package/build/_private/photoRequestPayload.js +3 -0
  13. package/build/_private/photoRequestPayload.js.map +1 -1
  14. package/build/generated/releaseMetadata.js +5 -5
  15. package/build/generated/releaseMetadata.js.map +1 -1
  16. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  17. package/ios/Source/DeviceManager.swift +2 -24
  18. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  19. package/ios/Source/camera/CameraModels.swift +24 -3
  20. package/ios/Source/sgcs/MentraLive.swift +85 -4
  21. package/ios/Tests/PhotoLocalFileTests.swift +41 -0
  22. package/ios/Tests/PhotoRequestRoutingTests.swift +90 -0
  23. package/package.json +2 -2
  24. package/src/BluetoothSdk.types.ts +9 -0
  25. package/src/_private/photoRequestPayload.ts +3 -0
  26. package/src/generated/releaseMetadata.ts +5 -5
@@ -130,6 +130,38 @@ class BlePhotoUploadService {
130
130
  }
131
131
  }
132
132
 
133
+ /**
134
+ * Process image data and keep it on the phone as a JPEG file in `directory`.
135
+ * Nothing is uploaded; the caller owns the file from then on.
136
+ * - Parameters:
137
+ * - imageData: Raw image data (AVIF or JPEG)
138
+ * - requestId: Original request ID for tracking
139
+ * - directory: Where the file goes; created when missing
140
+ */
141
+ static func processAndSavePhoto(
142
+ imageData: Data,
143
+ requestId: String,
144
+ directory: URL,
145
+ onSaved: @escaping (String, URL, Int) -> Void,
146
+ onError: @escaping (String, String) -> Void
147
+ ) {
148
+ Task {
149
+ do {
150
+ let jpegData = try convertToJpegPreservingExif(imageData: imageData)
151
+ try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
152
+ let file = directory.appendingPathComponent("photo_\(UUID().uuidString).jpg")
153
+ try jpegData.write(to: file, options: .atomic)
154
+ Bridge.log(
155
+ "\(TAG): Saved BLE photo on the phone for requestId: \(requestId) (\(jpegData.count) bytes)"
156
+ )
157
+ onSaved(requestId, file, jpegData.count)
158
+ } catch {
159
+ Bridge.log("\(TAG): Error saving BLE photo for requestId: \(requestId), error: \(error)")
160
+ onError(requestId, error.localizedDescription)
161
+ }
162
+ }
163
+ }
164
+
133
165
  private static func convertToJpegPreservingExif(imageData: Data) throws -> Data {
134
166
  logIncomingImageDiagnostics(imageData: imageData)
135
167
  if isJpeg(imageData) {
@@ -679,6 +711,8 @@ enum K900ProtocolUtils {
679
711
 
680
712
  private struct BlePhotoTransfer {
681
713
  var isThumbnail = false
714
+ /// The photo stays on the phone as a file instead of being uploaded.
715
+ var localFile = false
682
716
  let bleImgId: String
683
717
  let requestId: String
684
718
  let webhookUrl: String
@@ -2577,10 +2611,21 @@ class MentraLive: NSObject, SGCManager {
2577
2611
  let bleImgId =
2578
2612
  "I" + String(format: "%09d", Int(Date().timeIntervalSince1970 * 1000) % 100_000_000)
2579
2613
  json["bleImgId"] = bleImgId
2580
- json["transferMethod"] = request.transferMethod
2614
+ json["transferMethod"] = request.localFile ? "ble" : request.transferMethod
2581
2615
  if request.presendThumbnail { json["presend_thumbnail"] = true }
2582
2616
 
2583
- if let webhookUrl = request.webhookUrl, !webhookUrl.isEmpty {
2617
+ if request.localFile {
2618
+ var transfer = BlePhotoTransfer(
2619
+ bleImgId: bleImgId, requestId: request.requestId, webhookUrl: ""
2620
+ )
2621
+ transfer.localFile = true
2622
+ blePhotoTransfers[bleImgId] = transfer
2623
+ // A local photo has no upload target, but the glasses expect one: without it they
2624
+ // route a save-to-gallery request to their gallery and transfer nothing, and reject
2625
+ // a thumbnail request. So it names a stand-in, which the BLE transfer method never
2626
+ // contacts.
2627
+ json["webhookUrl"] = MentraLive.localPhotoTarget
2628
+ } else if let webhookUrl = request.webhookUrl, !webhookUrl.isEmpty {
2584
2629
  json["webhookUrl"] = webhookUrl
2585
2630
 
2586
2631
  var transfer = BlePhotoTransfer(
@@ -2596,7 +2641,7 @@ class MentraLive: NSObject, SGCManager {
2596
2641
  }
2597
2642
 
2598
2643
  // Add authToken to JSON if provided
2599
- if let authToken = request.authToken, !authToken.isEmpty {
2644
+ if !request.localFile, let authToken = request.authToken, !authToken.isEmpty {
2600
2645
  json["authToken"] = authToken
2601
2646
  }
2602
2647
 
@@ -2620,7 +2665,7 @@ class MentraLive: NSObject, SGCManager {
2620
2665
  request.appendScanFields(to: &json)
2621
2666
 
2622
2667
  Bridge.log(
2623
- "LIVE: PHOTO PIPELINE [5b/6] take_photo JSON ready bleImgId=\(bleImgId) transferMethod=\(request.transferMethod)"
2668
+ "LIVE: PHOTO PIPELINE [5b/6] take_photo JSON ready bleImgId=\(bleImgId) transferMethod=\(request.localFile ? "ble (local file)" : request.transferMethod)"
2624
2669
  )
2625
2670
  Bridge.log("LIVE: PHOTO PIPELINE [6/6] Dispatching take_photo to sendJson()")
2626
2671
 
@@ -5883,6 +5928,10 @@ class MentraLive: NSObject, SGCManager {
5883
5928
  ])
5884
5929
  return
5885
5930
  }
5931
+ if transfer.localFile {
5932
+ saveBlePhotoOnPhone(transfer, imageData: imageData)
5933
+ return
5934
+ }
5886
5935
  Bridge.log("LIVE: Processing BLE photo for upload. RequestId: \(transfer.requestId)")
5887
5936
 
5888
5937
  BlePhotoUploadService.processAndUploadPhoto(
@@ -5903,6 +5952,38 @@ class MentraLive: NSObject, SGCManager {
5903
5952
  }
5904
5953
  }
5905
5954
 
5955
+ /// Stand-in upload target the glasses are given for a local photo. Never contacted.
5956
+ private static let localPhotoTarget = "phone://local-photo"
5957
+
5958
+ /// Keep a BLE photo on the phone as a JPEG file and answer the request with its file URL.
5959
+ private func saveBlePhotoOnPhone(_ transfer: BlePhotoTransfer, imageData: Data) {
5960
+ Bridge.log("LIVE: Saving BLE photo on the phone. RequestId: \(transfer.requestId)")
5961
+ // The caller moves each file out of this cache folder.
5962
+ let directory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
5963
+ .appendingPathComponent("mentra_local_photos", isDirectory: true)
5964
+ BlePhotoUploadService.processAndSavePhoto(
5965
+ imageData: imageData, requestId: transfer.requestId, directory: directory
5966
+ ) { requestId, file, byteCount in
5967
+ Bridge.sendPhotoResponse([
5968
+ "type": "photo_response",
5969
+ "state": "success",
5970
+ "success": true,
5971
+ "requestId": requestId,
5972
+ "uploadUrl": "",
5973
+ "photoUrl": file.absoluteString,
5974
+ "contentType": "image/jpeg",
5975
+ "fileSizeBytes": byteCount,
5976
+ "timestamp": Int(Date().timeIntervalSince1970 * 1000),
5977
+ ])
5978
+ } onError: { requestId, error in
5979
+ Bridge.sendPhotoError(
5980
+ requestId: requestId,
5981
+ errorCode: "PHONE_SAVE_FAILED",
5982
+ errorMessage: "Could not save the photo on the phone: \(error)"
5983
+ )
5984
+ }
5985
+ }
5986
+
5906
5987
  private func sendPhotoTerminalSuccessResponse(
5907
5988
  requestId: String,
5908
5989
  uploadUrl: String,
@@ -0,0 +1,41 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
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
+ func testSavingKeepsAJpegOnThePhoneUnchanged() throws {
13
+ let jpeg = Data([0xFF, 0xD8, 1, 2, 3, 0xFF, 0xD9])
14
+ let directory = FileManager.default.temporaryDirectory
15
+ .appendingPathComponent("photo-local-file-tests-\(UUID().uuidString)", isDirectory: true)
16
+ .appendingPathComponent("nested", isDirectory: true)
17
+ defer { try? FileManager.default.removeItem(at: directory.deletingLastPathComponent()) }
18
+
19
+ let saved = expectation(description: "photo saved")
20
+ var savedFile: URL?
21
+ var savedBytes: Int?
22
+ BlePhotoUploadService.processAndSavePhoto(
23
+ imageData: jpeg, requestId: "0001", directory: directory
24
+ ) { requestId, file, byteCount in
25
+ XCTAssertEqual(requestId, "0001")
26
+ savedFile = file
27
+ savedBytes = byteCount
28
+ saved.fulfill()
29
+ } onError: { _, error in
30
+ XCTFail("save failed: \(error)")
31
+ saved.fulfill()
32
+ }
33
+ wait(for: [saved], timeout: 10)
34
+
35
+ let file = try XCTUnwrap(savedFile)
36
+ XCTAssertEqual(file.deletingLastPathComponent().path, directory.path)
37
+ XCTAssertEqual(file.pathExtension, "jpg")
38
+ XCTAssertEqual(savedBytes, jpeg.count)
39
+ XCTAssertEqual(try Data(contentsOf: file), jpeg)
40
+ }
41
+ }
@@ -0,0 +1,90 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ final class PhotoRequestRoutingTests: XCTestCase {
5
+ private let everyField: [String: Any] = [
6
+ "requestId": "photo-1",
7
+ "size": "high",
8
+ "mode": "text",
9
+ "transferMethod": "direct",
10
+ "webhookUrl": "https://example.com/upload",
11
+ "authToken": "token",
12
+ "compress": "medium",
13
+ "save": true,
14
+ "sound": false,
15
+ "exposureTimeNs": 8_000_000.0,
16
+ "iso": 400,
17
+ "aeExposureDivisor": 4,
18
+ "isoCap": 800,
19
+ "noiseReduction": true,
20
+ "edgeEnhancement": false,
21
+ "mfnr": true,
22
+ "zsl": false,
23
+ "ispDigitalGain": 2,
24
+ "ispAnalogGain": "4x",
25
+ "presend_thumbnail": true,
26
+ "localFile": true,
27
+ ]
28
+
29
+ private func assertSameCapture(_ routed: PhotoRequest, _ request: PhotoRequest, line: UInt = #line) {
30
+ XCTAssertEqual(routed.size, request.size, line: line)
31
+ XCTAssertEqual(routed.mode, request.mode, line: line)
32
+ XCTAssertEqual(routed.transferMethod, request.transferMethod, line: line)
33
+ XCTAssertEqual(routed.webhookUrl, request.webhookUrl, line: line)
34
+ XCTAssertEqual(routed.authToken, request.authToken, line: line)
35
+ XCTAssertEqual(routed.compress, request.compress, line: line)
36
+ XCTAssertEqual(routed.save, request.save, line: line)
37
+ XCTAssertEqual(routed.sound, request.sound, line: line)
38
+ XCTAssertEqual(routed.aeExposureDivisor, request.aeExposureDivisor, line: line)
39
+ XCTAssertEqual(routed.isoCap, request.isoCap, line: line)
40
+ XCTAssertEqual(routed.noiseReduction, request.noiseReduction, line: line)
41
+ XCTAssertEqual(routed.edgeEnhancement, request.edgeEnhancement, line: line)
42
+ XCTAssertEqual(routed.mfnr, request.mfnr, line: line)
43
+ XCTAssertEqual(routed.zsl, request.zsl, line: line)
44
+ XCTAssertEqual(routed.ispDigitalGain, request.ispDigitalGain, line: line)
45
+ 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
+ }
57
+
58
+ func testRoutingKeepsEveryField() throws {
59
+ let request = try PhotoRequest.from(params: everyField)
60
+ XCTAssertTrue(request.presendThumbnail)
61
+ XCTAssertTrue(request.localFile)
62
+ XCTAssertEqual(request.aeExposureDivisor, 4)
63
+
64
+ let routed = request.routedForCapture()
65
+ XCTAssertEqual(routed.requestId, "photo-1")
66
+ XCTAssertEqual(routed.exposureTimeNs, 8_000_000.0)
67
+ XCTAssertEqual(routed.iso, 400)
68
+ assertSameCapture(routed, request)
69
+
70
+ let renamed = request.withRequestId("photo-2")
71
+ XCTAssertEqual(renamed.requestId, "photo-2")
72
+ XCTAssertEqual(renamed.exposureTimeNs, request.exposureTimeNs)
73
+ XCTAssertEqual(renamed.iso, request.iso)
74
+ assertSameCapture(renamed, request)
75
+ }
76
+
77
+ func testRoutingDropsAnIsoWithoutAManualExposure() {
78
+ let auto = PhotoRequest(size: .medium, sound: true, exposureTimeNs: nil, iso: 400).routedForCapture()
79
+ XCTAssertNil(auto.exposureTimeNs)
80
+ XCTAssertNil(auto.iso)
81
+
82
+ let invalid = PhotoRequest(size: .medium, sound: true, exposureTimeNs: -1, iso: 400).routedForCapture()
83
+ XCTAssertNil(invalid.exposureTimeNs)
84
+ XCTAssertNil(invalid.iso)
85
+
86
+ let manual = PhotoRequest(size: .medium, sound: true, exposureTimeNs: 8_000_000, iso: 0).routedForCapture()
87
+ XCTAssertEqual(manual.exposureTimeNs, 8_000_000)
88
+ XCTAssertNil(manual.iso)
89
+ }
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "3.5.0-dev.1363",
3
+ "version": "3.5.0-dev.1367",
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.1363"
118
+ "@mentra/cloud-protocol": "3.5.0-dev.1367"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@types/node": "^25.9.3",
@@ -280,7 +280,9 @@ export type PhotoResponseEvent =
280
280
  type: "photo_response"
281
281
  state: "success"
282
282
  requestId: string
283
+ /** Where the photo was uploaded; empty for a `localFile` request. */
283
284
  uploadUrl: string
285
+ /** The upload target's own URL for the photo, or the saved file's `file://` URI for a `localFile` request. */
284
286
  photoUrl?: string
285
287
  statusUrl?: string
286
288
  contentType?: string
@@ -800,6 +802,13 @@ export type PhotoRequestParams = {
800
802
  transferMethod?: PhotoTransferMethod
801
803
  webhookUrl: string | null
802
804
  authToken: string | null
805
+ /**
806
+ * Keep the photo on the phone: it comes over BLE, is saved as a JPEG file, and the success
807
+ * response carries that file's `file://` URI as `photoUrl`, with `fileSizeBytes`. Nothing is
808
+ * uploaded, and `webhookUrl`, `authToken` and `transferMethod` are ignored. The file is in the
809
+ * app's cache folder and is the caller's to move or delete. Default false.
810
+ */
811
+ localFile?: boolean
803
812
  compress?: PhotoCompression
804
813
  save?: boolean
805
814
  sound: boolean
@@ -49,6 +49,9 @@ export function photoRequestParamsForNative(params: PhotoRequestParams): Record<
49
49
  if (params.presend_thumbnail === true) {
50
50
  payload.presend_thumbnail = true
51
51
  }
52
+ if (params.localFile === true) {
53
+ payload.localFile = true
54
+ }
52
55
  if (requestId != null) {
53
56
  payload.requestId = requestId
54
57
  }
@@ -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.1363",
16
- "releaseSetId": "mentra-3.5.0-dev.1363",
17
- "sourceCommit": "0713e644f2417ddd4c770da140d979ec63c63618",
18
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1363.json",
19
- "otaManifestSha256": "1dea83340f1ae1a9610d8fc63c701ca25c02c836764df67111869387070376ed"
15
+ "releaseIdentity": "3.5.0-dev.1367",
16
+ "releaseSetId": "mentra-3.5.0-dev.1367",
17
+ "sourceCommit": "3ab054e9d73a9adb4f664716790c7c07624193cf",
18
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1367.json",
19
+ "otaManifestSha256": "44a188de304a2ab7767dffc26233f5042aab56553ab13b962045a3e539e14fcb"
20
20
  })