Add useIsRoomE2EE()

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2023-08-11 16:59:26 +02:00
parent e246c053c1
commit edfae0138c
3 changed files with 23 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import { useEffect, useMemo } from "react";
import { useEnableE2EE } from "../settings/useSetting"; import { useEnableE2EE } from "../settings/useSetting";
import { useLocalStorage } from "../useLocalStorage"; import { useLocalStorage } from "../useLocalStorage";
import { useClient } from "../ClientContext";
import { PASSWORD_STRING, useUrlParams } from "../UrlParams"; import { PASSWORD_STRING, useUrlParams } from "../UrlParams";
export const getRoomSharedKeyLocalStorageKey = (roomId: string): string => export const getRoomSharedKeyLocalStorageKey = (roomId: string): string =>
@@ -66,4 +67,16 @@ export const useManageRoomSharedKey = (roomId: string): string | null => {
return e2eeSharedKey; 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;
}; };

View File

@@ -40,7 +40,7 @@ import { MuteStates, useMuteStates } from "./MuteStates";
import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext"; import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext";
import { import {
useManageRoomSharedKey, useManageRoomSharedKey,
useRoomSharedKey, useIsRoomE2EE,
} from "../e2ee/sharedKeyManagement"; } from "../e2ee/sharedKeyManagement";
import { useEnableE2EE } from "../settings/useSetting"; import { useEnableE2EE } from "../settings/useSetting";
@@ -78,6 +78,7 @@ export function GroupCallView({
} = useGroupCall(groupCall, client); } = useGroupCall(groupCall, client);
const e2eeSharedKey = useManageRoomSharedKey(groupCall.room.roomId); const e2eeSharedKey = useManageRoomSharedKey(groupCall.room.roomId);
const isRoomE2EE = useIsRoomE2EE(groupCall.room.roomId);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -272,6 +273,10 @@ export function GroupCallView({
); );
} }
if (!e2eeEnabled && isRoomE2EE) {
return <ErrorView error={new Error("You need to enable E2EE to join.")} />;
}
const livekitServiceURL = const livekitServiceURL =
groupCall.livekitServiceURL ?? Config.get().livekit?.livekit_service_url; groupCall.livekitServiceURL ?? Config.get().livekit?.livekit_service_url;
if (!livekitServiceURL) { if (!livekitServiceURL) {

View File

@@ -88,6 +88,7 @@ import { useEventEmitterThree } from "../useEvents";
import { useWakeLock } from "../useWakeLock"; import { useWakeLock } from "../useWakeLock";
import { useMergedRefs } from "../useMergedRefs"; import { useMergedRefs } from "../useMergedRefs";
import { MuteStates } from "./MuteStates"; import { MuteStates } from "./MuteStates";
import { useIsRoomE2EE } from "../e2ee/sharedKeyManagement";
const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {}); const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {});
// There is currently a bug in Safari our our code with cloning and sending MediaStreams // There is currently a bug in Safari our our code with cloning and sending MediaStreams
@@ -145,6 +146,8 @@ export function InCallView({
usePreventScroll(); usePreventScroll();
useWakeLock(); useWakeLock();
const isRoomE2EE = useIsRoomE2EE(groupCall.room.roomId);
const containerRef1 = useRef<HTMLDivElement | null>(null); const containerRef1 = useRef<HTMLDivElement | null>(null);
const [containerRef2, bounds] = useMeasure({ polyfill: ResizeObserver }); const [containerRef2, bounds] = useMeasure({ polyfill: ResizeObserver });
const boundsValid = bounds.height > 0; const boundsValid = bounds.height > 0;
@@ -424,7 +427,7 @@ export function InCallView({
users={unencryptedEventsFromUsers} users={unencryptedEventsFromUsers}
room={groupCall.room} room={groupCall.room}
/> />
<E2EELock /> {!isRoomE2EE && <E2EELock />}
</LeftNav> </LeftNav>
<RightNav> <RightNav>
<GridLayoutMenu layout={layout} setLayout={setLayout} /> <GridLayoutMenu layout={layout} setLayout={setLayout} />