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

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