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 DeviceSensorProvider

Remarks

A provider can be shared by several browsing contexts, and used from any thread.

Constructors

NameDescription
DeviceSensorProvider()

DeviceSensorProvider()

DeviceSensorProvider.cs
public DeviceSensorProvider()

No documentation is available.

Properties

NameDescription
SensorsGets the sensors of the device.

Gets the sensors of the device.

public IReadOnlyList<DeviceSensor> Sensors { get; }

Methods

NameDescription
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.cs

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.

public DeviceSensor AddSensor(DeviceSensorType type, bool canProvideReadings = true, double? minimumSamplingFrequency = null, double? maximumSamplingFrequency = null)

Parameters

type DeviceSensorType
The type of the sensor.
canProvideReadings bool
Whether the sensor works: when false, the sensor objects that start fail with a NotReadableError, and the events report null values.
minimumSamplingFrequency double?
The minimum sampling frequency of the sensor, in Hz (DeviceSensorProvider.DefaultMinimumSamplingFrequency by default).
maximumSamplingFrequency double?
The maximum sampling frequency of the sensor, in Hz (DeviceSensorProvider.DefaultMaximumSamplingFrequency by default).

Returns

DeviceSensor

Exceptions

InvalidOperationException
The device already has a sensor of this type.

GetSensor(DeviceSensorType)

DeviceSensorProvider.cs

Returns the sensor of a type, or null when the device has none.

public DeviceSensor? GetSensor(DeviceSensorType type)

Parameters

type DeviceSensorType

Returns

DeviceSensor?

RemoveSensor(DeviceSensorType)

DeviceSensorProvider.cs

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.

public bool RemoveSensor(DeviceSensorType type)

Parameters

type DeviceSensorType

Returns

bool

Constants

NameDescription
DefaultMaximumSamplingFrequencyThe default maximum sampling frequency of a sensor, in Hz (the browsers do not report the readings more often, to mitigate the attacks).
DefaultMinimumSamplingFrequencyThe 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 = 60d

DefaultMinimumSamplingFrequency

The default minimum sampling frequency of a sensor, in Hz.

public const double DefaultMinimumSamplingFrequency = 1d