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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. return;
  43. }
  44. dispatch(setLastN(muted ? 0 : undefined));
  45. if (muted) {
  46. const { video } = getState()['features/base/media'];
  47. if (video.muted) {
  48. // Video is already muted, do nothing.
  49. return;
  50. }
  51. } else {
  52. const { videoMuted } = getState()['features/background'];
  53. if (!videoMuted) {
  54. // We didn't mute video, do nothing.
  55. return;
  56. }
  57. }
  58. // Remember that local video was muted due to the app going to the
  59. // background vs user's choice.
  60. dispatch({
  61. type: _SET_BACKGROUND_VIDEO_MUTED,
  62. muted
  63. });
  64. dispatch(setVideoMuted(muted));
  65. };
  66. }
  67. /**
  68. * Signals that the App state has changed (in terms of execution state). The
  69. * application can be in 3 states: 'active', 'inactive' and 'background'.
  70. *
  71. * @param {string} appState - The new App state.
  72. * @public
  73. * @returns {{
  74. * type: APP_STATE_CHANGED,
  75. * appState: string
  76. * }}
  77. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  78. */
  79. export function appStateChanged(appState: string) {
  80. return {
  81. type: APP_STATE_CHANGED,
  82. appState
  83. };
  84. }