@mentra/miniapp 0.3.0-dev.0
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 +259 -0
- package/dist/background/index.d.ts +59 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +25 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +38 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +75 -0
- package/dist/background/register.js.map +1 -0
- package/dist/dev-reload.d.ts +21 -0
- package/dist/dev-reload.d.ts.map +1 -0
- package/dist/dev-reload.js +62 -0
- package/dist/dev-reload.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +47 -0
- package/dist/envelope.js.map +1 -0
- package/dist/globals.d.ts +54 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +12 -0
- package/dist/globals.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +54 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +122 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +52 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/base64.d.ts +16 -0
- package/dist/modules/base64.d.ts.map +1 -0
- package/dist/modules/base64.js +92 -0
- package/dist/modules/base64.js.map +1 -0
- package/dist/modules/blob.d.ts +161 -0
- package/dist/modules/blob.d.ts.map +1 -0
- package/dist/modules/blob.js +277 -0
- package/dist/modules/blob.js.map +1 -0
- package/dist/modules/camera.d.ts +137 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +104 -0
- package/dist/modules/camera.js.map +1 -0
- package/dist/modules/cloud.d.ts +34 -0
- package/dist/modules/cloud.d.ts.map +1 -0
- package/dist/modules/cloud.js +70 -0
- package/dist/modules/cloud.js.map +1 -0
- package/dist/modules/dashboard.d.ts +16 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +27 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +106 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +57 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +167 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +123 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +28 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +39 -0
- package/dist/modules/glasses.js.map +1 -0
- package/dist/modules/heading.d.ts +16 -0
- package/dist/modules/heading.d.ts.map +1 -0
- package/dist/modules/heading.js +20 -0
- package/dist/modules/heading.js.map +1 -0
- package/dist/modules/imu.d.ts +31 -0
- package/dist/modules/imu.d.ts.map +1 -0
- package/dist/modules/imu.js +40 -0
- package/dist/modules/imu.js.map +1 -0
- package/dist/modules/input.d.ts +34 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +50 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/led.d.ts +35 -0
- package/dist/modules/led.d.ts.map +1 -0
- package/dist/modules/led.js +39 -0
- package/dist/modules/led.js.map +1 -0
- package/dist/modules/location.d.ts +27 -0
- package/dist/modules/location.d.ts.map +1 -0
- package/dist/modules/location.js +35 -0
- package/dist/modules/location.js.map +1 -0
- package/dist/modules/mic.d.ts +44 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +67 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +72 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +48 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +326 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +386 -0
- package/dist/modules/navigation.js.map +1 -0
- package/dist/modules/permissions.d.ts +58 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/permissions.js +66 -0
- package/dist/modules/permissions.js.map +1 -0
- package/dist/modules/phone.d.ts +61 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +94 -0
- package/dist/modules/phone.js.map +1 -0
- package/dist/modules/pivots/engine.d.ts +169 -0
- package/dist/modules/pivots/engine.d.ts.map +1 -0
- package/dist/modules/pivots/engine.js +779 -0
- package/dist/modules/pivots/engine.js.map +1 -0
- package/dist/modules/pivots/geometry.d.ts +84 -0
- package/dist/modules/pivots/geometry.d.ts.map +1 -0
- package/dist/modules/pivots/geometry.js +371 -0
- package/dist/modules/pivots/geometry.js.map +1 -0
- package/dist/modules/pivots/instructions.d.ts +139 -0
- package/dist/modules/pivots/instructions.d.ts.map +1 -0
- package/dist/modules/pivots/instructions.js +280 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +163 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +250 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/storage.d.ts +50 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +99 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/stream.d.ts +129 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +52 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +45 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +42 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +67 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +106 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +59 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +119 -0
- package/dist/modules/translation.js.map +1 -0
- package/dist/modules/ui.d.ts +186 -0
- package/dist/modules/ui.d.ts.map +1 -0
- package/dist/modules/ui.js +293 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +294 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +320 -0
- package/dist/protocol.js.map +1 -0
- package/dist/react/MentraProvider.d.ts +33 -0
- package/dist/react/MentraProvider.d.ts.map +1 -0
- package/dist/react/MentraProvider.js +15 -0
- package/dist/react/MentraProvider.js.map +1 -0
- package/dist/react/MiniappHeader.d.ts +44 -0
- package/dist/react/MiniappHeader.d.ts.map +1 -0
- package/dist/react/MiniappHeader.js +32 -0
- package/dist/react/MiniappHeader.js.map +1 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCapabilities.d.ts +26 -0
- package/dist/react/useCapabilities.d.ts.map +1 -0
- package/dist/react/useCapabilities.js +27 -0
- package/dist/react/useCapabilities.js.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.js +36 -0
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
- package/dist/react/useColorScheme.d.ts +18 -0
- package/dist/react/useColorScheme.d.ts.map +1 -0
- package/dist/react/useColorScheme.js +24 -0
- package/dist/react/useColorScheme.js.map +1 -0
- package/dist/react/useConnected.d.ts +17 -0
- package/dist/react/useConnected.d.ts.map +1 -0
- package/dist/react/useConnected.js +39 -0
- package/dist/react/useConnected.js.map +1 -0
- package/dist/react/useRpc.d.ts +29 -0
- package/dist/react/useRpc.d.ts.map +1 -0
- package/dist/react/useRpc.js +82 -0
- package/dist/react/useRpc.js.map +1 -0
- package/dist/react/useSafeArea.d.ts +21 -0
- package/dist/react/useSafeArea.d.ts.map +1 -0
- package/dist/react/useSafeArea.js +22 -0
- package/dist/react/useSafeArea.js.map +1 -0
- package/dist/session.d.ts +310 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +653 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +28 -0
- package/dist/sub-path-types.test-d.d.ts.map +1 -0
- package/dist/sub-path-types.test-d.js +37 -0
- package/dist/sub-path-types.test-d.js.map +1 -0
- package/dist/transport/auto.d.ts +35 -0
- package/dist/transport/auto.d.ts.map +1 -0
- package/dist/transport/auto.js +125 -0
- package/dist/transport/auto.js.map +1 -0
- package/dist/transport/dispatch.d.ts +43 -0
- package/dist/transport/dispatch.d.ts.map +1 -0
- package/dist/transport/dispatch.js +91 -0
- package/dist/transport/dispatch.js.map +1 -0
- package/dist/transport/local-socket.d.ts +28 -0
- package/dist/transport/local-socket.d.ts.map +1 -0
- package/dist/transport/local-socket.js +80 -0
- package/dist/transport/local-socket.js.map +1 -0
- package/dist/transport/mock.d.ts +54 -0
- package/dist/transport/mock.d.ts.map +1 -0
- package/dist/transport/mock.js +205 -0
- package/dist/transport/mock.js.map +1 -0
- package/dist/transport/postmessage.d.ts +36 -0
- package/dist/transport/postmessage.d.ts.map +1 -0
- package/dist/transport/postmessage.js +78 -0
- package/dist/transport/postmessage.js.map +1 -0
- package/dist/transport/types.d.ts +25 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/index.d.ts +98 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +75 -0
- package/src/background/index.ts +152 -0
- package/src/background/register.ts +85 -0
- package/src/dev-reload.ts +60 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/index.ts +171 -0
- package/src/modules/actions.ts +156 -0
- package/src/modules/auth.ts +68 -0
- package/src/modules/base64.ts +87 -0
- package/src/modules/blob.ts +341 -0
- package/src/modules/camera.ts +196 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +31 -0
- package/src/modules/display.ts +122 -0
- package/src/modules/events.ts +264 -0
- package/src/modules/glasses.ts +44 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +71 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/mic.ts +74 -0
- package/src/modules/miniapps.ts +90 -0
- package/src/modules/navigation.ts +670 -0
- package/src/modules/permissions.ts +84 -0
- package/src/modules/phone.ts +120 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +343 -0
- package/src/modules/speaker.ts +328 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +163 -0
- package/src/modules/system.ts +76 -0
- package/src/modules/transcription.ts +128 -0
- package/src/modules/translation.ts +149 -0
- package/src/modules/ui.ts +498 -0
- package/src/protocol.ts +371 -0
- package/src/react/MentraProvider.tsx +50 -0
- package/src/react/MiniappHeader.tsx +122 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +54 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +106 -0
- package/src/react/useSafeArea.ts +40 -0
- package/src/session.ts +878 -0
- package/src/sub-path-types.test-d.ts +49 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +93 -0
- package/src/transport/mock.ts +248 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +122 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NavigationModule — turn-by-turn navigation for miniapps. A thin pass-through over the bridge;
|
|
3
|
+
* the phone-side daemon owns the trip lifecycle.
|
|
4
|
+
*
|
|
5
|
+
* Works on iOS and Android (both back it with the Mapbox Navigation SDK). Every Promise
|
|
6
|
+
* resolves with an `{ok, error?}` shape; nothing throws, so check `result.ok`.
|
|
7
|
+
*/
|
|
8
|
+
import { MiniappRequestType, MiniappStreamType } from "../protocol";
|
|
9
|
+
import { PivotEngine } from "./pivots/engine";
|
|
10
|
+
export class NavigationModule {
|
|
11
|
+
constructor(session) {
|
|
12
|
+
this.session = session;
|
|
13
|
+
this._pivots = new PivotEngine("walking", undefined);
|
|
14
|
+
/** Subscriptions owned while a trip is active. Released on stop(). */
|
|
15
|
+
this._tripUnsubs = [];
|
|
16
|
+
/** Trip params captured at start() so reroutes can re-issue computeRoute. */
|
|
17
|
+
this._tripStops = null;
|
|
18
|
+
this._tripMode = "walking";
|
|
19
|
+
this._tripAvoid = undefined;
|
|
20
|
+
/** Bumps per request so a stale reply from before a newer reroute is ignored. */
|
|
21
|
+
this._computeRouteSeq = 0;
|
|
22
|
+
/** Latest GPS position, used as the origin for reroute computeRoute calls. */
|
|
23
|
+
this._lastUserPosition = null;
|
|
24
|
+
// Reverse-geocode fallback for pivots whose instruction carried no road name.
|
|
25
|
+
this._pivots.setRoadNameResolver(async (coord) => {
|
|
26
|
+
try {
|
|
27
|
+
const result = await this.reverseGeocodeRoad(coord);
|
|
28
|
+
if (!result.ok)
|
|
29
|
+
return null;
|
|
30
|
+
return result.road ?? null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** True iff `LOCATION` is declared in the miniapp's manifest. */
|
|
38
|
+
get hasPermission() {
|
|
39
|
+
return this.session._hasManifestPermission("LOCATION");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Trigger the Nav SDK Terms & Conditions dialog up front, before the user hits "start".
|
|
43
|
+
* Idempotent. Resolves `{ok: false, accepted: false, error}` when LOCATION isn't declared.
|
|
44
|
+
*/
|
|
45
|
+
requestPermission() {
|
|
46
|
+
if (!this.hasPermission) {
|
|
47
|
+
return Promise.resolve({
|
|
48
|
+
ok: false,
|
|
49
|
+
accepted: false,
|
|
50
|
+
error: "LOCATION permission not declared in miniapp.json (required for navigation.requestPermission).",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return this.session.sendRequest({
|
|
54
|
+
type: MiniappRequestType.NAVIGATION_REQUEST_PERMISSION,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Start a navigation session. Pass `{lat, lng}` or `{stops: [...]}`. `{ok: true}` means the
|
|
59
|
+
* daemon accepted the request, not that a route was built — listen via `onUpdate(...)`.
|
|
60
|
+
*/
|
|
61
|
+
async start(opts) {
|
|
62
|
+
if (!this.hasPermission) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
error: "LOCATION permission not declared in miniapp.json (required for navigation.start).",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const stops = normalizeStops(opts);
|
|
69
|
+
const mode = opts.mode ?? "driving";
|
|
70
|
+
this._tripStops = stops.length > 0 ? stops : null;
|
|
71
|
+
this._tripMode = mode;
|
|
72
|
+
this._tripAvoid = opts.avoid;
|
|
73
|
+
// Subscribes the engine to route + location streams. Idempotent — detaches any prior trip first.
|
|
74
|
+
this._attachPivotTrackingForTrip(mode, opts.pivots);
|
|
75
|
+
// Every failure return below must release the subscriptions attached just above.
|
|
76
|
+
const failStart = (error) => {
|
|
77
|
+
this._detachPivotTracking();
|
|
78
|
+
return { ok: false, error };
|
|
79
|
+
};
|
|
80
|
+
if (stops.length === 0) {
|
|
81
|
+
return failStart("navigation.start: no stops");
|
|
82
|
+
}
|
|
83
|
+
// Origin: live position if known, else a one-shot host fetch. (stops[0] would be the
|
|
84
|
+
// destination for a single-stop trip — a degenerate origin.)
|
|
85
|
+
let origin = this._lastUserPosition;
|
|
86
|
+
if (!origin) {
|
|
87
|
+
try {
|
|
88
|
+
const fix = await this.session.location.getOnce();
|
|
89
|
+
origin = { lat: fix.lat, lng: fix.lng };
|
|
90
|
+
this._lastUserPosition = origin;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return failStart(`navigation.start: no GPS fix (${err instanceof Error ? err.message : String(err)})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Source-of-truth route is the host's Routes REST call. If it fails, abort (no native fallback).
|
|
97
|
+
const restResult = await this.computeRoute({ origin, stops, mode, avoid: opts.avoid });
|
|
98
|
+
if (!restResult.ok || !restResult.routes || restResult.routes.length === 0) {
|
|
99
|
+
return failStart(restResult.error ?? "computeRoute failed");
|
|
100
|
+
}
|
|
101
|
+
const restRoute = restResult.routes[0];
|
|
102
|
+
const nativeResult = await this.session.sendRequest({
|
|
103
|
+
type: MiniappRequestType.NAVIGATION_START,
|
|
104
|
+
// Keep lat/lng on the wire for hosts not yet upgraded to read `stops`.
|
|
105
|
+
lat: stops[0]?.lat,
|
|
106
|
+
lng: stops[0]?.lng,
|
|
107
|
+
stops,
|
|
108
|
+
mode,
|
|
109
|
+
avoid: opts.avoid,
|
|
110
|
+
simulate: opts.simulate ?? false,
|
|
111
|
+
speedMultiplier: opts.speedMultiplier ?? 1,
|
|
112
|
+
missedTurnRerouteMeters: opts.missedTurnRerouteMeters,
|
|
113
|
+
});
|
|
114
|
+
if (!nativeResult.ok) {
|
|
115
|
+
this._detachPivotTracking();
|
|
116
|
+
return nativeResult;
|
|
117
|
+
}
|
|
118
|
+
// Dispatch the REST route through the native route channel so subscribers see step roads now.
|
|
119
|
+
const syntheticRoute = buildNavRouteFromComputed(restRoute);
|
|
120
|
+
this.session.events._forwardEvent(MiniappStreamType.NAVIGATION_ROUTE, syntheticRoute);
|
|
121
|
+
return nativeResult;
|
|
122
|
+
}
|
|
123
|
+
/** Stop the active session (no-op if none). Fire-and-forget; also detaches pivot tracking. */
|
|
124
|
+
stop() {
|
|
125
|
+
this._detachPivotTracking();
|
|
126
|
+
this.session.sendOneShot({ type: MiniappRequestType.NAVIGATION_STOP });
|
|
127
|
+
}
|
|
128
|
+
/** Dev-only simulator helpers for testing trips. `deviate` works on both platforms;
|
|
129
|
+
* a few helpers are Android-only and return `{ok: false}` on iOS. */
|
|
130
|
+
get dev() {
|
|
131
|
+
return {
|
|
132
|
+
/** Nudge the simulator off-route to trigger a reroute. Default 20m. */
|
|
133
|
+
deviate: (offsetMeters = 20) => {
|
|
134
|
+
this.session.sendOneShot({ type: MiniappRequestType.NAVIGATION_DEVIATE, offsetMeters });
|
|
135
|
+
},
|
|
136
|
+
/** Lock simulated locations to the wrong sidewalk to test along-path pivot triggers. */
|
|
137
|
+
setWrongSidewalkOffset: (enabled) => {
|
|
138
|
+
this.session.sendOneShot({ type: MiniappRequestType.NAVIGATION_SET_WRONG_SIDEWALK, enabled });
|
|
139
|
+
},
|
|
140
|
+
/** Walk a polyline with crossing micro-steps removed, for missed-turn testing. */
|
|
141
|
+
setSkipCrossings: (enabled) => {
|
|
142
|
+
this.session.sendOneShot({ type: MiniappRequestType.NAVIGATION_SET_SKIP_CROSSINGS, enabled });
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** Subscribe to live trip events (maneuver / off_route / rerouting / arrived / error). */
|
|
147
|
+
onUpdate(handler) {
|
|
148
|
+
return this.session._subscribe(MiniappStreamType.NAVIGATION_UPDATE, handler);
|
|
149
|
+
}
|
|
150
|
+
/** Subscribe to the route polyline. Fires once per route build (initial + reroute), full path. */
|
|
151
|
+
onRoute(handler) {
|
|
152
|
+
return this.session._subscribe(MiniappStreamType.NAVIGATION_ROUTE, handler);
|
|
153
|
+
}
|
|
154
|
+
/** Snapshot of the active trip, or `null` when none is running. Use on mount to hydrate state. */
|
|
155
|
+
async getState() {
|
|
156
|
+
const result = await this.session.sendRequest({
|
|
157
|
+
type: MiniappRequestType.NAVIGATION_GET_STATE,
|
|
158
|
+
});
|
|
159
|
+
return result.ok ? (result.state ?? null) : null;
|
|
160
|
+
}
|
|
161
|
+
/** Compute a route without starting a trip. Primary route first, alternates after. */
|
|
162
|
+
computeRoute(opts) {
|
|
163
|
+
if (!this.hasPermission) {
|
|
164
|
+
return Promise.resolve({
|
|
165
|
+
ok: false,
|
|
166
|
+
error: "LOCATION permission not declared in miniapp.json (required for navigation.computeRoute).",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return this.session.sendRequest({
|
|
170
|
+
type: MiniappRequestType.NAVIGATION_COMPUTE_ROUTE,
|
|
171
|
+
origin: opts.origin,
|
|
172
|
+
stops: opts.stops,
|
|
173
|
+
mode: opts.mode ?? "driving",
|
|
174
|
+
avoid: opts.avoid,
|
|
175
|
+
alternatives: opts.alternatives ?? 1,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Reverse-geocode a coordinate into a short road name (`road`) and a full
|
|
180
|
+
* formatted street address (`address`, e.g. "369 Hayes Street, San Francisco,
|
|
181
|
+
* California 94102"). `road` backs the pivot engine's fallback; `address`
|
|
182
|
+
* backs UI labels for dropped pins / POI taps. Each is null when none of that
|
|
183
|
+
* kind is found near the coordinate; `ok: false` is an actual failure.
|
|
184
|
+
*
|
|
185
|
+
* Resolved entirely in the v2 cloud maps service (provider-abstracted, Mapbox
|
|
186
|
+
* today) via the host bridge — the miniapp never holds a maps token or calls a
|
|
187
|
+
* provider directly.
|
|
188
|
+
*/
|
|
189
|
+
reverseGeocodeRoad(coord) {
|
|
190
|
+
if (!this.hasPermission) {
|
|
191
|
+
return Promise.resolve({
|
|
192
|
+
ok: false,
|
|
193
|
+
error: "LOCATION permission not declared in miniapp.json (required for reverseGeocodeRoad).",
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return this.session.sendRequest({
|
|
197
|
+
type: MiniappRequestType.NAVIGATION_REVERSE_GEOCODE,
|
|
198
|
+
lat: coord.lat,
|
|
199
|
+
lng: coord.lng,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Type-ahead place search. Returns lightweight suggestions for `query`,
|
|
204
|
+
* optionally biased toward `near`. Resolved in the v2 cloud maps service
|
|
205
|
+
* (Mapbox Search Box today) via the host bridge — no maps token in the
|
|
206
|
+
* miniapp. `sessionToken` should be a stable per-search-box-opening string,
|
|
207
|
+
* reused on the following `placeDetails` call, then rotated after a pick, so
|
|
208
|
+
* the keystrokes + the final retrieve bill as one search session.
|
|
209
|
+
*
|
|
210
|
+
* Does NOT require LOCATION permission — it's a text search; `near` is only a
|
|
211
|
+
* ranking bias. Resolves `{ok, suggestions}`; `ok: false` is an actual failure.
|
|
212
|
+
*/
|
|
213
|
+
placeAutocomplete(opts) {
|
|
214
|
+
return this.session.sendRequest({
|
|
215
|
+
type: MiniappRequestType.NAVIGATION_PLACE_AUTOCOMPLETE,
|
|
216
|
+
query: opts.query,
|
|
217
|
+
near: opts.near ?? null,
|
|
218
|
+
sessionToken: opts.sessionToken,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Resolve a suggestion's `placeId` (from `placeAutocomplete`) to a full place
|
|
223
|
+
* with coordinates. Pass the SAME `sessionToken` used for the autocomplete so
|
|
224
|
+
* the provider closes the billing session. Resolved in the v2 cloud maps
|
|
225
|
+
* service via the host bridge. Resolves `{ok, place}`; `ok: false` is a
|
|
226
|
+
* failure (including an unresolvable id).
|
|
227
|
+
*/
|
|
228
|
+
placeDetails(opts) {
|
|
229
|
+
return this.session.sendRequest({
|
|
230
|
+
type: MiniappRequestType.NAVIGATION_PLACE_DETAILS,
|
|
231
|
+
placeId: opts.placeId,
|
|
232
|
+
sessionToken: opts.sessionToken,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// Pivots — real turns along the route, fired as approaching / entered / exited as GPS ticks in.
|
|
236
|
+
/** Subscribe to pivot events. Each pivot fires once per kind; passed pivots aren't re-evaluated. */
|
|
237
|
+
onPivot(handler) {
|
|
238
|
+
return this._pivots.subscribe(handler);
|
|
239
|
+
}
|
|
240
|
+
/** Full pivot list for the active route. Empty before the first `onRoute`. */
|
|
241
|
+
getPivots() {
|
|
242
|
+
return this._pivots.getPivots();
|
|
243
|
+
}
|
|
244
|
+
/** The pivot the user is currently inside (between `entered` and `exited`), or `null`. */
|
|
245
|
+
getActivePivot() {
|
|
246
|
+
return this._pivots.getActivePivot();
|
|
247
|
+
}
|
|
248
|
+
/** The next pivot ahead, or `null` once every pivot has been passed. */
|
|
249
|
+
getUpcomingPivot() {
|
|
250
|
+
return this._pivots.getUpcomingPivot();
|
|
251
|
+
}
|
|
252
|
+
_attachPivotTrackingForTrip(mode, opts) {
|
|
253
|
+
this._detachPivotTracking();
|
|
254
|
+
this._pivots.reset();
|
|
255
|
+
this._pivots.updateOptions(mode, opts);
|
|
256
|
+
// Rebuild pivots on every route. Initial start emits a synthetic onRoute with REST steps (build
|
|
257
|
+
// directly); a native reroute emits no steps (render geometry pivots, then enrich via REST).
|
|
258
|
+
this._tripUnsubs.push(this.onRoute((route) => {
|
|
259
|
+
if (route.steps && route.steps.length > 0) {
|
|
260
|
+
// NavStep carries only the step start; the engine needs endLat/endLng to anchor the turn.
|
|
261
|
+
// end of step[i] == start of step[i+1]; the final step uses the last polyline vertex.
|
|
262
|
+
const tail = route.points[route.points.length - 1];
|
|
263
|
+
const computedSteps = route.steps.map((s, i) => {
|
|
264
|
+
const next = route.steps?.[i + 1];
|
|
265
|
+
const endLat = next ? next.lat : (tail?.lat ?? s.lat);
|
|
266
|
+
const endLng = next ? next.lng : (tail?.lng ?? s.lng);
|
|
267
|
+
return {
|
|
268
|
+
lat: s.lat,
|
|
269
|
+
lng: s.lng,
|
|
270
|
+
endLat,
|
|
271
|
+
endLng,
|
|
272
|
+
distanceMeters: s.distanceMeters,
|
|
273
|
+
maneuver: s.maneuver,
|
|
274
|
+
road: s.road ?? undefined,
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
this._pivots.setRouteFromComputedSteps(route, computedSteps);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this._pivots.setRoute(route, null);
|
|
281
|
+
const seq = ++this._computeRouteSeq;
|
|
282
|
+
this._issueComputeRouteForTrip(route)
|
|
283
|
+
.then((result) => {
|
|
284
|
+
if (seq !== this._computeRouteSeq)
|
|
285
|
+
return; // superseded by a newer reroute
|
|
286
|
+
const computedSteps = result?.routes?.[0]?.steps;
|
|
287
|
+
if (computedSteps && computedSteps.length > 0) {
|
|
288
|
+
this._pivots.setRouteFromComputedSteps(route, computedSteps);
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
.catch((err) => {
|
|
292
|
+
console.warn("[NavigationModule] computeRoute for pivots failed:", err);
|
|
293
|
+
});
|
|
294
|
+
}));
|
|
295
|
+
// `arrived` resets the engine. `rerouting` is handled natively by the host, so no action here.
|
|
296
|
+
this._tripUnsubs.push(this.onUpdate((update) => {
|
|
297
|
+
if (update.kind === "arrived") {
|
|
298
|
+
this._pivots.reset();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}));
|
|
302
|
+
// Every fix drives the pivot cursor and records the latest position for reroute origin.
|
|
303
|
+
this._tripUnsubs.push(this.session.location.onUpdate((loc) => {
|
|
304
|
+
this._lastUserPosition = { lat: loc.lat, lng: loc.lng };
|
|
305
|
+
this._pivots.onLocationUpdate({ lat: loc.lat, lng: loc.lng });
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
/** computeRoute for the current trip, using the latest position (or route start) as origin. */
|
|
309
|
+
async _issueComputeRouteForTrip(route) {
|
|
310
|
+
if (!this._tripStops || this._tripStops.length === 0)
|
|
311
|
+
return null;
|
|
312
|
+
const origin = this._lastUserPosition ?? (route?.points && route.points[0] ? { lat: route.points[0].lat, lng: route.points[0].lng } : null);
|
|
313
|
+
if (!origin)
|
|
314
|
+
return null;
|
|
315
|
+
return this.computeRoute({
|
|
316
|
+
origin,
|
|
317
|
+
stops: this._tripStops,
|
|
318
|
+
mode: this._tripMode,
|
|
319
|
+
avoid: this._tripAvoid,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
// NOTE: client-side reroute was removed in the Mapbox migration — the host reroutes natively and
|
|
323
|
+
// pushes the new route through `onRoute`. If a future host doesn't, re-add it in `onUpdate`.
|
|
324
|
+
_detachPivotTracking() {
|
|
325
|
+
for (const unsub of this._tripUnsubs) {
|
|
326
|
+
try {
|
|
327
|
+
unsub();
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
console.warn("[NavigationModule] pivot-tracking unsubscribe threw:", err);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
this._tripUnsubs = [];
|
|
334
|
+
this._pivots.reset();
|
|
335
|
+
// Bumping the sequence is the real guard against a stale in-flight reply; the rest is tidiness.
|
|
336
|
+
this._tripStops = null;
|
|
337
|
+
this._tripAvoid = undefined;
|
|
338
|
+
this._computeRouteSeq++;
|
|
339
|
+
this._lastUserPosition = null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** Normalize the `{lat, lng}` shorthand into a `stops` array. */
|
|
343
|
+
function normalizeStops(opts) {
|
|
344
|
+
if (opts.stops && opts.stops.length > 0) {
|
|
345
|
+
return opts.stops;
|
|
346
|
+
}
|
|
347
|
+
if (typeof opts.lat === "number" && typeof opts.lng === "number") {
|
|
348
|
+
return [{ lat: opts.lat, lng: opts.lng }];
|
|
349
|
+
}
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Convert a REST `ComputedRoute` into the wire `NavRoute` shape. Anchors each step to a polyline
|
|
354
|
+
* vertex (`routeIndex`) by nearest-point search. Steps with no maneuver default to "STRAIGHT".
|
|
355
|
+
*/
|
|
356
|
+
function buildNavRouteFromComputed(computed) {
|
|
357
|
+
const points = computed.points ?? [];
|
|
358
|
+
const steps = (computed.steps ?? []).map((s) => {
|
|
359
|
+
let routeIndex = 0;
|
|
360
|
+
let best = Infinity;
|
|
361
|
+
for (let i = 0; i < points.length; i++) {
|
|
362
|
+
const dLat = points[i].lat - s.lat;
|
|
363
|
+
const dLng = points[i].lng - s.lng;
|
|
364
|
+
const d = dLat * dLat + dLng * dLng;
|
|
365
|
+
if (d < best) {
|
|
366
|
+
best = d;
|
|
367
|
+
routeIndex = i;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
lat: s.lat,
|
|
372
|
+
lng: s.lng,
|
|
373
|
+
routeIndex,
|
|
374
|
+
road: s.road ?? null,
|
|
375
|
+
maneuver: s.maneuver ?? "STRAIGHT",
|
|
376
|
+
distanceMeters: s.distanceMeters,
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
return {
|
|
380
|
+
points,
|
|
381
|
+
totalDistanceMeters: computed.totalDistanceMeters,
|
|
382
|
+
totalDurationSeconds: computed.totalDurationSeconds,
|
|
383
|
+
steps: steps.length > 0 ? steps : undefined,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/modules/navigation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAA;AAGjE,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAA;AAwO3C,MAAM,OAAO,gBAAgB;IAa3B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAZ5C,YAAO,GAAgB,IAAI,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QACpE,sEAAsE;QAC9D,gBAAW,GAAsB,EAAE,CAAA;QAC3C,6EAA6E;QACrE,eAAU,GAAoB,IAAI,CAAA;QAClC,cAAS,GAAe,SAAS,CAAA;QACjC,eAAU,GAAgC,SAAS,CAAA;QAC3D,iF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AC,QAAQ,IAAI,UAAU;YAClC,cAAc,EAAE,CAAC,CAAC,cAAc;SACjC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO;QACL,MAAM;QACN,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB;QACjD,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;QACnD,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KAC5C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PermissionsModule — manifest-declared permission introspection.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors cloud SDK v3's PermissionsManager surface and semantics:
|
|
5
|
+
* permissions.has(type) — synchronous boolean
|
|
6
|
+
* permissions.getAll() — full PermissionRecord
|
|
7
|
+
* permissions.onUpdate(handler) — fires on cache change
|
|
8
|
+
* permissions.onPermissionError(handler) — typed handler for the existing
|
|
9
|
+
* PERMISSION_NOT_DECLARED error
|
|
10
|
+
*
|
|
11
|
+
* What "permission" means here. Same as v3: this module tracks
|
|
12
|
+
* **manifest-declared** permissions. `permissions.has("microphone") === true`
|
|
13
|
+
* means the miniapp's manifest.json declared MICROPHONE — it does NOT mean
|
|
14
|
+
* the user actually granted the OS permission. To detect OS-grant state,
|
|
15
|
+
* observe whether your subscriptions actually deliver events.
|
|
16
|
+
*
|
|
17
|
+
* OS-level grant state and `request(...)` are deferred to a future round.
|
|
18
|
+
* Their additions will land additively on this same module — `isGranted(...)`
|
|
19
|
+
* / `request(...)` alongside the existing `has(...)` / `getAll(...)` —
|
|
20
|
+
* without renaming today's surface.
|
|
21
|
+
*/
|
|
22
|
+
import { MiniappSession } from "../session";
|
|
23
|
+
import type { PermissionRecord, PermissionType } from "../session";
|
|
24
|
+
import type { UnsubscribeFn } from "./events";
|
|
25
|
+
export interface PermissionErrorEvent {
|
|
26
|
+
/** The error code. Always PERMISSION_NOT_DECLARED today; reserved for future codes. */
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
/** The manifest permission name (UPPER_CASE) that was missing. */
|
|
30
|
+
permission?: string;
|
|
31
|
+
/** The subscription / operation that triggered the rejection. */
|
|
32
|
+
subscription?: string;
|
|
33
|
+
operation?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class PermissionsModule {
|
|
36
|
+
private readonly session;
|
|
37
|
+
/** Local handlers for onUpdate. Session emitter handles the fan-out. */
|
|
38
|
+
constructor(session: MiniappSession);
|
|
39
|
+
/** True iff the named permission is declared in the miniapp's manifest. */
|
|
40
|
+
has(type: PermissionType): boolean;
|
|
41
|
+
/** Full record of declared permissions. Fresh shallow copy. */
|
|
42
|
+
getAll(): PermissionRecord;
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to declared-permission updates. Fires when the cached record
|
|
45
|
+
* changes — usually on CONNECT_ACK, or when the phone pushes a
|
|
46
|
+
* PERMISSIONS_UPDATE (e.g. dev miniapp re-scanned with updated manifest).
|
|
47
|
+
*
|
|
48
|
+
* Does NOT fire immediately with the current value — call getAll()
|
|
49
|
+
* separately if you want the seed.
|
|
50
|
+
*/
|
|
51
|
+
onUpdate(handler: (perms: PermissionRecord) => void): UnsubscribeFn;
|
|
52
|
+
/**
|
|
53
|
+
* Subscribe to typed PERMISSION_NOT_DECLARED errors. Sugar over the
|
|
54
|
+
* existing session "error" event, filtered to the permission-error code.
|
|
55
|
+
*/
|
|
56
|
+
onPermissionError(handler: (err: PermissionErrorEvent) => void): UnsubscribeFn;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/modules/permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAC,gBAAgB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAA;AAChE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AAE3C,MAAM,WAAW,oBAAoB;IACnC,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,iBAAiB;IAEhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,wEAAwE;gBAC3C,OAAO,EAAE,cAAc;IAEpD,2EAA2E;IAC3E,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO;IAIlC,+DAA+D;IAC/D,MAAM,IAAI,gBAAgB;IAI1B;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,aAAa;IAInE;;;OAGG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,GAAG,aAAa;CAc/E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PermissionsModule — manifest-declared permission introspection.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors cloud SDK v3's PermissionsManager surface and semantics:
|
|
5
|
+
* permissions.has(type) — synchronous boolean
|
|
6
|
+
* permissions.getAll() — full PermissionRecord
|
|
7
|
+
* permissions.onUpdate(handler) — fires on cache change
|
|
8
|
+
* permissions.onPermissionError(handler) — typed handler for the existing
|
|
9
|
+
* PERMISSION_NOT_DECLARED error
|
|
10
|
+
*
|
|
11
|
+
* What "permission" means here. Same as v3: this module tracks
|
|
12
|
+
* **manifest-declared** permissions. `permissions.has("microphone") === true`
|
|
13
|
+
* means the miniapp's manifest.json declared MICROPHONE — it does NOT mean
|
|
14
|
+
* the user actually granted the OS permission. To detect OS-grant state,
|
|
15
|
+
* observe whether your subscriptions actually deliver events.
|
|
16
|
+
*
|
|
17
|
+
* OS-level grant state and `request(...)` are deferred to a future round.
|
|
18
|
+
* Their additions will land additively on this same module — `isGranted(...)`
|
|
19
|
+
* / `request(...)` alongside the existing `has(...)` / `getAll(...)` —
|
|
20
|
+
* without renaming today's surface.
|
|
21
|
+
*/
|
|
22
|
+
import { MiniappErrorCode } from "../protocol";
|
|
23
|
+
export class PermissionsModule {
|
|
24
|
+
/** Local handlers for onUpdate. Session emitter handles the fan-out. */
|
|
25
|
+
constructor(session) {
|
|
26
|
+
this.session = session;
|
|
27
|
+
}
|
|
28
|
+
/** True iff the named permission is declared in the miniapp's manifest. */
|
|
29
|
+
has(type) {
|
|
30
|
+
return this.session._getPermissions()[type] === true;
|
|
31
|
+
}
|
|
32
|
+
/** Full record of declared permissions. Fresh shallow copy. */
|
|
33
|
+
getAll() {
|
|
34
|
+
return this.session._getPermissions();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to declared-permission updates. Fires when the cached record
|
|
38
|
+
* changes — usually on CONNECT_ACK, or when the phone pushes a
|
|
39
|
+
* PERMISSIONS_UPDATE (e.g. dev miniapp re-scanned with updated manifest).
|
|
40
|
+
*
|
|
41
|
+
* Does NOT fire immediately with the current value — call getAll()
|
|
42
|
+
* separately if you want the seed.
|
|
43
|
+
*/
|
|
44
|
+
onUpdate(handler) {
|
|
45
|
+
return this.session.on("permissions", handler);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Subscribe to typed PERMISSION_NOT_DECLARED errors. Sugar over the
|
|
49
|
+
* existing session "error" event, filtered to the permission-error code.
|
|
50
|
+
*/
|
|
51
|
+
onPermissionError(handler) {
|
|
52
|
+
return this.session.on("error", (e) => {
|
|
53
|
+
const maybe = e;
|
|
54
|
+
if (maybe?.code === MiniappErrorCode.PERMISSION_NOT_DECLARED) {
|
|
55
|
+
handler({
|
|
56
|
+
code: String(maybe.code),
|
|
57
|
+
message: String(maybe.message ?? ""),
|
|
58
|
+
permission: maybe.permission,
|
|
59
|
+
subscription: maybe.subscription,
|
|
60
|
+
operation: maybe.operation,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/modules/permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAA;AAiB5C,MAAM,OAAO,iBAAiB;IAC5B,wEAAwE;IACxE,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD,2EAA2E;IAC3E,GAAG,CAAC,IAAoB;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;IACtD,CAAC;IAED,+DAA+D;IAC/D,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAA;IACvC,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,OAA0C;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;IAED;;;OAGG;IACH,iBAAiB,CAAC,OAA4C;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACpC,MAAM,KAAK,GAAG,CAAmE,CAAA;YACjF,IAAI,KAAK,EAAE,IAAI,KAAK,gBAAgB,CAAC,uBAAuB,EAAE,CAAC;gBAC7D,OAAO,CAAC;oBACN,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;oBACxB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;oBACpC,UAAU,EAAE,KAAK,CAAC,UAAgC;oBAClD,YAAY,EAAE,KAAK,CAAC,YAAkC;oBACtD,SAAS,EAAE,KAAK,CAAC,SAA+B;iBACjD,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PhoneModule — phone device-state events.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors cloud SDK v3's PhoneManager structure. Sub-namespaced by concern:
|
|
5
|
+
*
|
|
6
|
+
* session.phone.notifications.{on, hasPermission, stop}
|
|
7
|
+
* session.phone.calendar.{on, hasPermission, stop}
|
|
8
|
+
* session.phone.onBattery(...) // stays flat
|
|
9
|
+
*
|
|
10
|
+
* Imperative phone-OS calls (share, openUrl, copyToClipboard, download) live
|
|
11
|
+
* on `session.system` — different shape (one-shot calls vs. event subs) so
|
|
12
|
+
* we don't conflate them.
|
|
13
|
+
*
|
|
14
|
+
* `phone.notifications.onDismissed` is Android-only. iOS doesn't expose
|
|
15
|
+
* notification-dismiss callbacks to apps (Apple privacy restriction);
|
|
16
|
+
* subscribing on iOS is a no-op even though the API is present.
|
|
17
|
+
*/
|
|
18
|
+
import { MiniappSession } from "../session";
|
|
19
|
+
import type { BatteryData, CalendarEventData, NotificationDismissedData, PhoneNotificationData, UnsubscribeFn } from "./events";
|
|
20
|
+
declare class TrackedSubs {
|
|
21
|
+
private readonly unsubs;
|
|
22
|
+
protected track(unsub: UnsubscribeFn): UnsubscribeFn;
|
|
23
|
+
stop(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class PhoneNotificationsModule extends TrackedSubs {
|
|
26
|
+
private readonly session;
|
|
27
|
+
constructor(session: MiniappSession);
|
|
28
|
+
on(handler: (data: PhoneNotificationData) => void): UnsubscribeFn;
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to dismiss events for phone notifications. Fires when the user
|
|
31
|
+
* dismisses (swipes away or clears) a notification.
|
|
32
|
+
*
|
|
33
|
+
* **Android only.** iOS does not expose dismiss callbacks to apps (Apple
|
|
34
|
+
* privacy restriction); subscribing on iOS succeeds but no events ever
|
|
35
|
+
* fire. The matching `notifications.on()` post-event still works on both
|
|
36
|
+
* platforms.
|
|
37
|
+
*/
|
|
38
|
+
onDismissed(handler: (data: NotificationDismissedData) => void): UnsubscribeFn;
|
|
39
|
+
/** True iff `READ_NOTIFICATIONS` is declared in the miniapp's manifest. */
|
|
40
|
+
get hasPermission(): boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare class PhoneCalendarModule extends TrackedSubs {
|
|
43
|
+
private readonly session;
|
|
44
|
+
constructor(session: MiniappSession);
|
|
45
|
+
on(handler: (data: CalendarEventData) => void): UnsubscribeFn;
|
|
46
|
+
/** True iff `CALENDAR` is declared in the miniapp's manifest. */
|
|
47
|
+
get hasPermission(): boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare class PhoneModule {
|
|
50
|
+
private readonly session;
|
|
51
|
+
readonly notifications: PhoneNotificationsModule;
|
|
52
|
+
readonly calendar: PhoneCalendarModule;
|
|
53
|
+
constructor(session: MiniappSession);
|
|
54
|
+
/**
|
|
55
|
+
* Phone battery events. Stays flat (not sub-namespaced) — single event,
|
|
56
|
+
* no extra surface.
|
|
57
|
+
*/
|
|
58
|
+
onBattery(handler: (data: BatteryData) => void): UnsubscribeFn;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../src/modules/phone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,y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