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

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