@mentra/bluetooth-sdk 3.5.0-dev.1518 → 3.5.0-dev.1519
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/MIGRATION.md +9 -0
- package/README.md +64 -11
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +10 -0
- package/build/BluetoothSdk.types.d.ts +23 -5
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js +5 -0
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_internal.d.ts +1 -0
- package/build/_internal.d.ts.map +1 -1
- package/build/_internal.js +1 -0
- package/build/_internal.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +20 -9
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts +21 -0
- package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
- package/build/_private/MentraLocalNetworkModule.js.map +1 -1
- package/build/generated/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/glasses-wifi/connection.d.ts +6 -0
- package/build/glasses-wifi/connection.d.ts.map +1 -0
- package/build/glasses-wifi/connection.js +44 -0
- package/build/glasses-wifi/connection.js.map +1 -0
- package/build/glasses-wifi/continuous.d.ts +39 -0
- package/build/glasses-wifi/continuous.d.ts.map +1 -0
- package/build/glasses-wifi/continuous.js +151 -0
- package/build/glasses-wifi/continuous.js.map +1 -0
- package/build/glasses-wifi/files.d.ts +11 -0
- package/build/glasses-wifi/files.d.ts.map +1 -0
- package/build/glasses-wifi/files.js +33 -0
- package/build/glasses-wifi/files.js.map +1 -0
- package/build/glasses-wifi/index.d.ts +20 -0
- package/build/glasses-wifi/index.d.ts.map +1 -0
- package/build/glasses-wifi/index.js +15 -0
- package/build/glasses-wifi/index.js.map +1 -0
- package/build/glasses-wifi/link.d.ts +31 -0
- package/build/glasses-wifi/link.d.ts.map +1 -0
- package/build/glasses-wifi/link.js +71 -0
- package/build/glasses-wifi/link.js.map +1 -0
- package/build/glasses-wifi/native.d.ts +63 -0
- package/build/glasses-wifi/native.d.ts.map +1 -0
- package/build/glasses-wifi/native.js +138 -0
- package/build/glasses-wifi/native.js.map +1 -0
- package/build/glasses-wifi/service.d.ts +86 -0
- package/build/glasses-wifi/service.d.ts.map +1 -0
- package/build/glasses-wifi/service.js +497 -0
- package/build/glasses-wifi/service.js.map +1 -0
- package/build/index.d.ts +4 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +24 -6
- package/build/index.js.map +1 -1
- package/build/ota-transport/index.d.ts +2 -43
- package/build/ota-transport/index.d.ts.map +1 -1
- package/build/ota-transport/index.js +3 -49
- package/build/ota-transport/index.js.map +1 -1
- package/build/react/useBluetoothStatus.d.ts.map +1 -1
- package/build/react/useBluetoothStatus.js +5 -24
- package/build/react/useBluetoothStatus.js.map +1 -1
- package/build/react/useMentraBluetooth.d.ts +1 -2
- package/build/react/useMentraBluetooth.d.ts.map +1 -1
- package/build/react/useMentraBluetooth.js +0 -1
- package/build/react/useMentraBluetooth.js.map +1 -1
- package/expo-module.config.json +1 -1
- package/ios/MentraBluetoothSDK.podspec +5 -4
- package/ios/MentraLocalNetworkModule.swift +264 -0
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/hotspot/GlassesHotspotNetwork.swift +563 -0
- package/ios/Source/hotspot/HotspotAccessPurpose.swift +5 -0
- package/ios/Source/hotspot/HotspotAddressPolicy.swift +50 -0
- package/ios/Source/hotspot/HotspotInterfacePolicy.swift +155 -0
- package/ios/Source/hotspot/HotspotJoinFailure.swift +27 -0
- package/ios/Source/hotspot/HotspotLeaveCompletion.swift +24 -0
- package/ios/Source/hotspot/HotspotNetworkOwnership.swift +22 -0
- package/ios/Source/hotspot/HotspotReapplyPolicy.swift +26 -0
- package/ios/Source/hotspot/LocalNetworkAccessRequest.swift +160 -0
- package/ios/Source/hotspot/MacHotspotAssociation.swift +415 -0
- package/ios/Source/hotspot/MacHotspotAuthorization.swift +126 -0
- package/ios/Source/hotspot/MacHotspotAuthorizationFacts.swift +51 -0
- package/ios/Source/hotspot/MacHotspotCleanupContinuation.swift +35 -0
- package/ios/Tests/HotspotAddressPolicyTests.swift +30 -0
- package/ios/Tests/HotspotInterfacePolicyTests.swift +304 -0
- package/ios/Tests/HotspotJoinFailureTests.swift +37 -0
- package/ios/Tests/HotspotLeaveCompletionTests.swift +29 -0
- package/ios/Tests/HotspotReapplyPolicyTests.swift +18 -0
- package/ios/Tests/LocalNetworkAccessRequestTests.swift +237 -0
- package/ios/Tests/MacHotspotAssociationTests.swift +521 -0
- package/ios/Tests/MacHotspotAuthorizationFactsTests.swift +62 -0
- package/ios/Tests/MacHotspotAuthorizationTests.swift +348 -0
- package/ios/Tests/MacWifiInvocationTests.swift +76 -0
- package/package.json +7 -2
- package/plugin/build/withIos.d.ts +4 -0
- package/plugin/build/withIos.js +20 -1
- package/src/BluetoothSdk.types.ts +27 -5
- package/src/_internal.ts +1 -0
- package/src/_private/BluetoothSdkModule.ts +20 -10
- package/src/_private/MentraLocalNetworkModule.ts +22 -0
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/glasses-wifi/connection.ts +47 -0
- package/src/glasses-wifi/continuous.ts +177 -0
- package/src/glasses-wifi/files.ts +32 -0
- package/src/glasses-wifi/index.ts +24 -0
- package/src/glasses-wifi/link.ts +94 -0
- package/src/glasses-wifi/native.ts +193 -0
- package/src/glasses-wifi/service.ts +554 -0
- package/src/index.ts +34 -10
- package/src/ota-transport/index.ts +3 -85
- package/src/react/useBluetoothStatus.ts +5 -26
- package/src/react/useMentraBluetooth.ts +0 -3
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
@testable import MentraBluetoothSDK
|
|
3
|
+
import XCTest
|
|
4
|
+
|
|
5
|
+
final class MacHotspotAuthorizationTests: XCTestCase {
|
|
6
|
+
private final class Manager: CLLocationManager {
|
|
7
|
+
var status: CLAuthorizationStatus = .authorizedAlways
|
|
8
|
+
var requests = 0
|
|
9
|
+
override var authorizationStatus: CLAuthorizationStatus {
|
|
10
|
+
XCTAssertTrue(Thread.isMainThread, "CLLocationManager belongs to the main thread")
|
|
11
|
+
return status
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override func requestWhenInUseAuthorization() {
|
|
15
|
+
requests += 1
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private final class Wifi: MacWifiInterface {
|
|
20
|
+
var ssid: String?
|
|
21
|
+
var scans = 0
|
|
22
|
+
var joins = 0
|
|
23
|
+
var leaves = 0
|
|
24
|
+
var onRead: (() -> Void)?
|
|
25
|
+
var onScan: (() -> Void)?
|
|
26
|
+
var onJoin: (() -> Void)?
|
|
27
|
+
func name() throws -> String {
|
|
28
|
+
"en0"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func currentSSID() throws -> String? {
|
|
32
|
+
onRead?(); return ssid
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func network(ssid _: String, channels _: MacHotspotScan) throws -> NSObject? {
|
|
36
|
+
scans += 1; onScan?(); return NSObject()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func associate(network _: NSObject, password _: String) throws {
|
|
40
|
+
joins += 1; onJoin?(); ssid = "glasses"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func disassociate() {
|
|
44
|
+
leaves += 1; ssid = nil
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func forget(ssid _: String) throws {}
|
|
48
|
+
func setPower(_: Bool) throws {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private func started(_ manager: Manager) -> MacHotspotAuthorization {
|
|
52
|
+
let authorization = MacHotspotAuthorization(makeManager: { manager }, locationServicesEnabled: { true })
|
|
53
|
+
let ready = expectation(description: "initialized instance ready")
|
|
54
|
+
authorization.start {
|
|
55
|
+
if case let .failure(error) = $0 { XCTFail("Authorization failed: \(error)") }
|
|
56
|
+
ready.fulfill()
|
|
57
|
+
}
|
|
58
|
+
wait(for: [ready], timeout: 2)
|
|
59
|
+
return authorization
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private func closed(_ authorization: MacHotspotAuthorization) {
|
|
63
|
+
authorization.cancel()
|
|
64
|
+
let closed = expectation(description: "owning thread closed")
|
|
65
|
+
DispatchQueue.main.async { closed.fulfill() }
|
|
66
|
+
wait(for: [closed], timeout: 2)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func testInitializedAlwaysInstanceRemainsAliveAcrossJoinAndCleanup() throws {
|
|
70
|
+
let manager = Manager()
|
|
71
|
+
let authorization = started(manager)
|
|
72
|
+
XCTAssertNotNil(manager.delegate, "Success must not discard the initialized Location recipient")
|
|
73
|
+
let wifi = Wifi()
|
|
74
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
75
|
+
XCTAssertEqual(try association.associate(ssid: "glasses", password: "private"), "en0")
|
|
76
|
+
XCTAssertEqual(wifi.scans, 1)
|
|
77
|
+
XCTAssertEqual(wifi.joins, 1)
|
|
78
|
+
authorization.cancelPending()
|
|
79
|
+
let pendingCancelled = expectation(description: "cancel pending checked")
|
|
80
|
+
DispatchQueue.main.async { pendingCancelled.fulfill() }
|
|
81
|
+
wait(for: [pendingCancelled], timeout: 2)
|
|
82
|
+
try association.leave()
|
|
83
|
+
XCTAssertEqual(wifi.leaves, 1, "A cancelled join still owns its late association cleanup")
|
|
84
|
+
closed(authorization)
|
|
85
|
+
XCTAssertNil(manager.delegate)
|
|
86
|
+
XCTAssertThrowsError(try authorization.requireCurrentAuthorization())
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
func testInstanceReadDoesNotReuseEarlierAlwaysGrant() {
|
|
90
|
+
let manager = Manager()
|
|
91
|
+
let authorization = started(manager)
|
|
92
|
+
let wifi = Wifi()
|
|
93
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
94
|
+
manager.status = .notDetermined
|
|
95
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private")) {
|
|
96
|
+
XCTAssertTrue(HotspotJoinFailure($0).message.contains("raw=0 getter=instance-current"))
|
|
97
|
+
}
|
|
98
|
+
XCTAssertEqual(wifi.scans, 0)
|
|
99
|
+
XCTAssertEqual(wifi.joins, 0)
|
|
100
|
+
closed(authorization)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func testWorkerChecksCurrentRecipientOnOwningThread() {
|
|
104
|
+
let manager = Manager()
|
|
105
|
+
let authorization = started(manager)
|
|
106
|
+
let read = expectation(description: "worker current recipient read")
|
|
107
|
+
DispatchQueue.global().async {
|
|
108
|
+
do { try authorization.requireCurrentAuthorization() }
|
|
109
|
+
catch { XCTFail("Current authorized recipient rejected: \(error)") }
|
|
110
|
+
read.fulfill()
|
|
111
|
+
}
|
|
112
|
+
wait(for: [read], timeout: 2)
|
|
113
|
+
closed(authorization)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func testRecordedStaticNotDeterminedDoesNotReplaceCurrentInitializedAlwaysRecipient() throws {
|
|
117
|
+
let manager = Manager()
|
|
118
|
+
let facts = MacHotspotAuthorizationFacts()
|
|
119
|
+
let authorization = MacHotspotAuthorization(facts: facts, makeManager: { manager }, locationServicesEnabled: { true })
|
|
120
|
+
let ready = expectation(description: "same recipient ready")
|
|
121
|
+
authorization.start {
|
|
122
|
+
if case let .failure(error) = $0 { XCTFail("Authorization failed: \(error)") }
|
|
123
|
+
ready.fulfill()
|
|
124
|
+
}
|
|
125
|
+
wait(for: [ready], timeout: 2)
|
|
126
|
+
let oldStaticError = facts.failure("Location access is required to verify the current Mac Wi-Fi network",
|
|
127
|
+
raw: CLAuthorizationStatus.notDetermined.rawValue, getter: .staticSSID, foreground: .unknown)
|
|
128
|
+
XCTAssertTrue(oldStaticError.message.contains("raw=0 getter=static-ssid"))
|
|
129
|
+
XCTAssertTrue(oldStaticError.message.contains("instanceRaw=3 instanceGetter=instance-initial"))
|
|
130
|
+
let wifi = Wifi()
|
|
131
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
132
|
+
XCTAssertEqual(try association.associate(ssid: "glasses", password: "private"), "en0")
|
|
133
|
+
try association.leave()
|
|
134
|
+
closed(authorization)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
func testRevocationDuringScanPreventsAssociation() {
|
|
138
|
+
let manager = Manager()
|
|
139
|
+
let authorization = started(manager)
|
|
140
|
+
let wifi = Wifi()
|
|
141
|
+
wifi.onScan = { manager.status = .denied }
|
|
142
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
143
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private"))
|
|
144
|
+
XCTAssertEqual(wifi.scans, 1)
|
|
145
|
+
XCTAssertEqual(wifi.joins, 0)
|
|
146
|
+
closed(authorization)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
func testDisabledLocationServicesRejectsAlwaysGrantBeforeSSIDRead() {
|
|
150
|
+
let manager = Manager()
|
|
151
|
+
let authorization = MacHotspotAuthorization(makeManager: { manager }, locationServicesEnabled: { false })
|
|
152
|
+
let ready = expectation(description: "initial recipient status")
|
|
153
|
+
authorization.start { _ in ready.fulfill() }
|
|
154
|
+
wait(for: [ready], timeout: 2)
|
|
155
|
+
let wifi = Wifi()
|
|
156
|
+
var reads = 0
|
|
157
|
+
wifi.onRead = { reads += 1 }
|
|
158
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
159
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private")) {
|
|
160
|
+
XCTAssertTrue(HotspotJoinFailure($0).message.contains("Location services are required"))
|
|
161
|
+
}
|
|
162
|
+
XCTAssertEqual(reads, 0)
|
|
163
|
+
XCTAssertEqual(wifi.scans, 0)
|
|
164
|
+
XCTAssertEqual(wifi.joins, 0)
|
|
165
|
+
closed(authorization)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func testPermissionLossAfterSSIDReadPreventsScan() {
|
|
169
|
+
let manager = Manager()
|
|
170
|
+
let authorization = started(manager)
|
|
171
|
+
let wifi = Wifi()
|
|
172
|
+
wifi.onRead = { manager.status = .restricted }
|
|
173
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
174
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private"))
|
|
175
|
+
XCTAssertEqual(wifi.scans, 0)
|
|
176
|
+
XCTAssertEqual(wifi.joins, 0)
|
|
177
|
+
closed(authorization)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
func testActualCallbackRevocationNotifiesSessionOnce() {
|
|
181
|
+
let manager = Manager()
|
|
182
|
+
let authorization = started(manager)
|
|
183
|
+
var revocations = 0
|
|
184
|
+
authorization.onRevoked = { error in
|
|
185
|
+
XCTAssertTrue(HotspotJoinFailure(error).message.contains("getter=instance-callback"))
|
|
186
|
+
revocations += 1
|
|
187
|
+
}
|
|
188
|
+
manager.status = .denied
|
|
189
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
190
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
191
|
+
XCTAssertEqual(revocations, 1)
|
|
192
|
+
XCTAssertThrowsError(try authorization.requireCurrentAuthorization())
|
|
193
|
+
closed(authorization)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
func testRevocationAfterLateAssociationRetainsOwnedCleanupUntilPermissionReturns() throws {
|
|
197
|
+
let manager = Manager()
|
|
198
|
+
let authorization = started(manager)
|
|
199
|
+
let wifi = Wifi()
|
|
200
|
+
wifi.onJoin = { manager.status = .denied }
|
|
201
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
202
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private"))
|
|
203
|
+
XCTAssertEqual(wifi.joins, 1)
|
|
204
|
+
XCTAssertThrowsError(try association.leave())
|
|
205
|
+
XCTAssertEqual(wifi.leaves, 0, "Unknown membership must not disconnect a replacement network")
|
|
206
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
207
|
+
var cleanupReturns = 0
|
|
208
|
+
authorization.onRestored = {
|
|
209
|
+
do { try association.leave(); cleanupReturns += 1 }
|
|
210
|
+
catch { XCTFail("Restored permission did not settle retained cleanup: \(error)") }
|
|
211
|
+
}
|
|
212
|
+
manager.status = .authorizedAlways
|
|
213
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
214
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
215
|
+
XCTAssertEqual(cleanupReturns, 1)
|
|
216
|
+
XCTAssertEqual(wifi.leaves, 1)
|
|
217
|
+
XCTAssertEqual(wifi.joins, 1, "Reauthorization must not repeat association")
|
|
218
|
+
closed(authorization)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
func testOwnerRestorationBeforeFailedWorkerResultContinuesOnlyRetainedCleanup() throws {
|
|
222
|
+
let manager = Manager()
|
|
223
|
+
let authorization = started(manager)
|
|
224
|
+
let wifi = Wifi()
|
|
225
|
+
wifi.onJoin = { manager.status = .denied }
|
|
226
|
+
let association = MacHotspotAssociation(makeInterface: { wifi }, authorization: authorization)
|
|
227
|
+
XCTAssertThrowsError(try association.associate(ssid: "glasses", password: "private"))
|
|
228
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
229
|
+
|
|
230
|
+
var generation = 17
|
|
231
|
+
var finishingLeave = false
|
|
232
|
+
var attempts = 0
|
|
233
|
+
var workerResult: Result<Void, Error>?
|
|
234
|
+
var continuation: MacHotspotCleanupContinuation!
|
|
235
|
+
continuation = MacHotspotCleanupContinuation(authorization: authorization, queue: .main,
|
|
236
|
+
isCurrentCancelledSession: { generation == 17 }, requestCleanup: {
|
|
237
|
+
guard !finishingLeave else { return }
|
|
238
|
+
finishingLeave = true
|
|
239
|
+
continuation.cleanupStarted()
|
|
240
|
+
attempts += 1
|
|
241
|
+
workerResult = Result { try association.leave() }
|
|
242
|
+
})
|
|
243
|
+
// The worker has failed, but its result has not reached the owner yet.
|
|
244
|
+
finishingLeave = true
|
|
245
|
+
continuation.cleanupStarted()
|
|
246
|
+
attempts = 1
|
|
247
|
+
let firstWorkerResult = Result { try association.leave() }
|
|
248
|
+
XCTAssertThrowsError(try firstWorkerResult.get())
|
|
249
|
+
manager.status = .authorizedAlways
|
|
250
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
251
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
252
|
+
let restorationQueued = expectation(description: "actual owner restoration callback delivered")
|
|
253
|
+
DispatchQueue.main.async { restorationQueued.fulfill() }
|
|
254
|
+
wait(for: [restorationQueued], timeout: 2)
|
|
255
|
+
XCTAssertEqual(attempts, 1, "Restoration cannot overtake the in-flight cleanup")
|
|
256
|
+
|
|
257
|
+
// Now the owner receives the old denied result. The pending restoration
|
|
258
|
+
// must start one serialized, freshly authorized cleanup, never a rejoin.
|
|
259
|
+
finishingLeave = false
|
|
260
|
+
continuation.cleanupFailed()
|
|
261
|
+
try XCTUnwrap(workerResult).get()
|
|
262
|
+
XCTAssertEqual(attempts, 2)
|
|
263
|
+
XCTAssertEqual(wifi.leaves, 1)
|
|
264
|
+
XCTAssertEqual(wifi.joins, 1)
|
|
265
|
+
generation += 1
|
|
266
|
+
continuation.cleanupFailed()
|
|
267
|
+
XCTAssertEqual(attempts, 2)
|
|
268
|
+
closed(authorization)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
func testOwnerRestorationRetainsNoAutomaticLoopOrStaleGeneration() {
|
|
272
|
+
let manager = Manager()
|
|
273
|
+
let authorization = started(manager)
|
|
274
|
+
var current = true
|
|
275
|
+
var requests = 0
|
|
276
|
+
let continuation = MacHotspotCleanupContinuation(authorization: authorization, queue: .main,
|
|
277
|
+
isCurrentCancelledSession: { current }, requestCleanup: { requests += 1 })
|
|
278
|
+
manager.status = .denied
|
|
279
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
280
|
+
manager.status = .authorizedAlways
|
|
281
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
282
|
+
let delivered = expectation(description: "first restoration")
|
|
283
|
+
DispatchQueue.main.async { delivered.fulfill() }
|
|
284
|
+
wait(for: [delivered], timeout: 2)
|
|
285
|
+
XCTAssertEqual(requests, 1)
|
|
286
|
+
continuation.cleanupStarted()
|
|
287
|
+
continuation.cleanupFailed()
|
|
288
|
+
XCTAssertEqual(requests, 1, "Without a newer restoration, failed cleanup retains custody")
|
|
289
|
+
|
|
290
|
+
manager.status = .denied
|
|
291
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
292
|
+
manager.status = .authorizedAlways
|
|
293
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
294
|
+
current = false // Closed generation before the queued callback executes.
|
|
295
|
+
let stale = expectation(description: "stale restoration")
|
|
296
|
+
DispatchQueue.main.async { stale.fulfill() }
|
|
297
|
+
wait(for: [stale], timeout: 2)
|
|
298
|
+
continuation.cleanupFailed()
|
|
299
|
+
XCTAssertEqual(requests, 1)
|
|
300
|
+
closed(authorization)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
func testCancelWhileInitialCallbackIsHeldSettlesOnceAndIgnoresLateGrant() {
|
|
304
|
+
let manager = Manager(); manager.status = .notDetermined
|
|
305
|
+
let authorization = MacHotspotAuthorization(makeManager: { manager }, locationServicesEnabled: { true })
|
|
306
|
+
let installed = expectation(description: "initial pending read")
|
|
307
|
+
let cancelled = expectation(description: "cancelled reply")
|
|
308
|
+
var replies = 0
|
|
309
|
+
authorization.start {
|
|
310
|
+
replies += 1
|
|
311
|
+
if case let .failure(error) = $0 { XCTAssertTrue(error is CancellationError) }
|
|
312
|
+
else { XCTFail("Cancelled pending authorization succeeded") }
|
|
313
|
+
cancelled.fulfill()
|
|
314
|
+
}
|
|
315
|
+
DispatchQueue.main.async { installed.fulfill() }
|
|
316
|
+
wait(for: [installed], timeout: 2)
|
|
317
|
+
XCTAssertEqual(manager.requests, 1)
|
|
318
|
+
authorization.cancelPending()
|
|
319
|
+
wait(for: [cancelled], timeout: 2)
|
|
320
|
+
manager.status = .authorizedAlways
|
|
321
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
322
|
+
XCTAssertEqual(replies, 1)
|
|
323
|
+
XCTAssertNil(manager.delegate)
|
|
324
|
+
XCTAssertThrowsError(try authorization.requireCurrentAuthorization())
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
func testPendingCallbackGrantKeepsRecipientAndRecordsActualCallback() throws {
|
|
328
|
+
let manager = Manager(); manager.status = .notDetermined
|
|
329
|
+
let facts = MacHotspotAuthorizationFacts()
|
|
330
|
+
let authorization = MacHotspotAuthorization(facts: facts, makeManager: { manager }, locationServicesEnabled: { true })
|
|
331
|
+
let ready = expectation(description: "callback grant")
|
|
332
|
+
authorization.start {
|
|
333
|
+
if case let .failure(error) = $0 { XCTFail("Callback grant failed: \(error)") }
|
|
334
|
+
ready.fulfill()
|
|
335
|
+
}
|
|
336
|
+
DispatchQueue.main.async {
|
|
337
|
+
manager.status = .authorizedAlways
|
|
338
|
+
authorization.locationManagerDidChangeAuthorization(manager)
|
|
339
|
+
}
|
|
340
|
+
wait(for: [ready], timeout: 2)
|
|
341
|
+
XCTAssertNotNil(manager.delegate)
|
|
342
|
+
manager.status = .denied
|
|
343
|
+
XCTAssertThrowsError(try authorization.requireCurrentAuthorization()) {
|
|
344
|
+
XCTAssertTrue(HotspotJoinFailure($0).message.contains("initialCallbackObserved=true"))
|
|
345
|
+
}
|
|
346
|
+
closed(authorization)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import ObjectiveC
|
|
3
|
+
import XCTest
|
|
4
|
+
|
|
5
|
+
final class MacWifiInvocationTests: XCTestCase {
|
|
6
|
+
private final class Wifi: NSObject {
|
|
7
|
+
var succeeds = false
|
|
8
|
+
let network = NSObject()
|
|
9
|
+
|
|
10
|
+
/// Swift's Objective-C thunk uses the same autoreleasing NSError** ABI
|
|
11
|
+
/// as CoreWLAN. No network framework or device is loaded by this fixture.
|
|
12
|
+
@objc(scanForNetworksWithChannels:ssid:bssid:error:)
|
|
13
|
+
dynamic func scan(_: NSSet, ssid _: NSData, bssid _: NSString?, error: NSErrorPointer) -> NSSet? {
|
|
14
|
+
if succeeds { return NSSet(object: network) }
|
|
15
|
+
error?.pointee = NSError(domain: "MacWifiInvocationFixture", code: 7, userInfo: nil)
|
|
16
|
+
return nil
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@objc(associateToNetwork:password:error:)
|
|
20
|
+
dynamic func associate(_: NSObject, password _: NSString, error: NSErrorPointer) -> Bool {
|
|
21
|
+
if succeeds { return true }
|
|
22
|
+
error?.pointee = NSError(domain: "MacWifiInvocationFixture", code: 8, userInfo: nil)
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func testScanErrorWritebackSurvivesRepeatedAutoreleasePools() {
|
|
28
|
+
let wifi = Wifi(), selector = NSSelectorFromString("scanForNetworksWithChannels:ssid:bssid:error:")
|
|
29
|
+
let invoke = unsafeBitCast(wifi.method(for: selector), to: MacWifiInvocation.Scan.self)
|
|
30
|
+
for _ in 0 ..< 100 {
|
|
31
|
+
var retainedError: NSError?
|
|
32
|
+
autoreleasepool {
|
|
33
|
+
var error: NSError?
|
|
34
|
+
XCTAssertNil(invoke(wifi, selector, NSSet(), NSData(data: Data("fixture".utf8)), nil, &error))
|
|
35
|
+
retainedError = error
|
|
36
|
+
}
|
|
37
|
+
XCTAssertEqual(retainedError?.domain, "MacWifiInvocationFixture")
|
|
38
|
+
XCTAssertEqual(retainedError?.code, 7)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func testAssociationErrorWritebackSurvivesRepeatedAutoreleasePools() {
|
|
43
|
+
let wifi = Wifi(), selector = NSSelectorFromString("associateToNetwork:password:error:")
|
|
44
|
+
let invoke = unsafeBitCast(wifi.method(for: selector), to: MacWifiInvocation.Associate.self)
|
|
45
|
+
for _ in 0 ..< 100 {
|
|
46
|
+
var retainedError: NSError?
|
|
47
|
+
autoreleasepool {
|
|
48
|
+
var error: NSError?
|
|
49
|
+
XCTAssertFalse(invoke(wifi, selector, wifi.network, "fixture" as NSString, &error))
|
|
50
|
+
retainedError = error
|
|
51
|
+
}
|
|
52
|
+
XCTAssertEqual(retainedError?.domain, "MacWifiInvocationFixture")
|
|
53
|
+
XCTAssertEqual(retainedError?.code, 8)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func testSuccessfulCallsPreserveObjectAndBooleanReturnsWithoutAnError() {
|
|
58
|
+
let wifi = Wifi(); wifi.succeeds = true
|
|
59
|
+
let scanSelector = NSSelectorFromString("scanForNetworksWithChannels:ssid:bssid:error:")
|
|
60
|
+
let associateSelector = NSSelectorFromString("associateToNetwork:password:error:")
|
|
61
|
+
let scan = unsafeBitCast(wifi.method(for: scanSelector), to: MacWifiInvocation.Scan.self)
|
|
62
|
+
let associate = unsafeBitCast(wifi.method(for: associateSelector), to: MacWifiInvocation.Associate.self)
|
|
63
|
+
for _ in 0 ..< 100 {
|
|
64
|
+
var retainedNetworks: NSSet?
|
|
65
|
+
autoreleasepool {
|
|
66
|
+
var error: NSError?
|
|
67
|
+
retainedNetworks = scan(wifi, scanSelector, NSSet(), NSData(data: Data("fixture".utf8)), nil, &error)?.takeUnretainedValue()
|
|
68
|
+
XCTAssertNil(error)
|
|
69
|
+
XCTAssertTrue(associate(wifi, associateSelector, wifi.network, "fixture" as NSString, &error))
|
|
70
|
+
XCTAssertNil(error)
|
|
71
|
+
}
|
|
72
|
+
XCTAssertEqual(retainedNetworks?.count, 1)
|
|
73
|
+
XCTAssertTrue(retainedNetworks?.anyObject() as? NSObject === wifi.network)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/bluetooth-sdk",
|
|
3
|
-
"version": "3.5.0-dev.
|
|
3
|
+
"version": "3.5.0-dev.1519",
|
|
4
4
|
"description": "SDK for communicating with smart glasses",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"types": "./build/ota-transport/index.d.ts",
|
|
38
38
|
"default": "./build/ota-transport/index.js"
|
|
39
39
|
},
|
|
40
|
+
"./glasses-wifi": {
|
|
41
|
+
"react-native": "./src/glasses-wifi/index.ts",
|
|
42
|
+
"types": "./build/glasses-wifi/index.d.ts",
|
|
43
|
+
"default": "./build/glasses-wifi/index.js"
|
|
44
|
+
},
|
|
40
45
|
"./debug": {
|
|
41
46
|
"react-native": "./src/debug.ts",
|
|
42
47
|
"types": "./build/debug.d.ts",
|
|
@@ -115,7 +120,7 @@
|
|
|
115
120
|
"registry": "https://registry.npmjs.org/"
|
|
116
121
|
},
|
|
117
122
|
"dependencies": {
|
|
118
|
-
"@mentra/cloud-protocol": "3.5.0-dev.
|
|
123
|
+
"@mentra/cloud-protocol": "3.5.0-dev.1519"
|
|
119
124
|
},
|
|
120
125
|
"devDependencies": {
|
|
121
126
|
"@types/node": "^25.9.3",
|
|
@@ -4,5 +4,9 @@ export declare const INFO_ANALYTICS_ENVIRONMENT = "MentraBluetoothSdkAnalyticsEn
|
|
|
4
4
|
export declare const INFO_SDK_VERSION = "MentraBluetoothSdkVersion";
|
|
5
5
|
/** Lets iOS complete the SDK's pending reconnect, and deliver BLE events, while the app is suspended. */
|
|
6
6
|
export declare const IOS_BLUETOOTH_BACKGROUND_MODE = "bluetooth-central";
|
|
7
|
+
/** The fast link joins the glasses' hotspot and verifies the phone's address on it. */
|
|
8
|
+
export declare const IOS_FAST_LINK_ENTITLEMENTS: readonly ["com.apple.developer.networking.HotspotConfiguration", "com.apple.developer.networking.wifi-info"];
|
|
7
9
|
export declare function applyBluetoothSdkInfoPlist(infoPlist: IOSConfig.InfoPlist, props: BluetoothSdkPluginProps | undefined): IOSConfig.InfoPlist;
|
|
10
|
+
/** The entitlements the fast link needs, beside whatever else the app declares. */
|
|
11
|
+
export declare function applyBluetoothSdkEntitlements<T extends Record<string, unknown>>(entitlements: T): T;
|
|
8
12
|
export declare const withIosConfiguration: ConfigPlugin<BluetoothSdkPluginProps>;
|
package/plugin/build/withIos.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withIosConfiguration = exports.IOS_BLUETOOTH_BACKGROUND_MODE = exports.INFO_SDK_VERSION = exports.INFO_ANALYTICS_ENVIRONMENT = void 0;
|
|
6
|
+
exports.withIosConfiguration = exports.IOS_FAST_LINK_ENTITLEMENTS = exports.IOS_BLUETOOTH_BACKGROUND_MODE = exports.INFO_SDK_VERSION = exports.INFO_ANALYTICS_ENVIRONMENT = void 0;
|
|
7
7
|
exports.applyBluetoothSdkInfoPlist = applyBluetoothSdkInfoPlist;
|
|
8
|
+
exports.applyBluetoothSdkEntitlements = applyBluetoothSdkEntitlements;
|
|
8
9
|
const child_process_1 = require("child_process");
|
|
9
10
|
const fs_1 = __importDefault(require("fs"));
|
|
10
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -19,6 +20,12 @@ const STALE_INFO_POSTHOG_API_KEY = "MentraBluetoothSdkPostHogApiKey";
|
|
|
19
20
|
const STALE_INFO_POSTHOG_HOST = "MentraBluetoothSdkPostHogHost";
|
|
20
21
|
/** Lets iOS complete the SDK's pending reconnect, and deliver BLE events, while the app is suspended. */
|
|
21
22
|
exports.IOS_BLUETOOTH_BACKGROUND_MODE = "bluetooth-central";
|
|
23
|
+
/** The fast link joins the glasses' hotspot and verifies the phone's address on it. */
|
|
24
|
+
exports.IOS_FAST_LINK_ENTITLEMENTS = [
|
|
25
|
+
"com.apple.developer.networking.HotspotConfiguration",
|
|
26
|
+
"com.apple.developer.networking.wifi-info",
|
|
27
|
+
];
|
|
28
|
+
const LOCAL_NETWORK_DESCRIPTION = "Photos come from your glasses over their Wi-Fi.";
|
|
22
29
|
const ensureBluetoothSdkExpoAdapterPodEnv = (podfile) => {
|
|
23
30
|
if (podfile.includes(BLUETOOTH_SDK_EXPO_ADAPTER_ENV)) {
|
|
24
31
|
return podfile;
|
|
@@ -72,6 +79,8 @@ function applyBluetoothSdkInfoPlist(infoPlist, props) {
|
|
|
72
79
|
delete infoPlist[STALE_INFO_POSTHOG_API_KEY];
|
|
73
80
|
delete infoPlist[STALE_INFO_POSTHOG_HOST];
|
|
74
81
|
infoPlist[exports.INFO_SDK_VERSION] = sdkVersion;
|
|
82
|
+
// The fast link reaches the glasses on the local network; an app's own wording wins.
|
|
83
|
+
infoPlist.NSLocalNetworkUsageDescription ??= LOCAL_NETWORK_DESCRIPTION;
|
|
75
84
|
// Merge, never replace: apps may also declare audio, location or other modes.
|
|
76
85
|
const declaredModes = infoPlist.UIBackgroundModes;
|
|
77
86
|
if (declaredModes !== undefined && !Array.isArray(declaredModes)) {
|
|
@@ -95,12 +104,22 @@ function withBluetoothSdkInfoPlist(config, props) {
|
|
|
95
104
|
return config;
|
|
96
105
|
});
|
|
97
106
|
}
|
|
107
|
+
/** The entitlements the fast link needs, beside whatever else the app declares. */
|
|
108
|
+
function applyBluetoothSdkEntitlements(entitlements) {
|
|
109
|
+
for (const key of exports.IOS_FAST_LINK_ENTITLEMENTS)
|
|
110
|
+
entitlements[key] = true;
|
|
111
|
+
return entitlements;
|
|
112
|
+
}
|
|
98
113
|
const withIosConfiguration = (config, props) => {
|
|
99
114
|
config = (0, config_plugins_1.withPodfile)(config, (config) => {
|
|
100
115
|
config.modResults.contents = ensureBluetoothSdkExpoAdapterPodEnv(config.modResults.contents);
|
|
101
116
|
return config;
|
|
102
117
|
});
|
|
103
118
|
config = withBluetoothSdkInfoPlist(config, props);
|
|
119
|
+
config = (0, config_plugins_1.withEntitlementsPlist)(config, (config) => {
|
|
120
|
+
config.modResults = applyBluetoothSdkEntitlements(config.modResults);
|
|
121
|
+
return config;
|
|
122
|
+
});
|
|
104
123
|
if (props?.node) {
|
|
105
124
|
config = withXcodeEnvLocal(config);
|
|
106
125
|
}
|
|
@@ -855,7 +855,9 @@ export interface PhotoCapture {
|
|
|
855
855
|
readonly preview: Promise<PhotoPreview>
|
|
856
856
|
/**
|
|
857
857
|
* The full photo. The first call asks the glasses to send it; until then it waits on the
|
|
858
|
-
* glasses (deferred delivery), for 30 minutes at most.
|
|
858
|
+
* glasses (deferred delivery), for 30 minutes at most. It comes over the glasses Wi-Fi link
|
|
859
|
+
* when that link is up (`link.openFast()`), else over Bluetooth.
|
|
860
|
+
* Later calls return the same photo.
|
|
859
861
|
*/
|
|
860
862
|
photo(): Promise<PhotoTaken>
|
|
861
863
|
/** The full photo isn't needed: the glasses delete it. Stages not reached yet reject. */
|
|
@@ -1478,11 +1480,18 @@ export interface NativePhoneNotification {
|
|
|
1478
1480
|
action: 0
|
|
1479
1481
|
}
|
|
1480
1482
|
|
|
1483
|
+
/** The glasses Wi-Fi link is the SDK's own (`link.openFast`): apps don't see its hotspot. */
|
|
1481
1484
|
export type PublicGlassesStatus = Omit<
|
|
1482
1485
|
GlassesStatus,
|
|
1483
|
-
"otaUpdateAvailable" | "otaProgress" | "otaInProgress" | "otaVersionUrl"
|
|
1486
|
+
"otaUpdateAvailable" | "otaProgress" | "otaInProgress" | "otaVersionUrl" | "hotspot"
|
|
1484
1487
|
>
|
|
1485
1488
|
|
|
1489
|
+
/** A glasses status as apps see it: without the glasses Wi-Fi link's hotspot credentials. */
|
|
1490
|
+
export function publicGlassesStatus<T extends Partial<GlassesStatus>>(status: T): Omit<T, "hotspot"> {
|
|
1491
|
+
const {hotspot: _hotspot, ...rest} = status
|
|
1492
|
+
return rest
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1486
1495
|
export type PublicBluetoothStatus = Pick<
|
|
1487
1496
|
BluetoothStatus,
|
|
1488
1497
|
| "searching"
|
|
@@ -1518,8 +1527,6 @@ export type BluetoothSdkEventMap = {
|
|
|
1518
1527
|
wifi_scan_result: WifiScanResultEvent
|
|
1519
1528
|
wifi_forget_result: WifiForgetResultEvent
|
|
1520
1529
|
saved_wifi_networks: SavedWifiNetworksEvent
|
|
1521
|
-
hotspot_status_change: HotspotStatusChangeEvent
|
|
1522
|
-
hotspot_error: HotspotErrorEvent
|
|
1523
1530
|
photo_response: PhotoResponseEvent
|
|
1524
1531
|
photo_status: PhotoStatusEvent
|
|
1525
1532
|
camera_status: CameraStatusEvent
|
|
@@ -1627,7 +1634,6 @@ export interface BluetoothSdkPublicModule {
|
|
|
1627
1634
|
sendWifiCredentials(ssid: string, password: string): Promise<WifiStatusChangeEvent>
|
|
1628
1635
|
/** Forget a saved network and return its correlated semantic outcome. */
|
|
1629
1636
|
forgetWifiNetwork(ssid: string): Promise<WifiForgetResult>
|
|
1630
|
-
setHotspotState(enabled: boolean): Promise<HotspotStatusChangeEvent>
|
|
1631
1637
|
/** Set the glasses clock from the phone after an OTA clock-skew failure. */
|
|
1632
1638
|
setSystemTime(timestampMs: number): Promise<void>
|
|
1633
1639
|
/** Enable or disable Wi-Fi ADB on Mentra Live (no-op on other devices). */
|
|
@@ -1684,6 +1690,22 @@ export interface BluetoothSdkPublicModule {
|
|
|
1684
1690
|
capturePhoto(params: PhotoCaptureParams): PhotoCapture
|
|
1685
1691
|
/** A photo kept on the phone, whole: `capturePhoto(params).photo()`, then its release. */
|
|
1686
1692
|
takePhoto(params: PhotoCaptureParams): Promise<PhotoTaken>
|
|
1693
|
+
/**
|
|
1694
|
+
* The phone's links to the glasses: `state` says whether the glasses are connected and the fast
|
|
1695
|
+
* link (the glasses Wi-Fi) is up, `onChange` hears them change, and `openFast` / `closeFast`
|
|
1696
|
+
* hold and give back the fast link, which photos travel over while it is up.
|
|
1697
|
+
*/
|
|
1698
|
+
readonly link: import("./glasses-wifi/link").GlassesLink
|
|
1699
|
+
/**
|
|
1700
|
+
* Photos back to back, for a run that takes many (documenting a site, a walk-through): see
|
|
1701
|
+
* {@link import("./glasses-wifi/continuous").ContinuousCapture}. Each photo is a capture like
|
|
1702
|
+
* `capturePhoto`'s. While the run is on, the SDK holds the fast link for it, so full photos come
|
|
1703
|
+
* over Wi-Fi; the run is `paused` while only Bluetooth is left, and `stop()` gives the link back.
|
|
1704
|
+
* `maxPending` (default 12) is how many of its photos may stay on the glasses unreleased.
|
|
1705
|
+
*/
|
|
1706
|
+
captureContinuous(
|
|
1707
|
+
options: PhotoCaptureParams & {maxPending?: number},
|
|
1708
|
+
): import("./glasses-wifi/continuous").ContinuousCapture<PhotoCapture>
|
|
1687
1709
|
warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>
|
|
1688
1710
|
/** Release one request-owned warm-up. Opening requests reject with camera_warm_up_cancelled. */
|
|
1689
1711
|
stopCameraWarmUp(requestId: string): Promise<void>
|
package/src/_internal.ts
CHANGED
|
@@ -14,3 +14,4 @@ export * from "./_private/MentraLocalNetworkModule"
|
|
|
14
14
|
export {default as MentraOtaServer} from "./ota-server"
|
|
15
15
|
export * from "./ota-server/MentraOtaServer.types"
|
|
16
16
|
export {BLUETOOTH_SDK_VERSION, sdkPinnedOtaManifestUrl} from "./_private/sdkOtaManifest"
|
|
17
|
+
export * from "./glasses-wifi"
|
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
WifiSearchResult,
|
|
66
66
|
WifiStatusChangeEvent,
|
|
67
67
|
} from "../BluetoothSdk.types"
|
|
68
|
+
import {fetchGlassesFileOverWifi} from "../glasses-wifi/files"
|
|
68
69
|
import {warmUpCameraParamsForNative} from "./cameraRequestPayload"
|
|
69
70
|
import {photoCaptureParamsForNative, photoUploadParamsForNative} from "./photoRequestPayload"
|
|
70
71
|
import {streamRequestParamsForNative} from "./streamRequestPayload"
|
|
@@ -798,6 +799,24 @@ NativeBluetoothSdkModule.capturePhoto = function (params: PhotoCaptureParams): P
|
|
|
798
799
|
const started = quiet(nativeCapturePhoto({...photoCaptureParamsForNative(params), requestId}))
|
|
799
800
|
const stage = (name: "captured" | "preview" | "photo") =>
|
|
800
801
|
quiet(started.then(() => nativePhotoCaptureStage(requestId, name)))
|
|
802
|
+
const overBluetooth = () =>
|
|
803
|
+
stage("photo").then((value): PhotoTaken => {
|
|
804
|
+
const response = value as PhotoSuccessResponseEvent
|
|
805
|
+
return {
|
|
806
|
+
requestId,
|
|
807
|
+
fileUri: response.photoUrl ?? "",
|
|
808
|
+
mimeType: response.contentType || "image/jpeg",
|
|
809
|
+
size: response.fileSizeBytes ?? -1,
|
|
810
|
+
}
|
|
811
|
+
})
|
|
812
|
+
// Glasses that keep the full photo serve it by ID, over the glasses Wi-Fi link when it is up.
|
|
813
|
+
const fetchPhoto = async (): Promise<PhotoTaken> => {
|
|
814
|
+
const status = await NativeBluetoothSdkModule.getGlassesStatus().catch(() => null)
|
|
815
|
+
if ((status?.deferredPhotosVersion ?? 0) <= 0) return overBluetooth()
|
|
816
|
+
await stage("captured")
|
|
817
|
+
const overWifi = await fetchGlassesFileOverWifi(requestId)
|
|
818
|
+
return overWifi ? {requestId, fileUri: overWifi.uri, mimeType: "image/jpeg", size: overWifi.bytes} : overBluetooth()
|
|
819
|
+
}
|
|
801
820
|
// Each stage is asked for when first awaited, once.
|
|
802
821
|
let captured: Promise<void> | undefined
|
|
803
822
|
let preview: Promise<PhotoPreview> | undefined
|
|
@@ -810,16 +829,7 @@ NativeBluetoothSdkModule.capturePhoto = function (params: PhotoCaptureParams): P
|
|
|
810
829
|
get preview() {
|
|
811
830
|
return (preview ??= stage("preview") as Promise<PhotoPreview>)
|
|
812
831
|
},
|
|
813
|
-
photo: () =>
|
|
814
|
-
(photo ??= stage("photo").then((value) => {
|
|
815
|
-
const response = value as PhotoSuccessResponseEvent
|
|
816
|
-
return {
|
|
817
|
-
requestId,
|
|
818
|
-
fileUri: response.photoUrl ?? "",
|
|
819
|
-
mimeType: response.contentType || "image/jpeg",
|
|
820
|
-
size: response.fileSizeBytes ?? -1,
|
|
821
|
-
}
|
|
822
|
-
})),
|
|
832
|
+
photo: () => (photo ??= fetchPhoto()),
|
|
823
833
|
release: () => started.then(() => nativeReleasePhotoCapture(requestId)),
|
|
824
834
|
}
|
|
825
835
|
}
|