diff --git a/src/pages/Home_v_2504/components/VideoPlayer/index.tsx b/src/pages/Home_v_2504/components/VideoPlayer/index.tsx index d04f1754266128fcd04a76cb1da269597734dfe3..a6c3573160480ac86bd3199f671a29b800cc1968 100644 --- a/src/pages/Home_v_2504/components/VideoPlayer/index.tsx +++ b/src/pages/Home_v_2504/components/VideoPlayer/index.tsx @@ -3,6 +3,18 @@ import { message } from 'antd'; import { getPreviewUrl } from '@/services/VideoAPI'; import services from '@/services'; +const isDebug = false; + +const debugLog = (type: string, ...args: any[]) => { + if (isDebug) { + if(type === 'log' || type === undefined || type === null || type === '') { + console.log(...args); + } else if(type === 'error') { + console.error(...args); + } + } +}; + // Define types interface VideoPlayerProps { deviceId: string; @@ -35,16 +47,16 @@ if (typeof window !== 'undefined' && !window.hikPlayerInstances) { if (typeof window !== 'undefined') { window.cleanupHikPlayer = (playerId: string) => { try { - console.log(`手动清理播放器: ${playerId}`); + debugLog('log', `手动清理播放器: ${playerId}`); // 检查是否有缓存的实例 const cachedInstance = window.hikPlayerInstances?.[playerId]; if (cachedInstance) { try { cachedInstance.JS_HideWnd(); - console.log(`已手动隐藏播放器: ${playerId}`); + debugLog('log', `已手动隐藏播放器: ${playerId}`); } catch (err) { - console.error(`手动隐藏播放器出错: ${err}`); + debugLog('error', `手动隐藏播放器出错: ${err}`); } } @@ -53,14 +65,14 @@ if (typeof window !== 'undefined') { if (container) { // 设置为隐藏状态 container.style.visibility = 'hidden'; - console.log(`已手动设置播放器容器为隐藏: ${playerId}`); + debugLog('log', `已手动设置播放器容器为隐藏: ${playerId}`); } else { - console.error(`找不到播放器容器: ${playerId}`); + debugLog('error', `找不到播放器容器: ${playerId}`); } return true; } catch (error) { - console.error(`手动清理播放器出错: ${error}`); + debugLog('error', `手动清理播放器出错: ${error}`); return false; } }; @@ -69,12 +81,12 @@ if (typeof window !== 'undefined') { // Add the Hikvision script to the document const loadScript = (src: string): Promise => { return new Promise((resolve, reject) => { - console.log(`Loading script: ${src}`); + debugLog('log', `Loading script: ${src}`); // Check if script is already loaded const existingScript = document.querySelector(`script[src="${src}"]`); if (existingScript) { - console.log(`Script already loaded: ${src}`); + debugLog('log', `Script already loaded: ${src}`); resolve(); return; } @@ -84,12 +96,12 @@ const loadScript = (src: string): Promise => { script.async = true; script.onload = () => { - console.log(`Script loaded successfully: ${src}`); + debugLog('log', `Script loaded successfully: ${src}`); resolve(); }; script.onerror = (error) => { - console.error(`Failed to load script: ${src}`, error); + debugLog('error', `Failed to load script: ${src}`, error); reject(error); }; @@ -130,14 +142,14 @@ const VideoPlayer: React.FC = ({ // 初始化插件及依赖 const initDependencies = async () => { - console.log('initDependencies'); + debugLog('log', 'initDependencies'); try { // 尝试加载依赖脚本,先尝试使用已经在index.html中引入的脚本 if (!window.JSEncrypt) { try { await loadScript('/cd-comprehensive/js/hikvision/jsencrypt.min.js'); } catch (err) { - console.error('Failed to load jsencrypt.min.js', err); + debugLog('error', 'Failed to load jsencrypt.min.js', err); } } @@ -146,7 +158,7 @@ const VideoPlayer: React.FC = ({ try { await loadScript('/cd-comprehensive/js/hikvision/web-control_1.2.7.min.js'); } catch (err) { - console.error('Failed to load web-control_1.2.7.min.js', err); + debugLog('error', 'Failed to load web-control_1.2.7.min.js', err); } } @@ -158,10 +170,10 @@ const VideoPlayer: React.FC = ({ throw new Error('WebControl not initialized'); } - console.log('Dependencies loaded successfully!'); + debugLog('log', 'Dependencies loaded successfully!'); return true; } catch (error) { - console.error('Failed to load dependencies:', error); + debugLog('error', 'Failed to load dependencies:', error); onError?.(error); return false; } @@ -172,16 +184,16 @@ const VideoPlayer: React.FC = ({ // 安全检查:确保webControlRef.current存在 const webControl = webControlRef.current; if (!webControl) { - console.log(`${playWndId}:无法执行resize - webControlRef为空,稍后会重试`); + debugLog('log', `${playWndId}:无法执行resize - webControlRef为空,稍后会重试`); return; } try { - console.log(`${playWndId}:执行resize操作:`, PLAYER_WIDTH, PLAYER_HEIGHT); + debugLog('log', `${playWndId}:执行resize操作:`, PLAYER_WIDTH, PLAYER_HEIGHT); webControl.JS_Resize(PLAYER_WIDTH, PLAYER_HEIGHT); setWndCover(); } catch (err) { - console.error(`${playWndId}:resize操作失败:`, err); + debugLog('error', `${playWndId}:resize操作失败:`, err); } }; @@ -189,7 +201,7 @@ const VideoPlayer: React.FC = ({ const setWndCover = () => { const webControl = webControlRef.current; if (!webControl) { - console.log(`${playWndId}:setWndCover - webControlRef为空`); + debugLog('log', `${playWndId}:setWndCover - webControlRef为空`); return; } @@ -198,7 +210,7 @@ const VideoPlayer: React.FC = ({ const iHeight = window.innerHeight; const playWndElement = document.getElementById(playWndId); if (!playWndElement) { - console.log(`${playWndId}:setWndCover - 播放器DOM元素不存在`); + debugLog('log', `${playWndId}:setWndCover - 播放器DOM元素不存在`); return; } @@ -231,7 +243,7 @@ const VideoPlayer: React.FC = ({ webControl.JS_CuttingPartWindow(0, PLAYER_HEIGHT - iCoverBottom, PLAYER_WIDTH, iCoverBottom); } } catch (err) { - console.error(`${playWndId}:执行窗口裁剪出错:`, err); + debugLog('error', `${playWndId}:执行窗口裁剪出错:`, err); } }; @@ -239,25 +251,25 @@ const VideoPlayer: React.FC = ({ const fetchVideoUrl = async (webControl: any) => { // 防止重复获取视频 if (isPlaying) { - console.log(`${playWndId}:视频已在播放中,跳过获取视频流`); + debugLog('log', `${playWndId}:视频已在播放中,跳过获取视频流`); return; } // 正在获取视频URL时避免重复调用 const fetchingKey = `${playWndId}_fetching`; if ((window as any)[fetchingKey]) { - console.log(`${playWndId}:正在获取视频流,跳过重复请求`); + debugLog('log', `${playWndId}:正在获取视频流,跳过重复请求`); return; } try { - console.log(`${playWndId}:开始获取视频流`); + debugLog('log', `${playWndId}:开始获取视频流`); // (window as any)[fetchingKey] = true; (window as any)[fetchingKey] = false; playVideo(webControl, ''); } catch (error) { (window as any)[fetchingKey] = false; - console.error(`${playWndId}:获取视频流错误`, error); + debugLog('error', `${playWndId}:获取视频流错误`, error); // message.error('获取视频流出错'); onError?.(error); } @@ -266,19 +278,19 @@ const VideoPlayer: React.FC = ({ const fetchVideoUrlOld = async (webControl: any) => { // 防止重复获取视频 if (isPlaying) { - console.log(`${playWndId}:视频已在播放中,跳过获取视频流`); + debugLog('log', `${playWndId}:视频已在播放中,跳过获取视频流`); return; } // 正在获取视频URL时避免重复调用 const fetchingKey = `${playWndId}_fetching`; if ((window as any)[fetchingKey]) { - console.log(`${playWndId}:正在获取视频流,跳过重复请求`); + debugLog('log', `${playWndId}:正在获取视频流,跳过重复请求`); return; } try { - console.log(`${playWndId}:开始获取视频流`); + debugLog('log', `${playWndId}:开始获取视频流`); (window as any)[fetchingKey] = true; services.DataBase.getGzInfoData({ @@ -287,22 +299,22 @@ const VideoPlayer: React.FC = ({ (window as any)[fetchingKey] = false; if (res.code === 200) { - console.log(`${playWndId}:获取视频流成功`); + debugLog('log', `${playWndId}:获取视频流成功`); setStreamUrl(res.data); playVideo(webControl, res.data); } else { - console.error(`${playWndId}:获取视频流失败`, res); + debugLog('error', `${playWndId}:获取视频流失败`, res); // message.error('获取视频流失败'); onError?.(new Error('获取视频流失败')); } }).catch(error => { (window as any)[fetchingKey] = false; - console.error(`${playWndId}:获取视频流异常`, error); + debugLog('error', `${playWndId}:获取视频流异常`, error); onError?.(error); }); } catch (error) { (window as any)[fetchingKey] = false; - console.error(`${playWndId}:获取视频流错误`, error); + debugLog('error', `${playWndId}:获取视频流错误`, error); message.error('获取视频流出错'); onError?.(error); } @@ -320,7 +332,7 @@ const VideoPlayer: React.FC = ({ onError?.(new Error('获取视频流失败')); } } catch (error) { - console.error('获取视频流错误', error); + debugLog('error', '获取视频流错误', error); message.error('获取视频流出错'); onError?.(error); } @@ -329,25 +341,25 @@ const VideoPlayer: React.FC = ({ // 播放视频 const playVideo = (webControl: any, url: string) => { if (!webControl) { - console.error(`${playWndId}:无法播放视频 - WebControl实例不可用`); + debugLog('error', `${playWndId}:无法播放视频 - WebControl实例不可用`); return; } // 防止重复播放 if (isPlaying) { - console.log(`${playWndId}:视频已经在播放中,跳过播放`); + debugLog('log', `${playWndId}:视频已经在播放中,跳过播放`); return; } // 正在播放视频时避免重复调用 const playingKey = `${playWndId}_playing`; if ((window as any)[playingKey]) { - console.log(`${playWndId}:视频正在启动播放过程中,跳过重复调用`); + debugLog('log', `${playWndId}:视频正在启动播放过程中,跳过重复调用`); return; } try { - console.log(`${playWndId}:开始播放视频...`); + debugLog('log', `${playWndId}:开始播放视频...`); (window as any)[playingKey] = true; // 显示视频窗口 @@ -357,7 +369,7 @@ const VideoPlayer: React.FC = ({ webControl.JS_Resize(PLAYER_WIDTH, PLAYER_HEIGHT); setWndCover(); - console.log(`${playWndId}:开始预览, 相机码:`, deviceId); + debugLog('log', `${playWndId}:开始预览, 相机码:`, deviceId); const params = { argument: { @@ -374,7 +386,7 @@ const VideoPlayer: React.FC = ({ webControl.JS_RequestInterface(JSON.parse(param)) .then(function(oData: any) { - console.log(`${playWndId}:视频预览启动成功:`, oData); + debugLog('log', `${playWndId}:视频预览启动成功:`, oData); setIsPlaying(true); (window as any)[playingKey] = false; @@ -387,13 +399,13 @@ const VideoPlayer: React.FC = ({ }, 1000); }) .catch(function(error: any) { - console.error(`${playWndId}:视频预览启动失败:`, error); + debugLog('error', `${playWndId}:视频预览启动失败:`, error); (window as any)[playingKey] = false; setIsPlaying(false); onError?.(error); }); } catch (error) { - console.error(`${playWndId}:播放视频出错:`, error); + debugLog('error', `${playWndId}:播放视频出错:`, error); (window as any)[playingKey] = false; setIsPlaying(false); onError?.(error); @@ -404,25 +416,25 @@ const VideoPlayer: React.FC = ({ const hideWnd = () => { const webControl = webControlRef.current; if (webControl) { - console.log('===执行隐藏播放器:', playWndId); + debugLog('log', '===执行隐藏播放器:', playWndId); try { // 先停止预览 try { webControl.JS_RequestInterface({ funcName: 'stopAllPreview', }); - console.log('已停止所有预览:', playWndId); + debugLog('log', '已停止所有预览:', playWndId); setIsPlaying(false); } catch (err) { - console.error('停止预览失败:', err); + debugLog('error', '停止预览失败:', err); } // 隐藏窗口 try { webControl.JS_HideWnd(); - console.log('已隐藏窗口:', playWndId); + debugLog('log', '已隐藏窗口:', playWndId); } catch (err) { - console.error('隐藏窗口失败:', err); + debugLog('error', '隐藏窗口失败:', err); } // 隐藏容器 @@ -434,7 +446,7 @@ const VideoPlayer: React.FC = ({ setIsHidden(true); return true; } catch (error) { - console.error('隐藏播放器出错:', error); + debugLog('error', '隐藏播放器出错:', error); // 即使出错,也尝试设置隐藏状态 setIsHidden(true); @@ -448,7 +460,7 @@ const VideoPlayer: React.FC = ({ const destroyWnd = () => { const webControl = webControlRef.current; if (webControl) { - console.log('===执行销毁播放器:', playWndId); + debugLog('log', '===执行销毁播放器:', playWndId); try { // 先隐藏DOM容器 - 防止销毁过程中仍然可见 const container = document.getElementById(playWndId); @@ -461,31 +473,31 @@ const VideoPlayer: React.FC = ({ webControl.JS_RequestInterface({ funcName: 'stopAllPreview', }); - console.log('已停止所有预览:', playWndId); + debugLog('log', '已停止所有预览:', playWndId); } catch (err) { - console.error('停止预览失败:', err); + debugLog('error', '停止预览失败:', err); } // 隐藏窗口 (页面切换时使用) try { webControl.JS_HideWnd(); - console.log('已隐藏窗口:', playWndId); + debugLog('log', '已隐藏窗口:', playWndId); } catch (err) { - console.error('隐藏窗口失败:', err); + debugLog('error', '隐藏窗口失败:', err); } // 实际销毁 (只有在组件卸载时才调用) if (false) { // 页面切换时不调用断开连接 try { webControl.JS_Disconnect(); - console.log('已断开连接:', playWndId); + debugLog('log', '已断开连接:', playWndId); // 清除缓存 // if (window.hikPlayerInstances && window.hikPlayerInstances[playWndId]) { // delete window.hikPlayerInstances[playWndId]; // } } catch (err) { - console.error('断开连接失败:', err); + debugLog('error', '断开连接失败:', err); } webControlRef.current = null; @@ -497,7 +509,7 @@ const VideoPlayer: React.FC = ({ return true; } catch (error) { - console.error('销毁播放器出错:', error); + debugLog('error', '销毁播放器出错:', error); // 即使出错,也标记为隐藏状态 setIsPlaying(false); @@ -512,17 +524,17 @@ const VideoPlayer: React.FC = ({ // 手动触发一次resize事件 const triggerManualResize = () => { if (!webControlRef.current) { - console.log(`${playWndId}:手动resize失败 - webControlRef为空`); + debugLog('log', `${playWndId}:手动resize失败 - webControlRef为空`); return; } - console.log(`${playWndId}:触发手动resize`); + debugLog('log', `${playWndId}:触发手动resize`); handleResize(); }; // 组件挂载时初始化插件和事件监听 useEffect(() => { if (visible) { - console.log(`${playWndId}:开始初始化播放器`); + debugLog('log', `${playWndId}:开始初始化播放器`); initPlugin(); } @@ -548,7 +560,7 @@ const VideoPlayer: React.FC = ({ const timerId = window.setTimeout(() => { if (webControlRef.current) { - console.log(`${playWndId}:尝试resize - 第${currentAttempt + 1}次, delay=${delay}ms`); + debugLog('log', `${playWndId}:尝试resize - 第${currentAttempt + 1}次, delay=${delay}ms`); handleResize(); } else if (currentAttempt < maxAttempts - 1) { // 如果还没有实例且没达到最大尝试次数,递归调用 @@ -592,7 +604,7 @@ const VideoPlayer: React.FC = ({ // 组件卸载时清理 return () => { - console.log(`${playWndId}:组件卸载,执行销毁播放器`); + debugLog('log', `${playWndId}:组件卸载,执行销毁播放器`); hideWnd(); window.removeEventListener('resize', stableResizeHandler); @@ -616,10 +628,10 @@ const VideoPlayer: React.FC = ({ // 监听hide prop的变化 useEffect(() => { if (hide && webControlRef.current && !isHidden) { - console.log('接收到隐藏信号,正在隐藏播放器:', playWndId); + debugLog('log', '接收到隐藏信号,正在隐藏播放器:', playWndId); hideWnd(); } else if (!hide && webControlRef.current && isHidden && visible) { - console.log('接收到显示信号,正在显示播放器:', playWndId); + debugLog('log', '接收到显示信号,正在显示播放器:', playWndId); // 显示播放器 try { @@ -642,7 +654,7 @@ const VideoPlayer: React.FC = ({ fetchVideoUrl(webControlRef.current); } } catch (err) { - console.error('显示播放器窗口失败:', err); + debugLog('error', '显示播放器窗口失败:', err); } } }, [hide, playWndId, isHidden, visible, isPlaying]); @@ -650,7 +662,7 @@ const VideoPlayer: React.FC = ({ // 监听尺寸变化重新调整大小 useEffect(() => { if (webControlRef.current && isInitialized && !isHidden) { - console.log('播放器尺寸变化,重新调整大小:', PLAYER_WIDTH, PLAYER_HEIGHT); + debugLog('log', '播放器尺寸变化,重新调整大小:', PLAYER_WIDTH, PLAYER_HEIGHT); handleResize(); } }, [PLAYER_WIDTH, PLAYER_HEIGHT, isInitialized, isHidden]); @@ -662,26 +674,26 @@ const VideoPlayer: React.FC = ({ if (webControl && isInitialized && !isHidden) { // 如果正在播放,需要先停止当前视频,然后播放新视频 if (isPlaying) { - console.log(`${playWndId}:设备ID变化,停止当前视频并切换到新视频:`, deviceId); + debugLog('log', `${playWndId}:设备ID变化,停止当前视频并切换到新视频:`, deviceId); try { // 停止当前预览 webControl.JS_RequestInterface({ funcName: 'stopAllPreview', }).then(() => { - console.log(`${playWndId}:成功停止当前视频,准备播放新视频`); + debugLog('log', `${playWndId}:成功停止当前视频,准备播放新视频`); setIsPlaying(false); // 延迟一点时间后获取新视频 setTimeout(() => { fetchVideoUrl(webControl); }, 300); }).catch((err: any) => { - console.error(`${playWndId}:停止当前视频失败:`, err); + debugLog('error', `${playWndId}:停止当前视频失败:`, err); // 即使停止失败,也尝试重置状态并播放新视频 setIsPlaying(false); fetchVideoUrl(webControl); }); } catch (err: any) { - console.error(`${playWndId}:停止视频时发生异常:`, err); + debugLog('error', `${playWndId}:停止视频时发生异常:`, err); // 出现异常时也重置播放状态并尝试播放新视频 setIsPlaying(false); fetchVideoUrl(webControl); @@ -695,7 +707,7 @@ const VideoPlayer: React.FC = ({ // 集成回调函数 const cbIntegrationCallBack = (oData: any) => { - console.log('集成回调函数', oData); + debugLog('log', '集成回调函数', oData); if (oData.responseMsg?.msg?.result === 816) { setIsPlaying(false); } @@ -736,7 +748,7 @@ const VideoPlayer: React.FC = ({ // 修改初始化流程,确保初始化完成后再获取并播放视频 webControl.JS_RequestInterface(JSON.parse(param)) .then(function(oData: any) { - console.log('初始化成功', oData); + debugLog('log', '初始化成功', oData); // 初始化成功后再次调整窗口大小 webControl.JS_Resize(PLAYER_WIDTH, PLAYER_HEIGHT); setWndCover(); @@ -747,7 +759,7 @@ const VideoPlayer: React.FC = ({ }, 1000); }) .catch(function(error: any) { - console.error('初始化失败', error); + debugLog('error', '初始化失败', error); message.error('视频插件初始化失败'); onError?.(error); }); @@ -758,7 +770,7 @@ const VideoPlayer: React.FC = ({ if (!webControl) return; return webControl.JS_RequestInterface(JSON.parse(value)).then(function(oData: any) { - console.log('requestInterface', oData); + debugLog('log', 'requestInterface', oData); return oData; }); }; @@ -776,12 +788,12 @@ const VideoPlayer: React.FC = ({ // 初始化插件 const initPlugin = async () => { - console.log(`${playWndId}:开始初始化视频插件...`); + debugLog('log', `${playWndId}:开始初始化视频插件...`); // 防止重复初始化 const initializingKey = `${playWndId}_initializing`; if ((window as any)[initializingKey]) { - console.log(`${playWndId}:插件正在初始化中,跳过重复初始化`); + debugLog('log', `${playWndId}:插件正在初始化中,跳过重复初始化`); return; } @@ -790,7 +802,7 @@ const VideoPlayer: React.FC = ({ // 检查是否有全局缓存的实例 if (window.hikPlayerInstances?.[playWndId]) { - console.log(`${playWndId}:使用全局缓存的播放器实例`); + debugLog('log', `${playWndId}:使用全局缓存的播放器实例`); webControlRef.current = window.hikPlayerInstances[playWndId]; setOWebControl(window.hikPlayerInstances[playWndId]); setIsInitialized(true); @@ -822,7 +834,7 @@ const VideoPlayer: React.FC = ({ }, 500); } } catch (err) { - console.error(`${playWndId}:显示播放器窗口失败:`, err); + debugLog('error', `${playWndId}:显示播放器窗口失败:`, err); // 如果显示失败,需要重新初始化 webControlRef.current = null; @@ -858,7 +870,7 @@ const VideoPlayer: React.FC = ({ // 从这里开始是创建新实例的逻辑 const dependenciesLoaded = await initDependencies(); if (!dependenciesLoaded) { - console.error(`${playWndId}:依赖加载失败,无法初始化插件`); + debugLog('error', `${playWndId}:依赖加载失败,无法初始化插件`); message.error('依赖加载失败,无法初始化插件'); onInitialized?.(false); (window as any)[initializingKey] = false; @@ -868,7 +880,7 @@ const VideoPlayer: React.FC = ({ // 检查播放器容器是否存在 const container = document.getElementById(playWndId); if (!container) { - console.error(`${playWndId}:播放器容器不存在`); + debugLog('error', `${playWndId}:播放器容器不存在`); message.error('播放器容器不存在,请检查页面结构'); onInitialized?.(false); (window as any)[initializingKey] = false; @@ -880,7 +892,7 @@ const VideoPlayer: React.FC = ({ // 使用 WebControl 构造函数创建实例 const { WebControl } = window; - console.log(`${playWndId}:创建WebControl实例`); + debugLog('log', `${playWndId}:创建WebControl实例`); const webControl = new WebControl({ szPluginContainer: playWndId, @@ -888,7 +900,7 @@ const VideoPlayer: React.FC = ({ iServicePortEnd: 15900, szClassId: '23BF3B0A-2C56-4D97-9C03-0CB103AA8F11', cbConnectSuccess: function() { - console.log(`${playWndId}:创建WebControl实例成功`); + debugLog('log', `${playWndId}:创建WebControl实例成功`); // VideoPluginConnect.dll 是从 VideoWebPlugin.exe 安装后的程序文件夹获取的 // 这里的路径是相对于插件运行目录的路径,不是网站的相对路径 webControl @@ -897,14 +909,14 @@ const VideoPlayer: React.FC = ({ }) .then( () => { - console.log(`${playWndId}:启动插件服务成功`); + debugLog('log', `${playWndId}:启动插件服务成功`); webControl.JS_SetWindowControlCallback({ cbIntegrationCallBack: cbIntegrationCallBack, }); webControl .JS_CreateWnd(playWndId, PLAYER_WIDTH, PLAYER_HEIGHT) .then(() => { - console.log(`${playWndId}:创建播放窗口成功`); + debugLog('log', `${playWndId}:创建播放窗口成功`); // 立即调整大小和位置 webControl.JS_Resize(PLAYER_WIDTH, PLAYER_HEIGHT); @@ -929,30 +941,30 @@ const VideoPlayer: React.FC = ({ webControlRef.current.JS_Resize(PLAYER_WIDTH, PLAYER_HEIGHT); setWndCover(); initBtnClicked(webControlRef.current); - console.log(`${playWndId}:初始化完成,尺寸已调整为:`, PLAYER_WIDTH, PLAYER_HEIGHT); + debugLog('log', `${playWndId}:初始化完成,尺寸已调整为:`, PLAYER_WIDTH, PLAYER_HEIGHT); } }, 500); }) .catch((error: any) => { - console.error(`${playWndId}:创建播放窗口失败`, error); + debugLog('error', `${playWndId}:创建播放窗口失败`, error); onInitialized?.(false); (window as any)[initializingKey] = false; }); }, (error: any) => { - console.error(`${playWndId}:启动插件服务失败`, error); + debugLog('error', `${playWndId}:启动插件服务失败`, error); onInitialized?.(false); (window as any)[initializingKey] = false; } ) .catch((error: any) => { - console.error(`${playWndId}:JS_StartService 出错:`, error); + debugLog('error', `${playWndId}:JS_StartService 出错:`, error); onInitialized?.(false); (window as any)[initializingKey] = false; }); }, cbConnectError: function(error: any) { - console.error(`${playWndId}:创建WebControl实例失败`, error); + debugLog('error', `${playWndId}:创建WebControl实例失败`, error); webControlRef.current = null; setOWebControl(null); message.warning('插件未启动,正在尝试启动,请稍候...'); @@ -975,7 +987,7 @@ const VideoPlayer: React.FC = ({ }); }, cbConnectClose: function(isNormalClose: boolean) { - console.log(`${playWndId}:WebControl连接关闭,正常关闭:`, isNormalClose); + debugLog('log', `${playWndId}:WebControl连接关闭,正常关闭:`, isNormalClose); webControlRef.current = null; setOWebControl(null); (window as any)[initializingKey] = false; @@ -984,8 +996,8 @@ const VideoPlayer: React.FC = ({ } }); } catch (error) { - console.error(`${playWndId}:初始化插件失败:`, error); - message.error('初始化插件失败,请刷新页面重试'); + debugLog('error', `${playWndId}:初始化插件失败:`, error); + // message.error('初始化插件失败,请刷新页面重试'); onInitialized?.(false); (window as any)[initializingKey] = false; }