Index: remoting/webapp/crd/js/session_connector_impl.js |
diff --git a/remoting/webapp/crd/js/session_connector_impl.js b/remoting/webapp/crd/js/session_connector_impl.js |
index fdbd6f0ccc6b1d7bf30f0ba261f301c90c2d4ac0..16759966f2c3785aac0352590458cbecb8d69785 100644 |
--- a/remoting/webapp/crd/js/session_connector_impl.js |
+++ b/remoting/webapp/crd/js/session_connector_impl.js |
@@ -108,14 +108,14 @@ remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError, |
}; |
// Initialize/declare per-connection state. |
- this.reset(); |
+ this.reset_(); |
}; |
/** |
* Reset the per-connection state so that the object can be re-used for a |
* second connection. Note the none of the shared WCS state is reset. |
*/ |
-remoting.SessionConnectorImpl.prototype.reset = function() { |
+remoting.SessionConnectorImpl.prototype.reset_ = function() { |
/** |
* @type {remoting.Host} |
* @private |
@@ -128,12 +128,18 @@ remoting.SessionConnectorImpl.prototype.reset = function() { |
*/ |
this.logHostOfflineErrors_ = false; |
+ /** @type {remoting.ClientPlugin} @private */ |
+ this.plugin_ = null; |
+ |
/** |
* @type {remoting.ClientSession} |
* @private |
*/ |
this.clientSession_ = null; |
+ /** @type {remoting.DesktopConnectedView} @private */ |
+ this.connectedView_ = null; |
+ |
/** |
* @type {XMLHttpRequest} |
* @private |
@@ -288,15 +294,11 @@ remoting.SessionConnectorImpl.prototype.reconnect = function() { |
* Cancel a connection-in-progress. |
*/ |
remoting.SessionConnectorImpl.prototype.cancel = function() { |
- if (this.clientSession_) { |
garykac
2015/03/06 00:45:04
No longer needed - resetConnection does this.
|
- this.clientSession_.removePlugin(); |
- this.clientSession_ = null; |
- } |
if (this.pendingXhr_) { |
this.pendingXhr_.abort(); |
this.pendingXhr_ = null; |
} |
- this.reset(); |
+ this.resetConnection(); |
}; |
/** |
@@ -433,20 +435,89 @@ remoting.SessionConnectorImpl.prototype.createSession_ = function() { |
// In some circumstances, the WCS <iframe> can get reloaded, which results |
// in a new clientJid and a new callback. In this case, remove the old |
// client plugin before instantiating a new one. |
- if (this.clientSession_) { |
- this.clientSession_.removePlugin(); |
- this.clientSession_ = null; |
- } |
+ this.removePlugin(); |
this.clientSession_ = new remoting.ClientSession( |
this.host_, this.signalStrategy_, this.credentialsProvider_, |
- this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_); |
+ this.connectionMode_); |
+ remoting.clientSession = this.clientSession_; |
+ |
+ this.connectedView_ = new remoting.DesktopConnectedView( |
+ this.clientSession_, this.clientContainer_, this.host_, |
+ this.connectionMode_, |
+ this.defaultRemapKeys_); |
+ remoting.desktopConnectedView = this.connectedView_; |
+ |
this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); |
this.clientSession_.addEventListener( |
remoting.ClientSession.Events.stateChanged, |
this.bound_.onStateChange); |
- this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, |
- this.requiredCapabilities_); |
+ |
+ var pluginContainer = this.clientContainer_.querySelector( |
+ '.client-plugin-container'); |
+ |
+ this.plugin_ = remoting.ClientPlugin.factory.createPlugin( |
+ pluginContainer, this.onExtensionMessage_, this.requiredCapabilities_); |
+ |
+ var that = this; |
+ this.host_.options.load().then(function(){ |
+ that.plugin_.initialize(that.onPluginInitialized_.bind(that)); |
+ }); |
+}; |
+ |
+/** |
+ * @param {boolean} initialized |
+ */ |
+remoting.SessionConnectorImpl.prototype.onPluginInitialized_ = function( |
garykac
2015/03/06 00:45:04
Most of this came here from DesktopConnectedView
|
+ initialized) { |
+ if (!initialized) { |
+ console.error('ERROR: remoting plugin not loaded'); |
+ this.pluginError(remoting.Error.MISSING_PLUGIN); |
+ return; |
+ } |
+ |
+ if (!this.plugin_.isSupportedVersion()) { |
+ console.error('ERROR: bad plugin version'); |
+ this.pluginError(remoting.Error.BAD_PLUGIN_VERSION); |
+ return; |
+ } |
+ |
+ this.connectedView_.onPluginInitialized(this.plugin_); |
+ this.clientSession_.onPluginInitialized(this.plugin_); |
+}; |
+ |
+/** @param {remoting.Error} error */ |
+remoting.SessionConnectorImpl.prototype.pluginError = function(error) { |
+ this.signalStrategy_.setIncomingStanzaCallback(null); |
+ this.clientSession_.disconnect(error); |
+ this.removePlugin(); |
+}; |
+ |
+remoting.SessionConnectorImpl.prototype.removePlugin = function() { |
+ if (this.plugin_) { |
+ this.clientSession_.removePlugin(); |
+ this.connectedView_.removePlugin(); |
+ this.plugin_.dispose(); |
+ } |
+ this.plugin_ = null; |
+ |
+ if (this.clientSession_) { |
+ this.clientSession_.dispose(); |
+ } |
+ this.clientSession_ = null |
+ remoting.clientSession = null; |
+ |
+ this.connectedView_ = null; |
+ remoting.desktopConnectedView = null; |
+}; |
+ |
+remoting.SessionConnectorImpl.prototype.resetConnection = function() { |
+ this.removePlugin(); |
+ |
+ this.host_ = null; |
+ this.logHostOfflineErrors_ = false; |
+ this.pendingXhr_ = null; |
+ this.credentialsProvider_ = null; |
}; |
/** |