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 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * @private
  40. * @returns {void}
  41. */
  42. function _setWakeLock(wakeLock) {
  43. if (wakeLock) {
  44. KeepAwake.activate();
  45. } else {
  46. KeepAwake.deactivate();
  47. }
  48. }