files/en-us/web/api/mediatrackconstraints/index.md
{{APIRef("Media Capture and Streams")}}
The MediaTrackConstraints dictionary is used to describe a set of media capabilities and the value or values each can take on.
A constraints dictionary is passed into the {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} method of the {{domxref("MediaStreamTrack")}} interface 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.
The most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.
Objects of this type may also be passed to:
The {{domxref("MediaDevices.getUserMedia()")}} method, to specify constraints on a media stream requested from hardware such as a camera or microphone.
The {{domxref("MediaDevices.getDisplayMedia()")}} method, to specify constraints on a media stream requested from a screen or window capture.
The following types are used to specify a constraint for a property.
They allow you to specify one or more exact values from which one must be the parameter's value, or a set of ideal values which should be used if possible.
You can also specify a single value (or an array of values) which the user agent will do its best to match once all more stringent constraints have been applied.
To learn more about how constraints work, see Capabilities, constraints, and settings.
[!NOTE]
minandexactvalues are not permitted in constraints used in {{domxref("MediaDevices.getDisplayMedia()")}} calls — they produce aTypeError— but they are allowed in constraints used in {{domxref("MediaStreamTrack.applyConstraints()")}} calls.
The ConstrainBoolean constraint type is used to specify a constraint for a property whose value is a Boolean value.
Its value may either be set to a Boolean (true or false) or an object containing the following properties:
exact
ideal
The ConstrainBooleanOrDOMString constraint type is used to specify a constraint for a property whose value is a Boolean or string value. It can take values as specified in the ConstrainBoolean and ConstrainDOMString sections.
The ConstrainDouble constraint type is used to specify a constraint for a property whose value is a double-precision floating-point number.
Its value may either be set to a number or an object containing the following properties:
max
min
exact
ideal
The ConstrainDOMString constraint type is used to specify a constraint for a property whose value is a string.
Its value may either be set to a string, an array of strings, or an object containing the following properties:
exact
ideal
The ConstrainULong constraint type is used to specify a constraint for a property whose value is an integer.
Its value may either be set to a number or an object containing the following properties:
max
min
exact
ideal
Some combination—but not necessarily all—of the following properties will exist on the object. This may be because a given browser doesn't support the property, or because it doesn't apply For example, because {{Glossary("RTP")}} doesn't provide some of these values during negotiation of a WebRTC connection, a track associated with a {{domxref("RTCPeerConnection")}} will not include certain values, such as {{domxref("MediaTrackConstraints.facingMode", "facingMode")}} or {{domxref("MediaTrackConstraints.groupId", "groupId")}}.
ConstrainDOMString object specifying a device ID or an array of device IDs which are acceptable and/or required.ConstrainDOMString object specifying a group ID or an array of group IDs which are acceptable and/or required.ConstrainBoolean object which specifies whether automatic gain control is preferred and/or required.ConstrainULong specifying the channel count or range of channel counts which are acceptable and/or required.ConstrainBooleanOrDOMString object specifying whether or not echo cancellation is preferred and/or required, and if supported, what type.ConstrainDouble specifying the latency or range of latencies which are acceptable and/or required.ConstrainBoolean which specifies whether noise suppression is preferred and/or required.ConstrainULong specifying the sample rate or range of sample rates which are acceptable and/or required.ConstrainULong specifying the sample size or range of sample sizes which are acceptable and/or required.ConstrainDouble specifying the volume or range of volumes which are acceptable and/or required.whiteBalanceMode
"none", "manual", "single-shot", or "continuous".exposureMode
"none", "manual", "single-shot", or "continuous".focusMode
"none", "manual", "single-shot", or "continuous".pointsOfInterest
exposureCompensation
ConstrainDouble (a double-precision integer) specifying f-stop adjustment by up to ±3.colorTemperature
ConstrainDouble (a double-precision integer) specifying a desired color temperature in degrees kelvin.iso
ConstrainDouble (a double-precision integer) specifying a desired iso setting.brightness
ConstrainDouble (a double-precision integer) specifying a desired brightness setting.contrast
ConstrainDouble (a double-precision integer) specifying the degree of difference between light and dark.saturation
ConstrainDouble (a double-precision integer) specifying the degree of color intensity.sharpness
ConstrainDouble (a double-precision integer) specifying the intensity of edges.focusDistance
ConstrainDouble (a double-precision integer) specifying distance to a focused object.zoom
ConstrainDouble (a double-precision integer) specifying the desired focal length.torch
ConstrainDouble specifying the video {{glossary("aspect ratio")}} or range of aspect ratios which are acceptable and/or required.ConstrainDOMString object specifying a facing or an array of facings which are acceptable and/or required.ConstrainDouble specifying the frame rate or range of frame rates which are acceptable and/or required.ConstrainULong specifying the video height or range of heights which are acceptable and/or required.ConstrainULong specifying the video width or range of widths which are acceptable and/or required.resizeMode
: A ConstrainDOMString object specifying a mode or an array of modes the UA can use to derive the resolution and frame rate of a video track.
Allowed values are:
crop-and-scale
none
If resizeMode is unspecified the browser will choose a resolution based on a fitness distance that considers the specified constraints and both of the allowed values.
These constraints apply to the video property of the object passed into {{domxref("MediaDevices.getDisplayMedia", "getDisplayMedia()")}} to obtain a stream for screen sharing.
{{domxref("MediaTrackConstraints.displaySurface", "displaySurface")}}
ConstrainDOMString which specifies the types of display surface that may be selected by the user.
This may be a single one of the following strings, or a list of them to allow multiple source surfaces:
browser
monitor
window
{{domxref("MediaTrackConstraints.logicalSurface", "logicalSurface")}}
ConstrainBoolean value which may contain a single Boolean value or a set of them, indicating whether or not to allow the user to choose source surfaces which do not directly correspond to display areas.
These may include backing buffers for windows to allow capture of window contents that are hidden by other windows in front of them, or buffers containing larger documents that need to be scrolled through to see the entire contents in their windows.{{domxref("MediaTrackConstraints.suppressLocalAudioPlayback", "suppressLocalAudioPlayback")}} {{Experimental_Inline}}
ConstrainBoolean value describing the requested or mandatory constraints placed upon the value of the {{domxref("MediaTrackSettings.suppressLocalAudioPlayback","suppressLocalAudioPlayback")}} constrainable property.
This property controls whether the audio playing in a tab will continue to be played out of a user's local speakers when the tab is captured.{{domxref("MediaTrackConstraints.restrictOwnAudio", "restrictOwnAudio")}} {{Experimental_Inline}}
ConstrainBoolean value that specifies the requested or mandatory constraints placed on the value of the {{domxref("MediaTrackSettings.restrictOwnAudio","restrictOwnAudio")}} constrainable property.
This property controls whether the system audio originating from the capturing tab is filtered out of the screen capture.{{Specifications}}