Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.web.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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)) { // @ts-ignore
  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. // @ts-ignore
  70. dispatch(openDialog(ShareAudioDialog));
  71. };
  72. }
  73. /**
  74. * Start normal screen sharing flow.Function will switch between off and on states depending on the context, and if
  75. * not explicitly told otherwise.
  76. *
  77. * @param {boolean} enabled - Explicitly set the screen sharing state.
  78. * @returns {void}
  79. */
  80. export function startScreenShareFlow(enabled: boolean) {
  81. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  82. const state = getState();
  83. const audioOnlySharing = isAudioOnlySharing(state);
  84. // If we're in an audio screen sharing session, warn the user.
  85. if (audioOnlySharing) { // @ts-ignore
  86. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: false }));
  87. return;
  88. }
  89. dispatch(toggleScreensharing(enabled));
  90. };
  91. }