OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth | 5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth |
6 // device. All functions report failures via chrome.runtime.lastError. | 6 // device. All functions report failures via chrome.runtime.lastError. |
7 namespace bluetooth { | 7 namespace bluetooth { |
8 // Information about the state of the bluetooth adapater. | |
miket_OOO
2014/03/28 20:48:43
adapter
rpaquay
2014/03/31 15:39:19
Done.
| |
8 dictionary AdapterState { | 9 dictionary AdapterState { |
9 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. | 10 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. |
10 DOMString address; | 11 DOMString address; |
11 | 12 |
12 // The human-readable name of the adapter. | 13 // The human-readable name of the adapter. |
13 DOMString name; | 14 DOMString name; |
14 | 15 |
15 // Indicates whether or not the adapter has power. | 16 // Indicates whether or not the adapter has power. |
16 boolean powered; | 17 boolean powered; |
17 | 18 |
18 // Indicates whether or not the adapter is available (i.e. enabled). | 19 // Indicates whether or not the adapter is available (i.e. enabled). |
19 boolean available; | 20 boolean available; |
20 | 21 |
21 // Indicates whether or not the adapter is currently discovering. | 22 // Indicates whether or not the adapter is currently discovering. |
22 boolean discovering; | 23 boolean discovering; |
23 }; | 24 }; |
24 | 25 |
26 // Information about the state of a known bluetooth device. | |
25 dictionary Device { | 27 dictionary Device { |
26 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | 28 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
27 DOMString address; | 29 DOMString address; |
28 | 30 |
29 // The human-readable name of the device. | 31 // The human-readable name of the device. |
30 DOMString? name; | 32 DOMString? name; |
31 | 33 |
32 // Indicates whether or not the device is paired with the system. | 34 // Indicates whether or not the device is paired with the system. |
33 boolean? paired; | 35 boolean? paired; |
34 | 36 |
35 // Indicates whether the device is currently connected to the system. | 37 // Indicates whether the device is currently connected to the system. |
36 boolean? connected; | 38 boolean? connected; |
37 }; | 39 }; |
38 | 40 |
41 // Information about a bluetooth profile -- or service. | |
keybuk
2014/03/14 17:58:07
Bluetooth profile/service terminology isn't quite
rpaquay
2014/03/14 18:27:50
Ok, so stick with "profile" term only?
keybuk
2014/03/14 19:47:06
Yeah, and hope to get rid of that term as well
rpaquay
2014/03/14 20:30:56
OK, I'll change this comment and remove "service".
rpaquay
2014/03/20 00:48:18
Done.
| |
39 dictionary Profile { | 42 dictionary Profile { |
40 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB | 43 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB |
41 DOMString uuid; | 44 DOMString uuid; |
42 | 45 |
43 // Human-readable name of the Profile, e.g. "Health Device" | 46 // Human-readable name of the Profile, e.g. "Health Device" |
44 DOMString? name; | 47 DOMString? name; |
45 | 48 |
46 // The RFCOMM channel id, used when the profile is to be exported to remote | 49 // The RFCOMM channel id, used when the profile is to be exported to remote |
47 // devices. | 50 // devices. |
48 long? channel; | 51 long? channel; |
49 | 52 |
50 // The LS2CAP PSM number, used when the profile is to be exported to remote | 53 // The LS2CAP PSM number, used when the profile is to be exported to remote |
51 // deviecs. | 54 // devices. |
52 long? psm; | 55 long? psm; |
53 | 56 |
54 // Specifies whether pairing (and encryption) is required to be able to | 57 // Specifies whether pairing (and encryption) is required to be able to |
55 // connect. | 58 // connect. |
56 boolean? requireAuthentication; | 59 boolean? requireAuthentication; |
57 | 60 |
58 // Specifies whether user authorization is required to be able to connect. | 61 // Specifies whether user authorization is required to be able to connect. |
59 boolean? requireAuthorization; | 62 boolean? requireAuthorization; |
60 | 63 |
61 // Specifies whether this profile will be automatically connected if any | 64 // Specifies whether this profile will be automatically connected if any |
62 // other profile of device also exporting this profile connects to the host. | 65 // other profile of device also exporting this profile connects to the host. |
63 boolean? autoConnect; | 66 boolean? autoConnect; |
64 | 67 |
65 // Specifies the implemented version of the profile. | 68 // Specifies the implemented version of the profile. |
66 long? version; | 69 long? version; |
67 | 70 |
68 // Specifies the profile-specific bit field of features the implementation | 71 // Specifies the profile-specific bit field of features the implementation |
69 // supports. | 72 // supports. |
70 long? features; | 73 long? features; |
71 }; | 74 }; |
72 | 75 |
73 dictionary ServiceRecord { | 76 // The socket properties specified in the $ref:update function. Each property |
74 // The name of the service. | 77 // is optional. If a property value is not specified, the existing value if |
75 DOMString name; | 78 // preserved when calling $ref:update. |
79 dictionary SocketProperties { | |
80 // Flag indicating if the socket is left open when the event page of the | |
81 // application is unloaded (see <a | |
82 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App | |
83 // Lifecycle</a>). The default value is "false." When the application is | |
84 // loaded, any sockets previously opened with persistent=true can be fetched | |
85 // with $ref:getSockets. | |
86 boolean? persistent; | |
76 | 87 |
77 // The UUID of the service. | 88 // An application-defined string associated with the socket. |
78 DOMString? uuid; | 89 DOMString? name; |
90 | |
91 // The size of the buffer used to receive data. The default value is 4096. | |
92 long? bufferSize; | |
79 }; | 93 }; |
80 | 94 |
81 dictionary Socket { | 95 dictionary Socket { |
96 // The socket identifier. | |
97 long id; | |
98 | |
82 // The remote Bluetooth device associated with this socket. | 99 // The remote Bluetooth device associated with this socket. |
83 Device device; | 100 Device device; |
84 | 101 |
85 // The remote Bluetooth profile associated with this socket. | 102 // The remote Bluetooth profile associated with this socket. |
86 Profile profile; | 103 Profile profile; |
87 | 104 |
88 // An identifier for this socket that should be used with the | 105 // Flag indicating whether the socket is left open when the application is |
89 // read/write/disconnect methods. | 106 // suspended (see <code>SocketProperties.persistent</code>). |
90 long id; | 107 boolean persistent; |
108 | |
109 // Application-defined string associated with the socket. | |
110 DOMString? name; | |
111 | |
112 // The size of the buffer used to receive data. If no buffer size has been | |
113 // specified explictly, the value is not provided. | |
114 long? bufferSize; | |
115 | |
116 // Flag indicating whether a connected socket blocks its peer from sending | |
117 // more data (see <code>setPaused</code>). | |
118 boolean paused; | |
91 }; | 119 }; |
92 | 120 |
93 dictionary OutOfBandPairingData { | 121 dictionary OutOfBandPairingData { |
94 // Simple Pairing Hash C. | 122 // Simple Pairing Hash C. |
95 // Always 16 octets long. | 123 // Always 16 octets long. |
96 ArrayBuffer hash; | 124 ArrayBuffer hash; |
97 | 125 |
98 // Simple Pairing Randomizer R. | 126 // Simple Pairing Randomizer R. |
99 // Always 16 octets long. | 127 // Always 16 octets long. |
100 ArrayBuffer randomizer; | 128 ArrayBuffer randomizer; |
101 }; | 129 }; |
102 | 130 |
103 callback AdapterStateCallback = void(AdapterState result); | 131 callback AdapterStateCallback = void(AdapterState result); |
104 callback AddressCallback = void (DOMString result); | 132 callback AddressCallback = void (DOMString result); |
105 callback BooleanCallback = void (boolean result); | 133 callback BooleanCallback = void (boolean result); |
106 callback DataCallback = void (optional ArrayBuffer result); | |
107 callback DevicesCallback = void (Device[] result); | 134 callback DevicesCallback = void (Device[] result); |
108 callback NameCallback = void (DOMString result); | |
109 callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data); | 135 callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data); |
110 callback ProfilesCallback = void(Profile[] result); | 136 callback ProfilesCallback = void(Profile[] result); |
111 callback ResultCallback = void (); | 137 callback ResultCallback = void (); |
112 callback ServicesCallback = void(ServiceRecord[] result); | |
113 callback SizeCallback = void (long result); | 138 callback SizeCallback = void (long result); |
114 callback SocketCallback = void (Socket result); | |
115 | 139 |
116 // Options for the getProfiles function. | 140 // Options for the getProfiles function. |
117 dictionary GetProfilesOptions { | 141 dictionary GetProfilesOptions { |
118 // The remote Bluetooth device to retrieve the exported profiles list from. | 142 // The remote Bluetooth device to retrieve the exported profiles list from. |
119 Device device; | 143 Device device; |
120 }; | 144 }; |
121 | 145 |
122 // Options for the getServices function. | |
123 dictionary GetServicesOptions { | |
124 // The address of the device to inquire about. |deviceAddress| should be | |
125 // in the format 'XX:XX:XX:XX:XX:XX'. | |
126 DOMString deviceAddress; | |
127 }; | |
128 | |
129 // Options for the connect function. | 146 // Options for the connect function. |
130 dictionary ConnectOptions { | 147 dictionary ConnectOptions { |
131 // The connection is made to |device|. | 148 // The connection is made to |device|. |
132 Device device; | 149 Device device; |
133 | 150 |
134 // The connection is made to |profile|. | 151 // The connection is made to |profile|. |
135 Profile profile; | 152 Profile profile; |
136 }; | 153 }; |
137 | 154 |
138 // Options for the disconnect function. | 155 // Options for the disconnect function. |
139 dictionary DisconnectOptions { | 156 dictionary DisconnectOptions { |
140 // The socket to disconnect. | 157 // The socket identifier. |
141 Socket socket; | 158 long socketId; |
142 }; | 159 }; |
143 | 160 |
144 // Options for the read function. | 161 // Options for the $ref:send function. |
145 dictionary ReadOptions { | 162 dictionary SendOptions { |
146 // The socket to read from. | 163 // The socket identifier. |
147 Socket socket; | 164 long socketId; |
148 }; | |
149 | 165 |
150 // Options for the write function. | 166 // The data to send. |
151 dictionary WriteOptions { | |
152 // The socket to write to. | |
153 Socket socket; | |
154 | |
155 // The data to write. | |
156 ArrayBuffer data; | 167 ArrayBuffer data; |
157 }; | 168 }; |
158 | 169 |
159 // Options for the setOutOfBandPairingData function. | 170 // Options for the setOutOfBandPairingData function. |
160 dictionary SetOutOfBandPairingDataOptions { | 171 dictionary SetOutOfBandPairingDataOptions { |
161 // The address of the remote device that the data should be associated | 172 // The address of the remote device that the data should be associated |
162 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. | 173 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. |
163 DOMString address; | 174 DOMString address; |
164 | 175 |
165 // The Out Of Band Pairing Data. If this is omitted, the data for the | 176 // The Out Of Band Pairing Data. If this is omitted, the data for the |
166 // device is cleared instead. | 177 // device is cleared instead. |
167 OutOfBandPairingData? data; | 178 OutOfBandPairingData? data; |
168 }; | 179 }; |
169 | 180 |
181 // Callback from the <code>getSocket</code> method. | |
182 // |socket| : Object containing the socket information. | |
183 callback GetSocketCallback = void (Socket socket); | |
184 | |
185 // Callback from the <code>getSockets</code> method. | |
186 // |sockets| : Array of object containing socket information. | |
187 callback GetSocketsCallback = void (Socket[] sockets); | |
188 | |
189 // Data from an <code>onReceive</code> event. | |
190 dictionary ReceiveInfo { | |
191 // The socket identifier. | |
192 long socketId; | |
193 | |
194 // The data received, with a maxium size of <code>bufferSize</code>. | |
195 ArrayBuffer data; | |
196 }; | |
197 | |
198 enum ReceiveError { | |
199 // The connection was disconnected. | |
200 disconnected, | |
201 | |
202 // A system error occurred and the connection may be unrecoverable. | |
203 system_error | |
204 }; | |
205 | |
206 // Data from an <code>onReceiveError</code> event. | |
207 dictionary ReceiveErrorInfo { | |
208 // The socket identifier. | |
209 long socketId; | |
210 | |
211 // The error message. | |
212 DOMString errorMessage; | |
213 | |
214 // An error code indicating what went wrong. | |
215 ReceiveError error; | |
216 }; | |
217 | |
170 // These functions all report failures via chrome.runtime.lastError. | 218 // These functions all report failures via chrome.runtime.lastError. |
171 interface Functions { | 219 interface Functions { |
172 // Registers the JavaScript application as an implementation for the given | |
173 // Profile; if a channel or PSM is specified, the profile will be exported | |
174 // in the host's SDP and GATT tables and advertised to other devices. | |
175 static void addProfile(Profile profile, ResultCallback callback); | |
176 | |
177 // Unregisters the JavaScript application as an implementation for the given | |
178 // Profile; only the uuid field of the Profile object is used. | |
179 static void removeProfile(Profile profile, ResultCallback callback); | |
180 | |
181 // Get information about the Bluetooth adapter. | 220 // Get information about the Bluetooth adapter. |
182 // |callback| : Called with an AdapterState object describing the adapter | 221 // |callback| : Called with an AdapterState object describing the adapter |
183 // state. | 222 // state. |
184 static void getAdapterState(AdapterStateCallback callback); | 223 static void getAdapterState(AdapterStateCallback callback); |
185 | 224 |
186 // Get a list of Bluetooth devices known to the system, including paired | 225 // Get a list of Bluetooth devices known to the system, including paired |
187 // and recently discovered devices. | 226 // and recently discovered devices. |
188 // |callback| : Called when the search is completed. | 227 // |callback| : Called when the search is completed. |
189 static void getDevices(DevicesCallback callback); | 228 static void getDevices(DevicesCallback callback); |
190 | 229 |
230 // Registers the JavaScript application as an implementation for the given | |
231 // Profile; if a channel or PSM is specified, the profile will be exported | |
232 // in the host's SDP and GATT tables and advertised to other devices. | |
233 static void addProfile(Profile profile, ResultCallback callback); | |
234 | |
235 // Unregisters the JavaScript application as an implementation for the given | |
236 // Profile; only the uuid field of the Profile object is used. | |
237 static void removeProfile(Profile profile, ResultCallback callback); | |
238 | |
191 // Returns the set of exported profiles for the device specified in options. | 239 // Returns the set of exported profiles for the device specified in options. |
192 // This function will not initiate a connection to the remote device. | 240 // This function will not initiate a connection to the remote device. |
193 static void getProfiles(GetProfilesOptions options, | 241 static void getProfiles(GetProfilesOptions options, |
194 ProfilesCallback callback); | 242 ProfilesCallback callback); |
195 | 243 |
196 // Get a list of services provided by a device. | 244 // Connects to a profile on a device. |
197 static void getServices(GetServicesOptions options, | |
198 ServicesCallback callback); | |
199 | |
200 // Connect to a service on a device. | |
201 // |options| : The options for the connection. | 245 // |options| : The options for the connection. |
202 // |callback| : Called to indicate success or failure. | 246 // |callback| : Called to indicate success or failure. |
203 static void connect(ConnectOptions options, | 247 static void connect(ConnectOptions options, |
204 ResultCallback callback); | 248 ResultCallback callback); |
205 | 249 |
206 // Close a Bluetooth connection. | 250 // Closes a Bluetooth connection. |
207 // |options| : The options for this function. | 251 // |options| : The options for this function. |
208 // |callback| : Called to indicate success or failure. | 252 // |callback| : Called to indicate success or failure. |
209 static void disconnect(DisconnectOptions options, | 253 static void disconnect(DisconnectOptions options, |
210 optional ResultCallback callback); | 254 optional ResultCallback callback); |
211 | 255 |
212 // Read data from a Bluetooth connection. The |callback| will be called | 256 // Sends data to a Bluetooth connection. |
213 // with the current data in the buffer even if it is empty. This function | |
214 // should be polled to read incoming data. | |
215 // |options| : The options for this function. | 257 // |options| : The options for this function. |
216 // |callback| : Called with the data read from the socket buffer. | 258 // |callback| : Called with the number of bytes sent. |
217 static void read(ReadOptions options, | 259 static void send(SendOptions options, |
218 DataCallback callback); | 260 optional SizeCallback callback); |
keybuk
2014/03/14 17:58:07
The chrome.sockets.tcp.send() method takes the soc
rpaquay
2014/03/14 18:27:50
I had a chat with Kalman@ about that. We are betwe
keybuk
2014/03/14 19:47:06
I would prefer the Bluetooth API moved towards get
rpaquay
2014/03/14 20:30:56
Agreed: crbug/352775
| |
219 | 261 |
220 // Write data to a Bluetooth connection. | 262 // Updates the socket properties. |
221 // |options| : The options for this function. | 263 // |socketId| : The socket identifier. |
222 // |callback| : Called with the number of bytes written. | 264 // |properties| : The properties to update. |
223 static void write(WriteOptions options, | 265 // |callback| : Called when the properties are updated. |
224 optional SizeCallback callback); | 266 static void updateSocket(long socketId, |
267 SocketProperties properties, | |
268 optional ResultCallback callback); | |
269 | |
270 // Enables or disables the application from receiving messages from its | |
271 // peer. The default value is "false". Pausing a socket is typically used by | |
272 // an application to throttle data sent by its peer. When a socket is | |
273 // paused, no $ref:onReceive event is raised. When a socket is connected and | |
274 // un-paused, $ref:onReceive events are raised again when messages are | |
275 // received. | |
276 static void setSocketPaused(long socketId, | |
277 boolean paused, | |
278 optional ResultCallback callback); | |
279 | |
280 // Retrieves the state of the given socket. | |
281 // |socketId| : The socket identifier. | |
282 // |callback| : Called when the socket state is available. | |
283 static void getSocket(long socketId, | |
284 GetSocketCallback callback); | |
285 | |
286 // Retrieves the list of currently opened sockets owned by the application. | |
287 // |callback| : Called when the list of sockets is available. | |
288 static void getSockets(GetSocketsCallback callback); | |
225 | 289 |
226 // Get the local Out of Band Pairing data. | 290 // Get the local Out of Band Pairing data. |
227 // |callback| : Called with the data. | 291 // |callback| : Called with the data. |
228 static void getLocalOutOfBandPairingData( | 292 static void getLocalOutOfBandPairingData( |
229 OutOfBandPairingDataCallback callback); | 293 OutOfBandPairingDataCallback callback); |
230 | 294 |
231 // Set the Out of Band Pairing data for a remote device. | 295 // Set the Out of Band Pairing data for a remote device. |
232 // Any previous Out Of Band Pairing Data for this device is overwritten. | 296 // Any previous Out Of Band Pairing Data for this device is overwritten. |
233 // |options| : The options for this function. | 297 // |options| : The options for this function. |
234 // |callback| : Called to indicate success or failure. | 298 // |callback| : Called to indicate success or failure. |
(...skipping 30 matching lines...) Expand all Loading... | |
265 static void onDeviceChanged(Device device); | 329 static void onDeviceChanged(Device device); |
266 | 330 |
267 // Fired when a Bluetooth device that was previously discovered has been | 331 // Fired when a Bluetooth device that was previously discovered has been |
268 // out of range for long enough to be considered unavailable again, and | 332 // out of range for long enough to be considered unavailable again, and |
269 // when a paired device is removed. | 333 // when a paired device is removed. |
270 static void onDeviceRemoved(Device device); | 334 static void onDeviceRemoved(Device device); |
271 | 335 |
272 // Fired when a connection has been made for a registered profile. | 336 // Fired when a connection has been made for a registered profile. |
273 // |socket| : The socket for the connection. | 337 // |socket| : The socket for the connection. |
274 static void onConnection(Socket socket); | 338 static void onConnection(Socket socket); |
339 | |
340 // Event raised when data has been received for a given socket. | |
341 // |info| : The event data. | |
342 static void onReceive(ReceiveInfo info); | |
343 | |
344 // Event raised when a network error occured while the runtime was waiting | |
345 // for data on the socket. Once this event is raised, the socket is set to | |
346 // <code>paused</code> and no more <code>onReceive</code> events are raised | |
347 // for this socket. | |
348 // |info| : The event data. | |
349 static void onReceiveError(ReceiveErrorInfo info); | |
275 }; | 350 }; |
276 }; | 351 }; |
OLD | NEW |