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

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: Reviewer's feedback 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
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 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
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) {
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.dispose();
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
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;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698