This document proposes a set of HTML elements, <usermedia>, <camera>, and <microphone>, that mean to provide user-friendly and secure access to a {{MediaStream}}, handling the required premissions in the process.
This is a delta specification, meant to eventually be included in [[mediacapture-streams]] or [[mediacapture-extensions]].
This is a delta specification, meant to eventually be included in [[mediacapture-streams]] or [[mediacapture-extensions]]. It currently contains only the differences from this spec.
The <usermedia>, <camera>, and <microphone> HTML elements are [[HTML]] elements that can mediate access to a {{MediaStream}}, including handling the required [=permission/prompts=] for [=powerful features=].
These three elements cover three different use cases and allow for use case specific user interfaces in the [=user agent=]. Their content attributes and IDL are mostly the same.
The <usermedia> element uses the following DOM interface:
[Exposed=Window]
interface HTMLUserMediaElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLUserMediaElement includes ActivationBlockersMixin;
The <camera> and <microphone> DOM interfaces are almost the same. The <camera> element uses the following DOM interface:
[Exposed=Window]
interface HTMLCameraElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLCameraElement includes ActivationBlockersMixin;
The <microphone> element uses the following DOM interface:
[Exposed=Window]
interface HTMLMicrophoneElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLMicrophoneElement includes ActivationBlockersMixin;
The <usermedia>, <camera>, and <microphone> elements all use the following internal slot:
The <usermedia>, <camera>, and <microphone> elements belong to the [=flow content=], [=phrasing content=], [=interactive content=], and [=palpable content=] categories. They can be used in contexts where [=phrasing content=] is expected. Their content, if any, are their fallback content. They use the {{ActivationBlockersMixin}} from [[geolocation-element]], to provide protection against programmatic activation.
The <usermedia>, <camera>, and <microphone> elements all support the following content attributes:
The {{HTMLUserMediaElement}}, {{HTMLCameraElement}}, and {{HTMLMicrophoneElement}} all use the same constructor steps. Their {{HTMLUserMediaElement/constructor()}} steps are:
The <usermedia> element's [=insertion steps=] are:
The <usermedia> element's [=removing steps=] are:
The {{HTMLUserMediaElement/stream}} getter steps are:
The {{HTMLUserMediaElement/setConstraints()}} steps for an |element| and a parameter |constraints| steps:
The {{HTMLUserMediaElement/error}} getter steps are:
The <usermedia>, <camera>, and <microphone> permission name are:
| Element type | Value |
|---|---|
| <usermedia> | The [=string/concatenate|concatentation=] of « [=/"camera"=], " ", [=/"microphone"=] ». |
| <camera> | [=/"camera"=] |
| <microphone> | [=/"microphone"=] |
The <usermedia>, <camera>, and <microphone> default constraints are:
| Element type | Value |
|---|---|
| <usermedia> | «[ {{MediaStreamConstraints/video}} → true, {{MediaStreamConstraints/audio}} → true ]» |
| <camera> | «[ {{MediaStreamConstraints/video}} → true, {{MediaStreamConstraints/audio}} → false ]» |
| <microphone> | «[ {{MediaStreamConstraints/video}} → false, {{MediaStreamConstraints/audio}} → true ]» |
The <usermedia> |element|'s [=EventTarget/activation behavior=] is:
The activation initial steps are:
The activation second steps are:
The constraint filter steps for an |element| and {{MediaStreamConstraints}} |constraints| are:
To ease transition from the current <usermedia> element in Chrome, we support a limited form of the {{HTMLUserMediaElementLegacyMixin/type}} attribute, with values for `audio`, `video`, or both. If this attribute is set, it modifies the behaviour of the <usermedia> element to match the behaviour of any of the elements discussed here. This is a hold-over from the original <permission> element design. It is expected that this mixin will not be included in the final standard.
interface mixin HTMLUserMediaElementLegacyMixin {
attribute DOMString type;
boolean isTypeSupported(DOMString type);
};
HTMLUserMediaElement includes HTMLUserMediaElementLegacyMixin;
The {{HTMLUserMediaElementLegacyMixin/type}} IDL attribute reflects the `type` content attribute. Depending on {{HTMLUserMediaElementLegacyMixin/type}}, the <usermedia> element changes behaviour:
The {{HTMLUserMediaElementLegacyMixin/isTypeSupported()}} method can be used to query whether a given type is supported by this element. It will return true if the input string is one of `"audio video"`, `"video audio"`, `"audio"`, or `"video"`, and false in all other cases.