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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* @flow */
  2. import {
  3. CALLKIT_BACKGROUND_VIDEO_MUTED,
  4. sendAnalyticsEvent
  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. sendAnalyticsEvent(CALLKIT_BACKGROUND_VIDEO_MUTED);
  44. dispatch(setVideoMuted(muted, VIDEO_MUTISM_AUTHORITY.BACKGROUND));
  45. };
  46. }
  47. /**
  48. * Signals that the App state has changed (in terms of execution state). The
  49. * application can be in 3 states: 'active', 'inactive' and 'background'.
  50. *
  51. * @param {string} appState - The new App state.
  52. * @public
  53. * @returns {{
  54. * type: APP_STATE_CHANGED,
  55. * appState: string
  56. * }}
  57. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  58. */
  59. export function appStateChanged(appState: string) {
  60. return {
  61. type: APP_STATE_CHANGED,
  62. appState
  63. };
  64. }