'use client'; import { Monitor, MonitorPlay, Users } from 'lucide-react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { useEffect } from 'react'; import { useWatchRoomContext } from '@/components/WatchRoomProvider'; import { useScreenShare } from '@/hooks/useScreenShare'; const NEW_TAB_KEY_PREFIX = 'watch_room_screen_home_opened_'; export default function WatchRoomScreenPage() { const router = useRouter(); const watchRoom = useWatchRoomContext(); const { currentRoom, members, leaveRoom } = watchRoom; const { currentRoom: screenRoom, isOwner, isSharing, isStarting, error, localVideoRef, remoteVideoRef, startSharing, stopSharing, } = useScreenShare(); useEffect(() => { if (!currentRoom) { router.replace('/watch-room'); return; } if (currentRoom.roomType !== 'screen') { router.replace('/watch-room'); } }, [currentRoom, router]); useEffect(() => { if (!screenRoom || !isOwner) return; const key = `${NEW_TAB_KEY_PREFIX}${screenRoom.id}`; if (sessionStorage.getItem(key)) return; sessionStorage.setItem(key, '1'); window.open('/?watchRoomNoConnect=1', '_blank', 'noopener,noreferrer'); }, [isOwner, screenRoom?.id]); if (!screenRoom || screenRoom.roomType !== 'screen') { return null; } const handleLeave = () => { if (isOwner && isSharing) { stopSharing(true); } leaveRoom(); router.push('/watch-room'); }; return (
房间:{screenRoom.name} · 房主:{screenRoom.ownerName}
{isOwner ? '点击开始共享,向房员推送浏览器画面' : '等待房主开始共享屏幕'}
{isOwner && (本页不要关闭;已尝试为你新开一个主页标签页方便继续浏览。
)}类型:屏幕共享
状态:{isSharing ? '共享中' : '未开始'}
成员:{members.length} 人