{"id":13808171,"url":"https://github.com/KeudellCoding/Blazor.WebBluetooth","last_synced_at":"2025-05-14T02:31:23.160Z","repository":{"id":143199080,"uuid":"367899207","full_name":"KeudellCoding/Blazor.WebBluetooth","owner":"KeudellCoding","description":"Blazor service for the experimental WebBluetooth functions.","archived":false,"fork":false,"pushed_at":"2022-12-08T15:25:34.000Z","size":16,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-09-17T05:22:22.498Z","etag":null,"topics":["blazor","webbluetooth"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/KeudellCoding.Blazor.WebBluetooth/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KeudellCoding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"KeudellCoding","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-05-16T14:11:37.000Z","updated_at":"2024-01-03T02:23:36.604Z","dependencies_parsed_at":"2023-06-09T10:30:47.392Z","dependency_job_id":null,"html_url":"https://github.com/KeudellCoding/Blazor.WebBluetooth","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeudellCoding%2FBlazor.WebBluetooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeudellCoding%2FBlazor.WebBluetooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeudellCoding%2FBlazor.WebBluetooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeudellCoding%2FBlazor.WebBluetooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KeudellCoding","download_url":"https://codeload.github.com/KeudellCoding/Blazor.WebBluetooth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225273223,"owners_count":17448071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","webbluetooth"],"created_at":"2024-08-04T01:01:36.613Z","updated_at":"2024-11-19T00:30:36.213Z","avatar_url":"https://github.com/KeudellCoding.png","language":"C#","funding_links":["https://ko-fi.com/KeudellCoding"],"categories":["Libraries \u0026 Extensions"],"sub_categories":["Tools \u0026 Utilities"],"readme":"# Blazor.WebBluetooth\n\n## Installation\n1. Install the NuGet package `KeudellCoding.Blazor.WebBluetooth`.\n2. Add the following lines to _Imports.razor\n```csharp\n@using KeudellCoding.Blazor.WebBluetooth\n@using KeudellCoding.Blazor.WebBluetooth.Models\n```\n3. Register Service\n  * Option 1: If you are using Blazor WebAssembly, add the following lines to Program.cs\n  ```csharp\n  using KeudellCoding.Blazor.WebBluetooth;\n  \n  builder.Services.AddWebBluetooth();\n  ```\n  * Option 2: If you are using Blazor Server, add the following lines to the Startup.cs in the ConfigureServices function\n  ```csharp\n  using KeudellCoding.Blazor.WebBluetooth;\n  \n  services.AddWebBluetooth();\n  ```\n\n## Usage Example\n```csharp\n@page \"/\"\n@inject WebBluetoothControllerService __WebBluetooth\n\n\u003cdiv\u003e\n    @if (isAvailable.HasValue) {\n        if (isAvailable == true) {\n            \u003cbutton @onclick=\"connect\"\u003eConnect\u003c/button\u003e\n            \u003cbutton @onclick=\"disconnect\"\u003eDisconnect\u003c/button\u003e\n\n            \u003cbr /\u003e\n            \n            @if (connectedDevice != null) {\n                \u003cspan\u003e@connectedDevice.Id\u003c/span\u003e\u003cbr /\u003e\u003cspan\u003e@connectedDevice.Name\u003c/span\u003e\n            }\n        }\n        else {\n            \u003cb\u003eBluetooth not available!\u003c/b\u003e\n        }\n    }\n    else {\n        \u003ci\u003eLoading Bluetooth...\u003c/i\u003e\n    }\n\u003c/div\u003e\n\n@code {\n    private bool? isAvailable = null;\n    private Device connectedDevice;\n\n    protected override async Task OnAfterRenderAsync(bool firstRender) {\n        if (firstRender) {\n            isAvailable = await __WebBluetooth.IsAvailableAsync();\n            StateHasChanged();\n        }\n    }\n    \n    private async Task connect() {\n        connectedDevice = await __WebBluetooth.RequestDeviceAsync(new RequestDeviceQuery() {\n            Filters = new List\u003cFilter\u003e {\n                new Filter() {\n                    Services = new List\u003cstring\u003e {\n                        \"\u003c\u003cSERVICE_ID_OR_NAME\u003e\u003e\"\n                    }\n                }\n            }\n        });\n        StateHasChanged();\n    }\n    private async Task disconnect() {\n        if (connectedDevice == null) return;\n        await __WebBluetooth.DisconnectAsync(connectedDevice);\n    }\n}\n```\n\n## Notes\n1. I programmed this project based on [EngstromJimmy](https://github.com/EngstromJimmy/Blazm.Bluetooth) and adapted it for my personal needs. Maybe it will help others too.\n2. Currently, WebBluetooth is not yet supported by all browsers. A current implementation status can be found [here](https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md).\n3. WebBluetooth is a feature that is still under development. There may still be spontaneous massive changes in the JavaScript API that would result in this project no longer working.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeudellCoding%2FBlazor.WebBluetooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKeudellCoding%2FBlazor.WebBluetooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeudellCoding%2FBlazor.WebBluetooth/lists"}