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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { NativeModules } from 'react-native';
  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 which enables / disables the proximity sensor in accord with
  11. * conference-related actions. If the proximity sensor is enabled, it will dim
  12. * the screen and disable touch controls when an object is nearby. The
  13. * functionality is enabled when a conference is in audio-only mode.
  14. *
  15. * @param {Store} store - Redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(store => next => action => {
  19. switch (action.type) {
  20. case CONFERENCE_JOINED: {
  21. const { audioOnly } = store.getState()['features/base/conference'];
  22. _setProximityEnabled(audioOnly);
  23. break;
  24. }
  25. case CONFERENCE_FAILED:
  26. case CONFERENCE_LEFT:
  27. _setProximityEnabled(false);
  28. break;
  29. case SET_AUDIO_ONLY: {
  30. const { conference } = store.getState()['features/base/conference'];
  31. conference && _setProximityEnabled(action.audioOnly);
  32. break;
  33. }
  34. }
  35. return next(action);
  36. });
  37. /**
  38. * Enables / disables the proximity sensor. If the proximity sensor is enabled,
  39. * it will dim the screen and disable touch controls when an object is nearby.
  40. *
  41. * @param {boolean} enabled - True to enable the proximity sensor or false to
  42. * disable it.
  43. * @private
  44. * @returns {void}
  45. */
  46. function _setProximityEnabled(enabled) {
  47. NativeModules.Proximity.setEnabled(Boolean(enabled));
  48. }