2017-10-02 23:08:07 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-10-16 19:58:38 +00:00
|
|
|
import { sendAnalyticsEvent } from '../../analytics';
|
2017-03-29 10:24:18 +00:00
|
|
|
import { setLastN } from '../../base/conference';
|
2017-08-02 15:00:51 +00:00
|
|
|
import { setVideoMuted, VIDEO_MUTISM_AUTHORITY } from '../../base/media';
|
2017-02-10 16:13:39 +00:00
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
import { _SET_APP_STATE_LISTENER, APP_STATE_CHANGED } from './actionTypes';
|
2017-02-08 11:37:52 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-10 16:13:39 +00:00
|
|
|
* Sets the listener to be used with React Native's AppState API.
|
2017-02-08 11:37:52 +00:00
|
|
|
*
|
2017-02-10 16:13:39 +00:00
|
|
|
* @param {Function} listener - Function to be set as the change event listener.
|
|
|
|
* @protected
|
|
|
|
* @returns {{
|
|
|
|
* type: _SET_APP_STATE_LISTENER,
|
|
|
|
* listener: Function
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function _setAppStateListener(listener: ?Function) {
|
|
|
|
return {
|
|
|
|
type: _SET_APP_STATE_LISTENER,
|
|
|
|
listener
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the app should mute video because it's now running in the
|
|
|
|
* background, or unmute it because it came back from the background. If video
|
|
|
|
* was already muted nothing will happen; otherwise, it will be muted. When
|
|
|
|
* coming back from the background the previous state will be restored.
|
2017-02-08 11:37:52 +00:00
|
|
|
*
|
2017-02-10 16:13:39 +00:00
|
|
|
* @param {boolean} muted - True if video should be muted; false, otherwise.
|
|
|
|
* @protected
|
2017-02-08 11:37:52 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-02-10 16:13:39 +00:00
|
|
|
export function _setBackgroundVideoMuted(muted: boolean) {
|
2017-10-02 23:08:07 +00:00
|
|
|
return (dispatch: Dispatch<*>, getState: Function) => {
|
2017-03-29 10:24:18 +00:00
|
|
|
// Disable remote video when we mute by setting lastN to 0. Skip it if
|
|
|
|
// the conference is in audio-only mode, as it's already configured to
|
|
|
|
// have no video. Leave it as undefined when unmuting, the default value
|
|
|
|
// for last N will be chosen automatically.
|
2017-02-16 12:53:50 +00:00
|
|
|
const { audioOnly } = getState()['features/base/conference'];
|
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
audioOnly || dispatch(setLastN(muted ? 0 : undefined));
|
2017-10-09 21:40:38 +00:00
|
|
|
|
2017-10-16 19:58:38 +00:00
|
|
|
sendAnalyticsEvent('callkit.background.video.muted');
|
2017-10-09 21:40:38 +00:00
|
|
|
|
2017-08-02 15:00:51 +00:00
|
|
|
dispatch(setVideoMuted(muted, VIDEO_MUTISM_AUTHORITY.BACKGROUND));
|
2017-02-08 11:37:52 +00:00
|
|
|
};
|
|
|
|
}
|
2017-03-28 03:50:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the App state has changed (in terms of execution state). The
|
|
|
|
* application can be in 3 states: 'active', 'inactive' and 'background'.
|
|
|
|
*
|
|
|
|
* @param {string} appState - The new App state.
|
|
|
|
* @public
|
|
|
|
* @returns {{
|
|
|
|
* type: APP_STATE_CHANGED,
|
|
|
|
* appState: string
|
|
|
|
* }}
|
|
|
|
* @see {@link https://facebook.github.io/react-native/docs/appstate.html}
|
|
|
|
*/
|
|
|
|
export function appStateChanged(appState: string) {
|
|
|
|
return {
|
|
|
|
type: APP_STATE_CHANGED,
|
|
|
|
appState
|
|
|
|
};
|
|
|
|
}
|