CameraDeviceFactory

interface CameraDeviceFactory extends HybridObject

The CameraDeviceFactory allows getting CameraDevices, listening to device changes, and querying extensions or preferred Cameras.

Properties

cameraDevices

readonly cameraDevices: CameraDevice[]

Get a list of all CameraDevices on this platform.

This list may change as CameraDevices get plugged in/out (e.g. 'external' Cameras via USB/UVC), devices become available/unavailable (e.g. continuity Cameras), or Camera positions change (e.g. on foldable phones).


supportedMultiCamDeviceCombinations

readonly supportedMultiCamDeviceCombinations: CameraDevice[][]

A list of all CameraDevice combinations that are supported in Multi-Cam CameraSessions.

This list always contains a subset of cameraDevices, often less.

Discussion

For example, on many platforms only a 'front' and a 'back' CameraDevice are supported to be used in a Multi-Cam CameraSession - in this case, the returned 2D Array looks something like this:

[
  [{ position: 'back', ... }, { position: 'front', ... }]
]

Two 'back'-, or two 'front' CameraDevices are often not supported together in a Multi-Cam CameraSession.

When creating a Multi-Cam CameraSession, you must ensure that you are using Device combinations that are actually supported on the platform, otherwise the session might fail to configure.

Discussion

If the platform does not support Multi-Cam CameraSessions, an empty array ([]) will be returned.

Example

if (VisionCamera.supportsMultiCamSessions) {
  const deviceFactory = await VisionCamera.createDeviceFactory()
  const deviceCombinations = deviceFactory.supportedMultiCamDeviceCombinations[0]
  if (deviceCombinations != null) {
    const connections = deviceCombinations.map((device) => {
      const previewOutput = VisionCamera.createPreviewOutput()
      return {
        input: device,
        outputs: [
          { output: previewOutput, mirrorMode: 'auto' }
        ],
        constraints: []
      } satisfies CameraSessionConnection
    })

    const session = await VisionCamera.createCameraSession(true)
    const controllers = await session.configure(connections)
    await session.start()
  }
}

See

CameraFactory.supportsMultiCamSessions


userPreferredCamera?

optional userPreferredCamera: CameraDevice

Get or set the user's default preferred camera device. Setting a device here will persist the preference between apps.

Methods

addOnCameraDevicesChangedListener()

addOnCameraDevicesChangedListener(listener: (newDevices: CameraDevice[]) => void): ListenerSubscription

Add a listener to be called whenever the available cameraDevices change, for example when an external USB Camera gets plugged in- or out- of the Device.


getCameraForId()

getCameraForId(id: string): CameraDevice | undefined

Get the CameraDevice with the given unique id.

If no device with the given id is found, this method returns undefined.


getDefaultCamera()

getDefaultCamera(position: CameraPosition): CameraDevice | undefined

Get the platform's default CameraDevice at the given CameraPosition.


getSupportedExtensions()

getSupportedExtensions(camera: CameraDevice): Promise<CameraExtension[]>

Gets a list of all vendor-specific CameraExtensions the given CameraDevice supports.

A CameraExtension can be enabled when creating a CameraSession via configure(...).