1. Introduction
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.
The light-level
media feature [MEDIAQUERIES-4] provides
less granular information about the ambient light level.
Note: it might be worthwhile to provide a high-level 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.
2. Examples
let sensor = new AmbientLightSensor(); sensor.start(); sensor.onchange = function(event) { console.log(sensor.illuminance); }; sensor.onerror = function(event) { console.log(event.error.name, event.error.message); };
3. Security and Privacy Considerations
There are no specific security and privacy considerations beyond those described in the Generic Sensor API [GENERIC-SENSOR].
4. Model
The Ambient Light Sensor’s associated Sensor subclass is the AmbientLightSensor
class.
The Ambient Light Sensor has a default sensor, which is the device’s main light detector.
The Ambient Light Sensor’s reporting mode is implementation specific.
The Ambient Light Sensor has an associated PermissionName
which is "ambient-light-sensor".
The current light level or illuminance is a value that represents the ambient light levels 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.
5. API
5.1. The AmbientLightSensor Interface
[Constructor(optional SensorOptions sensorOptions)] interface AmbientLightSensor : Sensor { readonly attribute unrestricted double? illuminance; };
To Construct an AmbientLightSensor Object the user agent must invoke the construct a Sensor object abstract operation.
5.1.1. The illuminance attribute
The illuminance attribute of the AmbientLightSensor
interface represents the current light level.
6. Use Cases and Requirements
-
A Web application gradually updates document style based on light level changes.
-
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, based on occupational health regulations.
-
A Web application monitors light level changes produced by hovering hand user gesture and interprets them to control a game character.
-
A Web application calculates settings for a camera with manual controls (apperture, shutter speed, ISO).
The mentioned use cases require plain light level data, not a pre-defined set of values.
7. 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.
8. 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 conformant user agent 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]