diff --git a/react/features/desktop-picker/components/DesktopPicker.tsx b/react/features/desktop-picker/components/DesktopPicker.tsx index 616c7a84fa..43416f2170 100644 --- a/react/features/desktop-picker/components/DesktopPicker.tsx +++ b/react/features/desktop-picker/components/DesktopPicker.tsx @@ -127,13 +127,6 @@ class DesktopPicker extends PureComponent { types: [] }; - /** - * Stores the type of the selected tab. - * - * @type {string} - */ - _selectedTabType = DEFAULT_TAB_TYPE; - /** * Initializes a new DesktopPicker instance. * @@ -223,17 +216,20 @@ class DesktopPicker extends PureComponent { * Computes the selected source. * * @param {Object} sources - The available sources. + * @param {string} selectedTab - The selected tab. * @returns {Object} The selectedSource value. */ - _getSelectedSource(sources: any = {}) { + _getSelectedSource(sources: any = {}, selectedTab?: string) { const { selectedSource } = this.state; + const currentSelectedTab = selectedTab ?? this.state.selectedTab; + /** * If there are no sources for this type (or no sources for any type) * we can't select anything. */ - if (!Array.isArray(sources[this._selectedTabType as keyof typeof sources]) - || sources[this._selectedTabType as keyof typeof sources].length <= 0) { + if (!Array.isArray(sources[currentSelectedTab as keyof typeof sources]) + || sources[currentSelectedTab as keyof typeof sources].length <= 0) { return {}; } @@ -245,12 +241,12 @@ class DesktopPicker extends PureComponent { * 3) The selected source is no longer available. */ if (!selectedSource // scenario 1) - || selectedSource.type !== this._selectedTabType // scenario 2) - || !sources[this._selectedTabType].some( // scenario 3) + || selectedSource.type !== currentSelectedTab // scenario 2) + || !sources[currentSelectedTab].some( // scenario 3) (source: any) => source.id === selectedSource.id)) { return { - id: sources[this._selectedTabType][0].id, - type: this._selectedTabType + id: sources[currentSelectedTab][0].id, + type: currentSelectedTab }; } @@ -319,10 +315,10 @@ class DesktopPicker extends PureComponent { // use the option from one tab when sharing from another. this.setState({ screenShareAudio: false, - selectedSource: this._getSelectedSource(sources), + selectedSource: this._getSelectedSource(sources, id), // select type `window` or `screen` from id - selectedTab: id.split('-')[0] + selectedTab: id }); } @@ -410,8 +406,8 @@ class DesktopPicker extends PureComponent { const selectedSource = this._getSelectedSource(sources); this.setState({ - sources, - selectedSource + selectedSource, + sources }); }) .catch((error: any) => logger.log(error));