Namespace: SpawnDev.SpawnJS.JSObjects.Bluetooth
Inheritance: SpawnJSObject -> EventTarget -> BluetoothDevice
MDN Reference: BluetoothDevice - MDN
Represents a Bluetooth device. Provides access to the device name, ID, and GATT server for communicating with services and characteristics.
| Signature |
Description |
BluetoothDevice(SpawnJSObjectReference _ref) |
Deserialization constructor. |
| Property |
Type |
Description |
Id |
string |
A unique identifier for the device. |
Name |
string? |
The human-readable name of the device. |
Gatt |
BluetoothRemoteGATTServer? |
The GATT server for this device. Use to connect and discover services. |
| Event |
Type |
Description |
OnGATTServerDisconnected |
ActionEvent<Event> |
Fired when the GATT server disconnects. |
using var device = await bluetooth.RequestDevice(options);
Console.WriteLine($"Name: {device.Name}, ID: {device.Id}");
// Subscribe using a named method (required for proper cleanup)
device.OnGATTServerDisconnected += Device_OnGATTServerDisconnected;
using var gatt = device.Gatt;
if (gatt != null)
{
await gatt.Connect();
// Discover services and characteristics...
}
// Clean up event handler before disposal
device.OnGATTServerDisconnected -= Device_OnGATTServerDisconnected;
void Device_OnGATTServerDisconnected(Event e)
{
Console.WriteLine("Device disconnected");
}