Browse Source

fix(base/connection/reducer): clear 'connection' field

Currently the listeners for disconnected and failed connection events
are unsubscribed as soon as the connection is established, so
the CONNECTION_DISCONNECTED is never triggered which would clear the
'connection' field. This commit will clear the 'connection' state on
CONNECTION_WILL_CONNECT. It's needed anyway given that there's no
guarantee on when and if the async disconnect operation will finish.

One issue caused by the 'connection' not cleared was that
CONNECTION_FAILED was not reduced correctly and the reload screen was
not displayed for the following scenario:
1. Join and leave any working conference.
2. Turn off network connectivity on the device.
3. Wait for CONNECTION_FAILED. The reload screen will not be displayed,
   because CONNECTION_FAILED is not reduced correctly, because the old
   'connection' value is still there.
master
paweldomas 7 years ago
parent
commit
022954b40b
1 changed files with 22 additions and 6 deletions
  1. 22
    6
      react/features/base/connection/reducer.js

+ 22
- 6
react/features/base/connection/reducer.js View File

57
 function _connectionDisconnected(
57
 function _connectionDisconnected(
58
         state: Object,
58
         state: Object,
59
         { connection }: { connection: Object }) {
59
         { connection }: { connection: Object }) {
60
-    if (state.connection !== connection) {
60
+    const connection_ = _getCurrentConnection(state);
61
+
62
+    if (connection_ !== connection) {
61
         return state;
63
         return state;
62
     }
64
     }
63
 
65
 
104
             connection: Object,
106
             connection: Object,
105
             error: ConnectionFailedError
107
             error: ConnectionFailedError
106
         }) {
108
         }) {
107
-
108
-    // The current (similar to getCurrentConference in
109
-    // base/conference/functions.js) connection which is connecting or
110
-    // connected:
111
-    const connection_ = state.connection || state.connecting;
109
+    const connection_ = _getCurrentConnection(state);
112
 
110
 
113
     if (connection_ && connection_ !== connection) {
111
     if (connection_ && connection_ !== connection) {
114
         return state;
112
         return state;
139
         { connection }: { connection: Object }) {
137
         { connection }: { connection: Object }) {
140
     return assign(state, {
138
     return assign(state, {
141
         connecting: connection,
139
         connecting: connection,
140
+
141
+        // We don't care if the previous connection has been closed already,
142
+        // because it's an async process and there's no guarantee if it'll be
143
+        // done before the new one is established.
144
+        connection: undefined,
142
         error: undefined,
145
         error: undefined,
143
         passwordRequired: undefined
146
         passwordRequired: undefined
144
     });
147
     });
188
     };
191
     };
189
 }
192
 }
190
 
193
 
194
+/**
195
+ * The current (similar to getCurrentConference in base/conference/functions.js)
196
+ * connection which is {@code connection} or {@code connecting}.
197
+ *
198
+ * @param {Object} baseConnectionState - The current state of the
199
+ * {@code 'base/connection'} feature.
200
+ * @returns {JitsiConnection} - The current {@code JitsiConnection} if any.
201
+ * @private
202
+ */
203
+function _getCurrentConnection(baseConnectionState: Object): ?Object {
204
+    return baseConnectionState.connection || baseConnectionState.connecting;
205
+}
206
+
191
 /**
207
 /**
192
  * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
208
  * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
193
  * base/connection.
209
  * base/connection.

Loading…
Cancel
Save