2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-11-28 10:52:45 +00:00
|
|
|
// eslint-disable-next-line lines-around-comment
|
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';
|
2022-10-04 13:56:41 +00:00
|
|
|
import {
|
|
|
|
setScreenshareMuted,
|
|
|
|
setVideoMuted
|
|
|
|
} from '../media/actions';
|
|
|
|
import {
|
|
|
|
MEDIA_TYPE,
|
|
|
|
VIDEO_MUTISM_AUTHORITY
|
|
|
|
} from '../media/constants';
|
2022-10-06 17:18:22 +00:00
|
|
|
|
2022-10-04 13:56:41 +00:00
|
|
|
import { addLocalTrack, replaceLocalTrack } from './actions.any';
|
|
|
|
import { getLocalDesktopTrack, getTrackState, isLocalVideoTrackDesktop } from './functions.native';
|
2022-10-06 17:18:22 +00:00
|
|
|
|
|
|
|
export * from './actions.any';
|
|
|
|
|
2022-11-01 21:12:33 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
|
2022-10-06 17:18:22 +00:00
|
|
|
/**
|
|
|
|
* Signals that the local participant is ending screensharing or beginning the screensharing flow.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - The state to toggle screen sharing to.
|
2022-10-28 10:07:58 +00:00
|
|
|
* @param {boolean} _ignore1 - Ignored.
|
2022-11-08 19:15:49 +00:00
|
|
|
* @param {any} _ignore2 - Ignored.
|
2022-10-06 17:18:22 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-11-08 19:15:49 +00:00
|
|
|
export function toggleScreensharing(enabled: boolean, _ignore1?: boolean, _ignore2?: any) {
|
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 {
|
2022-10-04 13:56:41 +00:00
|
|
|
dispatch(setScreenshareMuted(true));
|
|
|
|
dispatch(setVideoMuted(false, MEDIA_TYPE.VIDEO, VIDEO_MUTISM_AUTHORITY.SCREEN_SHARE));
|
2022-10-13 09:53:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-01 21:12:33 +00:00
|
|
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
|
|
|
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-04 13:56:41 +00:00
|
|
|
async function _startScreenSharing(dispatch: Function, state: IReduxState) {
|
2022-10-06 17:18:22 +00:00
|
|
|
setPictureInPictureEnabled(false);
|
|
|
|
|
2022-10-04 13:56:41 +00:00
|
|
|
try {
|
|
|
|
const tracks: any[] = await JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] });
|
2022-10-06 17:18:22 +00:00
|
|
|
const track = tracks[0];
|
2022-10-04 13:56:41 +00:00
|
|
|
const currentLocalDesktopTrack = getLocalDesktopTrack(getTrackState(state));
|
|
|
|
const currentJitsiTrack = currentLocalDesktopTrack?.jitsiTrack;
|
2022-10-06 17:18:22 +00:00
|
|
|
|
2022-10-04 13:56:41 +00:00
|
|
|
// The first time the user shares the screen we add the track and create the transceiver.
|
|
|
|
// Afterwards, we just replace the old track, so the transceiver will be reused.
|
|
|
|
if (currentJitsiTrack) {
|
|
|
|
dispatch(replaceLocalTrack(currentJitsiTrack, track));
|
|
|
|
} else {
|
|
|
|
dispatch(addLocalTrack(track));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setVideoMuted(true, MEDIA_TYPE.VIDEO, VIDEO_MUTISM_AUTHORITY.SCREEN_SHARE));
|
2022-10-06 17:18:22 +00:00
|
|
|
|
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
|
|
|
|
|
|
|
if (audioOnly) {
|
|
|
|
dispatch(setAudioOnly(false));
|
|
|
|
}
|
2022-10-04 13:56:41 +00:00
|
|
|
} catch (error: any) {
|
2022-10-06 17:18:22 +00:00
|
|
|
console.log('ERROR creating ScreeSharing stream ', error);
|
|
|
|
|
|
|
|
setPictureInPictureEnabled(true);
|
2022-10-04 13:56:41 +00:00
|
|
|
}
|
2022-10-06 17:18:22 +00:00
|
|
|
}
|