| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 | /* @flow */
import Recording from '../../../modules/UI/recording/Recording';
import SideContainerToggler
    from '../../../modules/UI/side_pannels/SideContainerToggler';
import UIUtil from '../../../modules/UI/util/UIUtil';
import UIEvents from '../../../service/UI/UIEvents';
import {
    changeLocalRaiseHand,
    clearToolboxTimeout,
    setSubjectSlideIn,
    setToolbarButton,
    setToolboxTimeout,
    setToolboxTimeoutMS,
    setToolboxVisible,
    toggleFullScreen,
    toggleToolbarButton
} from './actions.native';
import { SET_DEFAULT_TOOLBOX_BUTTONS } from './actionTypes';
import { getDefaultToolboxButtons } from './functions';
declare var $: Function;
declare var APP: Object;
declare var config: Object;
declare var interfaceConfig: Object;
export * from './actions.native';
/**
 * Checks whether desktop sharing is enabled and whether
 * we have params to start automatically sharing.
 *
 * @returns {Function}
 */
export function checkAutoEnableDesktopSharing(): Function {
    return () => {
        // XXX Should use dispatcher to toggle screensharing but screensharing
        // hasn't been React-ified yet.
        if (UIUtil.isButtonEnabled('desktop')
                && config.autoEnableDesktopSharing) {
            APP.UI.eventEmitter.emit(UIEvents.TOGGLE_SCREENSHARING);
        }
    };
}
/**
 * Docks/undocks the Toolbox.
 *
 * @param {boolean} dock - True if dock, false otherwise.
 * @returns {Function}
 */
export function dockToolbox(dock: boolean): Function {
    return (dispatch: Dispatch<*>, getState: Function) => {
        if (interfaceConfig.filmStripOnly) {
            return;
        }
        const { timeoutMS, visible } = getState()['features/toolbox'];
        if (dock) {
            // First make sure the toolbox is shown.
            visible || dispatch(showToolbox());
            dispatch(clearToolboxTimeout());
        } else if (visible) {
            dispatch(
                setToolboxTimeout(
                    () => dispatch(hideToolbox()),
                    timeoutMS));
        } else {
            dispatch(showToolbox());
        }
    };
}
/**
 * Returns button on mount/unmount handlers with dispatch function stored in
 * closure.
 *
 * @param {Function} dispatch - Redux action dispatcher.
 * @param {Function} getState - The function fetching the Redux state.
 * @returns {Object} Button on mount/unmount handlers.
 * @private
 */
function _getButtonHandlers(dispatch, getState) {
    const localRaiseHandHandler
        = (...args) => dispatch(changeLocalRaiseHand(...args));
    const toggleFullScreenHandler
        = (...args) => dispatch(toggleFullScreen(...args));
    return {
        /**
         * Mount handler for desktop button.
         *
         * @type {Object}
         */
        desktop: {
            onMount: () => dispatch(showDesktopSharingButton())
        },
        /**
         * Mount/Unmount handler for toggling fullscreen button.
         *
         * @type {Object}
         */
        fullscreen: {
            onMount: () =>
                APP.UI.addListener(
                    UIEvents.FULLSCREEN_TOGGLED,
                    toggleFullScreenHandler),
            onUnmount: () =>
                APP.UI.removeListener(
                    UIEvents.FULLSCREEN_TOGGLED,
                    toggleFullScreenHandler)
        },
        /**
         * Mount handler for profile button.
         *
         * @type {Object}
         */
        profile: {
            onMount: () =>
                getState()['features/jwt']
                    || dispatch(setProfileButtonUnclickable(true))
        },
        /**
         * Mount/Unmount handlers for raisehand button.
         *
         * @type {button}
         */
        raisehand: {
            onMount: () =>
                APP.UI.addListener(
                    UIEvents.LOCAL_RAISE_HAND_CHANGED,
                    localRaiseHandHandler),
            onUnmount: () =>
                APP.UI.removeListener(
                    UIEvents.LOCAL_RAISE_HAND_CHANGED,
                    localRaiseHandHandler)
        },
        /**
         * Mount handler for recording button.
         *
         * @type {Object}
         */
        recording: {
            onMount: () =>
                config.enableRecording && dispatch(showRecordingButton())
        }
    };
}
/**
 * Hides the toolbox.
 *
 * @param {boolean} force - True to force the hiding of the toolbox without
 * caring about the extended toolbar side panels.
 * @returns {Function}
 */
export function hideToolbox(force: boolean = false): Function {
    return (dispatch: Dispatch<*>, getState: Function) => {
        const state = getState();
        const {
            alwaysVisible,
            hovered,
            timeoutMS
        } = state['features/toolbox'];
        if (alwaysVisible) {
            return;
        }
        dispatch(clearToolboxTimeout());
        if (!force
                && (hovered
                    || state['features/jwt'].callOverlayVisible
                    || SideContainerToggler.isVisible())) {
            dispatch(
                setToolboxTimeout(
                    () => dispatch(hideToolbox()),
                    timeoutMS));
        } else {
            dispatch(setToolboxVisible(false));
            dispatch(setSubjectSlideIn(false));
        }
    };
}
/**
 * Sets the default toolbar buttons of the Toolbox.
 *
 * @returns {Function}
 */
