| 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 * Class handling reconnecting the session when it is disconnected due to | 7 * Class handling reconnecting the session when it is disconnected due to |
| 8 * network failure. | 8 * network failure. |
| 9 * | 9 * |
| 10 * The SmartReconnector listens for changes in connection state of | 10 * The SmartReconnector listens for changes in connection state of |
| 11 * |clientSession| to determine if a reconnection is needed. It then calls into | 11 * |clientSession| to determine if a reconnection is needed. It then calls into |
| 12 * |connector| to reconnect the session. | 12 * |connector| to reconnect the session. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 /** @suppress {duplicate} */ | 15 /** @suppress {duplicate} */ |
| 16 var remoting = remoting || {}; | 16 var remoting = remoting || {}; |
| 17 | 17 |
| 18 (function () { | 18 (function () { |
| 19 | 19 |
| 20 'use strict'; | 20 'use strict'; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * @constructor | 23 * @constructor |
| 24 * @param {remoting.ConnectingDialog} connectingDialog |
| 24 * @param {function()} reconnectCallback | 25 * @param {function()} reconnectCallback |
| 25 * @param {function()} disconnectCallback | 26 * @param {function()} disconnectCallback |
| 26 * @param {remoting.ClientSession} clientSession This represents the current | 27 * @param {remoting.ClientSession} clientSession This represents the current |
| 27 * remote desktop connection. It is used to monitor the changes in | 28 * remote desktop connection. It is used to monitor the changes in |
| 28 * connection state. | 29 * connection state. |
| 29 * @implements {base.Disposable} | 30 * @implements {base.Disposable} |
| 30 */ | 31 */ |
| 31 remoting.SmartReconnector = | 32 remoting.SmartReconnector = function(connectingDialog, reconnectCallback, |
| 32 function(reconnectCallback, disconnectCallback, clientSession) { | 33 disconnectCallback, clientSession) { |
| 33 /** @private */ | 34 /** @private */ |
| 34 this.reconnectCallback_ = reconnectCallback; | 35 this.reconnectCallback_ = reconnectCallback; |
| 35 | 36 |
| 36 /** @private */ | 37 /** @private */ |
| 37 this.disconnectCallback_ = disconnectCallback; | 38 this.disconnectCallback_ = disconnectCallback; |
| 38 | 39 |
| 39 /** @private */ | 40 /** @private */ |
| 40 this.clientSession_ = clientSession; | 41 this.clientSession_ = clientSession; |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * Placeholder of any pending reconnect operations, e.g. Waiting for online, | 44 * Placeholder of any pending reconnect operations, e.g. Waiting for online, |
| 44 * or a timeout to reconnect. | 45 * or a timeout to reconnect. |
| 45 * | 46 * |
| 46 * @private {base.Disposable} | 47 * @private {base.Disposable} |
| 47 */ | 48 */ |
| 48 this.pending_ = null; | 49 this.pending_ = null; |
| 49 | 50 |
| 51 /** @private */ |
| 52 this.connectingDialog_ = connectingDialog; |
| 53 |
| 50 var Events = remoting.ClientSession.Events; | 54 var Events = remoting.ClientSession.Events; |
| 51 /** @private */ | 55 /** @private */ |
| 52 this.eventHooks_ = new base.Disposables( | 56 this.eventHooks_ = new base.Disposables( |
| 53 new base.EventHook(clientSession, Events.stateChanged, | 57 new base.EventHook(clientSession, Events.stateChanged, |
| 54 this.stateChanged_.bind(this)), | 58 this.stateChanged_.bind(this)), |
| 55 new base.EventHook(clientSession, Events.videoChannelStateChanged, | 59 new base.EventHook(clientSession, Events.videoChannelStateChanged, |
| 56 this.videoChannelStateChanged_.bind(this))); | 60 this.videoChannelStateChanged_.bind(this))); |
| 57 }; | 61 }; |
| 58 | 62 |
| 59 // The online event only means the network adapter is enabled, but | 63 // The online event only means the network adapter is enabled, but |
| 60 // it doesn't necessarily mean that we have a working internet connection. | 64 // it doesn't necessarily mean that we have a working internet connection. |
| 61 // Therefore, delay the connection by |RECONNECT_DELAY_MS| to allow for the | 65 // Therefore, delay the connection by |RECONNECT_DELAY_MS| to allow for the |
| 62 // network to connect. | 66 // network to connect. |
| 63 var RECONNECT_DELAY_MS = 2000; | 67 var RECONNECT_DELAY_MS = 2000; |
| 64 | 68 |
| 65 // If the video channel is inactive for 10 seconds reconnect the session. | 69 // If the video channel is inactive for 10 seconds reconnect the session. |
| 66 var CONNECTION_TIMEOUT_MS = 10000; | 70 var CONNECTION_TIMEOUT_MS = 10000; |
| 67 | 71 |
| 68 remoting.SmartReconnector.prototype.reconnect_ = function() { | 72 remoting.SmartReconnector.prototype.reconnect_ = function() { |
| 69 this.cancelPending_(); | 73 this.cancelPending_(); |
| 70 this.disconnectCallback_(); | 74 this.disconnectCallback_(); |
| 71 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
| 72 this.reconnectCallback_(); | 75 this.reconnectCallback_(); |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 remoting.SmartReconnector.prototype.reconnectAsync_ = function() { | 78 remoting.SmartReconnector.prototype.reconnectAsync_ = function() { |
| 76 this.cancelPending_(); | 79 this.cancelPending_(); |
| 77 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 80 this.connectingDialog_.show(); |
| 78 this.pending_ = | 81 this.pending_ = |
| 79 new base.OneShotTimer(this.reconnect_.bind(this), RECONNECT_DELAY_MS); | 82 new base.OneShotTimer(this.reconnect_.bind(this), RECONNECT_DELAY_MS); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 /** | 85 /** |
| 83 * @param {remoting.ClientSession.StateEvent=} event | 86 * @param {remoting.ClientSession.StateEvent=} event |
| 84 */ | 87 */ |
| 85 remoting.SmartReconnector.prototype.stateChanged_ = function(event) { | 88 remoting.SmartReconnector.prototype.stateChanged_ = function(event) { |
| 86 var State = remoting.ClientSession.State; | 89 var State = remoting.ClientSession.State; |
| 87 if (event.previous === State.CONNECTED && event.current === State.FAILED) { | 90 if (event.previous === State.CONNECTED && event.current === State.FAILED) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 this.pending_ = null; | 122 this.pending_ = null; |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 remoting.SmartReconnector.prototype.dispose = function() { | 125 remoting.SmartReconnector.prototype.dispose = function() { |
| 123 this.cancelPending_(); | 126 this.cancelPending_(); |
| 124 base.dispose(this.eventHooks_); | 127 base.dispose(this.eventHooks_); |
| 125 this.eventHooks_ = null; | 128 this.eventHooks_ = null; |
| 126 }; | 129 }; |
| 127 | 130 |
| 128 })(); | 131 })(); |
| OLD | NEW |