@glassly/miniapp 0.1.0-dev.26
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 +275 -0
- package/dist/background/index.d.ts +64 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +26 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +39 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +72 -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 +60 -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/hardware.d.ts +24 -0
- package/dist/hardware.d.ts.map +1 -0
- package/dist/hardware.js +20 -0
- package/dist/hardware.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +81 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +137 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/ai.d.ts +211 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +117 -0
- package/dist/modules/ai.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 +183 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +119 -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 +24 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +39 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +174 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +83 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +178 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +168 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +36 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +52 -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 +50 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +70 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/keys.d.ts +30 -0
- package/dist/modules/keys.d.ts.map +1 -0
- package/dist/modules/keys.js +37 -0
- package/dist/modules/keys.js.map +1 -0
- package/dist/modules/languages.d.ts +42 -0
- package/dist/modules/languages.d.ts.map +1 -0
- package/dist/modules/languages.js +57 -0
- package/dist/modules/languages.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/memory.d.ts +126 -0
- package/dist/modules/memory.d.ts.map +1 -0
- package/dist/modules/memory.js +141 -0
- package/dist/modules/memory.js.map +1 -0
- package/dist/modules/mic.d.ts +61 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +94 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +82 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +58 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +332 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +387 -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 +95 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +110 -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 +778 -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 +281 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +175 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +249 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/speakers.d.ts +29 -0
- package/dist/modules/speakers.d.ts.map +1 -0
- package/dist/modules/speakers.js +38 -0
- package/dist/modules/speakers.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 +133 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +53 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +71 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +65 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +99 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +126 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +65 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +121 -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 +289 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +390 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +419 -0
- package/dist/protocol.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/MiniappProvider.d.ts +33 -0
- package/dist/react/MiniappProvider.d.ts.map +1 -0
- package/dist/react/MiniappProvider.js +15 -0
- package/dist/react/MiniappProvider.js.map +1 -0
- package/dist/react/capsuleHeaderLayout.d.ts +3 -0
- package/dist/react/capsuleHeaderLayout.d.ts.map +1 -0
- package/dist/react/capsuleHeaderLayout.js +5 -0
- package/dist/react/capsuleHeaderLayout.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 +39 -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 +355 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +688 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +40 -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 +124 -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 +210 -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 +107 -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 +88 -0
- package/src/background/index.ts +177 -0
- package/src/background/register.ts +89 -0
- package/src/dev-reload.ts +59 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/hardware.ts +25 -0
- package/src/index.ts +216 -0
- package/src/modules/actions.ts +189 -0
- package/src/modules/ai.ts +281 -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 +258 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +51 -0
- package/src/modules/display.ts +214 -0
- package/src/modules/events.ts +318 -0
- package/src/modules/glasses.ts +58 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +87 -0
- package/src/modules/keys.ts +46 -0
- package/src/modules/languages.ts +72 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/memory.ts +224 -0
- package/src/modules/mic.ts +103 -0
- package/src/modules/miniapps.ts +103 -0
- package/src/modules/navigation.ts +674 -0
- package/src/modules/permissions.ts +83 -0
- package/src/modules/phone.ts +155 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +341 -0
- package/src/modules/speaker.ts +347 -0
- package/src/modules/speakers.ts +40 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +168 -0
- package/src/modules/system.ts +113 -0
- package/src/modules/transcription.ts +180 -0
- package/src/modules/translation.ts +156 -0
- package/src/modules/ui.ts +481 -0
- package/src/protocol.ts +482 -0
- package/src/react/MiniappHeader.tsx +114 -0
- package/src/react/MiniappProvider.tsx +50 -0
- package/src/react/capsuleHeaderLayout.ts +11 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +55 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +103 -0
- package/src/react/useSafeArea.ts +36 -0
- package/src/session.ts +969 -0
- package/src/sub-path-types.test-d.ts +60 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +91 -0
- package/src/transport/mock.ts +255 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +129 -0
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# @glassly/miniapp
|
|
2
|
+
|
|
3
|
+
SDK for building Glassly local miniapps — static web apps that run inside the Glassly phone app's WebView and talk to smart glasses via a typed session API.
|
|
4
|
+
|
|
5
|
+
> Developing this SDK or running the in-repo example from a fresh clone? Start at the **[SDK developer guide](../../../sdk/README.md)** (setup, build loop, doc map).
|
|
6
|
+
> Per-module deep dives (return shapes, events, error codes): **[`sdk/docs/`](../../../sdk/docs/README.md)**.
|
|
7
|
+
> Companion package: **[`@glassly/miniapp-cli`](../../../sdk/miniapp-cli/README.md)** — `glassly-miniapp` CLI (`dev`, `release`, `pack`, `manifest`, `permission`, `hardware`, `schema`). Per-command docs live there.
|
|
8
|
+
> Scaffolder: `bunx create-miniapp my-app`.
|
|
9
|
+
> Reference miniapp: [`miniapps/example-miniapp/`](../../../miniapps/example-miniapp).
|
|
10
|
+
> High-level walkthrough: [`agents/miniapp-sdk-overview.md`](../../../agents/miniapp-sdk-overview.md).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bun add @glassly/miniapp
|
|
16
|
+
# or
|
|
17
|
+
npm install @glassly/miniapp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`react` is an optional peer dependency — only required if you use `@glassly/miniapp/react`.
|
|
21
|
+
|
|
22
|
+
## Entry points
|
|
23
|
+
|
|
24
|
+
| Specifier | Contents |
|
|
25
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| `@glassly/miniapp` | `MiniappSession`, `NotConnectedError`, transports, manifest-types re-exports, module type exports |
|
|
27
|
+
| `@glassly/miniapp/background` | `MiniappSession`, `registerMiniapp` — the always-on session layer (see two-layer note below) |
|
|
28
|
+
| `@glassly/miniapp/ui` | The WebView-side `glassly` channel bridge + React adapters (`<MiniappProvider>`, `<MiniappHeader>`, hooks) |
|
|
29
|
+
| `@glassly/miniapp/react` | React hooks + `<MiniappProvider>` + `<MiniappHeader>` (also re-exported from `/ui`) |
|
|
30
|
+
| `@glassly/miniapp/protocol` | `MiniappRequestType`, `MiniappResponseType`, `MiniappStreamType`, `MiniappErrorCode` |
|
|
31
|
+
|
|
32
|
+
> **Two layers.** Miniapps split into an always-on **background** layer that
|
|
33
|
+
> owns the `MiniappSession` (`@glassly/miniapp/background`, entered via
|
|
34
|
+
> `registerMiniapp(session => …)`) and a **UI** layer that renders inside the
|
|
35
|
+
> WebView and talks to background over the injected `glassly` channel bridge
|
|
36
|
+
> (`@glassly/miniapp/ui`). The UI side does **not** construct a session. See
|
|
37
|
+
> [`sdk/docs/two-layer.md`](../../../sdk/docs/two-layer.md).
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
Background layer (owns the session):
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import {registerMiniapp} from "@glassly/miniapp/background"
|
|
45
|
+
|
|
46
|
+
// registerMiniapp constructs the session and connects it (CONNECT / CONNECT_ACK)
|
|
47
|
+
// before invoking your handler.
|
|
48
|
+
registerMiniapp((session) => {
|
|
49
|
+
// render() replaces the whole frame; stable ids update in place, render([]) clears.
|
|
50
|
+
const box = {x: 0, y: 0, w: 576, h: 288} // raw device px — see session.capabilities.display
|
|
51
|
+
session.display.render([{type: "text", id: "hello", box, text: "hello"}])
|
|
52
|
+
const unsub = session.transcription.on((d) => session.display.render([{type: "text", id: "hello", box, text: d.text}]))
|
|
53
|
+
// later: unsub()
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
UI layer (WebView React app — no session here):
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import {MiniappProvider, useConnected} from "@glassly/miniapp/ui"
|
|
61
|
+
|
|
62
|
+
function App() {
|
|
63
|
+
const ready = useConnected()
|
|
64
|
+
// talk to the background layer over the injected `glassly` channel bridge
|
|
65
|
+
// ...
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// root:
|
|
69
|
+
;<MiniappProvider>
|
|
70
|
+
<App />
|
|
71
|
+
</MiniappProvider>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Session
|
|
75
|
+
|
|
76
|
+
`MiniappSession` is the only object you construct. It owns the transport, the request/response correlation map, the pre-ready outbound queue, the keepalive PONG, and the cached visibility / capabilities / color-scheme / permissions state.
|
|
77
|
+
|
|
78
|
+
### Lifecycle
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const session = new MiniappSession(options?)
|
|
82
|
+
await session.connect() // idempotent; same Promise on repeat calls
|
|
83
|
+
session.isConnected()
|
|
84
|
+
session.disconnect()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`MiniappSessionOptions`:
|
|
88
|
+
|
|
89
|
+
- `packageName?: string` — overrides auto-detection from `window.Glassly`
|
|
90
|
+
- `connectTimeoutMs?: number` — defaults to 10s
|
|
91
|
+
- transport-selection options from `createTransport` (`mode`, `transport`, `localSocket`)
|
|
92
|
+
|
|
93
|
+
### Lifecycle events
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const off = session.on("ready", () => {})
|
|
97
|
+
session.off("ready", handler)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
| Event | Signature |
|
|
101
|
+
| -------------- | --------------------------------------------- |
|
|
102
|
+
| `ready` | `() => void` — fires after CONNECT_ACK |
|
|
103
|
+
| `disconnect` | `(reason: string) => void` |
|
|
104
|
+
| `error` | `(err: Error) => void` |
|
|
105
|
+
| `visibility` | `("foreground" \| "background") => void` |
|
|
106
|
+
| `capabilities` | `(caps: GlassesCapabilities \| null) => void` |
|
|
107
|
+
| `colorScheme` | `("light" \| "dark") => void` |
|
|
108
|
+
| `permissions` | `(perms: PermissionRecord) => void` |
|
|
109
|
+
| `speakerState` | `(event: SpeakerStateEvent) => void` |
|
|
110
|
+
|
|
111
|
+
Convenience wrappers: `onVisibilityChange`, `onCapabilitiesChange`, `onColorSchemeChange`. Each `on(...)` call also returns an unsubscribe function.
|
|
112
|
+
|
|
113
|
+
### Cached state
|
|
114
|
+
|
|
115
|
+
`session.userId`, `session.packageName`, `session.capabilities`, `session.visibility`, `session.colorScheme`, `session.ready` — populated from `CONNECT_ACK` and kept in sync via the lifecycle events above.
|
|
116
|
+
|
|
117
|
+
## Modules
|
|
118
|
+
|
|
119
|
+
All event subscribers return an `UnsubscribeFn`. Subscriptions are ref-counted: the SDK sends `SUBSCRIBE` when a stream's active state or routing metadata changes.
|
|
120
|
+
|
|
121
|
+
| Module | Methods |
|
|
122
|
+
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
123
|
+
| `session.display` | `render(elements, opts?)` — scene API: diffed frames, stable-id in-place updates, `render([])` clears |
|
|
124
|
+
| `session.speaker` | `play({audioUrl})`, `speak(text, options?)`, `createStream({sampleRate?, volume?})` for bounded 16-bit PCM output, `stop()`, `onStateChange(handler)` |
|
|
125
|
+
| `session.mic` | `onAudioChunk(handler)`, `onVoiceActivity(handler)`, `stop()`, `hasPermission` |
|
|
126
|
+
| `session.transcription` | `on(handler, {forceLocal?})`, `forLanguage(lang \| [langs], handler, {forceLocal?})`, `configure({languageHints, vocabulary, diarization})`, `stop()`, `hasPermission` |
|
|
127
|
+
| `session.translation` | `forLanguagePair(from, to, handler)`, `stop()`, `hasPermission` |
|
|
128
|
+
| `session.input` | `onButtonPress(handler)`, `onTouch(handler \| gesture, handler \| gestures, handler)` |
|
|
129
|
+
| `session.location` | `onUpdate(handler)`, `hasPermission` |
|
|
130
|
+
| `session.imu` | `onHeadPosition(handler)` |
|
|
131
|
+
| `session.glasses` | `onBattery(handler)`, `onConnection(handler)` |
|
|
132
|
+
| `session.phone.notifications` | `on(handler)`, `onDismissed(handler)`, `stop()`, `hasPermission` |
|
|
133
|
+
| `session.phone.calendar` | `listEvents({startsAt, endsAt, limit?})`, `hasPermission` |
|
|
134
|
+
| `session.phone` | `onBattery(handler)` |
|
|
135
|
+
| `session.system` | `share(opts)`, `openUrl(url)`, `copyToClipboard(text)`, `download(opts)` |
|
|
136
|
+
| `session.camera` | `takePhoto({size?, mode?, transferMethod?, compress?, sound?, saveToGallery?, zsl?, mfnr?, timeoutMs?, ...})`, `setFov({fov, roiPosition?} \| {preset})`, `hasPermission` |
|
|
137
|
+
| `session.led` | `turnOn({color?, ontime?, offtime?, count?})`, `turnOff()`, `blink(color, ontime, offtime, count)`, `solid(color, duration)` — resolve after the glasses acknowledge the RGB command |
|
|
138
|
+
| `session.permissions` | `has(type)`, `getAll()`, `onUpdate(handler)`, `onPermissionError(handler)` |
|
|
139
|
+
| `session.storage` | `get(key)`, `set(key, value)`, `delete(key)`, `list()` — strings only, scoped to `(userId, packageName)` |
|
|
140
|
+
| `session.stream` | `startUnmanaged({streamUrl, video?, audio?, sound?})`, `startManaged({restreamDestinations?, video?, audio?, sound?, ingest?})`, `stop(streamId?)` — stream video input fields are `width`, `height`, `bitrate`, and `fps`; resolved status reports effective frame rate as `resolvedConfig.video.fps`. Start resolves with `{streamId, status, resolvedConfig?}` after glasses report the publisher is streaming; managed starts also return playback URLs; `ingest` selects `"srt"` for HLS/recording or `"whip"` for low-latency WebRTC; stop is idempotent for an already-stopped stream |
|
|
141
|
+
| `session.dashboard` | `setContent(mode, content)` — **noop in v1**, prints a one-time `console.warn`. Cloud DashboardManager owns rendering. |
|
|
142
|
+
|
|
143
|
+
`session.events` is **internal**. It exposes `subscribe(rawStreamType, handler)` only as a forward-compat escape hatch for new event types not yet wrapped on a domain module — prefer the typed module surface.
|
|
144
|
+
|
|
145
|
+
### Camera FOV
|
|
146
|
+
|
|
147
|
+
`await session.camera.setFov({fov, roiPosition})` applies a temporary, miniapp-owned FOV/ROI override and resolves with `CameraFovResult` after the ASG client reports the setting was applied following the camera restart cooldown. The host restores the previous live miniapp override—or the persistent 118-degree full-sensor base—when this miniapp closes. `roiPosition` accepts `"center"`, `"bottom"`, or `"top"` and defaults to `"center"`. You can also call `setFov({preset: "narrow" | "standard" | "wide"})`; presets map to 82, 102, and 118 degrees with center ROI. The call requires `CAMERA` in `miniapp.json` and rejects with `MiniappRequestError` if the host or glasses cannot apply it.
|
|
148
|
+
|
|
149
|
+
### Camera Photos
|
|
150
|
+
|
|
151
|
+
`await session.camera.takePhoto(...)` resolves only after the photo is delivered through the phone/cloud upload path. The result includes `{requestId, photoUrl, mimeType, size}`. Glasses-side or phone-relay failures such as `CAMERA_BUSY`, `BATTERY_LOW`, storage errors, or fallback upload failures reject before upload polling completes; intermediate `photo_status` progress and request acceptance alone do not resolve the miniapp photo promise.
|
|
152
|
+
|
|
153
|
+
Pass `transferMethod: "ble"` to skip direct Wi-Fi upload and always relay the image through the phone over Bluetooth. The default `"auto"` mode tries direct upload first and falls back to BLE.
|
|
154
|
+
|
|
155
|
+
### Transcription language convention
|
|
156
|
+
|
|
157
|
+
Transcription/translation streams use a colon-suffixed wire format: `transcription:en-US`, `translation:en-US:fr-FR`. `session.transcription.on(handler)` subscribes to `transcription:auto` (cloud auto-detects). The detected language is in the payload. A handler on `transcription:auto` receives any `transcription:<lang>` event — wildcard fan-out — so "give me transcripts in whatever language" works without manual wiring. Use `session.transcription.forLanguage(lang | [langs], handler)` to pin specific languages. Pass `{forceLocal: true}` as the final argument to either method to require on-device transcription and suppress cloud results for that subscription. Routing is per listener, so a default listener on the same stream can continue receiving cloud transcription.
|
|
158
|
+
|
|
159
|
+
### Permissions semantics
|
|
160
|
+
|
|
161
|
+
`session.permissions.has("microphone")` returns whether the manifest declared the permission. Same semantics as cloud SDK v3. **It does NOT report OS-level grant state** — even when `has(...)` returns `true` the user can have denied the OS prompt and your subscriptions will silently receive no events. OS-grant tracking and `request(...)` are deferred and will land additively on the same module.
|
|
162
|
+
|
|
163
|
+
`PermissionType` is the lowercase canonical union: `"location" | "microphone" | "camera" | "notifications" | "calendar"`. Manifest UPPER_CASE names map onto these (`BACKGROUND_LOCATION` → `location`; `READ_NOTIFICATIONS`, `POST_NOTIFICATIONS` → `notifications`).
|
|
164
|
+
|
|
165
|
+
## React bindings — `@glassly/miniapp/ui`
|
|
166
|
+
|
|
167
|
+
These UI-layer hooks run inside the WebView and read host state via the injected
|
|
168
|
+
`glassly` channel bridge / `window.Glassly` globals — they do **not** own a
|
|
169
|
+
`MiniappSession` (that lives in the background layer). They are also re-exported
|
|
170
|
+
from `@glassly/miniapp/react` for backwards-compat.
|
|
171
|
+
|
|
172
|
+
| Hook | Returns |
|
|
173
|
+
| ------------------------- | ------------------------------------------------------------------------------------------ |
|
|
174
|
+
| `useConnected()` | `boolean` — true while the `glassly` bridge is open (`onOpen` / `onClose`) |
|
|
175
|
+
| `useCapabilities()` | Glasses capability profile — currently always `null` on the UI side (caps arrive over a channel) |
|
|
176
|
+
| `useColorScheme()` | `"light" \| "dark"` (host theme) |
|
|
177
|
+
| `useSafeArea()` | `{insets, capsuleMenu}` — pixel insets + bounding rect of the host's floating capsule menu |
|
|
178
|
+
| `useCapsuleHeaderStyle()` | Pre-computed CSS for a header row that aligns with the capsule menu |
|
|
179
|
+
| `useRpc(...)` | Typed request helper over the `glassly` channel bridge |
|
|
180
|
+
|
|
181
|
+
Components:
|
|
182
|
+
|
|
183
|
+
- `<MiniappProvider>` — root provider. Keeps `<html class="dark">` in sync with the host color scheme during render (no FOUC).
|
|
184
|
+
- `<MiniappHeader title="…" left={…} right={…} onBack={…} />` — drop-in header that respects the safe area and leaves room for the capsule menu.
|
|
185
|
+
|
|
186
|
+
## Manifest — `miniapp.json`
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"packageName": "com.glassly.example",
|
|
191
|
+
"version": "1.0.0",
|
|
192
|
+
"name": "Live Captions",
|
|
193
|
+
"description": "…",
|
|
194
|
+
"icon": "icon.png",
|
|
195
|
+
"permissions": [{"type": "MICROPHONE", "description": "…"}],
|
|
196
|
+
"hardwareRequirements": [
|
|
197
|
+
{"type": "DISPLAY", "level": "REQUIRED"},
|
|
198
|
+
{"type": "MICROPHONE", "level": "REQUIRED"}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- `permissions[].type` ∈ `MICROPHONE | CAMERA | CALENDAR | LOCATION | BACKGROUND_LOCATION | READ_NOTIFICATIONS | POST_NOTIFICATIONS`
|
|
204
|
+
- `hardwareRequirements[].type` ∈ `CAMERA | DISPLAY | MICROPHONE | SPEAKER | IMU | BUTTON | LIGHT | WIFI`, `level` ∈ `REQUIRED | OPTIONAL`
|
|
205
|
+
|
|
206
|
+
The CLI validates the manifest on every `dev`, `release`, and `pack`. Run `glassly-miniapp schema print` for the canonical JSON Schema.
|
|
207
|
+
|
|
208
|
+
## CLI
|
|
209
|
+
|
|
210
|
+
The author-facing CLI lives in a sibling package: **[`@glassly/miniapp-cli`](../../../sdk/miniapp-cli/README.md)** (binary: `glassly-miniapp`). Full per-command docs there. Quick map:
|
|
211
|
+
|
|
212
|
+
| Command | Purpose |
|
|
213
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
214
|
+
| `glassly-miniapp dev` | Hot-reload dev server + QR sideload onto a phone over LAN |
|
|
215
|
+
| `glassly-miniapp release` | Build, pack, and serve a QR to install on a phone |
|
|
216
|
+
| `glassly-miniapp pack` | Validate manifest and zip `dist/` into `<pkg>-<version>.zip` |
|
|
217
|
+
| `glassly-miniapp manifest` | Interactive top-level wizard for `miniapp.json` |
|
|
218
|
+
| `glassly-miniapp permission list \| add \| remove [TYPE]` | Object-verb manifest edits for permissions |
|
|
219
|
+
| `glassly-miniapp hardware list \| add \| remove [TYPE] [LEVEL]` | Object-verb manifest edits for hardware requirements |
|
|
220
|
+
| `glassly-miniapp schema print` | Print the canonical `miniapp.json` JSON Schema |
|
|
221
|
+
|
|
222
|
+
See [the CLI README](../../../sdk/miniapp-cli/README.md) for flags, semantics, and the `miniapp://` URL schemes the QR codes encode.
|
|
223
|
+
|
|
224
|
+
## Host-injected globals — `window.Glassly`
|
|
225
|
+
|
|
226
|
+
The Glassly app injects this before content loads. Authors generally use the React hooks instead, but the raw shape is:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
{
|
|
230
|
+
packageName, platform, capabilities,
|
|
231
|
+
miniappLocal, miniappDeveloperMode,
|
|
232
|
+
safeAreaInsets: {top, bottom, left, right},
|
|
233
|
+
capsuleMenu: {top, right, bottom, left, width, height},
|
|
234
|
+
colorScheme: "light" | "dark"
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Use `getGlasslyGlobals()` (exported from the package) to read it with the right TypeScript types.
|
|
239
|
+
|
|
240
|
+
## Transports
|
|
241
|
+
|
|
242
|
+
Auto-selected by `createTransport(options)`:
|
|
243
|
+
|
|
244
|
+
- **`PostMessageTransport`** — used inside the Glassly WebView. `window.ReactNativeWebView.postMessage` outbound, `window` `message` listener inbound.
|
|
245
|
+
- **`LocalSocketTransport`** — fallback for laptop browsers. Default endpoint `ws://127.0.0.1:8765`. The in-laptop-browser dev story is currently broken; see the overview doc for status.
|
|
246
|
+
|
|
247
|
+
Both are exported for advanced uses (forced transport, tests). `MockTransport` is also exported for unit tests.
|
|
248
|
+
|
|
249
|
+
## Wire protocol
|
|
250
|
+
|
|
251
|
+
Every message is a `{payload, requestId?}` envelope, JSON over the chosen transport. `requestId` correlates request ↔ response for methods that return a value. Constants live in `@glassly/miniapp/protocol`:
|
|
252
|
+
|
|
253
|
+
- `MiniappRequestType` — `CONNECT`, `SUBSCRIBE`, etc.
|
|
254
|
+
- `MiniappResponseType` — `CONNECT_ACK`, `EVENT`, `REQUEST_RESULT`, `PERMISSIONS_UPDATE`, …
|
|
255
|
+
- `MiniappStreamType` — typed names for stream identifiers
|
|
256
|
+
- `MiniappErrorCode` — `NOT_CONNECTED`, `PERMISSION_NOT_DECLARED`, …
|
|
257
|
+
|
|
258
|
+
Full enum listings in [`src/protocol.ts`](./src/protocol.ts).
|
|
259
|
+
|
|
260
|
+
## Controller pattern (recommended)
|
|
261
|
+
|
|
262
|
+
Smart-glasses miniapps are **always-on services**. The webview is a UI on top of a continuously-running session. If you tie subscriptions to React component lifecycle, closing or navigating away from a page also stops the glasses behavior — wrong shape for glasses.
|
|
263
|
+
|
|
264
|
+
**Rule:** user-facing glasses logic lives in a session-scoped controller, instantiated once at module init. React pages read controller-driven state via a store (Zustand recommended) and call imperative methods on the controller for user-triggered actions. They do **not** subscribe to `session.*` directly.
|
|
265
|
+
|
|
266
|
+
See [`miniapps/example-miniapp/src/background/controllers/GlassesController.ts`](../../../miniapps/example-miniapp/src/background/controllers/GlassesController.ts) for a worked reference.
|
|
267
|
+
|
|
268
|
+
**Tester pages exception:** `pages/tester/*` are diagnostic surfaces — by design they inline-subscribe to `session.*` and tear down on unmount. This is the only place where that pattern is acceptable.
|
|
269
|
+
|
|
270
|
+
## File map
|
|
271
|
+
|
|
272
|
+
- Runtime: [`src/{session,protocol,envelope,globals}.ts`](./src/), [`src/modules/`](./src/modules/), [`src/transport/`](./src/transport/), [`src/react/`](./src/react/)
|
|
273
|
+
- CLI: [`../miniapp-cli/src/`](../../../sdk/miniapp-cli/src/)
|
|
274
|
+
- Scaffolder: [`../create-miniapp/`](../../../sdk/create-miniapp/)
|
|
275
|
+
- Reference miniapp: [`miniapps/example-miniapp/`](../../../miniapps/example-miniapp/)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @glassly/miniapp/background — background-side SDK entry point.
|
|
3
|
+
*
|
|
4
|
+
* Imported from a miniapp's `src/background/index.ts` to access the
|
|
5
|
+
* per-miniapp `MiniappSession` and its typed `session.*` module
|
|
6
|
+
* wrappers. This is the **always-running JSContext side** of a two-layer
|
|
7
|
+
* miniapp.
|
|
8
|
+
*
|
|
9
|
+
* What's NOT in this entry point:
|
|
10
|
+
* - `glassly` WebView global (UI-only — import from `@glassly/miniapp/ui`).
|
|
11
|
+
* - `MiniappProvider` / React hooks (UI-only).
|
|
12
|
+
* - Any DOM-bound API. The JSContext has no DOM.
|
|
13
|
+
*
|
|
14
|
+
* Importing the wrong sub-path is caught at compile time by the
|
|
15
|
+
* separate type-roots on each `exports` entry.
|
|
16
|
+
*/
|
|
17
|
+
export { MiniappSession, type MiniappSessionOptions } from "../session";
|
|
18
|
+
export { registerMiniapp, type MiniappInitHandler, type TypedMiniappSession } from "./register";
|
|
19
|
+
export type { TranscriptionData, TranslationData, ButtonPressData, AudioChunkData, VadData, BatteryData, ConnectionData, WifiData, HeadPositionData, AccelData, LocationData, PhoneNotificationData, NotificationDismissedData, HeadingData, TouchData, UnsubscribeFn, } from "../modules/events";
|
|
20
|
+
export type { CalendarEvent, CalendarListOptions, CalendarListResult } from "../modules/phone";
|
|
21
|
+
export { MiniappRequestType, MiniappResponseType, MiniappStreamType, MiniappErrorCode } from "../protocol";
|
|
22
|
+
export { MiniappValidationError, SUPPORTED_LANGUAGE_HINTS, SUPPORTED_TRANSCRIPTION_LANGUAGES, isTranscriptionLanguage, } from "../modules/languages";
|
|
23
|
+
export type { LanguageHint, TranscriptionLanguage } from "../modules/languages";
|
|
24
|
+
export type { ActionContext, ActionHandler, InvokeOptions } from "../modules/actions";
|
|
25
|
+
export type { DisplayManager } from "../modules/display";
|
|
26
|
+
export type { CameraFovPreset, CameraFovRequest, CameraFovResult, CameraModule, CameraRoiPosition, SetCameraFovOptions, } from "../modules/camera";
|
|
27
|
+
export type { CloudClientAudioTransport, CloudClientConnectionStatus, CloudClientStatus, CloudModule, } from "../modules/cloud";
|
|
28
|
+
export type { DashboardAPI } from "../modules/dashboard";
|
|
29
|
+
export type { GlassesModule } from "../modules/glasses";
|
|
30
|
+
export type { HeadingModule } from "../modules/heading";
|
|
31
|
+
export type { ImuModule } from "../modules/imu";
|
|
32
|
+
export type { InputModule } from "../modules/input";
|
|
33
|
+
export type { LedModule } from "../modules/led";
|
|
34
|
+
export type { LocationModule } from "../modules/location";
|
|
35
|
+
export type { MemoryModule, MemoryEntry, MemoryEntryKind, MemoryNoteSource, MemoryQuery, MemorySession, MemorySummary, } from "../modules/memory";
|
|
36
|
+
export type { SpeakersModule } from "../modules/speakers";
|
|
37
|
+
export type { MicModule } from "../modules/mic";
|
|
38
|
+
export type { NavigationModule } from "../modules/navigation";
|
|
39
|
+
export type { PermissionsModule } from "../modules/permissions";
|
|
40
|
+
export type { PhoneModule } from "../modules/phone";
|
|
41
|
+
export type { SimpleStorage } from "../modules/storage";
|
|
42
|
+
export { BlobModule, BlobWriter, BlobReader, BLOB_WRITE_CHUNK_BYTES, BLOB_READ_ALL_MAX_BYTES } from "../modules/blob";
|
|
43
|
+
export type { BlobMeta, BlobSetOptions, BlobSetFromUrlOptions, BlobImportOptions } from "../modules/blob";
|
|
44
|
+
export { bytesToBase64, base64ToBytes } from "../modules/base64";
|
|
45
|
+
export type { SpeakerModule } from "../modules/speaker";
|
|
46
|
+
export type { StreamModule } from "../modules/stream";
|
|
47
|
+
export type { SystemModule } from "../modules/system";
|
|
48
|
+
export type { TranscriptionModule } from "../modules/transcription";
|
|
49
|
+
export type { TranslationModule } from "../modules/translation";
|
|
50
|
+
export type { UIModule, UIChannelHandler, UIUnsubscribe } from "../modules/ui";
|
|
51
|
+
export type { Rpc, IsRpc, RpcReq, RpcRes, RpcRequestOptions, RpcHandlerContext } from "../modules/ui";
|
|
52
|
+
export { RpcError, RpcTimeoutError } from "../modules/ui";
|
|
53
|
+
export type { LedColor, LedControlOptions } from "../modules/led";
|
|
54
|
+
export type { ViewType, DisplayBreakMode, RenderBox, RenderElement, RenderOptions, RenderRectStyle, RenderResult, RenderTextStyle, } from "../modules/display";
|
|
55
|
+
export type { DashboardMode, ShowNativeDashboardResult } from "../modules/dashboard";
|
|
56
|
+
export type { PlayAudioOptions, SpeakOptions, SpeakResult, SpeakerState, SpeakerStateEvent } from "../modules/speaker";
|
|
57
|
+
export type { ShareOptions, ShareResult, DownloadOptions, DownloadResult, ScanQrOptions, ScanQrResult, } from "../modules/system";
|
|
58
|
+
export type { TranscriptionConfig, TranscriptionOptions } from "../modules/transcription";
|
|
59
|
+
export type { PermissionErrorEvent } from "../modules/permissions";
|
|
60
|
+
export type { AuthUpdatePayload, MiniappVisibility, PermissionType, PermissionRecord, GlassesCapabilities, ConnectAckPayload, MiniappAuthState, MiniappRequestError, } from "../session";
|
|
61
|
+
export type { AuthFetchOptions, AuthModule } from "../modules/auth";
|
|
62
|
+
export type { MiniappColorScheme } from "../globals";
|
|
63
|
+
export type { LatLng, TravelMode, ManeuverKind, RouteAvoidances, NavManeuver, NavOffRoute, NavRerouting, NavArrived, NavError, NavCancelled, NavUpdate, NavRoute, PivotOptions, Pivot, PivotEvent, NavStep, NavigationDev, StartNavigationOptions, NavState, NavPermissionResult, ComputeRouteOptions, ComputedRouteStep, ComputedRoute, ComputeRouteResult, } from "../modules/navigation";
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @glassly/miniapp/background — background-side SDK entry point.
|
|
3
|
+
*
|
|
4
|
+
* Imported from a miniapp's `src/background/index.ts` to access the
|
|
5
|
+
* per-miniapp `MiniappSession` and its typed `session.*` module
|
|
6
|
+
* wrappers. This is the **always-running JSContext side** of a two-layer
|
|
7
|
+
* miniapp.
|
|
8
|
+
*
|
|
9
|
+
* What's NOT in this entry point:
|
|
10
|
+
* - `glassly` WebView global (UI-only — import from `@glassly/miniapp/ui`).
|
|
11
|
+
* - `MiniappProvider` / React hooks (UI-only).
|
|
12
|
+
* - Any DOM-bound API. The JSContext has no DOM.
|
|
13
|
+
*
|
|
14
|
+
* Importing the wrong sub-path is caught at compile time by the
|
|
15
|
+
* separate type-roots on each `exports` entry.
|
|
16
|
+
*/
|
|
17
|
+
export { MiniappSession } from "../session";
|
|
18
|
+
export { registerMiniapp } from "./register";
|
|
19
|
+
// Public envelope + protocol types so authors can write strongly-typed
|
|
20
|
+
// glue when they need to fall back to session.sendOneShot / sendRequest.
|
|
21
|
+
export { MiniappRequestType, MiniappResponseType, MiniappStreamType, MiniappErrorCode } from "../protocol";
|
|
22
|
+
export { MiniappValidationError, SUPPORTED_LANGUAGE_HINTS, SUPPORTED_TRANSCRIPTION_LANGUAGES, isTranscriptionLanguage, } from "../modules/languages";
|
|
23
|
+
export { BlobModule, BlobWriter, BlobReader, BLOB_WRITE_CHUNK_BYTES, BLOB_READ_ALL_MAX_BYTES } from "../modules/blob";
|
|
24
|
+
export { bytesToBase64, base64ToBytes } from "../modules/base64";
|
|
25
|
+
export { RpcError, RpcTimeoutError } from "../modules/ui";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAC,cAAc,EAA6B,MAAM,YAAY,CAAA;AACrE,OAAO,EAAC,eAAe,EAAoD,MAAM,YAAY,CAAA;AAwB7F,uEAAuE;AACvE,yEAAyE;AACzE,OAAO,EAAC,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAA;AACxG,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AA+C7B,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,sBAAsB,EAAE,uBAAuB,EAAC,MAAM,iBAAiB,CAAA;AAEnH,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAQ9D,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* registerMiniapp — entry hook for the background JSContext.
|
|
3
|
+
*
|
|
4
|
+
* The GlasslyJS host loads the polyfill (which installs __dispatch /
|
|
5
|
+
* __deliver / timers / fetch / etc.), then evaluates the miniapp's
|
|
6
|
+
* background bundle. After both scripts have evaluated successfully,
|
|
7
|
+
* the host delivers a single `{kind: "init", sessionId}` envelope.
|
|
8
|
+
* The polyfill turns that into a call to `__initCallback(sessionId)`.
|
|
9
|
+
*
|
|
10
|
+
* This module wires that callback to:
|
|
11
|
+
* 1. Construct a `MiniappSession` (DispatchTransport picks itself
|
|
12
|
+
* automatically because `__dispatch` is on globalThis).
|
|
13
|
+
* 2. Call the user-supplied handler synchronously so subscriptions
|
|
14
|
+
* are registered before any host events fan out.
|
|
15
|
+
* 3. Call `session.connect()` so the host receives CONNECT and the
|
|
16
|
+
* first CONNECT_ACK populates `userId`, `capabilities`, etc.
|
|
17
|
+
*
|
|
18
|
+
* The handler runs once per spawn. If the host kills + respawns the
|
|
19
|
+
* JSContext (crash recovery, dev reload), the polyfill + bundle are
|
|
20
|
+
* re-evaluated and the handler fires again with a fresh session.
|
|
21
|
+
*/
|
|
22
|
+
import { MiniappSession, type MiniappSessionOptions } from "../session";
|
|
23
|
+
export type TypedMiniappSession<TChannels extends object> = MiniappSession<TChannels>;
|
|
24
|
+
export type MiniappInitHandler<TChannels extends object = Record<string, unknown>> = (session: TypedMiniappSession<TChannels>) => void | Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Register the miniapp's startup handler. Call once at the top level of
|
|
27
|
+
* `src/background/index.ts`. Top-level side effects are fine, but the
|
|
28
|
+
* vast majority of setup should live inside the handler so it can run
|
|
29
|
+
* with a connected session.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* registerMiniapp((session) => {
|
|
33
|
+
* session.transcription.on((tx) => {
|
|
34
|
+
* session.display.render([{type: "text", id: "tx", box, text: tx.text}])
|
|
35
|
+
* })
|
|
36
|
+
* })
|
|
37
|
+
*/
|
|
38
|
+
export declare function registerMiniapp<TChannels extends object = Record<string, unknown>>(handler: MiniappInitHandler<TChannels>, options?: MiniappSessionOptions): void;
|
|
39
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/background/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAC,cAAc,EAAE,KAAK,qBAAqB,EAAC,MAAM,YAAY,CAAA;AAErE,MAAM,MAAM,mBAAmB,CAAC,SAAS,SAAS,MAAM,IAAI,cAAc,CAAC,SAAS,CAAC,CAAA;AAErF,MAAM,MAAM,kBAAkB,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACnF,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,KACpC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAYzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChF,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,EACtC,OAAO,GAAE,qBAA0B,GAClC,IAAI,CAgCN"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* registerMiniapp — entry hook for the background JSContext.
|
|
3
|
+
*
|
|
4
|
+
* The GlasslyJS host loads the polyfill (which installs __dispatch /
|
|
5
|
+
* __deliver / timers / fetch / etc.), then evaluates the miniapp's
|
|
6
|
+
* background bundle. After both scripts have evaluated successfully,
|
|
7
|
+
* the host delivers a single `{kind: "init", sessionId}` envelope.
|
|
8
|
+
* The polyfill turns that into a call to `__initCallback(sessionId)`.
|
|
9
|
+
*
|
|
10
|
+
* This module wires that callback to:
|
|
11
|
+
* 1. Construct a `MiniappSession` (DispatchTransport picks itself
|
|
12
|
+
* automatically because `__dispatch` is on globalThis).
|
|
13
|
+
* 2. Call the user-supplied handler synchronously so subscriptions
|
|
14
|
+
* are registered before any host events fan out.
|
|
15
|
+
* 3. Call `session.connect()` so the host receives CONNECT and the
|
|
16
|
+
* first CONNECT_ACK populates `userId`, `capabilities`, etc.
|
|
17
|
+
*
|
|
18
|
+
* The handler runs once per spawn. If the host kills + respawns the
|
|
19
|
+
* JSContext (crash recovery, dev reload), the polyfill + bundle are
|
|
20
|
+
* re-evaluated and the handler fires again with a fresh session.
|
|
21
|
+
*/
|
|
22
|
+
import { MiniappSession } from "../session";
|
|
23
|
+
/**
|
|
24
|
+
* Register the miniapp's startup handler. Call once at the top level of
|
|
25
|
+
* `src/background/index.ts`. Top-level side effects are fine, but the
|
|
26
|
+
* vast majority of setup should live inside the handler so it can run
|
|
27
|
+
* with a connected session.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* registerMiniapp((session) => {
|
|
31
|
+
* session.transcription.on((tx) => {
|
|
32
|
+
* session.display.render([{type: "text", id: "tx", box, text: tx.text}])
|
|
33
|
+
* })
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export function registerMiniapp(handler, options = {}) {
|
|
37
|
+
const g = globalThis;
|
|
38
|
+
g.__initCallback = (_sessionId) => {
|
|
39
|
+
const session = new MiniappSession(options);
|
|
40
|
+
// Fire the user handler first so any session.* subscriptions get
|
|
41
|
+
// registered before the CONNECT_ACK fan-out lands.
|
|
42
|
+
try {
|
|
43
|
+
const result = handler(session);
|
|
44
|
+
if (result && typeof result.then === "function") {
|
|
45
|
+
;
|
|
46
|
+
result.catch((err) => {
|
|
47
|
+
console.error("[glassly-miniapp] registerMiniapp handler rejected:", err);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error("[glassly-miniapp] registerMiniapp handler threw:", err);
|
|
53
|
+
}
|
|
54
|
+
session.connect().catch((err) => {
|
|
55
|
+
console.error("[glassly-miniapp] session.connect() rejected:", err);
|
|
56
|
+
// Surface to the host's crash controller as a structured uncaught
|
|
57
|
+
// error so the existing backoff + crashloop machinery handles it.
|
|
58
|
+
// Repeated connect failures eventually flip the miniapp to
|
|
59
|
+
// CRASHLOOP_DISABLED, which the host turns into a user-facing
|
|
60
|
+
// alert + automatic incident report.
|
|
61
|
+
try {
|
|
62
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
63
|
+
const stack = err instanceof Error && err.stack ? err.stack : "";
|
|
64
|
+
g.__hostError?.(JSON.stringify({ message: `session.connect() failed: ${message}`, stack }));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* host bridge missing in tests — ignore */
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/background/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAC,cAAc,EAA6B,MAAM,YAAY,CAAA;AAkBrE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAsC,EACtC,UAAiC,EAAE;IAEnC,MAAM,CAAC,GAAG,UAAoC,CAAA;IAC9C,CAAC,CAAC,cAAc,GAAG,CAAC,UAAkB,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAY,OAAO,CAAC,CAAA;QACtD,iEAAiE;QACjE,mDAAmD;QACnD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;YAC/B,IAAI,MAAM,IAAI,OAAQ,MAAwB,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACnE,CAAC;gBAAC,MAAwB,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;oBAChD,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAA;gBAC3E,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,kDAAkD,EAAE,GAAG,CAAC,CAAA;QACxE,CAAC;QACD,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,+CAA+C,EAAE,GAAG,CAAC,CAAA;YACnE,kEAAkE;YAClE,kEAAkE;YAClE,2DAA2D;YAC3D,8DAA8D;YAC9D,qCAAqC;YACrC,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBAChE,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;gBAChE,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,OAAO,EAAE,6BAA6B,OAAO,EAAE,EAAE,KAAK,EAAC,CAAC,CAAC,CAAA;YAC3F,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SDK-side dev-reload listener — auto-installed when the host
|
|
3
|
+
* indicates we're running in a dev miniapp.
|
|
4
|
+
*
|
|
5
|
+
* Companion to the phone-side console-tap shim (which is injected by the
|
|
6
|
+
* Glassly app, not by the SDK). The SDK installs this listener on import so
|
|
7
|
+
* authors get live reload without any opt-in code.
|
|
8
|
+
*
|
|
9
|
+
* Mechanism:
|
|
10
|
+
* - Phone-side `DevServerBridge` receives `{type: "reload"}` from the dev
|
|
11
|
+
* server's WebSocket.
|
|
12
|
+
* - Phone-side `MiniappHost` then injects a `MessageEvent` into the WebView
|
|
13
|
+
* with payload `{type: "miniapp_dev_reload"}`.
|
|
14
|
+
* - This listener catches that MessageEvent and calls `location.reload()`.
|
|
15
|
+
*
|
|
16
|
+
* Gated on `window.Glassly.miniappDeveloperMode === true` so production
|
|
17
|
+
* miniapps never set up the listener. In production WebViews the host won't
|
|
18
|
+
* inject the message anyway, but belt-and-suspenders.
|
|
19
|
+
*/
|
|
20
|
+
export declare function installDevReloadListenerIfDevMode(): void;
|
|
21
|
+
//# sourceMappingURL=dev-reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-reload.d.ts","sourceRoot":"","sources":["../src/dev-reload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,wBAAgB,iCAAiC,IAAI,IAAI,CAoCxD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SDK-side dev-reload listener — auto-installed when the host
|
|
3
|
+
* indicates we're running in a dev miniapp.
|
|
4
|
+
*
|
|
5
|
+
* Companion to the phone-side console-tap shim (which is injected by the
|
|
6
|
+
* Glassly app, not by the SDK). The SDK installs this listener on import so
|
|
7
|
+
* authors get live reload without any opt-in code.
|
|
8
|
+
*
|
|
9
|
+
* Mechanism:
|
|
10
|
+
* - Phone-side `DevServerBridge` receives `{type: "reload"}` from the dev
|
|
11
|
+
* server's WebSocket.
|
|
12
|
+
* - Phone-side `MiniappHost` then injects a `MessageEvent` into the WebView
|
|
13
|
+
* with payload `{type: "miniapp_dev_reload"}`.
|
|
14
|
+
* - This listener catches that MessageEvent and calls `location.reload()`.
|
|
15
|
+
*
|
|
16
|
+
* Gated on `window.Glassly.miniappDeveloperMode === true` so production
|
|
17
|
+
* miniapps never set up the listener. In production WebViews the host won't
|
|
18
|
+
* inject the message anyway, but belt-and-suspenders.
|
|
19
|
+
*/
|
|
20
|
+
const RELOAD_MESSAGE_TYPE = "miniapp_dev_reload";
|
|
21
|
+
export function installDevReloadListenerIfDevMode() {
|
|
22
|
+
if (typeof window === "undefined")
|
|
23
|
+
return;
|
|
24
|
+
const glassly = window.Glassly;
|
|
25
|
+
if (!glassly?.miniappDeveloperMode)
|
|
26
|
+
return;
|
|
27
|
+
// Avoid double-install if the SDK is hot-reloaded mid-session.
|
|
28
|
+
const flagKey = "__devReloadInstalled";
|
|
29
|
+
if (window[flagKey])
|
|
30
|
+
return;
|
|
31
|
+
window[flagKey] = true;
|
|
32
|
+
const handler = (ev) => {
|
|
33
|
+
const data = typeof ev.data === "string" ? ev.data : null;
|
|
34
|
+
if (!data)
|
|
35
|
+
return;
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
parsed = JSON.parse(data);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const env = parsed;
|
|
44
|
+
const type = env?.payload?.type;
|
|
45
|
+
if (type !== RELOAD_MESSAGE_TYPE)
|
|
46
|
+
return;
|
|
47
|
+
console.log("[glassly-miniapp] dev reload signal received — reloading");
|
|
48
|
+
try {
|
|
49
|
+
location.reload();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Some embedded contexts forbid reload; ignore.
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
window.addEventListener("message", handler);
|
|
56
|
+
if (typeof document !== "undefined") {
|
|
57
|
+
document.addEventListener("message", handler);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=dev-reload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-reload.js","sourceRoot":"","sources":["../src/dev-reload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,mBAAmB,GAAG,oBAAoB,CAAA;AAEhD,MAAM,UAAU,iCAAiC;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAM;IACzC,MAAM,OAAO,GAAI,MAAuD,CAAC,OAAO,CAAA;IAChF,IAAI,CAAC,OAAO,EAAE,oBAAoB;QAAE,OAAM;IAE1C,+DAA+D;IAC/D,MAAM,OAAO,GAAG,sBAAsB,CAAA;IAEtC,IAAK,MAAc,CAAC,OAAO,CAAC;QAAE,OAC7B;IAAC,MAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IAEhC,MAAM,OAAO,GAAG,CAAC,EAAgB,EAAQ,EAAE;QACzC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;QACzD,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,IAAI,MAAe,CAAA;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,OAAM;QACR,CAAC;QACD,MAAM,GAAG,GAAG,MAAqC,CAAA;QACjD,MAAM,IAAI,GAAG,GAAG,EAAE,OAAO,EAAE,IAAI,CAAA;QAC/B,IAAI,IAAI,KAAK,mBAAmB;YAAE,OAAM;QAExC,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAA;QACvE,IAAI,CAAC;YACH,QAAQ,CAAC,MAAM,EAAE,CAAA;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,gDAAgD;QAClD,CAAC;IACH,CAAC,CAAA;IAED,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAmC,CAAC,CAAA;IAC3E,CAAC;AACH,CAAC"}
|