@mentra/sdk 2.1.27 → 2.1.28
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/dist/app/session/api-client.d.ts.map +1 -1
- package/dist/app/session/dashboard.d.ts +5 -8
- package/dist/app/session/dashboard.d.ts.map +1 -1
- package/dist/app/session/events.d.ts +2 -1
- package/dist/app/session/events.d.ts.map +1 -1
- package/dist/app/session/index.d.ts +62 -3
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/modules/audio.d.ts +33 -4
- package/dist/app/session/modules/audio.d.ts.map +1 -1
- package/dist/app/session/modules/camera-managed-extension.d.ts +2 -3
- package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
- package/dist/app/session/modules/camera.d.ts +5 -5
- package/dist/app/session/modules/camera.d.ts.map +1 -1
- package/dist/app/session/modules/led.d.ts +141 -0
- package/dist/app/session/modules/led.d.ts.map +1 -0
- package/dist/app/session/modules/location.d.ts +1 -2
- package/dist/app/session/modules/location.d.ts.map +1 -1
- package/dist/app/session/modules/simple-storage.d.ts.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5347 -112
- package/dist/index.js.map +45 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +3 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -14
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/message-types.d.ts +8 -1
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/messages/app-to-cloud.d.ts +48 -2
- package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-app.d.ts +16 -6
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-glasses.d.ts +29 -1
- package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +24 -1
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/rtmp-stream.d.ts +1 -1
- package/dist/types/rtmp-stream.d.ts.map +1 -1
- package/dist/types/streams.d.ts +28 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/package.json +9 -3
- package/dist/app/index.js +0 -24
- package/dist/app/server/index.js +0 -658
- package/dist/app/session/api-client.js +0 -101
- package/dist/app/session/dashboard.js +0 -149
- package/dist/app/session/events.js +0 -315
- package/dist/app/session/index.js +0 -1573
- package/dist/app/session/layouts.js +0 -372
- package/dist/app/session/modules/audio.js +0 -321
- package/dist/app/session/modules/camera-managed-extension.js +0 -310
- package/dist/app/session/modules/camera.js +0 -607
- package/dist/app/session/modules/index.js +0 -19
- package/dist/app/session/modules/location.js +0 -61
- package/dist/app/session/modules/simple-storage.js +0 -232
- package/dist/app/session/settings.js +0 -358
- package/dist/app/token/index.js +0 -22
- package/dist/app/token/utils.js +0 -144
- package/dist/app/webview/index.js +0 -382
- package/dist/constants/index.js +0 -16
- package/dist/constants/log-messages/color.js +0 -14
- package/dist/constants/log-messages/logos.js +0 -48
- package/dist/constants/log-messages/updates.js +0 -55
- package/dist/constants/log-messages/warning.js +0 -89
- package/dist/examples/managed-rtmp-streaming-example.js +0 -158
- package/dist/examples/managed-rtmp-streaming-with-restream-example.js +0 -124
- package/dist/examples/rtmp-streaming-example.js +0 -102
- package/dist/logging/logger.js +0 -79
- package/dist/types/capabilities.js +0 -9
- package/dist/types/dashboard/index.js +0 -12
- package/dist/types/enums.js +0 -75
- package/dist/types/index.js +0 -101
- package/dist/types/layouts.js +0 -3
- package/dist/types/message-types.js +0 -212
- package/dist/types/messages/app-to-cloud.js +0 -95
- package/dist/types/messages/base.js +0 -3
- package/dist/types/messages/cloud-to-app.js +0 -78
- package/dist/types/messages/cloud-to-glasses.js +0 -68
- package/dist/types/messages/glasses-to-cloud.js +0 -140
- package/dist/types/models.js +0 -101
- package/dist/types/photo-data.js +0 -2
- package/dist/types/rtmp-stream.js +0 -3
- package/dist/types/streams.js +0 -306
- package/dist/types/token.js +0 -7
- package/dist/types/webhooks.js +0 -28
- package/dist/utils/animation-utils.js +0 -340
- package/dist/utils/bitmap-utils.js +0 -475
- package/dist/utils/permissions-utils.js +0 -263
- package/dist/utils/resource-tracker.js +0 -153
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 🎬 Animation Utilities Module
|
|
4
|
-
*
|
|
5
|
-
* Provides helper functions for creating and managing bitmap animations in MentraOS applications.
|
|
6
|
-
* Includes timing utilities, animation factories, and performance optimization helpers.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { AnimationUtils } from '@mentra/sdk';
|
|
11
|
-
*
|
|
12
|
-
* // Create animation from files
|
|
13
|
-
* const animation = await AnimationUtils.createBitmapAnimation(
|
|
14
|
-
* session, './frames', 10, 1750, true
|
|
15
|
-
* );
|
|
16
|
-
*
|
|
17
|
-
* // Simple delay utility
|
|
18
|
-
* await AnimationUtils.delay(2000);
|
|
19
|
-
*
|
|
20
|
-
* // Stop animation
|
|
21
|
-
* animation.stop();
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.AnimationUtils = void 0;
|
|
26
|
-
const bitmap_utils_1 = require("./bitmap-utils");
|
|
27
|
-
/**
|
|
28
|
-
* Utility class for creating and managing animations in MentraOS applications
|
|
29
|
-
*/
|
|
30
|
-
class AnimationUtils {
|
|
31
|
-
/**
|
|
32
|
-
* Simple async delay helper
|
|
33
|
-
*
|
|
34
|
-
* @param ms - Milliseconds to delay
|
|
35
|
-
* @returns Promise that resolves after the specified delay
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* console.log('Starting...');
|
|
40
|
-
* await AnimationUtils.delay(2000);
|
|
41
|
-
* console.log('2 seconds later!');
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
static delay(ms) {
|
|
45
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create bitmap animation from files with advanced configuration
|
|
49
|
-
*
|
|
50
|
-
* @param session - MentraOS app session
|
|
51
|
-
* @param basePath - Directory containing animation frames
|
|
52
|
-
* @param frameCount - Number of frames to load
|
|
53
|
-
* @param config - Animation configuration options
|
|
54
|
-
* @returns Promise resolving to animation controller
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* // Simple animation
|
|
59
|
-
* const animation = await AnimationUtils.createBitmapAnimation(
|
|
60
|
-
* session, './animations', 10
|
|
61
|
-
* );
|
|
62
|
-
*
|
|
63
|
-
* // Advanced configuration
|
|
64
|
-
* const advancedAnimation = await AnimationUtils.createBitmapAnimation(
|
|
65
|
-
* session, './sprites', 8, {
|
|
66
|
-
* intervalMs: 1000,
|
|
67
|
-
* repeat: true,
|
|
68
|
-
* loadOptions: { filePattern: 'sprite_{i}.bmp', startFrame: 0 },
|
|
69
|
-
* onFrame: (frame, total) => console.log(`Frame ${frame}/${total}`),
|
|
70
|
-
* onError: (error) => console.error('Animation error:', error)
|
|
71
|
-
* }
|
|
72
|
-
* );
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
static async createBitmapAnimation(session, basePath, frameCount, config = {}) {
|
|
76
|
-
const { intervalMs = 1750, // Optimized for MentraOS hardware
|
|
77
|
-
repeat = false, validateFrames = true, loadOptions = {}, onStart, onStop, onFrame, onError, } = config;
|
|
78
|
-
try {
|
|
79
|
-
console.log(`🎬 Loading ${frameCount} animation frames from ${basePath}...`);
|
|
80
|
-
// Load frames with validation
|
|
81
|
-
const frames = await bitmap_utils_1.BitmapUtils.loadBmpFrames(basePath, frameCount, {
|
|
82
|
-
validateFrames,
|
|
83
|
-
...loadOptions,
|
|
84
|
-
});
|
|
85
|
-
if (frames.length === 0) {
|
|
86
|
-
throw new Error("No frames loaded for animation");
|
|
87
|
-
}
|
|
88
|
-
console.log(`📚 Animation ready: ${frames.length} frames at ${intervalMs}ms intervals`);
|
|
89
|
-
// Create enhanced animation with the loaded frames
|
|
90
|
-
return this.createBitmapAnimationFromFrames(session, frames, {
|
|
91
|
-
intervalMs,
|
|
92
|
-
repeat,
|
|
93
|
-
onStart,
|
|
94
|
-
onStop,
|
|
95
|
-
onFrame,
|
|
96
|
-
onError,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
const errorMsg = `Failed to create animation: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
101
|
-
console.error(`❌ ${errorMsg}`);
|
|
102
|
-
if (onError) {
|
|
103
|
-
onError(errorMsg);
|
|
104
|
-
}
|
|
105
|
-
throw new Error(errorMsg);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Create bitmap animation from pre-loaded frame data
|
|
110
|
-
*
|
|
111
|
-
* @param session - MentraOS app session
|
|
112
|
-
* @param frames - Array of hex-encoded bitmap data
|
|
113
|
-
* @param config - Animation configuration options
|
|
114
|
-
* @returns Animation controller
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```typescript
|
|
118
|
-
* const frames = ['424d461a...', '424d461b...', '424d461c...'];
|
|
119
|
-
* const animation = AnimationUtils.createBitmapAnimationFromFrames(
|
|
120
|
-
* session, frames, { intervalMs: 1500, repeat: true }
|
|
121
|
-
* );
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
static createBitmapAnimationFromFrames(session, frames, config = {}) {
|
|
125
|
-
const { intervalMs = 1750, repeat = false, onStart, onStop, onFrame, onError, } = config;
|
|
126
|
-
let isRunning = false;
|
|
127
|
-
const currentFrame = 0;
|
|
128
|
-
let animationController = null;
|
|
129
|
-
const controller = {
|
|
130
|
-
stop: () => {
|
|
131
|
-
if (animationController) {
|
|
132
|
-
animationController.stop();
|
|
133
|
-
animationController = null;
|
|
134
|
-
}
|
|
135
|
-
isRunning = false;
|
|
136
|
-
if (onStop) {
|
|
137
|
-
onStop();
|
|
138
|
-
}
|
|
139
|
-
console.log("🛑 Animation stopped");
|
|
140
|
-
},
|
|
141
|
-
isRunning: () => isRunning,
|
|
142
|
-
getCurrentFrame: () => currentFrame,
|
|
143
|
-
getTotalFrames: () => frames.length,
|
|
144
|
-
};
|
|
145
|
-
try {
|
|
146
|
-
// Start the animation using the session's built-in method
|
|
147
|
-
animationController = session.layouts.showBitmapAnimation(frames, intervalMs, repeat);
|
|
148
|
-
isRunning = true;
|
|
149
|
-
if (onStart) {
|
|
150
|
-
onStart();
|
|
151
|
-
}
|
|
152
|
-
console.log(`🎬 Animation started: ${frames.length} frames at ${intervalMs}ms${repeat ? " (repeating)" : ""}`);
|
|
153
|
-
// If we have frame callbacks, we need to track timing manually
|
|
154
|
-
// This is a limitation of the current SDK - we can't hook into individual frame displays
|
|
155
|
-
if (onFrame) {
|
|
156
|
-
let frameTracker = 0;
|
|
157
|
-
// Call onFrame for the first frame immediately
|
|
158
|
-
onFrame(frameTracker, frames.length);
|
|
159
|
-
const frameInterval = setInterval(() => {
|
|
160
|
-
if (!isRunning) {
|
|
161
|
-
clearInterval(frameInterval);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
frameTracker = (frameTracker + 1) % frames.length;
|
|
165
|
-
onFrame(frameTracker, frames.length);
|
|
166
|
-
// If not repeating and we've shown all frames, stop tracking
|
|
167
|
-
if (!repeat && frameTracker === frames.length - 1) {
|
|
168
|
-
clearInterval(frameInterval);
|
|
169
|
-
}
|
|
170
|
-
}, intervalMs);
|
|
171
|
-
// Override stop to also clear frame tracking
|
|
172
|
-
const originalStop = controller.stop;
|
|
173
|
-
controller.stop = () => {
|
|
174
|
-
clearInterval(frameInterval);
|
|
175
|
-
originalStop();
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
const errorMsg = `Failed to start animation: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
181
|
-
console.error(`❌ ${errorMsg}`);
|
|
182
|
-
if (onError) {
|
|
183
|
-
onError(errorMsg);
|
|
184
|
-
}
|
|
185
|
-
throw new Error(errorMsg);
|
|
186
|
-
}
|
|
187
|
-
return controller;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Create a sequence of bitmap displays with custom timing
|
|
191
|
-
*
|
|
192
|
-
* @param session - MentraOS app session
|
|
193
|
-
* @param sequence - Array of frame data with individual timing
|
|
194
|
-
* @returns Promise that resolves when sequence completes
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* await AnimationUtils.createBitmapSequence(session, [
|
|
199
|
-
* { frame: frame1Hex, duration: 1000 },
|
|
200
|
-
* { frame: frame2Hex, duration: 500 },
|
|
201
|
-
* { frame: frame3Hex, duration: 2000 }
|
|
202
|
-
* ]);
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
|
-
static async createBitmapSequence(session, sequence) {
|
|
206
|
-
console.log(`🎭 Starting bitmap sequence: ${sequence.length} frames with custom timing`);
|
|
207
|
-
for (let i = 0; i < sequence.length; i++) {
|
|
208
|
-
const { frame, duration } = sequence[i];
|
|
209
|
-
try {
|
|
210
|
-
console.log(`📽️ Sequence frame ${i + 1}/${sequence.length} (${duration}ms)`);
|
|
211
|
-
session.layouts.showBitmapView(frame);
|
|
212
|
-
if (i < sequence.length - 1) {
|
|
213
|
-
// Don't delay after the last frame
|
|
214
|
-
await this.delay(duration);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
console.error(`❌ Error in sequence frame ${i + 1}:`, error);
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
console.log("✅ Bitmap sequence completed");
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Measure animation timing performance
|
|
226
|
-
*
|
|
227
|
-
* @param targetInterval - Expected interval between frames in ms
|
|
228
|
-
* @param measureDuration - How long to measure in ms (default: 10 seconds)
|
|
229
|
-
* @returns Promise resolving to timing performance data
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```typescript
|
|
233
|
-
* const timing = await AnimationUtils.measureTiming(1750, 10000);
|
|
234
|
-
* console.log(`Target: ${timing.targetInterval}ms, Actual: ${timing.actualInterval}ms`);
|
|
235
|
-
* console.log(`Drift: ${timing.drift}ms, FPS: ${timing.fps.toFixed(1)}`);
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
static async measureTiming(targetInterval, measureDuration = 10000) {
|
|
239
|
-
return new Promise((resolve) => {
|
|
240
|
-
const timestamps = [];
|
|
241
|
-
const startTime = Date.now();
|
|
242
|
-
const measureInterval = setInterval(() => {
|
|
243
|
-
timestamps.push(Date.now());
|
|
244
|
-
}, targetInterval);
|
|
245
|
-
setTimeout(() => {
|
|
246
|
-
clearInterval(measureInterval);
|
|
247
|
-
if (timestamps.length < 2) {
|
|
248
|
-
resolve({
|
|
249
|
-
targetInterval,
|
|
250
|
-
actualInterval: targetInterval,
|
|
251
|
-
drift: 0,
|
|
252
|
-
fps: 1000 / targetInterval,
|
|
253
|
-
});
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
// Calculate actual interval
|
|
257
|
-
const intervals = [];
|
|
258
|
-
for (let i = 1; i < timestamps.length; i++) {
|
|
259
|
-
intervals.push(timestamps[i] - timestamps[i - 1]);
|
|
260
|
-
}
|
|
261
|
-
const actualInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
|
|
262
|
-
const drift = actualInterval - targetInterval;
|
|
263
|
-
const fps = 1000 / actualInterval;
|
|
264
|
-
resolve({
|
|
265
|
-
targetInterval,
|
|
266
|
-
actualInterval,
|
|
267
|
-
drift,
|
|
268
|
-
fps,
|
|
269
|
-
});
|
|
270
|
-
}, measureDuration);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Create optimized animation settings for different hardware
|
|
275
|
-
*
|
|
276
|
-
* @param deviceType - Target device type
|
|
277
|
-
* @returns Recommended animation configuration
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* const config = AnimationUtils.getOptimizedConfig('even-realities-g1');
|
|
282
|
-
* const animation = await AnimationUtils.createBitmapAnimation(
|
|
283
|
-
* session, './frames', 10, config
|
|
284
|
-
* );
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
static getOptimizedConfig(deviceType) {
|
|
288
|
-
switch (deviceType) {
|
|
289
|
-
case "even-realities-g1":
|
|
290
|
-
return {
|
|
291
|
-
intervalMs: 1650, // Tested optimal timing for Even Realities G1
|
|
292
|
-
repeat: false,
|
|
293
|
-
validateFrames: true,
|
|
294
|
-
loadOptions: {
|
|
295
|
-
validateFrames: true,
|
|
296
|
-
skipMissingFrames: false,
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
case "generic":
|
|
300
|
-
default:
|
|
301
|
-
return {
|
|
302
|
-
intervalMs: 1000,
|
|
303
|
-
repeat: false,
|
|
304
|
-
validateFrames: true,
|
|
305
|
-
loadOptions: {
|
|
306
|
-
validateFrames: true,
|
|
307
|
-
skipMissingFrames: false,
|
|
308
|
-
},
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Preload and cache animation frames for better performance
|
|
314
|
-
*
|
|
315
|
-
* @param basePath - Directory containing frames
|
|
316
|
-
* @param frameCount - Number of frames to preload
|
|
317
|
-
* @param options - Loading options
|
|
318
|
-
* @returns Promise resolving to cached frame data
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* // Preload frames
|
|
323
|
-
* const cachedFrames = await AnimationUtils.preloadFrames('./animations', 10);
|
|
324
|
-
*
|
|
325
|
-
* // Use cached frames multiple times
|
|
326
|
-
* const animation1 = AnimationUtils.createBitmapAnimationFromFrames(session, cachedFrames);
|
|
327
|
-
* const animation2 = AnimationUtils.createBitmapAnimationFromFrames(session, cachedFrames);
|
|
328
|
-
* ```
|
|
329
|
-
*/
|
|
330
|
-
static async preloadFrames(basePath, frameCount, options = {}) {
|
|
331
|
-
console.log(`📦 Preloading ${frameCount} frames from ${basePath}...`);
|
|
332
|
-
const frames = await bitmap_utils_1.BitmapUtils.loadBmpFrames(basePath, frameCount, {
|
|
333
|
-
validateFrames: true,
|
|
334
|
-
...options,
|
|
335
|
-
});
|
|
336
|
-
console.log(`✅ Preloaded ${frames.length} frames (${frames.reduce((total, frame) => total + frame.length, 0)} total characters)`);
|
|
337
|
-
return frames;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
exports.AnimationUtils = AnimationUtils;
|