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

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