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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Add pub/sub system for device events, various issue fixes Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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 cr.define('bluetooth_internals', function() { 10 cr.define('bluetooth_internals', function() {
(...skipping 13 matching lines...) Expand all
24 adapterBroker.addEventListener('devicechanged', function(event) { 24 adapterBroker.addEventListener('devicechanged', function(event) {
25 devices.addOrUpdate(event.detail.deviceInfo); 25 devices.addOrUpdate(event.detail.deviceInfo);
26 }); 26 });
27 adapterBroker.addEventListener('deviceremoved', function(event) { 27 adapterBroker.addEventListener('deviceremoved', function(event) {
28 devices.remove(event.detail.deviceInfo); 28 devices.remove(event.detail.deviceInfo);
29 }); 29 });
30 30
31 response.devices.forEach(devices.addOrUpdate, 31 response.devices.forEach(devices.addOrUpdate,
32 devices /* this */); 32 devices /* this */);
33 33
34 // TODO(crbug.com/663470): Move subscribe statements to DevicesView when
35 // it's added.
36 bluetooth_internals.subscribe('connectrequest', function(event) {
ortuno 2016/11/09 03:24:03 I think we want to do this the other way around. D
mbrunson 2016/11/09 23:39:37 We can use addEventListener on DeviceTable since i
37 var index = event.detail.index;
38 var device = devices.item(index);
39
40 if (device.proxy) {
41 device.disconnect();
42 devices.updateConnectionStatus(index);
43 } else {
44 device.connect().then(function() {
45 devices.updateConnectionStatus(index);
46
47 device.getServices().then(function() {
48 devices.updateIndex(index);
49 });
50 }).catch(function(error) {
51 devices.updateConnectionStatus(index, error);
52 });
53 }
54 });
ortuno 2016/11/09 03:24:03 Should this be bound to bluetooth_internals?
mbrunson 2016/11/09 23:39:37 It doesn't really need to be.
55
34 var deviceTable = new device_table.DeviceTable(); 56 var deviceTable = new device_table.DeviceTable();
35 deviceTable.setDevices(devices); 57 deviceTable.setDevices(devices);
36 document.body.appendChild(deviceTable); 58 document.body.appendChild(deviceTable);
37 }) 59 })
38 .catch(function(error) { console.error(error); }); 60 .catch(function(error) { console.error(error); });
39 } 61 }
40 62
63 var eventHandlersMap = new Map();
64
65 function publish(event) {
66 var handlers = eventHandlersMap.get(event.type);
67 handlers.forEach(function(handler) {
68 handler(event);
69 });
70 }
71
72 function subscribe(eventName, delegate) {
73 if (!eventHandlersMap.has(eventName)) {
74 eventHandlersMap.set(eventName, []);
75 }
76
77 eventHandlersMap.get(eventName).push(delegate);
78 }
79
41 return { 80 return {
81 publish: publish,
82 subscribe: subscribe,
42 initializeViews: initializeViews 83 initializeViews: initializeViews
43 }; 84 };
44 85
45 }); 86 });
46 87
47 document.addEventListener( 88 document.addEventListener(
48 'DOMContentLoaded', bluetooth_internals.initializeViews); 89 'DOMContentLoaded', bluetooth_internals.initializeViews);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698