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

Side by Side Diff: remoting/webapp/base/js/application.js

Issue 952353002: Requiem for client_screen.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + Ready for Check-in Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « remoting/webapp/app_remoting/js/app_remoting.js ('k') | remoting/webapp/base/js/base.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * TODO(garykac): Make clientSession a member var of Application.
19 */
20 remoting.clientSession = null;
21
22 /**
23 * @type {remoting.DesktopConnectedView} The client session view object, set
24 * once the connector has invoked its onOk callback.
25 */
26 remoting.desktopConnectedView = null;
27
28 /**
16 * @param {Array<string>} app_capabilities Array of application capabilities. 29 * @param {Array<string>} app_capabilities Array of application capabilities.
17 * @constructor 30 * @constructor
18 */ 31 */
19 remoting.Application = function(app_capabilities) { 32 remoting.Application = function(app_capabilities) {
20 /** 33 /**
21 * @type {remoting.Application.Delegate} 34 * @type {remoting.Application.Delegate}
22 * @private 35 * @private
23 */ 36 */
24 this.delegate_ = null; 37 this.delegate_ = null;
25 38
26 /** 39 /**
27 * @type {Array<string>} 40 * @type {Array<string>}
28 * @private 41 * @private
29 */ 42 */
30 this.app_capabilities_ = [ 43 this.app_capabilities_ = [
31 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION, 44 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
32 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS, 45 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS,
33 remoting.ClientSession.Capability.VIDEO_RECORDER 46 remoting.ClientSession.Capability.VIDEO_RECORDER
34 ]; 47 ];
35 // Append the app-specific capabilities. 48 // Append the app-specific capabilities.
36 this.app_capabilities_.push.apply(this.app_capabilities_, app_capabilities); 49 this.app_capabilities_.push.apply(this.app_capabilities_, app_capabilities);
37 50
38 /** 51 /**
39 * @type {remoting.SessionConnector} 52 * @type {remoting.SessionConnector}
40 * @private 53 * @private
41 */ 54 */
42 this.session_connector_ = null; 55 this.session_connector_ = null;
56
57 /** @private {base.Disposable} */
58 this.sessionConnectedHooks_ = null;
43 }; 59 };
44 60
45 /** 61 /**
46 * @param {remoting.Application.Delegate} appDelegate The delegate that 62 * @param {remoting.Application.Delegate} appDelegate The delegate that
47 * contains the app-specific functionality. 63 * contains the app-specific functionality.
48 */ 64 */
49 remoting.Application.prototype.setDelegate = function(appDelegate) { 65 remoting.Application.prototype.setDelegate = function(appDelegate) {
50 this.delegate_ = appDelegate; 66 this.delegate_ = appDelegate;
51 }; 67 };
52 68
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 remoting.SessionConnector.factory = 102 remoting.SessionConnector.factory =
87 new remoting.DefaultSessionConnectorFactory(); 103 new remoting.DefaultSessionConnectorFactory();
88 104
89 // TODO(garykac): This should be owned properly rather than living in the 105 // TODO(garykac): This should be owned properly rather than living in the
90 // global 'remoting' namespace. 106 // global 'remoting' namespace.
91 remoting.settings = new remoting.Settings(); 107 remoting.settings = new remoting.Settings();
92 108
93 this.delegate_.init(this.getSessionConnector()); 109 this.delegate_.init(this.getSessionConnector());
94 }; 110 };
95 111
112 /** Disconnect the remoting client. */
113 remoting.Application.prototype.disconnect = function() {
114 if (remoting.clientSession) {
115 remoting.clientSession.disconnect(remoting.Error.NONE);
116 console.log('Disconnected.');
117 }
118 };
119
96 /** 120 /**
97 * Called when a new session has been connected. 121 * Called when a new session has been connected.
98 * 122 *
99 * @param {remoting.ClientSession} clientSession 123 * @param {remoting.ClientSession} clientSession
100 * @return {void} Nothing. 124 * @return {void} Nothing.
101 */ 125 */
102 remoting.Application.prototype.onConnected = function(clientSession) { 126 remoting.Application.prototype.onConnected = function(clientSession) {
103 // TODO(garykac): Make clientSession a member var of Application.
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 134
110 this.delegate_.handleConnected(clientSession); 135 this.delegate_.handleConnected(clientSession);
111 }; 136 };
112 137
113 /** 138 /**
114 * Called when the current session has been disconnected. 139 * Called when the current session has been disconnected.
115 * 140 *
116 * @return {void} Nothing. 141 * @return {void} Nothing.
117 */ 142 */
118 remoting.Application.prototype.onDisconnected = function() { 143 remoting.Application.prototype.onDisconnected = function() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 this.onConnected.bind(this), 210 this.onConnected.bind(this),
186 this.onError.bind(this), 211 this.onError.bind(this),
187 this.onExtensionMessage.bind(this), 212 this.onExtensionMessage.bind(this),
188 this.onConnectionFailed.bind(this), 213 this.onConnectionFailed.bind(this),
189 this.getRequiredCapabilities_(), 214 this.getRequiredCapabilities_(),
190 this.delegate_.getDefaultRemapKeys()); 215 this.delegate_.getDefaultRemapKeys());
191 } 216 }
192 return this.session_connector_; 217 return this.session_connector_;
193 }; 218 };
194 219
220 /**
221 * Callback function called when the state of the client plugin changes. The
222 * current and previous states are available via the |state| member variable.
223 *
224 * @param {remoting.ClientSession.StateEvent=} state
225 * @private
226 */
227 remoting.Application.prototype.onClientStateChange_ = function(state) {
228 switch (state.current) {
229 case remoting.ClientSession.State.CLOSED:
230 console.log('Connection closed by host');
231 this.onDisconnected();
232 break;
233 case remoting.ClientSession.State.FAILED:
234 var error = remoting.clientSession.getError();
235 console.error('Client plugin reported connection failed: ' + error);
236 if (error === null) {
237 error = remoting.Error.UNEXPECTED;
238 }
239 this.onError(error);
240 break;
241
242 default:
243 console.error('Unexpected client plugin state: ' + state.current);
244 // This should only happen if the web-app and client plugin get out of
245 // sync, so MISSING_PLUGIN is a suitable error.
246 this.onError(remoting.Error.MISSING_PLUGIN);
247 break;
248 }
249
250 base.dispose(this.sessionConnectedHooks_);
251 this.sessionConnectedHooks_= null;
252 remoting.clientSession.dispose();
253 remoting.clientSession = null;
254 };
255
256 /** @private */
257 remoting.Application.prototype.updateStatistics_ = function() {
258 var perfstats = remoting.clientSession.getPerfStats();
259 remoting.stats.update(perfstats);
260 remoting.clientSession.logStatistics(perfstats);
261 };
195 262
196 /** 263 /**
197 * @interface 264 * @interface
198 */ 265 */
199 remoting.Application.Delegate = function() {}; 266 remoting.Application.Delegate = function() {};
200 267
201 /** 268 /**
202 * Initialize the application and register all event handlers. After this 269 * Initialize the application and register all event handlers. After this
203 * is called, the app is running and waiting for user events. 270 * is called, the app is running and waiting for user events.
204 * 271 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 * Called when an error needs to be displayed to the user. 333 * Called when an error needs to be displayed to the user.
267 * 334 *
268 * @param {remoting.Error} errorTag The error to be localized and displayed. 335 * @param {remoting.Error} errorTag The error to be localized and displayed.
269 * @return {void} Nothing. 336 * @return {void} Nothing.
270 */ 337 */
271 remoting.Application.Delegate.prototype.handleError = function(errorTag) {}; 338 remoting.Application.Delegate.prototype.handleError = function(errorTag) {};
272 339
273 340
274 /** @type {remoting.Application} */ 341 /** @type {remoting.Application} */
275 remoting.app = null; 342 remoting.app = null;
OLDNEW
« no previous file with comments | « remoting/webapp/app_remoting/js/app_remoting.js ('k') | remoting/webapp/base/js/base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698