diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 9d6bc2c6fb..8ad93fa960 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -93,6 +93,26 @@ declare global { mxSetupEncryptionStore?: SetupEncryptionStore; mxRoomScrollStateStore?: RoomScrollStateStore; mxOnRecaptchaLoaded?: () => void; + electron?: Electron; + } + + interface DesktopCapturerSource { + id: string; + name: string; + thumbnailURL: string; + } + + interface GetSourcesOptions { + types: Array; + thumbnailSize?: { + height: number; + width: number; + }; + fetchWindowIcons?: boolean; + } + + interface Electron { + getDesktopCapturerSources(options: GetSourcesOptions): Promise>; } interface Document { diff --git a/src/components/views/elements/DesktopCapturerSourcePicker.tsx b/src/components/views/elements/DesktopCapturerSourcePicker.tsx index 1f00353aeb..034fc3d49c 100644 --- a/src/components/views/elements/DesktopCapturerSourcePicker.tsx +++ b/src/components/views/elements/DesktopCapturerSourcePicker.tsx @@ -20,14 +20,21 @@ import BaseDialog from "..//dialogs/BaseDialog"; import DialogButtons from "./DialogButtons"; import classNames from 'classnames'; import AccessibleButton from './AccessibleButton'; -import { getDesktopCapturerSources } from "matrix-js-sdk/src/webrtc/call"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import TabbedView, { Tab, TabLocation } from '../../structures/TabbedView'; -export interface DesktopCapturerSource { - id: string; - name: string; - thumbnailURL; +export function getDesktopCapturerSources(): Promise> { + const options: GetSourcesOptions = { + thumbnailSize: { + height: 176, + width: 312, + }, + types: [ + "screen", + "window", + ], + }; + return window.electron.getDesktopCapturerSources(options); } export enum Tabs { @@ -78,7 +85,7 @@ export interface PickerIState { selectedSource: DesktopCapturerSource | null; } export interface PickerIProps { - onFinished(source: DesktopCapturerSource): void; + onFinished(sourceId: string): void; } @replaceableComponent("views.elements.DesktopCapturerSourcePicker") @@ -123,7 +130,7 @@ export default class DesktopCapturerSourcePicker extends React.Component< }; private onShare = (): void => { - this.props.onFinished(this.state.selectedSource); + this.props.onFinished(this.state.selectedSource.id); }; private onTabChange = (): void => { diff --git a/src/components/views/voip/CallView.tsx b/src/components/views/voip/CallView.tsx index 9d82291286..cec67499ae 100644 --- a/src/components/views/voip/CallView.tsx +++ b/src/components/views/voip/CallView.tsx @@ -273,14 +273,14 @@ export default class CallView extends React.Component { }; private onScreenshareClick = async (): Promise => { - const isScreensharing = await this.props.call.setScreensharingEnabled( - !this.state.screensharing, - async (): Promise => { - const { finished } = Modal.createDialog(DesktopCapturerSourcePicker); - const [source] = await finished; - return source; - }, - ); + let isScreensharing; + if (this.state.screensharing) { + isScreensharing = await this.props.call.setScreensharingEnabled(false); + } else { + const { finished } = Modal.createDialog(DesktopCapturerSourcePicker); + const [source] = await finished; + isScreensharing = await this.props.call.setScreensharingEnabled(true, source); + } this.setState({ sidebarShown: true,