2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-01-31 20:58:48 +00:00
|
|
|
import { CONFERENCE_FAILED } from '../base/conference';
|
2017-09-19 19:20:29 +00:00
|
|
|
import {
|
|
|
|
CONNECTION_ESTABLISHED,
|
|
|
|
CONNECTION_FAILED,
|
|
|
|
CONNECTION_WILL_CONNECT
|
|
|
|
} from '../base/connection';
|
2017-02-28 03:21:50 +00:00
|
|
|
import {
|
|
|
|
isFatalJitsiConnectionError,
|
|
|
|
JitsiConferenceErrors,
|
|
|
|
JitsiConnectionErrors
|
2017-02-19 00:42:11 +00:00
|
|
|
} from '../base/lib-jitsi-meet';
|
2017-04-22 22:57:08 +00:00
|
|
|
import { assign, ReducerRegistry, set } from '../base/redux';
|
2017-01-31 20:58:48 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
|
|
|
|
SUSPEND_DETECTED
|
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces the redux actions of the feature overlay.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
|
|
|
ReducerRegistry.register('features/overlay', (state = {}, action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
return _conferenceFailed(state, action);
|
|
|
|
|
|
|
|
case CONNECTION_ESTABLISHED:
|
2017-10-24 22:26:56 +00:00
|
|
|
return _connectionEstablished(state);
|
2017-01-31 20:58:48 +00:00
|
|
|
|
|
|
|
case CONNECTION_FAILED:
|
|
|
|
return _connectionFailed(state, action);
|
|
|
|
|
2017-09-19 19:20:29 +00:00
|
|
|
case CONNECTION_WILL_CONNECT:
|
|
|
|
return _connectionWillConnect(state, action);
|
|
|
|
|
2017-01-31 20:58:48 +00:00
|
|
|
case MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED:
|
|
|
|
return _mediaPermissionPromptVisibilityChanged(state, action);
|
|
|
|
|
|
|
|
case SUSPEND_DETECTED:
|
2017-10-24 22:26:56 +00:00
|
|
|
return _suspendDetected(state);
|
2017-01-31 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces a specific redux action CONFERENCE_FAILED of the feature overlay.
|
2017-01-31 20:58:48 +00:00
|
|
|
*
|
2017-09-19 19:20:29 +00:00
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @param {Action} action - The redux action CONFERENCE_FAILED to reduce.
|
|
|
|
* @private
|
2017-02-19 00:42:11 +00:00
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
2017-10-05 12:41:35 +00:00
|
|
|
function _conferenceFailed(state, { error: { message, name } }) {
|
|
|
|
if (name === JitsiConferenceErrors.FOCUS_LEFT
|
|
|
|
|| name === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-01-31 20:58:48 +00:00
|
|
|
haveToReload: true,
|
|
|
|
isNetworkFailure: false,
|
2017-10-05 12:41:35 +00:00
|
|
|
|
|
|
|
// FIXME There is no message associated with CONFERENCE_FAILED at
|
|
|
|
// the time of this writing. In jitsi-meet the action creator
|
|
|
|
// conferenceFailed neither accepts an argument message nor defines
|
|
|
|
// a property message on the error. In lib-jitsi-meet
|
|
|
|
// CONFERENCE_FAILED emissions mostly do not provide a message with
|
|
|
|
// the exception of at least one which provides an Error, not a
|
|
|
|
// string.
|
2017-05-09 05:15:43 +00:00
|
|
|
reason: message
|
2017-01-31 20:58:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces a specific redux action CONNECTION_ESTABLISHED of the feature
|
2017-01-31 20:58:48 +00:00
|
|
|
* overlay.
|
|
|
|
*
|
2017-09-19 19:20:29 +00:00
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @private
|
2017-02-19 00:42:11 +00:00
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
|
|
|
function _connectionEstablished(state) {
|
2017-04-22 22:57:08 +00:00
|
|
|
return set(state, 'connectionEstablished', true);
|
2017-01-31 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces a specific redux action CONNECTION_FAILED of the feature overlay.
|
2017-01-31 20:58:48 +00:00
|
|
|
*
|
2017-09-19 19:20:29 +00:00
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @param {Action} action - The redux action CONNECTION_FAILED to reduce.
|
|
|
|
* @private
|
2017-02-19 00:42:11 +00:00
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
2017-09-24 21:51:43 +00:00
|
|
|
function _connectionFailed(state, { error }) {
|
2017-02-19 00:42:11 +00:00
|
|
|
if (isFatalJitsiConnectionError(error)) {
|
2017-09-24 21:51:43 +00:00
|
|
|
const { message } = error;
|
|
|
|
|
2017-09-19 19:20:29 +00:00
|
|
|
logger.error(`FATAL XMPP connection error: ${message}`);
|
2017-01-31 20:58:48 +00:00
|
|
|
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-01-31 20:58:48 +00:00
|
|
|
haveToReload: true,
|
2017-02-19 00:42:11 +00:00
|
|
|
|
|
|
|
// From all of the cases above only CONNECTION_DROPPED_ERROR is
|
|
|
|
// considered a network type of failure.
|
2017-01-31 20:58:48 +00:00
|
|
|
isNetworkFailure:
|
2017-09-24 21:51:43 +00:00
|
|
|
error.name === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
|
2017-05-09 05:15:43 +00:00
|
|
|
reason: `xmpp-conn-dropped: ${message}`
|
2017-01-31 20:58:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces a specific redux action CONNECTION_WILL_CONNECT in the feature
|
|
|
|
* overlay. Clears the redux state related to the XMPP connection's status.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @param {Action} action - The redux action to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature overlay after reducing the
|
2017-10-01 06:35:19 +00:00
|
|
|
* specified {@code action} in the feature overlay.
|
2017-09-19 19:20:29 +00:00
|
|
|
*/
|
|
|
|
function _connectionWillConnect(
|
|
|
|
state,
|
|
|
|
action) { // eslint-disable-line no-unused-vars
|
|
|
|
return assign(state, {
|
|
|
|
connectionEstablished: undefined,
|
|
|
|
haveToReload: undefined,
|
|
|
|
isNetworkFailure: undefined,
|
|
|
|
reason: undefined
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
|
2017-02-19 00:42:11 +00:00
|
|
|
* the feature overlay.
|
2017-01-31 20:58:48 +00:00
|
|
|
*
|
2017-09-19 19:20:29 +00:00
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @param {Action} action - The redux action to reduce.
|
|
|
|
* @private
|
2017-02-19 00:42:11 +00:00
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
function _mediaPermissionPromptVisibilityChanged(
|
|
|
|
state,
|
|
|
|
{ browser, isVisible }) {
|
2017-04-22 22:57:08 +00:00
|
|
|
return assign(state, {
|
2017-10-04 22:36:09 +00:00
|
|
|
browser,
|
|
|
|
isMediaPermissionPromptVisible: isVisible
|
2017-01-31 20:58:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-19 19:20:29 +00:00
|
|
|
* Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
|
2017-01-31 20:58:48 +00:00
|
|
|
*
|
2017-09-19 19:20:29 +00:00
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @private
|
2017-02-19 00:42:11 +00:00
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
2017-01-31 20:58:48 +00:00
|
|
|
*/
|
|
|
|
function _suspendDetected(state) {
|
2017-04-22 22:57:08 +00:00
|
|
|
return set(state, 'suspendDetected', true);
|
2017-01-31 20:58:48 +00:00
|
|
|
}
|