Skip to content

Commit

Permalink
fix(electron-screensharing): simplify the proccess
Browse files Browse the repository at this point in the history
  • Loading branch information
gabiborlea committed Oct 18, 2023
1 parent fa64e2e commit 22ce5a5
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 216 deletions.
21 changes: 8 additions & 13 deletions modules/API/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -1004,7 +993,13 @@ function initCommands() {
callback(isP2pActive(APP.store.getState()));
break;
}
case '_is_electron_screensharing': {
callback(true);
break;
}
default:
callback(null);

return false;
}

Expand Down Expand Up @@ -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
});
Expand Down
42 changes: 28 additions & 14 deletions modules/API/external/external_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

/**
Expand Down Expand Up @@ -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'
};

Expand Down Expand Up @@ -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);
}
});
}

/**
Expand Down Expand Up @@ -1260,6 +1274,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
});
}

/**
* Returns the state of availability electron share screen via external api.
*
* @returns {Promise}
*/
_isElectronScreensharing() {
return this._transport.sendRequest({
name: '_is_electron_screensharing'
});
}

/**
* Pins a participant's video on to the stage view.
*
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion react/features/app/reducers.web.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 0 additions & 2 deletions react/features/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions react/features/desktop-picker/actionTypes.ts

This file was deleted.

26 changes: 0 additions & 26 deletions react/features/desktop-picker/actions.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
};
}
76 changes: 11 additions & 65 deletions react/features/desktop-picker/components/DesktopPicker.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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()}.
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Loading

0 comments on commit 22ce5a5

Please sign in to comment.