2017-01-17 01:12:43 +00:00
|
|
|
import KeepAwake from 'react-native-keep-awake';
|
|
|
|
|
2018-05-25 21:10:48 +00:00
|
|
|
import { getCurrentConference } from '../../base/conference';
|
|
|
|
import { StateListenerRegistry } from '../../base/redux';
|
2017-01-17 01:12:43 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-25 21:10:48 +00:00
|
|
|
* State listener that activates or deactivates the wake lock accordingly. If
|
|
|
|
* the wake lock is active, it will prevent the screen from dimming.
|
2017-01-17 01:12:43 +00:00
|
|
|
*/
|
2018-05-25 21:10:48 +00:00
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => {
|
2019-07-31 12:47:52 +00:00
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
2018-05-25 21:10:48 +00:00
|
|
|
const conference = getCurrentConference(state);
|
2017-01-17 01:12:43 +00:00
|
|
|
|
2018-05-25 21:10:48 +00:00
|
|
|
return Boolean(conference && !audioOnly);
|
|
|
|
},
|
|
|
|
/* listener */ wakeLock => _setWakeLock(wakeLock)
|
|
|
|
);
|
2017-01-17 01:12:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates/deactivates the wake lock. If the wake lock is active, it will
|
|
|
|
* prevent the screen from dimming.
|
|
|
|
*
|
|
|
|
* @param {boolean} wakeLock - True to active the wake lock or false to
|
|
|
|
* deactivate it.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2017-01-17 01:12:43 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-01-28 23:28:13 +00:00
|
|
|
function _setWakeLock(wakeLock) {
|
2017-01-17 01:12:43 +00:00
|
|
|
if (wakeLock) {
|
|
|
|
KeepAwake.activate();
|
|
|
|
} else {
|
|
|
|
KeepAwake.deactivate();
|
|
|
|
}
|
|
|
|
}
|