Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 DeviceDetailsPage which displays all of the details of a | 6 * Javascript for DeviceDetailsPage which displays all of the details of a |
| 7 * device. The page is generated and managed dynamically in bluetooth_internals. | 7 * device. The page is generated and managed dynamically in bluetooth_internals. |
| 8 * served from chrome://bluetooth-internals/. | 8 * served from chrome://bluetooth-internals/. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 address: this.deviceInfo.address, | 76 address: this.deviceInfo.address, |
| 77 }, | 77 }, |
| 78 })); | 78 })); |
| 79 }.bind(this)); | 79 }.bind(this)); |
| 80 | 80 |
| 81 this.connectBtn_ = this.pageDiv.querySelector('.disconnect'); | 81 this.connectBtn_ = this.pageDiv.querySelector('.disconnect'); |
| 82 this.connectBtn_.addEventListener('click', function() { | 82 this.connectBtn_.addEventListener('click', function() { |
| 83 this.devicePtr !== null ? this.disconnect() : this.connect(); | 83 this.devicePtr !== null ? this.disconnect() : this.connect(); |
| 84 }.bind(this)); | 84 }.bind(this)); |
| 85 | 85 |
| 86 this.serviceList.addEventListener( | |
| 87 'characteristicsrequested', function(event) { | |
| 88 if (!this.devicePtr) { | |
| 89 event.target.onCharacteristicsReturned([]); | |
|
dpapad
2017/01/17 20:01:01
I am confused about what is happening here.
| |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 this.devicePtr.getCharacteristics(event.detail.serviceId).then( | |
| 94 function(response) { | |
| 95 event.target.onCharacteristicsReturned( | |
|
dpapad
2017/01/17 20:01:01
This strikes me as odd. Instead of calling a metho
mbrunson
2017/01/17 21:05:49
I've been juggling solutions to this issue. I'm cr
dpapad
2017/01/17 22:01:39
Firing an event from a subcomponent that propagate
mbrunson
2017/01/18 22:04:23
Ok. I've created a global service object for this,
| |
| 96 response.characteristics); | |
| 97 }.bind(this)); | |
| 98 }.bind(this)); | |
| 99 | |
| 86 this.redraw(); | 100 this.redraw(); |
| 87 } | 101 } |
| 88 | 102 |
| 89 DeviceDetailsPage.prototype = { | 103 DeviceDetailsPage.prototype = { |
| 90 __proto__: Page.prototype, | 104 __proto__: Page.prototype, |
| 91 | 105 |
| 92 /** Creates a connection to the Bluetooth device. */ | 106 /** Creates a connection to the Bluetooth device. */ |
| 93 connect: function() { | 107 connect: function() { |
| 94 if (this.status_ !== device_collection.ConnectionStatus.DISCONNECTED) | 108 if (this.status_ !== device_collection.ConnectionStatus.DISCONNECTED) |
| 95 return; | 109 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 117 }.bind(this)).catch(function(error) { | 131 }.bind(this)).catch(function(error) { |
| 118 // If a connection error occurs while fetching the services, the | 132 // If a connection error occurs while fetching the services, the |
| 119 // devicePtr reference must be removed. | 133 // devicePtr reference must be removed. |
| 120 if (this.devicePtr) { | 134 if (this.devicePtr) { |
| 121 this.devicePtr.disconnect(); | 135 this.devicePtr.disconnect(); |
| 122 this.devicePtr = null; | 136 this.devicePtr = null; |
| 123 } | 137 } |
| 124 | 138 |
| 125 Snackbar.show( | 139 Snackbar.show( |
| 126 this.deviceInfo.name_for_display + ': ' + error.message, | 140 this.deviceInfo.name_for_display + ': ' + error.message, |
| 127 SnackbarType.DANGER, 'Retry', this.connect.bind(this)); | 141 SnackbarType.ERROR, 'Retry', this.connect.bind(this)); |
| 128 | 142 |
| 129 this.updateConnectionStatus_( | 143 this.updateConnectionStatus_( |
| 130 device_collection.ConnectionStatus.DISCONNECTED); | 144 device_collection.ConnectionStatus.DISCONNECTED); |
| 131 }.bind(this)); | 145 }.bind(this)); |
| 132 }, | 146 }, |
| 133 | 147 |
| 134 /** Disconnects the page from the Bluetooth device. */ | 148 /** Disconnects the page from the Bluetooth device. */ |
| 135 disconnect: function() { | 149 disconnect: function() { |
| 136 if (!this.devicePtr) return; | 150 if (!this.devicePtr) return; |
| 137 | 151 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 status: status, | 238 status: status, |
| 225 } | 239 } |
| 226 })); | 240 })); |
| 227 }, | 241 }, |
| 228 }; | 242 }; |
| 229 | 243 |
| 230 return { | 244 return { |
| 231 DeviceDetailsPage: DeviceDetailsPage, | 245 DeviceDetailsPage: DeviceDetailsPage, |
| 232 }; | 246 }; |
| 233 }); | 247 }); |
| OLD | NEW |