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 = () => {