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

middleware.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = store.getState()['features/base/conference'];
  31. fullScreen = conference ? !conference.audioOnly : false;
  32. }
  33. break;
  34. }
  35. case CONFERENCE_WILL_JOIN: {
  36. const conference = store.getState()['features/base/conference'];
  37. fullScreen = !conference.audioOnly;
  38. break;
  39. }
  40. case CONFERENCE_FAILED:
  41. case CONFERENCE_LEFT:
  42. fullScreen = false;
  43. break;
  44. }
  45. if (fullScreen !== null) {
  46. _setFullScreen(fullScreen)
  47. .catch(err =>
  48. console.warn(`Failed to set full screen mode: ${err}`));
  49. }
  50. return next(action);
  51. });
  52. /**
  53. * Activates/deactivates the full screen mode. On iOS it will hide the status
  54. * bar, and on Android it will turn immersive mode on.
  55. *
  56. * @param {boolean} fullScreen - True to set full screen mode, false to
  57. * deactivate it.
  58. * @private
  59. * @returns {Promise}
  60. */
  61. function _setFullScreen(fullScreen: boolean) {
  62. // XXX The React Native module Immersive is only implemented on Android and
  63. // throws on other platforms.
  64. if (Platform.OS === 'android') {
  65. return fullScreen ? Immersive.on() : Immersive.off();
  66. }
  67. // On platforms other than Android go with whatever React Native itself
  68. // supports.
  69. StatusBar.setHidden(fullScreen, 'slide');
  70. return Promise.resolve();
  71. }