@@ -138,32 +138,27 @@ Examples {#examples}
138
138
========
139
139
140
140
<div class="example">
141
- In this simple example, ambient light sensor is created with
141
+ In this simple example, an {{AmbientLightSensor}} instance is created with
142
142
default configuration. Whenever a new [=sensor readings|reading=] is available,
143
143
it is printed to the console.
144
144
145
145
<pre highlight="js">
146
- const sensor = new AmbientLightSensor();
147
- sensor.onreading = () => console.log(sensor.illuminance);
148
- sensor.onerror = event => console.log(event.error.name, event.error.message);
149
- sensor.start();
146
+ navigator.mediaDevices.getUserMedia({video: true}).then(() => {
147
+ const sensor = new AmbientLightSensor();
148
+ sensor.onreading = () => console.log(sensor.illuminance);
149
+ sensor.onerror = event => console.log(event.error.name, event.error.message);
150
+ sensor.start();
151
+ });
150
152
</pre>
151
153
</div>
152
154
153
155
<div class="example">
154
156
In this example, the exposure value (EV) at ISO 100 is calculated from
155
- the ambient light [=sensor readings=] . Initially, we check that the user
156
- agent has permissions to access ambient light [=sensor readings=] . Then,
157
- the {{AmbientLightSensor/illuminance!!attribute}} value is converted to the
158
- closest exposure value.
157
+ the ambient light [=sensor readings=] . The {{AmbientLightSensor/illuminance}}
158
+ value is converted to the closest exposure value.
159
159
160
160
<pre highlight="js">
161
- navigator.permissions.query({ name: 'ambient-light-sensor' }).then(result => {
162
- if (result.state === 'denied' ) {
163
- console.log('Permission to use ambient light sensor is denied.' );
164
- return;
165
- }
166
-
161
+ navigator.mediaDevices.getUserMedia({ video: true }).then(() => {
167
162
const als = new AmbientLightSensor({frequency: 20});
168
163
als.addEventListener('activate' , () => console.log('Ready to measure EV.' ));
169
164
als.addEventListener('error' , event => console.log(\`Error: ${event.error.name}\`));
@@ -182,42 +177,6 @@ Examples {#examples}
182
177
</pre>
183
178
</div>
184
179
185
- <div class="example">
186
- This example demonstrates how ambient light [=sensor readings=] can be mapped
187
- to recommended workplace light levels.
188
-
189
- <pre highlight="js">
190
- const als = new AmbientLightSensor();
191
-
192
- als.onreading = () => {
193
- let str = luxToWorkplaceLevel(als.illuminance);
194
- if (str) {
195
- console.log(\`Light level is suitable for: ${str}.\`);
196
- }
197
- };
198
-
199
- als.start();
200
-
201
- function luxToWorkplaceLevel(lux) {
202
- if (lux > 20 && lux < 100) {
203
- return 'public areas, short visits' ;
204
- } else if (lux > 100 && lux < 150) {
205
- return 'occasionally performed visual tasks' ;
206
- } else if (lux > 150 && lux < 250) {
207
- return 'easy office work, classes, homes, theaters' ;
208
- } else if (lux > 250 && lux < 500) {
209
- return 'normal office work, groceries, laboratories' ;
210
- } else if (lux > 500 && lux < 1000) {
211
- return 'mechanical workshops, drawing, supermarkets' ;
212
- } else if (lux > 1000 && lux < 5000) {
213
- return 'detailed drawing work, visual tasks of low contrast' ;
214
- }
215
-
216
- return;
217
- }
218
- </pre>
219
- </div>
220
-
221
180
Security and Privacy Considerations {#security-and-privacy}
222
181
===================================
223
182
0 commit comments