2024-03-08 09:59:02 -06:00
|
|
|
import { batch } from 'react-redux';
|
2022-10-19 14:38:38 +03:00
|
|
|
import { AnyAction } from 'redux';
|
2017-04-01 00:52:40 -05:00
|
|
|
|
2024-02-28 13:52:04 -06:00
|
|
|
import { IReduxState } from '../app/types';
|
|
|
|
|
import { OVERWRITE_CONFIG, SET_CONFIG, UPDATE_CONFIG } from '../base/config/actionTypes';
|
2024-03-08 09:59:02 -06:00
|
|
|
import { NotifyClickButton } from '../base/config/configType';
|
2022-10-19 14:38:38 +03:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2024-02-29 17:39:13 -06:00
|
|
|
import { I_AM_VISITOR_MODE } from '../visitors/actionTypes';
|
|
|
|
|
import { iAmVisitor } from '../visitors/functions';
|
2017-04-01 00:52:40 -05:00
|
|
|
|
2018-03-06 16:28:19 -08:00
|
|
|
import {
|
|
|
|
|
CLEAR_TOOLBOX_TIMEOUT,
|
2024-03-08 09:59:02 -06:00
|
|
|
SET_BUTTONS_WITH_NOTIFY_CLICK,
|
2022-09-27 10:10:28 +03:00
|
|
|
SET_FULL_SCREEN,
|
2024-03-08 09:59:02 -06:00
|
|
|
SET_PARTICIPANT_MENU_BUTTONS_WITH_NOTIFY_CLICK,
|
2024-02-28 13:52:04 -06:00
|
|
|
SET_TOOLBAR_BUTTONS,
|
2022-09-27 10:10:28 +03:00
|
|
|
SET_TOOLBOX_TIMEOUT
|
2018-03-06 16:28:19 -08:00
|
|
|
} from './actionTypes';
|
2024-05-17 09:53:08 -05:00
|
|
|
import { setMainToolbarThresholds } from './actions.web';
|
2024-02-29 17:39:13 -06:00
|
|
|
import { TOOLBAR_BUTTONS, VISITORS_MODE_BUTTONS } from './constants';
|
2024-03-08 09:59:02 -06:00
|
|
|
import { NOTIFY_CLICK_MODE } from './types';
|
2018-03-06 16:28:19 -08:00
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
import './subscriber.web';
|
2021-07-13 09:50:08 +03:00
|
|
|
|
2017-04-01 00:52:40 -05:00
|
|
|
/**
|
|
|
|
|
* Middleware which intercepts Toolbox actions to handle changes to the
|
|
|
|
|
* visibility timeout of the Toolbox.
|
|
|
|
|
*
|
2017-07-16 03:44:07 -05:00
|
|
|
* @param {Store} store - The redux store.
|
2017-04-01 00:52:40 -05:00
|
|
|
* @returns {Function}
|
|
|
|
|
*/
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
case CLEAR_TOOLBOX_TIMEOUT: {
|
|
|
|
|
const { timeoutID } = store.getState()['features/toolbox'];
|
|
|
|
|
|
2022-10-19 14:38:38 +03:00
|
|
|
clearTimeout(timeoutID ?? undefined);
|
2017-04-01 00:52:40 -05:00
|
|
|
break;
|
|
|
|
|
}
|
2024-02-28 13:52:04 -06:00
|
|
|
case UPDATE_CONFIG:
|
|
|
|
|
case OVERWRITE_CONFIG:
|
2024-02-29 17:39:13 -06:00
|
|
|
case I_AM_VISITOR_MODE:
|
2024-02-28 13:52:04 -06:00
|
|
|
case SET_CONFIG: {
|
|
|
|
|
const result = next(action);
|
2024-03-08 09:59:02 -06:00
|
|
|
const { dispatch, getState } = store;
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
if (action.type !== I_AM_VISITOR_MODE) {
|
|
|
|
|
const {
|
|
|
|
|
customToolbarButtons,
|
|
|
|
|
buttonsWithNotifyClick,
|
|
|
|
|
participantMenuButtonsWithNotifyClick,
|
|
|
|
|
customParticipantMenuButtons
|
|
|
|
|
} = state['features/base/config'];
|
|
|
|
|
|
|
|
|
|
batch(() => {
|
2024-05-17 09:53:08 -05:00
|
|
|
if (action.type !== I_AM_VISITOR_MODE) {
|
|
|
|
|
dispatch(setMainToolbarThresholds());
|
|
|
|
|
}
|
2024-03-08 09:59:02 -06:00
|
|
|
dispatch({
|
|
|
|
|
type: SET_BUTTONS_WITH_NOTIFY_CLICK,
|
|
|
|
|
buttonsWithNotifyClick: _buildButtonsArray(buttonsWithNotifyClick, customToolbarButtons)
|
|
|
|
|
});
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SET_PARTICIPANT_MENU_BUTTONS_WITH_NOTIFY_CLICK,
|
|
|
|
|
participantMenuButtonsWithNotifyClick:
|
|
|
|
|
_buildButtonsArray(participantMenuButtonsWithNotifyClick, customParticipantMenuButtons)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toolbarButtons = _getToolbarButtons(state);
|
2024-02-28 13:52:04 -06:00
|
|
|
|
2024-03-08 09:59:02 -06:00
|
|
|
dispatch({
|
2024-02-28 13:52:04 -06:00
|
|
|
type: SET_TOOLBAR_BUTTONS,
|
|
|
|
|
toolbarButtons
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2017-04-01 00:52:40 -05:00
|
|
|
|
2018-03-06 16:28:19 -08:00
|
|
|
case SET_FULL_SCREEN:
|
|
|
|
|
return _setFullScreen(next, action);
|
|
|
|
|
|
2017-04-01 00:52:40 -05:00
|
|
|
case SET_TOOLBOX_TIMEOUT: {
|
|
|
|
|
const { timeoutID } = store.getState()['features/toolbox'];
|
2022-10-19 14:38:38 +03:00
|
|
|
const { handler, timeoutMS }: { handler: Function; timeoutMS: number; } = action;
|
2017-04-01 00:52:40 -05:00
|
|
|
|
2022-10-19 14:38:38 +03:00
|
|
|
clearTimeout(timeoutID ?? undefined);
|
2018-04-09 07:03:26 +02:00
|
|
|
action.timeoutID = setTimeout(handler, timeoutMS);
|
2017-04-01 00:52:40 -05:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-07-24 15:56:57 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-01 00:52:40 -05:00
|
|
|
return next(action);
|
|
|
|
|
});
|
2017-07-16 03:44:07 -05:00
|
|
|
|
2019-03-19 16:42:25 +01:00
|
|
|
type DocumentElement = {
|
2022-10-19 14:38:38 +03:00
|
|
|
requestFullscreen?: Function;
|
|
|
|
|
webkitRequestFullscreen?: Function;
|
|
|
|
|
};
|
2019-03-19 16:42:25 +01:00
|
|
|
|
2018-03-06 16:28:19 -08:00
|
|
|
/**
|
|
|
|
|
* Makes an external request to enter or exit full screen mode.
|
|
|
|
|
*
|
|
|
|
|
* @param {Dispatch} next - The redux dispatch function to dispatch the
|
|
|
|
|
* specified action to the specified store.
|
|
|
|
|
* @param {Action} action - The redux action SET_FULL_SCREEN which is being
|
|
|
|
|
* dispatched in the specified store.
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
|
*/
|
2022-10-19 14:38:38 +03:00
|
|
|
function _setFullScreen(next: Function, action: AnyAction) {
|
2021-11-04 22:10:43 +01:00
|
|
|
const result = next(action);
|
|
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
const { fullScreen } = action;
|
2018-03-06 16:28:19 -08:00
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
if (fullScreen) {
|
|
|
|
|
const documentElement: DocumentElement
|
|
|
|
|
= document.documentElement || {};
|
2018-10-03 11:29:19 +02:00
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
if (typeof documentElement.requestFullscreen === 'function') {
|
|
|
|
|
documentElement.requestFullscreen();
|
|
|
|
|
} else if (
|
|
|
|
|
typeof documentElement.webkitRequestFullscreen === 'function') {
|
|
|
|
|
documentElement.webkitRequestFullscreen();
|
2021-11-04 22:10:43 +01:00
|
|
|
}
|
2018-10-03 11:29:19 +02:00
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
2018-10-03 11:29:19 +02:00
|
|
|
|
2023-06-12 10:48:16 +02:00
|
|
|
if (typeof document.exitFullscreen === 'function') {
|
|
|
|
|
document.exitFullscreen();
|
|
|
|
|
} else if (typeof document.webkitExitFullscreen === 'function') {
|
|
|
|
|
document.webkitExitFullscreen();
|
2018-03-06 16:28:19 -08:00
|
|
|
}
|
|
|
|
|
|
2021-11-04 22:10:43 +01:00
|
|
|
return result;
|
2018-03-06 16:28:19 -08:00
|
|
|
}
|
2024-02-28 13:52:04 -06:00
|
|
|
|
2024-03-08 09:59:02 -06:00
|
|
|
/**
|
|
|
|
|
* Common logic to gather buttons that have to notify the api when clicked.
|
|
|
|
|
*
|
2024-12-19 13:09:42 +00:00
|
|
|
* @param {Array} buttonsWithNotifyClick - The array of system buttons that need to notify the api.
|
2024-03-08 09:59:02 -06:00
|
|
|
* @param {Array} customButtons - The custom buttons.
|
|
|
|
|
* @returns {Array}
|
|
|
|
|
*/
|
|
|
|
|
function _buildButtonsArray(
|
|
|
|
|
buttonsWithNotifyClick?: NotifyClickButton[],
|
|
|
|
|
customButtons?: {
|
|
|
|
|
icon: string;
|
|
|
|
|
id: string;
|
|
|
|
|
text: string;
|
|
|
|
|
}[]
|
|
|
|
|
): Map<string, NOTIFY_CLICK_MODE> {
|
|
|
|
|
const customButtonsWithNotifyClick = customButtons?.map(
|
|
|
|
|
({ id }) => ([ id, NOTIFY_CLICK_MODE.ONLY_NOTIFY ]) as [string, NOTIFY_CLICK_MODE]) ?? [];
|
|
|
|
|
const buttons = (Array.isArray(buttonsWithNotifyClick) ? buttonsWithNotifyClick : [])
|
|
|
|
|
.filter(button => typeof button === 'string' || (typeof button === 'object' && typeof button.key === 'string'))
|
|
|
|
|
.map(button => {
|
|
|
|
|
if (typeof button === 'string') {
|
|
|
|
|
return [ button, NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY ] as [string, NOTIFY_CLICK_MODE];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
button.key,
|
|
|
|
|
button.preventExecution ? NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY : NOTIFY_CLICK_MODE.ONLY_NOTIFY
|
|
|
|
|
] as [string, NOTIFY_CLICK_MODE];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new Map([ ...customButtonsWithNotifyClick, ...buttons ]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 13:52:04 -06:00
|
|
|
/**
|
|
|
|
|
* Returns the list of enabled toolbar buttons.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
|
* @returns {Array<string>} - The list of enabled toolbar buttons.
|
|
|
|
|
*/
|
|
|
|
|
function _getToolbarButtons(state: IReduxState): Array<string> {
|
|
|
|
|
const { toolbarButtons, customToolbarButtons } = state['features/base/config'];
|
|
|
|
|
const customButtons = customToolbarButtons?.map(({ id }) => id);
|
2024-02-29 17:39:13 -06:00
|
|
|
let buttons = Array.isArray(toolbarButtons) ? toolbarButtons : TOOLBAR_BUTTONS;
|
2024-02-28 13:52:04 -06:00
|
|
|
|
2024-02-29 17:39:13 -06:00
|
|
|
if (iAmVisitor(state)) {
|
|
|
|
|
buttons = VISITORS_MODE_BUTTONS.filter(button => buttons.indexOf(button) > -1);
|
|
|
|
|
}
|
2024-02-28 13:52:04 -06:00
|
|
|
|
|
|
|
|
if (customButtons) {
|
|
|
|
|
return [ ...buttons, ...customButtons ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
|
}
|