@mentra/sdk 2.0.4 → 2.1.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/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
-
3
2
  "name": "@mentra/sdk",
4
- "version": "2.0.4",
3
+ "version": "2.1.1",
5
4
  "description": "Build apps for MentraOS smartglasses. This SDK provides everything you need to create real-time smartglasses applications.",
6
5
  "source": "src/index.ts",
7
6
  "main": "dist/index.js",
@@ -32,6 +31,7 @@
32
31
  "express": "^4.18.2",
33
32
  "jsonwebtoken": "^8.5.1",
34
33
  "jsrsasign": "^11.1.0",
34
+ "multer": "^2.0.1",
35
35
  "pino": "^9.6.0",
36
36
  "pino-pretty": "^13.0.0",
37
37
  "ws": "^8.18.2"
@@ -1,100 +0,0 @@
1
- /**
2
- * 📹 RTMP Streaming Module
3
- *
4
- * Provides functionality for Apps to request and manage RTMP streams from smart glasses.
5
- * Handles stream lifecycle, status monitoring, and cleanup.
6
- */
7
- import { RtmpStreamStatus } from '../../../types';
8
- import { VideoConfig, AudioConfig, StreamConfig, StreamStatusHandler } from '../../../types/rtmp-stream';
9
- export { VideoConfig, AudioConfig, StreamConfig, StreamStatusHandler };
10
- /**
11
- * Configuration options for an RTMP stream
12
- */
13
- export interface RtmpStreamOptions {
14
- /** The RTMP URL to stream to (e.g., rtmp://server.example.com/live/stream-key) */
15
- rtmpUrl: string;
16
- /** Optional video configuration settings */
17
- video?: VideoConfig;
18
- /** Optional audio configuration settings */
19
- audio?: AudioConfig;
20
- /** Optional stream configuration settings */
21
- stream?: StreamConfig;
22
- }
23
- /**
24
- * StreamingModule provides functionality for Apps to request and manage RTMP streams.
25
- *
26
- * Streams can be requested with configurable parameters for video quality,
27
- * audio settings, and stream constraints. Status updates are received through
28
- * the standard subscription mechanism.
29
- */
30
- export declare class StreamingModule {
31
- private send;
32
- private packageName;
33
- private sessionId;
34
- private session?;
35
- private isStreaming;
36
- private currentStreamUrl?;
37
- private currentStreamState?;
38
- /**
39
- * Create a new StreamingModule
40
- *
41
- * @param packageName - The App package name
42
- * @param sessionId - The current session ID
43
- * @param send - Function to send messages to the cloud
44
- * @param session - Reference to the parent AppSession (optional)
45
- */
46
- constructor(packageName: string, sessionId: string, send: (message: any) => void, session?: any);
47
- /**
48
- * Begin an RTMP stream to the specified URL
49
- *
50
- * @param options - Configuration options for the stream
51
- * @returns Promise that resolves when the stream request is sent (not when streaming begins)
52
- */
53
- requestStream(options: RtmpStreamOptions): Promise<void>;
54
- /**
55
- * Stop the current RTMP stream
56
- *
57
- * @returns Promise that resolves when the stop request is sent
58
- */
59
- stopStream(): Promise<void>;
60
- /**
61
- * Check if currently streaming
62
- *
63
- * @returns True if a stream is active or initializing
64
- */
65
- isCurrentlyStreaming(): boolean;
66
- /**
67
- * Get the URL of the current stream (if any)
68
- *
69
- * @returns The RTMP URL of the current stream, or undefined if not streaming
70
- */
71
- getCurrentStreamUrl(): string | undefined;
72
- /**
73
- * Get the current stream status
74
- *
75
- * @returns The current stream status, or undefined if not available
76
- */
77
- getStreamStatus(): RtmpStreamStatus | undefined;
78
- /**
79
- * Subscribe to RTMP stream status updates
80
- * This uses the standard stream subscription mechanism
81
- */
82
- subscribeToStatusUpdates(): void;
83
- /**
84
- * Unsubscribe from RTMP stream status updates
85
- */
86
- unsubscribeFromStatusUpdates(): void;
87
- /**
88
- * Listen for status updates using the standard event system
89
- * @param handler - Function to call when stream status changes
90
- * @returns Cleanup function to remove the handler
91
- */
92
- onStatus(handler: StreamStatusHandler): () => void;
93
- /**
94
- * Update internal stream state based on a status message
95
- * For internal use by AppSession
96
- * @param message - The status message from the cloud
97
- */
98
- updateStreamState(message: any): void;
99
- }
100
- //# sourceMappingURL=streaming.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../src/app/session/modules/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAKL,gBAA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I,IAAI;IAMpC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,IAAI;IAUlD;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;CA2DtC"}
@@ -1,270 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamingModule = void 0;
4
- /**
5
- * 📹 RTMP Streaming Module
6
- *
7
- * Provides functionality for Apps to request and manage RTMP streams from smart glasses.
8
- * Handles stream lifecycle, status monitoring, and cleanup.
9
- */
10
- const types_1 = require("../../../types");
11
- const streams_1 = require("../../../types/streams");
12
- // Stream status information and handler types are imported from '../../../types/rtmp-stream'
13
- /**
14
- * StreamingModule provides functionality for Apps to request and manage RTMP streams.
15
- *
16
- * Streams can be requested with configurable parameters for video quality,
17
- * audio settings, and stream constraints. Status updates are received through
18
- * the standard subscription mechanism.
19
- */
20
- class StreamingModule {
21
- /**
22
- * Create a new StreamingModule
23
- *
24
- * @param packageName - The App package name
25
- * @param sessionId - The current session ID
26
- * @param send - Function to send messages to the cloud
27
- * @param session - Reference to the parent AppSession (optional)
28
- */
29
- constructor(packageName, sessionId, send, session) {
30
- this.isStreaming = false;
31
- this.packageName = packageName;
32
- this.sessionId = sessionId;
33
- this.send = send;
34
- this.session = session;
35
- }
36
- /**
37
- * Begin an RTMP stream to the specified URL
38
- *
39
- * @param options - Configuration options for the stream
40
- * @returns Promise that resolves when the stream request is sent (not when streaming begins)
41
- */
42
- async requestStream(options) {
43
- console.log(`[RTMP_STREAM_REQUEST] StreamingModule.requestStream called`, {
44
- debugKey: 'RTMP_STREAM_REQUEST',
45
- packageName: this.packageName,
46
- sessionId: this.sessionId,
47
- rtmpUrl: options.rtmpUrl,
48
- isCurrentlyStreaming: this.isStreaming,
49
- currentStreamUrl: this.currentStreamUrl,
50
- currentStreamState: this.currentStreamState
51
- });
52
- if (!options.rtmpUrl) {
53
- throw new Error('rtmpUrl is required');
54
- }
55
- if (this.isStreaming) {
56
- console.error(`[RTMP_STREAM_ALREADY_ACTIVE] Already streaming error`, {
57
- debugKey: 'RTMP_STREAM_ALREADY_ACTIVE',
58
- packageName: this.packageName,
59
- sessionId: this.sessionId,
60
- currentStreamUrl: this.currentStreamUrl,
61
- requestedUrl: options.rtmpUrl,
62
- currentStreamState: this.currentStreamState,
63
- isStreaming: this.isStreaming
64
- });
65
- throw new Error('Already streaming. Stop the current stream before starting a new one.');
66
- }
67
- // Create stream request message
68
- const message = {
69
- type: types_1.AppToCloudMessageType.RTMP_STREAM_REQUEST,
70
- packageName: this.packageName,
71
- sessionId: this.sessionId,
72
- rtmpUrl: options.rtmpUrl,
73
- video: options.video,
74
- audio: options.audio,
75
- stream: options.stream,
76
- timestamp: new Date()
77
- };
78
- // Save stream URL for reference
79
- this.currentStreamUrl = options.rtmpUrl;
80
- // Send the request
81
- try {
82
- console.log(`[RTMP_STREAM_SENDING] Sending RTMP stream request`, {
83
- debugKey: 'RTMP_STREAM_SENDING',
84
- packageName: this.packageName,
85
- sessionId: this.sessionId,
86
- rtmpUrl: options.rtmpUrl,
87
- messageType: message.type
88
- });
89
- this.send(message);
90
- this.isStreaming = true;
91
- console.log(`[RTMP_STREAM_REQUEST_SENT] RTMP stream request sent successfully`, {
92
- debugKey: 'RTMP_STREAM_REQUEST_SENT',
93
- packageName: this.packageName,
94
- sessionId: this.sessionId,
95
- isStreaming: this.isStreaming,
96
- currentStreamUrl: this.currentStreamUrl
97
- });
98
- return Promise.resolve();
99
- }
100
- catch (error) {
101
- console.error(`[RTMP_STREAM_REQUEST_FAIL] Failed to send RTMP stream request`, {
102
- debugKey: 'RTMP_STREAM_REQUEST_FAIL',
103
- packageName: this.packageName,
104
- sessionId: this.sessionId,
105
- error,
106
- rtmpUrl: options.rtmpUrl
107
- });
108
- const errorMessage = error instanceof Error ? error.message : String(error);
109
- return Promise.reject(new Error(`Failed to request RTMP stream: ${errorMessage}`));
110
- }
111
- }
112
- /**
113
- * Stop the current RTMP stream
114
- *
115
- * @returns Promise that resolves when the stop request is sent
116
- */
117
- async stopStream() {
118
- console.log(`[RTMP_STREAM_STOP_REQUEST] StreamingModule.stopStream called`, {
119
- debugKey: 'RTMP_STREAM_STOP_REQUEST',
120
- packageName: this.packageName,
121
- sessionId: this.sessionId,
122
- isCurrentlyStreaming: this.isStreaming,
123
- currentStreamUrl: this.currentStreamUrl,
124
- currentStreamState: this.currentStreamState
125
- });
126
- if (!this.isStreaming) {
127
- console.log(`[RTMP_STREAM_STOP_NOOP] Not streaming - no-op`, {
128
- debugKey: 'RTMP_STREAM_STOP_NOOP',
129
- packageName: this.packageName,
130
- sessionId: this.sessionId
131
- });
132
- // Not an error - just a no-op if not streaming
133
- return Promise.resolve();
134
- }
135
- // Create stop request message
136
- const message = {
137
- type: types_1.AppToCloudMessageType.RTMP_STREAM_STOP,
138
- packageName: this.packageName,
139
- sessionId: this.sessionId,
140
- streamId: this.currentStreamState?.streamId, // Include streamId if available
141
- timestamp: new Date()
142
- };
143
- // Send the request
144
- try {
145
- this.send(message);
146
- return Promise.resolve();
147
- }
148
- catch (error) {
149
- const errorMessage = error instanceof Error ? error.message : String(error);
150
- return Promise.reject(new Error(`Failed to stop RTMP stream: ${errorMessage}`));
151
- }
152
- }
153
- /**
154
- * Check if currently streaming
155
- *
156
- * @returns True if a stream is active or initializing
157
- */
158
- isCurrentlyStreaming() {
159
- return this.isStreaming;
160
- }
161
- /**
162
- * Get the URL of the current stream (if any)
163
- *
164
- * @returns The RTMP URL of the current stream, or undefined if not streaming
165
- */
166
- getCurrentStreamUrl() {
167
- return this.currentStreamUrl;
168
- }
169
- /**
170
- * Get the current stream status
171
- *
172
- * @returns The current stream status, or undefined if not available
173
- */
174
- getStreamStatus() {
175
- return this.currentStreamState;
176
- }
177
- /**
178
- * Subscribe to RTMP stream status updates
179
- * This uses the standard stream subscription mechanism
180
- */
181
- subscribeToStatusUpdates() {
182
- if (this.session) {
183
- this.session.subscribe(streams_1.StreamType.RTMP_STREAM_STATUS);
184
- }
185
- else {
186
- console.error('Cannot subscribe to status updates: session reference not available');
187
- }
188
- }
189
- /**
190
- * Unsubscribe from RTMP stream status updates
191
- */
192
- unsubscribeFromStatusUpdates() {
193
- if (this.session) {
194
- this.session.unsubscribe(streams_1.StreamType.RTMP_STREAM_STATUS);
195
- }
196
- }
197
- /**
198
- * Listen for status updates using the standard event system
199
- * @param handler - Function to call when stream status changes
200
- * @returns Cleanup function to remove the handler
201
- */
202
- onStatus(handler) {
203
- if (!this.session) {
204
- console.error('Cannot listen for status updates: session reference not available');
205
- return () => { };
206
- }
207
- this.subscribeToStatusUpdates();
208
- return this.session.on(streams_1.StreamType.RTMP_STREAM_STATUS, handler);
209
- }
210
- /**
211
- * Update internal stream state based on a status message
212
- * For internal use by AppSession
213
- * @param message - The status message from the cloud
214
- */
215
- updateStreamState(message) {
216
- console.log(`[RTMP_STREAM_STATE_UPDATE] StreamingModule.updateStreamState called`, {
217
- debugKey: 'RTMP_STREAM_STATE_UPDATE',
218
- packageName: this.packageName,
219
- sessionId: this.sessionId,
220
- messageType: message?.type,
221
- messageStatus: message?.status,
222
- currentIsStreaming: this.isStreaming
223
- });
224
- // Verify this is a valid stream response
225
- if (!(0, types_1.isRtmpStreamStatus)(message)) {
226
- console.warn('[RTMP_STREAM_INVALID_STATUS] Received invalid stream status message', {
227
- debugKey: 'RTMP_STREAM_INVALID_STATUS',
228
- packageName: this.packageName,
229
- sessionId: this.sessionId,
230
- message
231
- });
232
- return;
233
- }
234
- // Convert to StreamStatus format
235
- const status = {
236
- type: message.type,
237
- streamId: message.streamId,
238
- status: message.status,
239
- errorDetails: message.errorDetails,
240
- appId: message.appId,
241
- stats: message.stats,
242
- timestamp: message.timestamp || new Date()
243
- };
244
- console.log(`[RTMP_STREAM_STATUS_PROCESSED] Stream status processed`, {
245
- debugKey: 'RTMP_STREAM_STATUS_PROCESSED',
246
- packageName: this.packageName,
247
- sessionId: this.sessionId,
248
- streamId: status.streamId,
249
- oldStatus: this.currentStreamState?.status,
250
- newStatus: status.status,
251
- wasStreaming: this.isStreaming
252
- });
253
- // Updated logic to check for timeout to handle resetting state.
254
- // Update local state based on status
255
- if (status.status === 'stopped' || status.status === 'error' || status.status === 'timeout') {
256
- console.log(`[RTMP_STREAM_STATE_STOPPED] Stream stopped - updating local state`, {
257
- debugKey: 'RTMP_STREAM_STATE_STOPPED',
258
- packageName: this.packageName,
259
- sessionId: this.sessionId,
260
- status: status.status,
261
- wasStreaming: this.isStreaming
262
- });
263
- this.isStreaming = false;
264
- this.currentStreamUrl = undefined;
265
- }
266
- // Save the latest status
267
- this.currentStreamState = status;
268
- }
269
- }
270
- exports.StreamingModule = StreamingModule;