mbr/elm-camera/1.0.0

NOTE: the latest version is 1.3.0

Camera.Configuration

Types for asking what a camera can do and changing how it behaves.

An application can change only settings that both the browser recognizes and the particular camera supports.

Camera configuration has three related parts:

  • Capabilities contains the values a camera can support.
  • Constraints contains the values the application asks for.
  • Settings contains the values the browser is actually using.

A browser may know a setting without supporting every value or combination on a particular camera. Properties it does not report are Nothing. After configuring a camera, use the returned Settings as the camera's current settings.

Camera state

type alias Capabilities =
{ width : Maybe NumericRange
, height : Maybe NumericRange
, aspectRatio : Maybe NumericRange
, frameRate : Maybe NumericRange
, facingMode : Maybe (List FacingMode)
, resizeMode : Maybe (List ResizeMode)
, focusMode : Maybe (List MeteringMode)
, focusDistance : Maybe NumericRange
, exposureMode : Maybe (List MeteringMode)
, exposureCompensation : Maybe NumericRange
, exposureTime : Maybe NumericRange
, iso : Maybe NumericRange
, whiteBalanceMode : Maybe (List MeteringMode)
, colorTemperature : Maybe NumericRange
, brightness : Maybe NumericRange
, contrast : Maybe NumericRange
, saturation : Maybe NumericRange
, sharpness : Maybe NumericRange
, zoom : Maybe NumericRange
, torch : Maybe (List Bool)
, pan : Maybe NumericRange
, tilt : Maybe NumericRange
, backgroundBlur : Maybe (List Bool)
}

The values supported by an open camera.

Numbers use ranges, while modes and Boolean properties list their available values. Nothing means the camera does not report that property.

type alias Constraints =
{ width : Maybe Float
, height : Maybe Float
, aspectRatio : Maybe Float
, frameRate : Maybe Float
, facingMode : Maybe FacingMode
, resizeMode : Maybe ResizeMode
, focusMode : Maybe MeteringMode
, focusDistance : Maybe Float
, exposureMode : Maybe MeteringMode
, exposureCompensation : Maybe Float
, exposureTime : Maybe Float
, iso : Maybe Float
, whiteBalanceMode : Maybe MeteringMode
, colorTemperature : Maybe Float
, brightness : Maybe Float
, contrast : Maybe Float
, saturation : Maybe Float
, sharpness : Maybe Float
, zoom : Maybe Float
, torch : Maybe Bool
, pan : Maybe Float
, tilt : Maybe Float
, backgroundBlur : Maybe Bool
}

Settings to ask a camera to use.

Every field is optional. Keep this value in your application model when making several changes, and use defaultConstraints when starting without preferences.

defaultConstraints : Constraints

Camera constraints with no requested values.

type alias Settings =
{ width : Maybe Int
, height : Maybe Int
, aspectRatio : Maybe Float
, frameRate : Maybe Float
, facingMode : Maybe FacingMode
, resizeMode : Maybe ResizeMode
, deviceId : Maybe DeviceId
, groupId : Maybe String
, focusMode : Maybe MeteringMode
, focusDistance : Maybe Float
, exposureMode : Maybe MeteringMode
, exposureCompensation : Maybe Float
, exposureTime : Maybe Float
, iso : Maybe Float
, whiteBalanceMode : Maybe MeteringMode
, colorTemperature : Maybe Float
, brightness : Maybe Float
, contrast : Maybe Float
, saturation : Maybe Float
, sharpness : Maybe Float
, zoom : Maybe Float
, torch : Maybe Bool
, pan : Maybe Float
, tilt : Maybe Float
, backgroundBlur : Maybe Bool
}

The settings a camera is currently using.

The browser returns these after opening or configuring a camera. A field is Nothing when the browser does not report it.

Constraint support

= WidthConstraint
| HeightConstraint
| AspectRatioConstraint
| FrameRateConstraint
| FacingModeConstraint
| ResizeModeConstraint
| FocusModeConstraint
| FocusDistanceConstraint
| ExposureModeConstraint
| ExposureCompensationConstraint
| ExposureTimeConstraint
| IsoConstraint
| WhiteBalanceModeConstraint
| ColorTemperatureConstraint
| BrightnessConstraint
| ContrastConstraint
| SaturationConstraint
| SharpnessConstraint
| ZoomConstraint
| TorchConstraint
| PanConstraint
| TiltConstraint
| BackgroundBlurConstraint
| UnknownConstraint String

A camera setting name recognized by the browser.

A particular camera may still not support the setting or a requested combination of values. Unknown names are kept in UnknownConstraint.

Return the Web API name for a supported constraint.

type alias NumericRange =
{ minimum : Float
, maximum : Float
, step : Maybe Float
}

A range of values supported by a camera.

step is Nothing when the camera does not report an increment.

contains : NumericRange -> Float -> Bool

Check whether a value is within a camera's advertised minimum and maximum.

This does not check whether the value follows the optional step increment.

Modes

= UserFacing
| EnvironmentFacing
| LeftFacing
| RightFacing
| UnknownFacingMode String

The direction a camera faces relative to its device.

Unknown values are kept so newer browser values can still pass through Elm.

Return the Web API name for a facing mode.

= NoMetering
| Manual
| SingleShot
| Continuous
| UnknownMeteringMode String

An automatic or manual mode used by camera controls.

Continuous is commonly used for autofocus, automatic exposure, and automatic white balance. Unknown browser values are kept in UnknownMeteringMode.

Return the Web API name for a metering mode.

= NoResize
| CropAndScale
| UnknownResizeMode String

Whether the browser may crop and scale camera output.

Return the Web API name for a resize mode.