MediaTrackConstraints: deviceId property
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.
TheMediaTrackConstraints dictionary'sdeviceId property is aConstrainDOMStringdescribing the requested or mandatory constraints placed upon the value of thedeviceId constrainable property.
If needed, you can determine whether or not this constraint is supported by checkingthe value ofMediaTrackSupportedConstraints.deviceId as returned by acall toMediaDevices.getSupportedConstraints(). However, typically thisis unnecessary since browsers will ignore any constraints they're unfamiliar with.
BecauseRTP doesn't include this information, tracks associated with aWebRTCRTCPeerConnectionwill never include this property.
In this article
Value
An object based onConstrainDOMString specifying one or more acceptable,ideal, and/or exact (mandatory) device IDs which are acceptable as the source of mediacontent.
Device IDs are unique for a given origin, and are guaranteed to be the same acrossbrowsing sessions on the same origin. However, the value of thedeviceId isdetermined by the source of the track's content, and there's no particular formatmandated by the specification (although some kind of GUID is recommended). That meansthat a given track will only return one value for thedeviceId when youcallgetCapabilities().
Because of this, there's no use for the device ID when callingMediaStreamTrack.applyConstraints(), since there is only one possiblevalue; however, you can record adeviceId and use it to ensure that you getthe same source for multiple calls togetUserMedia().
Note:An exception to the rule that device IDs are the same across browsing sessions:private browsing mode will use a different ID, and will change it each browsingsession.
Examples
See theConstraint exerciser example.
Specifications
| Specification |
|---|
| Media Capture and Streams> # dom-mediatrackconstraintset-deviceid> |