Skip to content

Commit

Permalink
Merge pull request #1891 from vector-im/dbkr/require_e2eeconfig
Browse files Browse the repository at this point in the history
Make E2EEConfig required
  • Loading branch information
dbkr authored Nov 15, 2023
2 parents d46156d + 5ab6d18 commit 56c4ad0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/livekit/useLiveKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ interface UseLivekitResult {
export function useLiveKit(
rtcSession: MatrixRTCSession,
muteStates: MuteStates,
sfuConfig?: SFUConfig,
e2eeConfig?: E2EEConfig,
sfuConfig: SFUConfig | undefined,
e2eeConfig: E2EEConfig,
): UseLivekitResult {
const e2eeOptions = useMemo((): E2EEOptions | undefined => {
if (!e2eeConfig || e2eeConfig.mode === E2eeType.NONE) return undefined;
if (e2eeConfig.mode === E2eeType.NONE) return undefined;

if (e2eeConfig.mode === E2eeType.PER_PARTICIPANT) {
return {
Expand All @@ -79,7 +79,7 @@ export function useLiveKit(
}, [e2eeConfig]);

useEffect(() => {
if (!e2eeConfig || !e2eeOptions) return;
if (e2eeConfig.mode === E2eeType.NONE || !e2eeOptions) return;

if (e2eeConfig.mode === E2eeType.PER_PARTICIPANT) {
(e2eeOptions.keyProvider as MatrixKeyProvider).setRTCSession(rtcSession);
Expand Down Expand Up @@ -137,7 +137,11 @@ export function useLiveKit(
// We have to create the room manually here due to a bug inside
// @livekit/components-react. JSON.stringify() is used in deps of a
// useEffect() with an argument that references itself, if E2EE is enabled
const roomWithoutProps = useMemo(() => new Room(roomOptions), [roomOptions]);
const roomWithoutProps = useMemo(() => {
const r = new Room(roomOptions);
r.setE2EEEnabled(e2eeConfig.mode !== E2eeType.NONE);
return r;
}, [roomOptions, e2eeConfig]);
const { room } = useLiveKitRoom({
token: sfuConfig?.jwt,
serverUrl: sfuConfig?.url,
Expand Down
4 changes: 3 additions & 1 deletion src/room/GroupCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ export const GroupCallView: FC<Props> = ({
}
}, [isJoined, rtcSession]);

const e2eeConfig = useMemo((): E2EEConfig | undefined => {
const e2eeConfig = useMemo((): E2EEConfig => {
if (perParticipantE2EE) {
return { mode: E2eeType.PER_PARTICIPANT };
} else if (e2eeSharedKey) {
return { mode: E2eeType.SHARED_KEY, sharedKey: e2eeSharedKey };
} else {
return { mode: E2eeType.NONE };
}
}, [perParticipantE2EE, e2eeSharedKey]);

Expand Down
6 changes: 1 addition & 5 deletions src/room/InCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const POST_FOCUS_PARTICIPANT_UPDATE_DELAY_MS = 3000;

export interface ActiveCallProps
extends Omit<InCallViewProps, "livekitRoom" | "connState"> {
e2eeConfig?: E2EEConfig;
e2eeConfig: E2EEConfig;
}

export const ActiveCall: FC<ActiveCallProps> = (props) => {
Expand All @@ -111,10 +111,6 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
return null;
}

if (props.e2eeConfig && !livekitRoom.isE2EEEnabled) {
livekitRoom.setE2EEEnabled(!!props.e2eeConfig);
}

return (
<RoomContext.Provider value={livekitRoom}>
<InCallView {...props} livekitRoom={livekitRoom} connState={connState} />
Expand Down

0 comments on commit 56c4ad0

Please sign in to comment.