forked from w3c/ambient-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
285 lines (235 loc) · 10.9 KB
/
index.bs
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
<pre class="metadata">
Title: Ambient Light Sensor
Level: none
Status: ED
ED: https://w3c.github.io/ambient-light/
Shortname: ambient-light
TR: http://www.w3.org/TR/ambient-light/
Previous Version: https://www.w3.org/TR/2017/WD-ambient-light-20170814/
Editor: Anssi Kostiainen 41974, Intel Corporation, http://intel.com/
Former Editor: Tobie Langel 60809, Codespeaks, formerly on behalf of Intel Corporation, http://tobie.me, tobie@codespeaks.com
Former Editor: Doug Turner, Mozilla Corporation, http://mozilla.com/
Group: dap
Abstract:
This specification defines a concrete sensor interface to monitor
the ambient light level or illuminance of the device's environment.
Version History: https://github.com/w3c/ambient-light/commits/gh-pages/index.bs
!Bug Reports: <a href="https://www.github.com/w3c/ambient-light/issues/new">via the w3c/ambient-light repository on GitHub</a>
Indent: 2
Repository: w3c/ambient-light
Markup Shorthands: markdown on
Inline Github Issues: off
!Issue Tracking: <a href="https://github.com/w3c/ambient-light/milestones/Level%202">Level 2 Issues</a>
!Test Suite: <a href="https://github.com/w3c/web-platform-tests/tree/master/ambient-light">web-platform-tests on GitHub</a>
Boilerplate: omit issues-index, omit conformance
Default Biblio Status: current
</pre>
<pre class="anchors">
urlPrefix: https://w3c.github.io/sensors; spec: GENERIC-SENSOR
type: dfn
text: high-level
text: default sensor
text: implementation specific; url: implementation-specific
text: reporting mode; url: reporting-modes
text: auto
text: construct a sensor object; url: construct-sensor-object
text: limit maximum sampling frequency; url: limit-max-frequency
text: reduce accuracy; url: reduce-accuracy
text: mitigation strategies; url: mitigation-strategies
text: sampling frequency
text: sensor type
text: sensor readings
</pre>
<pre class=biblio>
{
"MEDIAQUERIES-5": {
"authors": [
"Dean Jackson",
"Florian Rivoal",
"Tab Atkins"
],
"href": "https://drafts.csswg.org/mediaqueries-5/",
"title": "Media Queries Level 5",
"status": "ED",
"publisher": "W3C",
"deliveredBy": [
"https://www.w3.org/Style/CSS/members"
]
}
}
</pre>
Introduction {#intro}
============
The Ambient Light Sensor extends the Generic Sensor API [[GENERIC-SENSOR]]
to provide information about ambient light levels,
as detected by the device's main light detector, in terms of lux units.
Scope {#scope}
-----
This document specifies an API designed for [[#usecases-requirements|use cases]]
which require fine grained illuminance data, with low latency, and possibly
sampled at high frequencies.
Common use cases relying on a small set of illuminance values, such as styling
webpages according to ambient light levels are best served by the the
`light-level` CSS media feature [[MEDIAQUERIES-5]] and its accompanying
`matchMedia` API [[CSSOM]] and are out of scope of this API.
Note: it might be worthwhile to provide a <a>high-level</a> Light Level Sensor
which would mirror the `light-level` media feature, but in JavaScript.
This sensor would *not require additional user permission to be activated*
in user agents that exposed the `light-level` media feature.
Examples {#examples}
========
<div class="example">
In this simple example, ambient light sensor is created with
default configuration. Whenever new [=sensor readings|reading=] is available,
it is printed to the console.
<pre highlight="js">
const sensor = new AmbientLightSensor();
sensor.onreading = () => console.log(sensor.illuminance);
sensor.onerror = event => console.log(event.error.name, event.error.message);
sensor.start();
</pre>
</div>
<div class="example">
In this example, exposure value (EV) at ISO 100 is calculated from
the ambient light [=sensor readings=]. Initially, we check that the user
agent has permissions to access ambient light [=sensor readings=]. Then,
{{AmbientLightSensor/illuminance!!attribute}} value is converted to the
closest exposure value.
<pre highlight="js">
navigator.permissions.query({ name: 'ambient-light-sensor' }).then(result => {
if (result.state === 'denied') {
console.log('Permission to use ambient light sensor is denied.');
return;
}
const als = new AmbientLightSensor({frequency: 20});
als.addEventListener('activate', () => console.log('Ready to measure EV.'));
als.addEventListener('error', event => console.log(\`Error: ${event.error.name}\`));
als.addEventListener('reading', () => {
// Defaut ISO value.
const ISO = 100;
// Incident-light calibration constant.
const C = 250;
let EV = Math.round(Math.log2((als.illuminance * ISO) / C));
console.log(\`Exposure Value (EV) is: ${EV}\`);
});
als.start();
});
</pre>
</div>
<div class="example">
This example demonstrates how ambient light [=sensor readings=] can be mapped
to recommended workplace light levels.
<pre highlight="js">
const als = new AmbientLightSensor();
als.onreading = () => {
let str = luxToWorkplaceLevel(als.illuminance);
if (str) {
console.log(\`Light level is suitable for: ${str}.\`);
}
};
als.start();
function luxToWorkplaceLevel(lux) {
if (lux > 20 && lux < 100) {
return 'public areas, short visits';
} else if (lux > 100 && lux < 150) {
return 'occasionally performed visual tasks';
} else if (lux > 150 && lux < 250) {
return 'easy office work, classes, homes, theaters';
} else if (lux > 250 && lux < 500) {
return 'normal office work, groceries, laboratories';
} else if (lux > 500 && lux < 1000) {
return 'mechanical workshops, drawing, supermarkets';
} else if (lux > 1000 && lux < 5000) {
return 'detailed drawing work, visual tasks of low contrast';
}
return;
}
</pre>
</div>
Security and Privacy Considerations {#security-and-privacy}
===================================
Ambient Light Sensor provides information about lighting conditions near
the device environment. Potential privacy risks include:
- Profiling. Ambient Light Sensor can leak information about user's use
patterns and surrounding. This information can be used to enhance user
profiling and behavioral analysis.
- Cross-device linking. Two devices can access web sites that include the
same third-party script that correlates lighting levels over time.
- Cross-device communication. A simple broadcast communication method can
use device screen or camera LED flashes to broadcast messages read
out with an Ambient Light Sensor in a close by device.
- Cross-origin leaks. Light emitted from the screen can be reflected back to
the sensor from nearby reflective surfaces. Malicious sites can embed
resources from different origins and scale the content to display
particular pixels to allow distinguish the contents, pixel by pixel.
- Hijacking browsing history. Styling visited links to allow distinguish the
light levels associated with visited and unvisited links i.e. visited
links styled as a block of black screen; white for unvisited.
To mitigate these Ambient Light Sensor specific threats, user agents should
use one or both of the following mitigation strategies:
- <a>limit maximum sampling frequency</a>
- <a>reduce accuracy</a> of sensor readings
The generic <a>mitigation strategies</a> are described in the Generic Sensor
API [[!GENERIC-SENSOR]].
Model {#model}
=====
The <dfn>Ambient Light Sensor</dfn> <a>sensor type</a>'s associated {{Sensor}}
subclass is the {{AmbientLightSensor}} class.
The <a>Ambient Light Sensor</a> has a <a>default sensor</a>,
which is the device's main light detector.
The <a>Ambient Light Sensor</a> has an associated {{PermissionName}}
which is <a for="PermissionName" enum-value>"ambient-light-sensor"</a>.
The <dfn>current light level</dfn> or <dfn>illuminance</dfn>
is a value that represents the ambient light level
around the hosting device. Its unit is the lux (lx) [[SI]].
Note: The precise lux value reported by
different devices in the same light can be different,
due to differences in detection method, sensor construction, etc.
API {#api}
===
The AmbientLightSensor Interface {#ambient-light-sensor-interface}
--------------------------------
<pre class="idl">
[Constructor(optional SensorOptions sensorOptions), SecureContext, Exposed=Window]
interface AmbientLightSensor : Sensor {
readonly attribute double? illuminance;
};
</pre>
To <dfn>Construct an AmbientLightSensor Object</dfn> the user agent must invoke the
<a>construct a Sensor object</a> abstract operation.
### The illuminance attribute ### {#ambient-light-sensor-reading-attribute}
The <a attribute for="AmbientLightSensor">illuminance</a> attribute of the {{AmbientLightSensor}}
interface represents the [=current light level=] and returns the result of invoking
[=get value from latest reading=] with `this` and "illuminance" as arguments.
Use Cases and Requirements {#usecases-requirements}
=========
- A Web application provides input for a smart home system to control lighting.
- A Web aplication checks whether light level at work space is sufficient.
- A Web application calculates settings for a camera with manual controls (apperture, shutter speed, ISO).
- A Web application monitors light level changes produced by hovering hand user gesture and
interprets them to control a game character.
While some of the use cases may benefit from obtaining precise ambient light measurements, the use
cases that convert ambient light level fluctuations to user input events, would benefit from
higher [=sampling frequency|sampling frequencies=].
Acknowledgements {#acknowledgements}
================
Doug Turner for the initial prototype and
Marcos Caceres for the test suite.
Paul Bakaus for the LightLevelSensor idea.
Mikhail Pozdnyakov and Alexander Shalamov for the use cases and requirements.
Lukasz Olejnik for the privacy risk assessment.
Conformance {#conformance}
===========
Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. [[!RFC2119]]
A <dfn>conformant user agent</dfn> must implement all the requirements
listed in this specification that are applicable to user agents.
The IDL fragments in this specification must be interpreted as required for
conforming IDL fragments, as described in the Web IDL specification. [[!WEBIDL]]