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

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