LeCodesdocs

CameraViewer

The device camera as a live preview plus still-photo capture. All methods are static — there is one camera session, no instances. takePhoto() returns a File (a host buffer handle), so a shot can go straight into a texture (Texture2D.load(file)), an upload (FormData), or the share sheet (share(file)).

At a glance

TypeScript
await CameraViewer.open()                 // asks permission, starts the back-camera preview
const photo = await CameraViewer.takePhoto()
CameraViewer.close()

share(photo, 'My shot')

API

TypeScript
CameraViewer.open(facingMode?: 'front' | 'back'): Promise<void>   // default 'back'
CameraViewer.setFacingMode(facingMode: 'front' | 'back'): void    // switch while open
CameraViewer.takePhoto(): Promise<File>                           // host-encoded still image
CameraViewer.close(): void                                        // stop preview, release camera

open() first requests camera permission (the same engine-level request QRScanner uses), then starts the live preview. The promise rejects if permission is denied or the camera can't start — handle it.

Note

lifecycle — the camera stays claimed until close(). Always close when leaving the screen (onClose), or the camera (and its OS indicator) stays on.

See also

  • Files & shareshare() a captured photo; openFilePicker as the non-camera way to get an image
  • Networking — the File handle and uploading via FormData