1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /* @flow */
-
- import { SET_VIDEO_AVAILABLE, SET_VIDEO_MUTED } from '../base/media';
- import { MiddlewareRegistry } from '../base/redux';
-
- import { setToolbarButton } from './actions';
- import { CLEAR_TOOLBOX_TIMEOUT, SET_TOOLBOX_TIMEOUT } from './actionTypes';
-
- /**
- * Middleware which intercepts Toolbox actions to handle changes to the
- * visibility timeout of the Toolbox.
- *
- * @param {Store} store - The redux store.
- * @returns {Function}
- */
- MiddlewareRegistry.register(store => next => action => {
- switch (action.type) {
- case CLEAR_TOOLBOX_TIMEOUT: {
- const { timeoutID } = store.getState()['features/toolbox'];
-
- clearTimeout(timeoutID);
- break;
- }
-
- case SET_TOOLBOX_TIMEOUT: {
- const { timeoutID } = store.getState()['features/toolbox'];
- const { handler, timeoutMS } = action;
-
- clearTimeout(timeoutID);
- const newTimeoutId = setTimeout(handler, timeoutMS);
-
- action.timeoutID = newTimeoutId;
- break;
- }
-
- case SET_VIDEO_AVAILABLE:
- case SET_VIDEO_MUTED:
- return _setVideoAvailableOrMuted(store, next, action);
- }
-
- return next(action);
- });
-
- /**
- * Adjusts the state of toolbar's camera button.
- *
- * @param {Store} store - The redux store.
- * @param {Function} next - The redux function to continue dispatching the
- * specified {@code action} in the specified {@code store}.
- * @param {Object} action - Either {@link SET_VIDEO_AVAILABLE} or
- * {@link SET_VIDEO_MUTED}.
- * @returns {Object} The new state that is the result of the reduction of the
- * specified {@code action}.
- */
- function _setVideoAvailableOrMuted({ dispatch, getState }, next, action) {
- const result = next(action);
-
- const { available, muted } = getState()['features/base/media'].video;
- const i18nKey = available ? 'videomute' : 'cameraDisabled';
-
- dispatch(setToolbarButton('camera', {
- enabled: available,
- i18n: `[content]toolbar.${i18nKey}`,
- toggled: available ? muted : true
- }));
-
- return result;
- }
|