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

no edit summary
No edit summary
Line 19: Line 19:


; Summary
; Summary
: A handler to trigger when a bluetooth adapter becomes enabled on the device.
: A handler to trigger when a Bluetooth adapter becomes enabled on the device.


; Sample Code
; Sample
  var manager = navigator.mozBluetooth;
  var manager = navigator.mozBluetooth;
  manager.onadapteradded = ''funcRef''
  manager.onadapteradded = ''funcRef''
Line 29: Line 29:


; Summary
; Summary
: A handler to trigger when a bluetooth adapter becomes disabled on the device.
: A handler to trigger when a Bluetooth adapter becomes disabled on the device. The disabled BluetoothAdapter object is already unavailable inside the event handler.


; Sample Code
; Sample
  var manager = navigator.mozBluetooth
  var manager = navigator.mozBluetooth;
  manager.onadapterremoved = ''funcRef''
  manager.onadapterremoved = ''funcRef''
: Where ''funcRef'' is a function to be called when a Bluetooth adapter becomes disabled on the device.
: Where ''funcRef'' is a function to be called when a Bluetooth adapter becomes disabled on the device.
Line 46: Line 46:


; Return
; Return
: The array of all BluetoothAdapter objects.
: An array of BluetoothAdapter objects.


; Sample Code
; Sample
  var adapters = navigator.mozBluetooth.getAdapters();
  var manager = navigator.mozBluetooth;
var adapter = manager.getAdapters();
 
; // TODO
* What would happen if 0 is unplugged and another dongle is plugged?
* Does the array keeps BluetoothAdapter with state 'disabled'?


=== getDefaultAdapter() ===
=== getDefaultAdapter() ===


; Summary
; Summary
: The <tt>getDefaultAdapter</tt> method is used to retrieve the default adapter object used to connect the device to third-party Bluetooth devices.
: The <tt>getDefaultAdapter</tt> method is used to retrieve the default adapter used to connect the device to third-party Bluetooth devices.


; Return
; Return
: The default BluetoothAdapter object.
: The default BluetoothAdapter object.


; Sample Code
; Sample
  var adapter = navigator.mozBluetooth.getDefaultAdapter();
  var manager = navigator.mozBluetooth;
var adapter = manager.getDefaultAdapter();
 
; // TODO
* How do we know defaultAdapter has been changed?


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

edits