OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview | 6 * @fileoverview |
7 * REST API for host-list management. | 7 * REST API for host-list management. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 */ | 102 */ |
103 remoting.HostListApiImpl.prototype.parseHostListResponse_ = | 103 remoting.HostListApiImpl.prototype.parseHostListResponse_ = |
104 function(onDone, onError, xhr) { | 104 function(onDone, onError, xhr) { |
105 if (xhr.status == 200) { | 105 if (xhr.status == 200) { |
106 var response = /** @type {{data: {items: Array}}} */ | 106 var response = /** @type {{data: {items: Array}}} */ |
107 (base.jsonParseSafe(xhr.responseText)); | 107 (base.jsonParseSafe(xhr.responseText)); |
108 if (!response || !response.data) { | 108 if (!response || !response.data) { |
109 console.error('Invalid "hosts" response from server.'); | 109 console.error('Invalid "hosts" response from server.'); |
110 onError(remoting.Error.UNEXPECTED); | 110 onError(remoting.Error.UNEXPECTED); |
111 } else { | 111 } else { |
112 var hosts = response.data.items || []; | 112 var items = response.data.items || []; |
| 113 var hosts = items.map( |
| 114 /** @param {Object} item */ |
| 115 function(item) { |
| 116 var host = new remoting.Host(); |
| 117 host.hostName = item['hostName']; |
| 118 host.hostId = item['hostId']; |
| 119 host.status = item['status']; |
| 120 host.jabberId = item['jabberId']; |
| 121 host.publicKey = item['publicKey']; |
| 122 host.hostVersion = item['hostVersion']; |
| 123 host.tokenUrlPatterns = item['tokenUrlPatterns']; |
| 124 host.updatedTime = item['updatedTime']; |
| 125 host.hostOfflineReason = item['hostOfflineReason']; |
| 126 return host; |
| 127 }); |
113 onDone(hosts); | 128 onDone(hosts); |
114 } | 129 } |
115 } else { | 130 } else { |
116 onError(remoting.Error.fromHttpStatus(xhr.status)); | 131 onError(remoting.Error.fromHttpStatus(xhr.status)); |
117 } | 132 } |
118 }; | 133 }; |
119 | 134 |
120 /** @type {remoting.HostListApi} */ | 135 /** @type {remoting.HostListApi} */ |
121 remoting.hostListApi = new remoting.HostListApiImpl(); | 136 remoting.hostListApi = new remoting.HostListApiImpl(); |
OLD | NEW |