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 { StatusBar } from 'react-native';
|
|
|
|
import { Immersive } from 'react-native-immersive';
|
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
|
2017-01-19 22:22:30 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
2018-02-07 13:34:40 +00:00
|
|
|
CONFERENCE_JOINED,
|
2017-01-19 22:22:30 +00:00
|
|
|
CONFERENCE_LEFT,
|
2017-03-29 12:07:05 +00:00
|
|
|
CONFERENCE_WILL_JOIN,
|
|
|
|
SET_AUDIO_ONLY
|
2017-03-27 09:39:10 +00:00
|
|
|
} from '../../base/conference';
|
|
|
|
import { Platform } from '../../base/react';
|
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
import { _setImmersiveListener as _setImmersiveListenerA } from './actions';
|
2018-02-07 13:34:40 +00:00
|
|
|
import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case CONFERENCE_WILL_JOIN:
|
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
case SET_AUDIO_ONLY: {
|
2018-02-14 18:28:22 +00:00
|
|
|
const result = next(action);
|
2017-10-09 16:13:01 +00:00
|
|
|
const { audioOnly, conference, joining }
|
2018-02-14 18:28:22 +00:00
|
|
|
= store.getState()['features/base/conference'];
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
_setFullScreen(conference || joining ? !audioOnly : false);
|
|
|
|
|
|
|
|
return result;
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case CONFERENCE_FAILED:
|
2018-02-14 18:28:22 +00:00
|
|
|
case CONFERENCE_LEFT: {
|
|
|
|
const result = next(action);
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
_setFullScreen(false);
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-14 18:28:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
2017-01-19 22:22:30 +00:00
|
|
|
});
|
|
|
|
|
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') {
|
|
|
|
const { audioOnly, conference, joining }
|
|
|
|
= state['features/base/conference'];
|
|
|
|
const fullScreen = conference || joining ? !audioOnly : false;
|
|
|
|
|
|
|
|
_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
|
|
|
} else {
|
|
|
|
// On platforms other than Android go with whatever React Native itself
|
|
|
|
// supports.
|
|
|
|
StatusBar.setHidden(fullScreen, 'slide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|