Files
jitsi-meet/react/features/mobile/wake-lock/middleware.js
paweldomas 701552ec8f ref(mobile/wake-lock): convert middleware to a state listener
If CONFERENCE_LEFT would arrive with a delay while we're in
another conference already, then the wake lock could end up in
an incorrect state.
2018-05-30 16:29:27 +02:00

36 lines
1006 B
JavaScript

import KeepAwake from 'react-native-keep-awake';
import { getCurrentConference } from '../../base/conference';
import { StateListenerRegistry } from '../../base/redux';
/**
* State listener that activates or deactivates the wake lock accordingly. If
* the wake lock is active, it will prevent the screen from dimming.
*/
StateListenerRegistry.register(
/* selector */ state => {
const { audioOnly } = state['features/base/conference'];
const conference = getCurrentConference(state);
return Boolean(conference && !audioOnly);
},
/* listener */ wakeLock => _setWakeLock(wakeLock)
);
/**
* 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.
* @private
* @returns {void}
*/
function _setWakeLock(wakeLock) {
if (wakeLock) {
KeepAwake.activate();
} else {
KeepAwake.deactivate();
}
}