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.ts 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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';
  5. import { toggleScreensharing } from '../base/tracks/actions';
  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/ShareAudioDialog';
  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: any) {
  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: IStore['dispatch'], getState: IStore['getState']) => {
  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)) { // @ts-ignore
  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. // @ts-ignore
  85. dispatch(openDialog(ShareAudioDialog));
  86. };
  87. }
  88. /**
  89. * Start normal screen sharing flow.Function will switch between off and on states depending on the context, and if
  90. * not explicitly told otherwise.
  91. *
  92. * @param {boolean} enabled - Explicitly set the screen sharing state.
  93. * @returns {void}
  94. */
  95. export function startScreenShareFlow(enabled: boolean) {
  96. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  97. const state = getState();
  98. const audioOnlySharing = isAudioOnlySharing(state);
  99. // If we're in an audio screen sharing session, warn the user.
  100. if (audioOnlySharing) { // @ts-ignore
  101. dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: false }));
  102. return;
  103. }
  104. dispatch(toggleScreensharing(enabled));
  105. };
  106. }