-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathusermedia-element-delta.html
More file actions
405 lines (370 loc) · 17.2 KB
/
usermedia-element-delta.html
File metadata and controls
405 lines (370 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<!doctype html>
<html lang="en-us">
<head>
<title>Proposed <usermedia>, <camera>, and <microphone>
media capture HTML elements,
as a delta specification to Media Capture and Streams Extensions</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script class='remove'>
"use strict";
// See https://github.com/w3c/respec/wiki/ for how to configure ReSpec
var respecConfig = {
xref: ["geometry-1", "html", "infra", "permissions", "dom", "hr-time", "image-capture", "mediacapture-streams", "screen-capture", "webaudio", "webcodecs", "webidl", "ECMAScript", "geolocation-element"],
editors: [{name: "Daniel Vogelheim", company: "Google LLC"}],
specStatus: "UD",
shortName: "proposed-usermedia-html-elements",
edDraftURI: "https://wicg.github.io/PEPC/usermedia-element-delta.html",
latestVersion: null,
noRecTrack: true,
localBiblio: {
"mediacapture-extensions": {
title: "Media Capture and Streams Extensions",
href: "https://w3c.github.io/mediacapture-extensions/",
},
},
};
</script>
</head>
<body>
<section id="abstract">
<p>This document proposes a set of HTML elements, <<a>usermedia</a>>,
<<a>camera</a>>, and <<a>microphone</a>>,
that mean to provide user-friendly and secure access
to a {{MediaStream}}, handling the required premissions in the process.</p>
<p>This is a delta specification, meant to eventually be included in
[[mediacapture-streams]] or [[mediacapture-extensions]].</p>
</section>
<section id="sotd">
<p>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. </p>
</section>
<section>
<h2>The <<a>usermedia</a>>, <<a>camera</a>>, and
<<a>microphone</a>> media capture HTML elements</h2>
<p>The <<dfn element>usermedia</dfn>>,
<<dfn element>camera</dfn>>, and <<dfn element>microphone</dfn>>
HTML elements are [[HTML]] elements that can mediate access to a
{{MediaStream}}, including handling the required [=permission/prompts=]
for [=powerful features=].</p>
<p>These three elements cover three different use cases and allow for use
case specific user interfaces in the [=user agent=]. Their
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-attributes">content attributes</a>
and IDL are mostly the same.</p>
<p>The <<a>usermedia</a>> element uses the following
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-dom">DOM interface</a>:</p>
<pre class=idl>
[Exposed=Window]
interface HTMLUserMediaElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLUserMediaElement includes ActivationBlockersMixin;
</pre>
<p>The <<a>camera</a>> and <<a>microphone</a>>
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-dom">DOM interfaces</a> are almost the same.
The <<a>camera</a>> element uses the following
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-dom">DOM interface</a>:</p>
<pre class=idl>
[Exposed=Window]
interface HTMLCameraElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLCameraElement includes ActivationBlockersMixin;
</pre>
<p>The <<a>microphone</a>> element uses the following
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-dom">DOM interface</a>:</p>
<pre class=idl>
[Exposed=Window]
interface HTMLMicrophoneElement : HTMLElement {
[HTMLConstructor] constructor();
readonly attribute MediaStream? stream;
undefined setConstraints(MediaStreamConstraints constraints);
readonly attribute DOMException? error;
};
HTMLMicrophoneElement includes ActivationBlockersMixin;
</pre>
<p>The <<a element>usermedia</a>>,
<<a element>camera</a>>, and <<a element>microphone</a>>
elements all use the following internal slot:</p>
<ul>
<li><dfn data-dfn-for=HTMLUserMediaElement>[[\stream]]</dfn>
— Holds null or a {{MediaStream}}.</li>
<li><dfn data-dfn-for=HTMLUserMediaElement>[[\constraints]]</dfn>
— Holds a {{MediaStreamConstraints}}.</li>
<li><dfn data-dfn-for=HTMLUserMediaElement>[[\error]]</dfn>
— Holds an {{DOMException}} instance or null.</li>
</ul>
<p>The <<a element>usermedia</a>>,
<<a element>camera</a>>, and <<a element>microphone</a>>
elements belong to the [=flow content=],
[=phrasing content=], [=interactive content=], and [=palpable content=]
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-categories">categories</a>.
They can be used in contexts where [=phrasing content=] is expected.
Their content, if any, are their
<a href="https://html.spec.whatwg.org/multipage/dom.html#fallback-content">fallback content</a>.
They use the {{ActivationBlockersMixin}} from [[geolocation-element]], to
provide protection against programmatic activation.</p>
<p>The <<a element>usermedia</a>>,
<<a element>camera</a>>, and <<a element>microphone</a>>
elements all support the following
<a href="https://html.spec.whatwg.org/multipage/dom.html#concept-element-attributes">content attributes</a>:</p>
<dl>
<dt><a href="https://html.spec.whatwg.org/multipage/dom.html#global-attributes">global attributes</a></dt>
<dd>— all global content attributes.</dd>
<dt><a href="https://wicg.github.io/PEPC/geolocation-element.html#dom-activationblockersmixin-isvalid">isValid</a></dt>
<dt><a href="https://wicg.github.io/PEPC/geolocation-element.html#dom-activationblockersmixin-invalidreason">invalidReason</a></dt>
<dt><a href="https://wicg.github.io/PEPC/geolocation-element.html#dom-activationblockersmixin-onvalidationstatuschange">onvalidationstatuschange</a></dt>
<dd>— content attributes from {{ActivationBlockersMixin}}</dd>
</dl>
<section>
<h3>Algorithms</h3>
<p>The {{HTMLUserMediaElement}}, {{HTMLCameraElement}}, and
{{HTMLMicrophoneElement}} all use the same constructor steps. Their
{{HTMLUserMediaElement/constructor()}} steps are:</p>
<ol class=algorithm>
<li>Run {{ActivationBlockersMixin}}'s
[=ActivationBlockersMixin/initialization steps=].</li>
<li>Initialize {{HTMLUserMediaElement/[[stream]]}} to null.</li>
<li>Initialize {{HTMLUserMediaElement/[[error]]}} to null.</li>
<li>Initialize {{HTMLUserMediaElement/[[constraints]]}} to [=this=]'s
[=HTMLUserMediaElement/default constraints=].</li>
</ol>
<p>The <<a>usermedia</a>> element's [=insertion steps=] are:</p>
<ol class=algorithm>
<li>Run {{ActivationBlockersMixin}}'s
[=ActivationBlockersMixin/insertion steps=].</li>
</ol>
<p>The <<a>usermedia</a>> element's [=removing steps=] are:</p>
<ol class=algorithm>
<li>Run {{ActivationBlockersMixin}}'s
[=ActivationBlockersMixin/removing steps=].</li>
</ol>
<p>The {{HTMLUserMediaElement/stream}} <a>getter</a> steps are:</p>
<ol class=algorithm>
<li>Return {{HTMLUserMediaElement/[[stream]]}}.</li>
</ol>
<p>The {{HTMLUserMediaElement/setConstraints()}} steps for an |element| and
a parameter |constraints| steps:</p>
<ol class=algorithm>
<li>Set {{HTMLUserMediaElement/[[constraints]]}} to the result of
[=HTMLUserMediaElement/constraint filter=] for |element|
and |constraints|.</li>
</ol>
<p>The {{HTMLUserMediaElement/error}} <a>getter</a> steps are:</p>
<ol class=algorithm>
<li>Return {{HTMLUserMediaElement/[[error]]}}.
</ol>
<p>The <<a>usermedia</a>>, <<a>camera</a>>, and
<<a>microphone</a>>
<dfn for=HTMLUserMediaElement>permission name</dfn> are:</p>
<table class="simple">
<thead>
<tr>
<th>Element type</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<th><<a>usermedia</a>></th>
<td>The [=string/concatenate|concatentation=] of
« [=/"camera"=], " ", [=/"microphone"=] ».</td>
</tr>
<tr>
<th><<a>camera</a>></th>
<td>[=/"camera"=]</td>
</tr>
<tr>
<th><<a>microphone</a>></th>
<td>[=/"microphone"=]</td>
</tr>
</tbody>
</table>
<p>The <<a>usermedia</a>>, <<a>camera</a>>, and
<<a>microphone</a>>
<dfn for=HTMLUserMediaElement>default constraints</dfn> are:</p>
<table class="simple">
<thead>
<tr>
<th>Element type</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<th><<a>usermedia</a>></th>
<td>«[
{{MediaStreamConstraints/video}} → true,
{{MediaStreamConstraints/audio}} → true
]»</td>
</tr>
<tr>
<th><<a>camera</a>></th>
<td>«[
{{MediaStreamConstraints/video}} → true,
{{MediaStreamConstraints/audio}} → false
]»</td>
</tr>
<tr>
<th><<a>microphone</a>></th>
<td>«[
{{MediaStreamConstraints/video}} → false,
{{MediaStreamConstraints/audio}} → true
]»</td>
</tr>
</tbody>
</table>
<p>The <<a>usermedia</a>> |element|'s
[=EventTarget/activation behavior=] is:</p>
<ol class=algorithm>
<li>If |element|.{{ActivationBlockersMixin/isValid}} is false,
then return.</li>
<li>If {{HTMLUserMediaElement/[[stream]]}} is null, run the
[=HTMLUserMediaElement/activation initial=] steps.</li>
<li>Otherwise, if
{{HTMLUserMediaElement/[[stream]]}}.{{MediaStream/active}}
is false, run the [=HTMLUserMediaElement/activation inactive=]
steps.</li>
<li>Otherwise, run the [=HTMLUserMediaElement/activation active=]
steps.</li>
</ol>
<p>The <dfn for=HTMLUserMediaElement>activation initial</dfn> steps
are:</p>
<ol class=algorithm>
<li>[=Assert=]: |element|.{{ActivationBlockersMixin/isValid}}.</li>
<li>[=Assert=]: {{HTMLUserMediaElement/[[stream]]}} is null.</li>
<li>Let |permissionName| be |element|'s [=permission name=].</li>
<li>Let |descriptor| be a new {{PermissionDescriptor}} with value
«[ {{PermissionDescriptor/name}} → |permissionName|
]».</li>
<li>Let |permissionState| be the result of
[=request permission to use=] the [=powerful features=]
described by |descriptor| with allowMultiple set to false.</li>
<li>If |permissionState| is not {{PermissionState/"granted"}}:</li>
<ol>
<li>Set {{HTMLUserMediaElement/[[stream]]}} to null.</li>
<li>Set {{HTMLUserMediaElement/[[error]]}} to null.</li>
<li>Return.</li>
</ol>
<li>Let |contraints| be {{HTMLUserMediaElement/[[constraints]]}}.</li>
<li>Let |mediaPromise| be the result of calling
{{MediaDevices/getUserMedia()}} with |constraints| as its first
argument.</li>
<li>[=promise/React=] to |mediaPromise|:
<ol>
<li>If |mediaPromise| was fulfilled with value |v|:</li>
<ol>
<li>[=Assert=]: |v| is a {{MediaStream}}.</li>
<li>Set {{HTMLUserMediaElement/[[stream]]}} to |v|.</li>
<li>Set {{HTMLUserMediaElement/[[error]]}} to null.</li>
</ol>
<li>else:
<ol>
<li>[=Assert=]: |mediaPromise| was rejected with reason |r|.</li>
<li>[=Assert=]: |r| is a |DOMException|.</li>
<li>Set {{HTMLUserMediaElement/[[stream]]}} to null.</li>
<li>Set {{HTMLUserMediaElement/[[error]]}} to |r|.</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>The <dfn for=HTMLUserMediaElement>activation inactive</dfn> steps
are:</p>
<ol class=algorithm>
<li>[=Assert=]: |element|.{{ActivationBlockersMixin/isValid}}.</li>
<li>[=Assert=]: {{HTMLUserMediaElement/[[stream]]}} is a
{{MediaStream}}.</li>
<li>[=Assert=]: {{HTMLUserMediaElement/[[stream]]}}.{{MediaStream/active}}
is false.</li>
<li>[=list/iterate|For each=] {{MediaStreamTrack}} |track| of
{{HTMLUserMediaElement/[[stream]]}}'s [=track set=]:
<ol>
<li>Set |track|.{{MediaStreamTrack/enabled}} to true.
</ol>
</li>
</ol>
<p>The <dfn for=HTMLUserMediaElement>activation active</dfn> steps
are:</p>
<ol class=algorithm>
<li>[=Assert=]: |element|.{{ActivationBlockersMixin/isValid}}.</li>
<li>[=Assert=]: {{HTMLUserMediaElement/[[stream]]}} is a
{{MediaStream}}.</li>
<li>[=Assert=]: {{HTMLUserMediaElement/[[stream]]}}.{{MediaStream/active}}
is true.</li>
<li>Let |muted| be false.</li>
<li>[=list/iterate|For each=] {{MediaStreamTrack}} |track| of
{{HTMLUserMediaElement/[[stream]]}}'s [=track set=]:
<ol>
<li>If |track|.{{MediaStreamTrack/muted}}, set |muted| to true.
</ol>
</li>
<li>[=list/iterate|For each=] {{MediaStreamTrack}} |track| of
{{HTMLUserMediaElement/[[stream]]}}'s [=track set=]:
<ol>
<li>Set |track|.{{MediaStreamTrack/muted}} to ¬|muted|.
</ol>
</li>
</ol>
<p>The <dfn for=HTMLUserMediaElement>constraint filter</dfn> steps
for an |element| and {{MediaStreamConstraints}} |constraints| are:</p>
<ol class=algorithm>
<li>Let |result| be a new [=dictionary=].</li>
<li>Let |defaults| be |element|'s [=default constraints=].</li>
<li>For |key| of « {{MediaStreamConstraints/audio}}, {{MediaStreamConstraints/video}} »:
<ol>
<li>If |defaults|[|key|] is true, then set |result|[|key|] to |constraints|[|key|].</li>
<li>Otherwise, set |result|[|key|] to false.</li>
</ol>
</li>
<li>TODO: |results| should have additional filtering to support a
reasonable, easy-to-use subset of all the constraints allowed for
the getUserMedia call.</li>
<li>Return |result|.
</ol>
</section>
<section>
<h3><usermedia> legacy support.</h3>
<p>To ease transition from the current <<a>usermedia</a>> 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 <<a>usermedia</a>> element to
match the behaviour of any of the elements discussed here. This is a
hold-over from the original <<a href="https://wicg.github.io/PEPC/permission-element.html">permission</a>> element design. It is expected
that this mixin will not be included in the final standard.</p>
<pre class=idl>
interface mixin HTMLUserMediaElementLegacyMixin {
attribute DOMString type;
boolean isTypeSupported(DOMString type);
};
HTMLUserMediaElement includes HTMLUserMediaElementLegacyMixin;
</pre>
<p>The {{HTMLUserMediaElementLegacyMixin/type}} IDL attribute reflects
the `type` content attribute.
Depending on {{HTMLUserMediaElementLegacyMixin/type}}, the
<<a>usermedia</a>> element changes behaviour:</p>
<dl>
<dt>`"audio video"`</dt>
<dt>`"video audio"`</dt>
<dd>— behaves like a regular <<a>usermedia</a>> element.</dd>
<dt>`"audio"`</dt>
<dd>— behaves like a <<a>microphone</a>> element.</dd>
<dt>`"video"`</dt>
<dd>— behaves like a <<a>camera</a>> element.</dd>
<dt>all other values</dt>
<dd>— behaves like an {{HTMLUnknownElement}}.</dd>
</dl>
<p>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.
</p>
</section>
</section>
</body>
</html>