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.

middleware.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* @flow */
  2. import { SET_VIDEO_AVAILABLE, SET_VIDEO_MUTED } from '../base/media';
  3. import { MiddlewareRegistry } from '../base/redux';
  4. import { setToolbarButton } from './actions';
  5. import { CLEAR_TOOLBOX_TIMEOUT, SET_TOOLBOX_TIMEOUT } from './actionTypes';
  6. /**
  7. * Middleware which intercepts Toolbox actions to handle changes to the
  8. * visibility timeout of the Toolbox.
  9. *
  10. * @param {Store} store - The redux store.
  11. * @returns {Function}
  12. */
  13. MiddlewareRegistry.register(store => next => action => {
  14. switch (action.type) {
  15. case CLEAR_TOOLBOX_TIMEOUT: {
  16. const { timeoutID } = store.getState()['features/toolbox'];
  17. clearTimeout(timeoutID);
  18. break;
  19. }
  20. case SET_TOOLBOX_TIMEOUT: {
  21. const { timeoutID } = store.getState()['features/toolbox'];
  22. const { handler, timeoutMS } = action;
  23. clearTimeout(timeoutID);
  24. const newTimeoutId = setTimeout(handler, timeoutMS);
  25. action.timeoutID = newTimeoutId;
  26. break;
  27. }
  28. case SET_VIDEO_AVAILABLE:
  29. case SET_VIDEO_MUTED:
  30. return _setVideoAvailableOrMuted(store, next, action);
  31. }
  32. return next(action);
  33. });
  34. /**
  35. * Adjusts the state of toolbar's camera button.
  36. *
  37. * @param {Store} store - The redux store.
  38. * @param {Function} next - The redux function to continue dispatching the
  39. * specified {@code action} in the specified {@code store}.
  40. * @param {Object} action - Either {@link SET_VIDEO_AVAILABLE} or
  41. * {@link SET_VIDEO_MUTED}.
  42. * @returns {Object} The new state that is the result of the reduction of the
  43. * specified {@code action}.
  44. */
  45. function _setVideoAvailableOrMuted({ dispatch, getState }, next, action) {
  46. const result = next(action);
  47. const { available, muted } = getState()['features/base/media'].video;
  48. const i18nKey = available ? 'videomute' : 'cameraDisabled';
  49. dispatch(setToolbarButton('camera', {
  50. enabled: available,
  51. i18n: `[content]toolbar.${i18nKey}`,
  52. toggled: available ? muted : true
  53. }));
  54. return result;
  55. }