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

middleware.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import KeepAwake from 'react-native-keep-awake';
  2. import {
  3. CONFERENCE_FAILED,
  4. CONFERENCE_JOINED,
  5. CONFERENCE_LEFT
  6. } from '../base/conference';
  7. import { MiddlewareRegistry } from '../base/redux';
  8. /**
  9. * Middleware that captures conference actions and activates or deactivates the
  10. * wake lock accordingly. If the wake lock is active, it will prevent the screen
  11. * from dimming.
  12. *
  13. * @param {Store} store - Redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. switch (action.type) {
  18. case CONFERENCE_JOINED: {
  19. const state = store.getState()['features/base/conference'];
  20. // TODO(saghul): Implement audio-only mode.
  21. if (!state.audioOnly) {
  22. setWakeLock(true);
  23. }
  24. break;
  25. }
  26. case CONFERENCE_FAILED:
  27. case CONFERENCE_LEFT:
  28. setWakeLock(false);
  29. break;
  30. }
  31. return next(action);
  32. });
  33. /**
  34. * Activates/deactivates the wake lock. If the wake lock is active, it will
  35. * prevent the screen from dimming.
  36. *
  37. * @param {boolean} wakeLock - True to active the wake lock or false to
  38. * deactivate it.
  39. * @returns {void}
  40. */
  41. function setWakeLock(wakeLock) {
  42. if (wakeLock) {
  43. KeepAwake.activate();
  44. } else {
  45. KeepAwake.deactivate();
  46. }
  47. }