2018-02-07 13:34:40 +00:00
|
|
|
// @flow
|
2017-02-06 21:32:03 +00:00
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
import { Immersive } from 'react-native-immersive';
|
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app';
|
2018-05-24 20:30:59 +00:00
|
|
|
import { getCurrentConference } from '../../base/conference';
|
2020-02-20 13:01:23 +00:00
|
|
|
import { isAnyDialogOpen } from '../../base/dialog/functions';
|
2017-03-27 09:39:10 +00:00
|
|
|
import { Platform } from '../../base/react';
|
2018-05-24 20:30:59 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../../base/redux';
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { _setImmersiveListener as _setImmersiveListenerA } from './actions';
|
2018-02-07 13:34:40 +00:00
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures conference actions and activates or deactivates the
|
2017-02-06 21:32:03 +00:00
|
|
|
* full screen mode. On iOS it hides the status bar, and on Android it uses the
|
2017-01-19 22:22:30 +00:00
|
|
|
* immersive mode:
|
|
|
|
* https://developer.android.com/training/system-ui/immersive.html
|
|
|
|
* In immersive mode the status and navigation bars are hidden and thus the
|
|
|
|
* entire screen will be covered by our application.
|
|
|
|
*
|
2017-08-04 21:06:42 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-01-19 22:22:30 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2018-02-14 18:28:22 +00:00
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2017-01-19 22:22:30 +00:00
|
|
|
switch (action.type) {
|
2018-02-07 13:34:40 +00:00
|
|
|
case _SET_IMMERSIVE_LISTENER:
|
2018-02-14 18:28:22 +00:00
|
|
|
return _setImmersiveListenerF(store, next, action);
|
2018-02-07 13:34:40 +00:00
|
|
|
|
|
|
|
case APP_WILL_MOUNT: {
|
2018-02-14 18:28:22 +00:00
|
|
|
const result = next(action);
|
2017-02-08 16:25:49 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
store.dispatch(
|
|
|
|
_setImmersiveListenerA(_onImmersiveChange.bind(undefined, store)));
|
|
|
|
|
|
|
|
return result;
|
2018-02-07 13:34:40 +00:00
|
|
|
}
|
2018-02-14 18:28:22 +00:00
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
case APP_WILL_UNMOUNT:
|
2018-02-14 18:28:22 +00:00
|
|
|
store.dispatch(_setImmersiveListenerA(undefined));
|
2018-02-07 13:34:40 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
2017-01-19 22:22:30 +00:00
|
|
|
});
|
|
|
|
|
2018-05-24 20:30:59 +00:00
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => {
|
2019-07-31 12:47:52 +00:00
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
2018-05-24 20:30:59 +00:00
|
|
|
const conference = getCurrentConference(state);
|
2020-02-20 13:01:23 +00:00
|
|
|
const dialogOpen = isAnyDialogOpen(state);
|
2018-05-24 20:30:59 +00:00
|
|
|
|
2020-02-20 13:01:23 +00:00
|
|
|
return conference ? !audioOnly && !dialogOpen : false;
|
2018-05-24 20:30:59 +00:00
|
|
|
},
|
|
|
|
/* listener */ fullScreen => _setFullScreen(fullScreen)
|
|
|
|
);
|
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
/**
|
|
|
|
* Handler for Immersive mode changes. This will be called when Android's
|
|
|
|
* immersive mode changes. This can happen without us wanting, so re-evaluate if
|
|
|
|
* immersive mode is desired and reactivate it if needed.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onImmersiveChange({ getState }) {
|
|
|
|
const state = getState();
|
|
|
|
const { appState } = state['features/background'];
|
|
|
|
|
|
|
|
if (appState === 'active') {
|
2019-07-31 12:47:52 +00:00
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
2018-05-24 20:15:32 +00:00
|
|
|
const conference = getCurrentConference(state);
|
2020-02-20 13:01:23 +00:00
|
|
|
const dialogOpen = isAnyDialogOpen(state);
|
|
|
|
const fullScreen = conference ? !audioOnly && !dialogOpen : false;
|
2018-02-07 13:34:40 +00:00
|
|
|
|
|
|
|
_setFullScreen(fullScreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Activates/deactivates the full screen mode. On iOS it will hide the status
|
2017-02-06 21:32:03 +00:00
|
|
|
* bar, and on Android it will turn immersive mode on.
|
2017-01-19 22:22:30 +00:00
|
|
|
*
|
2017-02-06 21:32:03 +00:00
|
|
|
* @param {boolean} fullScreen - True to set full screen mode, false to
|
2017-01-19 22:22:30 +00:00
|
|
|
* deactivate it.
|
2017-02-06 21:32:03 +00:00
|
|
|
* @private
|
2018-02-07 13:34:40 +00:00
|
|
|
* @returns {void}
|
2017-01-19 22:22:30 +00:00
|
|
|
*/
|
2017-02-06 21:32:03 +00:00
|
|
|
function _setFullScreen(fullScreen: boolean) {
|
|
|
|
// XXX The React Native module Immersive is only implemented on Android and
|
|
|
|
// throws on other platforms.
|
2017-01-19 22:22:30 +00:00
|
|
|
if (Platform.OS === 'android') {
|
2018-02-07 13:34:40 +00:00
|
|
|
fullScreen ? Immersive.on() : Immersive.off();
|
2018-02-14 18:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the feature filmstrip that the action
|
|
|
|
* {@link _SET_IMMERSIVE_LISTENER} is being dispatched within a specific redux
|
|
|
|
* store.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified action is being
|
|
|
|
* dispatched.
|
|
|
|
* @param {Dispatch} next - The redux dispatch function to dispatch the
|
|
|
|
* specified action to the specified store.
|
|
|
|
* @param {Action} action - The redux action {@code _SET_IMMERSIVE_LISTENER}
|
|
|
|
* which is being dispatched in the specified store.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
*/
|
|
|
|
function _setImmersiveListenerF({ getState }, next, action) {
|
|
|
|
// XXX The React Native module Immersive is only implemented on Android and
|
|
|
|
// throws on other platforms.
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
// Remove the old Immersive listener and add the new one.
|
|
|
|
const { listener: oldListener } = getState()['features/full-screen'];
|
|
|
|
const result = next(action);
|
|
|
|
const { listener: newListener } = getState()['features/full-screen'];
|
|
|
|
|
|
|
|
if (oldListener !== newListener) {
|
|
|
|
oldListener && Immersive.removeImmersiveListener(oldListener);
|
|
|
|
newListener && Immersive.addImmersiveListener(newListener);
|
|
|
|
}
|
2018-02-07 13:34:40 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
return result;
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
return next(action);
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|