@mentra/bluetooth-sdk 3.2.0-dev.180 → 3.2.0-dev.181

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 (48) hide show
  1. package/README.md +7 -0
  2. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +6 -0
  3. package/android/src/main/java/com/mentra/bluetoothsdk/ConnectedDeviceMatcher.kt +69 -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 +57 -1
  6. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +38 -1
  7. package/android/src/test/java/com/mentra/bluetoothsdk/ConnectedDeviceMatcherTest.kt +161 -0
  8. package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +87 -0
  9. package/build/BluetoothSdk.types.d.ts +7 -0
  10. package/build/BluetoothSdk.types.d.ts.map +1 -1
  11. package/build/BluetoothSdk.types.js.map +1 -1
  12. package/build/_private/BluetoothSdkModule.d.ts +2 -1
  13. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  14. package/build/_private/BluetoothSdkModule.js +28 -49
  15. package/build/_private/BluetoothSdkModule.js.map +1 -1
  16. package/build/_private/scanSession.d.ts +21 -0
  17. package/build/_private/scanSession.d.ts.map +1 -0
  18. package/build/_private/scanSession.js +75 -0
  19. package/build/_private/scanSession.js.map +1 -0
  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.map +1 -1
  25. package/build/react/useBluetoothScan.d.ts +2 -1
  26. package/build/react/useBluetoothScan.d.ts.map +1 -1
  27. package/build/react/useBluetoothScan.js +13 -0
  28. package/build/react/useBluetoothScan.js.map +1 -1
  29. package/build/react/useMentraBluetooth.d.ts +2 -1
  30. package/build/react/useMentraBluetooth.d.ts.map +1 -1
  31. package/build/react/useMentraBluetooth.js +1 -0
  32. package/build/react/useMentraBluetooth.js.map +1 -1
  33. package/ios/BluetoothSdkModule.swift +7 -0
  34. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  35. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  36. package/ios/Source/MentraBluetoothSDK.swift +43 -2
  37. package/ios/Source/connection/ScanSession.swift +11 -0
  38. package/ios/Source/internal/BluetoothAvailability.swift +7 -0
  39. package/ios/Source/internal/ConnectedDeviceMatcher.swift +45 -0
  40. package/ios/Tests/ConnectedDeviceMatcherTests.swift +27 -0
  41. package/package.json +1 -1
  42. package/src/BluetoothSdk.types.ts +8 -0
  43. package/src/_private/BluetoothSdkModule.ts +39 -57
  44. package/src/_private/scanSession.ts +88 -0
  45. package/src/generated/releaseMetadata.ts +5 -5
  46. package/src/index.ts +1 -0
  47. package/src/react/useBluetoothScan.ts +12 -1
  48. package/src/react/useMentraBluetooth.ts +2 -0
@@ -1,7 +1,7 @@
1
1
  import {useEffect, useRef, useState} from "react"
2
2
 
3
3
  import BluetoothSdk, {DeviceModels} from "../index"
4
- import type {Device, DeviceModel} from "../BluetoothSdk.types"
4
+ import type {Device, DeviceModel, ScanDiagnostic} from "../BluetoothSdk.types"
5
5
 
6
6
  export type BluetoothScanDedupe = "id" | "name" | ((device: Device) => string)
7
7
 
@@ -15,6 +15,7 @@ export type UseBluetoothScanOptions = {
15
15
  export type BluetoothScanHookResult = {
16
16
  clearResults: () => void
17
17
  devices: Device[]
18
+ diagnostic: ScanDiagnostic | null
18
19
  error: unknown | null
19
20
  model: DeviceModel
20
21
  scanning: boolean
@@ -61,6 +62,7 @@ function hasDevice(devices: Device[], selectedDevice: Device | null, dedupe: Blu
61
62
 
62
63
  export function useBluetoothScan(options: UseBluetoothScanOptions = {}): BluetoothScanHookResult {
63
64
  const [devices, setDevices] = useState<Device[]>([])
65
+ const [diagnostic, setDiagnostic] = useState<ScanDiagnostic | null>(null)
64
66
  const [error, setError] = useState<unknown | null>(null)
65
67
  const [model, setModelState] = useState<DeviceModel>(options.model ?? DeviceModels.MentraLive)
66
68
  const [scanning, setScanning] = useState(false)
@@ -98,11 +100,13 @@ export function useBluetoothScan(options: UseBluetoothScanOptions = {}): Bluetoo
98
100
  }, [])
99
101
 
100
102
  function clearResults() {
103
+ setDiagnostic(null)
101
104
  setDevices([])
102
105
  selectDevice(null)
103
106
  }
104
107
 
105
108
  function setModel(nextModel: DeviceModel) {
109
+ if (scanningRef.current) void stopScan()
106
110
  setModelState(nextModel)
107
111
  clearResults()
108
112
  }
@@ -116,6 +120,7 @@ export function useBluetoothScan(options: UseBluetoothScanOptions = {}): Bluetoo
116
120
  }
117
121
 
118
122
  setError(null)
123
+ setDiagnostic(null)
119
124
  setScanning(true)
120
125
  scanningRef.current = true
121
126
  setDevices([])
@@ -124,10 +129,14 @@ export function useBluetoothScan(options: UseBluetoothScanOptions = {}): Bluetoo
124
129
  try {
125
130
  const nextDevices = await BluetoothSdk.scan(scanModel, {
126
131
  ...(timeoutMsRef.current == null ? {} : {timeoutMs: timeoutMsRef.current}),
132
+ onDiagnostic: (hint) => {
133
+ if (activeScanRef.current === scanId) setDiagnostic(hint)
134
+ },
127
135
  onResults: (results) => {
128
136
  if (activeScanRef.current !== scanId) {
129
137
  return
130
138
  }
139
+ if (results.length > 0) setDiagnostic(null)
131
140
  setDevices(dedupeDevices(results, dedupeRef.current))
132
141
  },
133
142
  })
@@ -152,6 +161,7 @@ export function useBluetoothScan(options: UseBluetoothScanOptions = {}): Bluetoo
152
161
  }
153
162
 
154
163
  async function stopScan() {
164
+ setDiagnostic(null)
155
165
  activeScanRef.current += 1
156
166
  setScanning(false)
157
167
  scanningRef.current = false
@@ -161,6 +171,7 @@ export function useBluetoothScan(options: UseBluetoothScanOptions = {}): Bluetoo
161
171
  return {
162
172
  clearResults,
163
173
  devices,
174
+ diagnostic,
164
175
  error,
165
176
  model,
166
177
  scanning,
@@ -106,6 +106,7 @@ export type ScanController = {
106
106
  active: boolean
107
107
  clear: () => void
108
108
  devices: Device[]
109
+ diagnostic: GlassesConnectionHookResult["scan"]["diagnostic"]
109
110
  error: unknown | null
110
111
  model: DeviceModel
111
112
  selectedDevice: Device | null
@@ -252,6 +253,7 @@ function scanController(connection: GlassesConnectionHookResult): ScanController
252
253
  active: connection.scan.scanning,
253
254
  clear: connection.scan.clearResults,
254
255
  devices: connection.scan.devices,
256
+ diagnostic: connection.scan.diagnostic,
255
257
  error: connection.scan.error,
256
258
  model: connection.scan.model,
257
259
  selectedDevice: connection.scan.selectedDevice,