The MediaTrackConstraints dictionary is used to describe a set of capabilities and the value or values each can take on. A constraints dictionary is passed into applyConstraints() to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling getConstraints().
For each constraint, you can typically specify an exact value you need, an ideal value you want, a range of acceptable values, and/or a value which you'd like to be as close to as possible. The specifics vary somewhat depending on the type of the constrainable property.
To learn more about how constraints work, see Capabilities, constraints, and settings.
Some combination—but not necessarily all—of the following properties will exist on the object.
deviceIdConstrainDOMString object specifying a device ID or an array of device IDs which are acceptable and/or required.groupIdConstrainDOMString object specifying a group ID or an array of group IDs which are acceptable and/or required.autoGainControlConstrainBoolean object which specifies whether automatic gain control is preferred and/or required.channelCountConstrainLong specifying the channel count or range of channel counts which are acceptable and/or required.echoCancellationConstrainBoolean object specifying whether or not echo cancellation is preferred and/or required.latencyConstrainDouble specifying the latency or range of latencies which are acceptable and/or required.noiseSuppressionConstrainBoolean which specifies whether noise suppression is preferred and/or required.sampleRateConstrainLong specifying the sample rate or range of sample rates which are acceptable and/or required.sampleSizeConstrainLong specifying the sample size or range of sample sizes which are acceptable and/or required.volumeConstrainDouble specifying the volume or range of volumes which are acceptable and/or required.whiteBalanceModeString specifying one of "none", "manual", "single-shot", or "continuous".exposureModeString specifying one of "none", "manual", "single-shot", or "continuous".focusModeString specifying one of "none", "manual", "single-shot", or "continuous".pointsOfInterestexposureCompensationConstrainDouble (a double-precision integer) specifying f-stop adjustment by up to ±3. colorTemperatureConstrainDouble (a double-precision integer) specifying a desired color temperature in degrees kelvin.isoConstrainDouble (a double-precision integer) specifying a desired iso setting.brightnessConstrainDouble (a double-precision integer) specifying a desired brightness setting.contrastConstrainDouble (a double-precision integer) specifying the degree of difference between light and dark.saturationConstrainDouble (a double-precision integer) specifying the degree of color intensity.sharpnessConstrainDouble (a double-precision integer) specifying the intensity of edges.focusDistanceConstrainDouble (a double-precision integer) specifying distance to a focused object.zoomConstrainDouble (a double-precision integer) specifying the desired focal length.torchBoolean defining whether the fill light is continuously connected, meaning it stays on as long as the track is active.aspectRatioConstrainDouble specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.facingModeConstrainDOMString object specifying a facing or an array of facings which are acceptable and/or required.frameRateConstrainDouble specifying the frame rate or range of frame rates which are acceptable and/or required.heightConstrainLong specifying the video height or range of heights which are acceptable and/or required.widthConstrainLong specifying the video width or range of widths which are acceptable and/or required.resizeModeConstrainDOMString object specifying a mode or an array of modes the UA can use to derive the resolution of a video track. Allowed values are "none" and "crop-and-scale". "none" means that the UA uses the resolution provided by the camera, its driver or the OS. "crop-and-scale" means that the UA can use cropping and downscaling on the camera output in order to satisfy other constraints that affect the resolution.| Specification | Status | Comment |
|---|---|---|
| Media Capture and Streams The definition of 'applyConstraints()' in that specification. | Candidate Recommendation | Initial definition. |
| MediaStream Image Capture The definition of 'applyConstraints()' in that specification. | Working Draft | Adds image constraints. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 59 | Yes | ? | ? | 46 | ? |
aspectRatio |
Yes | ? | No | No | Yes | ? |
autoGainControl |
Yes | ? | 55
|
No | Yes | ? |
channelCount |
Yes | ? | No | No | Yes | ? |
deviceId |
Yes | ? | 50 | No | Yes | ? |
echoCancellation |
Yes | ? | 50 | No | Yes | ? |
facingMode |
Yes | ? | 50 | No | Yes | ? |
frameRate |
Yes | ? | 50 | No | Yes | ? |
groupId |
Yes | ? | 50 | No | Yes | ? |
height |
Yes | ? | 50 | No | Yes | ? |
latency |
Yes | ? | 50 | No | Yes | ? |
noiseSuppression |
Yes | ? | 55
|
No | Yes | ? |
sampleRate |
Yes | ? | No | No | Yes | ? |
sampleSize |
Yes | ? | No | No | Yes | ? |
volume |
Yes | ? | No | No | Yes | ? |
width |
Yes | ? | 50 | No | Yes | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 59 | Yes | Yes | Yes | 46 | ? | ? |
aspectRatio |
? | Yes | ? | 29 | ? | ? | ? |
autoGainControl |
Yes | Yes | ? | 55
|
? | ? | ? |
channelCount |
Yes | Yes | ? | No | ? | ? | ? |
deviceId |
Yes | Yes | ? | 50 | ? | ? | ? |
echoCancellation |
Yes | Yes | ? | 50 | ? | ? | ? |
facingMode |
Yes | Yes | ? | 50 | ? | ? | ? |
frameRate |
Yes | Yes | ? | 50 | ? | ? | ? |
groupId |
Yes | Yes | ? | 50 | ? | ? | ? |
height |
Yes | Yes | ? | 50 | ? | ? | ? |
latency |
Yes | Yes | ? | 50 | ? | ? | ? |
noiseSuppression |
Yes | Yes | ? | 55
|
? | ? | ? |
sampleRate |
Yes | Yes | ? | No | ? | ? | ? |
sampleSize |
Yes | Yes | ? | No | ? | ? | ? |
volume |
Yes | Yes | ? | No | ? | ? | ? |
width |
Yes | Yes | ? | 50 | ? | ? | ? |
MediaDevices.getUserMedia()MediaStreamTrack.getConstraints()MediaStreamTrack.applyConstraints()MediaDevices.getSupportedConstraints()MediaTrackSupportedConstraintsMediaStreamTrack.getSettings()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints