OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** @constructor */ | 10 /** @constructor */ |
11 remoting.HostController = function() { | 11 remoting.HostController = function() { |
12 this.hostDaemonFacade_ = this.createDaemonFacade_(); | 12 /** @type {remoting.HostDaemonFacade} @private */ |
13 this.hostDaemonFacade_ = new remoting.HostDaemonFacade(); | |
14 | |
15 /** @param {string} version */ | |
16 var printVersion = function(version) { | |
17 if (version == '') { | |
18 console.log('Host not installed.'); | |
19 } else { | |
20 console.log('Host version: ' + version); | |
21 } | |
22 }; | |
23 | |
24 this.getLocalHostVersion().then(printVersion, function() { | |
kelvinp
2015/06/10 18:00:45
Nit: Use .catch for error handling for readability
Jamie
2015/06/10 18:14:44
Done.
| |
25 console.log('Host version not available.'); | |
26 }); | |
13 }; | 27 }; |
14 | 28 |
15 // The values in the enums below are duplicated in daemon_controller.h except | 29 // The values in the enums below are duplicated in daemon_controller.h except |
16 // for NOT_INSTALLED. | 30 // for NOT_INSTALLED. |
17 /** @enum {number} */ | 31 /** @enum {number} */ |
18 remoting.HostController.State = { | 32 remoting.HostController.State = { |
19 NOT_IMPLEMENTED: 0, | 33 NOT_IMPLEMENTED: 0, |
20 NOT_INSTALLED: 1, | 34 NOT_INSTALLED: 1, |
21 STOPPED: 2, | 35 STOPPED: 2, |
22 STARTING: 3, | 36 STARTING: 3, |
(...skipping 26 matching lines...) Expand all Loading... | |
49 * @return {remoting.HostController.AsyncResult} The result enum value. | 63 * @return {remoting.HostController.AsyncResult} The result enum value. |
50 */ | 64 */ |
51 remoting.HostController.AsyncResult.fromString = function(result) { | 65 remoting.HostController.AsyncResult.fromString = function(result) { |
52 if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) { | 66 if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) { |
53 throw "Invalid HostController.AsyncResult: " + result; | 67 throw "Invalid HostController.AsyncResult: " + result; |
54 } | 68 } |
55 return remoting.HostController.AsyncResult[result]; | 69 return remoting.HostController.AsyncResult[result]; |
56 } | 70 } |
57 | 71 |
58 /** | 72 /** |
59 * @return {remoting.HostDaemonFacade} | |
60 * @private | |
61 */ | |
62 remoting.HostController.prototype.createDaemonFacade_ = function() { | |
63 /** @type {remoting.HostDaemonFacade} @private */ | |
64 var hostDaemonFacade = new remoting.HostDaemonFacade(); | |
65 | |
66 /** @param {string} version */ | |
67 var printVersion = function(version) { | |
68 if (version == '') { | |
69 console.log('Host not installed.'); | |
70 } else { | |
71 console.log('Host version: ' + version); | |
72 } | |
73 }; | |
74 | |
75 hostDaemonFacade.getDaemonVersion().then(printVersion, function() { | |
76 console.log('Host version not available.'); | |
77 }); | |
78 | |
79 return hostDaemonFacade; | |
80 }; | |
81 | |
82 /** | |
83 * Set of features for which hasFeature() can be used to test. | 73 * Set of features for which hasFeature() can be used to test. |
84 * | 74 * |
85 * @enum {string} | 75 * @enum {string} |
86 */ | 76 */ |
87 remoting.HostController.Feature = { | 77 remoting.HostController.Feature = { |
88 PAIRING_REGISTRY: 'pairingRegistry', | 78 PAIRING_REGISTRY: 'pairingRegistry', |
89 OAUTH_CLIENT: 'oauthClient' | 79 OAUTH_CLIENT: 'oauthClient' |
90 }; | 80 }; |
91 | 81 |
92 /** | 82 /** |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 } | 402 } |
413 onDone(hostId); | 403 onDone(hostId); |
414 }; | 404 }; |
415 | 405 |
416 this.hostDaemonFacade_.getDaemonConfig().then(onConfig, function(error) { | 406 this.hostDaemonFacade_.getDaemonConfig().then(onConfig, function(error) { |
417 onDone(null); | 407 onDone(null); |
418 }); | 408 }); |
419 }; | 409 }; |
420 | 410 |
421 /** | 411 /** |
412 * @return {Promise<string>} Promise that resolves with the host version, if | |
413 * installed, or rejects otherwise. | |
414 */ | |
415 remoting.HostController.prototype.getLocalHostVersion = function() { | |
416 return this.hostDaemonFacade_.getDaemonVersion(); | |
417 }; | |
418 | |
419 /** | |
422 * Fetch the list of paired clients for this host. | 420 * Fetch the list of paired clients for this host. |
423 * | 421 * |
424 * @param {function(Array<remoting.PairedClient>):void} onDone | 422 * @param {function(Array<remoting.PairedClient>):void} onDone |
425 * @param {function(!remoting.Error):void} onError | 423 * @param {function(!remoting.Error):void} onError |
426 * @return {void} | 424 * @return {void} |
427 */ | 425 */ |
428 remoting.HostController.prototype.getPairedClients = function(onDone, | 426 remoting.HostController.prototype.getPairedClients = function(onDone, |
429 onError) { | 427 onError) { |
430 this.hostDaemonFacade_.getPairedClients().then( | 428 this.hostDaemonFacade_.getPairedClients().then( |
431 onDone, remoting.Error.handler(onError)); | 429 onDone, remoting.Error.handler(onError)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 emailPromise.then(function(/** string */ email) { | 498 emailPromise.then(function(/** string */ email) { |
501 signalStrategy.connect(remoting.settings.XMPP_SERVER, email, token); | 499 signalStrategy.connect(remoting.settings.XMPP_SERVER, email, token); |
502 }); | 500 }); |
503 }); | 501 }); |
504 | 502 |
505 return result; | 503 return result; |
506 }; | 504 }; |
507 | 505 |
508 /** @type {remoting.HostController} */ | 506 /** @type {remoting.HostController} */ |
509 remoting.hostController = null; | 507 remoting.hostController = null; |
OLD | NEW |