OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 28 matching lines...) Expand all Loading... | |
39 * @constructor | 39 * @constructor |
40 * @extends {base.EventSourceImpl} | 40 * @extends {base.EventSourceImpl} |
41 * @implements {base.Disposable} | 41 * @implements {base.Disposable} |
42 * @implements {remoting.ClientPlugin.ConnectionEventHandler} | 42 * @implements {remoting.ClientPlugin.ConnectionEventHandler} |
43 */ | 43 */ |
44 remoting.ClientSession = function(plugin, host, signalStrategy, mode) { | 44 remoting.ClientSession = function(plugin, host, signalStrategy, mode) { |
45 /** @private */ | 45 /** @private */ |
46 this.state_ = remoting.ClientSession.State.CREATED; | 46 this.state_ = remoting.ClientSession.State.CREATED; |
47 | 47 |
48 /** @private {!remoting.Error} */ | 48 /** @private {!remoting.Error} */ |
49 this.error_ = remoting.Error.NONE; | 49 this.error_ = remoting.Error.none(); |
50 | 50 |
51 /** @private */ | 51 /** @private */ |
52 this.host_ = host; | 52 this.host_ = host; |
53 | 53 |
54 /** @private */ | 54 /** @private */ |
55 this.sessionId_ = ''; | 55 this.sessionId_ = ''; |
56 | 56 |
57 /** @private */ | 57 /** @private */ |
58 this.hasReceivedFrame_ = false; | 58 this.hasReceivedFrame_ = false; |
59 this.logToServer = new remoting.LogToServer(signalStrategy, mode); | 59 this.logToServer = new remoting.LogToServer(signalStrategy, mode); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 remoting.ClientSession.prototype.removePlugin = function() { | 248 remoting.ClientSession.prototype.removePlugin = function() { |
249 this.plugin_ = null; | 249 this.plugin_ = null; |
250 }; | 250 }; |
251 | 251 |
252 /** | 252 /** |
253 * Disconnect the current session with a particular |error|. The session will | 253 * Disconnect the current session with a particular |error|. The session will |
254 * raise a |stateChanged| event in response to it. The caller should then call | 254 * raise a |stateChanged| event in response to it. The caller should then call |
255 * dispose() to remove and destroy the <embed> element. | 255 * dispose() to remove and destroy the <embed> element. |
256 * | 256 * |
257 * @param {!remoting.Error} error The reason for the disconnection. Use | 257 * @param {!remoting.Error} error The reason for the disconnection. Use |
258 * remoting.Error.NONE if there is no error. | 258 * remoting.Error.none() if there is no error. |
259 * @return {void} Nothing. | 259 * @return {void} Nothing. |
260 */ | 260 */ |
261 remoting.ClientSession.prototype.disconnect = function(error) { | 261 remoting.ClientSession.prototype.disconnect = function(error) { |
262 var state = error.isError() ? | 262 var state = error.isNone() ? |
263 remoting.ClientSession.State.FAILED : | 263 remoting.ClientSession.State.CLOSED : |
264 remoting.ClientSession.State.CLOSED; | 264 remoting.ClientSession.State.FAILED; |
265 | 265 |
266 // The plugin won't send a state change notification, so we explicitly log | 266 // The plugin won't send a state change notification, so we explicitly log |
267 // the fact that the connection has closed. | 267 // the fact that the connection has closed. |
268 this.logToServer.logClientSessionStateChange(state, error); | 268 this.logToServer.logClientSessionStateChange(state, error); |
269 this.error_ = error; | 269 this.error_ = error; |
270 this.setState_(state); | 270 this.setState_(state); |
271 }; | 271 }; |
272 | 272 |
273 /** | 273 /** |
274 * Deletes the <embed> element from the container and disconnects. | 274 * Deletes the <embed> element from the container and disconnects. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 * @param {remoting.ClientSession.ConnectionError} error The plugin's error | 387 * @param {remoting.ClientSession.ConnectionError} error The plugin's error |
388 * state, if any. | 388 * state, if any. |
389 */ | 389 */ |
390 remoting.ClientSession.prototype.onConnectionStatusUpdate = | 390 remoting.ClientSession.prototype.onConnectionStatusUpdate = |
391 function(status, error) { | 391 function(status, error) { |
392 if (status == remoting.ClientSession.State.CONNECTED) { | 392 if (status == remoting.ClientSession.State.CONNECTED) { |
393 remoting.desktopConnectedView.onConnected(); | 393 remoting.desktopConnectedView.onConnected(); |
394 } else if (status == remoting.ClientSession.State.FAILED) { | 394 } else if (status == remoting.ClientSession.State.FAILED) { |
395 switch (error) { | 395 switch (error) { |
396 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: | 396 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: |
397 this.error_ = remoting.Error.HOST_IS_OFFLINE; | 397 this.error_ = new remoting.Error( |
398 remoting.Error.Tag.HOST_IS_OFFLINE); | |
398 break; | 399 break; |
399 case remoting.ClientSession.ConnectionError.SESSION_REJECTED: | 400 case remoting.ClientSession.ConnectionError.SESSION_REJECTED: |
400 this.error_ = remoting.Error.INVALID_ACCESS_CODE; | 401 this.error_ = new remoting.Error( |
402 remoting.Error.Tag.INVALID_ACCESS_CODE); | |
401 break; | 403 break; |
402 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: | 404 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: |
403 this.error_ = remoting.Error.INCOMPATIBLE_PROTOCOL; | 405 this.error_ = new remoting.Error( |
406 remoting.Error.Tag.INCOMPATIBLE_PROTOCOL); | |
404 break; | 407 break; |
405 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: | 408 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: |
406 this.error_ = remoting.Error.P2P_FAILURE; | 409 this.error_ = new remoting.Error( |
410 remoting.Error.Tag.P2P_FAILURE); | |
407 break; | 411 break; |
408 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD: | 412 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD: |
409 this.error_ = remoting.Error.HOST_OVERLOAD; | 413 this.error_ = new remoting.Error( |
414 remoting.Error.Tag.HOST_OVERLOAD); | |
410 break; | 415 break; |
411 default: | 416 default: |
412 this.error_ = remoting.Error.UNEXPECTED; | 417 this.error_ = remoting.Error.unexpected(); |
413 } | 418 } |
414 } | 419 } |
415 this.setState_(status); | 420 this.setState_(status); |
416 }; | 421 }; |
417 | 422 |
418 /** | 423 /** |
419 * Callback that the plugin invokes to indicate that the connection type for | 424 * Callback that the plugin invokes to indicate that the connection type for |
420 * a channel has changed. | 425 * a channel has changed. |
421 * | 426 * |
422 * @param {string} channel The channel name. | 427 * @param {string} channel The channel name. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 * @private | 489 * @private |
485 */ | 490 */ |
486 remoting.ClientSession.prototype.setState_ = function(newState) { | 491 remoting.ClientSession.prototype.setState_ = function(newState) { |
487 var oldState = this.state_; | 492 var oldState = this.state_; |
488 this.state_ = newState; | 493 this.state_ = newState; |
489 var state = this.state_; | 494 var state = this.state_; |
490 if (oldState == remoting.ClientSession.State.CONNECTING) { | 495 if (oldState == remoting.ClientSession.State.CONNECTING) { |
491 if (this.state_ == remoting.ClientSession.State.CLOSED) { | 496 if (this.state_ == remoting.ClientSession.State.CLOSED) { |
492 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 497 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
493 } else if (this.state_ == remoting.ClientSession.State.FAILED && | 498 } else if (this.state_ == remoting.ClientSession.State.FAILED && |
494 this.error_.tag == remoting.Error.Tag.HOST_IS_OFFLINE && | 499 this.error_.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && |
495 !this.logHostOfflineErrors_) { | 500 !this.logHostOfflineErrors_) { |
496 // The application requested host-offline errors to be suppressed, for | 501 // The application requested host-offline errors to be suppressed, for |
497 // example, because this connection attempt is using a cached host JID. | 502 // example, because this connection attempt is using a cached host JID. |
498 console.log('Suppressing host-offline error.'); | 503 console.log('Suppressing host-offline error.'); |
499 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 504 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
500 } | 505 } |
501 } else if (oldState == remoting.ClientSession.State.CONNECTED && | 506 } else if (oldState == remoting.ClientSession.State.CONNECTED && |
502 this.state_ == remoting.ClientSession.State.FAILED) { | 507 this.state_ == remoting.ClientSession.State.FAILED) { |
503 state = remoting.ClientSession.State.CONNECTION_DROPPED; | 508 state = remoting.ClientSession.State.CONNECTION_DROPPED; |
504 } | 509 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 } | 636 } |
632 /** @type {remoting.ClientSession} */ | 637 /** @type {remoting.ClientSession} */ |
633 var that = this; | 638 var that = this; |
634 | 639 |
635 /** @param {string} token */ | 640 /** @param {string} token */ |
636 var sendToken = function(token) { | 641 var sendToken = function(token) { |
637 remoting.clientSession.sendClientMessage('accessToken', token); | 642 remoting.clientSession.sendClientMessage('accessToken', token); |
638 }; | 643 }; |
639 /** @param {!remoting.Error} error */ | 644 /** @param {!remoting.Error} error */ |
640 var sendError = function(error) { | 645 var sendError = function(error) { |
641 console.log('Failed to refresh access token: ' + error); | 646 console.log('Failed to refresh access token:', error.toString()); |
Jamie
2015/03/13 20:26:01
Nit: When all objects are strings, plus is better
John Williams
2015/03/13 22:40:30
It still works the same way :(
| |
642 }; | 647 }; |
643 remoting.identity.getNewToken(). | 648 remoting.identity.getNewToken(). |
644 then(sendToken). | 649 then(sendToken). |
645 catch(remoting.Error.handler(sendError)); | 650 catch(remoting.Error.handler(sendError)); |
646 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), | 651 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), |
647 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); | 652 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); |
648 }; | 653 }; |
649 | 654 |
650 /** | 655 /** |
651 * Send a Cast extension message to the host. | 656 * Send a Cast extension message to the host. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 */ | 712 */ |
708 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { | 713 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { |
709 if (enable) { | 714 if (enable) { |
710 this.plugin_.setDebugDirtyRegionHandler( | 715 this.plugin_.setDebugDirtyRegionHandler( |
711 remoting.desktopConnectedView.handleDebugRegion.bind( | 716 remoting.desktopConnectedView.handleDebugRegion.bind( |
712 remoting.desktopConnectedView)); | 717 remoting.desktopConnectedView)); |
713 } else { | 718 } else { |
714 this.plugin_.setDebugDirtyRegionHandler(null); | 719 this.plugin_.setDebugDirtyRegionHandler(null); |
715 } | 720 } |
716 } | 721 } |
OLD | NEW |