Skip to content

Commit 4b38bb1

Browse files
author
Raphael Kubo da Costa
committed
editorial: Define a "pre-activation checks algorithm".
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.
1 parent 79f3b9a commit 4b38bb1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

index.bs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,10 @@ A [=sensor type=] may have an associated <dfn export>reading quantization
810810
algorithm</dfn>, which takes a [=sensor reading=] and returns a less accurate
811811
[=sensor reading=].
812812

813+
A [=sensor type=] may have an associated <dfn export>pre-activation checks
814+
algorithm</dfn>, which takes a {{Sensor}} instance and returns a boolean, to
815+
perform extra checks before activating the given {{Sensor}} instance.
816+
813817
<h3 id="model-sensor">Sensor</h3>
814818

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

11751179

@@ -1330,6 +1334,14 @@ to {{SensorErrorEventInit}}.
13301334
:: None
13311335

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

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

0 commit comments

Comments
 (0)