Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 2.2KB

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