| 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 bluetooth_internals.html, served from | 6 * Javascript for bluetooth_internals.html, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 (function() { | 10 (function() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 deviceRow.querySelector('.device-address').textContent = | 75 deviceRow.querySelector('.device-address').textContent = |
| 76 deviceInfo.address; | 76 deviceInfo.address; |
| 77 | 77 |
| 78 var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) || | 78 var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) || |
| 79 deviceRow.querySelector('.device-rssi').textContent; | 79 deviceRow.querySelector('.device-rssi').textContent; |
| 80 deviceRow.querySelector('.device-rssi').textContent = rssi; | 80 deviceRow.querySelector('.device-rssi').textContent = rssi; |
| 81 } | 81 } |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * TODO(crbug.com/652361): Move to shared location. | |
| 86 * Helper to convert callback-based define() API to a promise-based API. | |
| 87 * @param {!Array<string>} moduleNames | |
| 88 * @return {!Promise} | |
| 89 */ | |
| 90 function importModules(moduleNames) { | |
| 91 return new Promise(function(resolve, reject) { | |
| 92 define(moduleNames, function(var_args) { | |
| 93 resolve(Array.prototype.slice.call(arguments, 0)); | |
| 94 }); | |
| 95 }); | |
| 96 } | |
| 97 | |
| 98 /** | |
| 99 * Initializes Mojo proxies for page and Bluetooth services. | 85 * Initializes Mojo proxies for page and Bluetooth services. |
| 100 * @return {!Promise} resolves if adapter is acquired, rejects if Bluetooth | 86 * @return {!Promise} resolves if adapter is acquired, rejects if Bluetooth |
| 101 * is not supported. | 87 * is not supported. |
| 102 */ | 88 */ |
| 103 function initializeProxies() { | 89 function initializeProxies() { |
| 104 return importModules([ | 90 return importModules([ |
| 105 'content/public/renderer/frame_interfaces', | 91 'content/public/renderer/frame_interfaces', |
| 106 'device/bluetooth/public/interfaces/adapter.mojom', | 92 'device/bluetooth/public/interfaces/adapter.mojom', |
| 107 'device/bluetooth/public/interfaces/device.mojom', | 93 'device/bluetooth/public/interfaces/device.mojom', |
| 108 'mojo/public/js/connection', | 94 'mojo/public/js/connection', |
| (...skipping 30 matching lines...) Expand all Loading... |
| 139 initializeProxies() | 125 initializeProxies() |
| 140 .then(function() { return adapter.getInfo(); }) | 126 .then(function() { return adapter.getInfo(); }) |
| 141 .then(function(response) { console.log('adapter', response.info); }) | 127 .then(function(response) { console.log('adapter', response.info); }) |
| 142 .then(function() { return adapter.getDevices(); }) | 128 .then(function() { return adapter.getDevices(); }) |
| 143 .then(function(response) { | 129 .then(function(response) { |
| 144 response.devices.forEach(adapterClient.deviceAdded, adapterClient); | 130 response.devices.forEach(adapterClient.deviceAdded, adapterClient); |
| 145 }) | 131 }) |
| 146 .catch(function(error) { console.error(error); }); | 132 .catch(function(error) { console.error(error); }); |
| 147 }); | 133 }); |
| 148 })(); | 134 })(); |
| OLD | NEW |