ref(mobile/proximity): convert middleware to a state listener
This commit is contained in:
parent
bcb955ea72
commit
d26d1ff925
|
@ -1,43 +1,23 @@
|
||||||
import { NativeModules } from 'react-native';
|
import { NativeModules } from 'react-native';
|
||||||
|
|
||||||
import {
|
import { getCurrentConference } from '../../base/conference';
|
||||||
CONFERENCE_FAILED,
|
import { StateListenerRegistry } from '../../base/redux';
|
||||||
CONFERENCE_JOINED,
|
|
||||||
CONFERENCE_LEFT,
|
|
||||||
SET_AUDIO_ONLY
|
|
||||||
} from '../../base/conference';
|
|
||||||
import { MiddlewareRegistry } from '../../base/redux';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Middleware which enables / disables the proximity sensor in accord with
|
* State listener which enables / disables the proximity sensor based on the
|
||||||
* conference-related actions. If the proximity sensor is enabled, it will dim
|
* current conference state. If the proximity sensor is enabled, it will dim
|
||||||
* the screen and disable touch controls when an object is nearby. The
|
* the screen and disable touch controls when an object is nearby. The
|
||||||
* functionality is enabled when a conference is in audio-only mode.
|
* functionality is enabled when a conference is in audio-only mode.
|
||||||
*
|
|
||||||
* @param {Store} store - The redux store.
|
|
||||||
* @returns {Function}
|
|
||||||
*/
|
*/
|
||||||
MiddlewareRegistry.register(({ getState }) => next => action => {
|
StateListenerRegistry.register(
|
||||||
const result = next(action);
|
/* selector */ state => {
|
||||||
|
const { audioOnly } = state['features/base/conference'];
|
||||||
|
const conference = getCurrentConference(state);
|
||||||
|
|
||||||
switch (action.type) {
|
return Boolean(conference && audioOnly);
|
||||||
case CONFERENCE_FAILED:
|
},
|
||||||
case CONFERENCE_LEFT:
|
/* listener */ proximityEnabled => _setProximityEnabled(proximityEnabled)
|
||||||
_setProximityEnabled(false);
|
);
|
||||||
break;
|
|
||||||
|
|
||||||
case CONFERENCE_JOINED:
|
|
||||||
case SET_AUDIO_ONLY: {
|
|
||||||
const { audioOnly, conference }
|
|
||||||
= getState()['features/base/conference'];
|
|
||||||
|
|
||||||
conference && _setProximityEnabled(audioOnly);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables / disables the proximity sensor. If the proximity sensor is enabled,
|
* Enables / disables the proximity sensor. If the proximity sensor is enabled,
|
||||||
|
|
Loading…
Reference in New Issue