@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,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PostMessage transport — in-WebView bridge via React Native WebView.
|
|
3
|
+
*
|
|
4
|
+
* The React Native WebView exposes:
|
|
5
|
+
* - window.ReactNativeWebView.postMessage(string): miniapp → phone
|
|
6
|
+
* - document "message" events + window "message" events: phone → miniapp
|
|
7
|
+
*
|
|
8
|
+
* react-native-webview sends incoming messages as regular DOM `MessageEvent`s
|
|
9
|
+
* on the `window` object, with `event.data` as the string payload. We listen
|
|
10
|
+
* there.
|
|
11
|
+
*
|
|
12
|
+
* Old MentraOS builds injected a global `window.receiveNativeMessage` function;
|
|
13
|
+
* we also accept that path for compatibility by assigning our handler to it.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {Transport, TransportDisconnectHandler, TransportMessageHandler} from "./types"
|
|
17
|
+
|
|
18
|
+
// Note: window.MentraOS is declared in ../globals.ts. ReactNativeWebView and
|
|
19
|
+
// receiveNativeMessage are local to this transport.
|
|
20
|
+
declare global {
|
|
21
|
+
interface Window {
|
|
22
|
+
ReactNativeWebView?: {
|
|
23
|
+
postMessage: (data: string) => void
|
|
24
|
+
}
|
|
25
|
+
receiveNativeMessage?: (raw: string) => void
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class PostMessageTransport implements Transport {
|
|
30
|
+
private messageHandler: TransportMessageHandler | null = null
|
|
31
|
+
private disconnectHandler: TransportDisconnectHandler | null = null
|
|
32
|
+
private open_ = false
|
|
33
|
+
private windowListener: ((ev: MessageEvent) => void) | null = null
|
|
34
|
+
|
|
35
|
+
async open(): Promise<void> {
|
|
36
|
+
if (this.open_) return
|
|
37
|
+
if (typeof window === "undefined" || !window.ReactNativeWebView) {
|
|
38
|
+
throw new Error("PostMessageTransport: not running inside a React Native WebView")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Listen on window "message" — react-native-webview routes host→webview
|
|
42
|
+
// messages here. Also some builds dispatch on document; hook both.
|
|
43
|
+
this.windowListener = (ev: MessageEvent) => {
|
|
44
|
+
const data = ev.data
|
|
45
|
+
if (typeof data !== "string") return
|
|
46
|
+
this.messageHandler?.(data)
|
|
47
|
+
}
|
|
48
|
+
window.addEventListener("message", this.windowListener)
|
|
49
|
+
if (typeof document !== "undefined") {
|
|
50
|
+
document.addEventListener("message", this.windowListener as unknown as EventListener)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Legacy path: some host code calls window.receiveNativeMessage directly.
|
|
54
|
+
window.receiveNativeMessage = (raw: string) => {
|
|
55
|
+
this.messageHandler?.(raw)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.open_ = true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
send(raw: string): void {
|
|
62
|
+
if (typeof window === "undefined" || !window.ReactNativeWebView) {
|
|
63
|
+
throw new Error("PostMessageTransport: not running inside a React Native WebView")
|
|
64
|
+
}
|
|
65
|
+
window.ReactNativeWebView.postMessage(raw)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onMessage(handler: TransportMessageHandler): void {
|
|
69
|
+
this.messageHandler = handler
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onDisconnect(handler: TransportDisconnectHandler): void {
|
|
73
|
+
this.disconnectHandler = handler
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
close(): void {
|
|
77
|
+
if (!this.open_) return
|
|
78
|
+
this.open_ = false
|
|
79
|
+
if (this.windowListener) {
|
|
80
|
+
window.removeEventListener("message", this.windowListener)
|
|
81
|
+
if (typeof document !== "undefined") {
|
|
82
|
+
document.removeEventListener("message", this.windowListener as unknown as EventListener)
|
|
83
|
+
}
|
|
84
|
+
this.windowListener = null
|
|
85
|
+
}
|
|
86
|
+
if (typeof window !== "undefined" && window.receiveNativeMessage) {
|
|
87
|
+
window.receiveNativeMessage = undefined
|
|
88
|
+
}
|
|
89
|
+
this.disconnectHandler?.("closed")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
isOpen(): boolean {
|
|
93
|
+
return this.open_
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Transport abstraction for @mentra/miniapp.
|
|
3
|
+
*
|
|
4
|
+
* Two v1 implementations:
|
|
5
|
+
* - PostMessageTransport — inside MentraOS WebView, uses window.ReactNativeWebView
|
|
6
|
+
* - LocalSocketTransport — in external Safari/Chrome fallback, uses ws://127.0.0.1
|
|
7
|
+
*
|
|
8
|
+
* createTransport() in auto.ts picks the right one based on environment.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type TransportMessageHandler = (raw: string) => void
|
|
12
|
+
export type TransportDisconnectHandler = (reason: string) => void
|
|
13
|
+
|
|
14
|
+
export interface Transport {
|
|
15
|
+
/** Establish whatever connection the transport needs. May be a no-op. */
|
|
16
|
+
open(): Promise<void>
|
|
17
|
+
/** Send a serialized envelope. */
|
|
18
|
+
send(raw: string): void
|
|
19
|
+
/** Register a callback for incoming serialized envelopes. */
|
|
20
|
+
onMessage(handler: TransportMessageHandler): void
|
|
21
|
+
/** Register a callback for transport-level disconnects / errors. */
|
|
22
|
+
onDisconnect(handler: TransportDisconnectHandler): void
|
|
23
|
+
/** Close the transport cleanly. Idempotent. */
|
|
24
|
+
close(): void
|
|
25
|
+
isOpen(): boolean
|
|
26
|
+
}
|
package/src/ui/index.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mentra/miniapp/ui — WebView-side SDK entry point.
|
|
3
|
+
*
|
|
4
|
+
* Imported from a miniapp's `src/ui/main.tsx` (or equivalent) to access
|
|
5
|
+
* the `mentra` WebView global, React hooks, and the `MentraProvider`
|
|
6
|
+
* wrapper. This is the **on-demand WebView side** of a two-layer miniapp.
|
|
7
|
+
*
|
|
8
|
+
* What's NOT in this entry point:
|
|
9
|
+
* - `MiniappSession` — background-only.
|
|
10
|
+
* - Any `session.*` module classes — background-only.
|
|
11
|
+
* - `__dispatch` / direct native access — by design, the WebView has
|
|
12
|
+
* no host-native APIs. All hardware calls go through the background
|
|
13
|
+
* bus via `mentra.send(channel, payload)`.
|
|
14
|
+
*
|
|
15
|
+
* The `mentra` global is injected into every UI WebView at mount time
|
|
16
|
+
* by the host's `mentraUiShim` (see `@mentra/engine/services/mentraUiShim`).
|
|
17
|
+
* This entry point exports its TypeScript declaration so authors get
|
|
18
|
+
* autocomplete and compile-time errors on channel names + payloads.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type {IsRpc, RpcReq, RpcRes, RpcRequestOptions} from "../modules/ui"
|
|
22
|
+
export type {Rpc, IsRpc, RpcReq, RpcRes, RpcRequestOptions, RpcHandlerContext} from "../modules/ui"
|
|
23
|
+
export {MentraRpcError, MentraRpcTimeoutError} from "../modules/ui"
|
|
24
|
+
|
|
25
|
+
export interface MentraUiGlobal<TChannels extends object = Record<string, unknown>> {
|
|
26
|
+
/**
|
|
27
|
+
* Broadcast a typed message to the bound background JSContext.
|
|
28
|
+
* Buffered until `ready()` acks; once acked, fires immediately.
|
|
29
|
+
* Compile-error if `C` is an RPC channel — use `request()` instead.
|
|
30
|
+
*/
|
|
31
|
+
send<C extends keyof TChannels & string>(
|
|
32
|
+
channel: IsRpc<TChannels[C]> extends true ? never : C,
|
|
33
|
+
payload: TChannels[C],
|
|
34
|
+
): void
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to broadcast messages from the background. Compile-error
|
|
38
|
+
* if `C` is an RPC channel.
|
|
39
|
+
*/
|
|
40
|
+
on<C extends keyof TChannels & string>(
|
|
41
|
+
channel: IsRpc<TChannels[C]> extends true ? never : C,
|
|
42
|
+
cb: (payload: TChannels[C]) => void,
|
|
43
|
+
): () => void
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Make an RPC call to the background `session.ui.handle(channel, ...)`
|
|
47
|
+
* handler. On failure, throws an `Error` whose `name` is one of:
|
|
48
|
+
* - `"MentraRpcError"` — the handler threw. `err.cause?.code` may be set.
|
|
49
|
+
* - `"MentraRpcTimeoutError"` — `options.timeout` elapsed.
|
|
50
|
+
* - `"AbortError"` — `options.signal` aborted.
|
|
51
|
+
* Distinguish by `err.name`, not `instanceof` — these errors are
|
|
52
|
+
* constructed in the WebView's bare runtime scope. No default timeout.
|
|
53
|
+
*/
|
|
54
|
+
request<C extends keyof TChannels & string>(
|
|
55
|
+
channel: IsRpc<TChannels[C]> extends true ? C : never,
|
|
56
|
+
payload: RpcReq<TChannels[C]>,
|
|
57
|
+
options?: RpcRequestOptions,
|
|
58
|
+
): Promise<RpcRes<TChannels[C]>>
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Fires when the bridge is open and `mentra.send` is flushable. If
|
|
62
|
+
* subscribed AFTER `ready()` has been called, fires immediately.
|
|
63
|
+
*/
|
|
64
|
+
onOpen(cb: () => void): () => void
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Fires when the host is about to destroy the WebView. Handlers
|
|
68
|
+
* should snapshot any session state into background via
|
|
69
|
+
* `mentra.send` if they want it to survive.
|
|
70
|
+
*/
|
|
71
|
+
onClose(cb: () => void): () => void
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* MUST be called once on UI bootstrap. Tells the host the WebView is
|
|
75
|
+
* mounted and ready to receive messages from background. Idempotent
|
|
76
|
+
* — subsequent calls no-op. Background's `session.ui.onOpen` handlers
|
|
77
|
+
* fire after this lands.
|
|
78
|
+
*/
|
|
79
|
+
ready(): void
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// React adapters are re-exported here so authors can import everything
|
|
83
|
+
// from a single sub-path. The actual hooks live in src/react/ and are
|
|
84
|
+
// already shipped as a separate sub-path for backwards-compat.
|
|
85
|
+
export {
|
|
86
|
+
MentraProvider,
|
|
87
|
+
type MentraProviderProps,
|
|
88
|
+
} from "../react/MentraProvider"
|
|
89
|
+
export {MiniappHeader} from "../react/MiniappHeader"
|
|
90
|
+
export {useColorScheme} from "../react/useColorScheme"
|
|
91
|
+
export {useCapabilities} from "../react/useCapabilities"
|
|
92
|
+
export {useConnected} from "../react/useConnected"
|
|
93
|
+
export {useSafeArea} from "../react/useSafeArea"
|
|
94
|
+
export {useCapsuleHeaderStyle} from "../react/useCapsuleHeaderStyle"
|
|
95
|
+
export {useRpc, type RpcCallable} from "../react/useRpc"
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Type helper for declaring a typed `mentra` global inside a miniapp.
|
|
99
|
+
*
|
|
100
|
+
* Every mini app should declare ONE global `mentra` typed against its
|
|
101
|
+
* own channel registry. The SDK no longer auto-declares the global so
|
|
102
|
+
* each miniapp's registry doesn't collide with the SDK's default.
|
|
103
|
+
*
|
|
104
|
+
* Usage (in your miniapp's `src/shared/channels.ts`):
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* import type {MentraTyped} from "@mentra/miniapp/ui"
|
|
108
|
+
*
|
|
109
|
+
* export interface Channels {
|
|
110
|
+
* "live-transcript": {text: string}
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* declare global {
|
|
114
|
+
* // eslint-disable-next-line no-var
|
|
115
|
+
* var mentra: MentraTyped<Channels>
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* Both halves of the miniapp (background + UI) import this same file,
|
|
120
|
+
* so the typed shape is consistent across the bridge.
|
|
121
|
+
*/
|
|
122
|
+
export type MentraTyped<TChannels extends object> = MentraUiGlobal<TChannels>
|