From 4ee6e450b7b2404b6ee5b9b90db6111d11c392c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 20 Oct 2022 19:07:27 +0200 Subject: [PATCH] Make Element Call screensharing work on desktop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/room/useGroupCall.ts | 27 ++++++++++++++++++++++++--- src/widget.ts | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/room/useGroupCall.ts b/src/room/useGroupCall.ts index 5221f80..87bbdb2 100644 --- a/src/room/useGroupCall.ts +++ b/src/room/useGroupCall.ts @@ -30,6 +30,7 @@ import { useTranslation } from "react-i18next"; import { usePageUnload } from "./usePageUnload"; import { TranslatedError, translatedError } from "../TranslatedError"; +import { ElementWidgetActions, widget } from "../widget"; export interface UseGroupCallReturnType { state: GroupCallState; @@ -304,11 +305,31 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType { const toggleScreensharing = useCallback(() => { updateState({ requestingScreenshare: true }); - groupCall - .setScreensharingEnabled(!groupCall.isScreensharing(), { audio: true }) - .then(() => { + if (groupCall.isScreensharing()) { + groupCall.setScreensharingEnabled(false).then(() => { updateState({ requestingScreenshare: false }); }); + } else { + widget.api.transport + .send(ElementWidgetActions.Screenshare, {}) + .then( + (reply: { desktopCapturerSourceId: string; failed?: boolean }) => { + if (reply.failed) { + updateState({ requestingScreenshare: false }); + return; + } + + groupCall + .setScreensharingEnabled(true, { + audio: !reply.desktopCapturerSourceId, + desktopCapturerSourceId: reply.desktopCapturerSourceId, + }) + .then(() => { + updateState({ requestingScreenshare: false }); + }); + } + ); + } }, [groupCall]); const { t } = useTranslation(); diff --git a/src/widget.ts b/src/widget.ts index 56d83c0..aa0be83 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -30,6 +30,7 @@ export enum ElementWidgetActions { HangupCall = "im.vector.hangup", TileLayout = "io.element.tile_layout", SpotlightLayout = "io.element.spotlight_layout", + Screenshare = "io.element.screenshare", } export interface JoinCallData {