Confirmed users
891
edits
No edit summary |
|||
| Line 3: | Line 3: | ||
== Interface == | == Interface == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#BluetoothManager|BluetoothManager]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#BluetoothManagerAttribute|BluetoothManagerAttribute]] | |||
=== BluetoothManager === | |||
[Func="Navigator::HasBluetoothSupport"] | |||
interface BluetoothManager: EventTarget | interface BluetoothManager: EventTarget | ||
{ | { | ||
readonly attribute | readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]] defaultAdapter; | ||
attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onattributechanged|onattributechanged]]; | attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onattributechanged|onattributechanged]]; | ||
attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|onadapteradded]]; | attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|onadapteradded]]; | ||
attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|onadapterremoved]]; | attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|onadapterremoved]]; | ||
sequence<BluetoothAdapter> | sequence<BluetoothAdapter> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29|getAdapters()]]; | ||
}; | }; | ||
=== BluetoothManagerAttribute === | |||
enum BluetoothManagerAttribute | |||
{ | |||
"defaultAdapter" | |||
} | |||
== Properties == | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#defaultAdapter|BluetoothManager.defaultAdapter]] | |||
=== defaultAdapter === | |||
; Description | |||
: The default adapter used to connect to the remote bluetooth devices. | |||
; Value type | |||
: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter#BluetoothAdapter|BluetoothAdapter]] | |||
; Default value | |||
: Null pointer if no adapter exists. | |||
; Sample | |||
var defaultAdapter = navigator.mozBluetooth.defaultAdapter; | |||
== Event Handlers == | == Event Handlers == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onattributechanged|BluetoothManager.onattributechanged]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|BluetoothManager.onadapteradded]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapteradded|BluetoothManager.onadapteradded]] | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|BluetoothManager.onadapterremoved]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onadapterremoved|BluetoothManager.onadapterremoved]] | ||
=== onattributechanged === | |||
; Description | |||
: A handler to trigger when bluetooth manager's only property (defaultAdapter) has changed. | |||
; Parameter | |||
: ''aAttributeEvent'' | |||
:: The event is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent|BluetoothAttributeEvent]] with property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent#attr|attr]] as a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#BluetoothManagerAttribute|BluetoothManagerAttribute]]. | |||
; Sample | |||
manager.onattributechanged = function onManagerAttributeChanged(evt) { | |||
var attr = evt.attr; | |||
var value = evt.value; | |||
switch (attr) { | |||
case BluetoothManagerAttribute.defaultAdapter: | |||
console.log("defaultAdapter changed. address:", value.address); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
=== onadapteradded === | === onadapteradded === | ||
; Description | ; Description | ||
: A handler to trigger when a bluetooth adapter is added (i.e., plugged in) to the device. | : A handler to trigger when a bluetooth adapter is added (i.e., plugged in) to the device. | ||
| Line 25: | Line 74: | ||
; Parameter | ; Parameter | ||
: ''aAdapterEvent'' | : ''aAdapterEvent'' | ||
:: The event is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent|BluetoothAdapterEvent]] with property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapterEvent#adapter|adapter]] as the added bluetooth 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. If the added adapter becomes default adapter, [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onattributechanged|onattributechanged]] would also be triggered to reflect the change of property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#defaultAdapter|defaultAdapter]]. | ||
; Sample | ; Sample | ||
function | manager.onadapteradded = function onAdapterAdded(evt) { | ||
var adapter = evt.adapter; | var adapter = evt.adapter; | ||
// do your things here. | |||
} | } | ||
=== onadapterremoved === | === onadapterremoved === | ||
| Line 46: | Line 88: | ||
; Parameter | ; Parameter | ||
: ''aAddressEvent'' | : ''aAddressEvent'' | ||
:: 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 | :: 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. If the removed adapter is default adapter, [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#onattributechanged|onattributechanged]] would also be triggered to reflect the change of property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#defaultAdapter|defaultAdapter]]. | ||
; Sample | ; Sample | ||
function | manager.onadapterremoved = function onAdapterRemoved(evt) { | ||
var address = evt.address; | var address = evt.address; | ||
// do your things here. | |||
} | } | ||
== Methods == | == Methods == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29|BluetoothManager.getAdapters()]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothManager#getAdapters.28.29|BluetoothManager.getAdapters()]] | ||
=== getAdapters() === | === getAdapters() === | ||
; Description | ; Description | ||
: The method | : The method returns an array representing a snapshot of current adapters list on the device. Each getAdapters() call returns a new array instead of a reference to current adapters list, in order to prevent applications from modifying the shared adapters list. | ||
; Return | ; Return | ||
: | : Sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]]> | ||
; Sample | ; Sample | ||
var | var adapters = navigator.mozBluetooth.getAdapters(); | ||
for (var i = 0; i < adapters.length; i++) { | |||
console.log("adapter", i, "address", adapter[i].address); | |||
} | |||
; | |||
; | |||
; | |||