1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth
6 // device. All functions report failures via chrome.runtime.lastError.
8 // Allocation authorities for Vendor IDs.
9 enum VendorIdSource
{bluetooth
, usb
};
11 // Common device types recognized by Chrome.
12 enum DeviceType
{computer
, phone
, modem
, audio
, carAudio
, video
, peripheral
,
13 joystick
, gamepad
, keyboard
, mouse
, tablet
,
16 // Information about the state of the Bluetooth adapter.
17 dictionary AdapterState
{
18 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.
21 // The human-readable name of the adapter.
24 // Indicates whether or not the adapter has power.
27 // Indicates whether or not the adapter is available (i.e. enabled).
30 // Indicates whether or not the adapter is currently discovering.
34 // Callback from the <code>getAdapterState</code> method.
35 // |adapterInfo| : Object containing the adapter information.
36 callback AdapterStateCallback
= void(AdapterState adapterInfo
);
38 // Information about the state of a known Bluetooth device.
40 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'.
43 // The human-readable name of the device.
46 // The class of the device, a bit-field defined by
47 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband.
50 // The Device ID record of the device, where available.
51 VendorIdSource? vendorIdSource
;
56 // The type of the device, if recognized by Chrome. This is obtained from
57 // the |deviceClass| field and only represents a small fraction of the
58 // possible device types. When in doubt you should use the |deviceClass|
62 // Indicates whether or not the device is paired with the system.
65 // Indicates whether the device is currently connected to the system.
68 // UUIDs of protocols, profiles and services advertised by the device.
69 // For classic Bluetooth devices, this list is obtained from EIR data and
70 // SDP tables. For Low Energy devices, this list is obtained from AD and
71 // GATT primary services. For dual mode devices this may be obtained from
75 // The received signal strength, in dBm. This field is avaliable and valid
76 // only during discovery. Outside of discovery it's value is not specified.
79 // The transmitted power level. This field is avaliable only for LE devices
80 // that include this field in AD. It is avaliable and valid only during
85 // Callback from the <code>getDevice</code> method.
86 // |deviceInfo| : Object containing the device information.
87 callback GetDeviceCallback
= void(Device deviceInfo
);
89 // Callback from the <code>getDevices</code> method.
90 // |deviceInfos| : Array of object containing device information.
91 callback GetDevicesCallback
= void(Device
[] deviceInfos
);
93 // Callback from the <code>startDiscovery</code> method.
94 callback StartDiscoveryCallback
= void();
96 // Callback from the <code>stopDiscovery</code> method.
97 callback StopDiscoveryCallback
= void();
99 // These functions all report failures via chrome.runtime.lastError.
100 interface Functions
{
101 // Get information about the Bluetooth adapter.
102 // |callback| : Called with an AdapterState object describing the adapter
104 static
void getAdapterState
(AdapterStateCallback
callback);
106 // Get information about a Bluetooth device known to the system.
107 // |deviceAddress| : Address of device to get.
108 // |callback| : Called with the Device object describing the device.
109 static
void getDevice
(DOMString deviceAddress
, GetDeviceCallback
callback);
111 // Get a list of Bluetooth devices known to the system, including paired
112 // and recently discovered devices.
113 // |callback| : Called when the search is completed.
114 static
void getDevices
(GetDevicesCallback
callback);
116 // Start discovery. Newly discovered devices will be returned via the
117 // onDeviceAdded event. Previously discovered devices already known to
118 // the adapter must be obtained using getDevices and will only be updated
119 // using the |onDeviceChanged| event if information about them changes.
121 // Discovery will fail to start if this application has already called
122 // startDiscovery. Discovery can be resource intensive: stopDiscovery
123 // should be called as soon as possible.
124 // |callback| : Called to indicate success or failure.
125 static
void startDiscovery
(optional StartDiscoveryCallback
callback);
128 // |callback| : Called to indicate success or failure.
129 static
void stopDiscovery
(optional StopDiscoveryCallback
callback);
133 // Fired when the state of the Bluetooth adapter changes.
134 // |state| : The new state of the adapter.
135 static
void onAdapterStateChanged
(AdapterState state
);
137 // Fired when information about a new Bluetooth device is available.
138 static
void onDeviceAdded
(Device device
);
140 // Fired when information about a known Bluetooth device has changed.
141 static
void onDeviceChanged
(Device device
);
143 // Fired when a Bluetooth device that was previously discovered has been
144 // out of range for long enough to be considered unavailable again, and
145 // when a paired device is removed.
146 static
void onDeviceRemoved
(Device device
);