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 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
11 var remoting = remoting || {}; | 11 var remoting = remoting || {}; |
12 | 12 |
13 (function() { | 13 (function() { |
14 | 14 |
15 'use strict'; | 15 'use strict'; |
16 | 16 |
17 /** | 17 /** |
18 * @constructor | 18 * @constructor |
19 * @implements {remoting.HostListApi} | 19 * @implements {remoting.HostListApi} |
20 */ | 20 */ |
21 remoting.LegacyHostListApi = function() { | 21 remoting.LegacyHostListApi = function() { |
22 }; | 22 }; |
23 | 23 |
24 /** @override */ | 24 /** @override */ |
25 remoting.LegacyHostListApi.prototype.register = function( | 25 remoting.LegacyHostListApi.prototype.register = function( |
26 hostName, publicKey, hostClientId) { | 26 hostName, publicKey, hostClientId) { |
27 var newHostId = base.generateUuid(); | 27 var newHostId = base.generateUuid(); |
28 return remoting.LegacyHostListApi.registerWithHostId( | |
29 newHostId, hostName, publicKey, hostClientId); | |
John Williams
2015/06/29 19:45:05
I split the implementation of this method into a s
| |
30 }; | |
31 | |
32 /** | |
33 * Registers a host with the Chromoting directory using a specified | |
34 * host ID, which should not be equal to the ID of any existing host. | |
35 * | |
36 * @param {string} newHostId The host ID of the new host. | |
37 * @param {string} hostName The user-visible name of the new host. | |
38 * @param {string} publicKey The public half of the host's key pair. | |
39 * @param {?string} hostClientId The OAuth2 client ID of the host. | |
40 * @return {!Promise<remoting.HostListApi.RegisterResult>} | |
41 */ | |
42 remoting.LegacyHostListApi.registerWithHostId = function( | |
43 newHostId, hostName, publicKey, hostClientId) { | |
28 var newHostDetails = { data: { | 44 var newHostDetails = { data: { |
29 hostId: newHostId, | 45 hostId: newHostId, |
30 hostName: hostName, | 46 hostName: hostName, |
31 publicKey: publicKey | 47 publicKey: publicKey |
32 } }; | 48 } }; |
33 | 49 |
34 return new remoting.Xhr({ | 50 return new remoting.Xhr({ |
35 method: 'POST', | 51 method: 'POST', |
36 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', | 52 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', |
37 urlParams: { | 53 urlParams: { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 throw remoting.Error.unexpected(); | 204 throw remoting.Error.unexpected(); |
189 } | 205 } |
190 } else if (xhrResponse.status == 404) { | 206 } else if (xhrResponse.status == 404) { |
191 throw new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); | 207 throw new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); |
192 } else { | 208 } else { |
193 throw remoting.Error.fromHttpStatus(xhrResponse.status); | 209 throw remoting.Error.fromHttpStatus(xhrResponse.status); |
194 } | 210 } |
195 }); | 211 }); |
196 }; | 212 }; |
197 | 213 |
214 /** @override */ | |
215 remoting.LegacyHostListApi.prototype.getHostIdFromConfig = function(config) { | |
216 return base.getStringAttr(config, 'host_id'); | |
217 }; | |
218 | |
198 })(); | 219 })(); |
OLD | NEW |