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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { setVideoMuted } from '../base/media';
  2. import {
  3. _SET_APP_STATE_LISTENER,
  4. _SET_BACKGROUND_VIDEO_MUTED,
  5. APP_STATE_CHANGED
  6. } from './actionTypes';
  7. import './middleware';
  8. import './reducer';
  9. /**
  10. * Signals that the App state has changed (in terms of execution state). The
  11. * application can be in 3 states: 'active', 'inactive' and 'background'.
  12. *
  13. * @param {string} appState - The new App state.
  14. * @public
  15. * @returns {{
  16. * type: APP_STATE_CHANGED,
  17. * appState: string
  18. * }}
  19. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  20. */
  21. export function appStateChanged(appState: string) {
  22. return {
  23. type: APP_STATE_CHANGED,
  24. appState
  25. };
  26. }
  27. /**
  28. * Sets the listener to be used with React Native's AppState API.
  29. *
  30. * @param {Function} listener - Function to be set as the change event listener.
  31. * @protected
  32. * @returns {{
  33. * type: _SET_APP_STATE_LISTENER,
  34. * listener: Function
  35. * }}
  36. */
  37. export function _setAppStateListener(listener: ?Function) {
  38. return {
  39. type: _SET_APP_STATE_LISTENER,
  40. listener
  41. };
  42. }
  43. /**
  44. * Signals that the app should mute video because it's now running in the
  45. * background, or unmute it because it came back from the background. If video
  46. * was already muted nothing will happen; otherwise, it will be muted. When
  47. * coming back from the background the previous state will be restored.
  48. *
  49. * @param {boolean} muted - True if video should be muted; false, otherwise.
  50. * @protected
  51. * @returns {Function}
  52. */
  53. export function _setBackgroundVideoMuted(muted: boolean) {
  54. return (dispatch, getState) => {
  55. if (muted) {
  56. const mediaState = getState()['features/base/media'];
  57. if (mediaState.video.muted) {
  58. // Video is already muted, do nothing.
  59. return;
  60. }
  61. } else {
  62. const bgState = getState()['features/background'];
  63. if (!bgState.videoMuted) {
  64. // We didn't mute video, do nothing.
  65. return;
  66. }
  67. }
  68. // Remember that video was muted due to the app going to the background
  69. // vs user's choice.
  70. dispatch({
  71. type: _SET_BACKGROUND_VIDEO_MUTED,
  72. muted
  73. });
  74. dispatch(setVideoMuted(muted));
  75. };
  76. }