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.ts 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import { CONFERENCE_JOINED, CONFERENCE_LEFT } from '../base/conference/actionTypes';
  4. import { SET_CONFIG } from '../base/config/actionTypes';
  5. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  6. import { CAPTURE_EVENTS } from '../remote-control/actionTypes';
  7. import {
  8. disableKeyboardShortcuts,
  9. disposeKeyboardShortcuts,
  10. enableKeyboardShortcuts,
  11. initKeyboardShortcuts
  12. } from './actions';
  13. MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyAction) => {
  14. const { dispatch } = store;
  15. switch (action.type) {
  16. case CAPTURE_EVENTS:
  17. if (action.isCapturingEvents) {
  18. dispatch(disableKeyboardShortcuts());
  19. } else {
  20. dispatch(enableKeyboardShortcuts());
  21. }
  22. return next(action);
  23. case SET_CONFIG: {
  24. const result = next(action);
  25. const state = store.getState();
  26. const { disableShortcuts } = state['features/base/config'];
  27. if (disableShortcuts !== undefined) {
  28. if (disableShortcuts) {
  29. dispatch(disableKeyboardShortcuts());
  30. } else {
  31. dispatch(enableKeyboardShortcuts());
  32. }
  33. }
  34. return result;
  35. }
  36. case CONFERENCE_JOINED:
  37. dispatch(initKeyboardShortcuts());
  38. break;
  39. case CONFERENCE_LEFT:
  40. dispatch(disposeKeyboardShortcuts());
  41. }
  42. return next(action);
  43. });