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

12345678910111213141516171819202122232425262728293031323334
  1. import { NativeModules } from 'react-native';
  2. import { getCurrentConference } from '../../base/conference';
  3. import { StateListenerRegistry } from '../../base/redux';
  4. /**
  5. * State listener which enables / disables the proximity sensor based on the
  6. * current conference state. If the proximity sensor is enabled, it will dim
  7. * the screen and disable touch controls when an object is nearby. The
  8. * functionality is enabled when the current audio device is the earpiece.
  9. */
  10. StateListenerRegistry.register(
  11. /* selector */ state => {
  12. const { devices } = state['features/mobile/audio-mode'];
  13. const selectedDevice = devices.filter(d => d.selected)[0];
  14. const conference = getCurrentConference(state);
  15. return Boolean(conference && selectedDevice?.type === 'EARPIECE');
  16. },
  17. /* listener */ proximityEnabled => _setProximityEnabled(proximityEnabled)
  18. );
  19. /**
  20. * Enables / disables the proximity sensor. If the proximity sensor is enabled,
  21. * it will dim the screen and disable touch controls when an object is nearby.
  22. *
  23. * @param {boolean} enabled - True to enable the proximity sensor or false to
  24. * disable it.
  25. * @private
  26. * @returns {void}
  27. */
  28. function _setProximityEnabled(enabled) {
  29. NativeModules.Proximity.setEnabled(Boolean(enabled));
  30. }