OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * Javascript for AdapterBroker, served from | 6 * Javascript for AdapterBroker, served from |
7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
8 */ | 8 */ |
9 cr.define('adapter_broker', function() { | 9 cr.define('adapter_broker', function() { |
10 /** | 10 /** |
11 * The proxy class of an adapter and router of adapter events. | 11 * The proxy class of an adapter and router of adapter events. |
12 * Exposes an EventTarget interface that allows other object to subscribe to | 12 * Exposes an EventTarget interface that allows other object to subscribe to |
13 * to specific AdapterClient events. | 13 * to specific AdapterClient events. |
14 * Provides proxy access to Adapter functions. Converts parameters to Mojo | 14 * Provides proxy access to Adapter functions. Converts parameters to Mojo |
15 * handles and back when necessary. | 15 * handles and back when necessary. |
16 * @constructor | 16 * @constructor |
17 * @extends {cr.EventTarget} | 17 * @extends {cr.EventTarget} |
18 * @param {!interfaces.BluetoothAdapter.Adapter.proxyClass} adapter | 18 * @param {!interfaces.BluetoothAdapter.Adapter.proxyClass} adapter |
19 */ | 19 */ |
20 var AdapterBroker = function(adapter) { | 20 var AdapterBroker = function(adapter) { |
21 this.adapter_ = adapter; | 21 this.adapter_ = adapter; |
22 this.adapterClient_ = new AdapterClient(this); | 22 this.adapterClient_ = new AdapterClient(this); |
23 this.setClient(this.adapterClient_); | 23 this.setClient(this.adapterClient_); |
24 }; | 24 }; |
25 | 25 |
26 AdapterBroker.prototype = { | 26 AdapterBroker.prototype = { |
27 __proto__: cr.EventTarget.prototype, | 27 __proto__: cr.EventTarget.prototype, |
28 | 28 |
29 /** | 29 /** |
30 * Creates a GATT connection to the device with |address|. | |
31 * @param {string} address | |
32 * @return {Promise<interfaces.BluetoothDevice.Device.proxyClass>} | |
33 */ | |
34 connectToDevice: function(address) { | |
35 return this.adapter_.connectToDevice(address).then(function(response) { | |
36 if (response.result != | |
37 interfaces.BluetoothAdapter.ConnectResult.SUCCESS) { | |
38 // TODO(crbug.com/663394): Replace with more descriptive error | |
39 // messages. | |
40 var errorString = Object.keys( | |
41 interfaces.BluetoothAdapter.ConnectResult)[response.result]; | |
42 | |
43 throw new Error(errorString); | |
44 } | |
45 | |
46 response.device = interfaces.Connection.bindHandleToProxy( | |
47 response.device, | |
48 interfaces.BluetoothDevice.Device); | |
49 return response; | |
ortuno
2016/11/09 03:24:03
Why not return just the device?
mbrunson
2016/11/09 23:39:37
Done.
| |
50 }); | |
51 }, | |
52 | |
53 /** | |
30 * Sets client of Adapter service. | 54 * Sets client of Adapter service. |
31 * @param {interfaces.BluetoothAdapter.AdapterClient} adapterClient | 55 * @param {interfaces.BluetoothAdapter.AdapterClient} adapterClient |
32 */ | 56 */ |
33 setClient: function(adapterClient) { | 57 setClient: function(adapterClient) { |
34 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( | 58 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( |
35 adapterClient)); | 59 adapterClient)); |
36 }, | 60 }, |
37 | 61 |
38 /** | 62 /** |
39 * Gets an array of currently detectable devices from the Adapter service. | 63 * Gets an array of currently detectable devices from the Adapter service. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 164 |
141 adapterBroker = new AdapterBroker(adapter); | 165 adapterBroker = new AdapterBroker(adapter); |
142 return adapterBroker; | 166 return adapterBroker; |
143 }); | 167 }); |
144 } | 168 } |
145 | 169 |
146 return { | 170 return { |
147 getAdapterBroker: getAdapterBroker, | 171 getAdapterBroker: getAdapterBroker, |
148 }; | 172 }; |
149 }); | 173 }); |
OLD | NEW |