Skip to content

Commit beaa34e

Browse files
author
Raphael Kubo da Costa
committed
Update examples to show Media Capture integration.
The last example was removed because it showed a use case that was deleted in the previous commit, as it no longer seems very relevant with the new media capture requirements.
1 parent cb9e5aa commit beaa34e

File tree

1 file changed

+10
-51
lines changed

1 file changed

+10
-51
lines changed

index.bs

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,27 @@ Examples {#examples}
138138
========
139139

140140
<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
142142
default configuration. Whenever a new [=sensor readings|reading=] is available,
143143
it is printed to the console.
144144

145145
<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+
});
150152
</pre>
151153
</div>
152154

153155
<div class="example">
154156
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.
159159

160160
<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(() => {
167162
const als = new AmbientLightSensor({frequency: 20});
168163
als.addEventListener('activate', () => console.log('Ready to measure EV.'));
169164
als.addEventListener('error', event => console.log(\`Error: ${event.error.name}\`));
@@ -182,42 +177,6 @@ Examples {#examples}
182177
</pre>
183178
</div>
184179

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-
221180
Security and Privacy Considerations {#security-and-privacy}
222181
===================================
223182

0 commit comments

Comments
 (0)