Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jitsi-meet/react/features/toolbox/reducer.js

198 lines
4.6 KiB

9 years ago
/* @flow */
import { ReducerRegistry } from '../base/redux';
import {
9 years ago
CLEAR_TOOLBOX_TIMEOUT,
SET_TOOLBOX_ALWAYS_VISIBLE,
9 years ago
SET_SUBJECT,
SET_SUBJECT_SLIDE_IN,
SET_TOOLBAR_BUTTON,
SET_TOOLBAR_HOVERED,
9 years ago
SET_TOOLBOX_TIMEOUT,
SET_TOOLBOX_TIMEOUT_MS,
SET_TOOLBOX_VISIBLE
9 years ago
} from './actionTypes';
import { getDefaultToolbarButtons } from './functions';
declare var interfaceConfig: Object;
/**
9 years ago
* Returns initial state for toolbox's part of Redux store.
9 years ago
*
9 years ago
* @private
9 years ago
* @returns {{
9 years ago
* alwaysVisible: boolean,
* hovered: boolean,
9 years ago
* primaryToolbarButtons: Map,
9 years ago
* secondaryToolbarButtons: Map,
* subject: string,
* subjectSlideIn: boolean,
* timeoutID: number,
* timeoutMS: number,
* visible: boolean
9 years ago
* }}
*/
function _getInitialState() {
9 years ago
// Default toolbox timeout for mobile app.
let timeoutMS = 5000;
9 years ago
if (typeof interfaceConfig !== 'undefined'
&& interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
9 years ago
timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
9 years ago
}
return {
...getDefaultToolbarButtons(),
/**
9 years ago
* The indicator which determines whether the Toolbox should always be
* visible.
9 years ago
*
* @type {boolean}
*/
alwaysVisible: false,
/**
9 years ago
* The indicator which determines whether a Toolbar in the Toolbox is
* hovered.
9 years ago
*
* @type {boolean}
*/
hovered: false,
/**
9 years ago
* The text of the conference subject.
9 years ago
*
* @type {string}
*/
subject: '',
/**
9 years ago
* The indicator which determines whether the subject is sliding in.
9 years ago
*
* @type {boolean}
*/
subjectSlideIn: false,
/**
9 years ago
* A number, non-zero value which identifies the timer created by a call
* to setTimeout() with timeoutMS.
9 years ago
*
* @type {number|null}
*/
9 years ago
timeoutID: null,
9 years ago
/**
9 years ago
* The delay in milliseconds before timeoutID executes (after its
* initialization).
9 years ago
*
* @type {number}
*/
9 years ago
timeoutMS,
9 years ago
/**
9 years ago
* The indicator which determines whether the Toolbox is visible.
9 years ago
*
* @type {boolean}
*/
visible: false
};
}
ReducerRegistry.register(
9 years ago
'features/toolbox',
9 years ago
(state: Object = _getInitialState(), action: Object) => {
switch (action.type) {
9 years ago
case CLEAR_TOOLBOX_TIMEOUT:
9 years ago
return {
...state,
9 years ago
timeoutID: undefined
9 years ago
};
9 years ago
case SET_TOOLBOX_ALWAYS_VISIBLE:
9 years ago
return {
...state,
alwaysVisible: action.alwaysVisible
};
case SET_SUBJECT:
return {
...state,
subject: action.subject
};
case SET_SUBJECT_SLIDE_IN:
return {
...state,
subjectSlideIn: action.subjectSlideIn
};
case SET_TOOLBAR_BUTTON:
return _setButton(state, action);
case SET_TOOLBAR_HOVERED:
return {
...state,
hovered: action.hovered
};
9 years ago
case SET_TOOLBOX_TIMEOUT:
9 years ago
return {
...state,
9 years ago
timeoutID: action.timeoutID,
timeoutMS: action.timeoutMS
9 years ago
};
9 years ago
case SET_TOOLBOX_TIMEOUT_MS:
9 years ago
return {
...state,
9 years ago
timeoutMS: action.timeoutMS
9 years ago
};
9 years ago
case SET_TOOLBOX_VISIBLE:
9 years ago
return {
...state,
visible: action.visible
};
}
return state;
});
/**
* Sets new value of the button.
*
* @param {Object} state - Redux state.
* @param {Object} action - Dispatched action.
* @param {Object} action.button - Object describing toolbar button.
* @param {Object} action.buttonName - The name of the button.
* @private
9 years ago
* @returns {Object}
9 years ago
*/
function _setButton(state, { buttonName, button }): Object {
const {
primaryToolbarButtons,
secondaryToolbarButtons
} = state;
let selectedButton = primaryToolbarButtons.get(buttonName);
let place = 'primaryToolbarButtons';
if (!selectedButton) {
selectedButton = secondaryToolbarButtons.get(buttonName);
place = 'secondaryToolbarButtons';
}
selectedButton = {
...selectedButton,
...button
};
const updatedToolbar = state[place].set(buttonName, selectedButton);
return {
...state,
[place]: new Map(updatedToolbar)
};
}