Namespace: SpawnDev.SpawnJS.JSObjects.Bluetooth
Inheritance: SpawnJSObject -> EventTarget -> Bluetooth
MDN Reference: Bluetooth - MDN
The Bluetooth interface of the Web Bluetooth API provides methods to query and connect to Bluetooth Low Energy (BLE) devices. Access via Navigator.Bluetooth. Requires a secure context (HTTPS) and user gesture for RequestDevice().
| Signature |
Description |
Bluetooth(SpawnJSObjectReference _ref) |
Deserialization constructor. Access via navigator.Bluetooth. |
| Method |
Return Type |
Description |
RequestDevice(BluetoothDeviceOptions options) |
Task<BluetoothDevice> |
Requests a device from the user. Shows a browser picker dialog. Requires user gesture. |
GetDevices() |
Task<BluetoothDevice[]> |
Returns previously paired devices (if the browser supports it). |
| Event |
Type |
Description |
OnAvailabilityChanged |
ActionEvent<Event> |
Fired when Bluetooth adapter availability changes. |
using var navigator = new Navigator();
var bluetooth = navigator.Bluetooth;
if (bluetooth != null)
{
using var device = await bluetooth.RequestDevice(new BluetoothDeviceOptions
{
Filters = new[] { new BluetoothDeviceFilter { Services = new[] { "heart_rate" } } }
});
Console.WriteLine($"Device: {device.Name}");
}