From 022954b40bd8498307b7a89c98bc2a161d0a9258 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Wed, 6 Jun 2018 16:31:08 +0200 Subject: [PATCH] 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. --- react/features/base/connection/reducer.js | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/react/features/base/connection/reducer.js b/react/features/base/connection/reducer.js index fd50bd033..3d08176b2 100644 --- a/react/features/base/connection/reducer.js +++ b/react/features/base/connection/reducer.js @@ -57,7 +57,9 @@ ReducerRegistry.register( function _connectionDisconnected( state: Object, { connection }: { connection: Object }) { - if (state.connection !== connection) { + const connection_ = _getCurrentConnection(state); + + if (connection_ !== connection) { return state; } @@ -104,11 +106,7 @@ function _connectionFailed( connection: Object, error: ConnectionFailedError }) { - - // The current (similar to getCurrentConference in - // base/conference/functions.js) connection which is connecting or - // connected: - const connection_ = state.connection || state.connecting; + const connection_ = _getCurrentConnection(state); if (connection_ && connection_ !== connection) { return state; @@ -139,6 +137,11 @@ function _connectionWillConnect( { connection }: { connection: Object }) { return assign(state, { connecting: connection, + + // We don't care if the previous connection has been closed already, + // because it's an async process and there's no guarantee if it'll be + // done before the new one is established. + connection: undefined, error: undefined, passwordRequired: undefined }); @@ -188,6 +191,19 @@ function _constructOptions(locationURL: URL) { }; } +/** + * The current (similar to getCurrentConference in base/conference/functions.js) + * connection which is {@code connection} or {@code connecting}. + * + * @param {Object} baseConnectionState - The current state of the + * {@code 'base/connection'} feature. + * @returns {JitsiConnection} - The current {@code JitsiConnection} if any. + * @private + */ +function _getCurrentConnection(baseConnectionState: Object): ?Object { + return baseConnectionState.connection || baseConnectionState.connecting; +} + /** * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature * base/connection.