From edfae0138c59f7d9fc2790a30f771bd95efde64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 11 Aug 2023 16:59:26 +0200 Subject: [PATCH] Add `useIsRoomE2EE()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/e2ee/sharedKeyManagement.ts | 13 +++++++++++++ src/room/GroupCallView.tsx | 7 ++++++- src/room/InCallView.tsx | 5 ++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/e2ee/sharedKeyManagement.ts b/src/e2ee/sharedKeyManagement.ts index ed7ba2f5..0e373ce1 100644 --- a/src/e2ee/sharedKeyManagement.ts +++ b/src/e2ee/sharedKeyManagement.ts @@ -18,6 +18,7 @@ import { useEffect, useMemo } from "react"; import { useEnableE2EE } from "../settings/useSetting"; import { useLocalStorage } from "../useLocalStorage"; +import { useClient } from "../ClientContext"; import { PASSWORD_STRING, useUrlParams } from "../UrlParams"; export const getRoomSharedKeyLocalStorageKey = (roomId: string): string => @@ -66,4 +67,16 @@ export const useManageRoomSharedKey = (roomId: string): string | null => { return e2eeSharedKey; }; +export const useIsRoomE2EE = (roomId: string): boolean | null => { + const client = useClient(); + const room = useMemo( + () => client.client?.getRoom(roomId) ?? null, + [roomId, client.client] + ); + const isE2EE = useMemo( + () => (room ? !room?.getCanonicalAlias() : null), + [room] + ); + + return isE2EE; }; diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 5b4068c4..c6c73815 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -40,7 +40,7 @@ import { MuteStates, useMuteStates } from "./MuteStates"; import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext"; import { useManageRoomSharedKey, - useRoomSharedKey, + useIsRoomE2EE, } from "../e2ee/sharedKeyManagement"; import { useEnableE2EE } from "../settings/useSetting"; @@ -78,6 +78,7 @@ export function GroupCallView({ } = useGroupCall(groupCall, client); const e2eeSharedKey = useManageRoomSharedKey(groupCall.room.roomId); + const isRoomE2EE = useIsRoomE2EE(groupCall.room.roomId); const { t } = useTranslation(); @@ -272,6 +273,10 @@ export function GroupCallView({ ); } + if (!e2eeEnabled && isRoomE2EE) { + return ; + } + const livekitServiceURL = groupCall.livekitServiceURL ?? Config.get().livekit?.livekit_service_url; if (!livekitServiceURL) { diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index fd3964c6..fa99a5c9 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -88,6 +88,7 @@ import { useEventEmitterThree } from "../useEvents"; import { useWakeLock } from "../useWakeLock"; import { useMergedRefs } from "../useMergedRefs"; import { MuteStates } from "./MuteStates"; +import { useIsRoomE2EE } from "../e2ee/sharedKeyManagement"; const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {}); // There is currently a bug in Safari our our code with cloning and sending MediaStreams @@ -145,6 +146,8 @@ export function InCallView({ usePreventScroll(); useWakeLock(); + const isRoomE2EE = useIsRoomE2EE(groupCall.room.roomId); + const containerRef1 = useRef(null); const [containerRef2, bounds] = useMeasure({ polyfill: ResizeObserver }); const boundsValid = bounds.height > 0; @@ -424,7 +427,7 @@ export function InCallView({ users={unencryptedEventsFromUsers} room={groupCall.room} /> - + {!isRoomE2EE && }