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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import ImmersiveMode from 'react-native-immersive-mode';
  2. import { IStore } from '../../app/types';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app/actionTypes';
  4. import { getCurrentConference } from '../../base/conference/functions';
  5. import { isAnyDialogOpen } from '../../base/dialog/functions';
  6. import { FULLSCREEN_ENABLED } from '../../base/flags/constants';
  7. import { getFeatureFlag } from '../../base/flags/functions';
  8. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  9. import StateListenerRegistry from '../../base/redux/StateListenerRegistry';
  10. import { _setImmersiveSubscription } from './actions';
  11. import logger from './logger';
  12. type BarVisibilityType = {
  13. navigationBottomBar: boolean;
  14. statusBar: boolean;
  15. };
  16. type ImmersiveListener = (visibility: BarVisibilityType) => void;
  17. /**
  18. * Middleware that captures conference actions and activates or deactivates the
  19. * full screen mode. On iOS it hides the status bar, and on Android it uses the
  20. * immersive mode:
  21. * https://developer.android.com/training/system-ui/immersive.html
  22. * In immersive mode the status and navigation bars are hidden and thus the
  23. * entire screen will be covered by our application.
  24. *
  25. * @param {Store} store - The redux store.
  26. * @returns {Function}
  27. */
  28. MiddlewareRegistry.register(store => next => action => {
  29. switch (action.type) {
  30. case APP_WILL_MOUNT: {
  31. _setImmersiveListener(store, _onImmersiveChange.bind(undefined, store));
  32. break;
  33. }
  34. case APP_WILL_UNMOUNT:
  35. _setImmersiveListener(store, undefined);
  36. break;
  37. }
  38. return next(action);
  39. });
  40. StateListenerRegistry.register(
  41. /* selector */ state => {
  42. const { enabled: audioOnly } = state['features/base/audio-only'];
  43. const conference = getCurrentConference(state);
  44. const dialogOpen = isAnyDialogOpen(state);
  45. const fullscreenEnabled = getFeatureFlag(state, FULLSCREEN_ENABLED, true);
  46. return conference ? !audioOnly && !dialogOpen && fullscreenEnabled : false;
  47. },
  48. /* listener */ fullScreen => _setFullScreen(fullScreen)
  49. );
  50. /**
  51. * Handler for Immersive mode changes. This will be called when Android's
  52. * immersive mode changes. This can happen without us wanting, so re-evaluate if
  53. * immersive mode is desired and reactivate it if needed.
  54. *
  55. * @param {Object} store - The redux store.
  56. * @private
  57. * @returns {void}
  58. */
  59. function _onImmersiveChange({ getState }: IStore) {
  60. const state = getState();
  61. const { appState } = state['features/background'];
  62. if (appState === 'active') {
  63. const { enabled: audioOnly } = state['features/base/audio-only'];
  64. const conference = getCurrentConference(state);
  65. const dialogOpen = isAnyDialogOpen(state);
  66. const fullscreenEnabled = getFeatureFlag(state, FULLSCREEN_ENABLED, true);
  67. const fullScreen = conference ? !audioOnly && !dialogOpen && fullscreenEnabled : false;
  68. _setFullScreen(fullScreen);
  69. }
  70. }
  71. /**
  72. * Activates/deactivates the full screen mode. On iOS it will hide the status
  73. * bar, and on Android it will turn immersive mode on.
  74. *
  75. * @param {boolean} fullScreen - True to set full screen mode, false to
  76. * deactivate it.
  77. * @private
  78. * @returns {void}
  79. */
  80. function _setFullScreen(fullScreen: boolean) {
  81. logger.info(`Setting full-screen mode: ${fullScreen}`);
  82. ImmersiveMode.fullLayout(fullScreen);
  83. ImmersiveMode.setBarMode(fullScreen ? 'Full' : 'Normal');
  84. }
  85. /**
  86. * Notifies the feature filmstrip that the action
  87. * {@link _SET_IMMERSIVE_LISTENER} is being dispatched within a specific redux
  88. * store.
  89. *
  90. * @param {Store} store - The redux store in which the specified action is being
  91. * dispatched.
  92. * @param {Function} listener - Listener for immersive state.
  93. * @private
  94. * @returns {Object} The value returned by {@code next(action)}.
  95. */
  96. function _setImmersiveListener({ dispatch, getState }: IStore, listener?: ImmersiveListener) {
  97. const { subscription } = getState()['features/full-screen'];
  98. subscription?.remove();
  99. dispatch(_setImmersiveSubscription(listener ? ImmersiveMode.addEventListener(listener) : undefined));
  100. }