您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.5KB

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