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.9KB

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