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.web.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { IStore } from '../../app/types';
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app/actionTypes';
  3. import { CONFERENCE_JOINED } from '../conference/actionTypes';
  4. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  5. import { clientResized } from './actions';
  6. /**
  7. * Dimensions change handler.
  8. */
  9. let handler: undefined | ((this: Window, ev: UIEvent) => any);
  10. /**
  11. * Middleware that handles window dimension changes.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. const result = next(action);
  18. switch (action.type) {
  19. case APP_WILL_UNMOUNT: {
  20. _appWillUnmount();
  21. break;
  22. }
  23. case APP_WILL_MOUNT:
  24. _appWillMount(store);
  25. break;
  26. case CONFERENCE_JOINED: {
  27. const { clientHeight = 0, clientWidth = 0 } = store.getState()['features/base/responsive-ui'];
  28. if (!clientHeight && !clientWidth) {
  29. const {
  30. innerHeight,
  31. innerWidth
  32. } = window;
  33. store.dispatch(clientResized(innerWidth, innerHeight));
  34. }
  35. break;
  36. }
  37. }
  38. return result;
  39. });
  40. /**
  41. * Notifies this feature that the action {@link APP_WILL_MOUNT} is being
  42. * dispatched within a specific redux {@code store}.
  43. *
  44. * @param {Store} store - The redux store in which the specified {@code action}
  45. * is being dispatched.
  46. * @private
  47. * @returns {void}
  48. */
  49. function _appWillMount(store: IStore) {
  50. handler = () => {
  51. const {
  52. innerHeight,
  53. innerWidth
  54. } = window;
  55. store.dispatch(clientResized(innerWidth, innerHeight));
  56. };
  57. window.addEventListener('resize', handler);
  58. }
  59. /**
  60. * Notifies this feature that the action {@link APP_WILL_UNMOUNT} is being
  61. * dispatched within a specific redux {@code store}.
  62. *
  63. * @private
  64. * @returns {void}
  65. */
  66. function _appWillUnmount() {
  67. handler && window.removeEventListener('resize', handler);
  68. handler = undefined;
  69. }