You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* @flow */
  2. import { setLastN } from '../../base/conference';
  3. import { setVideoMuted, VIDEO_MUTISM_AUTHORITY } from '../../base/media';
  4. import { _SET_APP_STATE_LISTENER, APP_STATE_CHANGED } from './actionTypes';
  5. /**
  6. * Sets the listener to be used with React Native's AppState API.
  7. *
  8. * @param {Function} listener - Function to be set as the change event listener.
  9. * @protected
  10. * @returns {{
  11. * type: _SET_APP_STATE_LISTENER,
  12. * listener: Function
  13. * }}
  14. */
  15. export function _setAppStateListener(listener: ?Function) {
  16. return {
  17. type: _SET_APP_STATE_LISTENER,
  18. listener
  19. };
  20. }
  21. /**
  22. * Signals that the app should mute video because it's now running in the
  23. * background, or unmute it because it came back from the background. If video
  24. * was already muted nothing will happen; otherwise, it will be muted. When
  25. * coming back from the background the previous state will be restored.
  26. *
  27. * @param {boolean} muted - True if video should be muted; false, otherwise.
  28. * @protected
  29. * @returns {Function}
  30. */
  31. export function _setBackgroundVideoMuted(muted: boolean) {
  32. return (dispatch: Dispatch<*>, getState: Function) => {
  33. // Disable remote video when we mute by setting lastN to 0. Skip it if
  34. // the conference is in audio-only mode, as it's already configured to
  35. // have no video. Leave it as undefined when unmuting, the default value
  36. // for last N will be chosen automatically.
  37. const { audioOnly } = getState()['features/base/conference'];
  38. audioOnly || dispatch(setLastN(muted ? 0 : undefined));
  39. dispatch(setVideoMuted(muted, VIDEO_MUTISM_AUTHORITY.BACKGROUND));
  40. };
  41. }
  42. /**
  43. * Signals that the App state has changed (in terms of execution state). The
  44. * application can be in 3 states: 'active', 'inactive' and 'background'.
  45. *
  46. * @param {string} appState - The new App state.
  47. * @public
  48. * @returns {{
  49. * type: APP_STATE_CHANGED,
  50. * appState: string
  51. * }}
  52. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  53. */
  54. export function appStateChanged(appState: string) {
  55. return {
  56. type: APP_STATE_CHANGED,
  57. appState
  58. };
  59. }