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

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