Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Interface abstracting the Application functionality. | 7 * Interface abstracting the Application functionality. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * @type {remoting.ClientSession} The client session object, set once the | |
| 17 * connector has invoked its onOk callback. | |
| 18 */ | |
| 19 remoting.clientSession = null; | |
| 20 | |
| 21 /** | |
| 22 * @type {remoting.DesktopConnectedView} The client session view object, set | |
| 23 * once the connector has invoked its onOk callback. | |
| 24 */ | |
| 25 remoting.desktopConnectedView = null; | |
| 26 | |
| 27 /** | |
| 16 * @param {Array<string>} app_capabilities Array of application capabilities. | 28 * @param {Array<string>} app_capabilities Array of application capabilities. |
| 17 * @constructor | 29 * @constructor |
| 18 */ | 30 */ |
| 19 remoting.Application = function(app_capabilities) { | 31 remoting.Application = function(app_capabilities) { |
| 20 /** | 32 /** |
| 21 * @type {remoting.Application.Delegate} | 33 * @type {remoting.Application.Delegate} |
| 22 * @private | 34 * @private |
| 23 */ | 35 */ |
| 24 this.delegate_ = null; | 36 this.delegate_ = null; |
| 25 | 37 |
| 26 /** | 38 /** |
| 27 * @type {Array<string>} | 39 * @type {Array<string>} |
| 28 * @private | 40 * @private |
| 29 */ | 41 */ |
| 30 this.app_capabilities_ = [ | 42 this.app_capabilities_ = [ |
| 31 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION, | 43 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION, |
| 32 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS, | 44 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS, |
| 33 remoting.ClientSession.Capability.VIDEO_RECORDER | 45 remoting.ClientSession.Capability.VIDEO_RECORDER |
| 34 ]; | 46 ]; |
| 35 // Append the app-specific capabilities. | 47 // Append the app-specific capabilities. |
| 36 this.app_capabilities_.push.apply(this.app_capabilities_, app_capabilities); | 48 this.app_capabilities_.push.apply(this.app_capabilities_, app_capabilities); |
| 37 | 49 |
| 38 /** | 50 /** |
| 39 * @type {remoting.SessionConnector} | 51 * @type {remoting.SessionConnector} |
| 40 * @private | 52 * @private |
| 41 */ | 53 */ |
| 42 this.session_connector_ = null; | 54 this.session_connector_ = null; |
| 55 | |
| 56 /** @private {base.Disposable} */ | |
| 57 this.sessionConnectedHooks_ = null; | |
| 43 }; | 58 }; |
| 44 | 59 |
| 45 /** | 60 /** |
| 46 * @param {remoting.Application.Delegate} appDelegate The delegate that | 61 * @param {remoting.Application.Delegate} appDelegate The delegate that |
| 47 * contains the app-specific functionality. | 62 * contains the app-specific functionality. |
| 48 */ | 63 */ |
| 49 remoting.Application.prototype.setDelegate = function(appDelegate) { | 64 remoting.Application.prototype.setDelegate = function(appDelegate) { |
| 50 this.delegate_ = appDelegate; | 65 this.delegate_ = appDelegate; |
| 51 }; | 66 }; |
| 52 | 67 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 remoting.SessionConnector.factory = | 101 remoting.SessionConnector.factory = |
| 87 new remoting.DefaultSessionConnectorFactory(); | 102 new remoting.DefaultSessionConnectorFactory(); |
| 88 | 103 |
| 89 // TODO(garykac): This should be owned properly rather than living in the | 104 // TODO(garykac): This should be owned properly rather than living in the |
| 90 // global 'remoting' namespace. | 105 // global 'remoting' namespace. |
| 91 remoting.settings = new remoting.Settings(); | 106 remoting.settings = new remoting.Settings(); |
| 92 | 107 |
| 93 this.delegate_.init(this.getSessionConnector()); | 108 this.delegate_.init(this.getSessionConnector()); |
| 94 }; | 109 }; |
| 95 | 110 |
| 111 /** Disconnect the remoting client. */ | |
| 112 remoting.Application.prototype.disconnect = function() { | |
| 113 if (remoting.clientSession) { | |
| 114 remoting.clientSession.disconnect(remoting.Error.NONE); | |
| 115 console.log('Disconnected.'); | |
| 116 } | |
| 117 }; | |
| 118 | |
| 96 /** | 119 /** |
| 97 * Called when a new session has been connected. | 120 * Called when a new session has been connected. |
| 98 * | 121 * |
| 99 * @param {remoting.ClientSession} clientSession | 122 * @param {remoting.ClientSession} clientSession |
| 100 * @return {void} Nothing. | 123 * @return {void} Nothing. |
| 101 */ | 124 */ |
| 102 remoting.Application.prototype.onConnected = function(clientSession) { | 125 remoting.Application.prototype.onConnected = function(clientSession) { |
| 103 // TODO(garykac): Make clientSession a member var of Application. | 126 // 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.
| |
| 104 remoting.clientSession = clientSession; | 127 remoting.clientSession = clientSession; |
| 105 remoting.clientSession.addEventListener('stateChanged', onClientStateChange_); | 128 this.sessionConnectedHooks_ = new base.Disposables( |
| 106 | 129 new base.EventHook( |
| 130 clientSession, 'stateChanged', this.onClientStateChange_.bind(this)), | |
| 131 new base.RepeatingTimer(this.updateStatistics_.bind(this), 1000) | |
| 132 ); | |
| 107 remoting.clipboard.startSession(); | 133 remoting.clipboard.startSession(); |
| 108 updateStatistics_(); | |
| 109 remoting.hangoutSessionEvents.raiseEvent( | 134 remoting.hangoutSessionEvents.raiseEvent( |
| 110 remoting.hangoutSessionEvents.sessionStateChanged, | 135 remoting.hangoutSessionEvents.sessionStateChanged, |
| 111 remoting.ClientSession.State.CONNECTED | 136 remoting.ClientSession.State.CONNECTED |
| 112 ); | 137 ); |
| 113 | 138 |
| 114 this.delegate_.handleConnected(clientSession); | 139 this.delegate_.handleConnected(clientSession); |
| 115 }; | 140 }; |
| 116 | 141 |
| 117 /** | 142 /** |
| 118 * Called when the current session has been disconnected. | 143 * Called when the current session has been disconnected. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 this.onConnected.bind(this), | 214 this.onConnected.bind(this), |
| 190 this.onError.bind(this), | 215 this.onError.bind(this), |
| 191 this.onExtensionMessage.bind(this), | 216 this.onExtensionMessage.bind(this), |
| 192 this.onConnectionFailed.bind(this), | 217 this.onConnectionFailed.bind(this), |
| 193 this.getRequiredCapabilities_(), | 218 this.getRequiredCapabilities_(), |
| 194 this.delegate_.getDefaultRemapKeys()); | 219 this.delegate_.getDefaultRemapKeys()); |
| 195 } | 220 } |
| 196 return this.session_connector_; | 221 return this.session_connector_; |
| 197 }; | 222 }; |
| 198 | 223 |
| 224 /** | |
| 225 * Callback function called when the state of the client plugin changes. The | |
| 226 * current and previous states are available via the |state| member variable. | |
| 227 * | |
| 228 * @param {remoting.ClientSession.StateEvent=} state | |
| 229 * @private | |
| 230 */ | |
| 231 remoting.Application.prototype.onClientStateChange_ = function(state) { | |
|
kelvinp
2015/02/25 22:44:38
Moved from client_screen.js.
| |
| 232 switch (state.current) { | |
| 233 case remoting.ClientSession.State.CLOSED: | |
| 234 console.log('Connection closed by host'); | |
| 235 this.onDisconnected(); | |
| 236 break; | |
| 237 case remoting.ClientSession.State.FAILED: | |
| 238 var error = remoting.clientSession.getError(); | |
| 239 console.error('Client plugin reported connection failed: ' + error); | |
| 240 if (error === null) { | |
| 241 error = remoting.Error.UNEXPECTED; | |
| 242 } | |
| 243 this.onError(error); | |
| 244 break; | |
| 245 | |
| 246 default: | |
| 247 console.error('Unexpected client plugin state: ' + state.current); | |
| 248 // This should only happen if the web-app and client plugin get out of | |
| 249 // sync, so MISSING_PLUGIN is a suitable error. | |
| 250 this.onError(remoting.Error.MISSING_PLUGIN); | |
| 251 break; | |
| 252 } | |
| 253 | |
| 254 base.dispose(this.sessionConnectedHooks_); | |
| 255 this.sessionConnectedHooks_= null; | |
| 256 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.
| |
| 257 remoting.clientSession = null; | |
| 258 }; | |
| 259 | |
| 260 /** @private */ | |
| 261 remoting.Application.prototype.updateStatistics_ = function() { | |
| 262 var perfstats = remoting.clientSession.getPerfStats(); | |
| 263 remoting.stats.update(perfstats); | |
| 264 remoting.clientSession.logStatistics(perfstats); | |
| 265 }; | |
| 199 | 266 |
| 200 /** | 267 /** |
| 201 * @interface | 268 * @interface |
| 202 */ | 269 */ |
| 203 remoting.Application.Delegate = function() {}; | 270 remoting.Application.Delegate = function() {}; |
| 204 | 271 |
| 205 /** | 272 /** |
| 206 * Initialize the application and register all event handlers. After this | 273 * Initialize the application and register all event handlers. After this |
| 207 * is called, the app is running and waiting for user events. | 274 * is called, the app is running and waiting for user events. |
| 208 * | 275 * |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 * Called when an error needs to be displayed to the user. | 337 * Called when an error needs to be displayed to the user. |
| 271 * | 338 * |
| 272 * @param {remoting.Error} errorTag The error to be localized and displayed. | 339 * @param {remoting.Error} errorTag The error to be localized and displayed. |
| 273 * @return {void} Nothing. | 340 * @return {void} Nothing. |
| 274 */ | 341 */ |
| 275 remoting.Application.Delegate.prototype.handleError = function(errorTag) {}; | 342 remoting.Application.Delegate.prototype.handleError = function(errorTag) {}; |
| 276 | 343 |
| 277 | 344 |
| 278 /** @type {remoting.Application} */ | 345 /** @type {remoting.Application} */ |
| 279 remoting.app = null; | 346 remoting.app = null; |
| OLD | NEW |