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.eventHook_ = | 56 this.eventHook_ = |
53 new base.EventHook(clientSession, Events.videoChannelStateChanged, | 57 new base.EventHook(clientSession, Events.videoChannelStateChanged, |
54 this.videoChannelStateChanged_.bind(this)); | 58 this.videoChannelStateChanged_.bind(this)); |
55 }; | 59 }; |
56 | 60 |
57 // The online event only means the network adapter is enabled, but | 61 // The online event only means the network adapter is enabled, but |
58 // it doesn't necessarily mean that we have a working internet connection. | 62 // it doesn't necessarily mean that we have a working internet connection. |
59 // Therefore, delay the connection by |RECONNECT_DELAY_MS| to allow for the | 63 // Therefore, delay the connection by |RECONNECT_DELAY_MS| to allow for the |
60 // network to connect. | 64 // network to connect. |
61 var RECONNECT_DELAY_MS = 2000; | 65 var RECONNECT_DELAY_MS = 2000; |
62 | 66 |
63 // If the video channel is inactive for 10 seconds reconnect the session. | 67 // If the video channel is inactive for 10 seconds reconnect the session. |
64 var CONNECTION_TIMEOUT_MS = 10000; | 68 var CONNECTION_TIMEOUT_MS = 10000; |
65 | 69 |
66 remoting.SmartReconnector.prototype.reconnect_ = function() { | 70 remoting.SmartReconnector.prototype.reconnect_ = function() { |
67 this.cancelPending_(); | 71 this.cancelPending_(); |
68 this.disconnectCallback_(); | 72 this.disconnectCallback_(); |
69 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
70 this.reconnectCallback_(); | 73 this.reconnectCallback_(); |
71 }; | 74 }; |
72 | 75 |
73 remoting.SmartReconnector.prototype.reconnectAsync_ = function() { | 76 remoting.SmartReconnector.prototype.reconnectAsync_ = function() { |
74 this.cancelPending_(); | 77 this.cancelPending_(); |
75 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 78 this.connectingDialog_.show(); |
76 this.pending_ = | 79 this.pending_ = |
77 new base.OneShotTimer(this.reconnect_.bind(this), RECONNECT_DELAY_MS); | 80 new base.OneShotTimer(this.reconnect_.bind(this), RECONNECT_DELAY_MS); |
78 }; | 81 }; |
79 | 82 |
80 /** | 83 /** |
81 * @param {!remoting.Error} reason | 84 * @param {!remoting.Error} reason |
82 */ | 85 */ |
83 remoting.SmartReconnector.prototype.onConnectionDropped = function(reason) { | 86 remoting.SmartReconnector.prototype.onConnectionDropped = function(reason) { |
84 this.cancelPending_(); | 87 this.cancelPending_(); |
85 if (navigator.onLine) { | 88 if (navigator.onLine) { |
(...skipping 28 matching lines...) Expand all Loading... |
114 this.pending_ = null; | 117 this.pending_ = null; |
115 }; | 118 }; |
116 | 119 |
117 remoting.SmartReconnector.prototype.dispose = function() { | 120 remoting.SmartReconnector.prototype.dispose = function() { |
118 this.cancelPending_(); | 121 this.cancelPending_(); |
119 base.dispose(this.eventHook_); | 122 base.dispose(this.eventHook_); |
120 this.eventHook_ = null; | 123 this.eventHook_ = null; |
121 }; | 124 }; |
122 | 125 |
123 })(); | 126 })(); |
OLD | NEW |