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