2017-03-30 08:12:38 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
|
|
|
|
2018-05-25 20:41:43 +00:00
|
|
|
import { getCurrentConference } from '../../base/conference';
|
|
|
|
import { StateListenerRegistry } from '../../base/redux';
|
2017-03-30 08:12:38 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-25 20:41:43 +00:00
|
|
|
* State listener which enables / disables the proximity sensor based on the
|
|
|
|
* current conference state. If the proximity sensor is enabled, it will dim
|
2017-03-30 08:12:38 +00:00
|
|
|
* the screen and disable touch controls when an object is nearby. The
|
2019-08-14 11:02:19 +00:00
|
|
|
* functionality is enabled when the current audio device is the earpiece.
|
2017-03-30 08:12:38 +00:00
|
|
|
*/
|
2018-05-25 20:41:43 +00:00
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => {
|
2019-08-14 11:02:19 +00:00
|
|
|
const { devices } = state['features/mobile/audio-mode'];
|
|
|
|
const selectedDevice = devices.filter(d => d.selected)[0];
|
2018-05-25 20:41:43 +00:00
|
|
|
const conference = getCurrentConference(state);
|
2017-03-30 08:12:38 +00:00
|
|
|
|
2019-08-14 11:02:19 +00:00
|
|
|
return Boolean(conference && selectedDevice?.type === 'EARPIECE');
|
2018-05-25 20:41:43 +00:00
|
|
|
},
|
|
|
|
/* listener */ proximityEnabled => _setProximityEnabled(proximityEnabled)
|
|
|
|
);
|
2017-03-30 08:12:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables / disables the proximity sensor. If the proximity sensor is enabled,
|
|
|
|
* it will dim the screen and disable touch controls when an object is nearby.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - True to enable the proximity sensor or false to
|
|
|
|
* disable it.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _setProximityEnabled(enabled) {
|
|
|
|
NativeModules.Proximity.setEnabled(Boolean(enabled));
|
|
|
|
}
|