Skip to content

Commit

Permalink
Ensure encryption key has been set before enabling e2ee (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Sep 27, 2024
1 parent 398b172 commit 7964ba6
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions app/rooms/[roomName]/PageClientImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function VideoConferenceComponent(props: {
new Worker(new URL('livekit-client/e2ee-worker', import.meta.url));
const e2eeEnabled = !!(e2eePassphrase && worker);
const keyProvider = new ExternalE2EEKeyProvider();
const [e2eeSetupComplete, setE2eeSetupComplete] = React.useState(false);

const roomOptions = React.useMemo((): RoomOptions => {
let videoCodec: VideoCodec | undefined = props.options.codec ? props.options.codec : 'vp9';
Expand Down Expand Up @@ -131,23 +132,32 @@ function VideoConferenceComponent(props: {
}
: undefined,
};
// @ts-ignore
setLogLevel('debug', 'lk-e2ee');
}, [props.userChoices, props.options.hq, props.options.codec]);

const room = React.useMemo(() => new Room(roomOptions), []);

if (e2eeEnabled) {
keyProvider.setKey(decodePassphrase(e2eePassphrase));
room.setE2EEEnabled(true).catch((e) => {
if (e instanceof DeviceUnsupportedError) {
alert(
`You're trying to join an encrypted meeting, but your browser does not support it. Please update it to the latest version and try again.`,
);
console.error(e);
}
});
}
React.useEffect(() => {
if (e2eeEnabled) {
keyProvider
.setKey(decodePassphrase(e2eePassphrase))
.then(() => {
room.setE2EEEnabled(true).catch((e) => {
if (e instanceof DeviceUnsupportedError) {
alert(
`You're trying to join an encrypted meeting, but your browser does not support it. Please update it to the latest version and try again.`,
);
console.error(e);
} else {
throw e;
}
});
})
.then(() => setE2eeSetupComplete(true));
} else {
setE2eeSetupComplete(true);
}
}, [e2eeEnabled, room, e2eePassphrase]);

const connectOptions = React.useMemo((): RoomConnectOptions => {
return {
autoSubscribe: true,
Expand All @@ -170,6 +180,7 @@ function VideoConferenceComponent(props: {
return (
<>
<LiveKitRoom
connect={e2eeSetupComplete}
room={room}
token={props.connectionDetails.participantToken}
serverUrl={props.connectionDetails.serverUrl}
Expand Down

0 comments on commit 7964ba6

Please sign in to comment.