BluetoothAdapter (Firefox OS)

This API is available on Firefox OS for internal applications only.

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

JavaScript
[CheckPermissions="bluetooth"]
interface BluetoothAdapter: EventTarget
{
  [AvailableIn=CertifiedApps] readonly attribute DOMString <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#address" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">address</a>;
  [AvailableIn=CertifiedApps] readonly attribute <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothPairingListener#Interface" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothPairingListener">BluetoothPairingListener</a> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#pairingReqs" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">pairingReqs</a>; 
  readonly attribute <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#BluetoothAdapterState" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">BluetoothAdapterState</a> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#state" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">state</a>;
  readonly attribute DOMString <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#name" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">name</a>;
  readonly attribute boolean <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#discoverable" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">discoverable</a>;
  readonly attribute boolean <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#discovering" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">discovering</a>;
  readonly attribute <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#BluetoothGattServer" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer">BluetoothGattServer</a>? <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#gattServer" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">gattServer</a>;

           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#onattributechanged" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">onattributechanged</a>;
           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#ondevicepaired" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">ondevicepaired</a>;
           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#ondeviceunpaired" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">ondeviceunpaired</a>;
           attribute EventHandler <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#onpairingaborted" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">onpairingaborted</a>;

  [NewObject, AvailableIn=CertifiedApps] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#enable.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">enable()</a>;
  [NewObject, AvailableIn=CertifiedApps] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#disable.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">disable()</a>;
  [NewObject, AvailableIn=CertifiedApps] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#setName.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">setName(DOMString aName)</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#setDiscoverable.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">setDiscoverable(boolean aDiscoverable)</a>;
  [NewObject] Promise<<a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDiscoveryHandle" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothDiscoveryHandle">BluetoothDiscoveryHandle</a>> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#startDiscovery.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">startDiscovery()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#stopDiscovery.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">stopDiscovery()</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#pair.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">pair(DOMString aAddress)</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#unpair.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">unpair(DOMString aAddress)</a>;
  sequence<<a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDevice" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice">BluetoothDevice</a>> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#getPairedDevices.28.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">getPairedDevices()</a>;

  // BLE methods
  [NewObject] Promise<<a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDiscoveryHandle" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothDiscoveryHandle">BluetoothDiscoveryHandle</a>> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#startLeScan.28sequence.3CDOMString.3E_aServiceUuids.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">startLeScan(sequence<DOMString> aServiceUuids)</a>;
  [NewObject] Promise<void> <a href="https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#stopLeScan.28BluetoothDiscoveryHandle_aDiscoveryHandle.29" class="external" title="B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter">stopLeScan(BluetoothDiscoveryHandle aDiscoveryHandle)</a>;
};

Properties

BluetoothAdapter.address Read only
A string representing the address of the device's adapter.
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.gattServer Read only
Returns the BluetoothGattServer to use to conduct GATT server operations on the local bluetooth adapter. Will return null if the adapter is not enabled.
BluetoothAdapter.name Read only
A string indicating the human readable name of the device's adapter.
BluetoothAdapter.pairingReqs Read only
Returns the BluetoothPairingListener object containing the event handlers needed to response to  different pairing types operations.
BluetoothAdapter.state Read only
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.

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

Obsolete properties

BluetoothAdapter.class Read only
A number representing the Class of Device(CoD) field of the device's adapter.
BluetoothAdapter.discoverableTimeout Read only
A number indicating how long (in seconds) the device remains discoverable.
BluetoothAdapter.devices Read only
An Array of BluetoothDevice object representing all the Bluetooth devices discovered in the area surrounding the device.
BluetoothAdapter.uuids Read only
An Array of string, each of them representing the UUID of a Bluetooth service the device's adapter is able to provide.

Obsolete event handlers

BluetoothAdapter.ona2dpstatuschanged
A handler for the a2dpstatuschanged event; it is triggered when an A2DP connection status changes.
BluetoothAdapter.ondevicefound
A handler for the devicefound event; it is triggered when a Bluetooth device is found.
BluetoothAdapter.onhfpstatuschanged
A handler for the hfpstatuschanged event; it is triggered when an HFP connection status changes.
BluetoothAdapter.onpairedstatuschanged
A handler for the pairedstatuschanged event; it is triggered when a pairing process is completed.
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.

