Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setMicrophoneActive and setCameraActive return promises. #312

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 122 additions & 10 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ urlPrefix: https://html.spec.whatwg.org/multipage/dom.html; spec: dom
text: permissions policy; url:#concept-document-permissions-policy
urlPrefix: https://www.w3.org/TR/mediacapture-streams/; spec: mediacapture-main
type: dfn
text: MediaStreamTrack; url:#mediastreamtrack
text: MediaStreamTrack muted state; url:#track-muted
text: set MediaStreamTrack muted state; url:#set-track-muted
</pre>
Expand Down Expand Up @@ -786,9 +787,9 @@ interface MediaSession {

undefined setPositionState(optional MediaPositionState state = {});

undefined setMicrophoneActive(boolean active);
Promise&lt;undefined&gt; setMicrophoneActive(boolean active);

undefined setCameraActive(boolean active);
Promise&lt;undefined&gt; setCameraActive(boolean active);
};
</pre>

Expand Down Expand Up @@ -922,14 +923,125 @@ interface MediaSession {
</p>

<p>
The <dfn method for=MediaSession>setMicrophoneActive(active)</dfn> and
<dfn method for=MediaSession>setCameraActive(active)</dfn> methods indicate to
the user agent whether the microphone and camera are currently considered by
the page to be active (e.g. if the microphone is considered "muted" by the
page since it is no longer sending audio through to a call, then the page can
invoke <code>setMicrophoneActive(false)</code>).
It is RECOMMENDED that the user agent respect the microphone and camera
states indicated by the page in this UI.
The <dfn method for=MediaSession>setMicrophoneActive(active)</dfn> method
indicates to the user agent the microphone capture state desired by the page
(e.g. if the microphone is considered "inactive" by the page since it is no
longer sending audio through a call, the page can invoke
<code>setMicrophoneActive(false)</code>). When invoked, it MUST perform
the following steps:
<ol>
<li>
Let <var>document</var> be [=this=]'s [=relevant global object=]'s
[=associated Document=].
</li>
<li>
Let <var>captureKind</var> be "microphone".
youennf marked this conversation as resolved.
Show resolved Hide resolved
</li>
<li>
Return the result of running the [=update capture state algorithm=] with
<var>document</var>, <var>active</var> and <var>captureKind</var>.
</li>
</ol>
</p>
<p>
Similarly, the <dfn method for=MediaSession>setCameraActive(active)</dfn>
method indicates to the user agent the camera capture state desired by the page.
When invoked, it MUST perform the following steps:
<ol>
<li>
Let <var>document</var> be [=this=]'s [=relevant global object=]'s
[=associated Document=].
</li>
<li>
Let <var>captureKind</var> be "camera".
</li>
<li>
Return the result of running the [=update capture state algorithm=] with
<var>document</var>, <var>active</var> and <var>captureKind</var>.
</li>
</ol>
</p>
<p>
The <dfn>update capture state algorithm</dfn>, when invoked with
<var>document</var>, <var>active</var> and <var>captureKind</var>,
MUST perform the following steps:
<ol>
<li>
If <var>document</var> is not [=fully active=], return [=a promise
rejected with=] <a exception>InvalidStateError</a>.
</li>
<li>
If <var>active</var> is <code>true</code> and <var>document</var>'s
[=Document/visibility state=] is not "visible", the user agent MAY return
[=a promise rejected with=] <a exception>InvalidStateError</a>.
</li>
<li>
Let <var>p</var> be a new promise.
</li>
<li>
<a>In parallel</a>, run the following steps:
<ol>
<li>
Let <var>applyPausePolicy</var> be <code>true</code> if the user agent
implements a policy of <dfn>pausing all input sources</dfn> of type
<var>captureKind</var> in response to UI and <code>false</code>
otherwise.
</li>
<li>
If <var>applyPausePolicy</var> is <code>true</code>, run the following substeps:
<ol>
<li>
Let <var>currentlyActive</var> be <code>false</code> if the user
agent is currently [=pausing all input sources=] of type <var>captureKind</var>
and <code>true</code> otherwise.
</li>
<li>
If <var>active</var> is <var>currentlyActive</var>, resolve
<var>p</var> with <code>undefined</code> and abort these steps.
</li>
<li>
If <var>active</var> is <code>true</code>, the user agent MAY wait to
proceed, for instance to prompt the user.
</li>
<li>
If the user agent denies the request to update the capture state,
reject <var>p</var> with a <a exception>NotAllowedError</a> and
abort these steps.
youennf marked this conversation as resolved.
Show resolved Hide resolved
</li>
</ol>
</li>
<li>
Update the user agent capture state UI according to <var>captureKind</var>
and <var>active</var>.
</li>
<li>Resolve <var>p</var> with <code>undefined</code>.</li>
<li>
If <var>applyPausePolicy</var> is <code>true</code>, run the following substeps:
<ol>
<li>
Let <var>newMutedState</var> be <code>true</code> if <var>active</var> is
<code>false</code> and <code>false</code> otherwise.</li>
<li>
For each [=MediaStreamTrack=] whose source is of type <var>captureKind</var>,
<a>queue a task</a> to [=set MediaStreamTrack muted state=] to
<var>newMutedState</var>.
</li>
</ol>
</li>
</ol>
</li>
<li>
Return <var>p</var>.
</li>
</ol>
</p>
<p class=note>
Both the <a>setMicrophoneActive(active)</a> and <a>setCameraActive(active)</a>
methods can reject based on user agent specific heuristics. This might in
particular happen when the web page asks to activate (aka unmute) microphone
or camera. The user agent could decide to require [=transient activation=] in
that case. It might also require user input through a prompt to make the
actual decision.
</p>

<p>
Expand Down
Loading