Skip to content

Commit 87f02b2

Browse files
authored
Merge pull request #3293 from element-hq/toger5/more-disconnect-logging (#3297)
Fix creating two lk rooms if there is no local store setup (fixes a resulting disconnect bug)
1 parent 24cb61c commit 87f02b2

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/e2ee/sharedKeyManagement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getRoomSharedKeyLocalStorageKey = (roomId: string): string =>
2121

2222
const useInternalRoomSharedKey = (roomId: string): string | null => {
2323
const key = getRoomSharedKeyLocalStorageKey(roomId);
24-
const roomSharedKey = useLocalStorage(key)[0];
24+
const [roomSharedKey] = useLocalStorage(key);
2525

2626
return roomSharedKey;
2727
};

src/livekit/useLivekit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function useLivekit(
131131
// @livekit/components-react. JSON.stringify() is used in deps of a
132132
// useEffect() with an argument that references itself, if E2EE is enabled
133133
const room = useMemo(() => {
134+
logger.info("[LivekitRooms] Create LiveKit room with options", roomOptions);
134135
const r = new Room(roomOptions);
135136
r.setE2EEEnabled(e2eeSystem.kind !== E2eeType.NONE).catch((e) => {
136137
logger.error("Failed to set E2EE enabled on room", e);

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ window.setLKLogLevel = setLKLogLevel;
2929
initRageshake().catch((e) => {
3030
logger.error("Failed to initialize rageshake", e);
3131
});
32-
setLKLogLevel("warn");
32+
setLKLogLevel("info");
3333
setLKLogExtension((level, msg, context) => {
3434
// we pass a synthetic logger name of "livekit" to the rageshake to make it easier to read
3535
global.mx_rage_logger.log(level, "livekit", msg, context);

src/useLocalStorage.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export const useLocalStorage = (
4242
};
4343

4444
export const setLocalStorageItem = (key: string, value: string): void => {
45+
// Avoid unnecessary updates. Not avoiding them so can cause unexpected state updates across hooks.
46+
// For instance:
47+
// - In call view uses useRoomEncryptionSystem
48+
// - This will set the key again.
49+
// - All other instances of useRoomEncryptionSystem will now do a useMemo update of the e2eeSystem
50+
// - because the dependency `storedPassword = useInternalRoomSharedKey(roomId);` would change.
51+
if (localStorage.getItem(key) === value) return;
52+
4553
localStorage.setItem(key, value);
4654
localStorageBus.emit(key, value);
4755
};

0 commit comments

Comments
 (0)