Chromium Code Reviews| Index: remoting/webapp/base/js/application.js |
| diff --git a/remoting/webapp/base/js/application.js b/remoting/webapp/base/js/application.js |
| index e31fb503214938f5a1f9b8fd560625d2e5ec8ddd..2aa96884d3b36cad8fda047f0f6c2aa6d07b5123 100644 |
| --- a/remoting/webapp/base/js/application.js |
| +++ b/remoting/webapp/base/js/application.js |
| @@ -13,6 +13,18 @@ |
| var remoting = remoting || {}; |
| /** |
| + * @type {remoting.ClientSession} The client session object, set once the |
| + * connector has invoked its onOk callback. |
| + */ |
| +remoting.clientSession = null; |
| + |
| +/** |
| + * @type {remoting.DesktopConnectedView} The client session view object, set |
| + * once the connector has invoked its onOk callback. |
| + */ |
| +remoting.desktopConnectedView = null; |
| + |
| +/** |
| * @param {Array<string>} app_capabilities Array of application capabilities. |
| * @constructor |
| */ |
| @@ -40,6 +52,9 @@ remoting.Application = function(app_capabilities) { |
| * @private |
| */ |
| this.session_connector_ = null; |
| + |
| + /** @private {base.Disposable} */ |
| + this.sessionConnectedHooks_ = null; |
| }; |
| /** |
| @@ -93,6 +108,14 @@ remoting.Application.prototype.start = function() { |
| this.delegate_.init(this.getSessionConnector()); |
| }; |
| +/** Disconnect the remoting client. */ |
| +remoting.Application.prototype.disconnect = function() { |
| + if (remoting.clientSession) { |
| + remoting.clientSession.disconnect(remoting.Error.NONE); |
| + console.log('Disconnected.'); |
| + } |
| +}; |
| + |
| /** |
| * Called when a new session has been connected. |
| * |
| @@ -102,10 +125,12 @@ remoting.Application.prototype.start = function() { |
| remoting.Application.prototype.onConnected = function(clientSession) { |
| // TODO(garykac): Make clientSession a member var of Application. |
|
Jamie
2015/03/04 01:06:54
Move this TODO up to where remoting.clientSession
kelvinp
2015/03/04 21:02:20
Done.
|
| remoting.clientSession = clientSession; |
| - remoting.clientSession.addEventListener('stateChanged', onClientStateChange_); |
| - |
| + this.sessionConnectedHooks_ = new base.Disposables( |
| + new base.EventHook( |
| + clientSession, 'stateChanged', this.onClientStateChange_.bind(this)), |
| + new base.RepeatingTimer(this.updateStatistics_.bind(this), 1000) |
| + ); |
| remoting.clipboard.startSession(); |
| - updateStatistics_(); |
| remoting.hangoutSessionEvents.raiseEvent( |
| remoting.hangoutSessionEvents.sessionStateChanged, |
| remoting.ClientSession.State.CONNECTED |
| @@ -196,6 +221,48 @@ remoting.Application.prototype.getSessionConnector = function() { |
| return this.session_connector_; |
| }; |
| +/** |
| + * Callback function called when the state of the client plugin changes. The |
| + * current and previous states are available via the |state| member variable. |
| + * |
| + * @param {remoting.ClientSession.StateEvent=} state |
| + * @private |
| + */ |
| +remoting.Application.prototype.onClientStateChange_ = function(state) { |
|
kelvinp
2015/02/25 22:44:38
Moved from client_screen.js.
|
| + switch (state.current) { |
| + case remoting.ClientSession.State.CLOSED: |
| + console.log('Connection closed by host'); |
| + this.onDisconnected(); |
| + break; |
| + case remoting.ClientSession.State.FAILED: |
| + var error = remoting.clientSession.getError(); |
| + console.error('Client plugin reported connection failed: ' + error); |
| + if (error === null) { |
| + error = remoting.Error.UNEXPECTED; |
| + } |
| + this.onError(error); |
| + break; |
| + |
| + default: |
| + console.error('Unexpected client plugin state: ' + state.current); |
| + // This should only happen if the web-app and client plugin get out of |
| + // sync, so MISSING_PLUGIN is a suitable error. |
| + this.onError(remoting.Error.MISSING_PLUGIN); |
| + break; |
| + } |
| + |
| + base.dispose(this.sessionConnectedHooks_); |
| + this.sessionConnectedHooks_= null; |
| + remoting.clientSession.cleanup(); |
|
Jamie
2015/03/04 01:06:54
Not for this CL, but I think cleanup() pre-dates b
kelvinp
2015/03/04 21:02:20
Acknowledged.
|
| + remoting.clientSession = null; |
| +}; |
| + |
| +/** @private */ |
| +remoting.Application.prototype.updateStatistics_ = function() { |
| + var perfstats = remoting.clientSession.getPerfStats(); |
| + remoting.stats.update(perfstats); |
| + remoting.clientSession.logStatistics(perfstats); |
| +}; |
| /** |
| * @interface |