mirror of
https://github.com/suitenumerique/meet.git
synced 2026-07-26 11:58:53 +00:00
✨(feat) move pip state to valtio store
replace context provider with shared store for pip ui state
This commit is contained in:
@@ -4,7 +4,7 @@ import { useRoomPiP } from '../hooks/useRoomPiP'
|
||||
|
||||
/**
|
||||
* Wrapper that mounts the PiP UI when room-level PiP state is enabled.
|
||||
* Bridges RoomPiPProvider state with DocumentPiPPortal and PipView rendering.
|
||||
* Bridges Valtio-backed PiP state with DocumentPiPPortal and PipView rendering.
|
||||
*/
|
||||
export const RoomPiP = () => {
|
||||
const { isOpen, close } = useRoomPiP()
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
import { RoomPiPContext } from './roomPiPContext'
|
||||
|
||||
/**
|
||||
* Context Provider that manages Picture-in-Picture state at the room level.
|
||||
* Handles open/closed state, browser support detection, and exposes open/close/toggle functions.
|
||||
* Components access PiP state via the useRoomPiP hook.
|
||||
*/
|
||||
export const RoomPiPProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) => {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
// Feature detection for Document Picture-in-Picture.
|
||||
const isSupported =
|
||||
typeof window !== 'undefined' && 'documentPictureInPicture' in window
|
||||
|
||||
const open = useCallback(() => setIsOpen(true), [])
|
||||
const close = useCallback(() => setIsOpen(false), [])
|
||||
const toggle = useCallback(() => setIsOpen((current) => !current), [])
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
isSupported,
|
||||
isOpen,
|
||||
open,
|
||||
close,
|
||||
toggle,
|
||||
}),
|
||||
[close, isOpen, isSupported, open, toggle]
|
||||
)
|
||||
|
||||
return (
|
||||
<RoomPiPContext.Provider value={value}>{children}</RoomPiPContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { createContext } from 'react'
|
||||
|
||||
export type RoomPiPContextValue = {
|
||||
isSupported: boolean
|
||||
isOpen: boolean
|
||||
open: () => void
|
||||
close: () => void
|
||||
toggle: () => void
|
||||
}
|
||||
|
||||
export const RoomPiPContext = createContext<RoomPiPContextValue | null>(null)
|
||||
@@ -1,10 +1,29 @@
|
||||
import { useContext } from 'react'
|
||||
import { RoomPiPContext } from './roomPiPContext'
|
||||
import { useCallback } from 'react'
|
||||
import { useSnapshot } from 'valtio'
|
||||
import { roomPiPStore } from '@/stores/roomPiP'
|
||||
|
||||
export const useRoomPiP = () => {
|
||||
const context = useContext(RoomPiPContext)
|
||||
if (!context) {
|
||||
throw new Error('useRoomPiP must be used within a RoomPiPProvider')
|
||||
const { isOpen } = useSnapshot(roomPiPStore)
|
||||
const isSupported =
|
||||
typeof window !== 'undefined' && 'documentPictureInPicture' in window
|
||||
|
||||
const open = useCallback(() => {
|
||||
roomPiPStore.isOpen = true
|
||||
}, [])
|
||||
|
||||
const close = useCallback(() => {
|
||||
roomPiPStore.isOpen = false
|
||||
}, [])
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
roomPiPStore.isOpen = !roomPiPStore.isOpen
|
||||
}, [])
|
||||
|
||||
return {
|
||||
isSupported,
|
||||
isOpen,
|
||||
open,
|
||||
close,
|
||||
toggle,
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import { useVideoResolutionSubscription } from '../hooks/useVideoResolutionSubsc
|
||||
import { SettingsDialogProvider } from '@/features/settings/components/SettingsDialogProvider'
|
||||
import { IsIdleDisconnectModal } from '../components/IsIdleDisconnectModal'
|
||||
import { RoomPiP } from '../components/RoomPiP'
|
||||
import { RoomPiPProvider } from '../hooks/RoomPiPProvider'
|
||||
import { getParticipantName } from '@/features/rooms/utils/getParticipantName'
|
||||
import { useScreenReaderAnnounce } from '@/hooks/useScreenReaderAnnounce'
|
||||
import { ReactionPortals } from '@/features/reactions/components/ReactionPortals'
|
||||
@@ -240,11 +239,10 @@ export function VideoConference({ ...props }: VideoConferenceProps) {
|
||||
}}
|
||||
>
|
||||
{isWeb() && (
|
||||
<RoomPiPProvider>
|
||||
<LayoutContextProvider
|
||||
value={layoutContext}
|
||||
// onPinChange={handleFocusStateChange}
|
||||
>
|
||||
<LayoutContextProvider
|
||||
value={layoutContext}
|
||||
// onPinChange={handleFocusStateChange}
|
||||
>
|
||||
<ScreenShareErrorModal
|
||||
isOpen={isShareErrorVisible}
|
||||
onClose={() => setIsShareErrorVisible(false)}
|
||||
@@ -293,8 +291,7 @@ export function VideoConference({ ...props }: VideoConferenceProps) {
|
||||
/>
|
||||
<SidePanel />
|
||||
<RoomPiP />
|
||||
</LayoutContextProvider>
|
||||
</RoomPiPProvider>
|
||||
</LayoutContextProvider>
|
||||
)}
|
||||
<RoomAudioRenderer />
|
||||
<ConnectionStateToast />
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { proxy } from 'valtio'
|
||||
|
||||
type State = {
|
||||
isOpen: boolean
|
||||
}
|
||||
|
||||
export const roomPiPStore = proxy<State>({
|
||||
isOpen: false,
|
||||
})
|
||||
Reference in New Issue
Block a user