Skip to content

Commit

Permalink
editorial: Define a "pre-activation checks algorithm".
Browse files Browse the repository at this point in the history
Related to w3c/ambient-light#79, where we want to replace the
"ambient-light" powerful feature with an integration with the Media Capture
and Streams spec by only providing illuminance readouts if the same page has
an active local video source.

Part of it requires checking the above condition when `Sensor.start()` is
called; the new algorithm introduced here does it in the "activate a sensor
object" abstract operation.

Additionally, `Sensor.start()` is now invoking "activate a sensor object" as
a queued task, as we want it to run in the main event loop rather than in
parallel since at least the Ambient Light Sensor implementation of the
"pre-activation checks algorithm" needs access to the relevant global object
and its internal slots.
  • Loading branch information
rakuco committed Dec 13, 2022
1 parent f3f78c1 commit 52331e0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ A [=sensor type=] may have an associated <dfn export>reading quantization
algorithm</dfn>, which takes a [=sensor reading=] and returns a less accurate
[=sensor reading=].

A [=sensor type=] may have an associated <dfn export>pre-activation checks
algorithm</dfn>, which takes a {{Sensor}} instance and returns a boolean, to
perform extra checks before activating the given {{Sensor}} instance.

<h3 id="model-sensor">Sensor</h3>

The current [=browsing context=]'s [=platform sensor=] must have:
Expand Down Expand Up @@ -1169,7 +1173,7 @@ It represents a [=reading timestamp=].
but it is a tradeoff some User Agent might choose to make. -->
1. Queue a task to run [=notify error=] with [=this=] and |e| as arguments.
1. Return.
1. Invoke [=activate a sensor object=] with [=this=] as argument.
1. Queue a task to run [=activate a sensor object=] with [=this=] as argument.
</div>


Expand Down Expand Up @@ -1330,6 +1334,14 @@ to {{SensorErrorEventInit}}.
:: None

1. Let |sensor| be the [=platform sensor=] associated with |sensor_instance|.
1. Let |type| be |sensor|'s associated [=sensor type=].
1. If |type|'s [=pre-activation checks algorithm=] is defined:
1. Let |result| be the result of invoking |type|'s [=pre-activation checks algorithm=] with |sensor_instance|.
1. If |result| is false:
1. Let |e| be the result of [=created|creating=] a "{{NotReadableError}}" {{DOMException}}.
<!-- Or a NotAllowedError exception, see the comment in Sensor.start(). -->
1. Queue a task to run [=notify error=] with |sensor_instance| and |e|.
1. Return.
1. [=set/Append=] |sensor_instance| to |sensor|'s set of [=activated sensor objects=].
1. Invoke [=set sensor settings=] with |sensor| as argument.
1. Queue a task to run [=notify activated state=] with |sensor_instance|
Expand Down Expand Up @@ -2071,6 +2083,8 @@ for each [=sensor types=]:
be updated.
- A [=reading quantization algorithm=], which may return a sensor reading
with reduced accuracy.
- A [=pre-activation checks algorithm=] with extra steps that are run
before a {{Sensor}} instance is activated.

<h3 id="extend-automation">Automation</h3>

Expand Down

0 comments on commit 52331e0

Please sign in to comment.