Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(electron-screensharing): simplify the proccess (#13967)

Gabriel Borlea97e5f00dae4b
diff --git a/modules/API/API.js b/modules/API/API.js
index 4d8e8bf222..4cc7833855 100644
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -67,7 +67,6 @@ import {
toggleChat
} from '../../react/features/chat/actions';
import { openChat } from '../../react/features/chat/actions.web';
-import { setDesktopSources } from '../../react/features/desktop-picker/actions';
import {
processExternalDeviceRequest
} from '../../react/features/device-selection/functions';
@@ -839,16 +838,6 @@ function initCommands() {
},
'toggle-whiteboard': () => {
APP.store.dispatch(toggleWhiteboard());
- },
- '_request-desktop-sources-result': data => {
- if (data.error) {
- logger.error(`Error to retrieve desktop sources result, error data: ${data.error}`);
-
- return;
- }
- if (data.success?.data?.sources) {
- APP.store.dispatch(setDesktopSources(data.success.data.sources));
- }
}
};
transport.on('event', ({ data, name }) => {
@@ -1004,7 +993,13 @@ function initCommands() {
callback(isP2pActive(APP.store.getState()));
break;
}
+ case '_new_electron_screensharing_supported': {
+ callback(true);
+ break;
+ }
default:
+ callback({ error: new Error('UnknownRequestError') });
+
return false;
}
@@ -1296,8 +1291,8 @@ class API {
* @param {Object} options - Object with the options for desktop sources.
* @returns {void}
*/
- notifyRequestDesktopSources(options) {
- this._sendEvent({
+ requestDesktopSources(options) {
+ return transport.sendRequest({
name: '_request-desktop-sources',
options
});
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index 93bba44ffd..2fe1fcacb3 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -91,8 +91,7 @@ const commands = {
toggleTileView: 'toggle-tile-view',
toggleVirtualBackgroundDialog: 'toggle-virtual-background',
toggleVideo: 'toggle-video',
- toggleWhiteboard: 'toggle-whiteboard',
- _requestDesktopSourcesResult: '_request-desktop-sources-result'
+ toggleWhiteboard: 'toggle-whiteboard'
};
/**
@@ -160,7 +159,10 @@ const events = {
'suspend-detected': 'suspendDetected',
'tile-view-changed': 'tileViewChanged',
'toolbar-button-clicked': 'toolbarButtonClicked',
- 'whiteboard-status-changed': 'whiteboardStatusChanged',
+ 'whiteboard-status-changed': 'whiteboardStatusChanged'
+};
+
+const requests = {
'_request-desktop-sources': '_requestDesktopSources'
};
@@ -689,6 +691,18 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
return false;
});
+
+ this._transport.on('request', (request, callback) => {
+ const requestName = requests[request.name];
+ const data = {
+ ...request,
+ name: requestName
+ };
+
+ if (requestName) {
+ this.emit(requestName, data, callback);
+ }
+ });
}
/**
@@ -1260,6 +1274,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
});
}
+ /**
+ * Returns the state of availability electron share screen via external api.
+ *
+ * @returns {Promise}
+ */
+ _isNewElectronScreensharingSupported() {
+ return this._transport.sendRequest({
+ name: '_new_electron_screensharing_supported'
+ });
+ }
+
/**
* Pins a participant's video on to the stage view.
*
@@ -1313,17 +1338,6 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
}
}
- /**
- * Send request to request desktop sources.
- *
- * @returns {Promise} - Result.
- */
- _requestDesktopSources() {
- return this._transport.sendRequest({
- name: '_request-desktop-sources'
- });
- }
-
/**
* Passes an event along to the local conference participant to establish
* or update a direct peer connection. This is currently used for developing
diff --git a/react/features/app/reducers.web.ts b/react/features/app/reducers.web.ts
index 052f4539fc..071d0534ef 100644
--- a/react/features/app/reducers.web.ts
+++ b/react/features/app/reducers.web.ts
@@ -1,7 +1,6 @@
import '../base/devices/reducer';
import '../base/premeeting/reducer';
import '../base/tooltip/reducer';
-import '../desktop-picker/reducer';
import '../e2ee/reducer';
import '../face-landmarks/reducer';
import '../feedback/reducer';
diff --git a/react/features/app/types.ts b/react/features/app/types.ts
index 75466bf38a..9293206b5c 100644
--- a/react/features/app/types.ts
+++ b/react/features/app/types.ts
@@ -32,7 +32,6 @@ import { IBreakoutRoomsState } from '../breakout-rooms/reducer';
import { ICalendarSyncState } from '../calendar-sync/reducer';
import { IChatState } from '../chat/reducer';
import { IDeepLinkingState } from '../deep-linking/reducer';
-import { IDesktopPicker } from '../desktop-picker/reducer';
import { IDropboxState } from '../dropbox/reducer';
import { IDynamicBrandingState } from '../dynamic-branding/reducer';
import { IE2EEState } from '../e2ee/reducer';
@@ -124,7 +123,6 @@ export interface IReduxState {
'features/call-integration': ICallIntegrationState;
'features/chat': IChatState;
'features/deep-linking': IDeepLinkingState;
- 'features/desktop-picker': IDesktopPicker;
'features/dropbox': IDropboxState;
'features/dynamic-branding': IDynamicBrandingState;
'features/e2ee': IE2EEState;
diff --git a/react/features/desktop-picker/actionTypes.ts b/react/features/desktop-picker/actionTypes.ts
deleted file mode 100644
index 1cc83f6838..0000000000
--- a/react/features/desktop-picker/actionTypes.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- * Action type to set the device sources.
- */
-export const SET_DESKTOP_SOURCES = 'SET_DESKTOP_SOURCES';
-
-/**
- * Action type to DELETE_DESKTOP_SOURCES.
- */
-export const DELETE_DESKTOP_SOURCES = 'DELETE_DESKTOP_SOURCES';
diff --git a/react/features/desktop-picker/actions.ts b/react/features/desktop-picker/actions.ts
index 0e6f7ec064..c6e647209e 100644
--- a/react/features/desktop-picker/actions.ts
+++ b/react/features/desktop-picker/actions.ts
@@ -1,8 +1,6 @@
import { openDialog } from '../base/dialog/actions';
-import { DELETE_DESKTOP_SOURCES, SET_DESKTOP_SOURCES } from './actionTypes';
import DesktopPicker from './components/DesktopPicker';
-import { _separateSourcesByType } from './functions';
/**
* Signals to open a dialog with the DesktopPicker component.
@@ -20,27 +18,3 @@ export function showDesktopPicker(options: { desktopSharingSources?: any; } = {}
onSourceChoose
});
}
-
-/**
- * Signals to open a dialog with the DesktopPicker component with screen sharing sources.
- *
- * @param {Array} sources - Desktop capturer sources.
- * @returns {Function}
- */
-export function setDesktopSources(sources: Array<any>) {
- return {
- type: SET_DESKTOP_SOURCES,
- sources: _separateSourcesByType(sources ?? [])
- };
-}
-
-/**
- * Action used to delete desktop sources.
- *
- * @returns {Object}
- */
-export function deleteDesktopSources() {
- return {
- type: DELETE_DESKTOP_SOURCES
- };
-}
diff --git a/react/features/desktop-picker/components/DesktopPicker.tsx b/react/features/desktop-picker/components/DesktopPicker.tsx
index f98e49b7ee..616c7a84fa 100644
--- a/react/features/desktop-picker/components/DesktopPicker.tsx
+++ b/react/features/desktop-picker/components/DesktopPicker.tsx
@@ -1,21 +1,15 @@
-import _ from 'lodash';
import React, { PureComponent } from 'react';
import { WithTranslation } from 'react-i18next';
import { connect } from 'react-redux';
-import { IReduxState, IStore } from '../../app/types';
+import { IStore } from '../../app/types';
import { hideDialog } from '../../base/dialog/actions';
import { translate } from '../../base/i18n/functions';
import Dialog from '../../base/ui/components/web/Dialog';
import Tabs from '../../base/ui/components/web/Tabs';
-import { deleteDesktopSources } from '../actions';
import { THUMBNAIL_SIZE } from '../constants';
-import {
- getDesktopPickerSources,
- obtainDesktopSources,
- oldJitsiMeetElectronUsage
-} from '../functions';
-import { IDesktopSources } from '../types';
+import { obtainDesktopSources } from '../functions';
+import logger from '../logger';
import DesktopPickerPane from './DesktopPickerPane';
@@ -45,11 +39,6 @@ const VALID_TYPES = Object.keys(TAB_LABELS);
*/
interface IProps extends WithTranslation {
- /**
- * An object containing all the DesktopCapturerSources.
- */
- _sources: IDesktopSources;
-
/**
* An array with desktop sharing sources to be displayed.
*/
@@ -185,28 +174,6 @@ class DesktopPicker extends PureComponent<IProps, IState> {
this._stopPolling();
}
- /**
- * Clean up component and DesktopCapturerSource store state.
- *
- * @inheritdoc
- */
- componentDidUpdate(prevProps: IProps) {
- // skip logic if old jitsi meet electron used.
- if (oldJitsiMeetElectronUsage()) {
- return;
- }
-
- if (this.props._sources && !_.isEqual(this.props._sources, prevProps._sources)) {
- const selectedSource = this._getSelectedSource(this.props._sources);
-
- // update state with latest thumbnail desktop sources
- this.setState({
- sources: this.props._sources,
- selectedSource
- });
- }
- }
-
/**
* Implements React's {@link Component#render()}.
@@ -308,7 +275,6 @@ class DesktopPicker extends PureComponent<IProps, IState> {
_onCloseModal(id = '', type?: string, screenShareAudio = false) {
this.props.onSourceChoose(id, type, screenShareAudio);
this.props.dispatch(hideDialog());
- this.props.dispatch(deleteDesktopSources());
}
/**
@@ -432,14 +398,14 @@ class DesktopPicker extends PureComponent<IProps, IState> {
*/
_updateSources() {
const { types } = this.state;
+ const options = {
+ types,
+ thumbnailSize: THUMBNAIL_SIZE
+ };
- if (oldJitsiMeetElectronUsage()) {
- if (types.length > 0) {
- obtainDesktopSources(
- this.state.types,
- { thumbnailSize: THUMBNAIL_SIZE }
- )
+ if (types.length > 0) {
+ obtainDesktopSources(options)
.then((sources: any) => {
const selectedSource = this._getSelectedSource(sources);
@@ -448,29 +414,9 @@ class DesktopPicker extends PureComponent<IProps, IState> {
selectedSource
});
})
- .catch(() => { /* ignore */ });
- }
- } else {
- APP.API.notifyRequestDesktopSources({
- types,
- thumbnailSize: THUMBNAIL_SIZE
- });
+ .catch((error: any) => logger.log(error));
}
}
}
-/**
- * Maps (parts of) the redux state to the React props.
- *
- * @param {Object} state - The redux state.
- * @returns {{
-* _sources: IDesktopPicker
-* }}
-*/
-function _mapStateToProps(state: IReduxState) {
- return {
- _sources: getDesktopPickerSources(state)
- };
-}
-
-export default translate(connect(_mapStateToProps)(DesktopPicker));
+export default translate(connect()(DesktopPicker));
diff --git a/react/features/desktop-picker/functions.ts b/react/features/desktop-picker/functions.ts
index 11a3e62500..6a1da91ae5 100644
--- a/react/features/desktop-picker/functions.ts
+++ b/react/features/desktop-picker/functions.ts
@@ -1,52 +1,23 @@
-import { IReduxState } from '../app/types';
-
import logger from './logger';
import { ElectronWindowType } from './types';
-/**
- * Returns root conference state.
- *
- * @param {IReduxState} state - Global state.
- * @returns {Object} Conference state.
- */
-export const getDesktopPicker = (state: IReduxState) => state['features/desktop-picker'];
-
-/**
-* Selector to return a list of knocking participants.
-*
-* @param {IReduxState} state - State object.
-* @returns {IDesktopSources}
-*/
-export function getDesktopPickerSources(state: IReduxState) {
- const root = getDesktopPicker(state);
-
- return root.sources;
-}
-
/**
* Begins a request to get available DesktopCapturerSources.
*
- * @param {Array} types - An array with DesktopCapturerSource type strings.
* @param {Object} options - Additional configuration for getting a list of
* sources.
+ * @param {Array} options.types - An array with DesktopCapturerSource type strings.
* @param {Object} options.thumbnailSize - The desired height and width of the
* return native image object used for the preview image of the source.
* @returns {Function}
*/
-export function obtainDesktopSources(types: string[], options: { thumbnailSize?: Object; } = {}) {
- const capturerOptions: any = {
- types
- };
-
- if (options.thumbnailSize) {
- capturerOptions.thumbnailSize = options.thumbnailSize;
- }
-
- return new Promise((resolve, reject) => {
- const { JitsiMeetElectron } = window as ElectronWindowType;
+export function obtainDesktopSources(options: { thumbnailSize?: Object; types: string[]; }) {
+ const { JitsiMeetElectron } = window as ElectronWindowType;
- if (JitsiMeetElectron?.obtainDesktopStreams) {
+ // TODO: delete this after 2 releases
+ if (JitsiMeetElectron?.obtainDesktopStreams) {
+ return new Promise((resolve, reject) => {
JitsiMeetElectron.obtainDesktopStreams(
(sources: Array<{ id: string; }>) => resolve(_separateSourcesByType(sources)),
(error: Error) => {
@@ -54,17 +25,22 @@ export function obtainDesktopSources(types: string[], options: { thumbnailSize?:
`Error while obtaining desktop sources: ${error}`);
reject(error);
},
- capturerOptions
+ options
);
- } else {
- const reason = 'Called JitsiMeetElectron.obtainDesktopStreams'
- + ' but it is not defined';
-
- logger.error(reason);
+ });
+ }
- return Promise.reject(new Error(reason));
- }
- });
+ return APP.API.requestDesktopSources(options).then(
+ ({ sources, error }: { error: Error; sources: Array<{ id: string; }>; }) => {
+ if (sources) {
+ return _separateSourcesByType(sources);
+ } else if (error) {
+ logger.error(
+ `Error while obtaining desktop sources: ${error}`);
+
+ return null;
+ }
+ });
}
/**
diff --git a/react/features/desktop-picker/reducer.ts b/react/features/desktop-picker/reducer.ts
deleted file mode 100644
index 7b528d1e70..0000000000
--- a/react/features/desktop-picker/reducer.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import ReducerRegistry from '../base/redux/ReducerRegistry';
-
-import { DELETE_DESKTOP_SOURCES, SET_DESKTOP_SOURCES } from './actionTypes';
-import { IDesktopSources } from './types';
-
-/**
- * The initial state of the web-hid feature.
-*/
-const DEFAULT_STATE: IDesktopPicker = {
- sources: {} as IDesktopSources
-};
-
-export interface IDesktopPicker {
- sources: IDesktopSources;
-}
-
-ReducerRegistry.register<IDesktopPicker>(
-'features/desktop-picker',
-(state: IDesktopPicker = DEFAULT_STATE, action): IDesktopPicker => {
- switch (action.type) {
- case SET_DESKTOP_SOURCES:
- return {
- ...state,
- sources: action.sources
- };
- case DELETE_DESKTOP_SOURCES:
- return {
- ...state,
- ...DEFAULT_STATE
- };
- default:
- return state;
- }
-});
diff --git a/react/features/desktop-picker/types.ts b/react/features/desktop-picker/types.ts
index 29bb0d59ff..d7e913f2aa 100644
--- a/react/features/desktop-picker/types.ts
+++ b/react/features/desktop-picker/types.ts
@@ -1,12 +1,3 @@
-export interface IDesktopSources {
- sources: ISourcesByType;
-}
-
-export interface ISourcesByType {
- screen: [];
- window: [];
-}
-
export type ElectronWindowType = {
JitsiMeetElectron?: {
obtainDesktopStreams: Function;