DeviceSensorProvider Class
The sensors of the device (https://w3c.github.io/sensors/#virtual-sensors) of the browsing contexts that share a BrowsingContextOptions (DeviceSensorsOptions.Provider): the application adds a sensor of a type with DeviceSensorProvider.AddSensor, then pushes its readings with DeviceSensor.Update. The sensor objects of the documents (e.g. new Accelerometer()) connect to the sensor of their type when they start, and the device orientation and motion events read the accelerometer, linear acceleration, gyroscope and orientation sensors.
public sealed class DeviceSensorProviderRemarks
A provider can be shared by several browsing contexts, and used from any thread.
Constructors
| Name | Description |
|---|---|
| DeviceSensorProvider() |
DeviceSensorProvider()
DeviceSensorProvider.cspublic DeviceSensorProvider()No documentation is available.
Properties
| Name | Description |
|---|---|
| Sensors | Gets the sensors of the device. |
Sensors
DeviceSensorProvider.csMethods
| Name | Description |
|---|---|
| AddSensor(DeviceSensorType, bool, double?, double?) | Adds a sensor to the device (https://w3c.github.io/sensors/#create-virtual-sensor-command). The sensor objects of its type that start from now on connect to it. A device has at most one sensor of each type. |
| GetSensor(DeviceSensorType) | Returns the sensor of a type, or null when the device has none. |
| RemoveSensor(DeviceSensorType) | Removes the sensor of a type from the device (https://w3c.github.io/sensors/#delete-virtual-sensor-command): the sensor objects connected to it no longer receive readings. Returns false when the device has no sensor of this type. |
AddSensor(DeviceSensorType, bool, double?, double?)
DeviceSensorProvider.csAdds a sensor to the device (https://w3c.github.io/sensors/#create-virtual-sensor-command). The sensor objects of its type that start from now on connect to it. A device has at most one sensor of each type.
public DeviceSensor AddSensor(DeviceSensorType type, bool canProvideReadings = true, double? minimumSamplingFrequency = null, double? maximumSamplingFrequency = null)Parameters
typeDeviceSensorType- The type of the sensor.
canProvideReadingsbool- Whether the sensor works: when false, the sensor objects that start fail with a
NotReadableError, and the events report null values. minimumSamplingFrequencydouble?- The minimum sampling frequency of the sensor, in Hz (
DeviceSensorProvider.DefaultMinimumSamplingFrequencyby default). maximumSamplingFrequencydouble?- The maximum sampling frequency of the sensor, in Hz (
DeviceSensorProvider.DefaultMaximumSamplingFrequencyby default).
Returns
Exceptions
InvalidOperationException- The device already has a sensor of this type.
GetSensor(DeviceSensorType)
DeviceSensorProvider.csReturns the sensor of a type, or null when the device has none.
public DeviceSensor? GetSensor(DeviceSensorType type)RemoveSensor(DeviceSensorType)
DeviceSensorProvider.csRemoves the sensor of a type from the device (https://w3c.github.io/sensors/#delete-virtual-sensor-command): the sensor objects connected to it no longer receive readings. Returns false when the device has no sensor of this type.
public bool RemoveSensor(DeviceSensorType type)Constants
| Name | Description |
|---|---|
| DefaultMaximumSamplingFrequency | The default maximum sampling frequency of a sensor, in Hz (the browsers do not report the readings more often, to mitigate the attacks). |
| DefaultMinimumSamplingFrequency | The default minimum sampling frequency of a sensor, in Hz. |
DefaultMaximumSamplingFrequency
The default maximum sampling frequency of a sensor, in Hz (the browsers do not report the readings more often, to mitigate the attacks).
public const double DefaultMaximumSamplingFrequency = 60dDefaultMinimumSamplingFrequency
The default minimum sampling frequency of a sensor, in Hz.
public const double DefaultMinimumSamplingFrequency = 1d