MediaTrackConstraints: groupId property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
TheMediaTrackConstraints dictionary'sgroupId property is aConstrainDOMStringdescribing the requested or mandatory constraints placed upon the value of thegroupId constrainable property.
If needed, you can determine whether or not this constraint is supported by checkingthe value ofMediaTrackSupportedConstraints.groupId as returned by a calltoMediaDevices.getSupportedConstraints(). However, typically this isunnecessary since browsers will ignore any constraints they're unfamiliar with.
In this article
Value
An object based onConstrainDOMString specifying one or more acceptable,ideal, and/or exact (mandatory) group IDs which are acceptable as the source of mediacontent.
Group IDs are unique for a given origin for the duration of a single browsing session,and are shared by all media sources that come from the same physical device. Forexample, the microphone and speaker on the same headset would share a group ID. Thismakes it possible to use the group ID to ensure that the audio and input devices are onthe same headset by retrieving the group ID of the input device and specifying it whenasking for an output device, perhaps.
However, the value of thegroupId is determined by the source of thetrack's content, and there's no particular format mandated by the specification(although some kind of GUID is recommended). That means that a given track will onlyreturn one value for thegroupId when you callgetCapabilities(), and keep in mindthat this value will change for each browsing session.
Because of this, there's no use for the group ID when callingMediaStreamTrack.applyConstraints(), since there is only one possiblevalue, and you can't use it to ensure the same group is used across multiple browsingsessions when callinggetUserMedia().
Examples
See theConstraint exerciser example.
Specifications
| Specification |
|---|
| Media Capture and Streams> # dom-mediatrackconstraintset-groupid> |