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

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