diff --git a/src/home/RegisteredView.tsx b/src/home/RegisteredView.tsx index 5de21a3e..8a5115a6 100644 --- a/src/home/RegisteredView.tsx +++ b/src/home/RegisteredView.tsx @@ -38,7 +38,7 @@ import { JoinExistingCallModal } from "./JoinExistingCallModal"; import { Caption, Title } from "../typography/Typography"; import { Form } from "../form/Form"; import { CallType, CallTypeDropdown } from "./CallTypeDropdown"; -import { useOptInAnalytics } from "../settings/useSetting"; +import { useEnableE2EE, useOptInAnalytics } from "../settings/useSetting"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; import { E2EEBanner } from "../E2EEBanner"; import { setLocalStorageItem } from "../useLocalStorage"; @@ -57,6 +57,7 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) { const history = useHistory(); const { t } = useTranslation(); const { modalState, modalProps } = useModalTriggerState(); + const [e2eeEnabled] = useEnableE2EE(); const onSubmit: FormEventHandler = useCallback( (e: FormEvent) => { @@ -73,12 +74,16 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) { setError(undefined); setLoading(true); - const [roomAlias, roomId] = await createRoom(client, roomName, ptt); + const roomId = ( + await createRoom(client, roomName, ptt, e2eeEnabled ?? false) + )[1]; - setLocalStorageItem( - getRoomSharedKeyLocalStorageKey(roomId), - randomString(32) - ); + if (e2eeEnabled) { + setLocalStorageItem( + getRoomSharedKeyLocalStorageKey(roomId), + randomString(32) + ); + } history.push(`/room/#?roomId=${roomId}`); } @@ -96,7 +101,7 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) { } }); }, - [client, history, modalState, callType] + [client, history, modalState, callType, e2eeEnabled] ); const recentRooms = useGroupCallRooms(client); diff --git a/src/home/UnauthenticatedView.tsx b/src/home/UnauthenticatedView.tsx index a9c840df..721c56d1 100644 --- a/src/home/UnauthenticatedView.tsx +++ b/src/home/UnauthenticatedView.tsx @@ -40,9 +40,11 @@ import styles from "./UnauthenticatedView.module.css"; import commonStyles from "./common.module.css"; import { generateRandomName } from "../auth/generateRandomName"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; -import { useOptInAnalytics } from "../settings/useSetting"; +import { useEnableE2EE, useOptInAnalytics } from "../settings/useSetting"; import { Config } from "../config/Config"; import { E2EEBanner } from "../E2EEBanner"; +import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement"; +import { setLocalStorageItem } from "../useLocalStorage"; export const UnauthenticatedView: FC = () => { const { setClient } = useClient(); @@ -58,6 +60,8 @@ export const UnauthenticatedView: FC = () => { const history = useHistory(); const { t } = useTranslation(); + const [e2eeEnabled] = useEnableE2EE(); + const onSubmit: FormEventHandler = useCallback( (e) => { e.preventDefault(); @@ -79,9 +83,18 @@ export const UnauthenticatedView: FC = () => { true ); - let roomAlias: string; + let roomId: string; try { - [roomAlias] = await createRoom(client, roomName, ptt); + roomId = ( + await createRoom(client, roomName, ptt, e2eeEnabled ?? false) + )[1]; + + if (e2eeEnabled) { + setLocalStorageItem( + getRoomSharedKeyLocalStorageKey(roomId), + randomString(32) + ); + } } catch (error) { if (!setClient) { throw error; @@ -120,7 +133,16 @@ export const UnauthenticatedView: FC = () => { reset(); }); }, - [register, reset, execute, history, callType, modalState, setClient] + [ + register, + reset, + execute, + history, + callType, + modalState, + setClient, + e2eeEnabled, + ] ); const callNameLabel = diff --git a/src/room/useLoadGroupCall.ts b/src/room/useLoadGroupCall.ts index 4aa82f11..3436360c 100644 --- a/src/room/useLoadGroupCall.ts +++ b/src/room/useLoadGroupCall.ts @@ -25,12 +25,16 @@ import { logger } from "matrix-js-sdk/src/logger"; import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client"; import { SyncState } from "matrix-js-sdk/src/sync"; import { useTranslation } from "react-i18next"; +import { randomString } from "matrix-js-sdk/src/randomstring"; import type { Room } from "matrix-js-sdk/src/models/room"; import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall"; +import { setLocalStorageItem } from "../useLocalStorage"; import { isLocalRoomId, createRoom, roomNameFromRoomId } from "../matrix-utils"; import { translatedError } from "../TranslatedError"; import { widget } from "../widget"; +import { useEnableE2EE } from "../settings/useSetting"; +import { getRoomSharedKeyLocalStorageKey } from "../e2ee/sharedKeyManagement"; const STATS_COLLECT_INTERVAL_TIME_MS = 10000; @@ -67,6 +71,8 @@ export const useLoadGroupCall = ( const { t } = useTranslation(); const [state, setState] = useState({ kind: "loading" }); + const [e2eeEnabled] = useEnableE2EE(); + useEffect(() => { const fetchOrCreateRoom = async (): Promise => { try { @@ -104,8 +110,17 @@ export const useLoadGroupCall = ( const [, roomId] = await createRoom( client, roomNameFromRoomId(roomIdOrAlias), - createPtt + createPtt, + e2eeEnabled ?? false ); + + if (e2eeEnabled) { + setLocalStorageItem( + getRoomSharedKeyLocalStorageKey(roomId), + randomString(32) + ); + } + // likewise, wait for the room await client.waitUntilRoomReadyForGroupCalls(roomId); return client.getRoom(roomId)!; @@ -194,7 +209,7 @@ export const useLoadGroupCall = ( .then(fetchOrCreateGroupCall) .then((groupCall) => setState({ kind: "loaded", groupCall })) .catch((error) => setState({ kind: "failed", error })); - }, [client, roomIdOrAlias, viaServers, createPtt, t]); + }, [client, roomIdOrAlias, viaServers, createPtt, t, e2eeEnabled]); return state; };