B2G/Bluetooth/WebBluetooth-v2/BluetoothManager: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
mNo edit summary
Line 5: Line 5:
  interface BluetoothManager: EventTarget
  interface BluetoothManager: EventTarget
  {
  {
   attribute EventHandler [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded onadapteradded];
   attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|onadapteradded]];
   attribute EventHandler [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved onadapterremoved];
   attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|onadapterremoved]];
   
   
   any              [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29 getAdapters()]; // array of BluetoothAdapter
   any              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29|getAdapters()]]; // array of BluetoothAdapter
   BluetoothAdapter [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getDefaultAdapter.28.29 getDefaultAdapter()];
   BluetoothAdapter [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getDefaultAdapter.28.29|getDefaultAdapter()]];
  };
  };


== Event Handlers ==
== Event Handlers ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded BluetoothManager.onadapteradded]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|BluetoothManager.onadapteradded]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved BluetoothManager.onadapterremoved]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|BluetoothManager.onadapterremoved]]


=== onadapteradded ===
=== onadapteradded ===
Line 23: Line 23:
; Parameter
; Parameter
: ''aAdapterEvent''
: ''aAdapterEvent''
:: The event is a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent BluetoothAdapterEvent] with property [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#adapter adapter] as the added bluetooth adapter and property [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#isDefault isDefault] indicating whether the added adapter is default adapter.
:: The event is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent|BluetoothAdapterEvent]] with property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#adapter|adapter]] as the added bluetooth adapter and property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#isDefault|isDefault]] indicating whether the added adapter is default adapter.


; Sample
; Sample
Line 44: Line 44:
; Parameter
; Parameter
: ''aAddressEvent''
: ''aAddressEvent''
:: The event is a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent BluetoothAdapterEvent] with property [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#address address] as the address of removed bluetooth adapter and property [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#isDefault isDefault] indicating whether the removed adapter is default adapter.
:: The event is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent|BluetoothAdapterEvent]] with property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#address|address]] as the address of removed bluetooth adapter and property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#isDefault|isDefault]] indicating whether the removed adapter is default adapter.


; Sample
; Sample
Line 60: Line 60:


== Methods ==
== Methods ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29 BluetoothManager.getAdapters()]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29|BluetoothManager.getAdapters()]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getDefaultAdapter.28.29 BluetoothManager.getDefaultAdapter()]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getDefaultAdapter.28.29|BluetoothManager.getDefaultAdapter()]]


=== getAdapters() ===
=== getAdapters() ===
Line 69: Line 69:


; Return
; Return
: An array of [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter BluetoothAdapter] objects.
: An array of [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]] objects.


; Sample
; Sample
Line 81: Line 81:


; Return
; Return
: The default [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter BluetoothAdapter] object.
: The default [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]] object.


; Sample
; Sample
Line 88: Line 88:


== See also ==
== See also ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter BluetoothAdapter]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]]

Revision as of 01:43, 3 April 2014

Overview

BluetoothManager allows to access all bluetooth adapters available on the device. Adapters are the interfaces that connect to the remote device.

Interface

interface BluetoothManager: EventTarget
{
  attribute EventHandler onadapteradded;
  attribute EventHandler onadapterremoved;

  any              getAdapters(); // array of BluetoothAdapter
  BluetoothAdapter getDefaultAdapter();
};

Event Handlers

onadapteradded

Description
A handler to trigger when a bluetooth adapter is added (i.e., plugged in) to the device.
Parameter
aAdapterEvent
The event is a BluetoothAdapterEvent with property adapter as the added bluetooth adapter and property isDefault indicating whether the added adapter is default adapter.
Sample
function bt_onAdapterAdded(evt) {
  var adapter = evt.adapter;
  var isDefaultAdapter = evt.isDefault;

  if (isDefaultAdapter) {
    // do your things here.
  }
}

var manager = navigator.mozBluetooth;
manager.onadapteradded = bt_onAdapterAdded;

onadapterremoved

Description
A handler to trigger when a bluetooth adapter is removed (i.e., unplugged) from the device.
Parameter
aAddressEvent
The event is a BluetoothAdapterEvent with property address as the address of removed bluetooth adapter and property isDefault indicating whether the removed adapter is default adapter.
Sample
function bt_onAdapterRemoved(evt) {
  var address = evt.address;
  var isDefaultAdapter = evt.isDefault;

  if (isDefaultAdapter) {
    // do your things here.
  }
}

var manager = navigator.mozBluetooth;
manager.onadapterremoved = bt_onAdapterRemoved;

Methods

getAdapters()

Description
The method retrieves all adapters on the device.
Return
An array of BluetoothAdapter objects.
Sample
var manager = navigator.mozBluetooth;
var adapters = manager.getAdapters();

getDefaultAdapter()

Description
The method retrieves the default adapter used to connect to the remote bluetooth devices.
Return
The default BluetoothAdapter object.
Sample
var manager = navigator.mozBluetooth;
var adapter = manager.getDefaultAdapter();

See also