MediaStreamTrack: getConstraints() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
ThegetConstraints()
method oftheMediaStreamTrack
interface returns aMediaTrackConstraints
object containing the set of constraints mostrecently established for the track using a prior call toapplyConstraints()
. Theseconstraints indicate values and ranges of values that the website or application hasspecified are required or acceptable for the included constrainable properties.
Constraints can be used to ensure that the media meets certain guidelines you prefer.For example, you may prefer high definition video but require that the frame rate be alittle low to help keep the data rate low enough not overtax the network. Constraintscan also specify ideal and/or acceptable sizes or ranges of sizes. SeeCapabilities, constraints, and settings for details on how to work with constrainable properties.
In this article
Syntax
getConstraints()
Parameters
None.
Return value
AMediaTrackConstraints
object which indicates the constrainableproperties the website or app most recently set usingapplyConstraints()
. The propertiesin the returned object are listed in the same order as when they were set, and onlyproperties specifically set by the site or app are included.
Note:The returned set of constraints doesn't necessarily describethe actual state of the media. Even if any of the constraints couldn't be met, theyare still included in the returned object as originally set by the site's code. To getthe currently active settings for all constrainable properties, you should insteadcallgetSettings()
.
Examples
This example obtains the current constraints for a track, sets thefacingMode
, and applies the updatedconstraints.
function switchCameras(track, camera) { const constraints = track.getConstraints(); constraints.facingMode = camera; track.applyConstraints(constraints);}
Specifications
Specification |
---|
Media Capture and Streams> # dom-mediastreamtrack-getconstraints> |
Browser compatibility
Loading…