@mentra/sdk 2.1.27 โ†’ 2.1.29-beta.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.
Files changed (95) hide show
  1. package/dist/app/session/api-client.d.ts.map +1 -1
  2. package/dist/app/session/dashboard.d.ts +5 -8
  3. package/dist/app/session/dashboard.d.ts.map +1 -1
  4. package/dist/app/session/events.d.ts +10 -4
  5. package/dist/app/session/events.d.ts.map +1 -1
  6. package/dist/app/session/index.d.ts +64 -4
  7. package/dist/app/session/index.d.ts.map +1 -1
  8. package/dist/app/session/modules/audio.d.ts +33 -4
  9. package/dist/app/session/modules/audio.d.ts.map +1 -1
  10. package/dist/app/session/modules/camera-managed-extension.d.ts +2 -3
  11. package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
  12. package/dist/app/session/modules/camera.d.ts +11 -10
  13. package/dist/app/session/modules/camera.d.ts.map +1 -1
  14. package/dist/app/session/modules/led.d.ts +141 -0
  15. package/dist/app/session/modules/led.d.ts.map +1 -0
  16. package/dist/app/session/modules/location.d.ts +1 -2
  17. package/dist/app/session/modules/location.d.ts.map +1 -1
  18. package/dist/app/session/modules/simple-storage.d.ts +22 -1
  19. package/dist/app/session/modules/simple-storage.d.ts.map +1 -1
  20. package/dist/display-utils.d.ts +989 -0
  21. package/dist/display-utils.d.ts.map +1 -0
  22. package/dist/display-utils.js +1197 -0
  23. package/dist/display-utils.js.map +17 -0
  24. package/dist/index.d.ts +7 -7
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5427 -112
  27. package/dist/index.js.map +45 -0
  28. package/dist/logging/logger.d.ts +1 -1
  29. package/dist/logging/logger.d.ts.map +1 -1
  30. package/dist/types/capabilities.d.ts +3 -0
  31. package/dist/types/capabilities.d.ts.map +1 -1
  32. package/dist/types/index.d.ts +4 -14
  33. package/dist/types/index.d.ts.map +1 -1
  34. package/dist/types/message-types.d.ts +8 -1
  35. package/dist/types/message-types.d.ts.map +1 -1
  36. package/dist/types/messages/app-to-cloud.d.ts +49 -3
  37. package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
  38. package/dist/types/messages/cloud-to-app.d.ts +18 -6
  39. package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
  40. package/dist/types/messages/cloud-to-glasses.d.ts +30 -2
  41. package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
  42. package/dist/types/messages/glasses-to-cloud.d.ts +24 -1
  43. package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
  44. package/dist/types/rtmp-stream.d.ts +1 -1
  45. package/dist/types/rtmp-stream.d.ts.map +1 -1
  46. package/dist/types/streams.d.ts +31 -2
  47. package/dist/types/streams.d.ts.map +1 -1
  48. package/package.json +34 -11
  49. package/dist/app/index.js +0 -24
  50. package/dist/app/server/index.js +0 -658
  51. package/dist/app/session/api-client.js +0 -101
  52. package/dist/app/session/dashboard.js +0 -149
  53. package/dist/app/session/events.js +0 -315
  54. package/dist/app/session/index.js +0 -1573
  55. package/dist/app/session/layouts.js +0 -372
  56. package/dist/app/session/modules/audio.js +0 -321
  57. package/dist/app/session/modules/camera-managed-extension.js +0 -310
  58. package/dist/app/session/modules/camera.js +0 -607
  59. package/dist/app/session/modules/index.js +0 -19
  60. package/dist/app/session/modules/location.js +0 -61
  61. package/dist/app/session/modules/simple-storage.js +0 -232
  62. package/dist/app/session/settings.js +0 -358
  63. package/dist/app/token/index.js +0 -22
  64. package/dist/app/token/utils.js +0 -144
  65. package/dist/app/webview/index.js +0 -382
  66. package/dist/constants/index.js +0 -16
  67. package/dist/constants/log-messages/color.js +0 -14
  68. package/dist/constants/log-messages/logos.js +0 -48
  69. package/dist/constants/log-messages/updates.js +0 -55
  70. package/dist/constants/log-messages/warning.js +0 -89
  71. package/dist/examples/managed-rtmp-streaming-example.js +0 -158
  72. package/dist/examples/managed-rtmp-streaming-with-restream-example.js +0 -124
  73. package/dist/examples/rtmp-streaming-example.js +0 -102
  74. package/dist/logging/logger.js +0 -79
  75. package/dist/types/capabilities.js +0 -9
  76. package/dist/types/dashboard/index.js +0 -12
  77. package/dist/types/enums.js +0 -75
  78. package/dist/types/index.js +0 -101
  79. package/dist/types/layouts.js +0 -3
  80. package/dist/types/message-types.js +0 -212
  81. package/dist/types/messages/app-to-cloud.js +0 -95
  82. package/dist/types/messages/base.js +0 -3
  83. package/dist/types/messages/cloud-to-app.js +0 -78
  84. package/dist/types/messages/cloud-to-glasses.js +0 -68
  85. package/dist/types/messages/glasses-to-cloud.js +0 -140
  86. package/dist/types/models.js +0 -101
  87. package/dist/types/photo-data.js +0 -2
  88. package/dist/types/rtmp-stream.js +0 -3
  89. package/dist/types/streams.js +0 -306
  90. package/dist/types/token.js +0 -7
  91. package/dist/types/webhooks.js +0 -28
  92. package/dist/utils/animation-utils.js +0 -340
  93. package/dist/utils/bitmap-utils.js +0 -475
  94. package/dist/utils/permissions-utils.js +0 -263
  95. package/dist/utils/resource-tracker.js +0 -153
