From 5a30d69cc8c330be4844c8217b06a057979a83db Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 28 Aug 2024 15:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/Meeting/index.tsx | 42 ++++++++++++++++++++++++++------------ src/utils/package/agora.ts | 4 ++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index 64bb067..2a74915 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -174,6 +174,7 @@ const Meeting: React.FC = () => { const msgTips = '您不是管理员或发言人,无法开启此功能!' useEffect(() => { let time: NodeJS.Timeout; + let getDesktopCapturerVideoTime: NodeJS.Timeout; setUser(userInfo) setTimeout(() => { if (location.hash.indexOf('/login') === -1) { @@ -193,11 +194,28 @@ const Meeting: React.FC = () => { time = setInterval(() => { setCurrentSeconds(currentSeconds++) }, 1000) + getDesktopCapturerVideoTime = setInterval(() => { + setSharedScreenItem((i: any) => { + if (i) { + agora.getDesktopCapturerVideo({ width: 0, height: 0 }, { width: 0, height: 0 }, false).then(res => { + if (res.length) { + let row = res.find((item: any) => item.sourceId === i.sourceId) + if (!row) { + stopScreenCapture() + setSharedScreenItem('') + } + } + }) + } + return i + }) + }, 3000) return () => { window.removeEventListener('customStorageChange', handleCustomStorageChange); window.removeEventListener('online', handleNetworkChange); window.removeEventListener('offline', handleNetworkChange); clearInterval(time) + clearInterval(getDesktopCapturerVideoTime) }; }, []); @@ -983,18 +1001,16 @@ const Meeting: React.FC = () => { } // 获取桌面可共享屏幕的引用 const getDesktopCapturerVideo = (): void => { - agora.getDesktopCapturerVideo().then((res: any) => { - if (sharedScreenList.length !== res.length) { - res.forEach((item: any) => { - if (item.thumbImage.buffer) { - item.thumbnailUrl = thumbImageBufferToBase64(item.thumbImage) - } - if (item.iconImage.buffer) { - item.iconDataUrl = thumbImageBufferToBase64(item.iconImage) - } - }) - setSharedScreenList(res) - } + agora.getDesktopCapturerVideo({ width: 300, height: 300 }, { width: 300, height: 300 }, true).then((res: any) => { + res.forEach((item: any) => { + if (item.thumbImage.buffer) { + item.thumbnailUrl = thumbImageBufferToBase64(item.thumbImage) + } + if (item.iconImage.buffer) { + item.iconDataUrl = thumbImageBufferToBase64(item.iconImage) + } + }) + setSharedScreenList(res) }) }; // 设置全员看谁 @@ -1662,7 +1678,7 @@ const Meeting: React.FC = () => {