Index: remoting/webapp/host_controller.js |
diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js |
index 9164d79e54d9a654a2c85ef44f039d0ef530b512..3429e27992ef64a5176bc7353ddb0c86e1835c68 100644 |
--- a/remoting/webapp/host_controller.js |
+++ b/remoting/webapp/host_controller.js |
@@ -9,28 +9,7 @@ var remoting = remoting || {}; |
/** @constructor */ |
remoting.HostController = function() { |
- /** @return {remoting.HostPlugin} */ |
- var createPluginForMe2Me = function() { |
- /** @type {HTMLElement} @private */ |
- var container = document.getElementById('daemon-plugin-container'); |
- return remoting.createNpapiPlugin(container); |
- }; |
- |
- /** @type {remoting.HostDispatcher} @private */ |
- this.hostDispatcher_ = new remoting.HostDispatcher(createPluginForMe2Me); |
- |
- /** @param {string} version */ |
- var printVersion = function(version) { |
- if (version == '') { |
- console.log('Host not installed.'); |
- } else { |
- console.log('Host version: ' + version); |
- } |
- }; |
- |
- this.hostDispatcher_.getDaemonVersion(printVersion, function() { |
- console.log('Host version not available.'); |
- }); |
+ this.hostDispatcher_ = this.createDispatcher(); |
}; |
// Note that the values in the enums below are copied from |
@@ -78,6 +57,36 @@ remoting.HostController.AsyncResult.fromString = function(result) { |
} |
/** |
+ * @return {remoting.HostDispatcher} |
+ */ |
+remoting.HostController.prototype.createDispatcher = function() { |
Jamie
2014/04/10 18:29:32
If this is private, please append _ to the name an
weitao
2014/04/10 21:33:47
Done.
|
+ /** @return {remoting.HostPlugin} */ |
+ var createPluginForMe2Me = function() { |
+ /** @type {HTMLElement} @private */ |
+ var container = document.getElementById('daemon-plugin-container'); |
+ return remoting.createNpapiPlugin(container); |
+ }; |
+ |
+ /** @type {remoting.HostDispatcher} @private */ |
+ var hostDispatcher = new remoting.HostDispatcher(createPluginForMe2Me); |
+ |
+ /** @param {string} version */ |
+ var printVersion = function(version) { |
+ if (version == '') { |
+ console.log('Host not installed.'); |
+ } else { |
+ console.log('Host version: ' + version); |
+ } |
+ }; |
+ |
+ hostDispatcher.getDaemonVersion(printVersion, function() { |
+ console.log('Host version not available.'); |
+ }); |
+ |
+ return hostDispatcher; |
+}; |
+ |
+/** |
* Set of features for which hasFeature() can be used to test. |
* |
* @enum {string} |
@@ -109,6 +118,15 @@ remoting.HostController.prototype.getConsent = function(onDone, onError) { |
}; |
/** |
+ * @param {function(remoting.HostController.AsyncResult):void} onDone |
+ * @param {function(remoting.Error):void} onError |
+ * @return {void} |
+ */ |
+remoting.HostController.prototype.installHost = function(onDone, onError) { |
+ this.hostDispatcher_.installHost(onDone, onError); |
+}; |
+ |
+/** |
* Registers and starts the host. |
* |
* @param {string} hostPin Host PIN. |
@@ -325,7 +343,25 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
onError); |
} |
- this.hostDispatcher_.getHostName(startWithHostname, onError); |
+ /** @param {remoting.HostController.AsyncResult} asyncResult */ |
+ var onHostInstalled = function(asyncResult) { |
+ if (asyncResult == remoting.HostController.AsyncResult.OK) { |
+ console.log('Recreating the host dispatcher.'); |
+ that.hostDispatcher_ = that.createDispatcher(); |
Jamie
2014/04/10 18:29:32
This is done in the ctor; does it need to be done
weitao
2014/04/10 21:33:47
Yes. Now that the host is installed, we need to ge
|
+ that.hostDispatcher_.getHostName(startWithHostname, onError); |
+ } else if (asyncResult == remoting.HostController.AsyncResult.CANCELLED) { |
+ onError(remoting.Error.CANCELLED); |
+ } else { |
+ onError(remoting.Error.UNEXPECTED); |
+ } |
+ } |
+ |
+ // Perform the installation step here on Windows. |
+ if (navigator.platform == 'Win32') { |
+ this.installHost(onHostInstalled, onError); |
+ } else { |
+ this.hostDispatcher_.getHostName(startWithHostname, onError); |
+ } |
}; |
/** |