Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 1.57 KB

File metadata and controls

52 lines (38 loc) · 1.57 KB

BluetoothDevice

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.

Constructors

Signature Description
BluetoothDevice(SpawnJSObjectReference _ref) Deserialization constructor.

Properties

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.

Events

Event Type Description
OnGATTServerDisconnected ActionEvent<Event> Fired when the GATT server disconnects.

Example

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");
}