@ -1,5 +1,4 @@
/* global APP */
const logger = require ( 'jitsi-meet-logger' ) . getLogger ( _ _filename ) ;
import UIEvents from '../../../service/UI/UIEvents' ;
@ -8,11 +7,13 @@ import {
LOCK _STATE _CHANGED ,
SET _PASSWORD _FAILED
} from '../base/conference' ;
import JitsiMeetJS from '../base/lib-jitsi-meet' ;
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet' ;
import { MiddlewareRegistry } from '../base/redux' ;
import { _showPasswordDialog } from './actions' ;
const logger = require ( 'jitsi-meet-logger' ) . getLogger ( _ _filename ) ;
/ * *
* Middleware that captures conference failed and checks for password required
* error and requests a dialog for user to enter password .
@ -21,41 +22,39 @@ import { _showPasswordDialog } from './actions';
* @ returns { Function }
* /
MiddlewareRegistry . register ( store => next => action => {
switch ( action . type ) {
case CONFERENCE _FAILED : {
const JitsiConferenceErrors = JitsiMeetJS . errors . conference ;
const { conference , error } = action ;
if ( action . conference
&& JitsiConferenceErrors . PASSWORD _REQUIRED === action . error ) {
// XXX temporary solution while some components are not listening
// for lock state updates in redux
if ( conference && error === JitsiConferenceErrors . PASSWORD _REQUIRED ) {
// XXX Temporary solution while some components are not listening
// for lock state updates in redux.
if ( typeof APP !== 'undefined' ) {
APP . UI . emitEvent ( UIEvents . TOGGLE _ROOM _LOCK , true ) ;
}
store . dispatch ( _showPasswordDialog ( action . conference ) ) ;
store . dispatch ( _showPasswordDialog ( conference ) ) ;
}
break ;
}
case LOCK _STATE _CHANGED : {
case LOCK _STATE _CHANGED :
// 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 ;
}
case SET _PASSWORD _FAILED :
return _notifySetPasswordError ( store , next , action ) ;
return _setPasswordFailed ( store , next , action ) ;
}
return next ( action ) ;
} ) ;
/ * *
* Handles errors that occur when a password is failed to be set .
* Handles errors that occur when a password fails to be set .
*
* @ param { Store } store - The Redux store in which the specified action is being
* dispatched .
@ -67,20 +66,24 @@ MiddlewareRegistry.register(store => next => action => {
* @ returns { Object } The new state that is the result of the reduction of the
* specified action .
* /
function _notifySetPasswordError ( store , next , action ) {
function _setPasswordFailed ( store , next , action ) {
if ( typeof APP !== 'undefined' ) {
// TODO remove this logic when displaying of error messages on web is
// handled through react/redux
if ( action . error
=== JitsiMeetJS . errors . conference . PASSWORD _NOT _SUPPORTED ) {
// 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 ) {
logger . warn ( 'room passwords not supported' ) ;
APP . UI . messageHandler . showError (
'dialog.warning' , 'dialog.passwordNotSupported' ) ;
title = 'dialog.warning' ;
message = 'dialog.passwordNotSupported' ;
} else {
logger . warn ( 'setting password failed' , action . error ) ;
APP . UI . messageHandler . showError (
'dialog.lockTitle' , 'dialog.lockMessage' ) ;
logger . warn ( 'setting password failed' , error ) ;
title = 'dialog.lockTitle' ;
message = 'dialog.lockMessage' ;
}
APP . UI . messageHandler . showError ( title , message ) ;
}
return next ( action ) ;