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

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 (61) hide show
  1. package/README.md +29 -0
  2. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +21 -0
  3. package/android/src/main/java/com/mentra/bluetoothsdk/ConnectedDeviceMatcher.kt +69 -0
  4. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +8 -0
  5. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  6. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +66 -1
  7. package/android/src/main/java/com/mentra/bluetoothsdk/NativeNotifications.kt +42 -0
  8. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +38 -1
  9. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/EvenFileService.kt +101 -0
  10. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/EvenNotificationProtocol.kt +113 -0
  11. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +378 -24
  12. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NotificationIds.kt +19 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +11 -0
  14. package/android/src/test/java/com/mentra/bluetoothsdk/ConnectedDeviceMatcherTest.kt +161 -0
  15. package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +87 -0
  16. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/EvenFileServiceTest.kt +153 -0
  17. package/build/BluetoothSdk.types.d.ts +57 -0
  18. package/build/BluetoothSdk.types.d.ts.map +1 -1
  19. package/build/BluetoothSdk.types.js.map +1 -1
  20. package/build/_private/BluetoothSdkModule.d.ts +6 -1
  21. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  22. package/build/_private/BluetoothSdkModule.js +28 -49
  23. package/build/_private/BluetoothSdkModule.js.map +1 -1
  24. package/build/_private/scanSession.d.ts +21 -0
  25. package/build/_private/scanSession.d.ts.map +1 -0
  26. package/build/_private/scanSession.js +75 -0
  27. package/build/_private/scanSession.js.map +1 -0
  28. package/build/generated/releaseMetadata.js +5 -5
  29. package/build/generated/releaseMetadata.js.map +1 -1
  30. package/build/index.d.ts +2 -1
  31. package/build/index.d.ts.map +1 -1
  32. package/build/index.js +4 -0
  33. package/build/index.js.map +1 -1
  34. package/build/react/useBluetoothScan.d.ts +2 -1
  35. package/build/react/useBluetoothScan.d.ts.map +1 -1
  36. package/build/react/useBluetoothScan.js +13 -0
  37. package/build/react/useBluetoothScan.js.map +1 -1
  38. package/build/react/useMentraBluetooth.d.ts +2 -1
  39. package/build/react/useMentraBluetooth.d.ts.map +1 -1
  40. package/build/react/useMentraBluetooth.js +1 -0
  41. package/build/react/useMentraBluetooth.js.map +1 -1
  42. package/ios/BluetoothSdkModule.swift +30 -0
  43. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  44. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  45. package/ios/Source/MentraBluetoothSDK.swift +53 -2
  46. package/ios/Source/NativeNotifications.swift +52 -0
  47. package/ios/Source/connection/ScanSession.swift +11 -0
  48. package/ios/Source/internal/BluetoothAvailability.swift +7 -0
  49. package/ios/Source/internal/ConnectedDeviceMatcher.swift +45 -0
  50. package/ios/Source/sgcs/G2.swift +131 -21
  51. package/ios/Source/sgcs/SGCManager.swift +22 -0
  52. package/ios/Tests/ConnectedDeviceMatcherTests.swift +27 -0
  53. package/ios/Tests/NativeNotificationTests.swift +20 -0
  54. package/package.json +1 -1
  55. package/src/BluetoothSdk.types.ts +62 -0
  56. package/src/_private/BluetoothSdkModule.ts +47 -57
  57. package/src/_private/scanSession.ts +88 -0
  58. package/src/generated/releaseMetadata.ts +5 -5
  59. package/src/index.ts +7 -0
  60. package/src/react/useBluetoothScan.ts +12 -1
  61. package/src/react/useMentraBluetooth.ts +2 -0
@@ -31,6 +31,7 @@ function hasDevice(devices, selectedDevice, dedupe) {
31
31
  }
32
32
  export function useBluetoothScan(options = {}) {
33
33
  const [devices, setDevices] = useState([]);
34
+ const [diagnostic, setDiagnostic] = useState(null);
34
35
  const [error, setError] = useState(null);
35
36
  const [model, setModelState] = useState(options.model ?? DeviceModels.MentraLive);
36
37
  const [scanning, setScanning] = useState(false);
@@ -63,10 +64,13 @@ export function useBluetoothScan(options = {}) {
63
64
  };
64
65
  }, []);
65
66
  function clearResults() {
67
+ setDiagnostic(null);
66
68
  setDevices([]);
67
69
  selectDevice(null);
68
70
  }
69
71
  function setModel(nextModel) {
72
+ if (scanningRef.current)
73
+ void stopScan();
70
74
  setModelState(nextModel);
71
75
  clearResults();
72
76
  }
@@ -78,6 +82,7 @@ export function useBluetoothScan(options = {}) {
78
82
  setModelState(nextModel);
79
83
  }
80
84
  setError(null);
85
+ setDiagnostic(null);
81
86
  setScanning(true);
82
87
  scanningRef.current = true;
83
88
  setDevices([]);
