MediaTrackConstraints: displaySurface property
The MediaTrackConstraints
dictionary's displaySurface
property is a ConstrainDOMString
describing the requested or mandatory constraints placed upon the value of the displaySurface
constrainable property.
This is used to specify the type or types of display surfaces which getDisplayMedia()
will let the user select among for sharing purposes.
If needed, you can determine whether or not this constraint is supported by checking the value of MediaTrackSupportedConstraints.displaySurface
as returned by a call to MediaDevices.getSupportedConstraints()
. However, typically this is unnecessary since browsers will ignore any constraints they're unfamiliar with.
Value
A ConstrainDOMString
which specifies the type of display surface that's being captured.
This value does not affect the list of display sources in the browser's user interface.
Usage notes
You can check the setting selected by the user agent after the display media has been
created by getDisplayMedia()
by calling
getSettings()
on the display media's
video MediaStreamTrack
, then checking the value of the returned
MediaTrackSettings
object's
displaySurface
object.
For example, if your app needs to know when the surface being shared is a monitor — meaning that there's possibly a non-content backdrop being captured — it can use code similar to this:
let mayHaveBackdropFlag = false;
let displaySurface = displayStream
.getVideoTracks()[0]
.getSettings().displaySurface;
if (displaySurface === "monitor") {
mayHaveBackdropFlag = true;
}
Following this code, mayHaveBackdrop
is true
if the display
surface contained in the stream is of type monitor
.
Later code can use this flag to determine whether or not to perform special processing,
such as to remove or replace the backdrop, or to "cut" the individual display areas out
of the received frames of video.
Examples
Here are some example constraints objects for getDisplayMedia()
that make
use of the displaySurface
property. In addition, see the
Constraint exerciser example
that demonstrates how constraints are used.
Specifications
Specification |
---|
Screen Capture # dom-mediatrackconstraintset-displaysurface |
Browser compatibility
BCD tables only load in the browser