Table of Contents

Class BaseBluetoothConnectedDevice

Namespace
Bluetooth.Core.Broadcasting
Assembly
Bluetooth.Core.Broadcasting.dll

Base class for Bluetooth broadcaster devices.

public abstract class BaseBluetoothConnectedDevice : BaseBindableObject, IBluetoothConnectedDevice, INotifyPropertyChanged, IAsyncDisposable
Inheritance
BaseBluetoothConnectedDevice
Implements
Derived
Inherited Members

Constructors

BaseBluetoothConnectedDevice(IBluetoothBroadcaster, BluetoothConnectedDeviceSpec, ILogger<IBluetoothConnectedDevice>?)

Initializes a new instance using a factory spec.

protected BaseBluetoothConnectedDevice(IBluetoothBroadcaster broadcaster, IBluetoothConnectedDeviceFactory.BluetoothConnectedDeviceSpec spec, ILogger<IBluetoothConnectedDevice>? logger = null)

Parameters

broadcaster IBluetoothBroadcaster

The broadcaster that owns this client device.

spec IBluetoothConnectedDeviceFactory.BluetoothConnectedDeviceSpec

The factory spec containing connected device information.

logger ILogger<IBluetoothConnectedDevice>

The logger for logging operations.

BaseBluetoothConnectedDevice(IBluetoothBroadcaster, string, ILogger<IBluetoothConnectedDevice>?)

Initializes a new instance of the BaseBluetoothConnectedDevice class.

protected BaseBluetoothConnectedDevice(IBluetoothBroadcaster broadcaster, string id, ILogger<IBluetoothConnectedDevice>? logger = null)

Parameters

broadcaster IBluetoothBroadcaster

The broadcaster that owns this client device.

id string

The unique identifier for the connected device, typically a UUID or MAC address.

logger ILogger<IBluetoothConnectedDevice>

The logger for logging operations.

Properties

Broadcaster

Gets the Bluetooth broadcaster hosting this service.

public IBluetoothBroadcaster Broadcaster { get; }

Property Value

IBluetoothBroadcaster

Id

Gets the unique identifier of the connected client device. This is typically a string that distinguishes this client device from others in the Bluetooth broadcasting context, such as a MAC address or a custom identifier assigned by the platform.

public string Id { get; }

Property Value

string

IsConnected

Indicates whether the client device is currently connected.

public bool IsConnected { get; protected set; }

Property Value

bool

Mtu

Gets the current Maximum Transmission Unit (MTU) for this client connection. The MTU determines the maximum size of a single packet that can be sent.

public int Mtu { get; protected set; }

Property Value

int

Name

Gets the name of the connected client device.

public string Name { get; }

Property Value

string

SubscribedCharacteristics

Gets the list of broadcast characteristics this client device is subscribed to.

public IReadOnlyList<IBluetoothLocalCharacteristic> SubscribedCharacteristics { get; }

Property Value

IReadOnlyList<IBluetoothLocalCharacteristic>

Methods

AddCharacteristicSubscription(IBluetoothLocalCharacteristic)

Adds a subscription to a broadcast characteristic for this client device.

public void AddCharacteristicSubscription(IBluetoothLocalCharacteristic localCharacteristic)

Parameters

localCharacteristic IBluetoothLocalCharacteristic

DisconnectAsync(TimeSpan?, CancellationToken)

Disconnects the client device from the broadcaster.

public ValueTask DisconnectAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

timeout TimeSpan?

An optional timeout for the disconnection operation.

cancellationToken CancellationToken

An optional cancellation token to cancel the disconnection operation.

Returns

ValueTask

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeAsyncCore()

Disposes the resources asynchronously.

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

NativeDisconnectAsync(TimeSpan?, CancellationToken)

Performs the native disconnection logic for the client device.

protected abstract ValueTask NativeDisconnectAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

timeout TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask

OnConnectionStatusChanged(bool)

Called when the connection status of the client device changes.

protected void OnConnectionStatusChanged(bool isConnected)

Parameters

isConnected bool

OnMtuChanged(int)

Called when MTU changes for this client connection.

protected void OnMtuChanged(int mtu)

Parameters

mtu int

RemoveAllCharacteristicSubscriptions()

Removes all characteristic subscriptions for this client device.

public void RemoveAllCharacteristicSubscriptions()

RemoveCharacteristicSubscription(IBluetoothLocalCharacteristic)

Removes a subscription to a broadcast characteristic for this client device.

public void RemoveCharacteristicSubscription(IBluetoothLocalCharacteristic localCharacteristic)

Parameters

localCharacteristic IBluetoothLocalCharacteristic

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

Events

Connected

Event raised when the client device successfully connects to the broadcaster.

public event EventHandler? Connected

Event Type

EventHandler

Disconnected

Event raised when the client device disconnects from the broadcaster.

public event EventHandler? Disconnected

Event Type

EventHandler

MtuChanged

Event raised when the MTU changes for this client connection.

public event EventHandler<MtuChangedEventArgs>? MtuChanged

Event Type

EventHandler<MtuChangedEventArgs>