2017-03-07 03:43:41 +00:00
|
|
|
/* global APP */
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2017-04-13 00:23:43 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
LOCK_STATE_CHANGED,
|
|
|
|
SET_PASSWORD_FAILED
|
|
|
|
} from '../base/conference';
|
2017-04-18 21:49:52 +00:00
|
|
|
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
|
2017-03-07 03:43:41 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2017-04-13 00:23:43 +00:00
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
import { _showPasswordDialog } from './actions';
|
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures conference failed and checks for password required
|
|
|
|
* error and requests a dialog for user to enter password.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_FAILED: {
|
2017-04-18 21:49:52 +00:00
|
|
|
const { conference, error } = action;
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
if (conference && error === JitsiConferenceErrors.PASSWORD_REQUIRED) {
|
|
|
|
// XXX Temporary solution while some components are not listening
|
|
|
|
// for lock state updates in redux.
|
2017-03-07 03:43:41 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
2017-04-13 00:23:43 +00:00
|
|
|
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, true);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
store.dispatch(_showPasswordDialog(conference));
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 21:49:52 +00:00
|
|
|
|
|
|
|
case LOCK_STATE_CHANGED:
|
2017-04-13 00:23:43 +00:00
|
|
|
// TODO Remove this logic when all components interested in the lock
|
|
|
|
// state change event are moved into react/redux.
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-18 21:49:52 +00:00
|
|
|
|
2017-04-13 00:23:43 +00:00
|
|
|
case SET_PASSWORD_FAILED:
|
2017-04-18 21:49:52 +00:00
|
|
|
return _setPasswordFailed(store, next, action);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* Handles errors that occur when a password fails to be set.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
|
|
|
* @param {Store} store - The Redux store in which the specified action is being
|
|
|
|
* dispatched.
|
|
|
|
* @param {Dispatch} next - The Redux dispatch function to dispatch the
|
|
|
|
* specified action to the specified store.
|
|
|
|
* @param {Action} action - The Redux action SET_PASSWORD_ERROR which has the
|
|
|
|
* error type that should be handled.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified action.
|
|
|
|
*/
|
2017-04-18 21:49:52 +00:00
|
|
|
function _setPasswordFailed(store, next, action) {
|
2017-04-13 00:23:43 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
2017-04-18 21:49:52 +00:00
|
|
|
// TODO Remove this logic when displaying of error messages on web is
|
|
|
|
// handled through react/redux.
|
|
|
|
const { error } = action;
|
|
|
|
let title;
|
|
|
|
let message;
|
|
|
|
|
|
|
|
if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
|
2017-04-13 00:23:43 +00:00
|
|
|
logger.warn('room passwords not supported');
|
2017-04-18 21:49:52 +00:00
|
|
|
title = 'dialog.warning';
|
|
|
|
message = 'dialog.passwordNotSupported';
|
2017-04-13 00:23:43 +00:00
|
|
|
} else {
|
2017-04-18 21:49:52 +00:00
|
|
|
logger.warn('setting password failed', error);
|
|
|
|
title = 'dialog.lockTitle';
|
|
|
|
message = 'dialog.lockMessage';
|
2017-04-13 00:23:43 +00:00
|
|
|
}
|
2017-04-18 21:49:52 +00:00
|
|
|
APP.UI.messageHandler.showError(title, message);
|
2017-04-13 00:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|