Table of Contents

Class Bluetooth

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll
NOTE
Experimental
The Bluetooth interface of the Web Bluetooth API provides methods to query Bluetooth availability and request access to devices.
[Value("Bluetooth")]
public class Bluetooth : EventTarget
Inheritance
Bluetooth
Inherited Members

Remarks

Constructors

Bluetooth()

public Bluetooth()

Properties

Onavailabilitychanged

[Value("onavailabilitychanged")]
public EventHandlerNonNull Onavailabilitychanged { get; set; }

Property Value

EventHandlerNonNull

ReferringDevice

[Value("referringDevice")]
public BluetoothDevice? ReferringDevice { get; }

Property Value

BluetoothDevice

Methods

GetAvailability()

NOTE
Experimental
The getAvailability() method of the Bluetooth interface nominally returns true if the user agent can support Bluetooth (because the device has a Bluetooth adapter), and false otherwise.
[Value("getAvailability")]
public Task<bool> GetAvailability()

Returns

Task<bool>

A Promise that resolves with a Boolean.The Promise will resolve with a value of false if access is disallowed by Permissions-Policy: bluetooth, if the user has configured the browser to always resolve with false, or if the device does not have a Bluetooth adapter.
Otherwise it will resolve with true.

Remarks

The word &quot;nominally&quot; is used because if permission to use the Web Bluetooth API is disallowed by the Permissions-Policy: bluetooth permission, the method will always return false.
In addition, a user can configure their browser to return false from a getAvailability() call even if the browser does have an operational Bluetooth adapter, and vice versa. This setting value ignored if access is blocked by the permission.

Even if getAvailability() returns true and the device actually has a Bluetooth adaptor, this does not necessarily mean that calling RequestDevice(RequestDeviceOptions) will resolve with a BluetoothDevice.
The Bluetooth adapter may not be powered, and a user might deny permission to use the API when prompted.

See also on MDN

GetDevices()

NOTE
Experimental
The getDevices() method of the Bluetooth interface returns an array containing the Bluetooth devices that this origin is allowed to access — including those that are out of range and powered off.
[Value("getDevices")]
public Task<List<BluetoothDevice>> GetDevices()

Returns

Task<List<BluetoothDevice>>

A {{JSxRef("Promise")}} that resolves with an array of BluetoothDevice objects.

Remarks

RequestDevice(RequestDeviceOptions)

NOTE
Experimental
The Bluetooth.requestDevice() method of the Bluetooth interface returns a {{jsxref("Promise")}} that fulfills with a BluetoothDevice object matching the specified options.
If there is no chooser UI, this method returns the first device matching the criteria.
[Value("requestDevice")]
public Task<BluetoothDevice> RequestDevice(RequestDeviceOptions options = null)

Parameters

options RequestDeviceOptions

Returns

Task<BluetoothDevice>

A {{jsxref("Promise")}} to a BluetoothDevice object.

Remarks

RequestLEScan(BluetoothLEScanOptions)

[Value("requestLEScan")]
public Task<BluetoothLEScan> RequestLEScan(BluetoothLEScanOptions options = null)

Parameters

options BluetoothLEScanOptions

Returns

Task<BluetoothLEScan>