export function setDefaultToolboxButtons(): Function {
    return (dispatch: Dispatch, getState: Function) => {
        // Save dispatch function in closure.
        const buttonHandlers = _getButtonHandlers(dispatch, getState);
        const toolboxButtons = getDefaultToolboxButtons(buttonHandlers);
        dispatch({
            type: SET_DEFAULT_TOOLBOX_BUTTONS,
            ...toolboxButtons
        });
    };
}
/**
 * Signals that unclickable property of profile button should change its value.
 *
 * @param {boolean} unclickable - Shows whether button is unclickable.
 * @returns {Function}
 */
export function setProfileButtonUnclickable(unclickable: boolean): Function {
    return (dispatch: Dispatch<*>) => {
        const buttonName = 'profile';
        dispatch(setToolbarButton(buttonName, {
            unclickable
        }));
        UIUtil.removeTooltip(document.getElementById('toolbar_button_profile'));
    };
}
/**
 * Shows desktop sharing button.
 *
 * @returns {Function}
 */
export function showDesktopSharingButton(): Function {
    return (dispatch: Dispatch<*>) => {
        const buttonName = 'desktop';
        const visible
            = APP.conference.isDesktopSharingEnabled
                && UIUtil.isButtonEnabled(buttonName);
        dispatch(setToolbarButton(buttonName, {
            hidden: !visible
        }));
    };
}
/**
 * Shows or hides the dialpad button.
 *
 * @param {boolean} show - Flag showing whether to show button or not.
 * @returns {Function}
 */
export function showDialPadButton(show: boolean): Function {
    return (dispatch: Dispatch<*>) => {
        const buttonName = 'dialpad';
        if (show && UIUtil.isButtonEnabled(buttonName)) {
            dispatch(setToolbarButton(buttonName, {
                hidden: false
            }));
        }
    };
}
/**
 * Shows recording button.
 *
 * @returns {Function}
 */
export function showRecordingButton(): Function {
    return (dispatch: Dispatch<*>) => {
        dispatch(setToolbarButton('recording', {
            hidden: false
        }));
        Recording.initRecordingButton();
    };
}
/**
 * Shows or hides the 'shared video' button.
 *
 * @returns {Function}
 */
export function showSharedVideoButton(): Function {
    return (dispatch: Dispatch<*>) => {
        const buttonName = 'sharedvideo';
        if (UIUtil.isButtonEnabled(buttonName)
                && !config.disableThirdPartyRequests) {
            dispatch(setToolbarButton(buttonName, {
                hidden: false
            }));
        }
    };
}
/**
 * Shows the dial out 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 showDialOutButton(show: boolean): Function {
    return (dispatch: Dispatch<*>, getState: Function) => {
        const buttonName = 'dialout';
        if (show
                && APP.conference.sipGatewayEnabled()
                && UIUtil.isButtonEnabled(buttonName)
                && (!config.enableUserRolesBasedOnToken
                    || !getState()['features/jwt'].isGuest)) {
            dispatch(setToolbarButton(buttonName, {
                hidden: false
            }));
        }
    };
}
/**
 * Shows the toolbox for specified timeout.
 *
 * @param {number} timeout - Timeout for showing the toolbox.
 * @returns {Function}
 */
export function showToolbox(timeout: number = 0): Object {
    return (dispatch: Dispatch<*>, getState: Function) => {
        const state = getState();
        const {
            alwaysVisible,
            enabled,
            timeoutMS,
            visible
        } = state['features/toolbox'];
        if (enabled && !visible) {
            dispatch(setToolboxVisible(true));
            dispatch(setSubjectSlideIn(true));
            // If the Toolbox is always visible, there's no need for a timeout
            // to toggle its visibility.
            if (!alwaysVisible) {
                dispatch(
                    setToolboxTimeout(
                        () => dispatch(hideToolbox()),
                        timeout || timeoutMS));
                dispatch(setToolboxTimeoutMS(interfaceConfig.TOOLBAR_TIMEOUT));
            }
        }
    };
}
/**
 * Event handler for side toolbar container toggled event.
 *
 * @param {string} containerId - ID of the container.
 * @returns {Function}
 */
export function toggleSideToolbarContainer(containerId: string): Function {
    return (dispatch: Dispatch, getState: Function) => {
        const { secondaryToolbarButtons } = getState()['features/toolbox'];
        for (const key of secondaryToolbarButtons.keys()) {
            const isButtonEnabled = UIUtil.isButtonEnabled(key);
            const button = secondaryToolbarButtons.get(key);
            if (isButtonEnabled
                    && button.sideContainerId
                    && button.sideContainerId === containerId) {
                dispatch(toggleToolbarButton(key));
                break;
            }
        }
    };
}
 |