chrome.bluetooth
Description: |
Use the chrome.bluetooth API to connect to a Bluetooth
device. All functions report failures via chrome.runtime.lastError.
|
Availability: |
Dev channel only.
|
Manifest: |
"bluetooth": {...}
|
Learn More: |
Bluetooth
|
Summary
Types | |
---|---|
AdapterState | |
Device | |
Profile | |
ServiceRecord | |
Socket | |
OutOfBandPairingData | |
Methods | |
addProfile −
chrome.bluetooth.addProfile( Profile profile, function callback)
| |
removeProfile −
chrome.bluetooth.removeProfile( Profile profile, function callback)
| |
getAdapterState −
chrome.bluetooth.getAdapterState(function callback)
| |
getDevices −
chrome.bluetooth.getDevices(function callback)
| |
getDevice −
chrome.bluetooth.getDevice(string deviceAddress, function callback)
| |
connect −
chrome.bluetooth.connect(object options, function callback)
| |
disconnect −
chrome.bluetooth.disconnect(object options, function callback)
| |
read −
chrome.bluetooth.read(object options, function callback)
| |
write −
chrome.bluetooth.write(object options, function callback)
| |
getLocalOutOfBandPairingData −
chrome.bluetooth.getLocalOutOfBandPairingData(function callback)
| |
setOutOfBandPairingData −
chrome.bluetooth.setOutOfBandPairingData(object options, function callback)
| |
startDiscovery −
chrome.bluetooth.startDiscovery(function callback)
| |
stopDiscovery −
chrome.bluetooth.stopDiscovery(function callback)
| |
Events | |
onAdapterStateChanged | |
onDeviceAdded | |
onDeviceChanged | |
onDeviceRemoved | |
onConnection |
Types
AdapterState
properties | ||
---|---|---|
string | address | The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. |
string | name | The human-readable name of the adapter. |
boolean | powered | Indicates whether or not the adapter has power. |
boolean | available | Indicates whether or not the adapter is available (i.e. enabled). |
boolean | discovering | Indicates whether or not the adapter is currently discovering. |
Device
properties | ||
---|---|---|
string | address | The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
string | (optional) name | The human-readable name of the device. |
integer | (optional) deviceClass | The class of the device, a bit-field defined by http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. |
enum of "bluetooth" , or "usb" |
(optional) vendorIdSource | The Device ID record of the device, where available. |
integer | (optional) vendorId | |
integer | (optional) productId | |
integer | (optional) deviceId | |
enum of "computer" , "phone" , "modem" , "audio" , "carAudio" , "video" , "peripheral" , "joystick" , "gamepad" , "keyboard" , "mouse" , "tablet" , or "keyboardMouseCombo" |
(optional) type | The type of the device, if recognized by Chrome. This is obtained from the |deviceClass| field and only represents a small fraction of the possible device types. When in doubt you should use the |deviceClass| field directly. |
boolean | (optional) paired | Indicates whether or not the device is paired with the system. |
boolean | (optional) connected | Indicates whether the device is currently connected to the system. |
array of string | (optional) uuids | UUIDs of protocols, profiles and services advertised by the device. For classic Bluetooth devices, this list is obtained from EIR data and SDP tables. For Low Energy devices, this list is obtained from AD and GATT primary services. For dual mode devices this may be obtained from both. |
Profile
properties | ||
---|---|---|
string | uuid | Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB |
string | (optional) name | Human-readable name of the Profile, e.g. "Health Device" |
integer | (optional) channel | The RFCOMM channel id, used when the profile is to be exported to remote devices. |
integer | (optional) psm | The LS2CAP PSM number, used when the profile is to be exported to remote deviecs. |
boolean | (optional) requireAuthentication | Specifies whether pairing (and encryption) is required to be able to connect. |
boolean | (optional) requireAuthorization | Specifies whether user authorization is required to be able to connect. |
boolean | (optional) autoConnect | Specifies whether this profile will be automatically connected if any other profile of device also exporting this profile connects to the host. |
integer | (optional) version | Specifies the implemented version of the profile. |
integer | (optional) features | Specifies the profile-specific bit field of features the implementation supports. |
ServiceRecord
properties | ||
---|---|---|
string | name | The name of the service. |
string | (optional) uuid | The UUID of the service. |
Socket
properties | ||
---|---|---|
Device | device | The remote Bluetooth device associated with this socket. |
Profile | profile | The remote Bluetooth profile associated with this socket. |
integer | id | An identifier for this socket that should be used with the read/write/disconnect methods. |
OutOfBandPairingData
properties | ||
---|---|---|
ArrayBuffer | hash | Simple Pairing Hash C. Always 16 octets long. |
ArrayBuffer | randomizer | Simple Pairing Randomizer R. Always 16 octets long. |
Methods
addProfile
chrome.bluetooth.addProfile( Profile profile, function callback)
Registers the JavaScript application as an implementation for the given Profile; if a channel or PSM is specified, the profile will be exported in the host's SDP and GATT tables and advertised to other devices.
Parameters | ||
---|---|---|
Profile | profile | |
function | callback |
The callback parameter should be a function that looks like this: function() {...};
|
removeProfile
chrome.bluetooth.removeProfile( Profile profile, function callback)
Unregisters the JavaScript application as an implementation for the given Profile; only the uuid field of the Profile object is used.
Parameters | ||
---|---|---|
Profile | profile | |
function | callback |
The callback parameter should be a function that looks like this: function() {...};
|
getAdapterState
chrome.bluetooth.getAdapterState(function callback)
Get information about the Bluetooth adapter.
Parameters | |||||
---|---|---|---|---|---|
function | callback |
Called with an AdapterState object describing the adapter state.
The callback parameter should be a function that looks like this: function( AdapterState result) {...};
|
getDevices
chrome.bluetooth.getDevices(function callback)
getDevice
chrome.bluetooth.getDevice(string deviceAddress, function callback)
Get information about a Bluetooth device known to the system.
Parameters | |||||
---|---|---|---|---|---|
string | deviceAddress | Address of device to get. | |||
function | callback |
Called with the Device object describing the device.
The callback parameter should be a function that looks like this: function( Device result) {...};
|
connect
chrome.bluetooth.connect(object options, function callback)
Connect to a service on a device.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | options |
The options for the connection.
|
||||||
function | callback |
Called to indicate success or failure.
The callback parameter should be a function that looks like this: function() {...};
|
disconnect
chrome.bluetooth.disconnect(object options, function callback)
Close a Bluetooth connection.
Parameters | |||||
---|---|---|---|---|---|
object | options |
The options for this function.
|
|||
function | (optional) callback |
Called to indicate success or failure.
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
read
chrome.bluetooth.read(object options, function callback)
Read data from a Bluetooth connection. The |callback| will be called with the current data in the buffer even if it is empty. This function should be polled to read incoming data.
Parameters | |||||
---|---|---|---|---|---|
object | options |
The options for this function.
|
|||
function | callback |
Called with the data read from the socket buffer.
The callback parameter should be a function that looks like this: function(ArrayBuffer result) {...};
|
write
chrome.bluetooth.write(object options, function callback)
Write data to a Bluetooth connection.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | options |
The options for this function.
|
||||||
function | (optional) callback |
Called with the number of bytes written.
If you specify the callback parameter, it should be a function that looks like this: function(integer result) {...};
|
getLocalOutOfBandPairingData
chrome.bluetooth.getLocalOutOfBandPairingData(function callback)
Get the local Out of Band Pairing data.
Parameters | |||||
---|---|---|---|---|---|
function | callback |
Called with the data.
The callback parameter should be a function that looks like this: function( OutOfBandPairingData data) {...};
|
setOutOfBandPairingData
chrome.bluetooth.setOutOfBandPairingData(object options, function callback)
Set the Out of Band Pairing data for a remote device. Any previous Out Of Band Pairing Data for this device is overwritten.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | options |
The options for this function.
|
||||||
function | (optional) callback |
Called to indicate success or failure.
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
startDiscovery
chrome.bluetooth.startDiscovery(function callback)
Start discovery. Newly discovered devices will be returned via the onDeviceAdded event. Previously discovered devices already known to the adapter must be obtained using getDevices and will only be updated using the |onDeviceChanged| event if information about them changes.
Discovery will fail to start if this application has already called startDiscovery. Discovery can be resource intensive: stopDiscovery should be called as soon as possible.
Parameters | ||
---|---|---|
function | (optional) callback |
Called to indicate success or failure.
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
stopDiscovery
chrome.bluetooth.stopDiscovery(function callback)
Stop discovery.
Parameters | ||
---|---|---|
function | (optional) callback |
Called to indicate success or failure.
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
Events
onAdapterStateChanged
Fired when the state of the Bluetooth adapter changes.
addListener
chrome.bluetooth.onAdapterStateChanged.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function( AdapterState state) {...};
|
onDeviceAdded
onDeviceChanged
onDeviceRemoved
Fired when a Bluetooth device that was previously discovered has been out of range for long enough to be considered unavailable again, and when a paired device is removed.
onConnection
Fired when a connection has been made for a registered profile.