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

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