Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

actions.js 2.6KB

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