diff --git a/index.bs b/index.bs index bc33775..0eb7c98 100644 --- a/index.bs +++ b/index.bs @@ -827,28 +827,36 @@ A {{Sensor}} object has an associated [=platform sensor=]. The [=task source=] for the [=tasks=] mentioned in this specification is the sensor task source.
- In the following example, we construct accelerometer sensor and add - [=event listener|event listeners=] to get [=event|events=] for [=platform sensor=] activation, error - conditions and notifications about newly available [=sensor readings=]. The example measures - and logs maximum total acceleration of a device hosting the [=platform sensor=]. + In the following example, firstly, we check whether the user agent has permission to access + [=sensor readings=], then we construct accelerometer sensor and add + [=event listener|event listeners=] to get [=event|events=] for [=platform sensor=] activation, + error conditions and notifications about newly available [=sensor readings=]. The example + measures and logs maximum total acceleration of a device hosting the [=platform sensor=]. The [=event handler event types=] for the corresponding [[#the-sensor-interface| Sensor Interface]]'s [=event handler=] attributes are defined in [[#event-handlers|Event handlers]] section.
-    let acl = new Accelerometer({frequency: 30});
-    let max_magnitude = 0;
-    acl.addEventListener('activate', () => console.log('Ready to measure.'));
-    acl.addEventListener('error', error => console.log('Error: ' + error.name));
-    acl.addEventListener('reading', () => {
-        let magnitude = Math.hypot(acl.x, acl.y, acl.z);
-        if (magnitude > max_magnitude) {
-            max_magnitude = magnitude;
-            console.log(\`Max magnitude: ${max_magnitude} m/s2\`);
+    navigator.permissions.query({ name: 'accelerometer' }).then(result => {
+        if (result.state === 'denied') {
+            console.log('Permission to use accelerometer sensor is denied.');
+            return;
         }
+
+        let acl = new Accelerometer({frequency: 30});
+        let max_magnitude = 0;
+        acl.addEventListener('activate', () => console.log('Ready to measure.'));
+        acl.addEventListener('error', error => console.log(\`Error: ${error.name}\`));
+        acl.addEventListener('reading', () => {
+            let magnitude = Math.hypot(acl.x, acl.y, acl.z);
+            if (magnitude > max_magnitude) {
+                max_magnitude = magnitude;
+                console.log(\`Max magnitude: ${max_magnitude} m/s2\`);
+            }
+        });
+        acl.start();
     });
-    acl.start();
     
diff --git a/index.html b/index.html index 7d6d9e1..61258b0 100644 --- a/index.html +++ b/index.html @@ -2116,23 +2116,30 @@

A Sensor object has an associated platform sensor.

The task source for the tasks mentioned in this specification is the sensor task source.

-
- In the following example, we construct accelerometer sensor and add event listeners to get events for platform sensor activation, error - conditions and notifications about newly available sensor readings. The example measures - and logs maximum total acceleration of a device hosting the platform sensor. +
+ In the following example, firstly, we check whether the user agent has permission to access sensor readings, then we construct accelerometer sensor and add event listeners to get events for platform sensor activation, + error conditions and notifications about newly available sensor readings. The example + measures and logs maximum total acceleration of a device hosting the platform sensor.

The event handler event types for the corresponding Sensor Interface's event handler attributes are defined in Event handlers section.

-
let acl = new Accelerometer({frequency: 30});
-let max_magnitude = 0;
-acl.addEventListener('activate', () => console.log('Ready to measure.'));
-acl.addEventListener('error', error => console.log('Error: ' + error.name));
-acl.addEventListener('reading', () => {
-    let magnitude = Math.hypot(acl.x, acl.y, acl.z);
-    if (magnitude > max_magnitude) {
-        max_magnitude = magnitude;
-        console.log(`Max magnitude: ${max_magnitude} m/s2`);
+
navigator.permissions.query({ name: 'accelerometer' }).then(result => {
+    if (result.state === 'denied') {
+        console.log('Permission to use accelerometer sensor is denied.');
+        return;
     }
+
+    let acl = new Accelerometer({frequency: 30});
+    let max_magnitude = 0;
+    acl.addEventListener('activate', () => console.log('Ready to measure.'));
+    acl.addEventListener('error', error => console.log(`Error: ${error.name}`));
+    acl.addEventListener('reading', () => {
+        let magnitude = Math.hypot(acl.x, acl.y, acl.z);
+        if (magnitude > max_magnitude) {
+            max_magnitude = magnitude;
+            console.log(`Max magnitude: ${max_magnitude} m/s2`);
+        }
+    });
+    acl.start();
 });
-acl.start();
 

7.1.1. Sensor lifecycle

@@ -2234,13 +2241,13 @@

[[lastEventFiredAt]] - The high resolution timestamp of the latest sensor reading that was sent to observers of the Sensor object, + The high resolution timestamp of the latest sensor reading that was sent to observers of the Sensor object, expressed in milliseconds that passed since the time origin. It is initially null. [[pendingReadingNotification]] A boolean which indicates whether the observers need to be - notified after a new sensor reading was reported. + notified after a new sensor reading was reported. It is initially false.

7.1.3. Sensor.activated

@@ -2333,7 +2340,7 @@

7.1.8. Sensor.onreading

onreading is an EventHandler which is called -to notify that new reading is available.

+to notify that new reading is available.

7.1.9. Sensor.onactivate

onactivate is an EventHandler which is called when this.[[state]] transitions from "activating" to "activated".

7.1.10. Sensor.onerror

@@ -2425,7 +2432,7 @@

Let type be the sensor type of sensor_instance.

  • -

    If the device has a single device sensor which can provide readings for type, then

    +

    If the device has a single device sensor which can provide readings for type, then

    1. Associate sensor_instance with a platform sensor corresponding @@ -2434,7 +2441,7 @@

      Return true.

  • -

    If the device has multiple device sensors which can provide readings for type, then

    +

    If the device has multiple device sensors which can provide readings for type, then

    1. If type has an associated default sensor, then

      @@ -2549,7 +2556,7 @@

      Set latest reading[key] to null.

  • -

    Update the user-agent-specific way in which sensor readings are obtained from sensor to no longer provide readings.

    +

    Update the user-agent-specific way in which sensor readings are obtained from sensor to no longer provide readings.

  • Return.

    @@ -2564,7 +2571,7 @@

    sensor, a platform sensor.

    -

    reading, a sensor reading.

    +

    reading, a sensor reading.

    output

    None

    @@ -2760,7 +2767,7 @@

    key, a string representing the name of the value.

    output
    -

    A sensor reading value or null.

    +

    A sensor reading value or null.

    1. @@ -2828,15 +2835,15 @@

      9.2 the distance at which an object is from it may see its associated interface called ProximitySensor.

      Attributes of the Sensor subclass that -hold sensor readings values +hold sensor readings values should be named after the full name of these values. For example, the Thermometer interface should hold -the sensor reading's value in +the sensor reading's value in a temperature attribute (and not a value or temp attribute). A good starting point for naming are the Quantities, Units, Dimensions and Data Types Ontologies [QUDT].

      9.3. Unit

      -

      Extension specifications must specify the unit of sensor readings.

      +

      Extension specifications must specify the unit of sensor readings.

      As per the Technical Architecture Group’s (TAG) API Design Principles [API-DESIGN-PRINCIPLES], all time measurement should be in milliseconds. All other units should be specified using, @@ -2893,7 +2900,7 @@

      Constructor] must take, as an argument, an optional dictionary whose inherited dictionaries contains SensorOptions. - Its attributes which expose sensor readings are read only and + Its attributes which expose sensor readings are read only and their getters must return the result of invoking get value from latest reading with this and attribute identifier as arguments.

    2. A PermissionName.

      @@ -2910,11 +2917,11 @@

      9.7. Extending the Permission API

      -

      An implementation of the Sensor interface for each sensor type must protect its reading by associated PermissionName or PermissionDescriptor. +

      An implementation of the Sensor interface for each sensor type must protect its reading by associated PermissionName or PermissionDescriptor. A Low-level sensor may use its interface name as a PermissionName, for instance, "gyroscope" or "accelerometer". Fusion sensors must request permission to access each of the sensors that are used as a source of fusion.

      -

      Even though, it might be difficult to reconstruct low-level sensor readings from +

      Even though, it might be difficult to reconstruct low-level sensor readings from fused data, some of the original information might be inferred. For example, it is easy to deduce user’s orientation in space if absolute or geomagnetic orientation sensors are used, therefore, these sensors must request permission to use magnetometer as it provides information about orientation of device in relation to Earth’s @@ -3522,17 +3529,17 @@

      I
    3. 5.4. Reading change threshold (2)
    4. 5.5. Sampling Frequency and Reporting Frequency (2) (3) (4)
    5. 6.2. Sensor (2) (3) (4) -
    6. 7.1. The Sensor Interface -
    7. 7.1.2. Sensor internal slots (2) -
    8. 7.1.8. Sensor.onreading -
    9. 8.2. Connect to sensor (2) -
    10. 8.6. Set sensor settings (2) -
    11. 8.7. Update latest reading -
    12. 8.13. Get value from latest reading -
    13. 9.2. Naming (2) -
    14. 9.3. Unit -
    15. 9.6. Definition Requirements -
    16. 9.7. Extending the Permission API (2) +
    17. 7.1. The Sensor Interface (2) +
    18. 7.1.2. Sensor internal slots (2) +
    19. 7.1.8. Sensor.onreading +
    20. 8.2. Connect to sensor (2) +
    21. 8.6. Set sensor settings (2) +
    22. 8.7. Update latest reading +
    23. 8.13. Get value from latest reading +
    24. 9.2. Naming (2) +
    25. 9.3. Unit +
    26. 9.6. Definition Requirements +
    27. 9.7. Extending the Permission API (2)