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.3KB

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