2022-10-06 17:18:22 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-10-06 17:18:22 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import { setPictureInPictureEnabled } from '../../mobile/picture-in-picture/functions';
|
2022-10-17 11:28:01 +00:00
|
|
|
import { setAudioOnly } from '../audio-only/actions';
|
2022-10-06 17:18:22 +00:00
|
|
|
import JitsiMeetJS from '../lib-jitsi-meet';
|
|
|
|
|
|
|
|
import { destroyLocalDesktopTrackIfExists, replaceLocalTrack } from './actions.any';
|
|
|
|
import { getLocalVideoTrack, isLocalVideoTrackDesktop } from './functions';
|
|
|
|
/* eslint-enable lines-around-comment */
|
|
|
|
|
|
|
|
export * from './actions.any';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the local participant is ending screensharing or beginning the screensharing flow.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - The state to toggle screen sharing to.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-10-21 11:09:15 +00:00
|
|
|
export function toggleScreensharing(enabled: boolean) {
|
2022-10-13 09:53:15 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
|
|
|
const state = getState();
|
2022-10-06 17:18:22 +00:00
|
|
|
|
2022-10-13 09:53:15 +00:00
|
|
|
if (enabled) {
|
|
|
|
const isSharing = isLocalVideoTrackDesktop(state);
|
2022-10-06 17:18:22 +00:00
|
|
|
|
2022-10-13 09:53:15 +00:00
|
|
|
if (!isSharing) {
|
|
|
|
_startScreenSharing(dispatch, state);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dispatch(destroyLocalDesktopTrackIfExists());
|
|
|
|
setPictureInPictureEnabled(true);
|
2022-10-06 17:18:22 +00:00
|
|
|
}
|
2022-10-13 09:53:15 +00:00
|
|
|
};
|
2022-10-06 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates desktop track and replaces the local one.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Dispatch} dispatch - The redux {@code dispatch} function.
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _startScreenSharing(dispatch: Function, state: IReduxState) {
|
2022-10-06 17:18:22 +00:00
|
|
|
setPictureInPictureEnabled(false);
|
|
|
|
|
|
|
|
JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] })
|
|
|
|
.then((tracks: any[]) => {
|
|
|
|
const track = tracks[0];
|
|
|
|
const currentLocalTrack = getLocalVideoTrack(state['features/base/tracks']);
|
|
|
|
const currentJitsiTrack = currentLocalTrack?.jitsiTrack;
|
|
|
|
|
|
|
|
dispatch(replaceLocalTrack(currentJitsiTrack, track));
|
|
|
|
|
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
|
|
|
|
|
|
|
if (audioOnly) {
|
|
|
|
dispatch(setAudioOnly(false));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error: any) => {
|
|
|
|
console.log('ERROR creating ScreeSharing stream ', error);
|
|
|
|
|
|
|
|
setPictureInPictureEnabled(true);
|
|
|
|
});
|
|
|
|
}
|