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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * 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.
  37. // Skip it if the conference is in audio only mode, as it's
  38. // already configured to have no video.
  39. const { audioOnly } = getState()['features/base/conference'];
  40. if (!audioOnly) {
  41. let lastN;
  42. if (muted) {
  43. lastN = 0;
  44. } else {
  45. const { config } = getState()['features/base/lib-jitsi-meet'];
  46. lastN = config.channelLastN;
  47. if (typeof lastN === 'undefined') {
  48. lastN = -1;
  49. }
  50. }
  51. dispatch({
  52. type: _SET_LASTN,
  53. lastN
  54. });
  55. }
  56. if (muted) {
  57. const { video } = getState()['features/base/media'];
  58. if (video.muted) {
  59. // Video is already muted, do nothing.
  60. return;
  61. }
  62. } else {
  63. const { videoMuted } = getState()['features/background'];
  64. if (!videoMuted) {
  65. // We didn't mute video, do nothing.
  66. return;
  67. }
  68. }
  69. // Remember that local video was muted due to the app going to the
  70. // background vs user's choice.
  71. dispatch({
  72. type: _SET_BACKGROUND_VIDEO_MUTED,
  73. muted
  74. });
  75. dispatch(setVideoMuted(muted));
  76. };
  77. }
  78. /**
  79. * Signals that the App state has changed (in terms of execution state). The
  80. * application can be in 3 states: 'active', 'inactive' and 'background'.
  81. *
  82. * @param {string} appState - The new App state.
  83. * @public
  84. * @returns {{
  85. * type: APP_STATE_CHANGED,
  86. * appState: string
  87. * }}
  88. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  89. */
  90. export function appStateChanged(appState: string) {
  91. return {
  92. type: APP_STATE_CHANGED,
  93. appState
  94. };
  95. }