6.8 KiB
Camera Implementation Documentation
Overview
This document describes how camera functionality is implemented across the TimeSafari application. The application uses cameras for several purposes:
- QR Code scanning for contact sharing and verification
- Photo capture for gift records
- Profile photo management
- Shared photo handling
- Image upload and processing
Components
QRScannerDialog.vue
Primary component for QR code scanning in web browsers.
Key Features:
- Uses
qrcode-stream
for web-based QR scanning - Supports both front and back cameras
- Provides real-time camera status feedback
- Implements error handling with user-friendly messages
- Includes camera switching functionality
Camera Access Flow:
- Checks for camera API availability
- Enumerates available video devices
- Requests camera permissions
- Initializes camera stream with preferred settings
- Handles various error conditions with specific messages
PhotoDialog.vue
Component for photo capture and selection.
Key Features:
- Cross-platform photo capture interface
- Image cropping capabilities
- File selection fallback
- Unified interface for different platforms
ImageMethodDialog.vue
Component for selecting image input method.
Key Features:
- Multiple input methods (camera, file upload, URL)
- Unified interface for image selection
- Integration with PhotoDialog for processing
- Support for image cropping
- URL-based image handling
SharedPhotoView.vue
Component for handling shared photos.
Key Features:
- Processes incoming shared photos
- Options to use photo for gifts or profile
- Image preview and confirmation
- Server upload integration
- Temporary storage management
Services
QRScanner Services
WebDialogQRScanner
Web-based implementation of QR scanning.
Key Methods:
checkPermissions()
: Verifies camera permission statusrequestPermissions()
: Requests camera accessisSupported()
: Checks for camera API support- Handles various error conditions with specific messages
CapacitorQRScanner
Native implementation using Capacitor's MLKit.
Key Features:
- Uses
@capacitor-mlkit/barcode-scanning
- Supports both front and back cameras
- Implements permission management
- Provides continuous scanning capability
Platform Services
WebPlatformService
Web-specific implementation of platform features.
Camera Capabilities:
- Uses HTML5 file input with capture attribute
- Falls back to file selection if camera unavailable
- Processes captured images for consistent format
CapacitorPlatformService
Native implementation using Capacitor.
Camera Features:
- Uses
Camera.getPhoto()
for native camera access - Supports image editing
- Configures high-quality image capture
- Handles base64 image processing
ElectronPlatformService
Desktop implementation (currently unimplemented).
Status:
- Camera functionality not yet implemented
- Planned to use Electron's media APIs
Camera Usage Scenarios
Gift Photo Capture
Implementation:
- Uses PhotoDialog for capture/selection
- Supports multiple input methods
- Optional image cropping
- Server upload with authentication
- Integration with gift records
Flow:
- User initiates photo capture from gift details
- ImageMethodDialog presents input options
- PhotoDialog handles capture/selection
- Image is processed and uploaded
- URL is attached to gift record
Profile Photo Management
Implementation:
- Uses same PhotoDialog component
- Enforces square aspect ratio
- Requires image cropping
- Updates user profile settings
- Handles profile image updates
Flow:
- User initiates profile photo update
- PhotoDialog opens with cropping enabled
- Image is captured/selected
- User crops to square aspect ratio
- Image is uploaded and profile updated
Shared Photo Processing
Implementation:
- Handles incoming shared photos
- Temporary storage in IndexedDB
- Options for photo usage
- Server upload integration
- Cleanup after processing
Flow:
- Photo is shared to application
- Stored temporarily in IndexedDB
- SharedPhotoView presents options
- User chooses usage (gift/profile)
- Image is processed accordingly
Image Upload and Processing
Implementation:
- Secure server upload
- Authentication handling
- Image format standardization
- Error handling and retry
- Progress feedback
Flow:
- Image is prepared for upload
- Authentication token is obtained
- Multipart form data is created
- Upload progress is monitored
- Server URL is returned
Platform-Specific Considerations
iOS
- Requires
NSCameraUsageDescription
in Info.plist - Supports both front and back cameras
- Implements proper permission handling
Android
- Requires camera permissions in manifest
- Supports both front and back cameras
- Handles permission requests through Capacitor
Web
- Requires HTTPS for camera access
- Implements fallback mechanisms
- Handles browser compatibility issues
Error Handling
Common Error Scenarios
- No camera found
- Permission denied
- Camera in use by another application
- HTTPS required
- Browser compatibility issues
Error Response
- User-friendly error messages
- Troubleshooting tips
- Clear instructions for resolution
- Platform-specific guidance
Security Considerations
Permission Management
- Explicit permission requests
- Permission state tracking
- Graceful handling of denied permissions
Data Handling
- Secure image processing
- Proper cleanup of camera resources
- No persistent storage of camera data
Best Practices
Camera Access
- Always check for camera availability
- Request permissions explicitly
- Handle all error conditions
- Provide clear user feedback
- Implement proper cleanup
Performance
- Optimize camera resolution
- Implement proper resource cleanup
- Handle camera switching efficiently
- Manage memory usage
User Experience
- Clear status indicators
- Intuitive camera controls
- Helpful error messages
- Smooth camera switching
- Responsive UI feedback
Future Improvements
Planned Enhancements
- Implement Electron camera support
- Add advanced camera features
- Improve error handling
- Enhance user feedback
- Optimize performance
Known Issues
- Electron camera implementation pending
- Some browser compatibility limitations
- Platform-specific quirks to address
Dependencies
Key Packages
@capacitor-mlkit/barcode-scanning
qrcode-stream
vue-picture-cropper
- Platform-specific camera APIs
Testing
Test Scenarios
- Permission handling
- Camera switching
- Error conditions
- Platform compatibility
- Performance metrics
Test Environment
- Multiple browsers
- iOS and Android devices
- Desktop platforms
- Various network conditions