@@ -85,10 +90,16 @@ export function useBluetoothScan(options = {}) {
85
90
  try {
86
91
  const nextDevices = await BluetoothSdk.scan(scanModel, {
87
92
  ...(timeoutMsRef.current == null ? {} : { timeoutMs: timeoutMsRef.current }),
93
+ onDiagnostic: (hint) => {
94
+ if (activeScanRef.current === scanId)
95
+ setDiagnostic(hint);
96
+ },
88
97
  onResults: (results) => {
89
98
  if (activeScanRef.current !== scanId) {
90
99
  return;
91
100
  }
101
+ if (results.length > 0)
102
+ setDiagnostic(null);
92
103
  setDevices(dedupeDevices(results, dedupeRef.current));
93
104
  },
94
105
  });
@@ -114,6 +125,7 @@ export function useBluetoothScan(options = {}) {
114
125
  }
115
126
  }
116
127
  async function stopScan() {
128
+ setDiagnostic(null);
117
129
  activeScanRef.current += 1;
118
130
  setScanning(false);
119
131
  scanningRef.current = false;
@@ -122,6 +134,7 @@ export function useBluetoothScan(options = {}) {
122
134
  return {
123
135
  clearResults,
124
136
  devices,
137
+ diagnostic,
125
138
  error,
126
139
  model,
127
140
  scanning,
@@ -1 +1 @@
1
- {"version":3,"file":"useBluetoothScan.js","sourceRoot":"","sources":["../../src/react/useBluetoothScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAEjD,OAAO,YAAY,EAAE,EAAC,YAAY,EAAC,MAAM,UAAU,CAAA;AAyBnD,SAAS,SAAS,CAAC,MAAc,EAAE,MAA2B;IAC5D,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;IACvB,CAAC;IACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAA;IACzC,CAAC;IACD,OAAO,MAAM,CAAC,EAAE,CAAA;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,OAAiB,EAAE,MAA2B;IACnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,WAAW,GAAa,EAAE,CAAA;IAEhC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACrC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAM;QACR,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACb,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,SAAS,SAAS,CAAC,OAAiB,EAAE,cAA6B,EAAE,MAA2B;IAC9F,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,WAAW,GAA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AAW,CAAC,OAAO,GAAG,KAAK,CAAA;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,UAAU,QAAQ;QACrB,aAAa,CAAC,OAAO,IAAI,CAAC,CAAA;QAC1B,WAAW,CAAC,KAAK,CAAC,CAAA;QAClB,WAAW,CAAC,OAAO,GAAG,KAAK,CAAA;QAC3B,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAA;IAC/B,CAAC;IAED,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;QACL,KAAK;QACL,QAAQ;QACR,cAAc;QACd,YAAY;QACZ,QAAQ;QACR,SAAS;QACT,QAAQ;KACT,CAAA;AACH,CAAC","sourcesContent":["import {useEffect, useRef, useState} from \"react\"\n\nimport BluetoothSdk, {DeviceModels} from \"../index\"\nimport type {Device, DeviceModel} from \"../BluetoothSdk.types\"\n\nexport type BluetoothScanDedupe = \"id\" | \"name\" | ((device: Device) => string)\n\nexport type UseBluetoothScanOptions = {\n dedupe?: BluetoothScanDedupe\n model?: DeviceModel\n onError?: (error: unknown) => void\n timeoutMs?: number\n}\n\nexport type BluetoothScanHookResult = {\n clearResults: () => void\n devices: Device[]\n error: unknown | null\n model: DeviceModel\n scanning: boolean\n selectedDevice: Device | null\n selectDevice: (device: Device | null) => void\n setModel: (model: DeviceModel) => void\n startScan: (model?: DeviceModel) => Promise<Device[]>\n stopScan: () => Promise<void>\n}\n\nfunction dedupeKey(device: Device, dedupe: BluetoothScanDedupe): string {\n if (typeof dedupe === \"function\") {\n return dedupe(device)\n }\n if (dedupe === \"name\") {\n return `${device.model}:${device.name}`\n }\n return device.id\n}\n\nfunction dedupeDevices(devices: Device[], dedupe: BluetoothScanDedupe): Device[] {\n const seen = new Set<string>()\n const nextDevices: Device[] = []\n\n devices.forEach((device) => {\n const key = dedupeKey(device, dedupe)\n if (seen.has(key)) {\n return\n }\n seen.add(key)\n nextDevices.push(device)\n })\n\n return nextDevices\n}\n\nfunction hasDevice(devices: Device[], selectedDevice: Device | null, dedupe: BluetoothScanDedupe): boolean {\n if (!selectedDevice) {\n return true\n }\n const selectedKey = dedupeKey(selectedDevice, dedupe)\n return devices.some((device) => dedupeKey(device, dedupe) === selectedKey)\n}\n\nexport function useBluetoothScan(options: UseBluetoothScanOptions = {}): BluetoothScanHookResult {\n const [devices, setDevices] = useState<Device[]>([])\n const [error, setError] = useState<unknown | null>(null)\n const [model, setModelState] = useState<DeviceModel>(options.model ?? DeviceModels.MentraLive)\n const [scanning, setScanning] = useState(false)\n const [selectedDevice, selectDevice] = useState<Device | null>(null)\n const activeScanRef = useRef(0)\n const dedupeRef = useRef<BluetoothScanDedupe>(options.dedupe ?? \"id\")\n const onErrorRef = useRef(options.onError)\n const scanningRef = useRef(false)\n const timeoutMsRef = useRef(options.timeoutMs)\n\n useEffect(() => {\n dedupeRef.current = options.dedupe ?? \"id\"\n onErrorRef.current = options.onError\n timeoutMsRef.current = options.timeoutMs\n }, [options.dedupe, options.onError, options.timeoutMs])\n\n useEffect(() => {\n scanningRef.current = scanning\n }, [scanning])\n\n useEffect(() => {\n if (!hasDevice(devices, selectedDevice, dedupeRef.current)) {\n selectDevice(null)\n }\n }, [devices, selectedDevice])\n\n useEffect(() => {\n return () => {\n if (!scanningRef.current) {\n return\n }\n activeScanRef.current += 1\n void BluetoothSdk.stopScan().catch(() => undefined)\n }\n }, [])\n\n function clearResults() {\n setDevices([])\n selectDevice(null)\n }\n\n function setModel(nextModel: DeviceModel) {\n setModelState(nextModel)\n clearResults()\n }\n\n async function startScan(nextModel?: DeviceModel): Promise<Device[]> {\n const scanId = activeScanRef.current + 1\n activeScanRef.current = scanId\n const scanModel = nextModel ?? model\n if (nextModel && nextModel !== model) {\n setModelState(nextModel)\n }\n\n setError(null)\n setScanning(true)\n scanningRef.current = true\n setDevices([])\n selectDevice(null)\n\n try {\n const nextDevices = await BluetoothSdk.scan(scanModel, {\n ...(timeoutMsRef.current == null ? {} : {timeoutMs: timeoutMsRef.current}),\n onResults: (results) => {\n if (activeScanRef.current !== scanId) {\n return\n }\n setDevices(dedupeDevices(results, dedupeRef.current))\n },\n })\n const finalDevices = dedupeDevices(nextDevices, dedupeRef.current)\n if (activeScanRef.current === scanId) {\n setDevices(finalDevices)\n setError(null)\n }\n return finalDevices\n } catch (nextError) {\n if (activeScanRef.current === scanId) {\n setError(nextError)\n onErrorRef.current?.(nextError)\n }\n throw nextError\n } finally {\n if (activeScanRef.current === scanId) {\n setScanning(false)\n scanningRef.current = false\n }\n }\n }\n\n async function stopScan() {\n activeScanRef.current += 1\n setScanning(false)\n scanningRef.current = false\n await BluetoothSdk.stopScan()\n }\n\n return {\n clearResults,\n devices,\n error,\n model,\n scanning,\n selectedDevice,\n selectDevice,\n setModel,\n startScan,\n stopScan,\n }\n}\n"]}
1
+ {"version":3,"file":"useBluetoothScan.js","sourceRoot":"","sources":["../../src/react/useBluetoothScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAEjD,OAAO,YAAY,EAAE,EAAC,YAAY,EAAC,MAAM,UAAU,CAAA;AA0BnD,SAAS,SAAS,CAAC,MAAc,EAAE,MAA2B;IAC5D,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;IACvB,CAAC;IACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAA;IACzC,CAAC;IACD,OAAO,MAAM,CAAC,EAAE,CAAA;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,OAAiB,EAAE,MAA2B;IACnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,WAAW,GAAa,EAAE,CAAA;IAEhC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,SAAS,CAA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,QAAQ;QACR,cAAc;QACd,YAAY;QACZ,QAAQ;QACR,SAAS;QACT,QAAQ;KACT,CAAA;AACH,CAAC","sourcesContent":["import {useEffect, useRef, useState} from \"react\"\n\nimport BluetoothSdk, {DeviceModels} from \"../index\"\nimport type {Device, DeviceModel, ScanDiagnostic} from \"../BluetoothSdk.types\"\n\nexport type BluetoothScanDedupe = \"id\" | \"name\" | ((device: Device) => string)\n\nexport type UseBluetoothScanOptions = {\n dedupe?: BluetoothScanDedupe\n model?: DeviceModel\n onError?: (error: unknown) => void\n timeoutMs?: number\n}\n\nexport type BluetoothScanHookResult = {\n clearResults: () => void\n devices: Device[]\n diagnostic: ScanDiagnostic | null\n error: unknown | null\n model: DeviceModel\n scanning: boolean\n selectedDevice: Device | null\n selectDevice: (device: Device | null) => void\n setModel: (model: DeviceModel) => void\n startScan: (model?: DeviceModel) => Promise<Device[]>\n stopScan: () => Promise<void>\n}\n\nfunction dedupeKey(device: Device, dedupe: BluetoothScanDedupe): string {\n if (typeof dedupe === \"function\") {\n return dedupe(device)\n }\n if (dedupe === \"name\") {\n return `${device.model}:${device.name}`\n }\n return device.id\n}\n\nfunction dedupeDevices(devices: Device[], dedupe: BluetoothScanDedupe): Device[] {\n const seen = new Set<string>()\n const nextDevices: Device[] = []\n\n devices.forEach((device) => {\n const key = dedupeKey(device, dedupe)\n if (seen.has(key)) {\n return\n }\n seen.add(key)\n nextDevices.push(device)\n })\n\n return nextDevices\n}\n\nfunction hasDevice(devices: Device[], selectedDevice: Device | null, dedupe: BluetoothScanDedupe): boolean {\n if (!selectedDevice) {\n return true\n }\n const selectedKey = dedupeKey(selectedDevice, dedupe)\n return devices.some((device) => dedupeKey(device, dedupe) === selectedKey)\n}\n\nexport function useBluetoothScan(options: UseBluetoothScanOptions = {}): BluetoothScanHookResult {\n const [devices, setDevices] = useState<Device[]>([])\n const [diagnostic, setDiagnostic] = useState<ScanDiagnostic | null>(null)\n const [error, setError] = useState<unknown | null>(null)\n const [model, setModelState] = useState<DeviceModel>(options.model ?? DeviceModels.MentraLive)\n const [scanning, setScanning] = useState(false)\n const [selectedDevice, selectDevice] = useState<Device | null>(null)\n const activeScanRef = useRef(0)\n const dedupeRef = useRef<BluetoothScanDedupe>(options.dedupe ?? \"id\")\n const onErrorRef = useRef(options.onError)\n const scanningRef = useRef(false)\n const timeoutMsRef = useRef(options.timeoutMs)\n\n useEffect(() => {\n dedupeRef.current = options.dedupe ?? \"id\"\n onErrorRef.current = options.onError\n timeoutMsRef.current = options.timeoutMs\n }, [options.dedupe, options.onError, options.timeoutMs])\n\n useEffect(() => {\n scanningRef.current = scanning\n }, [scanning])\n\n useEffect(() => {\n if (!hasDevice(devices, selectedDevice, dedupeRef.current)) {\n selectDevice(null)\n }\n }, [devices, selectedDevice])\n\n useEffect(() => {\n return () => {\n if (!scanningRef.current) {\n return\n }\n activeScanRef.current += 1\n void BluetoothSdk.stopScan().catch(() => undefined)\n }\n }, [])\n\n function clearResults() {\n setDiagnostic(null)\n setDevices([])\n selectDevice(null)\n }\n\n function setModel(nextModel: DeviceModel) {\n if (scanningRef.current) void stopScan()\n setModelState(nextModel)\n clearResults()\n }\n\n async function startScan(nextModel?: DeviceModel): Promise<Device[]> {\n const scanId = activeScanRef.current + 1\n activeScanRef.current = scanId\n const scanModel = nextModel ?? model\n if (nextModel && nextModel !== model) {\n setModelState(nextModel)\n }\n\n setError(null)\n setDiagnostic(null)\n setScanning(true)\n scanningRef.current = true\n setDevices([])\n selectDevice(null)\n\n try {\n const nextDevices = await BluetoothSdk.scan(scanModel, {\n ...(timeoutMsRef.current == null ? {} : {timeoutMs: timeoutMsRef.current}),\n onDiagnostic: (hint) => {\n if (activeScanRef.current === scanId) setDiagnostic(hint)\n },\n onResults: (results) => {\n if (activeScanRef.current !== scanId) {\n return\n }\n if (results.length > 0) setDiagnostic(null)\n setDevices(dedupeDevices(results, dedupeRef.current))\n },\n })\n const finalDevices = dedupeDevices(nextDevices, dedupeRef.current)\n if (activeScanRef.current === scanId) {\n setDevices(finalDevices)\n setError(null)\n }\n return finalDevices\n } catch (nextError) {\n if (activeScanRef.current === scanId) {\n setError(nextError)\n onErrorRef.current?.(nextError)\n }\n throw nextError\n } finally {\n if (activeScanRef.current === scanId) {\n setScanning(false)\n scanningRef.current = false\n }\n }\n }\n\n async function stopScan() {\n setDiagnostic(null)\n activeScanRef.current += 1\n setScanning(false)\n scanningRef.current = false\n await BluetoothSdk.stopScan()\n }\n\n return {\n clearResults,\n devices,\n diagnostic,\n error,\n model,\n scanning,\n selectedDevice,\n selectDevice,\n setModel,\n startScan,\n stopScan,\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { ConnectOptions, Device, DeviceModel, GlassesConnectionStatus, HotspotStatus, MicMode, SettingsAckSuccessEvent, WifiSearchResult, WifiStatus } from "../BluetoothSdk.types";
2
- import { type DefaultDeviceStorage } from "./useGlassesConnection";
2
+ import { type DefaultDeviceStorage, type GlassesConnectionHookResult } from "./useGlassesConnection";
3
3
  export type BatteryState = {
4
4
  charging: boolean;
5
5
  level: number | null;
@@ -65,6 +65,7 @@ export type ScanController = {
65
65
  active: boolean;
66
66
  clear: () => void;
67
67
  devices: Device[];
68
+ diagnostic: GlassesConnectionHookResult["scan"]["diagnostic"];
68
69
  error: unknown | null;
69
70
  model: DeviceModel;
70
71
  selectedDevice: Device | null;
@@ -1 +1 @@
1
- {"version":3,"file":"useMentraBluetooth.d.ts","sourceRoot":"","sources":["../../src/react/useMentraBluetooth.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,WAAW,EACX,uBAAuB,EACvB,aAAa,EAGb,OAAO,EACP,uBAAuB,EACvB,gBAAgB,EAChB,UAAU,EACX,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,wBAAwB,CAAA;AAE/B,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM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A;IACzB,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAA;IAC7E,gCAAgC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACtE,CAAA;AA6HD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,yBAA8B,GAAG,sBAAsB,CAwDlG"}
@@ -99,6 +99,7 @@ function scanController(connection) {
99
99
  active: connection.scan.scanning,
100
100
  clear: connection.scan.clearResults,
101
101
  devices: connection.scan.devices,
102
+ diagnostic: connection.scan.diagnostic,
102
103
  error: connection.scan.error,
103
104
  model: connection.scan.model,
104
105
  selectedDevice: connection.scan.selectedDevice,
@@ -1 +1 @@
1
- {"version":3,"file":"useMentraBluetooth.js","sourceRoot":"","sources":["../../src/react/useMentraBluetooth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE9B,OAAO,YAAY,MAAM,UAAU,CAAA;AACnC,OAAO,EACL,wCAAwC,EACxC,YAAY,EACZ,+BAA+B,EAC/B,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,uBAAuB,CAAA;AAe9B,OAAO,EACL,oBAAoB,GAGrB,MAAM,wBAAwB,CAAA;AAkH/B,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1E,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AA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AAe,CAAC,kBAAkB,KAAK,KAAK;QAChE,KAAK,EAAE,gBAAgB;KACxB,CAAA;IAED,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,mBAAmB;QAC5C,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;QACjD,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,KAAK,EAAE,gBAAgB,IAAI,UAAU,CAAC,KAAK;QAC3C,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,aAAa,CAAC;QACtD,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC;QAChC,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC;QACrF,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,qBAAqB;QACrB,gCAAgC;KACjC,CAAA;AACH,CAAC","sourcesContent":["import {useState} from \"react\"\n\nimport BluetoothSdk from \"../index\"\nimport {\n DEFAULT_VOICE_ACTIVITY_DETECTION_ENABLED,\n DeviceModels,\n createDisconnectedGlassesStatus,\n isConnectedGlassesConnectionStatus,\n isReadyGlassesConnectionStatus,\n} from \"../BluetoothSdk.types\"\nimport type {\n ConnectOptions,\n Device,\n DeviceModel,\n GlassesConnectionStatus,\n HotspotStatus,\n PublicBluetoothStatus,\n PublicGlassesStatus,\n MicMode,\n SettingsAckSuccessEvent,\n WifiSearchResult,\n WifiStatus,\n} from \"../BluetoothSdk.types\"\n\nimport {\n useGlassesConnection,\n type DefaultDeviceStorage,\n type GlassesConnectionHookResult,\n} from \"./useGlassesConnection\"\n\nexport type BatteryState = {\n charging: boolean\n level: number | null\n}\n\nexport type ConnectedGlassesInfo = {\n appVersion?: string\n bluetoothName?: string\n buildNumber?: string\n color?: string\n deviceModel?: string\n firmwareVersion?: string\n serialNumber?: string\n style?: string\n}\n\nexport type FirmwareInfo = {\n appVersion?: string\n buildNumber?: string\n source:\n | \"app\"\n | \"bes\"\n | \"device\"\n | \"firmware\"\n | \"left\"\n | \"mtk\"\n | \"right\"\n | \"unknown\"\n version: string | null\n}\n\nexport type SignalState = {\n strengthDbm: number | null\n updatedAt: number | null\n}\n\nexport type GlassesRuntimeState =\n | {\n connected: false\n connection: Exclude<GlassesConnectionStatus, {state: \"connected\"}>\n ready: false\n }\n | {\n battery: BatteryState\n connected: true\n connection: Extract<GlassesConnectionStatus, {state: \"connected\"}>\n device: ConnectedGlassesInfo\n firmware: FirmwareInfo\n hotspot: HotspotStatus\n ready: boolean\n signal: SignalState\n voiceActivityDetectionEnabled: boolean\n wifi: WifiStatus\n }\n\nexport type GalleryModeState = {\n applying: boolean\n enabled: boolean\n error: unknown | null\n}\n\nexport type PhoneSdkRuntimeState = {\n currentMic: MicMode | null\n defaultDevice: Device | null\n galleryMode: GalleryModeState\n lastLog: string[]\n micRanking: MicMode[]\n otherBluetoothConnected: boolean\n searching: boolean\n searchingController: boolean\n systemMicUnavailable: boolean\n wifiScanResults: WifiSearchResult[]\n}\n\nexport type ScanController = {\n active: boolean\n clear: () => void\n devices: Device[]\n error: unknown | null\n model: DeviceModel\n selectedDevice: Device | null\n selectDevice: (device: Device | null) => void\n setModel: (model: DeviceModel) => void\n start: (model?: DeviceModel) => Promise<Device[]>\n stop: () => Promise<void>\n}\n\nexport type UseMentraBluetoothOptions = {\n autoConnectDefault?: boolean\n defaultDeviceStorage?: DefaultDeviceStorage\n defaultModel?: DeviceModel\n onError?: (error: unknown) => void\n scanTimeoutMs?: number\n}\n\nexport type MentraBluetoothSession = {\n busy: boolean\n clearDefaultDevice: () => Promise<void>\n connect: (device?: Device, options?: ConnectOptions) => Promise<void>\n connectDefault: (options?: ConnectOptions) => Promise<void>\n defaultDevice: Device | null\n disconnect: () => Promise<void>\n error: unknown | null\n glasses: GlassesRuntimeState\n refresh: () => Promise<void>\n scan: ScanController\n sdk: PhoneSdkRuntimeState\n setDefaultDevice: (device: Device | null) => Promise<void>\n setGalleryModeEnabled: (enabled: boolean) => Promise<SettingsAckSuccessEvent>\n setVoiceActivityDetectionEnabled: (enabled: boolean) => Promise<void>\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === \"string\" && value.length > 0 ? value : undefined\n}\n\nfunction numberValue(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null\n}\n\nfunction firmwareInfo(status: Partial<PublicGlassesStatus>): FirmwareInfo {\n const firmwareSources = [\n [\"firmwareVersion\", \"firmware\"],\n [\"deviceFirmwareVersion\", \"device\"],\n [\"rightFirmwareVersion\", \"right\"],\n [\"leftFirmwareVersion\", \"left\"],\n [\"besFirmwareVersion\", \"bes\"],\n [\"mtkFirmwareVersion\", \"mtk\"],\n [\"appVersion\", \"app\"],\n ] as const\n\n for (const [key, source] of firmwareSources) {\n const value = stringValue((status as Record<string, unknown>)[key])\n if (value) {\n return {\n appVersion: stringValue(status.appVersion),\n buildNumber: stringValue(status.buildNumber),\n source,\n version: value,\n }\n }\n }\n\n return {\n appVersion: stringValue(status.appVersion),\n buildNumber: stringValue(status.buildNumber),\n source: \"unknown\",\n version: null,\n }\n}\n\nfunction batteryState(status: Partial<PublicGlassesStatus>): BatteryState {\n const level = typeof status.batteryLevel === \"number\" && status.batteryLevel >= 0 ? status.batteryLevel : null\n return {\n charging: status.charging ?? false,\n level,\n }\n}\n\nfunction connectedGlassesInfo(status: Partial<PublicGlassesStatus>): ConnectedGlassesInfo {\n return {\n appVersion: stringValue(status.appVersion),\n bluetoothName: stringValue(status.bluetoothName),\n buildNumber: stringValue(status.buildNumber),\n color: stringValue(status.color),\n deviceModel: stringValue(status.deviceModel),\n firmwareVersion: stringValue(status.firmwareVersion),\n serialNumber: stringValue(status.serialNumber),\n style: stringValue(status.style),\n }\n}\n\nfunction runtimeGlassesState(status: Partial<PublicGlassesStatus>): GlassesRuntimeState {\n const connection = status.connection ?? createDisconnectedGlassesStatus().connection ?? {state: \"disconnected\"}\n\n if (!isConnectedGlassesConnectionStatus(connection)) {\n return {\n connected: false,\n connection,\n ready: false,\n }\n }\n\n return {\n battery: batteryState(status),\n connected: true,\n connection,\n device: connectedGlassesInfo(status),\n firmware: firmwareInfo(status),\n hotspot: status.hotspot ?? {state: \"disabled\"},\n ready: isReadyGlassesConnectionStatus(connection),\n signal: {\n strengthDbm: numberValue((status as Record<string, unknown>).signalStrength),\n updatedAt: numberValue((status as Record<string, unknown>).signalStrengthUpdatedAt),\n },\n voiceActivityDetectionEnabled: status.voiceActivityDetectionEnabled ?? DEFAULT_VOICE_ACTIVITY_DETECTION_ENABLED,\n wifi: status.wifi ?? {state: \"disconnected\"},\n }\n}\n\nfunction phoneSdkState(\n status: Partial<PublicBluetoothStatus>,\n defaultDevice: Device | null,\n galleryMode: GalleryModeState,\n): PhoneSdkRuntimeState {\n return {\n currentMic: status.currentMic || null,\n defaultDevice,\n galleryMode,\n lastLog: status.lastLog ?? [],\n micRanking: status.micRanking ?? [],\n otherBluetoothConnected: status.otherBtConnected ?? false,\n searching: status.searching ?? false,\n searchingController: status.searchingController ?? false,\n systemMicUnavailable: status.systemMicUnavailable ?? false,\n wifiScanResults: status.wifiScanResults ?? [],\n }\n}\n\nfunction scanController(connection: GlassesConnectionHookResult): ScanController {\n return {\n active: connection.scan.scanning,\n clear: connection.scan.clearResults,\n devices: connection.scan.devices,\n error: connection.scan.error,\n model: connection.scan.model,\n selectedDevice: connection.scan.selectedDevice,\n selectDevice: connection.scan.selectDevice,\n setModel: connection.scan.setModel,\n start: connection.scan.startScan,\n stop: connection.scan.stopScan,\n }\n}\n\nexport function useMentraBluetooth(options: UseMentraBluetoothOptions = {}): MentraBluetoothSession {\n const connection = useGlassesConnection({\n autoConnectDefault: options.autoConnectDefault,\n defaultDeviceStorage: options.defaultDeviceStorage,\n onError: options.onError,\n scanModel: options.defaultModel ?? DeviceModels.MentraLive,\n scanTimeoutMs: options.scanTimeoutMs,\n })\n const [galleryModeApplying, setGalleryModeApplying] = useState(false)\n const [galleryModeError, setGalleryModeError] = useState<unknown | null>(null)\n\n async function setGalleryModeEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent> {\n setGalleryModeApplying(true)\n setGalleryModeError(null)\n try {\n return await BluetoothSdk.setGalleryModeEnabled(enabled)\n } catch (error) {\n setGalleryModeError(error)\n options.onError?.(error)\n throw error\n } finally {\n setGalleryModeApplying(false)\n }\n }\n\n async function setVoiceActivityDetectionEnabled(enabled: boolean) {\n try {\n await BluetoothSdk.setVoiceActivityDetectionEnabled(enabled)\n } catch (error) {\n options.onError?.(error)\n throw error\n }\n }\n\n const galleryMode: GalleryModeState = {\n applying: galleryModeApplying,\n enabled: connection.bluetoothStatus.galleryModeEnabled !== false,\n error: galleryModeError,\n }\n\n return {\n busy: connection.busy || galleryModeApplying,\n clearDefaultDevice: connection.clearDefaultDevice,\n connect: connection.connect,\n connectDefault: connection.connectDefault,\n defaultDevice: connection.defaultDevice,\n disconnect: connection.disconnect,\n error: galleryModeError ?? connection.error,\n glasses: runtimeGlassesState(connection.glassesStatus),\n refresh: connection.refresh,\n scan: scanController(connection),\n sdk: phoneSdkState(connection.bluetoothStatus, connection.defaultDevice, galleryMode),\n setDefaultDevice: connection.setDefaultDevice,\n setGalleryModeEnabled,\n setVoiceActivityDetectionEnabled,\n }\n}\n"]}
1
+ {"version":3,"file":"useMentraBluetooth.js","sourceRoot":"","sources":["../../src/react/useMentraBluetooth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE9B,OAAO,YAAY,MAAM,UAAU,CAAA;AACnC,OAAO,EACL,wCAAwC,EACxC,YAAY,EACZ,+BAA+B,EAC/B,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,uBAAuB,CAAA;AAe9B,OAAO,EACL,oBAAoB,GAGrB,MAAM,wBAAwB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BAAsB,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,KAAK,UAAU,gCAAgC,CAAC,OAAgB;QAC9D,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAA;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YACxB,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAqB;QACpC,QAAQ,EAAE,mBAAmB;QAC7B,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,kBAAkB,KAAK,KAAK;QAChE,KAAK,EAAE,gBAAgB;KACxB,CAAA;IAED,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,mBAAmB;QAC5C,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;QACjD,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,KAAK,EAAE,gBAAgB,IAAI,UAAU,CAAC,KAAK;QAC3C,OAAO,EAAE,mBAAmB,CAAC,UAAU,CAAC,aAAa,CAAC;QACtD,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC;QAChC,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC;QACrF,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,qBAAqB;QACrB,gCAAgC;KACjC,CAAA;AACH,CAAC","sourcesContent":["import {useState} from \"react\"\n\nimport BluetoothSdk from \"../index\"\nimport {\n DEFAULT_VOICE_ACTIVITY_DETECTION_ENABLED,\n DeviceModels,\n createDisconnectedGlassesStatus,\n isConnectedGlassesConnectionStatus,\n isReadyGlassesConnectionStatus,\n} from \"../BluetoothSdk.types\"\nimport type {\n ConnectOptions,\n Device,\n DeviceModel,\n GlassesConnectionStatus,\n HotspotStatus,\n PublicBluetoothStatus,\n PublicGlassesStatus,\n MicMode,\n SettingsAckSuccessEvent,\n WifiSearchResult,\n WifiStatus,\n} from \"../BluetoothSdk.types\"\n\nimport {\n useGlassesConnection,\n type DefaultDeviceStorage,\n type GlassesConnectionHookResult,\n} from \"./useGlassesConnection\"\n\nexport type BatteryState = {\n charging: boolean\n level: number | null\n}\n\nexport type ConnectedGlassesInfo = {\n appVersion?: string\n bluetoothName?: string\n buildNumber?: string\n color?: string\n deviceModel?: string\n firmwareVersion?: string\n serialNumber?: string\n style?: string\n}\n\nexport type FirmwareInfo = {\n appVersion?: string\n buildNumber?: string\n source:\n | \"app\"\n | \"bes\"\n | \"device\"\n | \"firmware\"\n | \"left\"\n | \"mtk\"\n | \"right\"\n | \"unknown\"\n version: string | null\n}\n\nexport type SignalState = {\n strengthDbm: number | null\n updatedAt: number | null\n}\n\nexport type GlassesRuntimeState =\n | {\n connected: false\n connection: Exclude<GlassesConnectionStatus, {state: \"connected\"}>\n ready: false\n }\n | {\n battery: BatteryState\n connected: true\n connection: Extract<GlassesConnectionStatus, {state: \"connected\"}>\n device: ConnectedGlassesInfo\n firmware: FirmwareInfo\n hotspot: HotspotStatus\n ready: boolean\n signal: SignalState\n voiceActivityDetectionEnabled: boolean\n wifi: WifiStatus\n }\n\nexport type GalleryModeState = {\n applying: boolean\n enabled: boolean\n error: unknown | null\n}\n\nexport type PhoneSdkRuntimeState = {\n currentMic: MicMode | null\n defaultDevice: Device | null\n galleryMode: GalleryModeState\n lastLog: string[]\n micRanking: MicMode[]\n otherBluetoothConnected: boolean\n searching: boolean\n searchingController: boolean\n systemMicUnavailable: boolean\n wifiScanResults: WifiSearchResult[]\n}\n\nexport type ScanController = {\n active: boolean\n clear: () => void\n devices: Device[]\n diagnostic: GlassesConnectionHookResult[\"scan\"][\"diagnostic\"]\n error: unknown | null\n model: DeviceModel\n selectedDevice: Device | null\n selectDevice: (device: Device | null) => void\n setModel: (model: DeviceModel) => void\n start: (model?: DeviceModel) => Promise<Device[]>\n stop: () => Promise<void>\n}\n\nexport type UseMentraBluetoothOptions = {\n autoConnectDefault?: boolean\n defaultDeviceStorage?: DefaultDeviceStorage\n defaultModel?: DeviceModel\n onError?: (error: unknown) => void\n scanTimeoutMs?: number\n}\n\nexport type MentraBluetoothSession = {\n busy: boolean\n clearDefaultDevice: () => Promise<void>\n connect: (device?: Device, options?: ConnectOptions) => Promise<void>\n connectDefault: (options?: ConnectOptions) => Promise<void>\n defaultDevice: Device | null\n disconnect: () => Promise<void>\n error: unknown | null\n glasses: GlassesRuntimeState\n refresh: () => Promise<void>\n scan: ScanController\n sdk: PhoneSdkRuntimeState\n setDefaultDevice: (device: Device | null) => Promise<void>\n setGalleryModeEnabled: (enabled: boolean) => Promise<SettingsAckSuccessEvent>\n setVoiceActivityDetectionEnabled: (enabled: boolean) => Promise<void>\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === \"string\" && value.length > 0 ? value : undefined\n}\n\nfunction numberValue(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null\n}\n\nfunction firmwareInfo(status: Partial<PublicGlassesStatus>): FirmwareInfo {\n const firmwareSources = [\n [\"firmwareVersion\", \"firmware\"],\n [\"deviceFirmwareVersion\", \"device\"],\n [\"rightFirmwareVersion\", \"right\"],\n [\"leftFirmwareVersion\", \"left\"],\n [\"besFirmwareVersion\", \"bes\"],\n [\"mtkFirmwareVersion\", \"mtk\"],\n [\"appVersion\", \"app\"],\n ] as const\n\n for (const [key, source] of firmwareSources) {\n const value = stringValue((status as Record<string, unknown>)[key])\n if (value) {\n return {\n appVersion: stringValue(status.appVersion),\n buildNumber: stringValue(status.buildNumber),\n source,\n version: value,\n }\n }\n }\n\n return {\n appVersion: stringValue(status.appVersion),\n buildNumber: stringValue(status.buildNumber),\n source: \"unknown\",\n version: null,\n }\n}\n\nfunction batteryState(status: Partial<PublicGlassesStatus>): BatteryState {\n const level = typeof status.batteryLevel === \"number\" && status.batteryLevel >= 0 ? status.batteryLevel : null\n return {\n charging: status.charging ?? false,\n level,\n }\n}\n\nfunction connectedGlassesInfo(status: Partial<PublicGlassesStatus>): ConnectedGlassesInfo {\n return {\n appVersion: stringValue(status.appVersion),\n bluetoothName: stringValue(status.bluetoothName),\n buildNumber: stringValue(status.buildNumber),\n color: stringValue(status.color),\n deviceModel: stringValue(status.deviceModel),\n firmwareVersion: stringValue(status.firmwareVersion),\n serialNumber: stringValue(status.serialNumber),\n style: stringValue(status.style),\n }\n}\n\nfunction runtimeGlassesState(status: Partial<PublicGlassesStatus>): GlassesRuntimeState {\n const connection = status.connection ?? createDisconnectedGlassesStatus().connection ?? {state: \"disconnected\"}\n\n if (!isConnectedGlassesConnectionStatus(connection)) {\n return {\n connected: false,\n connection,\n ready: false,\n }\n }\n\n return {\n battery: batteryState(status),\n connected: true,\n connection,\n device: connectedGlassesInfo(status),\n firmware: firmwareInfo(status),\n hotspot: status.hotspot ?? {state: \"disabled\"},\n ready: isReadyGlassesConnectionStatus(connection),\n signal: {\n strengthDbm: numberValue((status as Record<string, unknown>).signalStrength),\n updatedAt: numberValue((status as Record<string, unknown>).signalStrengthUpdatedAt),\n },\n voiceActivityDetectionEnabled: status.voiceActivityDetectionEnabled ?? DEFAULT_VOICE_ACTIVITY_DETECTION_ENABLED,\n wifi: status.wifi ?? {state: \"disconnected\"},\n }\n}\n\nfunction phoneSdkState(\n status: Partial<PublicBluetoothStatus>,\n defaultDevice: Device | null,\n galleryMode: GalleryModeState,\n): PhoneSdkRuntimeState {\n return {\n currentMic: status.currentMic || null,\n defaultDevice,\n galleryMode,\n lastLog: status.lastLog ?? [],\n micRanking: status.micRanking ?? [],\n otherBluetoothConnected: status.otherBtConnected ?? false,\n searching: status.searching ?? false,\n searchingController: status.searchingController ?? false,\n systemMicUnavailable: status.systemMicUnavailable ?? false,\n wifiScanResults: status.wifiScanResults ?? [],\n }\n}\n\nfunction scanController(connection: GlassesConnectionHookResult): ScanController {\n return {\n active: connection.scan.scanning,\n clear: connection.scan.clearResults,\n devices: connection.scan.devices,\n diagnostic: connection.scan.diagnostic,\n error: connection.scan.error,\n model: connection.scan.model,\n selectedDevice: connection.scan.selectedDevice,\n selectDevice: connection.scan.selectDevice,\n setModel: connection.scan.setModel,\n start: connection.scan.startScan,\n stop: connection.scan.stopScan,\n }\n}\n\nexport function useMentraBluetooth(options: UseMentraBluetoothOptions = {}): MentraBluetoothSession {\n const connection = useGlassesConnection({\n autoConnectDefault: options.autoConnectDefault,\n defaultDeviceStorage: options.defaultDeviceStorage,\n onError: options.onError,\n scanModel: options.defaultModel ?? DeviceModels.MentraLive,\n scanTimeoutMs: options.scanTimeoutMs,\n })\n const [galleryModeApplying, setGalleryModeApplying] = useState(false)\n const [galleryModeError, setGalleryModeError] = useState<unknown | null>(null)\n\n async function setGalleryModeEnabled(enabled: boolean): Promise<SettingsAckSuccessEvent> {\n setGalleryModeApplying(true)\n setGalleryModeError(null)\n try {\n return await BluetoothSdk.setGalleryModeEnabled(enabled)\n } catch (error) {\n setGalleryModeError(error)\n options.onError?.(error)\n throw error\n } finally {\n setGalleryModeApplying(false)\n }\n }\n\n async function setVoiceActivityDetectionEnabled(enabled: boolean) {\n try {\n await BluetoothSdk.setVoiceActivityDetectionEnabled(enabled)\n } catch (error) {\n options.onError?.(error)\n throw error\n }\n }\n\n const galleryMode: GalleryModeState = {\n applying: galleryModeApplying,\n enabled: connection.bluetoothStatus.galleryModeEnabled !== false,\n error: galleryModeError,\n }\n\n return {\n busy: connection.busy || galleryModeApplying,\n clearDefaultDevice: connection.clearDefaultDevice,\n connect: connection.connect,\n connectDefault: connection.connectDefault,\n defaultDevice: connection.defaultDevice,\n disconnect: connection.disconnect,\n error: galleryModeError ?? connection.error,\n glasses: runtimeGlassesState(connection.glassesStatus),\n refresh: connection.refresh,\n scan: scanController(connection),\n sdk: phoneSdkState(connection.bluetoothStatus, connection.defaultDevice, galleryMode),\n setDefaultDevice: connection.setDefaultDevice,\n setGalleryModeEnabled,\n setVoiceActivityDetectionEnabled,\n }\n}\n"]}
@@ -55,6 +55,8 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
55
55
  "save_setting",
56
56
  "local_transcription",
57
57
  "phone_notification",
58
+ "native_notification_status",
59
+ "native_notification_delivery",
58
60
  "phone_notification_dismissed",
59
61
  "ws_text",
60
62
  "ws_bin",
@@ -220,6 +222,13 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
220
222
  }
221
223
  }
222
224
 
225
+ AsyncFunction("getScanDiagnostic") { (model: String) -> [String: String]? in
226
+ await MainActor.run {
227
+ guard let diagnostic = self.bluetoothSdk().scanDiagnostic(for: DeviceModel.fromDeviceType(model)) else { return nil }
228
+ return ["code": diagnostic.code, "message": diagnostic.message]
229
+ }
230
+ }
231
+
223
232
  AsyncFunction("stopScan") {
224
233
  await MainActor.run {
225
234
  self.bluetoothSdk().stopScan()
@@ -290,6 +299,27 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
290
299
  }
291
300
  }
292
301
 
302
+ AsyncFunction("configureNativeNotifications") { (values: [String: Any]) in
303
+ try await MainActor.run {
304
+ try self.bluetoothSdk().configureNativeNotifications(NativeNotificationConfig(
305
+ enabled: values["enabled"] as? Bool ?? false,
306
+ autoDisplay: values["autoDisplay"] as? Bool ?? true,
307
+ durationSeconds: (values["durationSeconds"] as? NSNumber)?.intValue ?? 5,
308
+ doNotDisturb: values["doNotDisturb"] as? Bool ?? false,
309
+ blockedApps: values["blockedApps"] as? [String] ?? []
310
+ ))
311
+ }
312
+ }
313
+ AsyncFunction("getNativeNotificationStatus") {
314
+ await MainActor.run { self.bluetoothSdk().getNativeNotificationStatus().dictionary }
315
+ }
316
+
317
+ // MARK: - Native Notification Centre
318
+
319
+ AsyncFunction("sendPhoneNotification") { (_: [String: Any]) in
320
+ throw NativeNotificationError.unsupported
321
+ }
322
+
293
323
  // MARK: - WiFi Commands
294
324
 
295
325
  AsyncFunction("requestWifiScan") {
@@ -11,7 +11,7 @@ enum BluetoothSdkDefaults {
11
11
  static let voiceActivityDetectionEnabled = false
12
12
  static let loudnessGateEnabled = false
13
13
  private static let infoSdkVersionKey = "MentraBluetoothSdkVersion"
14
- private static let swiftPackageSdkVersion = "3.2.0-dev.180"
14
+ private static let swiftPackageSdkVersion = "3.2.0-dev.187"
15
15
  private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
16
16
 
17
17
  private static func normalizedSdkVersion(_ value: String?) -> String? {
@@ -3,9 +3,9 @@ import Foundation
3
3
  /// Generated by release CI. Do not edit in a release checkout.
4
4
  enum GeneratedReleaseMetadata {
5
5
  static let familyBaseVersion = "3.2.0"
6
- static let releaseIdentity = "3.2.0-dev.180"
7
- static let releaseSetId = "mentra-3.2.0-dev.180"
8
- static let sourceCommit = "1f24e462561fef37b7082204847a541db4a87c41"
9
- static let otaManifestUrl = "https://github.com/Mentra-Community/MentraOS/releases/download/mentra-builds-v3.2.0/mentra-live-ota-3.2.0-dev.180.json"
10
- static let otaManifestSha256 = "cbf2a1b81430bd34942e2a1764138f6d79197767b4434a2d8c44311768f8b873"
6
+ static let releaseIdentity = "3.2.0-dev.187"
7
+ static let releaseSetId = "mentra-3.2.0-dev.187"
8
+ static let sourceCommit = "d8b34892f11593baa3c075b94380253b06eb874d"
9
+ static let otaManifestUrl = "https://github.com/Mentra-Community/MentraOS/releases/download/mentra-builds-v3.2.0/mentra-live-ota-3.2.0-dev.187.json"
10
+ static let otaManifestSha256 = "cf21f4ab6347acb12eefa38d2f0a3b433bc0e05428c527bcda57a8693d7a72f9"
11
11
  }
@@ -24,6 +24,7 @@ private final class ActiveScanSession {
24
24
  let model: DeviceModel
25
25
  let onResults: ([Device]) -> Void
26
26
  let onComplete: ([Device]) -> Void
27
+ let onDiagnostic: ((ScanDiagnostic) -> Void)?
27
28
  var latestResults: [Device] = []
28
29
  var timeoutTask: Task<Void, Never>?
29
30
  weak var publicSession: ScanSession?
@@ -31,11 +32,13 @@ private final class ActiveScanSession {
31
32
  init(
32
33
  model: DeviceModel,
33
34
  onResults: @escaping ([Device]) -> Void,
34
- onComplete: @escaping ([Device]) -> Void
35
+ onComplete: @escaping ([Device]) -> Void,
36
+ onDiagnostic: ((ScanDiagnostic) -> Void)?
35
37
  ) {
36
38
  self.model = model
37
39
  self.onResults = onResults
38
40
  self.onComplete = onComplete
41
+ self.onDiagnostic = onDiagnostic
39
42
  }
40
43
  }
41
44
 
@@ -354,13 +357,27 @@ public final class MentraBluetoothSDK {
354
357
  timeout: TimeInterval = 15,
355
358
  onResults: @escaping ([Device]) -> Void,
356
359
  onComplete: @escaping ([Device]) -> Void = { _ in }
360
+ ) throws -> ScanSession {
361
+ try scan(model: model, timeout: timeout, onResults: onResults, onDiagnostic: nil, onComplete: onComplete)
362
+ }
363
+
364
+ /// Optional advisory before an empty completed scan. Existing scan overloads
365
+ /// retain their signatures and behavior; cancellation does not produce hints.
366
+ @discardableResult
367
+ public func scan(
368
+ model: DeviceModel,
369
+ timeout: TimeInterval = 15,
370
+ onResults: @escaping ([Device]) -> Void,
371
+ onDiagnostic: ((ScanDiagnostic) -> Void)?,
372
+ onComplete: @escaping ([Device]) -> Void = { _ in }
357
373
  ) throws -> ScanSession {
358
374
  let normalizedTimeout = timeout > 0 && timeout.isFinite ? timeout : 15
359
375
  let id = UUID()
360
376
  let activeSession = ActiveScanSession(
361
377
  model: model,
362
378
  onResults: onResults,
363
- onComplete: onComplete
379
+ onComplete: onComplete,
380
+ onDiagnostic: onDiagnostic
364
381
  )
365
382
  let publicSession = ScanSession { [weak self] in
366
383
  self?.finishScanSession(id, reason: .cancelled, shouldStopScan: true)
@@ -481,6 +498,16 @@ public final class MentraBluetoothSDK {
481
498
  DeviceManager.shared.showDashboard()
482
499
  }
483
500
 
501
+ public func configureNativeNotifications(_ config: NativeNotificationConfig) throws {
502
+ try config.validate()
503
+ guard let driver = DeviceManager.shared.sgc else { throw NativeNotificationError.notConnected }
504
+ try driver.configureNativeNotifications(config)
505
+ }
506
+
507
+ public func getNativeNotificationStatus() -> NativeNotificationStatus {
508
+ DeviceManager.shared.sgc?.getNativeNotificationStatus() ?? .unavailable
509
+ }
510
+
484
511
  public func showNotificationsPanel() {
485
512
  DeviceManager.shared.showNotificationsPanel()
486
513
  }
@@ -2107,6 +2134,25 @@ private func dispatchDiscoveredDevices(_ rawSearchResults: Any?) {
2107
2134
  activeSession.onResults(devices)
2108
2135
  }
2109
2136
 
2137
+ /// Used by both the native scan callback and the React Native scan wrapper.
2138
+ func scanDiagnostic(for model: DeviceModel) -> ScanDiagnostic? {
2139
+ let status = glassesStatus
2140
+ guard model != .simulated, !status.connected,
2141
+ status.connectionState != .connected, status.connectionState != .connecting,
2142
+ status.connectionState != .bonding else { return nil }
2143
+ let services = ConnectedDeviceMatcher.serviceUUIDs(for: model).map { CBUUID(string: $0) }
2144
+ let saved = currentDefaultDevice()
2145
+ guard let device = BluetoothAvailability.shared.connectedPeripherals(withServices: services).first(where: {
2146
+ ConnectedDeviceMatcher.matches(model: model, defaultDevice: saved, name: $0.name, identifier: $0.identifier.uuidString)
2147
+ }) else { return nil }
2148
+ let name = device.name.flatMap { $0.isEmpty ? nil : $0 } ?? device.identifier.uuidString
2149
+ return ScanDiagnostic(
2150
+ code: "device_connected_on_phone",
2151
+ message: "Scan found no glasses, but a matching device \"\(name)\" is already connected to this phone. " +
2152
+ "If another app is using it, disconnect it there and scan again."
2153
+ )
2154
+ }
2155
+
2110
2156
  private func finishScanSession(_ id: UUID, reason: ScanStopReason, shouldStopScan: Bool) {
2111
2157
  guard let activeSession = activeScanSessions.removeValue(forKey: id) else { return }
2112
2158
  activeSession.timeoutTask?.cancel()
@@ -2114,6 +2160,11 @@ private func dispatchDiscoveredDevices(_ rawSearchResults: Any?) {
2114
2160
  if shouldStopScan {
2115
2161
  stopScan(reason: reason)
2116
2162
  }
2163
+ if reason == .completed, activeSession.latestResults.isEmpty,
2164
+ let onDiagnostic = activeSession.onDiagnostic, let diagnostic = scanDiagnostic(for: activeSession.model)
2165
+ {
2166
+ onDiagnostic(diagnostic)
2167
+ }
2117
2168
  activeSession.onComplete(activeSession.latestResults)
2118
2169
  }
2119
2170
 
@@ -0,0 +1,52 @@
1
+ import Foundation
2
+
3
+ /// Desired notification-centre controls. Submission does not imply firmware acknowledgement.
4
+ public struct NativeNotificationConfig: Equatable, Sendable {
5
+ public var enabled: Bool
6
+ public var autoDisplay: Bool
7
+ public var durationSeconds: Int
8
+ public var doNotDisturb: Bool
9
+ public var blockedApps: [String]
10
+
11
+ public init(enabled: Bool = false, autoDisplay: Bool = true, durationSeconds: Int = 5, doNotDisturb: Bool = false, blockedApps: [String] = []) {
12
+ self.enabled = enabled
13
+ self.autoDisplay = autoDisplay
14
+ self.durationSeconds = durationSeconds
15
+ self.doNotDisturb = doNotDisturb
16
+ self.blockedApps = blockedApps
17
+ }
18
+
19
+ func validate() throws {
20
+ guard (1 ... 30).contains(durationSeconds) else { throw NativeNotificationError.invalidDuration }
21
+ }
22
+
23
+ func validateForAncs() throws {
24
+ try validate()
25
+ guard blockedApps.isEmpty else { throw NativeNotificationError.unsupported }
26
+ }
27
+
28
+ var dictionary: [String: Any] {
29
+ ["enabled": enabled, "autoDisplay": autoDisplay, "durationSeconds": durationSeconds, "doNotDisturb": doNotDisturb, "blockedApps": blockedApps]
30
+ }
31
+ }
32
+
33
+ public enum NativeNotificationError: Error {
34
+ case unsupported
35
+ case notConnected
36
+ case invalidDuration
37
+ }
38
+
39
+ public struct NativeNotificationStatus: Sendable {
40
+ public let supported: Bool
41
+ public let source: String
42
+ public let authorization: String
43
+ public let state: String
44
+ public let config: NativeNotificationConfig
45
+ public let error: String
46
+
47
+ static let unavailable = NativeNotificationStatus(supported: false, source: "unsupported", authorization: "unknown", state: "unavailable", config: .init(), error: "")
48
+
49
+ var dictionary: [String: Any] {
50
+ ["supported": supported, "source": source, "authorization": authorization, "state": state, "config": config.dictionary, "error": error]
51
+ }
52
+ }
@@ -6,6 +6,17 @@ public enum ScanStopReason {
6
6
  case error
7
7
  }
8
8
 
9
+ /// A non-fatal explanation for an empty scan; it does not establish app ownership.
10
+ public struct ScanDiagnostic: Equatable {
11
+ public let code: String
12
+ public let message: String
13
+
14
+ public init(code: String, message: String) {
15
+ self.code = code
16
+ self.message = message
17
+ }
18
+ }
19
+
9
20
  @MainActor
10
21
  public final class ScanSession {
11
22
  private let stopAction: () -> Void
@@ -41,6 +41,13 @@ final class BluetoothAvailability: NSObject, CBCentralManagerDelegate {
41
41
  listeners[id] = nil
42
42
  }
43
43
 
44
+ /// Read-only system lookup. It neither connects nor claims ownership.
45
+ func connectedPeripherals(withServices services: [CBUUID]) -> [CBPeripheral] {
46
+ dispatchPrecondition(condition: .onQueue(.main))
47
+ guard let centralManager, centralManager.state == .poweredOn, !services.isEmpty else { return [] }
48
+ return centralManager.retrieveConnectedPeripherals(withServices: services)
49
+ }
50
+
44
51
  func requirePoweredOn(operation: String) throws {
45
52
  if let current = centralManager?.state {
46
53
  state = current
@@ -0,0 +1,45 @@
1
+ import Foundation
2
+
3
+ /// Model-level identity heuristic for system-connected peripherals, not app ownership.
4
+ enum ConnectedDeviceMatcher {
5
+ static func matches(model: DeviceModel, defaultDevice: Device?, name: String?, identifier: String?) -> Bool {
6
+ guard model != .simulated else { return false }
7
+ if let saved = defaultDevice, saved.model == model {
8
+ let savedID = saved.identifier.flatMap { $0.isEmpty ? nil : $0 }
9
+ let candidateID = identifier.flatMap { $0.isEmpty ? nil : $0 }
10
+ if let savedID, let candidateID {
11
+ if savedID.caseInsensitiveCompare(candidateID) == .orderedSame { return true }
12
+ } else if let name, !name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, name == saved.name {
13
+ return true
14
+ }
15
+ }
16
+ guard let name else { return false }
17
+ switch model {
18
+ case .mentraLive:
19
+ return name == "Xy_A" || name.hasPrefix("XyBLE_") || name.lowercased().hasPrefix("mentra_live")
20
+ case .mentraNex:
21
+ return name.hasPrefix("Nex1-") || name.hasPrefix("MENTRA_DISPLAY_")
22
+ default:
23
+ return false
24
+ }
25
+ }
26
+
27
+ /// Service IDs used by the corresponding SGCs. CoreBluetooth cannot enumerate
28
+ /// every system connection without service filters; unsupported models stay silent.
29
+ static func serviceUUIDs(for model: DeviceModel) -> [String] {
30
+ switch model {
31
+ case .mentraLive, .mentraNex:
32
+ return ["00004860-0000-1000-8000-00805F9B34FB"]
33
+ case .g1:
34
+ return ["6E400001-B5A3-F393-E0A9-E50E24DCCA9E"]
35
+ case .g2:
36
+ return ["00002760-08C2-11E1-9073-0E8AC72E0000"]
37
+ case .nimo:
38
+ return ["00007033-0000-1000-8000-00805F9B34FB"]
39
+ case .ar99:
40
+ return ["A72EC9A8-CF72-8544-AD96-D1481A02CE98"]
41
+ default:
42
+ return []
43
+ }
44
+ }
45
+ }