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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // @flow
  2. import { getMultipleVideoSendingSupportFeatureFlag } from '../base/config/functions.any';
  3. import { openDialog } from '../base/dialog/actions';
  4. import { browser } from '../base/lib-jitsi-meet';
  5. import { shouldHideShareAudioHelper } from '../base/settings';
  6. import { toggleScreensharing } from '../base/tracks';
  7. import {
  8. SET_SCREEN_AUDIO_SHARE_STATE,
  9. SET_SCREENSHARE_CAPTURE_FRAME_RATE,
  10. SET_SCREENSHARE_TRACKS
  11. } from './actionTypes';
  12. import { ShareAudioDialog } from './components';
  13. import ShareMediaWarningDialog from './components/ShareScreenWarningDialog';
  14. import { isAudioOnlySharing, isScreenVideoShared } from './functions';
  15. /**
  16. * Updates the current known status of the shared video.
  17. *
  18. * @param {boolean} isSharingAudio - Is audio currently being shared or not.
  19. * @returns {{
  20. * type: SET_SCREEN_AUDIO_SHARE_STATE,
  21. * isSharingAudio: boolean
  22. * }}
  23. */
  24. export function setScreenAudioShareState(isSharingAudio: boolean) {
  25. return {
  26. type: SET_SCREEN_AUDIO_SHARE_STATE,
  27. isSharingAudio
  28. };
  29. }
  30. /**
  31. * Updates the capture frame rate for screenshare in redux.
  32. *
  33. * @param {number} captureFrameRate - The frame rate to be used for screenshare.
  34. * @returns {{
  35. * type: SET_SCREENSHARE_CAPTURE_FRAME_RATE,
  36. * captureFrameRate: number
  37. * }}
  38. */
  39. export function setScreenshareFramerate(captureFrameRate: number) {
  40. return {
  41. type: SET_SCREENSHARE_CAPTURE_FRAME_RATE,
  42. captureFrameRate
  43. };
  44. }
  45. /**
  46. * Updates the audio track associated with the screenshare.
  47. *
  48. * @param {JitsiLocalTrack} desktopAudioTrack - The audio track captured from the screenshare.
  49. * @returns {{
  50. * type: SET_SCREENSHARE_TRACKS,
  51. * desktopAudioTrack: JitsiTrack
  52. * }}
  53. */
  54. export function setScreenshareAudioTrack(desktopAudioTrack) {
  55. return {
  56. type: SET_SCREENSHARE_TRACKS,
  57. desktopAudioTrack
  58. };
  59. }
  60. /**
  61. * Start the audio only screen sharing flow. Function will switch between off and on states depending on the context.
  62. *
  63. * @param {Object} state - The state of the application.
  64. * @returns {void}
  65. */
  66. export function startAudioScreenShareFlow() {
  67. return (dispatch: Object => Object, getState: () => any) => {
  68. const state = getState();
  69. const audioOnlySharing = isAudioOnlySharing(state);
  70. // If we're already in a normal screen sharing session, warn the user.
  71. if (isScreenVideoShared(state)) {
  72. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: true }));
  73. return;
  74. }
  75. // If users opted out of the helper dialog toggle directly.
  76. // If we're in an electron environment the helper dialog is not needed as there's only one option
  77. // available for audio screen sharing, namely full window audio.
  78. // If we're already sharing audio, toggle off.
  79. if (shouldHideShareAudioHelper(state) || browser.isElectron() || audioOnlySharing) {
  80. if (getMultipleVideoSendingSupportFeatureFlag(state)) {
  81. dispatch(toggleScreensharing(!audioOnlySharing, true));
  82. return;
  83. }
  84. // We don't want to explicity set the screens share state, by passing undefined we let the
  85. // underlying logic decide if it's on or off.
  86. dispatch(toggleScreensharing(undefined, true));
  87. return;
  88. }
  89. dispatch(openDialog(ShareAudioDialog));
  90. };
  91. }
  92. /**
  93. * Start normal screen sharing flow.Function will switch between off and on states depending on the context, and if
  94. * not explicity told otherwise.
  95. *
  96. * @param {boolean} enabled - Explicitly set the screen sharing state.
  97. * @returns {void}
  98. */
  99. export function startScreenShareFlow(enabled: boolean) {
  100. return (dispatch: Object => Object, getState: () => any) => {
  101. const state = getState();
  102. const audioOnlySharing = isAudioOnlySharing(state);
  103. // If we're in an audio screen sharing session, warn the user.
  104. if (audioOnlySharing) {
  105. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: false }));
  106. return;
  107. }
  108. dispatch(toggleScreensharing(enabled));
  109. };
  110. }