Methods

BluetoothAdapter.enable()
Enables the local bluetooth adapter.
BluetoothAdapter.disable()
Disables the local bluetooth adapter.
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.setName()
Allows to change the value of the name property.
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.

Obsolete methods

BluetoothAdapter.answerWaitingCall()
Allows HFP devices to answer a pending incoming call on a CDMA network.
BluetoothAdapter.confirmReceivingFile()
Allows to confirm reception of a file from a remote device.
BluetoothAdapter.connect()
Allows to connect the device to a remote device using a given Bluetooth profile.
BluetoothAdapter.connectSco()
Allows the device to enable the SCO connection to broadcast/listen audio to/from the remote devices it is connected to.
BluetoothAdapter.disconnect()
Allows to disconnect the device from a remote device for one or all Bluetooth profiles.
BluetoothAdapter.disconnectSco()
Allows the device to disable the SCO connection with the remote devices it is connected to.
BluetoothAdapter.getConnectedDevices()
Allows retrieving a full list of all devices connected to the device's adapter.
BluetoothAdapter.ignoreWaitingCall()
Allows HFP devices to dismiss a pending incoming call on a CDMA network.
BluetoothAdapter.isConnected()
Allows to know if the given Bluetooth service is connected or not .
BluetoothAdapter.isScoConnected()
Allows to know if the device is connected through a SCO connection with the remote devices it is connected to.
BluetoothAdapter.sendFile()
Allows to start sending a file to a given remote device.
BluetoothAdapter.sendMediaMetaData()
Allows to send metadata about a media to remote devices connected with the AVRCP profile.
BluetoothAdapter.sendMediaPlayStatus()
Allows to send the play status of the device to remote devices connected with the AVRCP profile.
BluetoothAdapter.setDiscoverableTimeout()
Allows to change the value of the discoverableTimeout property.
BluetoothAdapter.setPairingConfirmation()
Allows to accept the pairing confirmation to pair the device's adapter with a remote device.
BluetoothAdapter.setPasskey()
Allows to define a pass key to pair the device's adapter with a remote device.
BluetoothAdapter.setPinCode()
Allows to define a pin code to pair the device's adapter with a remote device.
BluetoothAdapter.stopSendingFile()
Allows to stop sending a file to a given remote device.
BluetoothAdapter.toggleCalls()
Allows HFP devices to switch from one call to the other on a CDMA network.

Specifications

Specification Status Comment
Web Bluetooth
The definition of 'BluetoothAdapter' in that specification.
Draft Rough draft; not part of any official specification yet. It should be discussed as part of the W3C's System Applications Working Group.

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support No support No support No support No support
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Bluetooth 'v2' support: pairingReqs, state, onadapterremoved, gattServer, onattributechange, ondevicepaired, ondeviceunpaired, onpairingaborted, enable(), disable(), startLeScan(), stopLeScan() No support No support No support 2.1 No support No support No support No support
Bluetooth initial support: address, discoverable, discovering, name, class, discoverableTimeout, devices, uuids, ona2dpstatuschanged, ondevicefound, onhfpstatuschanged, onpairedstatuschanged, onrequestmediaplaystatus, onscostatuschanged, setName(), setDiscoverable(), startDiscovery(), stopdiscovery(), pair(), unpair()getPairedDevices(), answerWaitingCall(), confirmReceivingFile(), connect(), connectSco(), disconnect(), disconnectSco(), getConnectedDevices(), ignoreWaitingCall(), isConnected(), isScoConnected(), sendFile(), sendMediaMetaData(), sendMediaPlayStatus(), setDiscoverableTimeout(), setPairingConformation(), setPasskey(), setPinCode(), stopSendingFile(), toggleCalls() No support No support No support 1.0.1 No support No support No support No support

 

See also

Using the Web Bluetooth API

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/bluetoothadapter

API B2G BluetoothAdapter Firefox OS Interface Non-standard Reference Référence Web Bluetooth WebAPI