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

actions.web.ts 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { IStore } from '../app/types';
  2. import { openDialog } from '../base/dialog/actions';
  3. import { browser } from '../base/lib-jitsi-meet';
  4. import { shouldHideShareAudioHelper } from '../base/settings/functions.web';
  5. import { toggleScreensharing } from '../base/tracks/actions.web';
  6. import {
  7. SET_SCREENSHARE_TRACKS,
  8. SET_SCREEN_AUDIO_SHARE_STATE
  9. } from './actionTypes';
  10. import ShareAudioDialog from './components/web/ShareAudioDialog';
  11. import ShareMediaWarningDialog from './components/web/ShareScreenWarningDialog';
  12. import { isAudioOnlySharing, isScreenVideoShared } from './functions';
  13. export * from './actions.any';
  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 audio track associated with the screenshare.
  31. *
  32. * @param {JitsiLocalTrack} desktopAudioTrack - The audio track captured from the screenshare.
  33. * @returns {{
  34. * type: SET_SCREENSHARE_TRACKS,
  35. * desktopAudioTrack: JitsiTrack
  36. * }}
  37. */
  38. export function setScreenshareAudioTrack(desktopAudioTrack: any) {
  39. return {
  40. type: SET_SCREENSHARE_TRACKS,
  41. desktopAudioTrack
  42. };
  43. }
  44. /**
  45. * Start the audio only screen sharing flow. Function will switch between off and on states depending on the context.
  46. *
  47. * @param {Object} state - The state of the application.
  48. * @returns {void}
  49. */
  50. export function startAudioScreenShareFlow() {
  51. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  52. const state = getState();
  53. const audioOnlySharing = isAudioOnlySharing(state);
  54. // If we're already in a normal screen sharing session, warn the user.
  55. if (isScreenVideoShared(state)) {
  56. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: true }));
  57. return;
  58. }
  59. // If users opted out of the helper dialog toggle directly.
  60. // If we're in an electron environment the helper dialog is not needed as there's only one option
  61. // available for audio screen sharing, namely full window audio.
  62. // If we're already sharing audio, toggle off.
  63. if (shouldHideShareAudioHelper(state) || browser.isElectron() || audioOnlySharing) {
  64. // We don't want to explicitly set the screens share state, by passing undefined we let the
  65. // underlying logic decide if it's on or off.
  66. dispatch(toggleScreensharing(undefined, true));
  67. return;
  68. }
  69. dispatch(openDialog(ShareAudioDialog));
  70. };
  71. }
  72. /**
  73. * Start normal screen sharing flow.Function will switch between off and on states depending on the context, and if
  74. * not explicitly told otherwise.
  75. *
  76. * @param {boolean} enabled - Explicitly set the screen sharing state.
  77. * @returns {void}
  78. */
  79. export function startScreenShareFlow(enabled: boolean) {
  80. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  81. const state = getState();
  82. const audioOnlySharing = isAudioOnlySharing(state);
  83. // If we're in an audio screen sharing session, warn the user.
  84. if (audioOnlySharing) {
  85. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: false }));
  86. return;
  87. }
  88. dispatch(toggleScreensharing(enabled));
  89. };
  90. }