Skip to main content

Overview

PhotoManager handles photo capture requests within a user session. It manages the lifecycle of photo requests from apps, forwards them to smart glasses, handles responses, and supports both default and custom webhook URLs for photo uploads. File: packages/cloud/src/services/session/PhotoManager.ts

Key Features

  1. Photo Request Management: Tracks pending photo requests with timeouts
  2. Webhook Support: Handles both default and custom webhook URLs
  3. Gallery Integration: Supports saving photos to device gallery
  4. Timeout Handling: Automatic cleanup of stale requests
  5. App Communication: Sends photo results back to requesting apps
  6. Session Lifecycle: Cleans up pending requests on disposal

Architecture

Request Management

Photo Request Structure

Request Processing

Webhook Handling

Custom Webhook Flow

When a custom webhook URL is provided:

Default Webhook

For apps without custom webhooks:

Response Handling

Photo Response Processing

Result Distribution

Timeout Management

Timeout Handler

Message Formats

Request to Glasses

Response from Glasses

Photos can be saved to the device gallery:

Lifecycle Management

Disposal

Error Handling

Connection Validation

Unknown Request Handling

Best Practices

  1. Always validate WebSocket connection before sending requests
  2. Use custom webhooks for direct uploads when possible
  3. Set appropriate timeouts based on network conditions
  4. Clean up pending requests on session disposal
  5. Log all state transitions for debugging
  6. Handle resurrection when sending results to apps

Future Enhancements

Current TODOs in the code:
  1. Error Response Support: Extend photo result to include error field
  2. Cancellation Notices: Send cancellation messages to apps on disposal
  3. Retry Logic: Implement retry for failed photo requests
  4. Progress Updates: Support progress notifications during upload

Integration Points

  • AppManager: Sends results to apps with resurrection support
  • WebSocket: Communicates with smart glasses
  • Installed Apps: Retrieves default webhook URLs
  • Message Types: Uses SDK-defined message formats