選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.js 2.7KB

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