@glassly/engine 0.1.0-dev.61 → 0.1.0-dev.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/build/engine.d.ts +7 -2
- package/build/engine.d.ts.map +1 -1
- package/build/engine.js +3 -0
- package/build/engine.js.map +1 -1
- package/build/facades/display.d.ts +10 -3
- package/build/facades/display.d.ts.map +1 -1
- package/build/facades/display.js +11 -1
- package/build/facades/display.js.map +1 -1
- package/build/facades/displayMirror.d.ts +2 -6
- package/build/facades/displayMirror.d.ts.map +1 -1
- package/build/facades/displayMirror.js +7 -14
- package/build/facades/displayMirror.js.map +1 -1
- package/build/facades/glasses.d.ts +1 -0
- package/build/facades/glasses.d.ts.map +1 -1
- package/build/facades/glasses.js +2 -0
- package/build/facades/glasses.js.map +1 -1
- package/build/facades/ota.d.ts +3 -1
- package/build/facades/ota.d.ts.map +1 -1
- package/build/facades/ota.js +4 -2
- package/build/facades/ota.js.map +1 -1
- package/build/facades/phoneNotifications.d.ts +12 -2
- package/build/facades/phoneNotifications.d.ts.map +1 -1
- package/build/facades/phoneNotifications.js +30 -10
- package/build/facades/phoneNotifications.js.map +1 -1
- package/build/generated/releaseMetadata.js +3 -3
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/react/MentraLiveOtaFlow.d.ts +6 -1
- package/build/react/MentraLiveOtaFlow.d.ts.map +1 -1
- package/build/react/MentraLiveOtaFlow.js +136 -14
- package/build/react/MentraLiveOtaFlow.js.map +1 -1
- package/build/react/useMentraLiveOta.d.ts +5 -1
- package/build/react/useMentraLiveOta.d.ts.map +1 -1
- package/build/react/useMentraLiveOta.js +135 -58
- package/build/react/useMentraLiveOta.js.map +1 -1
- package/build/services/CustomDashboardService.d.ts +11 -10
- package/build/services/CustomDashboardService.d.ts.map +1 -1
- package/build/services/CustomDashboardService.js +70 -69
- package/build/services/CustomDashboardService.js.map +1 -1
- package/build/services/DashboardCoordinator.d.ts +26 -0
- package/build/services/DashboardCoordinator.d.ts.map +1 -0
- package/build/services/DashboardCoordinator.js +125 -0
- package/build/services/DashboardCoordinator.js.map +1 -0
- package/build/services/DeviceEventRouter.d.ts.map +1 -1
- package/build/services/DeviceEventRouter.js +5 -7
- package/build/services/DeviceEventRouter.js.map +1 -1
- package/build/services/DisplayProcessor.d.ts +3 -3
- package/build/services/DisplayProcessor.js +3 -3
- package/build/services/DisplayProcessor.js.map +1 -1
- package/build/services/LocalDisplayManager.d.ts +12 -2
- package/build/services/LocalDisplayManager.d.ts.map +1 -1
- package/build/services/LocalDisplayManager.js +68 -14
- package/build/services/LocalDisplayManager.js.map +1 -1
- package/build/services/OtaInstallCoordinator.d.ts +2 -0
- package/build/services/OtaInstallCoordinator.d.ts.map +1 -1
- package/build/services/OtaInstallCoordinator.js +21 -1
- package/build/services/OtaInstallCoordinator.js.map +1 -1
- package/build/services/PhoneNotificationsSync.d.ts +13 -0
- package/build/services/PhoneNotificationsSync.d.ts.map +1 -1
- package/build/services/PhoneNotificationsSync.js +101 -9
- package/build/services/PhoneNotificationsSync.js.map +1 -1
- package/build/services/PhonePhotoCoordinator.js +1 -1
- package/build/services/PhonePhotoCoordinator.js.map +1 -1
- package/build/services/PhoneStreamCoordinator.d.ts.map +1 -1
- package/build/services/PhoneStreamCoordinator.js +9 -6
- package/build/services/PhoneStreamCoordinator.js.map +1 -1
- package/build/services/SceneRenderer.d.ts.map +1 -1
- package/build/services/SceneRenderer.js +5 -0
- package/build/services/SceneRenderer.js.map +1 -1
- package/build/services/StreamLifecycleController.d.ts +4 -0
- package/build/services/StreamLifecycleController.d.ts.map +1 -1
- package/build/services/StreamLifecycleController.js +4 -0
- package/build/services/StreamLifecycleController.js.map +1 -1
- package/build/services/effectiveCapabilities.d.ts +1 -1
- package/build/services/effectiveCapabilities.d.ts.map +1 -1
- package/build/services/effectiveCapabilities.js +9 -4
- package/build/services/effectiveCapabilities.js.map +1 -1
- package/build/services/iosNotificationAppCatalog.d.ts +13 -0
- package/build/services/iosNotificationAppCatalog.d.ts.map +1 -0
- package/build/services/iosNotificationAppCatalog.js +28 -0
- package/build/services/iosNotificationAppCatalog.js.map +1 -0
- package/build/services/otaInstallPolicy.d.ts +4 -0
- package/build/services/otaInstallPolicy.d.ts.map +1 -1
- package/build/services/otaInstallPolicy.js +4 -0
- package/build/services/otaInstallPolicy.js.map +1 -1
- package/build/stores/display.d.ts +4 -4
- package/build/stores/display.d.ts.map +1 -1
- package/build/stores/display.js +12 -36
- package/build/stores/display.js.map +1 -1
- package/build/stores/glasses.d.ts.map +1 -1
- package/build/stores/glasses.js +2 -0
- package/build/stores/glasses.js.map +1 -1
- package/build/stores/settings.d.ts.map +1 -1
- package/build/stores/settings.js +53 -2
- package/build/stores/settings.js.map +1 -1
- package/build/types/applet.d.ts +1 -1
- package/build/types/applet.js.map +1 -1
- package/build/types/capabilities/even-realities-g2.d.ts.map +1 -1
- package/build/types/capabilities/even-realities-g2.js +2 -2
- package/build/types/capabilities/even-realities-g2.js.map +1 -1
- package/build/types/hardware.d.ts.map +1 -1
- package/build/types/hardware.js +1 -0
- package/build/types/hardware.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js +1 -1
- package/build/types/index.js.map +1 -1
- package/build/utils/display/composer/ColumnComposer.d.ts +1 -1
- package/build/utils/display/composer/ColumnComposer.js +1 -1
- package/build/utils/display/composer/ColumnComposer.js.map +1 -1
- package/package.json +8 -7
- package/src/engine.ts +3 -0
- package/src/facades/display.ts +11 -1
- package/src/facades/displayMirror.ts +7 -15
- package/src/facades/glasses.ts +2 -0
- package/src/facades/ota.ts +4 -2
- package/src/facades/phoneNotifications.ts +32 -10
- package/src/generated/releaseMetadata.ts +3 -3
- package/src/index.ts +2 -1
- package/src/react/MentraLiveOtaFlow.tsx +226 -41
- package/src/react/useMentraLiveOta.ts +146 -60
- package/src/services/CustomDashboardService.ts +67 -66
- package/src/services/DashboardCoordinator.ts +121 -0
- package/src/services/DeviceEventRouter.ts +5 -7
- package/src/services/DisplayProcessor.ts +3 -3
- package/src/services/LocalDisplayManager.ts +68 -16
- package/src/services/OtaInstallCoordinator.ts +21 -0
- package/src/services/PhoneNotificationsSync.ts +125 -9
- package/src/services/PhonePhotoCoordinator.ts +1 -1
- package/src/services/PhoneStreamCoordinator.ts +10 -6
- package/src/services/SceneRenderer.ts +4 -0
- package/src/services/StreamLifecycleController.ts +4 -0
- package/src/services/effectiveCapabilities.ts +9 -4
- package/src/services/iosNotificationAppCatalog.ts +39 -0
- package/src/services/otaInstallPolicy.ts +4 -0
- package/src/stores/display.ts +16 -48
- package/src/stores/glasses.ts +2 -0
- package/src/stores/settings.ts +53 -2
- package/src/types/applet.ts +1 -1
- package/src/types/capabilities/even-realities-g2.ts +3 -2
- package/src/types/hardware.ts +1 -0
- package/src/types/index.ts +1 -1
- package/src/utils/display/composer/ColumnComposer.ts +1 -1
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import type { G2NotificationFilterSetting } from "@glassly/bluetooth-sdk/internal";
|
|
2
|
+
export interface SeenNotificationApp {
|
|
3
|
+
appId: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
lastSeen: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function getSeenNotificationApps(): SeenNotificationApp[];
|
|
8
|
+
/** Catalog ∪ seen apps, seen display names winning. Sorted by name. */
|
|
9
|
+
export declare function getKnownNotificationApps(): Array<{
|
|
10
|
+
appId: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function computeG2NotificationFilter(): G2NotificationFilterSetting;
|
|
1
14
|
export declare function startPhoneNotificationsSync(): void;
|
|
2
15
|
export declare function stopPhoneNotificationsSync(): void;
|
|
3
16
|
//# sourceMappingURL=PhoneNotificationsSync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNotificationsSync.d.ts","sourceRoot":"","sources":["../../src/services/PhoneNotificationsSync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PhoneNotificationsSync.d.ts","sourceRoot":"","sources":["../../src/services/PhoneNotificationsSync.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAEV,2BAA2B,EAE5B,MAAM,iCAAiC,CAAA;AAKxC,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAcD,wBAAgB,uBAAuB,IAAI,mBAAmB,EAAE,CAG/D;AAED,uEAAuE;AACvE,wBAAgB,wBAAwB,IAAI,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAAC,CAWtF;AAED,wBAAgB,2BAA2B,IAAI,2BAA2B,CAUzE;AAsCD,wBAAgB,2BAA2B,IAAI,IAAI,CAgClD;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CAKjD"}
|
|
@@ -1,37 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Phone-notifications sync — engine-owned.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Phone-notifications sync — engine-owned. Started by `engine.start()`.
|
|
3
|
+
*
|
|
4
|
+
* Android: pushes the notification-forwarding operational kill switch + config
|
|
5
|
+
* (`android_notification_listener_enabled` and `notifications_blocklist`) to
|
|
6
|
+
* the native NotificationListener via `CrustModule.setNotificationConfig`, so
|
|
6
7
|
* the blocklist reaches the listener for ANY host — not just the Glassly App,
|
|
7
8
|
* where this used to live in MantleManager. The Android service is desired by
|
|
8
9
|
* default now that its cold start is isolated from React Native. Native code
|
|
9
10
|
* keeps the component discoverable in Android's notification-access Settings,
|
|
10
11
|
* but only binds the service after access is granted. The debug setting remains
|
|
11
12
|
* a hidden emergency kill switch; Notify's running state gates presentation,
|
|
12
|
-
* not capture.
|
|
13
|
+
* not capture.
|
|
14
|
+
*
|
|
15
|
+
* iOS: the G2 consumes notifications on-firmware via ANCS, so the phone's job
|
|
16
|
+
* is config, not capture. This sync (a) records the apps the glasses report
|
|
17
|
+
* posting notifications (`notification_app_seen` → `ios_notification_seen_apps`)
|
|
18
|
+
* and (b) maps the shared `notifications_blocklist` + the G2 display settings
|
|
19
|
+
* onto the native `notification_filter` / `notification_ctrl` DeviceStore keys,
|
|
20
|
+
* which the bluetooth-sdk pushes to the glasses (and replays on reconnect).
|
|
21
|
+
* The firmware filter is allow-based and fail-open: an empty blocklist disables
|
|
22
|
+
* whitelisting entirely; any block enables it with allowlist = (catalog ∪ seen)
|
|
23
|
+
* minus blocked.
|
|
13
24
|
*/
|
|
25
|
+
import { Platform } from "react-native";
|
|
14
26
|
import { shallow } from "zustand/shallow";
|
|
15
27
|
import CrustModule from "@glassly/crust";
|
|
28
|
+
import BluetoothSdk from "@glassly/bluetooth-sdk/internal";
|
|
16
29
|
import { useSettingsStore, SETTINGS } from "../stores/settings";
|
|
30
|
+
import { IOS_NOTIFICATION_APP_CATALOG } from "./iosNotificationAppCatalog";
|
|
17
31
|
let unsubscribe = null;
|
|
18
|
-
|
|
32
|
+
let seenAppsSubscription = null;
|
|
33
|
+
function pushAndroidConfig() {
|
|
19
34
|
const s = useSettingsStore.getState();
|
|
20
35
|
const listenerEnabled = Boolean(s.getSetting(SETTINGS.android_notification_listener_enabled.key));
|
|
21
36
|
const blocklist = s.getSetting(SETTINGS.notifications_blocklist.key);
|
|
22
37
|
CrustModule.setNotificationConfig(listenerEnabled, Array.isArray(blocklist) ? blocklist : []).catch((err) => console.warn(`PhoneNotificationsSync: setNotificationConfig failed: ${err?.message ?? err}`));
|
|
23
38
|
}
|
|
39
|
+
export function getSeenNotificationApps() {
|
|
40
|
+
const seen = useSettingsStore.getState().getSetting(SETTINGS.ios_notification_seen_apps.key);
|
|
41
|
+
return Array.isArray(seen) ? seen : [];
|
|
42
|
+
}
|
|
43
|
+
/** Catalog ∪ seen apps, seen display names winning. Sorted by name. */
|
|
44
|
+
export function getKnownNotificationApps() {
|
|
45
|
+
const merged = new Map();
|
|
46
|
+
for (const app of IOS_NOTIFICATION_APP_CATALOG) {
|
|
47
|
+
merged.set(app.appId, app.displayName);
|
|
48
|
+
}
|
|
49
|
+
for (const app of getSeenNotificationApps()) {
|
|
50
|
+
if (app.appId)
|
|
51
|
+
merged.set(app.appId, app.displayName || app.appId);
|
|
52
|
+
}
|
|
53
|
+
return [...merged.entries()]
|
|
54
|
+
.map(([appId, displayName]) => ({ appId, displayName }))
|
|
55
|
+
.sort((a, b) => a.displayName.localeCompare(b.displayName));
|
|
56
|
+
}
|
|
57
|
+
export function computeG2NotificationFilter() {
|
|
58
|
+
const blocklistValue = useSettingsStore.getState().getSetting(SETTINGS.notifications_blocklist.key);
|
|
59
|
+
const blocklist = Array.isArray(blocklistValue) ? blocklistValue : [];
|
|
60
|
+
const blocked = new Set(blocklist);
|
|
61
|
+
// The list is included even while filtering is off, so the on-glass file
|
|
62
|
+
// already holds the user's current list when a first block enables it.
|
|
63
|
+
const apps = getKnownNotificationApps()
|
|
64
|
+
.filter((app) => !blocked.has(app.appId))
|
|
65
|
+
.map((app) => ({ id: app.appId, name: app.displayName }));
|
|
66
|
+
return { enabled: blocked.size > 0, apps };
|
|
67
|
+
}
|
|
68
|
+
function computeG2NotificationCtrl() {
|
|
69
|
+
const s = useSettingsStore.getState();
|
|
70
|
+
return {
|
|
71
|
+
enabled: Boolean(s.getSetting(SETTINGS.g2_notifications_enabled.key)),
|
|
72
|
+
auto_display: Boolean(s.getSetting(SETTINGS.g2_notification_auto_display.key)),
|
|
73
|
+
disp_time: Number(s.getSetting(SETTINGS.g2_notification_disp_time.key)) || 0,
|
|
74
|
+
avoid_disturb: Boolean(s.getSetting(SETTINGS.g2_notification_avoid_disturb.key)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function pushIosConfig() {
|
|
78
|
+
// The native DeviceStore dedupes unchanged values and replays these to the
|
|
79
|
+
// glasses on every reconnect, so pushing eagerly is cheap.
|
|
80
|
+
void Promise.resolve(BluetoothSdk.updateBluetoothSettings({
|
|
81
|
+
notification_ctrl: computeG2NotificationCtrl(),
|
|
82
|
+
notification_filter: computeG2NotificationFilter(),
|
|
83
|
+
})).catch((err) => console.warn(`PhoneNotificationsSync: notification config push failed: ${err?.message ?? err}`));
|
|
84
|
+
}
|
|
85
|
+
/** Record a glasses-reported source app. Writes only on new app / renamed app. */
|
|
86
|
+
function recordSeenApp(event) {
|
|
87
|
+
if (!event.appId)
|
|
88
|
+
return;
|
|
89
|
+
const seen = getSeenNotificationApps();
|
|
90
|
+
const existing = seen.find((app) => app.appId === event.appId);
|
|
91
|
+
const displayName = event.displayName || existing?.displayName || event.appId;
|
|
92
|
+
if (existing && existing.displayName === displayName)
|
|
93
|
+
return;
|
|
94
|
+
const next = seen
|
|
95
|
+
.filter((app) => app.appId !== event.appId)
|
|
96
|
+
.concat([{ appId: event.appId, displayName, lastSeen: event.timestamp || Date.now() }]);
|
|
97
|
+
useSettingsStore.getState().setSetting(SETTINGS.ios_notification_seen_apps.key, next);
|
|
98
|
+
}
|
|
24
99
|
export function startPhoneNotificationsSync() {
|
|
25
100
|
if (unsubscribe)
|
|
26
101
|
return;
|
|
27
|
-
|
|
102
|
+
if (Platform.OS === "android") {
|
|
103
|
+
pushAndroidConfig(); // initial sync so the listener has the current config
|
|
104
|
+
unsubscribe = useSettingsStore.subscribe((state) => ({
|
|
105
|
+
listenerEnabled: state.getSetting(SETTINGS.android_notification_listener_enabled.key),
|
|
106
|
+
blocklist: state.getSetting(SETTINGS.notifications_blocklist.key),
|
|
107
|
+
}), () => pushAndroidConfig(), { equalityFn: shallow });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (Platform.OS !== "ios")
|
|
111
|
+
return;
|
|
112
|
+
pushIosConfig();
|
|
28
113
|
unsubscribe = useSettingsStore.subscribe((state) => ({
|
|
29
|
-
listenerEnabled: state.getSetting(SETTINGS.android_notification_listener_enabled.key),
|
|
30
114
|
blocklist: state.getSetting(SETTINGS.notifications_blocklist.key),
|
|
31
|
-
|
|
115
|
+
seenApps: state.getSetting(SETTINGS.ios_notification_seen_apps.key),
|
|
116
|
+
enabled: state.getSetting(SETTINGS.g2_notifications_enabled.key),
|
|
117
|
+
autoDisplay: state.getSetting(SETTINGS.g2_notification_auto_display.key),
|
|
118
|
+
dispTime: state.getSetting(SETTINGS.g2_notification_disp_time.key),
|
|
119
|
+
avoidDisturb: state.getSetting(SETTINGS.g2_notification_avoid_disturb.key),
|
|
120
|
+
}), () => pushIosConfig(), { equalityFn: shallow });
|
|
121
|
+
seenAppsSubscription = BluetoothSdk.addListener("notification_app_seen", recordSeenApp);
|
|
32
122
|
}
|
|
33
123
|
export function stopPhoneNotificationsSync() {
|
|
34
124
|
unsubscribe?.();
|
|
35
125
|
unsubscribe = null;
|
|
126
|
+
seenAppsSubscription?.remove();
|
|
127
|
+
seenAppsSubscription = null;
|
|
36
128
|
}
|
|
37
129
|
//# sourceMappingURL=PhoneNotificationsSync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNotificationsSync.js","sourceRoot":"","sources":["../../src/services/PhoneNotificationsSync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAA;AACvC,OAAO,WAAW,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAC,gBAAgB,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAA;AAE7D,IAAI,WAAW,GAAwB,IAAI,CAAA;AAE3C,SAAS,UAAU;IACjB,MAAM,CAAC,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAA;IACrC,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,qCAAqC,CAAC,GAAG,CAAC,CAAC,CAAA;IACjG,MAAM,SAAS,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAA;IACpE,WAAW,CAAC,qBAAqB,CAAC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE,CACnH,OAAO,CAAC,IAAI,CAAC,yDAA0D,GAAa,EAAE,OAAO,IAAI,GAAG,EAAE,CAAC,CACxG,CAAA;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,IAAI,WAAW;QAAE,OAAM;IACvB,UAAU,EAAE,CAAA,CAAC,sDAAsD;IACnE,WAAW,GAAG,gBAAgB,CAAC,SAAS,CACtC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACV,eAAe,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,qCAAqC,CAAC,GAAG,CAAC;QACrF,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,uBAAuB,CAAC,GAAG,CAAC;KAClE,CAAC,EACF,GAAG,EAAE,CAAC,UAAU,EAAE,EAClB,EAAC,UAAU,EAAE,OAAO,EAAC,CACtB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,WAAW,EAAE,EAAE,CAAA;IACf,WAAW,GAAG,IAAI,CAAA;AACpB,CAAC","sourcesContent":["/**\n * Phone-notifications sync — engine-owned. Pushes the notification-forwarding\n * operational kill switch + config (`android_notification_listener_enabled`\n * and `notifications_blocklist`) to the native\n * NotificationListener via `CrustModule.setNotificationConfig`, so\n * the blocklist reaches the listener for ANY host — not just the Glassly App,\n * where this used to live in MantleManager. The Android service is desired by\n * default now that its cold start is isolated from React Native. Native code\n * keeps the component discoverable in Android's notification-access Settings,\n * but only binds the service after access is granted. The debug setting remains\n * a hidden emergency kill switch; Notify's running state gates presentation,\n * not capture. Android-only; a no-op elsewhere. Started by `engine.start()`.\n */\nimport {shallow} from \"zustand/shallow\"\nimport CrustModule from \"@glassly/crust\"\n\nimport {useSettingsStore, SETTINGS} from \"../stores/settings\"\n\nlet unsubscribe: (() => void) | null = null\n\nfunction pushConfig(): void {\n const s = useSettingsStore.getState()\n const listenerEnabled = Boolean(s.getSetting(SETTINGS.android_notification_listener_enabled.key))\n const blocklist = s.getSetting(SETTINGS.notifications_blocklist.key)\n CrustModule.setNotificationConfig(listenerEnabled, Array.isArray(blocklist) ? blocklist : []).catch((err: unknown) =>\n console.warn(`PhoneNotificationsSync: setNotificationConfig failed: ${(err as Error)?.message ?? err}`),\n )\n}\n\nexport function startPhoneNotificationsSync(): void {\n if (unsubscribe) return\n pushConfig() // initial sync so the listener has the current config\n unsubscribe = useSettingsStore.subscribe(\n (state) => ({\n listenerEnabled: state.getSetting(SETTINGS.android_notification_listener_enabled.key),\n blocklist: state.getSetting(SETTINGS.notifications_blocklist.key),\n }),\n () => pushConfig(),\n {equalityFn: shallow},\n )\n}\n\nexport function stopPhoneNotificationsSync(): void {\n unsubscribe?.()\n unsubscribe = null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PhoneNotificationsSync.js","sourceRoot":"","sources":["../../src/services/PhoneNotificationsSync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAA;AACrC,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAA;AACvC,OAAO,WAAW,MAAM,gBAAgB,CAAA;AACxC,OAAO,YAAY,MAAM,iCAAiC,CAAA;AAO1D,OAAO,EAAC,gBAAgB,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAC,4BAA4B,EAAC,MAAM,6BAA6B,CAAA;AAQxE,IAAI,WAAW,GAAwB,IAAI,CAAA;AAC3C,IAAI,oBAAoB,GAA4B,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UAAU,CAAC,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CAAC;QAChE,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,4BAA4B,CAAC,GAAG,CAAC;QACxE,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,yBAAyB,CAAC,GAAG,CAAC;QAClE,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,6BAA6B,CAAC,GAAG,CAAC;KAC3E,CAAC,EACF,GAAG,EAAE,CAAC,aAAa,EAAE,EACrB,EAAC,UAAU,EAAE,OAAO,EAAC,CACtB,CAAA;IACD,oBAAoB,GAAG,YAAY,CAAC,WAAW,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAA;AACzF,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,WAAW,EAAE,EAAE,CAAA;IACf,WAAW,GAAG,IAAI,CAAA;IAClB,oBAAoB,EAAE,MAAM,EAAE,CAAA;IAC9B,oBAAoB,GAAG,IAAI,CAAA;AAC7B,CAAC","sourcesContent":["/**\n * Phone-notifications sync — engine-owned. Started by `engine.start()`.\n *\n * Android: pushes the notification-forwarding operational kill switch + config\n * (`android_notification_listener_enabled` and `notifications_blocklist`) to\n * the native NotificationListener via `CrustModule.setNotificationConfig`, so\n * the blocklist reaches the listener for ANY host — not just the Glassly App,\n * where this used to live in MantleManager. The Android service is desired by\n * default now that its cold start is isolated from React Native. Native code\n * keeps the component discoverable in Android's notification-access Settings,\n * but only binds the service after access is granted. The debug setting remains\n * a hidden emergency kill switch; Notify's running state gates presentation,\n * not capture.\n *\n * iOS: the G2 consumes notifications on-firmware via ANCS, so the phone's job\n * is config, not capture. This sync (a) records the apps the glasses report\n * posting notifications (`notification_app_seen` → `ios_notification_seen_apps`)\n * and (b) maps the shared `notifications_blocklist` + the G2 display settings\n * onto the native `notification_filter` / `notification_ctrl` DeviceStore keys,\n * which the bluetooth-sdk pushes to the glasses (and replays on reconnect).\n * The firmware filter is allow-based and fail-open: an empty blocklist disables\n * whitelisting entirely; any block enables it with allowlist = (catalog ∪ seen)\n * minus blocked.\n */\nimport {Platform} from \"react-native\"\nimport {shallow} from \"zustand/shallow\"\nimport CrustModule from \"@glassly/crust\"\nimport BluetoothSdk from \"@glassly/bluetooth-sdk/internal\"\nimport type {\n G2NotificationCtrlSetting,\n G2NotificationFilterSetting,\n NotificationAppSeenEvent,\n} from \"@glassly/bluetooth-sdk/internal\"\n\nimport {useSettingsStore, SETTINGS} from \"../stores/settings\"\nimport {IOS_NOTIFICATION_APP_CATALOG} from \"./iosNotificationAppCatalog\"\n\nexport interface SeenNotificationApp {\n appId: string\n displayName: string\n lastSeen: number\n}\n\nlet unsubscribe: (() => void) | null = null\nlet seenAppsSubscription: {remove(): void} | null = null\n\nfunction pushAndroidConfig(): void {\n const s = useSettingsStore.getState()\n const listenerEnabled = Boolean(s.getSetting(SETTINGS.android_notification_listener_enabled.key))\n const blocklist = s.getSetting(SETTINGS.notifications_blocklist.key)\n CrustModule.setNotificationConfig(listenerEnabled, Array.isArray(blocklist) ? blocklist : []).catch((err: unknown) =>\n console.warn(`PhoneNotificationsSync: setNotificationConfig failed: ${(err as Error)?.message ?? err}`),\n )\n}\n\nexport function getSeenNotificationApps(): SeenNotificationApp[] {\n const seen = useSettingsStore.getState().getSetting(SETTINGS.ios_notification_seen_apps.key)\n return Array.isArray(seen) ? (seen as SeenNotificationApp[]) : []\n}\n\n/** Catalog ∪ seen apps, seen display names winning. Sorted by name. */\nexport function getKnownNotificationApps(): Array<{appId: string; displayName: string}> {\n const merged = new Map<string, string>()\n for (const app of IOS_NOTIFICATION_APP_CATALOG) {\n merged.set(app.appId, app.displayName)\n }\n for (const app of getSeenNotificationApps()) {\n if (app.appId) merged.set(app.appId, app.displayName || app.appId)\n }\n return [...merged.entries()]\n .map(([appId, displayName]) => ({appId, displayName}))\n .sort((a, b) => a.displayName.localeCompare(b.displayName))\n}\n\nexport function computeG2NotificationFilter(): G2NotificationFilterSetting {\n const blocklistValue = useSettingsStore.getState().getSetting(SETTINGS.notifications_blocklist.key)\n const blocklist = Array.isArray(blocklistValue) ? (blocklistValue as string[]) : []\n const blocked = new Set(blocklist)\n // The list is included even while filtering is off, so the on-glass file\n // already holds the user's current list when a first block enables it.\n const apps = getKnownNotificationApps()\n .filter((app) => !blocked.has(app.appId))\n .map((app) => ({id: app.appId, name: app.displayName}))\n return {enabled: blocked.size > 0, apps}\n}\n\nfunction computeG2NotificationCtrl(): G2NotificationCtrlSetting {\n const s = useSettingsStore.getState()\n return {\n enabled: Boolean(s.getSetting(SETTINGS.g2_notifications_enabled.key)),\n auto_display: Boolean(s.getSetting(SETTINGS.g2_notification_auto_display.key)),\n disp_time: Number(s.getSetting(SETTINGS.g2_notification_disp_time.key)) || 0,\n avoid_disturb: Boolean(s.getSetting(SETTINGS.g2_notification_avoid_disturb.key)),\n }\n}\n\nfunction pushIosConfig(): void {\n // The native DeviceStore dedupes unchanged values and replays these to the\n // glasses on every reconnect, so pushing eagerly is cheap.\n void Promise.resolve(\n BluetoothSdk.updateBluetoothSettings({\n notification_ctrl: computeG2NotificationCtrl(),\n notification_filter: computeG2NotificationFilter(),\n }),\n ).catch((err: unknown) =>\n console.warn(`PhoneNotificationsSync: notification config push failed: ${(err as Error)?.message ?? err}`),\n )\n}\n\n/** Record a glasses-reported source app. Writes only on new app / renamed app. */\nfunction recordSeenApp(event: NotificationAppSeenEvent): void {\n if (!event.appId) return\n const seen = getSeenNotificationApps()\n const existing = seen.find((app) => app.appId === event.appId)\n const displayName = event.displayName || existing?.displayName || event.appId\n if (existing && existing.displayName === displayName) return\n const next = seen\n .filter((app) => app.appId !== event.appId)\n .concat([{appId: event.appId, displayName, lastSeen: event.timestamp || Date.now()}])\n useSettingsStore.getState().setSetting(SETTINGS.ios_notification_seen_apps.key, next)\n}\n\nexport function startPhoneNotificationsSync(): void {\n if (unsubscribe) return\n\n if (Platform.OS === \"android\") {\n pushAndroidConfig() // initial sync so the listener has the current config\n unsubscribe = useSettingsStore.subscribe(\n (state) => ({\n listenerEnabled: state.getSetting(SETTINGS.android_notification_listener_enabled.key),\n blocklist: state.getSetting(SETTINGS.notifications_blocklist.key),\n }),\n () => pushAndroidConfig(),\n {equalityFn: shallow},\n )\n return\n }\n\n if (Platform.OS !== \"ios\") return\n\n pushIosConfig()\n unsubscribe = useSettingsStore.subscribe(\n (state) => ({\n blocklist: state.getSetting(SETTINGS.notifications_blocklist.key),\n seenApps: state.getSetting(SETTINGS.ios_notification_seen_apps.key),\n enabled: state.getSetting(SETTINGS.g2_notifications_enabled.key),\n autoDisplay: state.getSetting(SETTINGS.g2_notification_auto_display.key),\n dispTime: state.getSetting(SETTINGS.g2_notification_disp_time.key),\n avoidDisturb: state.getSetting(SETTINGS.g2_notification_avoid_disturb.key),\n }),\n () => pushIosConfig(),\n {equalityFn: shallow},\n )\n seenAppsSubscription = BluetoothSdk.addListener(\"notification_app_seen\", recordSeenApp)\n}\n\nexport function stopPhoneNotificationsSync(): void {\n unsubscribe?.()\n unsubscribe = null\n seenAppsSubscription?.remove()\n seenAppsSubscription = null\n}\n"]}
|
|
@@ -104,7 +104,7 @@ export class PhonePhotoCoordinator {
|
|
|
104
104
|
// to time out. Fail fast with a typed error.
|
|
105
105
|
//
|
|
106
106
|
// We DON'T pre-check `hasCamera` here — the canonical capability data
|
|
107
|
-
// lives in `getModelCapabilities(deviceModel)`
|
|
107
|
+
// lives in `getModelCapabilities(deviceModel)` from @glassly/engine and
|
|
108
108
|
// pulling that into this file would add a cross-package import. If a
|
|
109
109
|
// cameraless device receives the BLE photo command, the glasses-side
|
|
110
110
|
// handler will return a photo_response error within ~1s and the gated
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhonePhotoCoordinator.js","sourceRoot":"","sources":["../../src/services/PhonePhotoCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,YAAY,MAAM,iCAAiC,CAAA;AAE1D,OA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A;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 \"@glassly/bluetooth-sdk/internal\"\nimport type {PhotoSize, PhotoTransferMethod} from \"@glassly/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)` in the engine types 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.js","sourceRoot":"","sources":["../../src/services/PhonePhotoCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,YAAY,MAAM,iCAAiC,CAAA;AAE1D,OAAO,EAAC,kBAAkB,EA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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 \"@glassly/bluetooth-sdk/internal\"\nimport type {PhotoSize, PhotoTransferMethod} from \"@glassly/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 @glassly/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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneStreamCoordinator.d.ts","sourceRoot":"","sources":["../../src/services/PhoneStreamCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EAC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,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IASlD,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,cAAc;IAqCtB,OAAO,CAAC,yBAAyB;IA8GjC,OAAO,CAAC,qBAAqB;IAsE7B,OAAO,CAAC,MAAM;IAYd;;;;;;OAMG;YACW,cAAc;CAgD7B;AAqDD,eAAO,MAAM,sBAAsB,wBAA+B,CAAA"}
|
|
@@ -664,12 +664,6 @@ export class PhoneStreamCoordinator {
|
|
|
664
664
|
reject(pendingErr);
|
|
665
665
|
entry.hlsReadyResolvers = [];
|
|
666
666
|
entry.hlsReadyRejecters = [];
|
|
667
|
-
// Cloudflare DELETE is fire-and-forget — failing it doesn't undo the
|
|
668
|
-
// BLE stop we're about to do, and Cloudflare's idle-input scavenger
|
|
669
|
-
// will eventually clean up leaked inputs.
|
|
670
|
-
teardownManagedStream(entry.liveInputId).catch((err) => {
|
|
671
|
-
console.warn("[STREAM] teardownManagedStream failed:", err);
|
|
672
|
-
});
|
|
673
667
|
}
|
|
674
668
|
try {
|
|
675
669
|
if (sendBleStop) {
|
|
@@ -686,6 +680,15 @@ export class PhoneStreamCoordinator {
|
|
|
686
680
|
// serializes us, so this should always be true).
|
|
687
681
|
if (this.current === entry)
|
|
688
682
|
this.current = null;
|
|
683
|
+
if (entry.kind === "managed") {
|
|
684
|
+
// Start remote cleanup only after the publisher has stopped, but do not
|
|
685
|
+
// hold the local transition lock on an unbounded network request. The
|
|
686
|
+
// runtime's durable cleanup queue owns retries if this request fails or
|
|
687
|
+
// the app exits before Cloudflare finishes finalizing the recording.
|
|
688
|
+
void teardownManagedStream(entry.liveInputId).catch((err) => {
|
|
689
|
+
console.warn("[STREAM] teardownManagedStream failed:", err);
|
|
690
|
+
});
|
|
691
|
+
}
|
|
689
692
|
}
|
|
690
693
|
}
|
|
691
694
|
}
|