@mentra/engine 3.2.0-dev.235 → 3.2.0-dev.247

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 (44) hide show
  1. package/build/generated/releaseMetadata.js +5 -5
  2. package/build/generated/releaseMetadata.js.map +1 -1
  3. package/build/services/AcsMeetingService.d.ts +70 -0
  4. package/build/services/AcsMeetingService.d.ts.map +1 -1
  5. package/build/services/AcsMeetingService.js +97 -0
  6. package/build/services/AcsMeetingService.js.map +1 -1
  7. package/build/services/AppRegistry.d.ts +2 -12
  8. package/build/services/AppRegistry.d.ts.map +1 -1
  9. package/build/services/AppRegistry.js +2 -37
  10. package/build/services/AppRegistry.js.map +1 -1
  11. package/build/services/CloudClientService.d.ts +1 -1
  12. package/build/services/CloudClientService.d.ts.map +1 -1
  13. package/build/services/CloudClientService.js +2 -2
  14. package/build/services/CloudClientService.js.map +1 -1
  15. package/build/services/LocalMiniappRuntime.d.ts +51 -0
  16. package/build/services/LocalMiniappRuntime.d.ts.map +1 -1
  17. package/build/services/LocalMiniappRuntime.js +228 -6
  18. package/build/services/LocalMiniappRuntime.js.map +1 -1
  19. package/build/services/PhoneNotificationsSync.d.ts +1 -1
  20. package/build/services/PhonePhotoCoordinator.d.ts +3 -2
  21. package/build/services/PhonePhotoCoordinator.d.ts.map +1 -1
  22. package/build/services/PhonePhotoCoordinator.js +19 -14
  23. package/build/services/PhonePhotoCoordinator.js.map +1 -1
  24. package/build/services/SoftapCallTransport.d.ts +64 -0
  25. package/build/services/SoftapCallTransport.d.ts.map +1 -1
  26. package/build/services/SoftapCallTransport.js +103 -3
  27. package/build/services/SoftapCallTransport.js.map +1 -1
  28. package/build/services/manifestPermissions.d.ts +13 -0
  29. package/build/services/manifestPermissions.d.ts.map +1 -0
  30. package/build/services/manifestPermissions.js +42 -0
  31. package/build/services/manifestPermissions.js.map +1 -0
  32. package/build/types/applet.d.ts +13 -1
  33. package/build/types/applet.d.ts.map +1 -1
  34. package/build/types/applet.js.map +1 -1
  35. package/package.json +8 -8
  36. package/src/generated/releaseMetadata.ts +5 -5
  37. package/src/services/AcsMeetingService.ts +138 -0
  38. package/src/services/AppRegistry.ts +3 -40
  39. package/src/services/CloudClientService.ts +2 -2
  40. package/src/services/LocalMiniappRuntime.ts +268 -7
  41. package/src/services/PhonePhotoCoordinator.ts +18 -14
  42. package/src/services/SoftapCallTransport.ts +151 -16
  43. package/src/services/manifestPermissions.ts +44 -0
  44. package/src/types/applet.ts +11 -0
@@ -2,7 +2,7 @@ import type { PhoneNotificationEvent } from "@mentra/crust";
2
2
  export declare function nativeNotificationCapabilities(): {
3
3
  supported: boolean;
4
4
  source: "phone" | "ancs";
5
- contentAccess: "full" | "unsupported" | "app_identity";
5
+ contentAccess: "unsupported" | "full" | "app_identity";
6
6
  perAppFiltering: boolean;
7
7
  removal: boolean;
8
8
  };
@@ -17,6 +17,7 @@
17
17
  * short-circuit our long-poll with a typed error (CAMERA_BUSY, BATTERY_LOW,
18
18
  * etc.) instead of waiting 30s for cloud's timeout.
19
19
  */
20
+ import { type PhotoCompression } from "@mentra/cloud-protocol/photo-compression";
20
21
  import type { PhotoTransferMethod } from "@mentra/bluetooth-sdk/internal";
