Version: Smart Feature Phone 3.0

BluetoothAdapter

Description#

The BluetoothAdapter interface of the Web Bluetooth API is used to handle all the operations requested by Bluetooth networks. A Bluetooth adapter is the physical interface which is used to interact with local Bluetooth device.

Interface overview#

[CheckAnyPermissions="bluetooth"]
interface BluetoothAdapter: EventTarget
{
readonly attribute BluetoothAdapterState state;
readonly attribute DOMString name;
readonly attribute boolean discoverable;
readonly attribute boolean discovering;
attribute EventHandler onattributechanged;
attribute EventHandler ondevicepaired;
attribute EventHandler ondeviceunpaired;
attribute EventHandler onpairingaborted;
attribute EventHandler ona2dpstatuschanged;
attribute EventHandler onhfpstatuschanged;
attribute EventHandler onscostatuschanged;
attribute EventHandler onrequestmediaplaystatus;
[NewObject] Promise<void> setDiscoverable(boolean aDiscoverable);
[NewObject] Promise<BluetoothDiscoveryHandle> startDiscovery();
[NewObject] Promise<void> stopDiscovery();
[NewObject] Promise<void> pair(DOMString aAddress);
[NewObject] Promise<void> unpair(DOMString aAddress);
sequence<BluetoothDevice> getPairedDevices();
// BLE methods
[NewObject] Promise<BluetoothDiscoveryHandle> startLeScan(sequence<DOMString> aServiceUuids);
[NewObject] Promise<void> stopLeScan(BluetoothDiscoveryHandle aDiscoveryHandle);
};

Properties#

  • BluetoothAdapter.discoverable {.read-only}

A boolean indicating if the device is discoverable (true) or not (false) by other Bluetooth devices.

  • BluetoothAdapter.discovering {.read-only}

A boolean indicating if the device's adapter is in the process of discovering (true) or not (false) surrounding Bluetooth devices.

  • BluetoothAdapter.name {.read-only}

A string indicating the human readable name of the device's adapter.

  • BluetoothAdapter.state {.read-only .no-link}

Returns the state of the local bluetooth adapter.

Event Handlers#

  • BluetoothAdapter.onattributechanged A handler for the attributechanged event; it is triggered when one of the local bluetooth adapter's properties has changed

  • BluetoothAdapter.ondevicepaired A handler for the devicepaired event; it is triggered when a remote device gets paired with the local bluetooth adapter.

  • BluetoothAdapter.ondeviceunpaired A handler for the deviceunpaired event; it is triggered when a remote device gets unpaired from the local bluetooth adapter.

  • BluetoothAdapter.onpairingaborted A handler for the pairingaborted event; it is triggered when pairing fails due to authentication failure, the remote device being down (bluetooth ACL becomes disconnected), or some kind of internal error.

  • BluetoothAdapter.ona2dpstatuschanged A handler for the a2dpstatuschanged event; it is triggered when an A2DP connection status changes.

  • BluetoothAdapter.onhfpstatuschanged A handler for the hfpstatuschanged event; it is triggered when an HFP connection status changes.

  • BluetoothAdapter.onrequestmediaplaystatus A handler for the requestmediaplaystatus event; it is triggered when a remote Bluetooth device queries the current media play status.

  • BluetoothAdapter.onscostatuschanged A handler for the scostatuschanged event; it is triggered when a SCO connection status changes.

Note: Because the BluetoothAdapter interface inherits from the EventTarget interface, all these events can be listened by using the addEventListener method.

Methods#

  • BluetoothAdapter.getPairedDevices() Allows retrieving a full list of all devices paired with the device's adapter.

  • BluetoothAdapter.pair() Allows to start pairing a remote device with the device's adapter.

  • BluetoothAdapter.setDiscoverable() Allows to change the value of the discoverable property.

  • BluetoothAdapter.startDiscovery() Allows the device's adapter to start seeking for remote devices.

  • BluetoothAdapter.startLeScan() Instructs the device's adapter to start seeking for remote LE devices advertising given services.

  • BluetoothAdapter.stopDiscovery() Allows the device's adapter to stop seeking for remote devices.

  • BluetoothAdapter.stopLeScan() Instructs the device's adapter to stop scanning for remote LE devices.

  • BluetoothAdapter.unpair() Allows to unpair a remote device from the device's adapter.