docs.rodeo

MDN Web Docs mirror

MediaTrackConstraints

{{APIRef("Media Capture and Streams")}} 

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 {{domxref("MediaStreamTrack.applyConstraints", "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 {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}} .

Constraints

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: min and exact values are not permitted in constraints used in {{domxref("MediaDevices.getDisplayMedia()")}}  calls — they produce a TypeError — but they are allowed in constraints used in {{domxref("MediaStreamTrack.applyConstraints()")}}  calls.

ConstrainBoolean

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:

ConstrainDouble

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:

ConstrainDOMString

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:

ConstrainULong

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:

Instance properties

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")}} .

Instance properties of all media tracks

Instance properties of audio tracks

Instance properties of image tracks

Instance properties of video tracks

Instance properties of shared screen tracks

These constraints apply to the video property of the object passed into {{domxref("MediaDevices.getDisplayMedia", "getDisplayMedia()")}}  to obtain a stream for screen sharing.

Specifications

{{Specifications}} 

See also

In this article

View on MDN