21
22
  export interface PhotoOpts {
22
23
  /** Legacy cloud size names are normalized before the native take_photo command. */
@@ -24,7 +25,7 @@ export interface PhotoOpts {
24
25
  mode?: "photo" | "text";
25
26
  /** Select direct-only, phone-relayed BLE, or the default Wi-Fi/BLE fallback policy. */
26
27
  transferMethod?: PhotoTransferMethod;
27
- compress?: "none" | "low" | "medium" | "high";
28
+ compress?: PhotoCompression;
28
29
  sound?: boolean;
29
30
  saveToGallery?: boolean;
30
31
  exposureTimeNs?: number;
@@ -68,7 +69,7 @@ export declare class PhotoError extends Error {
68
69
  */
69
70
  export declare const CAPTURE_PIPELINE_TIMEOUT_MS = 45000;
70
71
  export declare const CAMERA_WARM_UP_DEFAULT_DURATION_MS = 15000;
71
- export declare const CAMERA_WARM_UP_MAX_DURATION_MS = 60000;
72
+ export declare const CAMERA_WARM_UP_MAX_DURATION_MS = 300000;
72
73
  export declare class PhonePhotoCoordinator {
73
74
  private readonly activeRequests;
74
75
  /** Short BLE correlation id (4-char hex) → full cloud requestId. */
@@ -1 +1 @@
1
- {"version":3,"file":"PhonePhotoCoordinator.d.ts","sourceRoot":"","sources":["../../src/services/PhonePhotoCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAY,mBAAmB,EAAC,MAAM,gCAAgC,CAAA;AA0BlF,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;IACrE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACvB,uFAAuF;IACvF,cAAc,CAAC,EAAE,mBAAmB,CAAA;IACpC,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,0BAA0B;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EA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AAa,CAG3B;IAEH,sEAAsE;IACtE,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQ1C,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IAgL1E,iFAAiF;IACjF,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAInD;;;;;;OAMG;IACG,YAAY,CAChB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE;QACJ,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAA;QACxC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;QACvB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,GAAG,CAAC,EAAE,OAAO,CAAA;QACb,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,GACA,OAAO,CAAC,IAAI,CAAC;IA2ChB,8FAA8F;IACxF,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1D,4FAA4F;IAC5F,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAKhC;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAWlF,OAAO,CAAC,YAAY;CAMrB;AAGD,eAAO,MAAM,qBAAqB,uBAA8B,CAAA"}
@@ -17,6 +17,7 @@
17
17
  * short-circuit our long-poll with a typed error (CAMERA_BUSY, BATTERY_LOW,
18
18
  * etc.) instead of waiting 30s for cloud's timeout.
19
19
  */
20
+ import { parsePhotoCompression } from "@mentra/cloud-protocol/photo-compression";
20
21
  import BluetoothSdk from "@mentra/bluetooth-sdk/internal";
21
22
  import { cloudClientService } from "./CloudClientService";
22
23
  import { isGlassesConnected } from "./GlassesReadiness";
@@ -66,7 +67,7 @@ function parsePhotoTransferMethod(value) {
66
67
  */
67
68
  export const CAPTURE_PIPELINE_TIMEOUT_MS = 45_000;
68
69
  export const CAMERA_WARM_UP_DEFAULT_DURATION_MS = 15_000;
69
- export const CAMERA_WARM_UP_MAX_DURATION_MS = 60_000;
70
+ export const CAMERA_WARM_UP_MAX_DURATION_MS = 300_000;
70
71
  let bleRequestCounter = 0;
71
72
  /** Short 4-hex-char correlation id sent over BLE instead of the full cloud
72
73
  * requestId UUID (wire v2 keeps BLE JSON small). */
@@ -74,13 +75,6 @@ function mintBleRequestId() {
74
75
  bleRequestCounter = (bleRequestCounter + 1) & 0xffff;
75
76
  return bleRequestCounter.toString(16).padStart(4, "0");
76
77
  }
77
- function toNativeCompression(compress) {
78
- if (compress === "high")
79
- return "heavy";
80
- if (compress === "low" || compress === "medium")
81
- return "medium";
82
- return "none";
83
- }
84
78
  export class PhonePhotoCoordinator {
85
79
  // Cloud requestId → in-flight slot. The gated photo_response listener
86
80
  // (DeviceEventRouter) resolves short BLE ids via bleIdToCloud before calling
@@ -98,6 +92,7 @@ export class PhonePhotoCoordinator {
98
92
  };
99
93
  }
100
94
  async takePhoto(packageName, opts) {
95
+ const compress = parsePhotoCompression(opts.compress);
101
96
  const transferMethod = parsePhotoTransferMethod(opts.transferMethod);
102
97
  // Pre-check: if glasses aren't even connected, the BLE photo command
103
98
  // would be sent into the void and we'd wait 30s for the cloud long-poll
@@ -113,8 +108,8 @@ export class PhonePhotoCoordinator {
113
108
  if (!isGlassesConnected(useGlassesStore.getState().connection)) {
114
109
  throw new PhotoError("GLASSES_NOT_CONNECTED", "Glasses are not connected", "command", "ble");
115
110
  }
116
- // Text-mode sensor resolution is owned by ASG constants; keep cloud metadata on a stable
117
- // high-capacity tier and let the glasses ignore the public size when mode=text.
111
+ // Text-mode sensor resolution is owned by ASG constants; the glasses ignore the public
112
+ // size when mode=text.
118
113
  const captureSize = opts.size ?? "medium";
119
114
  // 1) Presign via the cloud-v2 managed-photo service. Local miniapps use
120
115
  // ONLY the cloud-v2 path: the runtime presigns upload+read URLs and the
@@ -126,9 +121,7 @@ export class PhonePhotoCoordinator {
126
121
  const flowStarted = performance.now();
127
122
  try {
128
123
  const presignStarted = performance.now();
129
- const r = await cloudClientService.startManagedPhoto({
130
- size: opts.mode === "text" ? "max" : captureSize,
131
- });
124
+ const r = await cloudClientService.startManagedPhoto();
132
125
  const presignMs = Math.round(performance.now() - presignStarted);
133
126
  if (typeof __DEV__ !== "undefined" && __DEV__) {
134
127
  console.debug(`[PhonePhotoCoordinator] presign ${presignMs}ms size=${opts.mode === "text" ? "max" : captureSize} mode=${opts.mode ?? "photo"}`);
@@ -186,7 +179,7 @@ export class PhonePhotoCoordinator {
186
179
  webhookUrl: uploadUrl,
187
180
  authToken: null,
188
181
  ...(isLoopbackUpload ? { transferMethod: "ble" } : transferMethod ? { transferMethod } : {}),
189
- compress: toNativeCompression(opts.compress),
182
+ compress,
190
183
  save: opts.saveToGallery ?? false,
191
184
  sound: opts.sound ?? true,
192
185
  exposureTimeNs: opts.exposureTimeNs ?? null,
@@ -199,6 +192,18 @@ export class PhonePhotoCoordinator {
199
192
  ...(opts.mfnr != null ? { mfnr: opts.mfnr } : {}),
200
193
  ispDigitalGain: opts.ispDigitalGain,
201
194
  ispAnalogGain: opts.ispAnalogGain,
195
+ }).then((response) => {
196
+ // Native success is emitted only after the direct/phone-relayed upload
197
+ // completes. It is an independent completion signal when photo.ready
198
+ // cannot reach this phone (for example, a cross-pod WS routing gap).
199
+ // Older native bridges may resolve at dispatch with no response: those
200
+ // must still wait for the cloud push, never return an unuploaded image.
201
+ if (response?.state !== "success" || response.requestId !== bleRequestId)
202
+ return;
203
+ const e = this.activeRequests.get(requestId);
204
+ if (!e || e.abort.signal.aborted)
205
+ return;
206
+ e.resolve({ photoUrl: readUrl, mimeType: "image/jpeg", size: -1 });
202
207
  }).catch((err) => {
203
208
  const e = this.activeRequests.get(requestId);
204
209
  if (!e)
@@ -1 +1 @@
1
- {"version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M,IAAI,GAAI,GAAuB,EAAE,IAAI,CAAA;QAC3C,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAChE,OAAO,IAAI,UAAU,CAAC,IAAI,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IACxE,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAA","sourcesContent":["/**\n * PhonePhotoCoordinator — owns local-miniapp takePhoto() end-to-end.\n *\n * Architecture:\n * miniapp → SDK → LocalMiniappRuntime → photo runtime hook\n * → coordinator.takePhoto(packageName, opts)\n * ├── (precheck) glasses connected + hasCamera\n * ├── cloudClientService.startManagedPhoto → {requestId, uploadUrl, readUrl} (cloud-v2 runtime presign)\n * ├── BluetoothSdk.requestPhoto(requestId, size, uploadUrl, compress, sound)\n * └── race:\n * - cloudClientService.awaitManagedPhotoReady(requestId) resolves on photo.ready push\n * - BluetoothSdk.requestPhoto rejects if terminal photo_response is an error\n * - handlePhotoError(requestId, code, message) rejects if MantleManager observes\n * the same BLE photo_response error before the native promise crosses the bridge\n *\n * `activeRequests` lets MantleManager's gated `photo_response` listener\n * short-circuit our long-poll with a typed error (CAMERA_BUSY, BATTERY_LOW,\n * etc.) instead of waiting 30s for cloud's timeout.\n */\n\nimport BluetoothSdk from \"@mentra/bluetooth-sdk/internal\"\nimport type {PhotoSize, PhotoTransferMethod} from \"@mentra/bluetooth-sdk/internal\"\nimport {cloudClientService} from \"./CloudClientService\"\nimport {isGlassesConnected} from \"./GlassesReadiness\"\nimport {useGlassesStore} from \"../stores/glasses\"\n\ninterface PhotoResult {\n photoUrl: string\n mimeType: string\n size: number\n}\n\n/** Map legacy/cloud size names onto the native take_photo enum. */\nfunction normalizePhotoSize(value: unknown): PhotoSize {\n if (typeof value !== \"string\") return \"medium\"\n switch (value) {\n case \"small\":\n return \"low\"\n case \"large\":\n return \"high\"\n case \"full\":\n return \"max\"\n default:\n return ([\"low\", \"medium\", \"high\", \"max\"] as const).includes(value as PhotoSize) ? (value as PhotoSize) : \"medium\"\n }\n}\n\nexport interface PhotoOpts {\n /** Legacy cloud size names are normalized before the native take_photo command. */\n size?: \"low\" | \"medium\" | \"high\" | \"max\" | \"small\" | \"large\" | \"full\"\n mode?: \"photo\" | \"text\"\n /** Select direct-only, phone-relayed BLE, or the default Wi-Fi/BLE fallback policy. */\n transferMethod?: PhotoTransferMethod\n compress?: \"none\" | \"low\" | \"medium\" | \"high\"\n sound?: boolean\n saveToGallery?: boolean\n exposureTimeNs?: number\n iso?: number | null\n aeExposureDivisor?: number\n isoCap?: number\n noiseReduction?: boolean\n edgeEnhancement?: boolean\n /** ZSL preview buffering. */\n zsl?: boolean\n /** MFNR still capture. */\n mfnr?: boolean\n ispDigitalGain?: number\n ispAnalogGain?: string\n}\n\nexport interface PhotoTaken {\n photoUrl: string\n mimeType: string\n size: number\n requestId: string\n}\n\n/** Pipeline stage a photo request failed at — surfaced to the miniapp so a dev\n * sees exactly where it broke, not just a flattened message. */\nexport type PhotoStage = \"presign\" | \"command\" | \"capture\" | \"upload\" | \"push\"\n/** Transport in play at the point of failure. */\nexport type PhotoTransport = \"cloud-rest\" | \"ble\" | \"wifi\" | \"ws\"\n\nexport class PhotoError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n public readonly stage?: PhotoStage,\n public readonly transport?: PhotoTransport,\n ) {\n super(message)\n this.name = \"PhotoError\"\n }\n}\n\nfunction parsePhotoTransferMethod(value: unknown): PhotoTransferMethod | undefined {\n if (value === undefined) return undefined\n if (value === \"auto\" || value === \"direct\" || value === \"ble\") return value\n throw new PhotoError(\n \"INVALID_ARGUMENT\",\n `Invalid transferMethod ${JSON.stringify(value)}. Expected \"auto\", \"direct\", or \"ble\".`,\n )\n}\n\ninterface ActiveRequest {\n packageName: string\n abort: AbortController\n resolve: (r: PhotoResult) => void\n reject: (err: Error) => void\n}\n\n/**\n * Last-resort ceiling for the complete capture + encode + transfer + upload\n * pipeline. This must exceed the managed-photo service's 30s ready-push\n * timeout so the cloud can return its more specific failure first.\n *\n * Text mode commonly spends several seconds detecting/cropping the region and\n * can take another 10s+ to transfer over BLE. A 15s ceiling incorrectly\n * rejected successful captures while their upload was still in progress.\n */\nexport const CAPTURE_PIPELINE_TIMEOUT_MS = 45_000\nexport const CAMERA_WARM_UP_DEFAULT_DURATION_MS = 15_000\nexport const CAMERA_WARM_UP_MAX_DURATION_MS = 60_000\n\nlet bleRequestCounter = 0\n\n/** Short 4-hex-char correlation id sent over BLE instead of the full cloud\n * requestId UUID (wire v2 keeps BLE JSON small). */\nfunction mintBleRequestId(): string {\n bleRequestCounter = (bleRequestCounter + 1) & 0xffff\n return bleRequestCounter.toString(16).padStart(4, \"0\")\n}\n\nfunction toNativeCompression(compress: PhotoOpts[\"compress\"]): \"none\" | \"medium\" | \"heavy\" {\n if (compress === \"high\") return \"heavy\"\n if (compress === \"low\" || compress === \"medium\") return \"medium\"\n return \"none\"\n}\n\nexport class PhonePhotoCoordinator {\n // Cloud requestId → in-flight slot. The gated photo_response listener\n // (DeviceEventRouter) resolves short BLE ids via bleIdToCloud before calling\n // owns() / handlePhotoError().\n private readonly activeRequests = new Map<string, ActiveRequest>()\n /** Short BLE correlation id (4-char hex) → full cloud requestId. */\n private readonly bleIdToCloud = new Map<string, string>()\n private readonly activeWarmUps = new Map<\n string,\n {requestId: string; durationMs: number; expiryTimer?: ReturnType<typeof setTimeout>}\n >()\n\n /** Report-safe camera ownership snapshot for incident diagnostics. */\n getDiagnosticSnapshot(): Record<string, unknown> {\n return {\n captureOwners: [...new Set([...this.activeRequests.values()].map((request) => request.packageName))].sort(),\n warmUpOwners: [...this.activeWarmUps.keys()].sort(),\n activeCaptureCount: this.activeRequests.size,\n }\n }\n\n async takePhoto(packageName: string, opts: PhotoOpts): Promise<PhotoTaken> {\n const transferMethod = parsePhotoTransferMethod(opts.transferMethod)\n\n // Pre-check: if glasses aren't even connected, the BLE photo command\n // would be sent into the void and we'd wait 30s for the cloud long-poll\n // to time out. Fail fast with a typed error.\n //\n // We DON'T pre-check `hasCamera` here — the canonical capability data\n // lives in `getModelCapabilities(deviceModel)` from @mentra/engine and\n // pulling that into this file would add a cross-package import. If a\n // cameraless device receives the BLE photo command, the glasses-side\n // handler will return a photo_response error within ~1s and the gated\n // photo_response listener in MantleManager will short-circuit our\n // long-poll. Slower but correct.\n if (!isGlassesConnected(useGlassesStore.getState().connection)) {\n throw new PhotoError(\"GLASSES_NOT_CONNECTED\", \"Glasses are not connected\", \"command\", \"ble\")\n }\n\n // Text-mode sensor resolution is owned by ASG constants; keep cloud metadata on a stable\n // high-capacity tier and let the glasses ignore the public size when mode=text.\n const captureSize = opts.size ?? \"medium\"\n\n // 1) Presign via the cloud-v2 managed-photo service. Local miniapps use\n // ONLY the cloud-v2 path: the runtime presigns upload+read URLs and the\n // phone (as the device controller) delivers the bytes; the legacy\n // backend_url mint is gone from this flow.\n let requestId: string\n let uploadUrl: string\n let readUrl: string\n const flowStarted = performance.now()\n try {\n const presignStarted = performance.now()\n const r = await cloudClientService.startManagedPhoto({\n size: opts.mode === \"text\" ? \"max\" : captureSize,\n })\n const presignMs = Math.round(performance.now() - presignStarted)\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.debug(\n `[PhonePhotoCoordinator] presign ${presignMs}ms size=${opts.mode === \"text\" ? \"max\" : captureSize} mode=${\n opts.mode ?? \"photo\"\n }`,\n )\n }\n requestId = r.requestId\n uploadUrl = r.uploadUrl\n readUrl = r.readUrl\n } catch (err) {\n throw this.toPhotoError(err, \"PHOTO_REQUEST_FAILED\", \"presign\", \"cloud-rest\")\n }\n\n // 2) Build the outcome Promise FIRST so both resolve+reject handles\n // are wired into activeRequests BEFORE any code path can produce\n // an error. Without this, a fast BLE photo_response (BATTERY_LOW\n // etc.) racing with the Promise constructor could fire\n // handlePhotoError() against a no-op rejectFn and silently drop\n // the error.\n // When the managed-photo upload URL is loopback (the local storage provider\n // reached over `adb reverse`), the glasses cannot reach it over WiFi —\n // localhost on the glasses is the glasses. Force BLE transfer so the phone\n // (which CAN reach the reversed runtime) relays the bytes; a public r2/s3\n // presigned URL stays on \"auto\".\n const isLoopbackUpload = /^https?:\\/\\/(localhost|127\\.0\\.0\\.1|10\\.0\\.2\\.2)\\b/.test(uploadUrl)\n\n const abort = new AbortController()\n const bleRequestId = mintBleRequestId()\n this.bleIdToCloud.set(bleRequestId, requestId)\n\n const outcome = new Promise<PhotoResult>((resolve, reject) => {\n this.activeRequests.set(requestId, {packageName, abort, resolve, reject})\n })\n\n // Last-resort watchdog for a wedged pipeline. The managed-photo ready push\n // normally resolves or rejects first; this only prevents an indefinite hang\n // if both the native terminal response and cloud push disappear.\n const captureWatchdog = setTimeout(() => {\n const e = this.activeRequests.get(requestId)\n if (!e) return\n e.abort.abort()\n e.reject(\n new PhotoError(\n \"CAPTURE_TIMEOUT\",\n \"Photo capture did not complete. The take_photo command, media processing, transfer, or upload may have stalled.\",\n \"capture\",\n isLoopbackUpload ? \"ble\" : \"wifi\",\n ),\n )\n }, CAPTURE_PIPELINE_TIMEOUT_MS)\n // Clear the watchdog on BOTH arms. Not `.finally()`: that would mint a new\n // promise that re-rejects unobserved whenever the photo fails (the caller\n // only awaits `outcome` itself), i.e. an unhandled rejection per failure.\n const clearWatchdog = () => clearTimeout(captureWatchdog)\n void outcome.then(clearWatchdog, clearWatchdog)\n\n // 3) Drive glasses over BLE. requestPhoto now resolves at terminal\n // photo_response success, so run it beside the cloud poll instead of\n // awaiting it before polling. Native defaults transferMethod to \"auto\"\n // (Wi-Fi direct with BLE fallback) unless the miniapp forces BLE.\n try {\n void BluetoothSdk.requestPhoto({\n requestId: bleRequestId,\n appId: packageName,\n size: normalizePhotoSize(captureSize),\n mode: opts.mode ?? \"photo\",\n webhookUrl: uploadUrl,\n authToken: null,\n ...(isLoopbackUpload ? {transferMethod: \"ble\" as const} : transferMethod ? {transferMethod} : {}),\n compress: toNativeCompression(opts.compress),\n save: opts.saveToGallery ?? false,\n sound: opts.sound ?? true,\n exposureTimeNs: opts.exposureTimeNs ?? null,\n iso: opts.iso,\n aeExposureDivisor: opts.aeExposureDivisor,\n isoCap: opts.isoCap,\n noiseReduction: opts.noiseReduction,\n edgeEnhancement: opts.edgeEnhancement,\n ...(opts.zsl != null ? {zsl: opts.zsl} : {}),\n ...(opts.mfnr != null ? {mfnr: opts.mfnr} : {}),\n ispDigitalGain: opts.ispDigitalGain,\n ispAnalogGain: opts.ispAnalogGain,\n }).catch((err) => {\n const e = this.activeRequests.get(requestId)\n if (!e) return\n e.abort.abort()\n e.reject(this.toPhotoError(err, \"BLE_SEND_FAILED\", \"command\", \"ble\"))\n })\n } catch (err) {\n this.activeRequests.delete(requestId)\n this.bleIdToCloud.delete(bleRequestId)\n throw this.toPhotoError(err, \"BLE_SEND_FAILED\", \"command\", \"ble\")\n }\n\n // 4) Await the runtime's photo.ready push (replaces the legacy long-poll).\n // handlePhotoError races against it and uses the same entry to reject\n // first.\n cloudClientService\n .awaitManagedPhotoReady(requestId)\n .then((res) => {\n const e = this.activeRequests.get(requestId)\n if (!e) return // already settled by handlePhotoError\n e.resolve({photoUrl: res.readUrl ?? readUrl, mimeType: \"image/jpeg\", size: -1})\n })\n .catch((err) => {\n const e = this.activeRequests.get(requestId)\n if (e) e.reject(this.toPhotoError(err, \"POLL_FAILED\", \"push\", \"ws\"))\n })\n\n try {\n const result = await outcome\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.debug(\n `[PhonePhotoCoordinator] takePhoto complete ${Math.round(\n performance.now() - flowStarted,\n )}ms requestId=${requestId}`,\n )\n }\n return {\n photoUrl: result.photoUrl,\n mimeType: result.mimeType,\n size: result.size,\n requestId,\n }\n } finally {\n this.activeRequests.delete(requestId)\n this.bleIdToCloud.delete(bleRequestId)\n }\n }\n\n /** Map a short BLE requestId from photo_response back to the cloud requestId. */\n resolveCloudRequestId(bleOrCloudId: string): string {\n return this.bleIdToCloud.get(bleOrCloudId) ?? bleOrCloudId\n }\n\n /**\n * Pre-warm the glasses camera so the next takePhoto() is near-instant.\n *\n * Pure BLE — NO cloud presign, NO upload, NO long-poll. The phone mints and owns\n * the requestId, sends the warm-up command, and resolves when the camera reports\n * ready (the native promise resolves on the ready status event).\n */\n async warmUpCamera(\n packageName: string,\n opts: {\n size?: \"low\" | \"medium\" | \"high\" | \"max\"\n mode?: \"photo\" | \"text\"\n exposureTimeNs?: number\n durationMs?: number\n zsl?: boolean\n mfnr?: boolean\n },\n ): Promise<void> {\n // Pre-check: if glasses aren't connected, the BLE warm-up command would be\n // sent into the void. Fail fast with a typed error.\n if (!isGlassesConnected(useGlassesStore.getState().connection)) {\n throw new PhotoError(\"GLASSES_NOT_CONNECTED\", \"Glasses are not connected\", \"command\", \"ble\")\n }\n\n let lease: {requestId: string; durationMs: number; expiryTimer?: ReturnType<typeof setTimeout>} | undefined\n try {\n await this.stopWarmUpForApp(packageName)\n const requestId = mintBleRequestId()\n const requestedDuration =\n typeof opts.durationMs === \"number\" && Number.isFinite(opts.durationMs) && opts.durationMs > 0\n ? Math.round(opts.durationMs)\n : CAMERA_WARM_UP_DEFAULT_DURATION_MS\n const durationMs = Math.min(requestedDuration, CAMERA_WARM_UP_MAX_DURATION_MS)\n lease = {requestId, durationMs}\n this.activeWarmUps.set(packageName, lease)\n await BluetoothSdk.warmUpCamera({\n requestId,\n size: normalizePhotoSize(opts.size ?? \"medium\"),\n mode: opts.mode ?? \"photo\",\n exposureTimeNs: opts.exposureTimeNs ?? null,\n durationMs,\n ...(opts.zsl != null ? {zsl: opts.zsl} : {}),\n ...(opts.mfnr != null ? {mfnr: opts.mfnr} : {}),\n })\n if (this.activeWarmUps.get(packageName) === lease) {\n lease.expiryTimer = setTimeout(() => {\n if (this.activeWarmUps.get(packageName) === lease) {\n this.activeWarmUps.delete(packageName)\n }\n }, durationMs)\n }\n } catch (err) {\n if (lease && this.activeWarmUps.get(packageName) === lease) {\n if (lease.expiryTimer) clearTimeout(lease.expiryTimer)\n this.activeWarmUps.delete(packageName)\n }\n throw this.toPhotoError(err, \"WARM_UP_FAILED\", \"command\", \"ble\")\n }\n }\n\n /** Release a miniapp's warm-up even if its original warmUpCamera promise is still opening. */\n async stopWarmUpForApp(packageName: string): Promise<void> {\n const active = this.activeWarmUps.get(packageName)\n if (!active) return\n await BluetoothSdk.stopCameraWarmUp(active.requestId)\n if (this.activeWarmUps.get(packageName) === active) {\n this.activeWarmUps.delete(packageName)\n if (active.expiryTimer) clearTimeout(active.expiryTimer)\n }\n }\n\n /** True iff this requestId (short BLE id or cloud id) is one we're currently waiting on. */\n owns(requestId: string): boolean {\n const cloudId = this.resolveCloudRequestId(requestId)\n return this.activeRequests.has(cloudId)\n }\n\n /**\n * Called by MantleManager's gated photo_response listener when glasses\n * report an error (BATTERY_LOW, CAMERA_BUSY, etc.) for a phone-owned\n * requestId. Rejects the in-flight takePhoto Promise immediately.\n */\n handlePhotoError(requestId: string, errorCode: string, errorMessage: string): void {\n const cloudId = this.resolveCloudRequestId(requestId)\n const entry = this.activeRequests.get(cloudId)\n if (!entry) return\n this.bleIdToCloud.delete(requestId)\n // Abort the in-flight long-poll first so we don't double-resolve.\n entry.abort.abort()\n entry.reject(new PhotoError(errorCode || \"GLASSES_ERROR\", errorMessage || \"Glasses error\", \"capture\", \"ble\"))\n // cloud-v2 pending photo requests TTL out on their own; nothing to free.\n }\n\n private toPhotoError(err: unknown, fallbackCode: string, stage?: PhotoStage, transport?: PhotoTransport): PhotoError {\n if (err instanceof PhotoError) return err\n const code = (err as {code?: string})?.code\n const message = err instanceof Error ? err.message : String(err)\n return new PhotoError(code || fallbackCode, message, stage, transport)\n }\n}\n\n// Singleton — coordinator state is process-wide (mirrors phoneStreamCoordinator).\nexport const phonePhotoCoordinator = new PhonePhotoCoordinator()\n"]}
1
+ {"version":3,"file":"PhonePhotoCoordinator.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AM,CAAC,IAAI,UAAU,CAAC,SAAS,IAAI,eAAe,EAAE,YAAY,IAAI,eAAe,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;QAC7G,yEAAyE;IAC3E,CAAC;IAEO,YAAY,CAAC,GAAY,EAAE,YAAoB,EAAE,KAAkB,EAAE,SAA0B;QACrG,IAAI,GAAG,YAAY,UAAU;YAAE,OAAO,GAAG,CAAA;QACzC,MAAM,IAAI,GAAI,GAAuB,EAAE,IAAI,CAAA;QAC3C,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAChE,OAAO,IAAI,UAAU,CAAC,IAAI,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IACxE,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAA","sourcesContent":["/**\n * PhonePhotoCoordinator — owns local-miniapp takePhoto() end-to-end.\n *\n * Architecture:\n * miniapp → SDK → LocalMiniappRuntime → photo runtime hook\n * → coordinator.takePhoto(packageName, opts)\n * ├── (precheck) glasses connected + hasCamera\n * ├── cloudClientService.startManagedPhoto → {requestId, uploadUrl, readUrl} (cloud-v2 runtime presign)\n * ├── BluetoothSdk.requestPhoto(requestId, size, uploadUrl, compress, sound)\n * └── race:\n * - cloudClientService.awaitManagedPhotoReady(requestId) resolves on photo.ready push\n * - BluetoothSdk.requestPhoto rejects if terminal photo_response is an error\n * - handlePhotoError(requestId, code, message) rejects if MantleManager observes\n * the same BLE photo_response error before the native promise crosses the bridge\n *\n * `activeRequests` lets MantleManager's gated `photo_response` listener\n * short-circuit our long-poll with a typed error (CAMERA_BUSY, BATTERY_LOW,\n * etc.) instead of waiting 30s for cloud's timeout.\n */\n\nimport {parsePhotoCompression, type PhotoCompression} from \"@mentra/cloud-protocol/photo-compression\"\nimport BluetoothSdk from \"@mentra/bluetooth-sdk/internal\"\nimport type {PhotoSize, PhotoTransferMethod} from \"@mentra/bluetooth-sdk/internal\"\nimport {cloudClientService} from \"./CloudClientService\"\nimport {isGlassesConnected} from \"./GlassesReadiness\"\nimport {useGlassesStore} from \"../stores/glasses\"\n\ninterface PhotoResult {\n photoUrl: string\n mimeType: string\n size: number\n}\n\n/** Map legacy/cloud size names onto the native take_photo enum. */\nfunction normalizePhotoSize(value: unknown): PhotoSize {\n if (typeof value !== \"string\") return \"medium\"\n switch (value) {\n case \"small\":\n return \"low\"\n case \"large\":\n return \"high\"\n case \"full\":\n return \"max\"\n default:\n return ([\"low\", \"medium\", \"high\", \"max\"] as const).includes(value as PhotoSize) ? (value as PhotoSize) : \"medium\"\n }\n}\n\nexport interface PhotoOpts {\n /** Legacy cloud size names are normalized before the native take_photo command. */\n size?: \"low\" | \"medium\" | \"high\" | \"max\" | \"small\" | \"large\" | \"full\"\n mode?: \"photo\" | \"text\"\n /** Select direct-only, phone-relayed BLE, or the default Wi-Fi/BLE fallback policy. */\n transferMethod?: PhotoTransferMethod\n compress?: PhotoCompression\n sound?: boolean\n saveToGallery?: boolean\n exposureTimeNs?: number\n iso?: number | null\n aeExposureDivisor?: number\n isoCap?: number\n noiseReduction?: boolean\n edgeEnhancement?: boolean\n /** ZSL preview buffering. */\n zsl?: boolean\n /** MFNR still capture. */\n mfnr?: boolean\n ispDigitalGain?: number\n ispAnalogGain?: string\n}\n\nexport interface PhotoTaken {\n photoUrl: string\n mimeType: string\n size: number\n requestId: string\n}\n\n/** Pipeline stage a photo request failed at — surfaced to the miniapp so a dev\n * sees exactly where it broke, not just a flattened message. */\nexport type PhotoStage = \"presign\" | \"command\" | \"capture\" | \"upload\" | \"push\"\n/** Transport in play at the point of failure. */\nexport type PhotoTransport = \"cloud-rest\" | \"ble\" | \"wifi\" | \"ws\"\n\nexport class PhotoError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n public readonly stage?: PhotoStage,\n public readonly transport?: PhotoTransport,\n ) {\n super(message)\n this.name = \"PhotoError\"\n }\n}\n\nfunction parsePhotoTransferMethod(value: unknown): PhotoTransferMethod | undefined {\n if (value === undefined) return undefined\n if (value === \"auto\" || value === \"direct\" || value === \"ble\") return value\n throw new PhotoError(\n \"INVALID_ARGUMENT\",\n `Invalid transferMethod ${JSON.stringify(value)}. Expected \"auto\", \"direct\", or \"ble\".`,\n )\n}\n\ninterface ActiveRequest {\n packageName: string\n abort: AbortController\n resolve: (r: PhotoResult) => void\n reject: (err: Error) => void\n}\n\n/**\n * Last-resort ceiling for the complete capture + encode + transfer + upload\n * pipeline. This must exceed the managed-photo service's 30s ready-push\n * timeout so the cloud can return its more specific failure first.\n *\n * Text mode commonly spends several seconds detecting/cropping the region and\n * can take another 10s+ to transfer over BLE. A 15s ceiling incorrectly\n * rejected successful captures while their upload was still in progress.\n */\nexport const CAPTURE_PIPELINE_TIMEOUT_MS = 45_000\nexport const CAMERA_WARM_UP_DEFAULT_DURATION_MS = 15_000\nexport const CAMERA_WARM_UP_MAX_DURATION_MS = 300_000\n\nlet bleRequestCounter = 0\n\n/** Short 4-hex-char correlation id sent over BLE instead of the full cloud\n * requestId UUID (wire v2 keeps BLE JSON small). */\nfunction mintBleRequestId(): string {\n bleRequestCounter = (bleRequestCounter + 1) & 0xffff\n return bleRequestCounter.toString(16).padStart(4, \"0\")\n}\n\nexport class PhonePhotoCoordinator {\n // Cloud requestId → in-flight slot. The gated photo_response listener\n // (DeviceEventRouter) resolves short BLE ids via bleIdToCloud before calling\n // owns() / handlePhotoError().\n private readonly activeRequests = new Map<string, ActiveRequest>()\n /** Short BLE correlation id (4-char hex) → full cloud requestId. */\n private readonly bleIdToCloud = new Map<string, string>()\n private readonly activeWarmUps = new Map<\n string,\n {requestId: string; durationMs: number; expiryTimer?: ReturnType<typeof setTimeout>}\n >()\n\n /** Report-safe camera ownership snapshot for incident diagnostics. */\n getDiagnosticSnapshot(): Record<string, unknown> {\n return {\n captureOwners: [...new Set([...this.activeRequests.values()].map((request) => request.packageName))].sort(),\n warmUpOwners: [...this.activeWarmUps.keys()].sort(),\n activeCaptureCount: this.activeRequests.size,\n }\n }\n\n async takePhoto(packageName: string, opts: PhotoOpts): Promise<PhotoTaken> {\n const compress = parsePhotoCompression(opts.compress)\n const transferMethod = parsePhotoTransferMethod(opts.transferMethod)\n\n // Pre-check: if glasses aren't even connected, the BLE photo command\n // would be sent into the void and we'd wait 30s for the cloud long-poll\n // to time out. Fail fast with a typed error.\n //\n // We DON'T pre-check `hasCamera` here — the canonical capability data\n // lives in `getModelCapabilities(deviceModel)` from @mentra/engine and\n // pulling that into this file would add a cross-package import. If a\n // cameraless device receives the BLE photo command, the glasses-side\n // handler will return a photo_response error within ~1s and the gated\n // photo_response listener in MantleManager will short-circuit our\n // long-poll. Slower but correct.\n if (!isGlassesConnected(useGlassesStore.getState().connection)) {\n throw new PhotoError(\"GLASSES_NOT_CONNECTED\", \"Glasses are not connected\", \"command\", \"ble\")\n }\n\n // Text-mode sensor resolution is owned by ASG constants; the glasses ignore the public\n // size when mode=text.\n const captureSize = opts.size ?? \"medium\"\n\n // 1) Presign via the cloud-v2 managed-photo service. Local miniapps use\n // ONLY the cloud-v2 path: the runtime presigns upload+read URLs and the\n // phone (as the device controller) delivers the bytes; the legacy\n // backend_url mint is gone from this flow.\n let requestId: string\n let uploadUrl: string\n let readUrl: string\n const flowStarted = performance.now()\n try {\n const presignStarted = performance.now()\n const r = await cloudClientService.startManagedPhoto()\n const presignMs = Math.round(performance.now() - presignStarted)\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.debug(\n `[PhonePhotoCoordinator] presign ${presignMs}ms size=${opts.mode === \"text\" ? \"max\" : captureSize} mode=${\n opts.mode ?? \"photo\"\n }`,\n )\n }\n requestId = r.requestId\n uploadUrl = r.uploadUrl\n readUrl = r.readUrl\n } catch (err) {\n throw this.toPhotoError(err, \"PHOTO_REQUEST_FAILED\", \"presign\", \"cloud-rest\")\n }\n\n // 2) Build the outcome Promise FIRST so both resolve+reject handles\n // are wired into activeRequests BEFORE any code path can produce\n // an error. Without this, a fast BLE photo_response (BATTERY_LOW\n // etc.) racing with the Promise constructor could fire\n // handlePhotoError() against a no-op rejectFn and silently drop\n // the error.\n // When the managed-photo upload URL is loopback (the local storage provider\n // reached over `adb reverse`), the glasses cannot reach it over WiFi —\n // localhost on the glasses is the glasses. Force BLE transfer so the phone\n // (which CAN reach the reversed runtime) relays the bytes; a public r2/s3\n // presigned URL stays on \"auto\".\n const isLoopbackUpload = /^https?:\\/\\/(localhost|127\\.0\\.0\\.1|10\\.0\\.2\\.2)\\b/.test(uploadUrl)\n\n const abort = new AbortController()\n const bleRequestId = mintBleRequestId()\n this.bleIdToCloud.set(bleRequestId, requestId)\n\n const outcome = new Promise<PhotoResult>((resolve, reject) => {\n this.activeRequests.set(requestId, {packageName, abort, resolve, reject})\n })\n\n // Last-resort watchdog for a wedged pipeline. The managed-photo ready push\n // normally resolves or rejects first; this only prevents an indefinite hang\n // if both the native terminal response and cloud push disappear.\n const captureWatchdog = setTimeout(() => {\n const e = this.activeRequests.get(requestId)\n if (!e) return\n e.abort.abort()\n e.reject(\n new PhotoError(\n \"CAPTURE_TIMEOUT\",\n \"Photo capture did not complete. The take_photo command, media processing, transfer, or upload may have stalled.\",\n \"capture\",\n isLoopbackUpload ? \"ble\" : \"wifi\",\n ),\n )\n }, CAPTURE_PIPELINE_TIMEOUT_MS)\n // Clear the watchdog on BOTH arms. Not `.finally()`: that would mint a new\n // promise that re-rejects unobserved whenever the photo fails (the caller\n // only awaits `outcome` itself), i.e. an unhandled rejection per failure.\n const clearWatchdog = () => clearTimeout(captureWatchdog)\n void outcome.then(clearWatchdog, clearWatchdog)\n\n // 3) Drive glasses over BLE. requestPhoto now resolves at terminal\n // photo_response success, so run it beside the cloud poll instead of\n // awaiting it before polling. Native defaults transferMethod to \"auto\"\n // (Wi-Fi direct with BLE fallback) unless the miniapp forces BLE.\n try {\n void BluetoothSdk.requestPhoto({\n requestId: bleRequestId,\n appId: packageName,\n size: normalizePhotoSize(captureSize),\n mode: opts.mode ?? \"photo\",\n webhookUrl: uploadUrl,\n authToken: null,\n ...(isLoopbackUpload ? {transferMethod: \"ble\" as const} : transferMethod ? {transferMethod} : {}),\n compress,\n save: opts.saveToGallery ?? false,\n sound: opts.sound ?? true,\n exposureTimeNs: opts.exposureTimeNs ?? null,\n iso: opts.iso,\n aeExposureDivisor: opts.aeExposureDivisor,\n isoCap: opts.isoCap,\n noiseReduction: opts.noiseReduction,\n edgeEnhancement: opts.edgeEnhancement,\n ...(opts.zsl != null ? {zsl: opts.zsl} : {}),\n ...(opts.mfnr != null ? {mfnr: opts.mfnr} : {}),\n ispDigitalGain: opts.ispDigitalGain,\n ispAnalogGain: opts.ispAnalogGain,\n }).then((response) => {\n // Native success is emitted only after the direct/phone-relayed upload\n // completes. It is an independent completion signal when photo.ready\n // cannot reach this phone (for example, a cross-pod WS routing gap).\n // Older native bridges may resolve at dispatch with no response: those\n // must still wait for the cloud push, never return an unuploaded image.\n if (response?.state !== \"success\" || response.requestId !== bleRequestId) return\n const e = this.activeRequests.get(requestId)\n if (!e || e.abort.signal.aborted) return\n e.resolve({photoUrl: readUrl, mimeType: \"image/jpeg\", size: -1})\n }).catch((err) => {\n const e = this.activeRequests.get(requestId)\n if (!e) return\n e.abort.abort()\n e.reject(this.toPhotoError(err, \"BLE_SEND_FAILED\", \"command\", \"ble\"))\n })\n } catch (err) {\n this.activeRequests.delete(requestId)\n this.bleIdToCloud.delete(bleRequestId)\n throw this.toPhotoError(err, \"BLE_SEND_FAILED\", \"command\", \"ble\")\n }\n\n // 4) Await the runtime's photo.ready push (replaces the legacy long-poll).\n // handlePhotoError races against it and uses the same entry to reject\n // first.\n cloudClientService\n .awaitManagedPhotoReady(requestId)\n .then((res) => {\n const e = this.activeRequests.get(requestId)\n if (!e) return // already settled by handlePhotoError\n e.resolve({photoUrl: res.readUrl ?? readUrl, mimeType: \"image/jpeg\", size: -1})\n })\n .catch((err) => {\n const e = this.activeRequests.get(requestId)\n if (e) e.reject(this.toPhotoError(err, \"POLL_FAILED\", \"push\", \"ws\"))\n })\n\n try {\n const result = await outcome\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.debug(\n `[PhonePhotoCoordinator] takePhoto complete ${Math.round(\n performance.now() - flowStarted,\n )}ms requestId=${requestId}`,\n )\n }\n return {\n photoUrl: result.photoUrl,\n mimeType: result.mimeType,\n size: result.size,\n requestId,\n }\n } finally {\n this.activeRequests.delete(requestId)\n this.bleIdToCloud.delete(bleRequestId)\n }\n }\n\n /** Map a short BLE requestId from photo_response back to the cloud requestId. */\n resolveCloudRequestId(bleOrCloudId: string): string {\n return this.bleIdToCloud.get(bleOrCloudId) ?? bleOrCloudId\n }\n\n /**\n * Pre-warm the glasses camera so the next takePhoto() is near-instant.\n *\n * Pure BLE — NO cloud presign, NO upload, NO long-poll. The phone mints and owns\n * the requestId, sends the warm-up command, and resolves when the camera reports\n * ready (the native promise resolves on the ready status event).\n */\n async warmUpCamera(\n packageName: string,\n opts: {\n size?: \"low\" | \"medium\" | \"high\" | \"max\"\n mode?: \"photo\" | \"text\"\n exposureTimeNs?: number\n durationMs?: number\n zsl?: boolean\n mfnr?: boolean\n },\n ): Promise<void> {\n // Pre-check: if glasses aren't connected, the BLE warm-up command would be\n // sent into the void. Fail fast with a typed error.\n if (!isGlassesConnected(useGlassesStore.getState().connection)) {\n throw new PhotoError(\"GLASSES_NOT_CONNECTED\", \"Glasses are not connected\", \"command\", \"ble\")\n }\n\n let lease: {requestId: string; durationMs: number; expiryTimer?: ReturnType<typeof setTimeout>} | undefined\n try {\n await this.stopWarmUpForApp(packageName)\n const requestId = mintBleRequestId()\n const requestedDuration =\n typeof opts.durationMs === \"number\" && Number.isFinite(opts.durationMs) && opts.durationMs > 0\n ? Math.round(opts.durationMs)\n : CAMERA_WARM_UP_DEFAULT_DURATION_MS\n const durationMs = Math.min(requestedDuration, CAMERA_WARM_UP_MAX_DURATION_MS)\n lease = {requestId, durationMs}\n this.activeWarmUps.set(packageName, lease)\n await BluetoothSdk.warmUpCamera({\n requestId,\n size: normalizePhotoSize(opts.size ?? \"medium\"),\n mode: opts.mode ?? \"photo\",\n exposureTimeNs: opts.exposureTimeNs ?? null,\n durationMs,\n ...(opts.zsl != null ? {zsl: opts.zsl} : {}),\n ...(opts.mfnr != null ? {mfnr: opts.mfnr} : {}),\n })\n if (this.activeWarmUps.get(packageName) === lease) {\n lease.expiryTimer = setTimeout(() => {\n if (this.activeWarmUps.get(packageName) === lease) {\n this.activeWarmUps.delete(packageName)\n }\n }, durationMs)\n }\n } catch (err) {\n if (lease && this.activeWarmUps.get(packageName) === lease) {\n if (lease.expiryTimer) clearTimeout(lease.expiryTimer)\n this.activeWarmUps.delete(packageName)\n }\n throw this.toPhotoError(err, \"WARM_UP_FAILED\", \"command\", \"ble\")\n }\n }\n\n /** Release a miniapp's warm-up even if its original warmUpCamera promise is still opening. */\n async stopWarmUpForApp(packageName: string): Promise<void> {\n const active = this.activeWarmUps.get(packageName)\n if (!active) return\n await BluetoothSdk.stopCameraWarmUp(active.requestId)\n if (this.activeWarmUps.get(packageName) === active) {\n this.activeWarmUps.delete(packageName)\n if (active.expiryTimer) clearTimeout(active.expiryTimer)\n }\n }\n\n /** True iff this requestId (short BLE id or cloud id) is one we're currently waiting on. */\n owns(requestId: string): boolean {\n const cloudId = this.resolveCloudRequestId(requestId)\n return this.activeRequests.has(cloudId)\n }\n\n /**\n * Called by MantleManager's gated photo_response listener when glasses\n * report an error (BATTERY_LOW, CAMERA_BUSY, etc.) for a phone-owned\n * requestId. Rejects the in-flight takePhoto Promise immediately.\n */\n handlePhotoError(requestId: string, errorCode: string, errorMessage: string): void {\n const cloudId = this.resolveCloudRequestId(requestId)\n const entry = this.activeRequests.get(cloudId)\n if (!entry) return\n this.bleIdToCloud.delete(requestId)\n // Abort the in-flight long-poll first so we don't double-resolve.\n entry.abort.abort()\n entry.reject(new PhotoError(errorCode || \"GLASSES_ERROR\", errorMessage || \"Glasses error\", \"capture\", \"ble\"))\n // cloud-v2 pending photo requests TTL out on their own; nothing to free.\n }\n\n private toPhotoError(err: unknown, fallbackCode: string, stage?: PhotoStage, transport?: PhotoTransport): PhotoError {\n if (err instanceof PhotoError) return err\n const code = (err as {code?: string})?.code\n const message = err instanceof Error ? err.message : String(err)\n return new PhotoError(code || fallbackCode, message, stage, transport)\n }\n}\n\n// Singleton — coordinator state is process-wide (mirrors phoneStreamCoordinator).\nexport const phonePhotoCoordinator = new PhonePhotoCoordinator()\n"]}
@@ -38,6 +38,35 @@ export declare class SoftapCallError extends Error {
38
38
  }
39
39
  /** Gallery sync already learned this: glasses report enabled before the SSID is in the phone scan. */
40
40
  export declare const HOTSPOT_BROADCAST_WAIT_MS = 3000;
41
+ /**
42
+ * What the glasses→phone hop is worth at 540p over a hotspot with one client and no contention.
43
+ *
44
+ * Not the ACS ceiling: this link is a metre of air between two devices that are already paired,
45
+ * and the profile's `maxBitrateBps` describes the phone→Teams hop, which crosses the internet.
46
+ * Sharing one number between them makes the easy hop obey the hard hop's limits.
47
+ */
48
+ export declare const GLASSES_PHONE_BITRATE_BPS = 2500000;
49
+ /** Field names are the glasses' `WhipStreamConfig` parser's, where `bitrate` means the maximum. */
50
+ export interface SoftapVideoPolicy {
51
+ width: number;
52
+ height: number;
53
+ fps: number;
54
+ bitrate: number;
55
+ initialBitrateBps: number;
56
+ minBitrateBps: number;
57
+ }
58
+ /**
59
+ * The bitrate the glasses are told to hold on the hop to the phone.
60
+ *
61
+ * The hotspot has its own bitrate budget, independent of the phone-to-Teams cap. Above 540p,
62
+ * allow a higher requested ceiling while retaining the hotspot budget for low WAN caps.
63
+ */
64
+ export declare function softapVideoPolicy(video: {
65
+ width: number;
66
+ height: number;
67
+ fps: number;
68
+ maxBitrateBps: number;
69
+ }): SoftapVideoPolicy;
41
70
  export type SoftapStepStatus = "pending" | "running" | "done" | "failed";
42
71
  /**
43
72
  * One step as the UI should show it. `detail` is the fact the step produced (SSID, phone address,
@@ -65,6 +94,15 @@ export interface SoftapProgress {
65
94
  /** Sub-status callback a step can use to narrate what it is doing while it runs. */
66
95
  export type SoftapStepReporter = (detail: string) => void;
67
96
  export interface SoftapCallDeps {
97
+ /**
98
+ * Is this phone's Wi-Fi radio on? Asked before anything is built.
99
+ *
100
+ * The station radio is what reaches the glasses, and no app can turn it on since Android 10.
101
+ * Finding out at `scopedJoin` means the glasses already raised a hotspot for a join that cannot
102
+ * happen, so the wearer pays a teardown for a condition that was knowable up front. Optional:
103
+ * a host that cannot answer skips the preflight and relies on the native throw at `scopedJoin`.
104
+ */
105
+ isWifiEnabled?(): Promise<boolean>;
68
106
  /** Enable the glasses hotspot and return its credentials. */
69
107
  startHotspot(report?: SoftapStepReporter): Promise<{
70
108
  ssid: string;
@@ -228,6 +266,19 @@ export declare class SoftapCallTransport {
228
266
  * "Cannot start glasses hotspot" followed by a scoped join that never found the SSID.
229
267
  */
230
268
  lastTeardownFailures(): SoftapStep[];
269
+ /**
270
+ * Refuse the call while the Wi-Fi radio is off, before the glasses are asked for anything.
271
+ *
272
+ * Ordered ahead of the hotspot step rather than folded into `scopedJoin` because the cost of
273
+ * learning late is paid by the glasses: a hotspot raised, a teardown, and a wearer watching a
274
+ * checklist fail at step 2 for a toggle on their own phone. The native join keeps its own throw
275
+ * for the radio that goes off in between — this is the explainable path, that one is the racy
276
+ * backstop.
277
+ *
278
+ * A probe that throws is treated as "unknown, carry on": an unanswerable question about the
279
+ * radio must not be the thing that stops a call the radio would have carried.
280
+ */
281
+ private preflightWifi;
231
282
  /**
232
283
  * Runs the sequence. On any failure the partial sequence is torn down before the error is
233
284
  * rethrown, so a failed start never leaves a hotspot up or a publisher running.
@@ -284,6 +335,16 @@ export declare function createSoftapCallDeps(args: {
284
335
  meetingUrl: string;
285
336
  token: string;
286
337
  displayName?: string;
338
+ /**
339
+ * The ACS outgoing profile. Used here only to size the glasses→phone hop; when absent the
340
+ * glasses keep their WHIP defaults, which is what every pre-policy build did.
341
+ */
342
+ video?: {
343
+ width: number;
344
+ height: number;
345
+ fps: number;
346
+ maxBitrateBps: number;
347
+ };
287
348
  /** Resolves when the meeting reports a frame reached ACS; rejects on a failed feed. */
288
349
  awaitFirstFrame: () => Promise<void>;
289
350
  subsystems: {
@@ -293,6 +354,8 @@ export declare function createSoftapCallDeps(args: {
293
354
  password?: string;
294
355
  localIp?: string;
295
356
  }>;
357
+ /** Whether this phone's Wi-Fi radio is on. Optional: only Android hosts can answer it. */
358
+ isWifiEnabled?: () => Promise<boolean>;
296
359
  joinScopedNetwork: (ssid: string, passphrase: string, gateway?: string) => Promise<string | undefined>;
297
360
  leaveScopedNetwork: () => Promise<void>;
298
361
  cancelScopedNetworkJoin?: () => Promise<void>;
@@ -318,6 +381,7 @@ export declare function createSoftapCallDeps(args: {
318
381
  };
319
382
  traceId: string;
320
383
  captureAudio?: boolean;
384
+ video?: SoftapVideoPolicy;
321
385
  }) => Promise<unknown>;
322
386
  stopPublishing: (packageName: string) => Promise<void>;
323
387
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SoftapCallTransport.d.ts","sourceRoot":"","sources":["../../src/services/SoftapCallTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,yDAAyD;AACzD,eAAO,MAAM,YAAY,kEAAmE,CAAA;AAE5F,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAA;AAE9E,+FAA+F;AAC/F,qBAAa,eAAgB,SAAQ,KAAK;IAEtC,QAAQ,CAAC,IAAI,EAAE,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;gBAHf,IAAI,EAAE,U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AAA;QACtD;;;;;;;;WAQG;QACH,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAA;QAChC;;;;;WAKG;QACH,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;YAAC,SAAS,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,CAAC,CAAA;QAClE;;;;;;;WAOG;QACH,4BAA4B,CAAC,EAAE,MAAM,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,GAAG,IAAI,CAAC,CAAA;QACtF;;;WAGG;QACH,qBAAqB,CAAC,EAAE,CACtB,QAAQ,EAAE,CAAC,KAAK,EAAE;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAC,KAAK,IAAI,KAC5F,MAAM,IAAI,CAAA;KAChB,CAAA;IACD,oFAAoF;IACpF,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,GAAG,cAAc,CAqLjB"}
@@ -37,6 +37,54 @@ export class SoftapCallError extends Error {
37
37
  }
38
38
  /** Gallery sync already learned this: glasses report enabled before the SSID is in the phone scan. */
39
39
  export const HOTSPOT_BROADCAST_WAIT_MS = 3_000;
40
+ /**
41
+ * What the glasses→phone hop is worth at 540p over a hotspot with one client and no contention.
42
+ *
43
+ * Not the ACS ceiling: this link is a metre of air between two devices that are already paired,
44
+ * and the profile's `maxBitrateBps` describes the phone→Teams hop, which crosses the internet.
45
+ * Sharing one number between them makes the easy hop obey the hard hop's limits.
46
+ */
47
+ export const GLASSES_PHONE_BITRATE_BPS = 2_500_000;
48
+ /** Where the encoder starts. High, because the link is good from the first frame. */
49
+ const SOFTAP_START_BITRATE_BPS = 2_000_000;
50
+ /**
51
+ * The floor. This is the whole point of the policy.
52
+ *
53
+ * WHIP's default has none, so after an ICE interruption WebRTC restarts at its own minimum and
54
+ * climbs by probing — which is the "potato for a while" the wearer reports. The link did not get
55
+ * worse; the estimator merely forgot what it knew. A floor says: this hop is a hotspot, not a
56
+ * congested uplink, and it is never worth less than this.
57
+ *
58
+ * That trade is the opposite of Mentra-Call#27's cloud-WHIP review: a 1 Mbps floor on Auto over
59
+ * LTE turns a weak WAN into freezes. This function is SoftAP-only. Cloud WHIP must not call it.
60
+ */
61
+ const SOFTAP_MIN_BITRATE_BPS = 1_200_000;
62
+ /**
63
+ * The bitrate the glasses are told to hold on the hop to the phone.
64
+ *
65
+ * The hotspot has its own bitrate budget, independent of the phone-to-Teams cap. Above 540p,
66
+ * allow a higher requested ceiling while retaining the hotspot budget for low WAN caps.
67
+ */
68
+ export function softapVideoPolicy(video) {
69
+ const isSmall = video.width * video.height <= 960 * 540;
70
+ if (!Number.isFinite(video.maxBitrateBps) || video.maxBitrateBps <= 0) {
71
+ throw new Error(`invalid SoftAP video bitrate: ${video.maxBitrateBps}`);
72
+ }
73
+ const max = isSmall ? GLASSES_PHONE_BITRATE_BPS : Math.max(GLASSES_PHONE_BITRATE_BPS, video.maxBitrateBps);
74
+ const initialBitrateBps = Math.min(SOFTAP_START_BITRATE_BPS, max);
75
+ const minBitrateBps = Math.min(SOFTAP_MIN_BITRATE_BPS, initialBitrateBps);
76
+ if (!(minBitrateBps <= initialBitrateBps && initialBitrateBps <= max)) {
77
+ throw new Error(`incoherent SoftAP video policy: min=${minBitrateBps} start=${initialBitrateBps} max=${max}`);
78
+ }
79
+ return {
80
+ width: video.width,
81
+ height: video.height,
82
+ fps: video.fps,
83
+ bitrate: max,
84
+ initialBitrateBps,
85
+ minBitrateBps,
86
+ };
87
+ }
40
88
  /**
41
89
  * Android's WifiNetworkSpecifier called onUnavailable. The native message lists three causes
42
90
  * because the callback does not say which one happened; on the 18:02 Samsung path the SSID was
@@ -204,6 +252,41 @@ export class SoftapCallTransport {
204
252
  }
205
253
  return [...this.teardownFailures];
206
254
  }
255
+ /**
256
+ * Refuse the call while the Wi-Fi radio is off, before the glasses are asked for anything.
257
+ *
258
+ * Ordered ahead of the hotspot step rather than folded into `scopedJoin` because the cost of
259
+ * learning late is paid by the glasses: a hotspot raised, a teardown, and a wearer watching a
260
+ * checklist fail at step 2 for a toggle on their own phone. The native join keeps its own throw
261
+ * for the radio that goes off in between — this is the explainable path, that one is the racy
262
+ * backstop.
263
+ *
264
+ * A probe that throws is treated as "unknown, carry on": an unanswerable question about the
265
+ * radio must not be the thing that stops a call the radio would have carried.
266
+ */
267
+ async preflightWifi() {
268
+ if (!this.deps.isWifiEnabled)
269
+ return;
270
+ let enabled;
271
+ try {
272
+ enabled = await this.deps.isWifiEnabled();
273
+ }
274
+ catch (error) {
275
+ softapTraceFailure("softap_wifi_preflight_unknown", {
276
+ reason: error instanceof Error ? error.message : String(error),
277
+ });
278
+ return;
279
+ }
280
+ softapTrace("softap_wifi_preflight", { enabled });
281
+ if (enabled)
282
+ return;
283
+ this.setStep("hotspot", { status: "failed", error: "This phone's Wi-Fi is off" });
284
+ this.emitProgress();
285
+ // Code in the message as well as on the error: the miniapp classifies on the message today
286
+ // (the structured code only arrives on the join rejection), and every other SoftAP failure
287
+ // carries its code the same way.
288
+ throw new SoftapCallError("hotspot", "SOFTAP_WIFI_DISABLED", "SOFTAP_WIFI_DISABLED: this phone's Wi-Fi is off, so it cannot reach the glasses.");
289
+ }
207
290
  /**
208
291
  * Runs the sequence. On any failure the partial sequence is torn down before the error is
209
292
  * rethrown, so a failed start never leaves a hotspot up or a publisher running.
@@ -239,6 +322,7 @@ export class SoftapCallTransport {
239
322
  softapTrace("softap_call_start", { traceId });
240
323
  this.emitProgress();
241
324
  try {
325
+ await this.preflightWifi();
242
326
  await this.step(generation, "hotspot", "HOTSPOT_FAILED", async (report) => {
243
327
  report("Asking the glasses to turn on their hotspot");
244
328
  const hotspot = await this.deps.startHotspot(report);
@@ -571,6 +655,7 @@ export function createSoftapCallDeps(args) {
571
655
  const hotspotBroadcastWaitMs = args.hotspotBroadcastWaitMs ?? HOTSPOT_BROADCAST_WAIT_MS;
572
656
  let gatewayAddress;
573
657
  return {
658
+ isWifiEnabled: subsystems.isWifiEnabled ? () => subsystems.isWifiEnabled() : undefined,
574
659
  startHotspot: async (report) => {
575
660
  const enable = async () => {
576
661
  const status = await subsystems.setHotspotState(true);
@@ -598,7 +683,7 @@ export function createSoftapCallDeps(args) {
598
683
  report?.("Glasses hotspot did not start; turning it off and trying again");
599
684
  await subsystems.setHotspotState(false);
600
685
  if (hotspotBroadcastWaitMs > 0) {
601
- await new Promise(resolve => setTimeout(resolve, Math.min(1_000, hotspotBroadcastWaitMs)));
686
+ await new Promise((resolve) => setTimeout(resolve, Math.min(1_000, hotspotBroadcastWaitMs)));
602
687
  }
603
688
  return await enable();
604
689
  }
@@ -608,7 +693,7 @@ export function createSoftapCallDeps(args) {
608
693
  return;
609
694
  softapTrace("hotspot_broadcast_wait", { ms: hotspotBroadcastWaitMs });
610
695
  report?.(`Giving the hotspot ${Math.round(hotspotBroadcastWaitMs / 1000)}s to start broadcasting`);
611
- await new Promise(resolve => setTimeout(resolve, hotspotBroadcastWaitMs));
696
+ await new Promise((resolve) => setTimeout(resolve, hotspotBroadcastWaitMs));
612
697
  },
613
698
  stopHotspot: async () => {
614
699
  await subsystems.setHotspotState(false);
@@ -635,7 +720,7 @@ export function createSoftapCallDeps(args) {
635
720
  gatewayAddress = status.localIp;
636
721
  if (hotspotBroadcastWaitMs > 0) {
637
722
  report?.(`Giving the hotspot ${Math.round(hotspotBroadcastWaitMs / 1000)}s to start broadcasting`);
638
- await new Promise(resolve => setTimeout(resolve, hotspotBroadcastWaitMs));
723
+ await new Promise((resolve) => setTimeout(resolve, hotspotBroadcastWaitMs));
639
724
  }
640
725
  address = await joinOnce(status.ssid, status.password);
641
726
  }
@@ -719,6 +804,20 @@ export function createSoftapCallDeps(args) {
719
804
  report?.(lc3Uplink
720
805
  ? "Publishing video only; the wearer's voice comes over Bluetooth LC3"
721
806
  : "Publishing video and the glasses microphone");
807
+ const policy = args.video ? softapVideoPolicy(args.video) : undefined;
808
+ if (policy) {
809
+ // Traced at send time rather than read back: the glasses log what they applied in
810
+ // `applyBitrateConstraints`, and the pair of lines is what shows a clamp we did not
811
+ // intend. One line alone can only ever show agreement with itself.
812
+ softapTrace("softap_video_policy", {
813
+ width: policy.width,
814
+ height: policy.height,
815
+ fps: policy.fps,
816
+ min: policy.minBitrateBps,
817
+ start: policy.initialBitrateBps,
818
+ max: policy.bitrate,
819
+ });
820
+ }
722
821
  try {
723
822
  await subsystems.startPublishing(packageName, {
724
823
  streamUrl: ingestUrl,
@@ -727,6 +826,7 @@ export function createSoftapCallDeps(args) {
727
826
  ice: { stun: "" },
728
827
  traceId,
729
828
  captureAudio: !lc3Uplink,
829
+ ...(policy ? { video: policy } : {}),
730
830
  });
731
831
  }
732
832
  finally {