@mentra/sdk 2.1.31-beta.5 → 3.0.0-alpha.1
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 +54 -9
- package/dist/MiniAppServer.d.ts +58 -0
- package/dist/MiniAppServer.d.ts.map +1 -0
- package/dist/app/server/index.d.ts +208 -70
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/session/events.d.ts +20 -3
- package/dist/app/session/events.d.ts.map +1 -1
- package/dist/app/session/index.d.ts +56 -3
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/modules/audio-output-stream.d.ts +108 -0
- package/dist/app/session/modules/audio-output-stream.d.ts.map +1 -0
- package/dist/app/session/modules/audio.d.ts +36 -1
- package/dist/app/session/modules/audio.d.ts.map +1 -1
- package/dist/app/session/modules/camera-managed-extension.d.ts +37 -33
- package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
- package/dist/app/session/modules/camera.d.ts +113 -93
- package/dist/app/session/modules/camera.d.ts.map +1 -1
- package/dist/app/session/modules/index.d.ts +4 -3
- package/dist/app/session/modules/index.d.ts.map +1 -1
- package/dist/app/session/modules/led.d.ts.map +1 -1
- package/dist/app/session/modules/location.d.ts.map +1 -1
- package/dist/app/session/settings.d.ts +5 -1
- package/dist/app/session/settings.d.ts.map +1 -1
- package/dist/app/webview/index.d.ts +67 -9
- package/dist/app/webview/index.d.ts.map +1 -1
- package/dist/constants/log-messages/updates.d.ts +32 -9
- package/dist/constants/log-messages/updates.d.ts.map +1 -1
- package/dist/constants/log-messages/warning.d.ts +12 -0
- package/dist/constants/log-messages/warning.d.ts.map +1 -1
- package/dist/display-utils.d.ts +3 -1
- package/dist/display-utils.d.ts.map +1 -1
- package/dist/display-utils.js +443 -26
- package/dist/display-utils.js.map +10 -6
- package/dist/index.d.ts +22 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8957 -4428
- package/dist/index.js.map +63 -31
- package/dist/internal/_SessionManager.d.ts +76 -0
- package/dist/internal/_SessionManager.d.ts.map +1 -0
- package/dist/logging/clean-transport.d.ts +50 -0
- package/dist/logging/clean-transport.d.ts.map +1 -0
- package/dist/logging/errors.d.ts +90 -0
- package/dist/logging/errors.d.ts.map +1 -0
- package/dist/logging/logger.d.ts +72 -1
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/telemetry-transport.d.ts +51 -0
- package/dist/logging/telemetry-transport.d.ts.map +1 -0
- package/dist/session/DataStreamRouter.d.ts +219 -0
- package/dist/session/DataStreamRouter.d.ts.map +1 -0
- package/dist/session/MentraSession.d.ts +102 -0
- package/dist/session/MentraSession.d.ts.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/internal/_ConnectionManager.d.ts +43 -0
- package/dist/session/internal/_ConnectionManager.d.ts.map +1 -0
- package/dist/session/internal/_MessageRouter.d.ts +11 -0
- package/dist/session/internal/_MessageRouter.d.ts.map +1 -0
- package/dist/session/internal/_SubscriptionManager.d.ts +32 -0
- package/dist/session/internal/_SubscriptionManager.d.ts.map +1 -0
- package/dist/session/internal/_V2AudioStreamShim.d.ts +12 -0
- package/dist/session/internal/_V2AudioStreamShim.d.ts.map +1 -0
- package/dist/session/internal/_V2CameraShim.d.ts +52 -0
- package/dist/session/internal/_V2CameraShim.d.ts.map +1 -0
- package/dist/session/internal/_V2EventManagerShim.d.ts +52 -0
- package/dist/session/internal/_V2EventManagerShim.d.ts.map +1 -0
- package/dist/session/internal/_V2SessionShim.d.ts +169 -0
- package/dist/session/internal/_V2SessionShim.d.ts.map +1 -0
- package/dist/session/internal/_V2SettingsShim.d.ts +17 -0
- package/dist/session/internal/_V2SettingsShim.d.ts.map +1 -0
- package/dist/session/managers/CameraManager.d.ts +198 -0
- package/dist/session/managers/CameraManager.d.ts.map +1 -0
- package/dist/session/managers/DashboardManager.d.ts +131 -0
- package/dist/session/managers/DashboardManager.d.ts.map +1 -0
- package/dist/session/managers/DeviceManager.d.ts +348 -0
- package/dist/session/managers/DeviceManager.d.ts.map +1 -0
- package/dist/session/managers/DisplayManager.d.ts +171 -0
- package/dist/session/managers/DisplayManager.d.ts.map +1 -0
- package/dist/session/managers/LedManager.d.ts +116 -0
- package/dist/session/managers/LedManager.d.ts.map +1 -0
- package/dist/session/managers/LocationManager.d.ts +224 -0
- package/dist/session/managers/LocationManager.d.ts.map +1 -0
- package/dist/session/managers/MicManager.d.ts +252 -0
- package/dist/session/managers/MicManager.d.ts.map +1 -0
- package/dist/session/managers/PermissionsManager.d.ts +139 -0
- package/dist/session/managers/PermissionsManager.d.ts.map +1 -0
- package/dist/session/managers/PhoneManager.d.ts +351 -0
- package/dist/session/managers/PhoneManager.d.ts.map +1 -0
- package/dist/session/managers/SpeakerManager.d.ts +285 -0
- package/dist/session/managers/SpeakerManager.d.ts.map +1 -0
- package/dist/session/managers/StorageManager.d.ts +289 -0
- package/dist/session/managers/StorageManager.d.ts.map +1 -0
- package/dist/session/managers/TimeUtils.d.ts +175 -0
- package/dist/session/managers/TimeUtils.d.ts.map +1 -0
- package/dist/session/managers/TranscriptionManager.d.ts +195 -0
- package/dist/session/managers/TranscriptionManager.d.ts.map +1 -0
- package/dist/session/managers/TranslationManager.d.ts +189 -0
- package/dist/session/managers/TranslationManager.d.ts.map +1 -0
- package/dist/session.d.ts +41 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +4110 -0
- package/dist/session.js.map +44 -0
- package/dist/transport/Transport.d.ts +119 -0
- package/dist/transport/Transport.d.ts.map +1 -0
- package/dist/transport/WebSocketTransport.d.ts +73 -0
- package/dist/transport/WebSocketTransport.d.ts.map +1 -0
- package/dist/types/index.d.ts +31 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/message-types.d.ts +25 -9
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/messages/app-to-cloud.d.ts +113 -16
- package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-app.d.ts +50 -4
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-glasses.d.ts +43 -14
- package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +5 -5
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/models.d.ts +17 -0
- package/dist/types/models.d.ts.map +1 -1
- package/dist/types/rtmp-stream.d.ts +4 -4
- package/dist/types/rtmp-stream.d.ts.map +1 -1
- package/dist/types/streams.d.ts +6 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/webhooks.d.ts +11 -0
- package/dist/types/webhooks.d.ts.map +1 -1
- package/dist/utils/error-utils.d.ts +139 -0
- package/dist/utils/error-utils.d.ts.map +1 -0
- package/dist/utils/permissions-utils.d.ts +30 -7
- package/dist/utils/permissions-utils.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/applet.d.ts +5 -1
- package/node_modules/@mentra/types/dist/applet.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts +12 -0
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.js +61 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts +12 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.js +54 -0
- package/node_modules/@mentra/types/dist/capabilities/none.d.ts +13 -0
- package/node_modules/@mentra/types/dist/capabilities/none.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/none.js +67 -0
- package/node_modules/@mentra/types/dist/enums.d.ts +8 -2
- package/node_modules/@mentra/types/dist/enums.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/enums.js +9 -2
- package/node_modules/@mentra/types/dist/hardware.d.ts +3 -1
- package/node_modules/@mentra/types/dist/hardware.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/hardware.js +12 -2
- package/node_modules/@mentra/types/dist/index.d.ts +1 -1
- package/node_modules/@mentra/types/dist/index.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/index.js +2 -1
- package/node_modules/@mentra/types/package.json +2 -2
- package/package.json +24 -12
- package/dist/examples/managed-rtmp-streaming-example.d.ts +0 -2
- package/dist/examples/managed-rtmp-streaming-example.d.ts.map +0 -1
- package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts +0 -11
- package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts.map +0 -1
- package/dist/examples/rtmp-streaming-example.d.ts +0 -2
- package/dist/examples/rtmp-streaming-example.d.ts.map +0 -1
- package/node_modules/@mentra/types/src/applet.ts +0 -51
- package/node_modules/@mentra/types/src/capabilities/even-realities-g1.ts +0 -63
- package/node_modules/@mentra/types/src/capabilities/mentra-live.ts +0 -103
- package/node_modules/@mentra/types/src/capabilities/simulated-glasses.ts +0 -76
- package/node_modules/@mentra/types/src/capabilities/vuzix-z100.ts +0 -60
- package/node_modules/@mentra/types/src/cli.ts +0 -169
- package/node_modules/@mentra/types/src/device.ts +0 -43
- package/node_modules/@mentra/types/src/enums.ts +0 -36
- package/node_modules/@mentra/types/src/hardware.ts +0 -172
- package/node_modules/@mentra/types/src/index.ts +0 -64
- package/node_modules/@mentra/types/tsconfig.json +0 -22
- package/node_modules/@mentra/types/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageManager — v3 SDK Key-Value Storage API
|
|
3
|
+
*
|
|
4
|
+
* Wraps the existing SimpleStorage patterns from v2 with a cleaner,
|
|
5
|
+
* composable API. Provides localStorage-like semantics with cloud
|
|
6
|
+
* synchronisation via HTTP REST endpoints.
|
|
7
|
+
*
|
|
8
|
+
* **Mental Model:** Local cache (RAM) is the source of truth for reads.
|
|
9
|
+
* Writes are applied to RAM immediately and batched/debounced to the
|
|
10
|
+
* server for persistence. On disconnect, pending writes are flushed.
|
|
11
|
+
*
|
|
12
|
+
* Data is isolated by userId and packageName on the server side.
|
|
13
|
+
* The REST endpoints live on the SDK's own HTTP server (same origin
|
|
14
|
+
* as the WebSocket connection, minus the `/app-ws` path).
|
|
15
|
+
*
|
|
16
|
+
* REST API:
|
|
17
|
+
* - `GET /api/sdk/simple-storage/:userId` → fetch all data
|
|
18
|
+
* - `PUT /api/sdk/simple-storage/:userId` → batch upsert `{ data: { key: value } }`
|
|
19
|
+
* - `DELETE /api/sdk/simple-storage/:userId/:key` → delete single key
|
|
20
|
+
* - `DELETE /api/sdk/simple-storage/:userId` → clear all data
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Dependencies injected by MentraSession.
|
|
26
|
+
*
|
|
27
|
+
* Structural type — no concrete imports so the manager stays unit-testable
|
|
28
|
+
* with plain stubs.
|
|
29
|
+
*/
|
|
30
|
+
export interface StorageManagerDeps {
|
|
31
|
+
/** DataStreamRouter — not used by StorageManager but part of the shared shape. */
|
|
32
|
+
router: {
|
|
33
|
+
on(key: string, handler: (streamType: string, data: any, message: any) => void): () => void;
|
|
34
|
+
};
|
|
35
|
+
/** MessageHandlerRegistry — not used by StorageManager but part of the shared shape. */
|
|
36
|
+
messageHandlers: {
|
|
37
|
+
register(type: string, handler: (msg: any) => void): () => void;
|
|
38
|
+
};
|
|
39
|
+
/** Add a subscription string (not used by StorageManager). */
|
|
40
|
+
addSubscription: (stream: string) => void;
|
|
41
|
+
/** Remove a subscription string (not used by StorageManager). */
|
|
42
|
+
removeSubscription: (stream: string) => void;
|
|
43
|
+
/** Send an arbitrary JSON message over the WebSocket. */
|
|
44
|
+
sendMessage: (message: any) => void;
|
|
45
|
+
/** Structured logger. */
|
|
46
|
+
logger: {
|
|
47
|
+
debug(...args: any[]): void;
|
|
48
|
+
info(...args: any[]): void;
|
|
49
|
+
warn(...args: any[]): void;
|
|
50
|
+
error(...args: any[]): void;
|
|
51
|
+
};
|
|
52
|
+
/** Package name — used for auth headers. */
|
|
53
|
+
getPackageName: () => string;
|
|
54
|
+
/** Current session ID. */
|
|
55
|
+
getSessionId: () => string;
|
|
56
|
+
/** Server URL for HTTP API calls (WebSocket URL or HTTP base). */
|
|
57
|
+
getServerUrl?: () => string | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configuration options for StorageManager.
|
|
61
|
+
*/
|
|
62
|
+
export interface StorageManagerConfig {
|
|
63
|
+
/** User ID for storage isolation. */
|
|
64
|
+
userId: string;
|
|
65
|
+
/** API key for authentication. */
|
|
66
|
+
apiKey?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Key-value storage with local caching and debounced cloud sync.
|
|
70
|
+
*
|
|
71
|
+
* Provides a familiar `get`/`set`/`delete`/`clear` interface backed by
|
|
72
|
+
* an in-memory cache with automatic persistence to the MentraOS cloud.
|
|
73
|
+
* Writes are batched and debounced to minimise network traffic.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const session = await mentra.connect();
|
|
78
|
+
*
|
|
79
|
+
* // Set a value
|
|
80
|
+
* await session.storage.set("username", "alice");
|
|
81
|
+
*
|
|
82
|
+
* // Get a value
|
|
83
|
+
* const name = await session.storage.get("username");
|
|
84
|
+
* console.log(name); // "alice"
|
|
85
|
+
*
|
|
86
|
+
* // Check existence
|
|
87
|
+
* const exists = await session.storage.has("username");
|
|
88
|
+
*
|
|
89
|
+
* // Delete a key
|
|
90
|
+
* await session.storage.delete("username");
|
|
91
|
+
*
|
|
92
|
+
* // Flush pending writes immediately
|
|
93
|
+
* await session.storage.flush();
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare class StorageManager {
|
|
97
|
+
private readonly deps;
|
|
98
|
+
private readonly userId;
|
|
99
|
+
private readonly apiKey;
|
|
100
|
+
/** Local cache — `null` means "not yet loaded from server". */
|
|
101
|
+
private cache;
|
|
102
|
+
/** Base URL for HTTP API calls. */
|
|
103
|
+
private readonly baseUrl;
|
|
104
|
+
/** Pending writes waiting to be flushed. */
|
|
105
|
+
private pendingWrites;
|
|
106
|
+
/** Timer for the idle debounce window. */
|
|
107
|
+
private debounceTimer;
|
|
108
|
+
/** Timer for the maximum wait window. */
|
|
109
|
+
private maxWaitTimer;
|
|
110
|
+
/** Timestamp of the first write in the current batch. */
|
|
111
|
+
private firstWriteTime;
|
|
112
|
+
constructor(deps: StorageManagerDeps, config: StorageManagerConfig);
|
|
113
|
+
/**
|
|
114
|
+
* Get a value by key.
|
|
115
|
+
*
|
|
116
|
+
* Reads from the local cache. If the cache has not been populated yet,
|
|
117
|
+
* it is fetched from the server first.
|
|
118
|
+
*
|
|
119
|
+
* @param key - The storage key to retrieve.
|
|
120
|
+
* @returns The stored value, or `undefined` if the key does not exist.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const value = await session.storage.get("theme");
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
get(key: string): Promise<any>;
|
|
128
|
+
/**
|
|
129
|
+
* Set a value for a key.
|
|
130
|
+
*
|
|
131
|
+
* The local cache is updated immediately. The write is batched and
|
|
132
|
+
* debounced — it will be persisted to the server after 3 seconds of
|
|
133
|
+
* idle time or 10 seconds maximum, whichever comes first.
|
|
134
|
+
*
|
|
135
|
+
* @param key - The storage key.
|
|
136
|
+
* @param value - The value to store. Will be serialised as JSON on the server.
|
|
137
|
+
* @throws If the serialised value exceeds the 100 KB size limit.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* await session.storage.set("score", "42");
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
set(key: string, value: any): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Delete a single key.
|
|
147
|
+
*
|
|
148
|
+
* Removes the key from the local cache immediately and sends a DELETE
|
|
149
|
+
* request to the server. Unlike `set()`, deletes are flushed immediately
|
|
150
|
+
* for consistency.
|
|
151
|
+
*
|
|
152
|
+
* @param key - The storage key to remove.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* await session.storage.delete("old-key");
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
delete(key: string): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Clear all stored data.
|
|
162
|
+
*
|
|
163
|
+
* Empties the local cache and sends a DELETE request to remove all
|
|
164
|
+
* data from the server.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* await session.storage.clear();
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
clear(): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Get all storage keys.
|
|
174
|
+
*
|
|
175
|
+
* @returns An array of all keys currently in storage.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const allKeys = await session.storage.keys();
|
|
180
|
+
* console.log("Stored keys:", allKeys);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
keys(): Promise<string[]>;
|
|
184
|
+
/**
|
|
185
|
+
* Check whether a key exists in storage.
|
|
186
|
+
*
|
|
187
|
+
* @param key - The storage key to check.
|
|
188
|
+
* @returns `true` if the key exists.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* if (await session.storage.has("user-prefs")) {
|
|
193
|
+
* // load prefs
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
has(key: string): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Get a shallow copy of all stored key-value pairs.
|
|
200
|
+
*
|
|
201
|
+
* @returns A record of all stored data.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const allData = await session.storage.getAll();
|
|
206
|
+
* console.log(allData);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getAll(): Promise<Record<string, any>>;
|
|
210
|
+
/**
|
|
211
|
+
* Set multiple key-value pairs at once.
|
|
212
|
+
*
|
|
213
|
+
* All values are validated for size before any are applied. The local
|
|
214
|
+
* cache is updated immediately and writes are batched for persistence.
|
|
215
|
+
*
|
|
216
|
+
* @param data - A record of key-value pairs to set.
|
|
217
|
+
* @throws If any value exceeds the 100 KB size limit.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* await session.storage.setMultiple({
|
|
222
|
+
* theme: "dark",
|
|
223
|
+
* language: "en",
|
|
224
|
+
* fontSize: "14",
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
setMultiple(data: Record<string, any>): Promise<void>;
|
|
229
|
+
/**
|
|
230
|
+
* Flush all pending writes to the server immediately.
|
|
231
|
+
*
|
|
232
|
+
* This is called automatically by the debounce/max-wait timers, but can
|
|
233
|
+
* also be called explicitly (e.g., before disconnect). If there are no
|
|
234
|
+
* pending writes, this is a no-op.
|
|
235
|
+
*
|
|
236
|
+
* @throws If the server returns an error (413 for size limit, 429 for rate limit).
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* await session.storage.flush();
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
flush(): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Flush pending writes and clean up all resources.
|
|
246
|
+
*
|
|
247
|
+
* Called by MentraSession during disconnect/cleanup.
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
destroy(): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Ensure the local cache is populated from the server.
|
|
253
|
+
* Only fetches once — subsequent calls are no-ops.
|
|
254
|
+
*/
|
|
255
|
+
private ensureCacheLoaded;
|
|
256
|
+
/**
|
|
257
|
+
* Fetch all stored data from the server and populate the local cache.
|
|
258
|
+
*/
|
|
259
|
+
private fetchFromServer;
|
|
260
|
+
/**
|
|
261
|
+
* Schedule a debounced flush of pending writes.
|
|
262
|
+
*
|
|
263
|
+
* Uses a two-timer strategy:
|
|
264
|
+
* 1. **Idle timer** — fires after {@link DEBOUNCE_MS} of inactivity (reset on each write).
|
|
265
|
+
* 2. **Max wait timer** — fires after {@link MAX_WAIT_MS} from the first write in the batch,
|
|
266
|
+
* ensuring writes are never delayed indefinitely during continuous activity.
|
|
267
|
+
*/
|
|
268
|
+
private scheduleFlush;
|
|
269
|
+
/**
|
|
270
|
+
* Clear all flush timers and reset batch tracking state.
|
|
271
|
+
*/
|
|
272
|
+
private clearTimers;
|
|
273
|
+
/**
|
|
274
|
+
* Resolve the base URL for HTTP API calls.
|
|
275
|
+
*
|
|
276
|
+
* Converts the WebSocket URL (e.g., `wss://host/app-ws`) to an HTTP URL
|
|
277
|
+
* (e.g., `https://host`). Falls back to `http://localhost:8002` if no
|
|
278
|
+
* server URL is available.
|
|
279
|
+
*/
|
|
280
|
+
private resolveBaseUrl;
|
|
281
|
+
/**
|
|
282
|
+
* Generate auth headers for API requests.
|
|
283
|
+
*
|
|
284
|
+
* Uses the `packageName:apiKey` format expected by the SDK server's
|
|
285
|
+
* auth middleware.
|
|
286
|
+
*/
|
|
287
|
+
private getAuthHeaders;
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=StorageManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageManager.d.ts","sourceRoot":"","sources":["../../../src/session/managers/StorageManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,MAAM,EAAE;QACN,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,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;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB9B;;;OAGG;YACW,iBAAiB;IAK/B;;OAEG;YACW,eAAe;IAyB7B;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;IA4CrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAcnB;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAMtB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⏰ TimeUtils — Stateless Timezone Utilities
|
|
3
|
+
*
|
|
4
|
+
* Pure utility class for timezone-aware date operations. Uses the built-in
|
|
5
|
+
* `Intl.DateTimeFormat` API for formatting — no external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* This class has **no transport layer**, no subscriptions, and no wire
|
|
8
|
+
* messages. It is a convenience wrapper for apps that need to display
|
|
9
|
+
* or reason about times in the user's local timezone (which may differ
|
|
10
|
+
* from the server's timezone).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const time = new TimeUtils("America/New_York");
|
|
15
|
+
*
|
|
16
|
+
* // Current time in the user's timezone
|
|
17
|
+
* const now = time.now();
|
|
18
|
+
*
|
|
19
|
+
* // Format a date for display
|
|
20
|
+
* const formatted = time.format(now, { hour: "numeric", minute: "2-digit" });
|
|
21
|
+
* // => "3:45 PM"
|
|
22
|
+
*
|
|
23
|
+
* // Convert a UTC date to the user's local timezone
|
|
24
|
+
* const local = time.toLocal(new Date("2024-01-15T20:00:00Z"));
|
|
25
|
+
*
|
|
26
|
+
* // Change timezone at runtime (e.g., user travelled)
|
|
27
|
+
* time.setTimezone("Europe/London");
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Timezone-aware date utility class.
|
|
34
|
+
*
|
|
35
|
+
* Wraps the `Intl.DateTimeFormat` API to provide convenient methods for
|
|
36
|
+
* creating, converting, and formatting dates in a specific timezone.
|
|
37
|
+
*
|
|
38
|
+
* The timezone can be changed at runtime via {@link setTimezone}, making
|
|
39
|
+
* this class suitable for long-lived sessions where the user may travel
|
|
40
|
+
* across timezone boundaries.
|
|
41
|
+
*/
|
|
42
|
+
export declare class TimeUtils {
|
|
43
|
+
/**
|
|
44
|
+
* The current IANA timezone identifier (e.g., `"America/New_York"`,
|
|
45
|
+
* `"Europe/London"`, `"Asia/Tokyo"`).
|
|
46
|
+
*/
|
|
47
|
+
private _zone;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new TimeUtils instance.
|
|
50
|
+
*
|
|
51
|
+
* @param timezone - IANA timezone identifier. Must be a valid timezone
|
|
52
|
+
* string recognised by `Intl.DateTimeFormat` (e.g., `"America/New_York"`,
|
|
53
|
+
* `"UTC"`, `"Asia/Tokyo"`).
|
|
54
|
+
*
|
|
55
|
+
* @throws {RangeError} If the provided timezone string is not a valid
|
|
56
|
+
* IANA timezone identifier.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const time = new TimeUtils("America/Los_Angeles");
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
constructor(timezone: string);
|
|
64
|
+
/**
|
|
65
|
+
* The current IANA timezone identifier.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* console.log(time.zone); // "America/New_York"
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
get zone(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current date/time.
|
|
75
|
+
*
|
|
76
|
+
* Returns a standard `Date` object representing the current instant.
|
|
77
|
+
* The `Date` itself is always UTC internally — use {@link format} or
|
|
78
|
+
* {@link toLocal} to interpret it in the configured timezone.
|
|
79
|
+
*
|
|
80
|
+
* @returns A `Date` representing the current moment.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const now = time.now();
|
|
85
|
+
* console.log(time.format(now)); // formatted in the configured timezone
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
now(): Date;
|
|
89
|
+
/**
|
|
90
|
+
* Convert a `Date` to a new `Date` whose UTC fields represent the
|
|
91
|
+
* wall-clock time in the configured timezone.
|
|
92
|
+
*
|
|
93
|
+
* This is useful when you need to extract hours/minutes/seconds that
|
|
94
|
+
* correspond to the local timezone without using `Intl` formatting.
|
|
95
|
+
*
|
|
96
|
+
* **Note:** The returned `Date` is a synthetic object — its
|
|
97
|
+
* `getUTCHours()` etc. return the *local* values, but calling
|
|
98
|
+
* `toISOString()` on it will produce a misleading string. Prefer
|
|
99
|
+
* {@link format} for display purposes.
|
|
100
|
+
*
|
|
101
|
+
* @param date - The date to convert. Defaults to `new Date()` (now).
|
|
102
|
+
* @returns A new `Date` whose UTC methods return local-timezone values.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const utcDate = new Date("2024-01-15T20:00:00Z");
|
|
107
|
+
* const local = time.toLocal(utcDate);
|
|
108
|
+
* console.log(local.getUTCHours()); // 15 if timezone is "America/New_York" (EST = UTC-5)
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
toLocal(date?: Date): Date;
|
|
112
|
+
/**
|
|
113
|
+
* Format a `Date` for display in the configured timezone.
|
|
114
|
+
*
|
|
115
|
+
* Delegates to `Intl.DateTimeFormat` with the configured timezone
|
|
116
|
+
* injected automatically. Any valid `Intl.DateTimeFormatOptions` can
|
|
117
|
+
* be passed through.
|
|
118
|
+
*
|
|
119
|
+
* If no options are provided, a sensible default is used:
|
|
120
|
+
* `"1/15/2024, 3:45:00 PM"` (locale-dependent).
|
|
121
|
+
*
|
|
122
|
+
* @param date - The date to format.
|
|
123
|
+
* @param opts - Optional `Intl.DateTimeFormatOptions` to control output.
|
|
124
|
+
* @returns The formatted date string.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Default format
|
|
129
|
+
* time.format(new Date());
|
|
130
|
+
* // => "1/15/2024, 3:45:00 PM"
|
|
131
|
+
*
|
|
132
|
+
* // Custom format — time only
|
|
133
|
+
* time.format(new Date(), { hour: "numeric", minute: "2-digit" });
|
|
134
|
+
* // => "3:45 PM"
|
|
135
|
+
*
|
|
136
|
+
* // Custom format — full date
|
|
137
|
+
* time.format(new Date(), {
|
|
138
|
+
* weekday: "long",
|
|
139
|
+
* year: "numeric",
|
|
140
|
+
* month: "long",
|
|
141
|
+
* day: "numeric",
|
|
142
|
+
* });
|
|
143
|
+
* // => "Monday, January 15, 2024"
|
|
144
|
+
*
|
|
145
|
+
* // With a specific locale
|
|
146
|
+
* time.format(new Date(), { hour: "numeric", minute: "2-digit" });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
format(date: Date, opts?: Intl.DateTimeFormatOptions): string;
|
|
150
|
+
/**
|
|
151
|
+
* Change the timezone at runtime.
|
|
152
|
+
*
|
|
153
|
+
* Validates the new timezone before applying it. If the timezone is
|
|
154
|
+
* invalid, a `RangeError` is thrown and the previous timezone is retained.
|
|
155
|
+
*
|
|
156
|
+
* @param tz - New IANA timezone identifier.
|
|
157
|
+
* @throws {RangeError} If the timezone string is not valid.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* time.setTimezone("Europe/London");
|
|
162
|
+
* console.log(time.zone); // "Europe/London"
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
setTimezone(tz: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Validate that a timezone string is recognised by the runtime's
|
|
168
|
+
* `Intl.DateTimeFormat` implementation.
|
|
169
|
+
*
|
|
170
|
+
* @param tz - The timezone string to validate.
|
|
171
|
+
* @throws {RangeError} If the timezone is not valid.
|
|
172
|
+
*/
|
|
173
|
+
private static validateTimezone;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=TimeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeUtils.d.ts","sourceRoot":"","sources":["../../../src/session/managers/TimeUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;;;;;;;;;;;OAcG;gBACS,QAAQ,EAAE,MAAM;IAS5B;;;;;;;OAOG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAID;;;;;;;;;;;;;;OAcG;IACH,GAAG,IAAI,IAAI;IAIX;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,IAAI,GAAE,IAAiB,GAAG,IAAI;IAiCtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM;IAS7D;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAO7B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;CAYhC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TranscriptionManager — v3 SDK Transcription API
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old `session.events.onTranscription*()` methods with a cleaner,
|
|
5
|
+
* composable API that supports multiple simultaneous subscriptions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const session = await mentra.connect();
|
|
10
|
+
*
|
|
11
|
+
* // Subscribe to all transcription (auto-detect language)
|
|
12
|
+
* const stopAll = session.transcription.on((evt) => {
|
|
13
|
+
* console.log(`[${evt.language}] ${evt.text}`);
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Also subscribe to a specific language — independent of the above
|
|
17
|
+
* const stopEn = session.transcription.forLanguage("en", (evt) => {
|
|
18
|
+
* console.log(`English: ${evt.text}`);
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Multiple languages in one call
|
|
22
|
+
* const stopMulti = session.transcription.forLanguage(["ja", "es"], (evt) => {
|
|
23
|
+
* console.log(`${evt.language}: ${evt.text}`);
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Configure hints / vocabulary / diarization
|
|
27
|
+
* session.transcription.configure({
|
|
28
|
+
* languageHints: ["en", "ja"],
|
|
29
|
+
* vocabulary: ["MentraOS", "HIPAA"],
|
|
30
|
+
* diarization: true,
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Cleanup individual subscriptions
|
|
34
|
+
* stopEn();
|
|
35
|
+
*
|
|
36
|
+
* // Or tear down everything
|
|
37
|
+
* session.transcription.stop();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Configuration options that influence transcription behaviour on the cloud.
|
|
44
|
+
*
|
|
45
|
+
* Passed to {@link TranscriptionManager.configure}. Applies globally to all
|
|
46
|
+
* active subscriptions managed by this instance.
|
|
47
|
+
*/
|
|
48
|
+
export interface TranscriptionConfig {
|
|
49
|
+
/** ISO 639-1 language hints to improve detection accuracy (e.g. `["en", "ja", "es"]`). */
|
|
50
|
+
languageHints?: string[];
|
|
51
|
+
/** Custom vocabulary / boosted terms (e.g. `["MentraOS", "HIPAA"]`). */
|
|
52
|
+
vocabulary?: string[];
|
|
53
|
+
/** Enable speaker diarisation. Defaults to `true`. */
|
|
54
|
+
diarization?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Normalised transcription event delivered to subscriber callbacks.
|
|
58
|
+
*
|
|
59
|
+
* This is the *public* shape — it is mapped from the raw cloud
|
|
60
|
+
* `TranscriptionData` message inside the manager so consumers never
|
|
61
|
+
* need to think about wire-level details.
|
|
62
|
+
*/
|
|
63
|
+
export interface TranscriptionEvent {
|
|
64
|
+
/** The transcribed text. */
|
|
65
|
+
text: string;
|
|
66
|
+
/** `true` when the cloud considers this utterance segment finalised. */
|
|
67
|
+
isFinal: boolean;
|
|
68
|
+
/** ISO 639-1 detected language code (e.g. `"en"`, `"ja"`). */
|
|
69
|
+
language: string;
|
|
70
|
+
/** Speaker identifier when diarisation is enabled. */
|
|
71
|
+
speakerId?: string;
|
|
72
|
+
/** Stable identifier for a contiguous utterance. Interim and final events for the same utterance share this ID. */
|
|
73
|
+
utteranceId?: string;
|
|
74
|
+
/** Recognition confidence in the range `[0, 1]`. */
|
|
75
|
+
confidence?: number;
|
|
76
|
+
/** Start time of the utterance segment in milliseconds. */
|
|
77
|
+
startTime: number;
|
|
78
|
+
/** End time of the utterance segment in milliseconds. */
|
|
79
|
+
endTime: number;
|
|
80
|
+
/** Audio duration in milliseconds. */
|
|
81
|
+
duration?: number;
|
|
82
|
+
/** Provider-specific metadata (token-level details, etc.). */
|
|
83
|
+
metadata?: any;
|
|
84
|
+
}
|
|
85
|
+
/** Callback signature for transcription subscribers. */
|
|
86
|
+
export type TranscriptionHandler = (data: TranscriptionEvent) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Dependencies injected by MentraSession.
|
|
89
|
+
*
|
|
90
|
+
* This is intentionally a *structural* type — we don't import the concrete
|
|
91
|
+
* `DataStreamRouter` class so that the manager remains unit-testable with
|
|
92
|
+
* plain stubs.
|
|
93
|
+
*/
|
|
94
|
+
export interface TranscriptionManagerDeps {
|
|
95
|
+
/** Register for DATA_STREAM messages by streamType key (exact or prefix). Returns a cleanup function. */
|
|
96
|
+
router: {
|
|
97
|
+
on(key: string, handler: (streamType: string, data: any, message: any) => void): () => void;
|
|
98
|
+
};
|
|
99
|
+
/** Add a subscription string (triggers SUBSCRIPTION_UPDATE to cloud). */
|
|
100
|
+
addSubscription: (stream: string) => void;
|
|
101
|
+
/** Remove a subscription string. */
|
|
102
|
+
removeSubscription: (stream: string) => void;
|
|
103
|
+
/** Send an arbitrary JSON message to the cloud. */
|
|
104
|
+
sendMessage: (message: any) => void;
|
|
105
|
+
/** Structured logger. */
|
|
106
|
+
logger: {
|
|
107
|
+
debug(...args: any[]): void;
|
|
108
|
+
info(...args: any[]): void;
|
|
109
|
+
warn(...args: any[]): void;
|
|
110
|
+
error(...args: any[]): void;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Manages transcription subscriptions and dispatches normalised events to
|
|
115
|
+
* application-level handlers.
|
|
116
|
+
*
|
|
117
|
+
* Every public subscription method (`on`, `forLanguage`) is **independent** —
|
|
118
|
+
* multiple can be active simultaneously and each returns its own cleanup
|
|
119
|
+
* function. Calling {@link stop} tears down *all* active subscriptions.
|
|
120
|
+
*/
|
|
121
|
+
export declare class TranscriptionManager {
|
|
122
|
+
private readonly deps;
|
|
123
|
+
/**
|
|
124
|
+
* All currently-active registrations. We track them so that {@link stop}
|
|
125
|
+
* can clean everything up in one shot.
|
|
126
|
+
*/
|
|
127
|
+
private registrations;
|
|
128
|
+
/**
|
|
129
|
+
* Reference count per subscription stream string.
|
|
130
|
+
*
|
|
131
|
+
* Multiple independent registrations may share the same underlying stream
|
|
132
|
+
* key (e.g. two `forLanguage("en", …)` calls). We only call
|
|
133
|
+
* `deps.removeSubscription` when the ref-count drops to zero.
|
|
134
|
+
*/
|
|
135
|
+
private refCounts;
|
|
136
|
+
/** Latest config applied via {@link configure}. */
|
|
137
|
+
private currentConfig;
|
|
138
|
+
constructor(deps: TranscriptionManagerDeps);
|
|
139
|
+
/**
|
|
140
|
+
* Subscribe to **all** transcription events (auto-detect, all languages).
|
|
141
|
+
*
|
|
142
|
+
* Registers a prefix handler on the router for `"transcription"` so that
|
|
143
|
+
* events for *any* language are delivered to `handler`. The cloud
|
|
144
|
+
* subscription is `"transcription:auto"`.
|
|
145
|
+
*
|
|
146
|
+
* @param handler - Called for every incoming transcription event.
|
|
147
|
+
* @returns A cleanup function that removes this specific subscription.
|
|
148
|
+
*/
|
|
149
|
+
on(handler: TranscriptionHandler): () => void;
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe to transcription for one or more specific languages.
|
|
152
|
+
*
|
|
153
|
+
* Each call is **independent** — multiple can be active simultaneously.
|
|
154
|
+
* When an array is provided the handler fires for events in *any* of the
|
|
155
|
+
* listed languages.
|
|
156
|
+
*
|
|
157
|
+
* @param lang - ISO 639-1 language code(s) (e.g. `"en"` or `["en", "ja"]`).
|
|
158
|
+
* @param handler - Called for every matching transcription event.
|
|
159
|
+
* @returns A cleanup function that removes this specific subscription.
|
|
160
|
+
*/
|
|
161
|
+
forLanguage(lang: string | string[], handler: TranscriptionHandler): () => void;
|
|
162
|
+
/**
|
|
163
|
+
* Apply transcription configuration (language hints, custom vocabulary,
|
|
164
|
+
* diarisation toggle).
|
|
165
|
+
*
|
|
166
|
+
* The configuration is sent to the cloud immediately and cached so that
|
|
167
|
+
* it can be re-sent if the session reconnects.
|
|
168
|
+
*
|
|
169
|
+
* @param config - Configuration to apply.
|
|
170
|
+
*/
|
|
171
|
+
configure(config: TranscriptionConfig): void;
|
|
172
|
+
/**
|
|
173
|
+
* Stop **all** transcription subscriptions and remove every handler.
|
|
174
|
+
*
|
|
175
|
+
* After calling this, no transcription callbacks will fire until new
|
|
176
|
+
* subscriptions are created via {@link on} or {@link forLanguage}.
|
|
177
|
+
*/
|
|
178
|
+
stop(): void;
|
|
179
|
+
/** Returns `true` if there is at least one active subscription. */
|
|
180
|
+
get active(): boolean;
|
|
181
|
+
/** Returns the current configuration, or `null` if none has been set. */
|
|
182
|
+
get config(): TranscriptionConfig | null;
|
|
183
|
+
/**
|
|
184
|
+
* Track a new registration: increment ref-counts and call
|
|
185
|
+
* `addSubscription` for any stream that is newly referenced.
|
|
186
|
+
*/
|
|
187
|
+
private addRegistration;
|
|
188
|
+
/**
|
|
189
|
+
* Tear down a registration: unregister router handlers, decrement
|
|
190
|
+
* ref-counts, and call `removeSubscription` when a stream drops to zero
|
|
191
|
+
* references.
|
|
192
|
+
*/
|
|
193
|
+
private removeRegistration;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=TranscriptionManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranscriptionManager.d.ts","sourceRoot":"","sources":["../../../src/session/managers/TranscriptionManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,sDAAsD;IACtD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mHAAmH;IACnH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,wDAAwD;AACxD,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAItE;;;;;;GAMG;AACH,MAAM,WAAW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