Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AspNetMonsters/Blazor.Sensors
Blazor interop for browers sensor apis
https://github.com/AspNetMonsters/Blazor.Sensors
Last synced: 18 days ago
JSON representation
Blazor interop for browers sensor apis
- Host: GitHub
- URL: https://github.com/AspNetMonsters/Blazor.Sensors
- Owner: AspNetMonsters
- License: mit
- Created: 2018-03-08T22:58:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-13T22:10:46.000Z (about 6 years ago)
- Last Synced: 2024-10-05T15:06:04.916Z (about 1 month ago)
- Language: C#
- Homepage:
- Size: 38.1 KB
- Stars: 11
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AspNetMonsters.Blazor.Sensors
This package provides Blazor applications with access to the browser sensor apis. Currently only the [AmbientLightSensor api](https://developer.mozilla.org/en-US/docs/Web/API/AmbientLightSensor) is supported.## Usage
1) In your Blazor app, add the `AspNetMonsters.Blazor.Sensors` [NuGet package](https://www.nuget.org/packages/AspNetMonsters.Blazor.Sensors/)```
Install-Package AspNetMonsters.Blazor.Sensors -IncludePrerelease
```1) In your Blazor app's `Startup.cs` `ConfigureServices` method, register the `AmbientLightSensorService`.
```
services.AddSingleton();
```1) Now you can inject the `AmbientLightSensorService` into any Blazor page and use it like this:
```
@using AspNetMonsters.Blazor.Sensors
@inject AmbientLightSensorService sensorService
Let there be light!
@sensor?.Illuminance
Stop
Start@functions
{
AmbientLightSensor sensor;protected override async Task OnInitAsync()
{
await Start();
}
private async Task Start()
{
sensor = await sensorService.StartReading(() =>
{
StateHasChanged();
});
}private async Task Stop()
{
if (sensor != null)
{
await sensorService.StopReading(sensor);
sensor = null;
}
}
}
```