2017-01-17 01:12:43 +00:00
|
|
|
import KeepAwake from 'react-native-keep-awake';
|
|
|
|
|
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_JOINED,
|
2017-03-29 12:07:05 +00:00
|
|
|
CONFERENCE_LEFT,
|
|
|
|
SET_AUDIO_ONLY
|
2017-03-27 09:39:10 +00:00
|
|
|
} from '../../base/conference';
|
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2017-01-17 01:12:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures conference actions and activates or deactivates the
|
|
|
|
* wake lock accordingly. If the wake lock is active, it will prevent the screen
|
|
|
|
* from dimming.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_JOINED: {
|
2017-03-29 12:07:05 +00:00
|
|
|
const { audioOnly } = store.getState()['features/base/conference'];
|
2017-01-17 01:12:43 +00:00
|
|
|
|
2017-03-29 12:07:05 +00:00
|
|
|
_setWakeLock(!audioOnly);
|
2017-01-17 01:12:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
case CONFERENCE_LEFT:
|
2017-01-28 23:28:13 +00:00
|
|
|
_setWakeLock(false);
|
2017-01-17 01:12:43 +00:00
|
|
|
break;
|
2017-03-29 12:07:05 +00:00
|
|
|
|
|
|
|
case SET_AUDIO_ONLY:
|
|
|
|
_setWakeLock(!action.audioOnly);
|
|
|
|
break;
|
2017-01-17 01:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|