2022-10-21 07:33:10 +00:00
|
|
|
import { IStore } from '../app/types';
|
2021-07-07 08:07:30 +00:00
|
|
|
import { openDialog } from '../base/dialog/actions';
|
|
|
|
import { browser } from '../base/lib-jitsi-meet';
|
2022-11-10 08:45:56 +00:00
|
|
|
import { shouldHideShareAudioHelper } from '../base/settings/functions.web';
|
|
|
|
import { toggleScreensharing } from '../base/tracks/actions.web';
|
2021-07-07 08:07:30 +00:00
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
SET_SCREENSHARE_TRACKS,
|
|
|
|
SET_SCREEN_AUDIO_SHARE_STATE
|
2022-03-15 17:24:49 +00:00
|
|
|
} from './actionTypes';
|
2022-10-28 10:07:58 +00:00
|
|
|
import ShareAudioDialog from './components/web/ShareAudioDialog';
|
|
|
|
import ShareMediaWarningDialog from './components/web/ShareScreenWarningDialog';
|
2021-07-07 08:07:30 +00:00
|
|
|
import { isAudioOnlySharing, isScreenVideoShared } from './functions';
|
2021-04-12 07:37:39 +00:00
|
|
|
|
2022-10-28 10:07:58 +00:00
|
|
|
export * from './actions.any';
|
|
|
|
|
2021-04-12 07:37:39 +00:00
|
|
|
/**
|
|
|
|
* Updates the current known status of the shared video.
|
|
|
|
*
|
|
|
|
* @param {boolean} isSharingAudio - Is audio currently being shared or not.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_SCREEN_AUDIO_SHARE_STATE,
|
|
|
|
* isSharingAudio: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setScreenAudioShareState(isSharingAudio: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_SCREEN_AUDIO_SHARE_STATE,
|
|
|
|
isSharingAudio
|
|
|
|
};
|
|
|
|
}
|
2021-06-28 07:48:16 +00:00
|
|
|
|
2022-03-15 17:24:49 +00:00
|
|
|
/**
|
|
|
|
* Updates the audio track associated with the screenshare.
|
|
|
|
*
|
|
|
|
* @param {JitsiLocalTrack} desktopAudioTrack - The audio track captured from the screenshare.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_SCREENSHARE_TRACKS,
|
|
|
|
* desktopAudioTrack: JitsiTrack
|
|
|
|
* }}
|
|
|
|
*/
|
2022-10-21 07:33:10 +00:00
|
|
|
export function setScreenshareAudioTrack(desktopAudioTrack: any) {
|
2022-03-15 17:24:49 +00:00
|
|
|
return {
|
|
|
|
type: SET_SCREENSHARE_TRACKS,
|
|
|
|
desktopAudioTrack
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-07 08:07:30 +00:00
|
|
|
/**
|
|
|
|
* Start the audio only screen sharing flow. Function will switch between off and on states depending on the context.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the application.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
export function startAudioScreenShareFlow() {
|
2022-10-21 07:33:10 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2021-07-07 08:07:30 +00:00
|
|
|
const state = getState();
|
|
|
|
const audioOnlySharing = isAudioOnlySharing(state);
|
|
|
|
|
|
|
|
// If we're already in a normal screen sharing session, warn the user.
|
2022-10-21 07:33:10 +00:00
|
|
|
if (isScreenVideoShared(state)) { // @ts-ignore
|
2021-07-07 08:07:30 +00:00
|
|
|
dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: true }));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If users opted out of the helper dialog toggle directly.
|
|
|
|
// If we're in an electron environment the helper dialog is not needed as there's only one option
|
|
|
|
// available for audio screen sharing, namely full window audio.
|
|
|
|
// If we're already sharing audio, toggle off.
|
|
|
|
if (shouldHideShareAudioHelper(state) || browser.isElectron() || audioOnlySharing) {
|
2022-07-14 07:10:08 +00:00
|
|
|
// We don't want to explicitly set the screens share state, by passing undefined we let the
|
2021-07-07 08:07:30 +00:00
|
|
|
// underlying logic decide if it's on or off.
|
|
|
|
dispatch(toggleScreensharing(undefined, true));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-21 07:33:10 +00:00
|
|
|
// @ts-ignore
|
2021-07-07 08:07:30 +00:00
|
|
|
dispatch(openDialog(ShareAudioDialog));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start normal screen sharing flow.Function will switch between off and on states depending on the context, and if
|
2022-07-14 07:10:08 +00:00
|
|
|
* not explicitly told otherwise.
|
2021-07-07 08:07:30 +00:00
|
|
|
*
|
2022-03-15 17:24:49 +00:00
|
|
|
* @param {boolean} enabled - Explicitly set the screen sharing state.
|
2021-07-07 08:07:30 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
export function startScreenShareFlow(enabled: boolean) {
|
2022-10-21 07:33:10 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2021-07-07 08:07:30 +00:00
|
|
|
const state = getState();
|
|
|
|
const audioOnlySharing = isAudioOnlySharing(state);
|
|
|
|
|
|
|
|
// If we're in an audio screen sharing session, warn the user.
|
2022-10-21 07:33:10 +00:00
|
|
|
if (audioOnlySharing) { // @ts-ignore
|
2021-07-07 08:07:30 +00:00
|
|
|
dispatch(openDialog(ShareMediaWarningDialog, { _isAudioScreenShareWarning: false }));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(toggleScreensharing(enabled));
|
|
|
|
};
|
|
|
|
}
|