Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3095)

Unified Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Renaming mojom, ConnectErrorCode changes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
index 8cde1c5bbcba2483fa2bd71b78f61081252da7ae..b41e4523354866c784a68bf3c970ef89a84b2339 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -58,7 +58,9 @@ cr.define('bluetooth_internals', function() {
// Update rssi if it's valid
var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) ||
(device.info.rssi && device.info.rssi.value);
- device.info = deviceInfo;
+
+ // Merge given |deviceInfo| with current device info.
+ Object.assign(device.info, deviceInfo);
device.info.rssi = { value: rssi };
this.devices.update(device);
}
@@ -118,6 +120,50 @@ cr.define('bluetooth_internals', function() {
});
}
+ function connectDevice(device) {
+ return adapter.connectToDevice(device.info.address).then(
+ function(response) {
+ if (response.error == bluetoothAdapter.ConnectErrorCode.SUCCESS) {
+ device.proxy = connection.bindHandleToProxy(response.device,
+ bluetoothDevice.Device);
+ return;
+ }
+
+ // TODO(mbrunson): Replace with more descriptive error messages.
+ var errorString = Object.keys(
+ bluetoothAdapter.ConnectErrorCode)[response.error];
+
+ throw new Error(errorString);
+ }).then(function() {
+ // TODO(mbrunson): Remove when ServicesDiscovered() callback function is
+ // added to AdapterClient.
+ var done = false;
+ var fetchJob = setInterval(function() {
+ if (!done) {
+ if (device.proxy) {
+ device.proxy.getServices().then(function(response) {
+ device.info.services = response.services;
+ done = true;
+
+ if (device.info.services) {
+ adapterClient.devices.update(device);
+ clearInterval(fetchJob);
+ }
+ });
+ } else {
+ done = true;
+ clearInterval(fetchJob);
+ }
+ }
+ }, 5000);
+ });
+ }
+
+ function disconnectDevice(device) {
+ device.proxy = null;
+ return Promise.resolve();
+ }
+
function initialize() {
initializeProxies()
.then(function() { return adapter.getInfo(); })
@@ -128,6 +174,8 @@ cr.define('bluetooth_internals', function() {
adapterClient /** this */);
var deviceTable = new device.DeviceTable();
+
+ deviceTable.setConnectionHandlers(connectDevice, disconnectDevice);
deviceTable.setDevices(adapterClient.devices);
document.body.appendChild(deviceTable);
})

Powered by Google App Engine
This is Rietveld 408576698