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

Add gamepad light indicator extension #143

Open
wants to merge 14 commits into
base: gh-pages
Choose a base branch
from
116 changes: 116 additions & 0 deletions extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,116 @@ <h2><dfn>GamepadPose</dfn> Interface</h2>
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightIndicatorType</dfn> Enum</h2>
<p>
This enum defines the type of light indicators supported by gamepads.
</p>

<pre class="idl">
enum GamepadLightIndicatorType {
"on-off",
"rgb"
};
</pre>

<dl data-dfn-for="GamepadLightIndicatorType">
<dt>"<dfn>on-off</dfn>"</dt>
<dd>
Light indicator that supports a single color.
</dd>

<dt>"<dfn>rgb</dfn>"</dt>
<dd>
Light indicator that supports multiple colors.
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightColor</dfn> dictionary</h2>
<p>
This represents the color of a light indicator.
</p>

<pre class="idl">
dictionary GamepadLightColor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should investigate what existing color objects we could use from the platform here.

octet red = 0;
octet green = 0;
octet blue = 0;
};
</pre>

<dl data-dfn-for="GamepadLightColor">
<dt><dfn>red</dt> member</dfn>
<dd>
Red component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>

<dt><dfn>green</dt> member</dfn>
<dd>
Blue component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>

<dt><dfn>blue</dt> member</dfn>
<dd>
Green component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightIndicator</dfn></h2>
<p>
This interface defines a light indicator.
</p>

<pre class="idl">
[Exposed=Window, SecureContext]
interface GamepadLightIndicator {
readonly attribute GamepadLightIndicatorType type;

Promise&lt;undefined&gt; setColor(GamepadLightColor color);
};
</pre>

<dl data-dfn-for="GamepadLightIndicator">
<dt><dfn>type</dt></dfn>
<dd>
Type of light indicator supported by the gamepad.
</dd>

<dt><dfn>setColor()</dt> method</dfn>
<dd>
<p>
Sets the color of a light indicator, or sets the light indicator to ON
or OFF.
</p>

<p>
For <code>on-off</code> light indicators, one or more non zero values
denotes the light indicator is on, whereas a zero value for all
components indicates the light indicator is off.
</p>

<p>
For RGB light indicators, one or more non zero values specify the
color of the light indicator, whereas all zero values indicate the
light indicator is OFF.
</p>

<p>
The returned Promise will resolve <code>true</code> when setting the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this can be guaranteed to succeed. @nondebug, do you have an opinion about this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't get a signal that the color was changed successfully so we shouldn't claim that in the spec. I think we should reword this so we resolve when the LED color change command is sent and reject if the command couldn't be sent.

Copy link
Member

@marcoscaceres marcoscaceres Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so yeah... it shouldn't resolve with true either.

We probably need to rewrite this whole section. I'd suggest having a look at:
https://w3c.github.io/web-share/#share-method

Basically, we need to do a few checks that can cause the promise to reject... the controller has been disconnected/no longer available, etc. There might be a SecurityError if the permission has been changed before .setColor() is called. Also, what should happen if:

while (true) {
   x.setColor(randomRGB());
}

Rate limit? Drop requests on the floor?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this and couldn't come up with any compelling reasons to keep the Promise. It's unlikely that we'll receive any error indication from the device and there isn't any way we can lose permission for a Gamepad. Let's remove the promise and treat setColor as fire-and-forget.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The returned Promise will resolve <code>true</code> when setting the
The returned Promise will resolve `undefined` when setting the

color has succeeded, and will reject the device API error code on
failure.
Comment on lines +441 to +442
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to reject with a an actual DOM Exception of some kind. I think this is overly broad/underspecified tho...

</p>
</dd>
</dl>
</section>

<section data-dfn-for="GamepadTouch">
<h2><dfn>GamepadTouch</dfn> Interface</h2>
Expand Down Expand Up @@ -397,6 +507,7 @@ <h2>Partial <dfn>Gamepad</dfn> Interface</h2>
readonly attribute GamepadHand hand;
readonly attribute FrozenArray&lt;GamepadHapticActuator> hapticActuators;
readonly attribute GamepadPose? pose;
readonly attribute FrozenArray&lt;GamepadLightIndicator> lightIndicators;
readonly attribute FrozenArray&lt;GamepadTouch>? touchEvents;
};
</pre>
Expand All @@ -423,6 +534,11 @@ <h2>Partial <dfn>Gamepad</dfn> Interface</h2>
<code>null</code>.
</dd>

<dt><dfn>lightIndicators</dfn></dt>
<dd>
A list of all light indicators in the gamepad. The array is empty if
the gamepad does not have, or does not support, a light indicator.
</dd>
<dt><dfn>touchEvents</dfn></dt>
<dd>
A list of touch events generated from all touch surfaces. <code>null</code>
Expand Down