屏幕共享优化
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
'use client';
|
||||
|
||||
import React, { createContext, useCallback,useContext, useEffect, useState } from 'react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import { useWatchRoom } from '@/hooks/useWatchRoom';
|
||||
|
||||
@@ -14,6 +13,8 @@ import type { ChatMessage, Member, Room, RoomType, ScreenState, WatchRoomConfig
|
||||
|
||||
// Import type from watch-room-socket
|
||||
type WatchRoomSocket = import('@/lib/watch-room-socket').WatchRoomSocket;
|
||||
const WATCH_ROOM_NO_CONNECT_KEY = 'watch_room_no_connect';
|
||||
const WATCH_ROOM_SCREEN_PATH = '/watch-room/screen';
|
||||
|
||||
interface WatchRoomContextType {
|
||||
socket: WatchRoomSocket | null;
|
||||
@@ -39,6 +40,7 @@ interface WatchRoomContextType {
|
||||
roomId: string;
|
||||
password?: string;
|
||||
userName: string;
|
||||
ownerToken?: string;
|
||||
}) => Promise<{ room: Room; members: Member[] }>;
|
||||
leaveRoom: () => void;
|
||||
getRoomList: () => Promise<Room[]>;
|
||||
@@ -81,12 +83,12 @@ interface WatchRoomProviderProps {
|
||||
}
|
||||
|
||||
export function WatchRoomProvider({ children }: WatchRoomProviderProps) {
|
||||
const searchParams = useSearchParams();
|
||||
const [config, setConfig] = useState<WatchRoomConfig | null>(null);
|
||||
const [isEnabled, setIsEnabled] = useState(false);
|
||||
const [toast, setToast] = useState<ToastProps | null>(null);
|
||||
const [reconnectFailed, setReconnectFailed] = useState(false);
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const [shouldDisableWatchRoomConnection, setShouldDisableWatchRoomConnection] = useState<boolean | null>(null);
|
||||
|
||||
// 处理房间删除的回调
|
||||
const handleRoomDeleted = useCallback((data?: { reason?: string }) => {
|
||||
@@ -123,7 +125,15 @@ export function WatchRoomProvider({ children }: WatchRoomProviderProps) {
|
||||
}, []);
|
||||
|
||||
const watchRoom = useWatchRoom(handleRoomDeleted, handleStateCleared);
|
||||
const shouldDisableWatchRoomConnection = searchParams.get('watchRoomNoConnect') === '1';
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
setShouldDisableWatchRoomConnection(
|
||||
window.location.pathname !== WATCH_ROOM_SCREEN_PATH
|
||||
&& window.localStorage.getItem(WATCH_ROOM_NO_CONNECT_KEY) === '1'
|
||||
);
|
||||
}, []);
|
||||
|
||||
// 检查登录状态
|
||||
useEffect(() => {
|
||||
@@ -162,6 +172,7 @@ export function WatchRoomProvider({ children }: WatchRoomProviderProps) {
|
||||
roomId: info.roomId,
|
||||
password: info.password,
|
||||
userName: info.userName,
|
||||
ownerToken: info.ownerToken,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[WatchRoomProvider] Failed to rejoin room after reconnect:', error);
|
||||
@@ -175,6 +186,10 @@ export function WatchRoomProvider({ children }: WatchRoomProviderProps) {
|
||||
|
||||
// 加载配置
|
||||
useEffect(() => {
|
||||
if (shouldDisableWatchRoomConnection === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldDisableWatchRoomConnection) {
|
||||
setConfig({
|
||||
enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user