🐛(frontend) close native PiP window when leaving the room

Force-close PiP on unmount and reset PiP state so next room starts clean.
This commit is contained in:
Cyril
2026-04-24 13:51:04 +02:00
parent 90ef4ce025
commit 775c8ac073
2 changed files with 20 additions and 1 deletions
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react'
import { useEffect, type ReactNode } from 'react'
import { roomPiPStore } from '@/stores/roomPiP'
import { DocumentPiPPortal } from './DocumentPiPPortal'
import { PipView } from './PipView'
import { useRoomPiP } from '../hooks/useRoomPiP'
@@ -12,6 +13,14 @@ import { useRoomPiP } from '../hooks/useRoomPiP'
export const RoomPiP = (): ReactNode => {
const { isOpen, close } = useRoomPiP()
// Reset PiP state on unmount (e.g. leaving the room) so the next session
// starts with PiP closed and doesn't try to auto-reopen without a user gesture.
useEffect(() => {
return () => {
roomPiPStore.isOpen = false
}
}, [])
const portal = DocumentPiPPortal({
isOpen,
onClose: close,
@@ -70,6 +70,16 @@ export const useDocumentPiP = ({
pipWindowRef.current = pipWindow
}, [pipWindow])
// Force-close the native PiP window when the hook unmounts (e.g. the user
// hangs up and the room is navigated away before `closePiP` could run).
useEffect(() => {
return () => {
const win = pipWindowRef.current
if (win && !win.closed) win.close()
pipWindowRef.current = null
}
}, [])
useEffect(() => {
if (!pipWindow) return