您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 3.8KB

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