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.device) { |
| 37 response.device = interfaces.Connection.bindHandleToProxy( |
| 38 response.device, |
| 39 interfaces.BluetoothDevice.Device); |
| 40 } |
| 41 return response; |
| 42 }); |
| 43 }, |
| 44 |
| 45 /** |
30 * Sets client of Adapter service. | 46 * Sets client of Adapter service. |
31 * @param {interfaces.BluetoothAdapter.AdapterClient} adapterClient | 47 * @param {interfaces.BluetoothAdapter.AdapterClient} adapterClient |
32 */ | 48 */ |
33 setClient: function(adapterClient) { | 49 setClient: function(adapterClient) { |
34 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( | 50 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( |
35 adapterClient)); | 51 adapterClient)); |
36 }, | 52 }, |
37 | 53 |
38 /** | 54 /** |
39 * Gets an array of currently detectable devices from the Adapter service. | 55 * 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 | 156 |
141 adapterBroker = new AdapterBroker(adapter); | 157 adapterBroker = new AdapterBroker(adapter); |
142 return adapterBroker; | 158 return adapterBroker; |
143 }); | 159 }); |
144 } | 160 } |
145 | 161 |
146 return { | 162 return { |
147 getAdapterBroker: getAdapterBroker, | 163 getAdapterBroker: getAdapterBroker, |
148 }; | 164 }; |
149 }); | 165 }); |
OLD | NEW |