From 3c31a60b3277d45cab48bff810c85520e53aed74 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Wed, 17 May 2017 16:44:28 -0500 Subject: [PATCH] Fix TypeError: Cannot read property 'isGuest' of undefined --- react/features/base/config/reducer.js | 7 +++++ react/features/base/lib-jitsi-meet/actions.js | 8 +---- .../base/lib-jitsi-meet/middleware.js | 31 ++++++++++--------- react/features/base/react/Platform.web.js | 2 +- react/features/toolbox/actions.web.js | 27 ++++++---------- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/react/features/base/config/reducer.js b/react/features/base/config/reducer.js index 15877b0eb..5c1ad5b63 100644 --- a/react/features/base/config/reducer.js +++ b/react/features/base/config/reducer.js @@ -58,6 +58,13 @@ function _setConfig(state, action) { // The config of INITIAL_STATE is meant to override the config // downloaded from the Jitsi Meet deployment because the former contains // values that are mandatory. + // + // FIXME At the time of this writing the hard-coded overriding values + // are specific to mobile/React Native but the source code here is + // executed on Web/React as well. The latter is not a practical problem + // right now because the rest of the Web/React source code does not read + // the overridden properties/values, it still relies on the global + // variable config. ...INITIAL_STATE }; } diff --git a/react/features/base/lib-jitsi-meet/actions.js b/react/features/base/lib-jitsi-meet/actions.js index e6d4eddc8..97bda7fb1 100644 --- a/react/features/base/lib-jitsi-meet/actions.js +++ b/react/features/base/lib-jitsi-meet/actions.js @@ -21,15 +21,9 @@ export function disposeLib() { return (dispatch: Dispatch<*>) => { dispatch({ type: LIB_WILL_DISPOSE }); - // XXX We're wrapping it with Promise because: - // a) to be better aligned with initLib() method which is async; - // b) as currently there is no implementation for it in lib-jitsi-meet - // and there is a big chance it will be async. // TODO Currently, lib-jitsi-meet doesn't have the functionality to // dispose itself. - return ( - Promise.resolve() - .then(() => dispatch({ type: LIB_DID_DISPOSE }))); + dispatch({ type: LIB_DID_DISPOSE }); }; } diff --git a/react/features/base/lib-jitsi-meet/middleware.js b/react/features/base/lib-jitsi-meet/middleware.js index deb6c9cd2..f6f0b5b08 100644 --- a/react/features/base/lib-jitsi-meet/middleware.js +++ b/react/features/base/lib-jitsi-meet/middleware.js @@ -99,22 +99,23 @@ function _setConfig({ dispatch, getState }, next, action) { // disposed of first. // TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet // because lib-jitsi-meet does not implement such functionality. - const disposeLibPromise - = initialized ? dispatch(disposeLib()) : Promise.resolve(); + if (initialized) { + dispatch(disposeLib()); + } - disposeLibPromise.then(() => { - // Let the new config into the Redux store (because initLib will read it - // from there). - next(action); + // Let the new config into the Redux store (because initLib will read it + // from there). + const result = next(action); - // FIXME Obviously, the following is bad design. However, I'm currently - // introducing the features base/config and base/logging and I'm trying - // to minimize the scope of the changes while I'm attempting to preserve - // compatibility with the existing partially React-ified Web source code - // and what was already executing on React Native. Additionally, I do - // not care to load logging_config.js on React Native. - dispatch(setLoggingConfig(window.loggingConfig)); + // FIXME Obviously, the following is bad design. However, I'm currently + // introducing the features base/config and base/logging and I'm trying to + // minimize the scope of the changes while I'm attempting to preserve + // compatibility with the existing partially React-ified Web source code and + // what was already executing on React Native. Additionally, I do not care + // to load logging_config.js on React Native. + dispatch(setLoggingConfig(window.loggingConfig)); - dispatch(initLib()); - }); + dispatch(initLib()); + + return result; } diff --git a/react/features/base/react/Platform.web.js b/react/features/base/react/Platform.web.js index 7066dfb01..b02cd17e2 100644 --- a/react/features/base/react/Platform.web.js +++ b/react/features/base/react/Platform.web.js @@ -1,6 +1,6 @@ /* @flow */ -const userAgent = navigator.userAgent; +const { userAgent } = navigator; let OS; if (userAgent.match(/Android/i)) { diff --git a/react/features/toolbox/actions.web.js b/react/features/toolbox/actions.web.js index fbf7608a8..9396f1949 100644 --- a/react/features/toolbox/actions.web.js +++ b/react/features/toolbox/actions.web.js @@ -172,9 +172,8 @@ export function showDesktopSharingButton(): Function { export function showDialPadButton(show: boolean): Function { return (dispatch: Dispatch<*>) => { const buttonName = 'dialpad'; - const shouldShow = UIUtil.isButtonEnabled(buttonName) && show; - if (shouldShow) { + if (show && UIUtil.isButtonEnabled(buttonName)) { dispatch(setToolbarButton(buttonName, { hidden: false })); @@ -205,11 +204,9 @@ export function showRecordingButton(): Function { export function showSharedVideoButton(): Function { return (dispatch: Dispatch<*>) => { const buttonName = 'sharedvideo'; - const shouldShow - = UIUtil.isButtonEnabled(buttonName) - && !config.disableThirdPartyRequests; - if (shouldShow) { + if (UIUtil.isButtonEnabled(buttonName) + && !config.disableThirdPartyRequests) { dispatch(setToolbarButton(buttonName, { hidden: false })); @@ -218,28 +215,22 @@ export function showSharedVideoButton(): Function { } /** - * Shows SIP call button if it's required and appropriate - * flag is passed. + * Shows SIP call button if it's required and appropriate flag is passed. * * @param {boolean} show - Flag showing whether to show button or not. * @returns {Function} */ export function showSIPCallButton(show: boolean): Function { - return (dispatch: Dispatch<*>) => { + return (dispatch: Dispatch<*>, getState: Function) => { const buttonName = 'sip'; - // hide the button if there is a config to check for user roles, - // based on the token and the the user is guest - const shouldShow - = APP.conference.sipGatewayEnabled() + if (show + && APP.conference.sipGatewayEnabled() && UIUtil.isButtonEnabled(buttonName) - && show && (!config.enableUserRolesBasedOnToken - || !APP.tokenData.isGuest); - - if (shouldShow) { + || !getState()['features/jwt'].isGuest)) { dispatch(setToolbarButton(buttonName, { - hidden: !shouldShow + hidden: false })); } };