diff --git a/src/e2ee/sharedKeyManagement.ts b/src/e2ee/sharedKeyManagement.ts index 651012c7..11b436ea 100644 --- a/src/e2ee/sharedKeyManagement.ts +++ b/src/e2ee/sharedKeyManagement.ts @@ -14,13 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { useEffect, useMemo } from "react"; -import { randomString } from "matrix-js-sdk/src/randomstring"; +import { useMemo } from "react"; import { useEnableE2EE } from "../settings/useSetting"; import { useLocalStorage } from "../useLocalStorage"; -const getRoomSharedKeyLocalStorageKey = (roomId: string): string => +export const getRoomSharedKeyLocalStorageKey = (roomId: string): string => `room-shared-key-${roomId}`; export const useRoomSharedKey = ( @@ -30,11 +29,5 @@ export const useRoomSharedKey = ( const [e2eeEnabled] = useEnableE2EE(); const [roomSharedKey, setRoomSharedKey] = useLocalStorage(key); - useEffect(() => { - if ((roomSharedKey && roomSharedKey !== "") || !e2eeEnabled) return; - - setRoomSharedKey(randomString(32)); - }, [roomSharedKey, e2eeEnabled, setRoomSharedKey]); - return e2eeEnabled ? [roomSharedKey, setRoomSharedKey] : [null, null]; }; diff --git a/src/home/RegisteredView.tsx b/src/home/RegisteredView.tsx index 76da921d..8fbea9c1 100644 --- a/src/home/RegisteredView.tsx +++ b/src/home/RegisteredView.tsx @@ -17,6 +17,7 @@ limitations under the License. import { useState, useCallback, FormEvent, FormEventHandler } from "react"; import { useHistory } from "react-router-dom"; import { MatrixClient } from "matrix-js-sdk/src/client"; +import { randomString } from "matrix-js-sdk/src/randomstring"; import { useTranslation } from "react-i18next"; import { @@ -40,6 +41,8 @@ import { CallType, CallTypeDropdown } from "./CallTypeDropdown"; import { useOptInAnalytics } from "../settings/useSetting"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; import { E2EEBanner } from "../E2EEBanner"; +import { setLocalStorageItem } from "../useLocalStorage"; +import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement"; interface Props { client: MatrixClient; @@ -70,11 +73,14 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) { setError(undefined); setLoading(true); - const [roomAlias] = await createRoom(client, roomName, ptt); + const [roomAlias, roomId] = await createRoom(client, roomName, ptt); - if (roomAlias) { - history.push(`/${roomAlias.substring(1).split(":")[0]}`); - } + setLocalStorageItem( + getRoomSharedKeyLocalStorageKey(roomId), + randomString(32) + ); + + history.push(`/${roomAlias.substring(1).split(":")[0]}`); } submit().catch((error) => { diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 4c796e9f..9f8f7dc4 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -40,6 +40,7 @@ import { MuteStates, useMuteStates } from "./MuteStates"; import { useMediaDevices, MediaDevices } from "../livekit/MediaDevicesContext"; import { useRoomSharedKey } from "../e2ee/sharedKeyManagement"; import { PASSWORD_STRING, useUrlParams } from "../UrlParams"; +import { useEnableE2EE } from "../settings/useSetting"; declare global { interface Window { @@ -244,6 +245,7 @@ export function GroupCallView({ } }, [groupCall, state, leave]); + const [e2eeEnabled] = useEnableE2EE(); const [e2eeSharedKey, setE2EESharedKey] = useRoomSharedKey( groupCall.room.roomId ); @@ -275,6 +277,18 @@ export function GroupCallView({ groupCall.enter(); }, [groupCall]); + if (!password && !e2eeSharedKey && e2eeEnabled) { + return ( + + ); + } + const livekitServiceURL = groupCall.livekitServiceURL ?? Config.get().livekit?.livekit_service_url; if (!livekitServiceURL) {