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 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 remoting.ClientSession.Events.videoChannelStateChanged, | 55 remoting.ClientSession.Events.videoChannelStateChanged, |
56 this.bound_.videoChannelStateChanged); | 56 this.bound_.videoChannelStateChanged); |
57 }; | 57 }; |
58 | 58 |
59 // The online event only means the network adapter is enabled, but | 59 // The online event only means the network adapter is enabled, but |
60 // it doesn't necessarily mean that we have a working internet connection. | 60 // it doesn't necessarily mean that we have a working internet connection. |
61 // Therefore, delay the connection by |kReconnectDelay| to allow for the network | 61 // Therefore, delay the connection by |kReconnectDelay| to allow for the network |
62 // to connect. | 62 // to connect. |
63 remoting.SmartReconnector.kReconnectDelay = 2000; | 63 remoting.SmartReconnector.kReconnectDelay = 2000; |
64 | 64 |
65 // If no frames are received from the server for more than |kConnectionTimeout|, | 65 // If the video channel is inactive for 10 seconds reconnect the session. |
66 // disconnect the session. | |
67 remoting.SmartReconnector.kConnectionTimeout = 10000; | 66 remoting.SmartReconnector.kConnectionTimeout = 10000; |
68 | 67 |
69 remoting.SmartReconnector.prototype = { | 68 remoting.SmartReconnector.prototype = { |
70 reconnect_: function() { | 69 reconnect_: function() { |
71 this.cancelPending_(); | 70 this.cancelPending_(); |
72 remoting.disconnect(); | 71 remoting.disconnect(); |
73 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 72 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
74 this.connector_.reconnect(); | 73 this.connector_.reconnect(); |
75 }, | 74 }, |
76 | 75 |
(...skipping 13 matching lines...) Expand all Loading... | |
90 this.cancelPending_(); | 89 this.cancelPending_(); |
91 if (navigator.onLine) { | 90 if (navigator.onLine) { |
92 this.reconnect_(); | 91 this.reconnect_(); |
93 } else { | 92 } else { |
94 window.addEventListener('online', this.bound_.reconnectAsync, false); | 93 window.addEventListener('online', this.bound_.reconnectAsync, false); |
95 } | 94 } |
96 } | 95 } |
97 }, | 96 }, |
98 | 97 |
99 /** | 98 /** |
100 * @param {boolean} active This function is called if no frames are received | 99 * @param {boolean} active True if the video channel is active. |
101 * on the client for more than 1 second. | |
102 */ | 100 */ |
103 videoChannelStateChanged_: function (active) { | 101 videoChannelStateChanged_: function (active) { |
104 this.cancelPending_(); | 102 this.cancelPending_(); |
105 if (!active) { | 103 if (!active) { |
106 // If the channel becomes inactive due to a lack of network connection, | 104 window.addEventListener( |
107 // wait for it to go online. The plugin will try to reconnect the video | |
108 // channel once it is online. If the video channels doesn't finish | |
109 // reconnecting within the timeout, tear down the session and reconnect. | |
110 if (navigator.onLine) { | |
Wez
2014/05/23 20:26:40
Would it be better to just have a shorter timeout
Sergey Ulanov
2014/05/23 20:38:36
navigator.onLine=true just tells us that the machi
| |
111 this.reconnect_(); | |
112 } else { | |
113 window.addEventListener( | |
114 'online', this.bound_.startReconnectTimeout, false); | 105 'online', this.bound_.startReconnectTimeout, false); |
115 } | |
116 } | 106 } |
117 }, | 107 }, |
118 | 108 |
119 startReconnectTimeout_: function () { | 109 startReconnectTimeout_: function () { |
120 this.cancelPending_(); | 110 this.cancelPending_(); |
121 this.connectionTimeoutTimerId_ = window.setTimeout( | 111 this.connectionTimeoutTimerId_ = window.setTimeout( |
122 this.bound_.reconnect, remoting.SmartReconnector.kConnectionTimeout); | 112 this.bound_.reconnect, remoting.SmartReconnector.kConnectionTimeout); |
123 }, | 113 }, |
124 | 114 |
125 cancelPending_: function() { | 115 cancelPending_: function() { |
126 window.removeEventListener( | 116 window.removeEventListener( |
127 'online', this.bound_.startReconnectTimeout, false); | 117 'online', this.bound_.startReconnectTimeout, false); |
128 window.removeEventListener('online', this.bound_.reconnectAsync, false); | 118 window.removeEventListener('online', this.bound_.reconnectAsync, false); |
129 window.clearTimeout(this.reconnectTimerId_); | 119 window.clearTimeout(this.reconnectTimerId_); |
130 window.clearTimeout(this.connectionTimeoutTimerId_); | 120 window.clearTimeout(this.connectionTimeoutTimerId_); |
131 this.reconnectTimerId_ = null; | 121 this.reconnectTimerId_ = null; |
132 this.connectionTimeoutTimerId_ = null; | 122 this.connectionTimeoutTimerId_ = null; |
133 }, | 123 }, |
134 | 124 |
135 dispose: function() { | 125 dispose: function() { |
136 this.clientSession_.removeEventListener( | 126 this.clientSession_.removeEventListener( |
137 remoting.ClientSession.Events.stateChanged, | 127 remoting.ClientSession.Events.stateChanged, |
138 this.bound_.stateChanged); | 128 this.bound_.stateChanged); |
139 this.clientSession_.removeEventListener( | 129 this.clientSession_.removeEventListener( |
140 remoting.ClientSession.Events.videoChannelStateChanged, | 130 remoting.ClientSession.Events.videoChannelStateChanged, |
141 this.bound_.videoChannelStateChanged); | 131 this.bound_.videoChannelStateChanged); |
142 } | 132 } |
143 }; | 133 }; |
OLD | NEW |