| 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 'use strict'; | 15 'use strict'; |
| 16 | 16 |
| 17 /** @suppress {duplicate} */ | 17 /** @suppress {duplicate} */ |
| 18 var remoting = remoting || {}; | 18 var remoting = remoting || {}; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * @constructor | 21 * @constructor |
| 22 * @param {function()} reconnectCallback | 22 * @param {function()} reconnectCallback |
| 23 * @param {function()} disconnectCallback |
| 23 * @param {remoting.ClientSession} clientSession This represents the current | 24 * @param {remoting.ClientSession} clientSession This represents the current |
| 24 * remote desktop connection. It is used to monitor the changes in | 25 * remote desktop connection. It is used to monitor the changes in |
| 25 * connection state. | 26 * connection state. |
| 26 * @implements {base.Disposable} | 27 * @implements {base.Disposable} |
| 27 */ | 28 */ |
| 28 remoting.SmartReconnector = function(reconnectCallback, clientSession) { | 29 remoting.SmartReconnector = |
| 30 function(reconnectCallback, disconnectCallback, clientSession) { |
| 29 /** @private */ | 31 /** @private */ |
| 30 this.reconnectCallback_ = reconnectCallback; | 32 this.reconnectCallback_ = reconnectCallback; |
| 31 | 33 |
| 32 /** @private */ | 34 /** @private */ |
| 35 this.disconnectCallback_ = disconnectCallback; |
| 36 |
| 37 /** @private */ |
| 33 this.clientSession_ = clientSession; | 38 this.clientSession_ = clientSession; |
| 34 | 39 |
| 35 /** @private */ | 40 /** @private */ |
| 36 this.reconnectTimerId_ = null; | 41 this.reconnectTimerId_ = null; |
| 37 | 42 |
| 38 /** @private */ | 43 /** @private */ |
| 39 this.connectionTimeoutTimerId_ = null; | 44 this.connectionTimeoutTimerId_ = null; |
| 40 | 45 |
| 41 /** @private */ | 46 /** @private */ |
| 42 this.bound_ = { | 47 this.bound_ = { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 // Therefore, delay the connection by |kReconnectDelay| to allow for the network | 65 // Therefore, delay the connection by |kReconnectDelay| to allow for the network |
| 61 // to connect. | 66 // to connect. |
| 62 remoting.SmartReconnector.kReconnectDelay = 2000; | 67 remoting.SmartReconnector.kReconnectDelay = 2000; |
| 63 | 68 |
| 64 // 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. |
| 65 remoting.SmartReconnector.kConnectionTimeout = 10000; | 70 remoting.SmartReconnector.kConnectionTimeout = 10000; |
| 66 | 71 |
| 67 remoting.SmartReconnector.prototype = { | 72 remoting.SmartReconnector.prototype = { |
| 68 reconnect_: function() { | 73 reconnect_: function() { |
| 69 this.cancelPending_(); | 74 this.cancelPending_(); |
| 70 remoting.app.disconnect(); | 75 this.disconnectCallback_(); |
| 71 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 76 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 72 this.reconnectCallback_(); | 77 this.reconnectCallback_(); |
| 73 }, | 78 }, |
| 74 | 79 |
| 75 reconnectAsync_: function() { | 80 reconnectAsync_: function() { |
| 76 this.cancelPending_(); | 81 this.cancelPending_(); |
| 77 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 82 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 78 this.reconnectTimerId_ = window.setTimeout( | 83 this.reconnectTimerId_ = window.setTimeout( |
| 79 this.bound_.reconnect, remoting.SmartReconnector.kReconnectDelay); | 84 this.bound_.reconnect, remoting.SmartReconnector.kReconnectDelay); |
| 80 }, | 85 }, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 128 |
| 124 dispose: function() { | 129 dispose: function() { |
| 125 this.clientSession_.removeEventListener( | 130 this.clientSession_.removeEventListener( |
| 126 remoting.ClientSession.Events.stateChanged, | 131 remoting.ClientSession.Events.stateChanged, |
| 127 this.bound_.stateChanged); | 132 this.bound_.stateChanged); |
| 128 this.clientSession_.removeEventListener( | 133 this.clientSession_.removeEventListener( |
| 129 remoting.ClientSession.Events.videoChannelStateChanged, | 134 remoting.ClientSession.Events.videoChannelStateChanged, |
| 130 this.bound_.videoChannelStateChanged); | 135 this.bound_.videoChannelStateChanged); |
| 131 } | 136 } |
| 132 }; | 137 }; |
| OLD | NEW |