Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: remoting/webapp/crd/js/client_session.js

Issue 1097133002: [Webapp Refactor] Remove remoting.SessionConnector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix merge conflicts Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/base/js/protocol_extension.js ('k') | remoting/webapp/crd/js/client_session_factory.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/client_session.js
diff --git a/remoting/webapp/crd/js/client_session.js b/remoting/webapp/crd/js/client_session.js
index f76069ea1d3f4e6b89ec3c01e9ae7f3114655c91..b31d69f22ff567721d31ba6e0259ae0d4cfb34e0 100644
--- a/remoting/webapp/crd/js/client_session.js
+++ b/remoting/webapp/crd/js/client_session.js
@@ -8,9 +8,8 @@
*
* The ClientSession class controls lifetime of the client plugin
* object and provides the plugin with the functionality it needs to
- * establish connection. Specifically it:
- * - Delivers incoming/outgoing signaling messages,
- * - Adjusts plugin size and position when destop resolution changes,
+ * establish connection, e.g. delivers incoming/outgoing signaling
+ * messages.
*
* This class should not access the plugin directly, instead it should
* do it through ClientPlugin class which abstracts plugin version
@@ -24,15 +23,15 @@ var remoting = remoting || {};
/**
* @param {remoting.ClientPlugin} plugin
- * @param {remoting.Host} host The host to connect to.
* @param {remoting.SignalStrategy} signalStrategy Signal strategy.
+ * @param {remoting.ClientSession.EventHandler} listener
*
* @constructor
* @extends {base.EventSourceImpl}
* @implements {base.Disposable}
* @implements {remoting.ClientPlugin.ConnectionEventHandler}
*/
-remoting.ClientSession = function(plugin, host, signalStrategy) {
+remoting.ClientSession = function(plugin, signalStrategy, listener) {
base.inherits(this, base.EventSourceImpl);
/** @private */
@@ -41,13 +40,19 @@ remoting.ClientSession = function(plugin, host, signalStrategy) {
/** @private {!remoting.Error} */
this.error_ = remoting.Error.none();
- /** @private */
- this.host_ = host;
+ /** @private {remoting.Host} */
+ this.host_ = null;
+
+ /** @private {remoting.CredentialsProvider} */
+ this.credentialsProvider_ = null;
/** @private */
this.sessionId_ = '';
/** @private */
+ this.listener_ = listener;
+
+ /** @private */
this.hasReceivedFrame_ = false;
this.logToServer = new remoting.LogToServer(signalStrategy);
@@ -58,9 +63,8 @@ remoting.ClientSession = function(plugin, host, signalStrategy) {
this.signalStrategy_.setIncomingStanzaCallback(
this.onIncomingMessage_.bind(this));
- /** @private */
- this.iqFormatter_ =
- new remoting.FormatIq(this.signalStrategy_.getJid(), host.jabberId);
+ /** @private {remoting.FormatIq} */
+ this.iqFormatter_ = null;
/**
* Allow host-offline error reporting to be suppressed in situations where it
@@ -255,6 +259,21 @@ remoting.ClientSession.Capability = {
};
/**
+ * Connects to |host| using |credentialsProvider| as the credentails.
+ *
+ * @param {remoting.Host} host
+ * @param {remoting.CredentialsProvider} credentialsProvider
+ */
+remoting.ClientSession.prototype.connect = function(host, credentialsProvider) {
+ this.host_ = host;
+ this.credentialsProvider_ = credentialsProvider;
+ this.iqFormatter_ =
+ new remoting.FormatIq(this.signalStrategy_.getJid(), host.jabberId);
+ this.plugin_.connect(this.host_, this.signalStrategy_.getJid(),
+ credentialsProvider);
+};
+
+/**
* Disconnect the current session with a particular |error|. The session will
* raise a |stateChanged| event in response to it. The caller should then call
* dispose() to remove and destroy the <embed> element.
@@ -297,6 +316,7 @@ remoting.ClientSession.prototype.disconnect = function(error) {
remoting.ClientSession.prototype.dispose = function() {
base.dispose(this.connectedDisposables_);
this.connectedDisposables_ = null;
+ base.dispose(this.plugin_);
this.plugin_ = null;
};
@@ -488,7 +508,65 @@ remoting.ClientSession.prototype.setState_ = function(newState) {
this.connectedDisposables_ = null;
}
+ this.notifyStateChanges_(oldState, this.state_);
this.logToServer.logClientSessionStateChange(this.state_, this.error_);
+};
+
+/**
+ * @param {remoting.ClientSession.State} oldState The new state for the session.
+ * @param {remoting.ClientSession.State} newState The new state for the session.
+ * @private
+ */
+remoting.ClientSession.prototype.notifyStateChanges_ =
+ function(oldState, newState) {
+ /** @type {remoting.Error} */
+ var error;
+ switch (this.state_) {
+ case remoting.ClientSession.State.CONNECTED:
+ console.log('Connection established.');
+ var connectionInfo = new remoting.ConnectionInfo(
+ this.host_, this.credentialsProvider_, this, this.plugin_);
+ this.listener_.onConnected(connectionInfo);
+ break;
+
+ case remoting.ClientSession.State.CONNECTING:
+ remoting.identity.getEmail().then(function(/** string */ email) {
+ console.log('Connecting as ' + email);
+ });
+ break;
+
+ case remoting.ClientSession.State.AUTHENTICATED:
+ console.log('Connection authenticated.');
+ break;
+
+ case remoting.ClientSession.State.INITIALIZING:
+ console.log('Connection initializing .');
+ break;
+
+ case remoting.ClientSession.State.CLOSED:
+ console.log('Connection closed.');
+ this.listener_.onDisconnected();
+ break;
+
+ case remoting.ClientSession.State.FAILED:
+ error = this.getError();
+ console.error('Connection failed: ' + error.toString());
+ this.listener_.onConnectionFailed(error);
+ break;
+
+ case remoting.ClientSession.State.CONNECTION_DROPPED:
+ error = this.getError();
+ console.error('Connection dropped: ' + error.toString());
+ this.listener_.onError(error);
+ break;
+
+ default:
+ console.error('Unexpected client plugin state: ' + newState);
+ // This should only happen if the web-app and client plugin get out of
+ // sync, and even then the version check should ensure compatibility.
+ this.listener_.onError(
+ new remoting.Error(remoting.Error.Tag.MISSING_PLUGIN));
+ }
this.raiseEvent(remoting.ClientSession.Events.stateChanged,
new remoting.ClientSession.StateEvent(newState, oldState)
« no previous file with comments | « remoting/webapp/base/js/protocol_extension.js ('k') | remoting/webapp/crd/js/client_session_factory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698