MediaStreamTrack.applyConstraints()

The applyConstraints() method of the MediaStreamTrack interface applies a set of constraints to the track; these constraints let the Web site or app establish ideal values and acceptable ranges of values for the constrainable properties of the track, such as frame rate, dimensions, echo cancelation, and so forth.

Constraints can be used to ensure that the media meets certain guidelines you prefer. For example, you may prefer high density video but require that the frame rate be a little low to help keep the data rate low enough not overtax the network. Constraints can also specify ideal and/or acceptable sizes or ranges of sizes. See See "Applying_constraints" in Media Capture and Streams API (Media Streams) for more information on how to apply your preferred constraints.

Syntax

JavaScript
var appliedPromise = MediaStreamTrack.applyConstraints(constraints);

Parameters

constraints Optional
A MediaTrackConstraints object listing the constraints to apply to the track's constrainable properties; any existing constraints are replaced with the new values specified, and any constrainable properties not included are restored to their default constraints. If this parameter is omitted, all currently set custom constraints are cleared.

Return value

A Promise which resolves when the constraints have been successfully applied. If the constraints cannot be applied, the promise is rejected with a MediaStreamError whose name is OverconstrainedError, to indicate that the constraints could not be met. This can happen if the specified constraints are too strict to find a match when attempting to configure the track.

Specifications

Specification Status Comment
Media Capture and Streams
The definition of 'applyConstraints()' in that specification.
Editor's Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 53.0 43 (43) ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 53.0 43.0 (43) ? ? ? 52.0

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/mediastreamtrack/applyconstraints

API applyConstraints Constraints Media Capture and Streams API Media Streams API MediaStreamTrack Method