Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(voice): share the voice room across popout trees (#2399)

Hampusadb9a689f068
diff --git a/fluxer_app/src/features/voice/components/VoiceLiveKitRoot.tsx b/fluxer_app/src/features/voice/components/VoiceLiveKitRoot.tsx
index 7a866d31d..4002569f3 100644
--- a/fluxer_app/src/features/voice/components/VoiceLiveKitRoot.tsx
+++ b/fluxer_app/src/features/voice/components/VoiceLiveKitRoot.tsx
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {VoiceRoomContext} from '@app/features/voice/components/VoiceRoomContext';
import {type RoomAudioRendererProps, RoomContext} from '@livekit/components-react';
import type {Room} from 'livekit-client';
import type React from 'react';
@@ -43,13 +44,15 @@ export function VoiceLiveKitRoot({room, children}: VoiceLiveKitRootProps): React
}, [components, room]);
if (!room) {
- return <>{children}</>;
+ return <VoiceRoomContext.Provider value={undefined}>{children}</VoiceRoomContext.Provider>;
}
return (
- <RoomContext.Provider value={room}>
- {children}
- {components && <components.RoomAudioRenderer data-flx="app.app.app-wrapper.room-audio-renderer" />}
- </RoomContext.Provider>
+ <VoiceRoomContext.Provider value={room}>
+ <RoomContext.Provider value={room}>
+ {children}
+ {components && <components.RoomAudioRenderer data-flx="app.app.app-wrapper.room-audio-renderer" />}
+ </RoomContext.Provider>
+ </VoiceRoomContext.Provider>
);
}
diff --git a/fluxer_app/src/features/voice/components/VoiceRoomContext.ts b/fluxer_app/src/features/voice/components/VoiceRoomContext.ts
new file mode 100644
index 000000000..ebe42f8c7
--- /dev/null
+++ b/fluxer_app/src/features/voice/components/VoiceRoomContext.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {Room} from 'livekit-client';
+import {createContext, useContext} from 'react';
+
+export const VoiceRoomContext = createContext<Room | undefined>(undefined);
+
+export function useMaybeVoiceRoom(): Room | undefined {
+ return useContext(VoiceRoomContext);
+}