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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* @flow */
  2. import { StatusBar } from 'react-native';
  3. import { Immersive } from 'react-native-immersive';
  4. import { APP_STATE_CHANGED } from '../background';
  5. import {
  6. CONFERENCE_FAILED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_JOIN
  9. } from '../base/conference';
  10. import { Platform } from '../base/react';
  11. import { MiddlewareRegistry } from '../base/redux';
  12. /**
  13. * Middleware that captures conference actions and activates or deactivates the
  14. * full screen mode. On iOS it hides the status bar, and on Android it uses the
  15. * immersive mode:
  16. * https://developer.android.com/training/system-ui/immersive.html
  17. * In immersive mode the status and navigation bars are hidden and thus the
  18. * entire screen will be covered by our application.
  19. *
  20. * @param {Store} store - Redux store.
  21. * @returns {Function}
  22. */
  23. MiddlewareRegistry.register(store => next => action => {
  24. let fullScreen = null;
  25. switch (action.type) {
  26. case APP_STATE_CHANGED: {
  27. // Check if we just came back from the background and reenable full
  28. // screen mode if necessary.
  29. if (action.appState === 'active') {
  30. const { conference, audioOnly }
  31. = store.getState()['features/base/conference'];
  32. fullScreen = conference ? !audioOnly : false;
  33. }
  34. break;
  35. }
  36. case CONFERENCE_WILL_JOIN: {
  37. const { audioOnly } = store.getState()['features/base/conference'];
  38. fullScreen = !audioOnly;
  39. break;
  40. }
  41. case CONFERENCE_FAILED:
  42. case CONFERENCE_LEFT:
  43. fullScreen = false;
  44. break;
  45. }
  46. if (fullScreen !== null) {
  47. _setFullScreen(fullScreen)
  48. .catch(err =>
  49. console.warn(`Failed to set full screen mode: ${err}`));
  50. }
  51. return next(action);
  52. });
  53. /**
  54. * Activates/deactivates the full screen mode. On iOS it will hide the status
  55. * bar, and on Android it will turn immersive mode on.
  56. *
  57. * @param {boolean} fullScreen - True to set full screen mode, false to
  58. * deactivate it.
  59. * @private
  60. * @returns {Promise}
  61. */
  62. function _setFullScreen(fullScreen: boolean) {
  63. // XXX The React Native module Immersive is only implemented on Android and
  64. // throws on other platforms.
  65. if (Platform.OS === 'android') {
  66. return fullScreen ? Immersive.on() : Immersive.off();
  67. }
  68. // On platforms other than Android go with whatever React Native itself
  69. // supports.
  70. StatusBar.setHidden(fullScreen, 'slide');
  71. return Promise.resolve();
  72. }