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.
This commit is contained in:
paweldomas 2018-06-06 16:31:08 +02:00
parent 8c7a3f16b1
commit 022954b40b
1 changed files with 22 additions and 6 deletions

View File

@ -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.