@@ -1,607 +0,0 @@
1
- "use strict";
2
- /**
3
- * ๐Ÿ“ท Camera Module
4
- *
5
- * Unified camera functionality for App Sessions.
6
- * Handles both photo requests and RTMP streaming from connected glasses.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.CameraModule = void 0;
10
- const types_1 = require("../../../types");
11
- const streams_1 = require("../../../types/streams");
12
- const camera_managed_extension_1 = require("./camera-managed-extension");
13
- const permissions_utils_1 = require("../../../utils/permissions-utils");
14
- /**
15
- * ๐Ÿ“ท Camera Module Implementation
16
- *
17
- * Unified camera management for App Sessions.
18
- * Provides methods for:
19
- * - ๐Ÿ“ธ Requesting photos from glasses
20
- * - ๐Ÿ“น Starting/stopping RTMP streams
21
- * - ๐Ÿ” Monitoring photo and stream status
22
- * - ๐Ÿงน Cleanup and cancellation
23
- *
24
- * @example
25
- * ```typescript
26
- * // Request a photo
27
- * const photoData = await session.camera.requestPhoto({ saveToGallery: true });
28
- *
29
- * // Start streaming
30
- * await session.camera.startStream({ rtmpUrl: 'rtmp://example.com/live/key' });
31
- *
32
- * // Monitor stream status
33
- * session.camera.onStreamStatus((status) => {
34
- * console.log('Stream status:', status.status);
35
- * });
36
- *
37
- * // Stop streaming
38
- * await session.camera.stopStream();
39
- * ```
40
- */
41
- class CameraModule {
42
- /**
43
- * Create a new CameraModule
44
- *
45
- * @param packageName - The App package name
46
- * @param sessionId - The current session ID
47
- * @param send - Function to send messages to the cloud
48
- * @param session - Reference to the parent AppSession (optional)
49
- * @param logger - Logger instance for debugging
50
- */
51
- constructor(packageName, sessionId, send, session, logger) {
52
- // Photo functionality
53
- /** Map to store pending photo request promises */
54
- this.pendingPhotoRequests = new Map();
55
- // Streaming functionality
56
- this.isStreaming = false;
57
- this.packageName = packageName;
58
- this.sessionId = sessionId;
59
- this.send = send;
60
- this.session = session;
61
- this.logger = logger || console;
62
- // Initialize managed extension
63
- this.managedExtension = new camera_managed_extension_1.CameraManagedExtension(packageName, sessionId, send, this.logger, session);
64
- }
65
- // =====================================
66
- // ๐Ÿ“ธ Photo Functionality
67
- // =====================================
68
- /**
69
- * ๐Ÿ“ธ Request a photo from the connected glasses
70
- *
71
- * @param options - Optional configuration for the photo request
72
- * @returns Promise that resolves with the actual photo data
73
- *
74
- * @example
75
- * ```typescript
76
- * // Request a photo
77
- * const photo = await session.camera.requestPhoto();
78
- *
79
- * // Request a photo with custom webhook URL and authentication
80
- * const photo = await session.camera.requestPhoto({
81
- * customWebhookUrl: 'https://my-custom-endpoint.com/photo-upload',
82
- * authToken: 'your-auth-token-here'
83
- * });
84
- * ```
85
- */
86
- async requestPhoto(options) {
87
- return new Promise((resolve, reject) => {
88
- const baseUrl = this.session?.getHttpsServerUrl?.() || "";
89
- (0, permissions_utils_1.cameraWarnLog)(baseUrl, this.packageName, "requestPhoto");
90
- try {
91
- console.log("DEBUG: requestPhoto options:", options);
92
- // Generate unique request ID
93
- const requestId = `photo_req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
94
- // Store promise resolvers for when we get the response
95
- this.pendingPhotoRequests.set(requestId, { resolve, reject });
96
- // Create photo request message
97
- const message = {
98
- type: types_1.AppToCloudMessageType.PHOTO_REQUEST,
99
- packageName: this.packageName,
100
- sessionId: this.sessionId,
101
- requestId,
102
- timestamp: new Date(),
103
- saveToGallery: options?.saveToGallery || false,
104
- customWebhookUrl: options?.customWebhookUrl,
105
- authToken: options?.authToken,
106
- size: options?.size || "medium",
107
- };
108
- // Send request to cloud
109
- this.send(message);
110
- this.logger.info({
111
- requestId,
112
- saveToGallery: options?.saveToGallery,
113
- hasCustomWebhook: !!options?.customWebhookUrl,
114
- hasAuthToken: !!options?.authToken,
115
- }, `๐Ÿ“ธ Photo request sent`);
116
- // If using custom webhook URL, resolve immediately since photo will be uploaded directly to custom endpoint
117
- if (options?.customWebhookUrl) {
118
- this.logger.info({ requestId, customWebhookUrl: options.customWebhookUrl }, `๐Ÿ“ธ Using custom webhook URL - resolving promise immediately since photo will be uploaded directly to custom endpoint`);
119
- // Create a mock PhotoData object for custom webhook URLs
120
- const mockPhotoData = {
121
- buffer: Buffer.from([]), // Empty buffer since we don't have the actual photo
122
- mimeType: "image/jpeg",
123
- filename: "photo.jpg",
124
- requestId,
125
- size: 0,
126
- timestamp: new Date(),
127
- };
128
- // Resolve immediately and clean up
129
- this.pendingPhotoRequests.delete(requestId);
130
- resolve(mockPhotoData);
131
- return;
132
- }
133
- // Set timeout to avoid hanging promises (only for non-custom webhook requests)
134
- const timeoutMs = 30000; // 30 seconds
135
- if (this.session && this.session.resources) {
136
- // Use session's resource tracker for automatic cleanup
137
- this.session.resources.setTimeout(() => {
138
- if (this.pendingPhotoRequests.has(requestId)) {
139
- this.pendingPhotoRequests
140
- .get(requestId)
141
- .reject("Photo request timed out");
142
- this.pendingPhotoRequests.delete(requestId);
143
- this.logger.warn({ requestId }, `๐Ÿ“ธ Photo request timed out`);
144
- }
145
- }, timeoutMs);
146
- }
147
- else {
148
- // Fallback to regular setTimeout if session not available
149
- setTimeout(() => {
150
- if (this.pendingPhotoRequests.has(requestId)) {
151
- this.pendingPhotoRequests
152
- .get(requestId)
153
- .reject("Photo request timed out");
154
- this.pendingPhotoRequests.delete(requestId);
155
- this.logger.warn({ requestId }, `๐Ÿ“ธ Photo request timed out`);
156
- }
157
- }, timeoutMs);
158
- }
159
- }
160
- catch (error) {
161
- const errorMessage = error instanceof Error ? error.message : String(error);
162
- reject(`Failed to request photo: ${errorMessage}`);
163
- }
164
- });
165
- }
166
- /**
167
- * ๐Ÿ“ฅ Handle photo received from /photo-upload endpoint
168
- *
169
- * This method is called internally when a photo response is received.
170
- * It resolves the corresponding pending promise with the photo data.
171
- *
172
- * @param photoData - The photo data received
173
- * @internal This method is used internally by AppSession
174
- */
175
- handlePhotoReceived(photoData) {
176
- const { requestId } = photoData;
177
- const pendingRequest = this.pendingPhotoRequests.get(requestId);
178
- if (pendingRequest) {
179
- this.logger.info({ requestId }, `๐Ÿ“ธ Photo received for request ${requestId}`);
180
- // Resolve the promise with the photo data
181
- pendingRequest.resolve(photoData);
182
- // Clean up
183
- this.pendingPhotoRequests.delete(requestId);
184
- }
185
- else {
186
- this.logger.warn({ requestId }, `๐Ÿ“ธ Received photo for unknown request ID: ${requestId}`);
187
- }
188
- }
189
- /**
190
- * โŒ Handle photo error from /photo-upload endpoint
191
- *
192
- * This method is called internally when a photo error response is received.
193
- * It rejects the corresponding pending promise with the error information.
194
- *
195
- * @param errorResponse - The error response received
196
- * @internal This method is used internally by AppSession
197
- */
198
- handlePhotoError(errorResponse) {
199
- const { requestId, error } = errorResponse;
200
- const pendingRequest = this.pendingPhotoRequests.get(requestId);
201
- if (pendingRequest) {
202
- this.logger.error({ requestId, errorCode: error.code, errorMessage: error.message }, `๐Ÿ“ธ Photo capture failed: ${error.code} - ${error.message}`);
203
- // Reject the promise with the error information
204
- pendingRequest.reject(`${error.code}: ${error.message}`);
205
- // Clean up
206
- this.pendingPhotoRequests.delete(requestId);
207
- }
208
- else {
209
- this.logger.warn({ requestId, errorCode: error.code, errorMessage: error.message }, `๐Ÿ“ธ Received photo error for unknown request ID: ${requestId}`);
210
- }
211
- }
212
- /**
213
- * ๐Ÿ” Check if there's a pending photo request for the given request ID
214
- *
215
- * @param requestId - The request ID to check
216
- * @returns true if there's a pending request
217
- */
218
- hasPhotoPendingRequest(requestId) {
219
- return this.pendingPhotoRequests.has(requestId);
220
- }
221
- /**
222
- * ๐Ÿ“Š Get the number of pending photo requests
223
- *
224
- * @returns Number of pending photo requests
225
- */
226
- getPhotoPendingRequestCount() {
227
- return this.pendingPhotoRequests.size;
228
- }
229
- /**
230
- * ๐Ÿ“‹ Get all pending photo request IDs
231
- *
232
- * @returns Array of pending request IDs
233
- */
234
- getPhotoPendingRequestIds() {
235
- return Array.from(this.pendingPhotoRequests.keys());
236
- }
237
- /**
238
- * โŒ Cancel a pending photo request
239
- *
240
- * @param requestId - The request ID to cancel
241
- * @returns true if the request was cancelled, false if it wasn't found
242
- */
243
- cancelPhotoRequest(requestId) {
244
- const pendingRequest = this.pendingPhotoRequests.get(requestId);
245
- if (pendingRequest) {
246
- pendingRequest.reject("Photo request cancelled");
247
- this.pendingPhotoRequests.delete(requestId);
248
- this.logger.info({ requestId }, `๐Ÿ“ธ Photo request cancelled`);
249
- return true;
250
- }
251
- return false;
252
- }
253
- /**
254
- * ๐Ÿงน Cancel all pending photo requests
255
- *
256
- * @returns Number of requests that were cancelled
257
- */
258
- cancelAllPhotoRequests() {
259
- const count = this.pendingPhotoRequests.size;
260
- for (const [requestId, { reject }] of this.pendingPhotoRequests) {
261
- reject("Photo request cancelled - session cleanup");
262
- this.logger.info({ requestId }, `๐Ÿ“ธ Photo request cancelled during cleanup`);
263
- }
264
- this.pendingPhotoRequests.clear();
265
- return count;
266
- }
267
- // =====================================
268
- // ๐Ÿ“น Streaming Functionality
269
- // =====================================
270
- /**
271
- * ๐Ÿ“น Start an RTMP stream to the specified URL
272
- *
273
- * @param options - Configuration options for the stream
274
- * @returns Promise that resolves when the stream request is sent (not when streaming begins)
275
- *
276
- * @example
277
- * ```typescript
278
- * await session.camera.startStream({
279
- * rtmpUrl: 'rtmp://live.example.com/stream/key',
280
- * video: { resolution: '1920x1080', bitrate: 5000 },
281
- * audio: { bitrate: 128 }
282
- * });
283
- * ```
284
- */
285
- async startStream(options) {
286
- this.logger.info({ rtmpUrl: options.rtmpUrl }, `๐Ÿ“น RTMP stream request starting`);
287
- (0, permissions_utils_1.cameraWarnLog)(this.session.getHttpsServerUrl?.(), this.packageName, "startStream");
288
- if (!options.rtmpUrl) {
289
- throw new Error("rtmpUrl is required");
290
- }
291
- if (this.isStreaming) {
292
- this.logger.error({
293
- currentStreamUrl: this.currentStreamUrl,
294
- requestedUrl: options.rtmpUrl,
295
- }, `๐Ÿ“น Already streaming error`);
296
- throw new Error("Already streaming. Stop the current stream before starting a new one.");
297
- }
298
- // Create stream request message
299
- const message = {
300
- type: types_1.AppToCloudMessageType.RTMP_STREAM_REQUEST,
301
- packageName: this.packageName,
302
- sessionId: this.sessionId,
303
- rtmpUrl: options.rtmpUrl,
304
- video: options.video,
305
- audio: options.audio,
306
- stream: options.stream,
307
- timestamp: new Date(),
308
- };
309
- // Save stream URL for reference
310
- this.currentStreamUrl = options.rtmpUrl;
311
- // Send the request
312
- try {
313
- this.send(message);
314
- this.isStreaming = true;
315
- this.logger.info({ rtmpUrl: options.rtmpUrl }, `๐Ÿ“น RTMP stream request sent successfully`);
316
- return Promise.resolve();
317
- }
318
- catch (error) {
319
- this.logger.error({ error, rtmpUrl: options.rtmpUrl }, `๐Ÿ“น Failed to send RTMP stream request`);
320
- const errorMessage = error instanceof Error ? error.message : String(error);
321
- return Promise.reject(`Failed to request RTMP stream: ${errorMessage}`);
322
- }
323
- }
324
- /**
325
- * ๐Ÿ›‘ Stop the current RTMP stream
326
- *
327
- * @returns Promise that resolves when the stop request is sent
328
- *
329
- * @example
330
- * ```typescript
331
- * await session.camera.stopStream();
332
- * ```
333
- */
334
- async stopStream() {
335
- this.logger.info({
336
- isCurrentlyStreaming: this.isStreaming,
337
- currentStreamUrl: this.currentStreamUrl,
338
- }, `๐Ÿ“น RTMP stream stop request`);
339
- if (!this.isStreaming) {
340
- this.logger.info(`๐Ÿ“น Not streaming - no-op`);
341
- // Not an error - just a no-op if not streaming
342
- return Promise.resolve();
343
- }
344
- // Create stop request message
345
- const message = {
346
- type: types_1.AppToCloudMessageType.RTMP_STREAM_STOP,
347
- packageName: this.packageName,
348
- sessionId: this.sessionId,
349
- streamId: this.currentStreamState?.streamId, // Include streamId if available
350
- timestamp: new Date(),
351
- };
352
- // Send the request
353
- try {
354
- this.send(message);
355
- return Promise.resolve();
356
- }
357
- catch (error) {
358
- const errorMessage = error instanceof Error ? error.message : String(error);
359
- return Promise.reject(`Failed to stop RTMP stream: ${errorMessage}`);
360
- }
361
- }
362
- /**
363
- * ๐Ÿ” Check if currently streaming
364
- *
365
- * @returns True if a stream is active or initializing
366
- */
367
- isCurrentlyStreaming() {
368
- return this.isStreaming;
369
- }
370
- /**
371
- * ๐Ÿ“ Get the URL of the current stream (if any)
372
- *
373
- * @returns The RTMP URL of the current stream, or undefined if not streaming
374
- */
375
- getCurrentStreamUrl() {
376
- return this.currentStreamUrl;
377
- }
378
- /**
379
- * ๐Ÿ“Š Get the current stream status
380
- *
381
- * @returns The current stream status, or undefined if not available
382
- */
383
- getStreamStatus() {
384
- return this.currentStreamState;
385
- }
386
- /**
387
- * ๐Ÿ“บ Subscribe to RTMP stream status updates
388
- * This uses the standard stream subscription mechanism
389
- */
390
- subscribeToStreamStatusUpdates() {
391
- if (this.session) {
392
- this.session.subscribe(streams_1.StreamType.RTMP_STREAM_STATUS);
393
- }
394
- else {
395
- this.logger.error("Cannot subscribe to status updates: session reference not available");
396
- }
397
- }
398
- /**
399
- * ๐Ÿ“บ Unsubscribe from RTMP stream status updates
400
- */
401
- unsubscribeFromStreamStatusUpdates() {
402
- if (this.session) {
403
- this.session.unsubscribe(streams_1.StreamType.RTMP_STREAM_STATUS);
404
- }
405
- }
406
- /**
407
- * ๐Ÿ‘‚ Listen for stream status updates using the standard event system
408
- * @param handler - Function to call when stream status changes
409
- * @returns Cleanup function to remove the handler
410
- *
411
- * @example
412
- * ```typescript
413
- * const cleanup = session.camera.onStreamStatus((status) => {
414
- * console.log('Stream status:', status.status);
415
- * if (status.status === 'error') {
416
- * console.error('Stream error:', status.errorDetails);
417
- * }
418
- * });
419
- *
420
- * // Later, cleanup the listener
421
- * cleanup();
422
- * ```
423
- */
424
- onStreamStatus(handler) {
425
- if (!this.session) {
426
- this.logger.error("Cannot listen for status updates: session reference not available");
427
- return () => { };
428
- }
429
- this.subscribeToStreamStatusUpdates();
430
- return this.session.on(streams_1.StreamType.RTMP_STREAM_STATUS, handler);
431
- }
432
- /**
433
- * ๐Ÿ”„ Update internal stream state based on a status message
434
- * For internal use by AppSession
435
- * @param message - The status message from the cloud
436
- * @internal This method is used internally by AppSession
437
- */
438
- updateStreamState(message) {
439
- this.logger.debug({
440
- messageType: message?.type,
441
- messageStatus: message?.status,
442
- currentIsStreaming: this.isStreaming,
443
- }, `๐Ÿ“น Stream state update`);
444
- // Verify this is a valid stream response
445
- if (!(0, types_1.isRtmpStreamStatus)(message)) {
446
- this.logger.warn({ message }, `๐Ÿ“น Received invalid stream status message`);
447
- return;
448
- }
449
- // Convert to StreamStatus format
450
- const status = {
451
- type: message.type,
452
- streamId: message.streamId,
453
- status: message.status,
454
- errorDetails: message.errorDetails,
455
- appId: message.appId,
456
- stats: message.stats,
457
- timestamp: message.timestamp || new Date(),
458
- };
459
- this.logger.info({
460
- streamId: status.streamId,
461
- oldStatus: this.currentStreamState?.status,
462
- newStatus: status.status,
463
- wasStreaming: this.isStreaming,
464
- }, `๐Ÿ“น Stream status processed`);
465
- // Update local state based on status
466
- if (status.status === "stopped" ||
467
- status.status === "error" ||
468
- status.status === "timeout") {
469
- this.logger.info({
470
- status: status.status,
471
- wasStreaming: this.isStreaming,
472
- }, `๐Ÿ“น Stream stopped - updating local state`);
473
- this.isStreaming = false;
474
- this.currentStreamUrl = undefined;
475
- }
476
- // Save the latest status
477
- this.currentStreamState = status;
478
- }
479
- // =====================================
480
- // ๐Ÿ“น Managed Streaming Functionality
481
- // =====================================
482
- /**
483
- * ๐Ÿ“น Start a managed stream
484
- *
485
- * The cloud handles the RTMP endpoint and returns HLS/DASH URLs for viewing.
486
- * Multiple apps can consume the same managed stream simultaneously.
487
- *
488
- * @param options - Configuration options for the managed stream
489
- * @returns Promise that resolves with viewing URLs when the stream is ready
490
- *
491
- * @example
492
- * ```typescript
493
- * const urls = await session.camera.startManagedStream({
494
- * quality: '720p',
495
- * enableWebRTC: true
496
- * });
497
- * console.log('HLS URL:', urls.hlsUrl);
498
- * ```
499
- */
500
- async startManagedStream(options) {
501
- return this.managedExtension.startManagedStream(options);
502
- }
503
- /**
504
- * ๐Ÿ›‘ Stop the current managed stream
505
- *
506
- * This will stop streaming for this app only. If other apps are consuming
507
- * the same managed stream, it will continue for them.
508
- *
509
- * @returns Promise that resolves when the stop request is sent
510
- */
511
- async stopManagedStream() {
512
- return this.managedExtension.stopManagedStream();
513
- }
514
- /**
515
- * ๐Ÿ”” Register a handler for managed stream status updates
516
- *
517
- * @param handler - Function to call when stream status changes
518
- * @returns Cleanup function to unregister the handler
519
- */
520
- onManagedStreamStatus(handler) {
521
- return this.managedExtension.onManagedStreamStatus(handler);
522
- }
523
- /**
524
- * ๐Ÿ“Š Check if currently managed streaming
525
- *
526
- * @returns true if a managed stream is active
527
- */
528
- isManagedStreamActive() {
529
- return this.managedExtension.isManagedStreamActive();
530
- }
531
- /**
532
- * ๐Ÿ”— Get current managed stream URLs
533
- *
534
- * @returns Current stream URLs or undefined if not streaming
535
- */
536
- getManagedStreamUrls() {
537
- return this.managedExtension.getManagedStreamUrls();
538
- }
539
- /**
540
- * ๐Ÿ” Check for any existing streams (managed or unmanaged) for the current user
541
- *
542
- * This method checks if there's already an active stream for the current user,
543
- * which is useful to avoid conflicts and to reconnect to existing streams.
544
- *
545
- * @returns Promise that resolves with stream information if a stream exists
546
- *
547
- * @example
548
- * ```typescript
549
- * const streamInfo = await session.camera.checkExistingStream();
550
- * if (streamInfo.hasActiveStream) {
551
- * console.log('Stream type:', streamInfo.streamInfo?.type);
552
- * if (streamInfo.streamInfo?.type === 'managed') {
553
- * console.log('HLS URL:', streamInfo.streamInfo.hlsUrl);
554
- * } else {
555
- * console.log('RTMP URL:', streamInfo.streamInfo.rtmpUrl);
556
- * }
557
- * }
558
- * ```
559
- */
560
- async checkExistingStream() {
561
- return this.managedExtension.checkExistingStream();
562
- }
563
- /**
564
- * Handle incoming stream status check response
565
- * @internal
566
- */
567
- handleStreamCheckResponse(response) {
568
- this.managedExtension.handleStreamCheckResponse(response);
569
- }
570
- /**
571
- * Handle incoming managed stream status messages
572
- * @internal
573
- */
574
- handleManagedStreamStatus(message) {
575
- this.managedExtension.handleManagedStreamStatus(message);
576
- }
577
- // =====================================
578
- // ๐Ÿ”ง General Utilities
579
- // =====================================
580
- /**
581
- * ๐Ÿ”ง Update the session ID (used when reconnecting)
582
- *
583
- * @param newSessionId - The new session ID
584
- * @internal This method is used internally by AppSession
585
- */
586
- updateSessionId(newSessionId) {
587
- this.sessionId = newSessionId;
588
- }
589
- /**
590
- * ๐Ÿงน Cancel all pending requests and clean up resources
591
- *
592
- * @returns Object with counts of cancelled requests
593
- */
594
- cancelAllRequests() {
595
- const photoRequests = this.cancelAllPhotoRequests();
596
- // Stop streaming if active
597
- if (this.isStreaming) {
598
- this.stopStream().catch((error) => {
599
- this.logger.error({ error }, "Error stopping stream during cleanup");
600
- });
601
- }
602
- // Clean up managed extension
603
- this.managedExtension.cleanup();
604
- return { photoRequests };
605
- }
606
- }
607
- exports.CameraModule = CameraModule;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./audio"), exports);
18
- __exportStar(require("./camera"), exports);
19
- __exportStar(require("./camera-managed-extension"), exports);
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocationManager = void 0;
4
- const permissions_utils_1 = require("../../../utils/permissions-utils");
5
- const types_1 = require("../../../types");
6
- class LocationManager {
7
- constructor(session, send) {
8
- this.session = session;
9
- this.send = send;
10
- this.lastLocationCleanupHandler = () => { };
11
- }
12
- // subscribes to the continuous location stream with a specified accuracy tier
13
- subscribeToStream(options, handler) {
14
- //Checking for permission location from dev console:
15
- (0, permissions_utils_1.locationWarnLog)(this.session.getHttpsServerUrl() || "", this.session.getPackageName(), this.subscribeToStream.name);
16
- const subscription = {
17
- stream: "location_stream",
18
- rate: options.accuracy,
19
- };
20
- this.session.subscribe(subscription);
21
- this.lastLocationCleanupHandler = this.session.events.onLocation(handler);
22
- return this.lastLocationCleanupHandler;
23
- }
24
- // unsubscribes from the continuous location stream
25
- unsubscribeFromStream() {
26
- if (this.lastLocationCleanupHandler) {
27
- this.lastLocationCleanupHandler();
28
- this.lastLocationCleanupHandler = () => { };
29
- }
30
- else {
31
- this.session.unsubscribe("location_stream");
32
- }
33
- }
34
- // performs a one-time, intelligent poll for a location fix
35
- async getLatestLocation(options) {
36
- return new Promise((resolve, reject) => {
37
- const requestId = `poll_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
38
- // listens for a location update with a matching correlationId
39
- const unsubscribe = this.session.events.on("location_update", (data) => {
40
- if (data.correlationId === requestId) {
41
- unsubscribe(); // clean up the listener
42
- resolve(data);
43
- }
44
- });
45
- // sends the poll request message to the cloud
46
- this.send({
47
- type: types_1.AppToCloudMessageType.LOCATION_POLL_REQUEST,
48
- correlationId: requestId,
49
- packageName: this.session.getPackageName(),
50
- sessionId: this.session.getSessionId(),
51
- accuracy: options.accuracy,
52
- });
53
- // sets a timeout to prevent the promise from hanging indefinitely
54
- setTimeout(() => {
55
- unsubscribe();
56
- reject("Location poll request timed out");
57
- }, 15000); // 15 second timeout
58
- });
59
- }
60
- }
61
- exports.LocationManager = LocationManager;