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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. _setProximityEnabled(action.audioOnly);
  31. break;
  32. }
  33. return next(action);
  34. });
  35. /**
  36. * Enables / disables the proximity sensor. If the proximity sensor is enabled,
  37. * it will dim the screen and disable touch controls when an object is nearby.
  38. *
  39. * @param {boolean} enabled - True to enable the proximity sensor or false to
  40. * disable it.
  41. * @private
  42. * @returns {void}
  43. */
  44. function _setProximityEnabled(enabled) {
  45. NativeModules.Proximity.setEnabled(Boolean(enabled));
  46. }